@ -10,6 +10,8 @@
# include "ProgramEdgeGroup.h"
# include "ProgramEdgeGroup.h"
# include "ProgramAction.h"
# include "ProgramAction.h"
# include "src/storage/pgcl/VariableDeclaration.h"
namespace storm {
namespace storm {
namespace ppg {
namespace ppg {
/**
/**
@ -21,9 +23,10 @@ namespace storm {
using EdgeGroupIterator = ProgramLocation : : EdgeGroupIterator ;
using EdgeGroupIterator = ProgramLocation : : EdgeGroupIterator ;
using ConstLocationIterator = std : : unordered_map < ProgramLocationIdentifier , ProgramLocation > : : const_iterator ;
using ConstLocationIterator = std : : unordered_map < ProgramLocationIdentifier , ProgramLocation > : : const_iterator ;
ProgramGraph ( std : : shared_ptr < storm : : expressions : : ExpressionManager > const & expManager , std : : vector < storm : : expressions : : Variable > const & variables ) : expManager ( expManager ) , variables ( ) {
ProgramGraph ( std : : shared_ptr < storm : : expressions : : ExpressionManager > const & expManager , std : : vector < storm : : pgcl : : VariableDeclaration > const & variables ) : variables ( ) , expManager ( expManager ) {
for ( auto const & v : variables ) {
for ( auto const & v : variables ) {
this - > variables . emplace ( v . getIndex ( ) , v ) ;
this - > variables . emplace ( v . getVariable ( ) . getIndex ( ) , v . getVariable ( ) ) ;
this - > initialValues . emplace ( v . getVariable ( ) . getIndex ( ) , v . getInitialValueExpression ( ) ) ;
}
}
/ / No Action :
/ / No Action :
deterministicActions . emplace ( noActionId , DeterministicProgramAction ( this , noActionId ) ) ;
deterministicActions . emplace ( noActionId , DeterministicProgramAction ( this , noActionId ) ) ;
@ -46,9 +49,10 @@ namespace storm {
return & ( probabilisticActions . emplace ( newId , ProbabilisticProgramAction ( this , newId , var , from , to ) ) . first - > second ) ;
return & ( probabilisticActions . emplace ( newId , ProbabilisticProgramAction ( this , newId , var , from , to ) ) . first - > second ) ;
}
}
ProgramLocation * addLocation ( bool isInitial = false ) {
ProgramLocation * addLocation ( bool isInitial = false , bool successfulTermination = false , bool aborted = false , std : : vector < std : : string > const & labels = { } ) {
ProgramLocationIdentifier newId = freeLocationIndex ( ) ;
ProgramLocationIdentifier newId = freeLocationIndex ( ) ;
assert ( ! hasLocation ( newId ) ) ;
assert ( ! hasLocation ( newId ) ) ;
locationLabels [ newId ] = labels ;
return & ( locations . emplace ( newId , ProgramLocation ( this , newId , isInitial ) ) . first - > second ) ;
return & ( locations . emplace ( newId , ProgramLocation ( this , newId , isInitial ) ) . first - > second ) ;
}
}
@ -92,9 +96,25 @@ namespace storm {
}
}
return res ;
return res ;
}
bool hasLabel ( ProgramLocationIdentifier loc , std : : string const & label ) const {
return std : : find ( locationLabels . at ( loc ) . begin ( ) , locationLabels . at ( loc ) . end ( ) , label ) ! = locationLabels . at ( loc ) . end ( ) ;
}
}
bool hasSuccessfulTerminationLabel ( ProgramLocationIdentifier loc ) const {
return hasLabel ( loc , succesfulTerminationLabel ) ;
}
bool hasAbortLabel ( ProgramLocationIdentifier loc ) const {
return hasLabel ( loc , abortLabel ) ;
}
bool hasTerminationLabel ( ProgramLocationIdentifier loc ) const {
return hasSuccessfulTerminationLabel ( loc ) | | hasAbortLabel ( loc ) ;
}
ProgramActionIdentifier getNoActionId ( ) const {
ProgramActionIdentifier getNoActionId ( ) const {
return noActionId ;
return noActionId ;
@ -163,6 +183,11 @@ namespace storm {
return variables . size ( ) ;
return variables . size ( ) ;
}
}
storm : : expressions : : Expression getInitialValue ( ProgramVariableIdentifier v ) const {
return initialValues . at ( v ) ;
}
void collectInitialValues ( ) ;
ConstLocationIterator locationBegin ( ) const {
ConstLocationIterator locationBegin ( ) const {
return locations . begin ( ) ;
return locations . begin ( ) ;
@ -180,7 +205,10 @@ namespace storm {
return expManager ;
return expManager ;
}
}
std : : vector < ProgramVariableIdentifier > transientVariables ( ) const ;
std : : vector < ProgramVariableIdentifier > noeffectVariables ( ) const ;
std : : vector < ProgramVariableIdentifier > rewardVariables ( ) const ;
void checkValid ( ) {
void checkValid ( ) {
@ -195,11 +223,25 @@ namespace storm {
void printDot ( std : : ostream & os ) const ;
void printDot ( std : : ostream & os ) const ;
protected :
protected :
std : : vector < ProgramLocationIdentifier > initialLocationIdentifiers ( ) const {
std : : vector < ProgramLocationIdentifier > result ;
for ( auto const & loc : locations ) {
if ( loc . second . isInitial ( ) ) {
result . push_back ( loc . first ) ;
}
}
return result ;
}
/**
/**
* Returns the set of variables which do not occur in guards .
* Returns the set of variables which do not occur in guards .
*/
*/
std : : vector < ProgramVariableIdentifier > variablesNotInGuards ( ) const ;
std : : vector < ProgramVariableIdentifier > variablesNotInGuards ( ) const ;
std : : pair < bool , bool > checkIfRewardVariableHelper ( storm : : expressions : : Variable const & var , std : : unordered_map < ProgramActionIdentifier , DeterministicProgramAction > const & detActions ) const ;
ProgramLocation & getLocation ( ProgramLocationIdentifier id ) {
ProgramLocation & getLocation ( ProgramLocationIdentifier id ) {
return locations . at ( id ) ;
return locations . at ( id ) ;
}
}
@ -228,7 +270,10 @@ namespace storm {
std : : unordered_map < ProgramLocationIdentifier , ProgramLocation > locations ;
std : : unordered_map < ProgramLocationIdentifier , ProgramLocation > locations ;
storm : : expressions : : Expression initialValueRestriction ;
storm : : expressions : : Expression initialValueRestriction ;
std : : unordered_map < ProgramVariableIdentifier , storm : : expressions : : Variable > variables ;
std : : unordered_map < ProgramVariableIdentifier , storm : : expressions : : Variable > variables ;
/ / /
std : : unordered_map < ProgramVariableIdentifier , storm : : expressions : : Expression > initialValues ;
/ / If heavily used , then it might be better to use a bitvector and a seperate list for the names .
std : : unordered_map < ProgramVariableIdentifier , std : : vector < std : : string > > locationLabels ;
std : : shared_ptr < storm : : expressions : : ExpressionManager > expManager ;
std : : shared_ptr < storm : : expressions : : ExpressionManager > expManager ;
private :
private :
/ / Helper for IDs , may be changed later .
/ / Helper for IDs , may be changed later .
@ -237,6 +282,9 @@ namespace storm {
ProgramEdgeIdentifier newEdgeId = 0 ;
ProgramEdgeIdentifier newEdgeId = 0 ;
ProgramActionIdentifier newActionId = 1 ;
ProgramActionIdentifier newActionId = 1 ;
ProgramActionIdentifier noActionId = 0 ;
ProgramActionIdentifier noActionId = 0 ;
std : : string succesfulTerminationLabel = " __ret0__ " ;
std : : string abortLabel = " __ret1__ " ;
} ;
} ;
}
}