@ -3,6 +3,7 @@
# include <algorithm>
# include "src/storage/dd/CuddDdManager.h"
# include "src/exceptions/ExceptionMacros.h"
# include "src/exceptions/InvalidArgumentException.h"
# include "src/settings/Settings.h"
@ -49,17 +50,9 @@ namespace storm {
}
Dd < DdType : : CUDD > DdManager < DdType : : CUDD > : : getEncoding ( std : : string const & metaVariableName , int_fast64_t value ) {
// Check whether the meta variable exists.
if ( ! this - > hasMetaVariable ( metaVariableName ) ) {
throw storm : : exceptions : : InvalidArgumentException ( ) < < " Unknown meta variable name ' " < < metaVariableName < < " '. " ;
}
DdMetaVariable < DdType : : CUDD > const & metaVariable = this - > getMetaVariable ( metaVariableName ) ;
// Check whether the value is legal for this meta variable.
if ( value < metaVariable . getLow ( ) | | value > metaVariable . getHigh ( ) ) {
throw storm : : exceptions : : InvalidArgumentException ( ) < < " Illegal value " < < value < < " for meta variable ' " < < metaVariableName < < " '. " ;
}
LOG_THROW ( value > = metaVariable . getLow ( ) & & value < = metaVariable . getHigh ( ) , storm : : exceptions : : InvalidArgumentException , " Illegal value " < < value < < " for meta variable ' " < < metaVariableName < < " '. " ) ;
// Now compute the encoding relative to the low value of the meta variable.
value - = metaVariable . getLow ( ) ;
@ -85,11 +78,6 @@ namespace storm {
}
Dd < DdType : : CUDD > DdManager < DdType : : CUDD > : : getRange ( std : : string const & metaVariableName ) {
// Check whether the meta variable exists.
if ( ! this - > hasMetaVariable ( metaVariableName ) ) {
throw storm : : exceptions : : InvalidArgumentException ( ) < < " Unknown meta variable name ' " < < metaVariableName < < " '. " ;
}
storm : : dd : : DdMetaVariable < DdType : : CUDD > const & metaVariable = this - > getMetaVariable ( metaVariableName ) ;
Dd < DdType : : CUDD > result = this - > getZero ( ) ;
@ -101,11 +89,6 @@ namespace storm {
}
Dd < DdType : : CUDD > DdManager < DdType : : CUDD > : : getIdentity ( std : : string const & metaVariableName ) {
// Check whether the meta variable exists.
if ( ! this - > hasMetaVariable ( metaVariableName ) ) {
throw storm : : exceptions : : InvalidArgumentException ( ) < < " Unknown meta variable name ' " < < metaVariableName < < " '. " ;
}
storm : : dd : : DdMetaVariable < DdType : : CUDD > const & metaVariable = this - > getMetaVariable ( metaVariableName ) ;
Dd < DdType : : CUDD > result = this - > getZero ( ) ;
@ -116,91 +99,57 @@ namespace storm {
}
void DdManager < DdType : : CUDD > : : addMetaVariable ( std : : string const & name , int_fast64_t low , int_fast64_t high ) {
// Check whether the variable name is legal.
LOG_THROW ( name ! = " " & & name . back ( ) ! = ' \' ' , storm : : exceptions : : InvalidArgumentException , " Illegal name of meta variable: ' " < < name < < " '. " ) ;
// Check whether a meta variable already exists.
if ( this - > hasMetaVariable ( name ) ) {
throw storm : : exceptions : : InvalidArgumentException ( ) < < " A meta variable ' " < < name < < " ' already exists. " ;
}
LOG_THROW ( ! this - > hasMetaVariable ( name ) , storm : : exceptions : : InvalidArgumentException , " A meta variable ' " < < name < < " ' already exists. " ) ;
// Check that the range is legal.
if ( high = = low ) {
throw storm : : exceptions : : InvalidArgumentException ( ) < < " Range of meta variable must be at least 2 elements. " ;
}
LOG_THROW ( high ! = low , storm : : exceptions : : InvalidArgumentException , " Range of meta variable must be at least 2 elements. " ) ;
std : : size_t numberOfBits = static_cast < std : : size_t > ( std : : ceil ( std : : log2 ( high - low + 1 ) ) ) ;
std : : vector < Dd < DdType : : CUDD > > variables ;
std : : vector < Dd < DdType : : CUDD > > variablesPrime ;
for ( std : : size_t i = 0 ; i < numberOfBits ; + + i ) {
variables . emplace_back ( Dd < DdType : : CUDD > ( this - > shared_from_this ( ) , cuddManager . addVar ( ) , { name } ) ) ;
variablesPrime . emplace_back ( Dd < DdType : : CUDD > ( this - > shared_from_this ( ) , cuddManager . addVar ( ) , { name + " ' " } ) ) ;
}
// Now group the non-primed and primed variable.
for ( uint_fast64_t i = 0 ; i < numberOfBits ; + + i ) {
this - > getCuddManager ( ) . MakeTreeNode ( variables [ i ] . getCuddAdd ( ) . NodeReadIndex ( ) , 2 , MTR_FIXED ) ;
}
metaVariableMap . emplace ( name , DdMetaVariable < DdType : : CUDD > ( name , low , high , variables , this - > shared_from_this ( ) ) ) ;
metaVariableMap . emplace ( name + " ' " , DdMetaVariable < DdType : : CUDD > ( name + " ' " , low , high , variablesPrime , this - > shared_from_this ( ) ) ) ;
}
void DdManager < DdType : : CUDD > : : addMetaVariable ( std : : string const & name ) {
// Check whether the variable name is legal.
LOG_THROW ( name ! = " " & & name . back ( ) ! = ' \' ' , storm : : exceptions : : InvalidArgumentException , " Illegal name of meta variable: ' " < < name < < " '. " ) ;
// Check whether a meta variable already exists.
if ( this - > hasMetaVariable ( name ) ) {
throw storm : : exceptions : : InvalidArgumentException ( ) < < " A meta variable ' " < < name < < " ' already exists. " ;
}
LOG_THROW ( ! this - > hasMetaVariable ( name ) , storm : : exceptions : : InvalidArgumentException , " A meta variable ' " < < name < < " ' already exists. " ) ;
std : : vector < Dd < DdType : : CUDD > > variables ;
std : : vector < Dd < DdType : : CUDD > > variablesPrime ;
variables . emplace_back ( Dd < DdType : : CUDD > ( this - > shared_from_this ( ) , cuddManager . addVar ( ) , { name } ) ) ;
metaVariableMap . emplace ( name , DdMetaVariable < DdType : : CUDD > ( name , variables , this - > shared_from_this ( ) ) ) ;
}
void DdManager < DdType : : CUDD > : : addMetaVariablesInterleaved ( std : : vector < std : : string > const & names , int_fast64_t low , int_fast64_t high , bool fixedGroup ) {
// Make sure that at least one meta variable is added.
if ( names . size ( ) = = 0 ) {
throw storm : : exceptions : : InvalidArgumentException ( ) < < " Illegal to add zero meta variables. " ;
}
// Check that there are no duplicate names in the given name vector.
std : : vector < std : : string > nameCopy ( names ) ;
std : : sort ( nameCopy . begin ( ) , nameCopy . end ( ) ) ;
if ( std : : adjacent_find ( nameCopy . begin ( ) , nameCopy . end ( ) ) ! = nameCopy . end ( ) ) {
throw storm : : exceptions : : InvalidArgumentException ( ) < < " Cannot add duplicate meta variables. " ;
}
// Check that the range is legal.
if ( high = = low ) {
throw storm : : exceptions : : InvalidArgumentException ( ) < < " Range of meta variable must be at least 2 elements. " ;
}
variablesPrime . emplace_back ( Dd < DdType : : CUDD > ( this - > shared_from_this ( ) , cuddManager . addVar ( ) , { name + " ' " } ) ) ;
// Check whether a meta variable already exists.
for ( auto const & metaVariableName : names ) {
if ( this - > hasMetaVariable ( metaVariableName ) ) {
throw storm : : exceptions : : InvalidArgumentException ( ) < < " A meta variable ' " < < metaVariableName < < " ' already exists. " ;
}
}
// Add the variables in interleaved order.
std : : size_t numberOfBits = static_cast < std : : size_t > ( std : : ceil ( std : : log2 ( high - low + 1 ) ) ) ;
std : : vector < std : : vector < Dd < DdType : : CUDD > > > variables ( names . size ( ) ) ;
for ( uint_fast64_t bit = 0 ; bit < numberOfBits ; + + bit ) {
for ( uint_fast64_t i = 0 ; i < names . size ( ) ; + + i ) {
variables [ i ] . emplace_back ( Dd < DdType : : CUDD > ( this - > shared_from_this ( ) , cuddManager . addVar ( ) , { names [ i ] } ) ) ;
}
}
// If required, we group the bits on the same layer of the interleaved meta variables.
if ( fixedGroup ) {
for ( uint_fast64_t i = 0 ; i < names . size ( ) ; + + i ) {
this - > getCuddManager ( ) . MakeTreeNode ( variables [ i ] . front ( ) . getCuddAdd ( ) . NodeReadIndex ( ) , names . size ( ) , MTR_FIXED ) ;
}
}
// Now group the non-primed and primed variable.
this - > getCuddManager ( ) . MakeTreeNode ( variables . front ( ) . getCuddAdd ( ) . NodeReadIndex ( ) , 2 , MTR_FIXED ) ;
// Now add the meta variables.
for ( uint_fast64_t i = 0 ; i < names . size ( ) ; + + i ) {
metaVariableMap . emplace ( names [ i ] , DdMetaVariable < DdType : : CUDD > ( names [ i ] , low , high , variables [ i ] , this - > shared_from_this ( ) ) ) ;
}
metaVariableMap . emplace ( name , DdMetaVariable < DdType : : CUDD > ( name , variables , this - > shared_from_this ( ) ) ) ;
metaVariableMap . emplace ( name + " ' " , DdMetaVariable < DdType : : CUDD > ( name + " ' " , variablesPrime , this - > shared_from_this ( ) ) ) ;
}
DdMetaVariable < DdType : : CUDD > const & DdManager < DdType : : CUDD > : : getMetaVariable ( std : : string const & metaVariableName ) const {
auto const & nameVariablePair = metaVariableMap . find ( metaVariableName ) ;
if ( ! this - > hasMetaVariable ( metaVariableName ) ) {
throw storm : : exceptions : : InvalidArgumentException ( ) < < " Unknown meta variable name ' " < < metaVariableName < < " '. " ;
}
// Check whether the meta variable exists.
LOG_THROW ( nameVariablePair ! = metaVariableMap . end ( ) , storm : : exceptions : : InvalidArgumentException , " Unknown meta variable name ' " < < metaVariableName < < " '. " ) ;
return nameVariablePair - > second ;
}