@ -22,6 +22,15 @@ import prism.PrismComponent;
import prism.PrismException ;
import prism.PrismLangException ;
/ * *
* A variant of ModulesFileGenerator that is suitable for model generation
* at a symbolic level , i . e . , where numeric values are kept as expressions
* instead of being evaluated .
* < br >
* Used by the parametric / exact engine to build models .
* < br >
* Uses exact arithmetic to evaluate the various expressions in a model description .
* /
public class ModulesFileModelGeneratorSymbolic implements ModelGeneratorSymbolic
{
/ / Parent PrismComponent ( logs , settings etc . )
@ -246,7 +255,8 @@ public class ModulesFileModelGeneratorSymbolic implements ModelGeneratorSymbolic
public State getInitialState ( ) throws PrismException
{
if ( modulesFile . getInitialStates ( ) = = null ) {
return modulesFile . getDefaultInitialState ( ) ;
/ / get initial state , using exact evaluation
return modulesFile . getDefaultInitialState ( true ) ;
} else {
/ / Inefficient but probably won ' t be called
return getInitialStates ( ) . get ( 0 ) ;
@ -259,7 +269,8 @@ public class ModulesFileModelGeneratorSymbolic implements ModelGeneratorSymbolic
List < State > initStates = new ArrayList < State > ( ) ;
/ / Easy ( normal ) case : just one initial state
if ( modulesFile . getInitialStates ( ) = = null ) {
State state = modulesFile . getDefaultInitialState ( ) ;
/ / get initial state , using exact evaluation
State state = modulesFile . getDefaultInitialState ( true ) ;
initStates . add ( state ) ;
}
/ / Otherwise , there may be multiple initial states
@ -268,7 +279,7 @@ public class ModulesFileModelGeneratorSymbolic implements ModelGeneratorSymbolic
Expression init = modulesFile . getInitialStates ( ) ;
List < State > allPossStates = varList . getAllStates ( ) ;
for ( State possState : allPossStates ) {
if ( init . evaluateBoolean ( modulesFile . getConstantValues ( ) , possState ) ) {
if ( init . evaluateExact ( modulesFile . getConstantValues ( ) , possState ) . toBoolean ( ) ) {
initStates . add ( possState ) ;
}
}
@ -369,7 +380,7 @@ public class ModulesFileModelGeneratorSymbolic implements ModelGeneratorSymbolic
public boolean isLabelTrue ( int i ) throws PrismException
{
Expression expr = labelList . getLabel ( i ) ;
return expr . evaluateBoolean ( exploreState ) ;
return expr . evaluateExact ( exploreState ) . toBoolean ( ) ;
}
@Override
@ -381,8 +392,8 @@ public class ModulesFileModelGeneratorSymbolic implements ModelGeneratorSymbolic
for ( int i = 0 ; i < n ; i + + ) {
if ( ! rewStr . getRewardStructItem ( i ) . isTransitionReward ( ) ) {
Expression guard = rewStr . getStates ( i ) ;
if ( guard . evaluateBoolean ( modulesFile . getConstantValues ( ) , state ) ) {
double rew = rewStr . getReward ( i ) . evaluateDouble ( modulesFile . getConstantValues ( ) , state ) ;
if ( guard . evaluateExact ( modulesFile . getConstantValues ( ) , state ) . toBoolean ( ) ) {
double rew = rewStr . getReward ( i ) . evaluateExact ( modulesFile . getConstantValues ( ) , state ) . doubleValue ( ) ;
if ( Double . isNaN ( rew ) )
throw new PrismLangException ( "Reward structure evaluates to NaN at state " + state , rewStr . getReward ( i ) ) ;
d + = rew ;
@ -403,8 +414,8 @@ public class ModulesFileModelGeneratorSymbolic implements ModelGeneratorSymbolic
Expression guard = rewStr . getStates ( i ) ;
String cmdAction = rewStr . getSynch ( i ) ;
if ( action = = null ? ( cmdAction . isEmpty ( ) ) : action . equals ( cmdAction ) ) {
if ( guard . evaluateBoolean ( modulesFile . getConstantValues ( ) , state ) ) {
double rew = rewStr . getReward ( i ) . evaluateDouble ( modulesFile . getConstantValues ( ) , state ) ;
if ( guard . evaluateExact ( modulesFile . getConstantValues ( ) , state ) . toBoolean ( ) ) {
double rew = rewStr . getReward ( i ) . evaluateExact ( modulesFile . getConstantValues ( ) , state ) . doubleValue ( ) ;
if ( Double . isNaN ( rew ) )
throw new PrismLangException ( "Reward structure evaluates to NaN at state " + state , rewStr . getReward ( i ) ) ;
d + = rew ;