@ -26,7 +26,7 @@ namespace storm {
instantaneousRewardFormula = ( qi : : lit ( " I= " ) > expressionParser ) [ qi : : _val = phoenix : : bind ( & FormulaParserGrammar : : createInstantaneousRewardFormula , phoenix : : ref ( * this ) , qi : : _1 ) ] ;
instantaneousRewardFormula . name ( " instantaneous reward formula " ) ;
cumulativeRewardFormula = ( qi : : lit ( " C " ) > > timeBound ) [ qi : : _val = phoenix : : bind ( & FormulaParserGrammar : : createCumulativeRewardFormula , phoenix : : ref ( * this ) , qi : : _1 ) ] ;
cumulativeRewardFormula = ( qi : : lit ( " C " ) > > ( timeBound % qi : : lit ( " , " ) ) ) [ qi : : _val = phoenix : : bind ( & FormulaParserGrammar : : createCumulativeRewardFormula , phoenix : : ref ( * this ) , qi : : _1 ) ] ;
cumulativeRewardFormula . name ( " cumulative reward formula " ) ;
totalRewardFormula = ( qi : : lit ( " C " ) ) [ qi : : _val = phoenix : : bind ( & FormulaParserGrammar : : createTotalRewardFormula , phoenix : : ref ( * this ) ) ] ;
@ -71,15 +71,20 @@ namespace storm {
pathFormulaWithoutUntil = eventuallyFormula ( qi : : _r1 ) | globallyFormula ( qi : : _r1 ) | nextFormula ( qi : : _r1 ) | stateFormula ;
pathFormulaWithoutUntil . name ( " path formula " ) ;
untilFormula = pathFormulaWithoutUntil ( qi : : _r1 ) [ qi : : _val = qi : : _1 ] > > * ( qi : : lit ( " U " ) > > - timeBound > > pathFormulaWithoutUntil ( qi : : _r1 ) ) [ qi : : _val = phoenix : : bind ( & FormulaParserGrammar : : createUntilFormula , phoenix : : ref ( * this ) , qi : : _val , qi : : _1 , qi : : _2 ) ] ;
untilFormula = pathFormulaWithoutUntil ( qi : : _r1 ) [ qi : : _val = qi : : _1 ] > > * ( qi : : lit ( " U " ) > > - ( timeBound % qi : : lit ( " , " ) ) > > pathFormulaWithoutUntil ( qi : : _r1 ) ) [ qi : : _val = phoenix : : bind ( & FormulaParserGrammar : : createUntilFormula , phoenix : : ref ( * this ) , qi : : _val , qi : : _1 , qi : : _2 ) ] ;
untilFormula . name ( " until formula " ) ;
conditionalFormula = untilFormula ( qi : : _r1 ) [ qi : : _val = qi : : _1 ] > > * ( qi : : lit ( " || " ) > > untilFormula ( storm : : logic : : FormulaContext : : Probability ) ) [ qi : : _val = phoenix : : bind ( & FormulaParserGrammar : : createConditionalFormula , phoenix : : ref ( * this ) , qi : : _val , qi : : _1 , qi : : _r1 ) ] ;
conditionalFormula . name ( " conditional formula " ) ;
timeBound = ( ( - rewardModelName > > qi : : lit ( " [ " ) ) > expressionParser > qi : : lit ( " , " ) > expressionParser > qi : : lit ( " ] " ) )
timeBoundReference = ( - qi : : lit ( " rew " ) > > rewardModelName ) [ qi : : _val = phoenix : : bind ( & FormulaParserGrammar : : createTimeBoundReference , phoenix : : ref ( * this ) , storm : : logic : : TimeBoundType : : Reward , qi : : _1 ) ]
| ( qi : : lit ( " steps " ) ) [ qi : : _val = phoenix : : bind ( & FormulaParserGrammar : : createTimeBoundReference , phoenix : : ref ( * this ) , storm : : logic : : TimeBoundType : : Steps , boost : : none ) ]
| ( - qi : : lit ( " time " ) ) [ qi : : _val = phoenix : : bind ( & FormulaParserGrammar : : createTimeBoundReference , phoenix : : ref ( * this ) , storm : : logic : : TimeBoundType : : Time , boost : : none ) ] ;
timeBoundReference . name ( " time bound reference " ) ;
timeBound = ( ( timeBoundReference > > qi : : lit ( " [ " ) ) > expressionParser > qi : : lit ( " , " ) > expressionParser > qi : : lit ( " ] " ) )
[ qi : : _val = phoenix : : bind ( & FormulaParserGrammar : : createTimeBoundFromInterval , phoenix : : ref ( * this ) , qi : : _2 , qi : : _3 , qi : : _1 ) ]
| ( - rewardModelName > > ( qi : : lit ( " <= " ) [ qi : : _a = true , qi : : _b = false ] | qi : : lit ( " < " ) [ qi : : _a = true , qi : : _b = true ] | qi : : lit ( " >= " ) [ qi : : _a = false , qi : : _b = false ] | qi : : lit ( " > " ) [ qi : : _a = false , qi : : _b = true ] ) > > expressionParser )
| ( timeBoundReferenc e > > ( qi : : lit ( " <= " ) [ qi : : _a = true , qi : : _b = false ] | qi : : lit ( " < " ) [ qi : : _a = true , qi : : _b = true ] | qi : : lit ( " >= " ) [ qi : : _a = false , qi : : _b = false ] | qi : : lit ( " > " ) [ qi : : _a = false , qi : : _b = true ] ) > > expressionParser )
[ qi : : _val = phoenix : : bind ( & FormulaParserGrammar : : createTimeBoundFromSingleBound , phoenix : : ref ( * this ) , qi : : _2 , qi : : _a , qi : : _b , qi : : _1 ) ] ;
timeBound . name ( " time bound " ) ;
@ -215,20 +220,29 @@ namespace storm {
return static_cast < bool > ( manager ) ;
}
std : : tuple < boost : : optional < storm : : logic : : TimeBound > , boost : : optional < storm : : logic : : TimeBound > , boost : : optional < std : : string > > FormulaParserGrammar : : createTimeBoundFromInterval ( storm : : expressions : : Expression const & lowerBound , storm : : expressions : : Expression const & upperBound , boost : : optional < std : : string > const & rewardName ) const {
std : : shared_ptr < storm : : logic : : TimeBoundReference > FormulaParserGrammar : : createTimeBoundReference ( storm : : logic : : TimeBoundType const & type , boost : : optional < std : : string > const & rewardModelName ) const {
if ( type = = storm : : logic : : TimeBoundType : : Reward ) {
STORM_LOG_THROW ( rewardModelName , storm : : exceptions : : WrongFormatException , " Reward bound does not specify a reward model name. " ) ;
return std : : make_shared < storm : : logic : : TimeBoundReference > ( rewardModelName . get ( ) ) ;
} else {
return std : : make_shared < storm : : logic : : TimeBoundReference > ( type ) ;
}
}
std : : tuple < boost : : optional < storm : : logic : : TimeBound > , boost : : optional < storm : : logic : : TimeBound > , std : : shared_ptr < storm : : logic : : TimeBoundReference > > FormulaParserGrammar : : createTimeBoundFromInterval ( storm : : expressions : : Expression const & lowerBound , storm : : expressions : : Expression const & upperBound , std : : shared_ptr < storm : : logic : : TimeBoundReference > const & timeBoundReference ) const {
// As soon as it somehow does not break everything anymore, I will change return types here.
storm : : logic : : TimeBound lower ( false , lowerBound ) ;
storm : : logic : : TimeBound upper ( false , upperBound ) ;
return std : : make_tuple ( lower , upper , rewardName ) ;
return std : : make_tuple ( lower , upper , timeBoundReferenc e) ;
}
std : : tuple < boost : : optional < storm : : logic : : TimeBound > , boost : : optional < storm : : logic : : TimeBound > , boost : : optional < std : : string > > FormulaParserGrammar : : createTimeBoundFromSingleBound ( storm : : expressions : : Expression const & bound , bool upperBound , bool strict , boost : : optional < std : : string > const & rewardName ) const {
std : : tuple < boost : : optional < storm : : logic : : TimeBound > , boost : : optional < storm : : logic : : TimeBound > , std : : shared_ptr < storm : : logic : : TimeBoundReference > > FormulaParserGrammar : : createTimeBoundFromSingleBound ( storm : : expressions : : Expression const & bound , bool upperBound , bool strict , std : : shared_ptr < storm : : logic : : TimeBoundReference > const & timeBoundReferenc e) const {
// As soon as it somehow does not break everything anymore, I will change return types here.
if ( upperBound ) {
return std : : make_tuple ( boost : : none , storm : : logic : : TimeBound ( strict , bound ) , rewardNam e) ;
return std : : make_tuple ( boost : : none , storm : : logic : : TimeBound ( strict , bound ) , timeBoundReferenc e) ;
} else {
return std : : make_tuple ( storm : : logic : : TimeBound ( strict , bound ) , boost : : none , rewardNam e) ;
return std : : make_tuple ( storm : : logic : : TimeBound ( strict , bound ) , boost : : none , timeBoundReferenc e) ;
}
}
@ -236,16 +250,16 @@ namespace storm {
return std : : shared_ptr < storm : : logic : : Formula const > ( new storm : : logic : : InstantaneousRewardFormula ( timeBound ) ) ;
}
std : : shared_ptr < storm : : logic : : Formula const > FormulaParserGrammar : : createCumulativeRewardFormula ( std : : tuple < boost : : optional < storm : : logic : : TimeBound > , boost : : optional < storm : : logic : : TimeBound > , boost : : optional < std : : string > > const & timeBound ) const {
STORM_LOG_THROW ( ! std : : get < 0 > ( timeBound ) , storm : : exceptions : : WrongFormatException , " Cumulative reward formulas with lower time bound are not allowed. " ) ;
STORM_LOG_THROW ( std : : get < 1 > ( timeBound ) , storm : : exceptions : : WrongFormatException , " Cumulative reward formulas require an upper bound. " ) ;
if ( std : : get < 2 > ( timeBound ) ) {
storm : : logic : : TimeBoundReference tbr ( std : : get < 2 > ( timeBound ) . get ( ) ) ;
return std : : shared_ptr < storm : : logic : : Formula const > ( new storm : : logic : : CumulativeRewardFormula ( std : : get < 1 > ( timeBound ) . get ( ) , tbr ) ) ;
} else {
storm : : logic : : TimeBoundReference tbr ( storm : : logic : : TimeBoundType : : Time ) ;
return std : : shared_ptr < storm : : logic : : Formula const > ( new storm : : logic : : CumulativeRewardFormula ( std : : get < 1 > ( timeBound ) . get ( ) , tbr ) ) ;
std : : shared_ptr < storm : : logic : : Formula const > FormulaParserGrammar : : createCumulativeRewardFormula ( std : : vector < std : : tuple < boost : : optional < storm : : logic : : TimeBound > , boost : : optional < storm : : logic : : TimeBound > , std : : shared_ptr < storm : : logic : : TimeBoundReference > > > const & timeBounds ) const {
std : : vector < storm : : logic : : TimeBound > bounds ;
std : : vector < storm : : logic : : TimeBoundReference > timeBoundReferences ;
for ( auto const & timeBound : timeBounds ) {
STORM_LOG_THROW ( ! std : : get < 0 > ( timeBound ) , storm : : exceptions : : WrongFormatException , " Cumulative reward formulas with lower time bound are not allowed. " ) ;
STORM_LOG_THROW ( std : : get < 1 > ( timeBound ) , storm : : exceptions : : WrongFormatException , " Cumulative reward formulas require an upper bound. " ) ;
bounds . push_back ( std : : get < 1 > ( timeBound ) . get ( ) ) ;
timeBoundReferences . emplace_back ( * std : : get < 2 > ( timeBound ) ) ;
}
return std : : shared_ptr < storm : : logic : : Formula const > ( new storm : : logic : : CumulativeRewardFormula ( bounds . front ( ) , timeBoundReferences . front ( ) ) ) ;
}
std : : shared_ptr < storm : : logic : : Formula const > FormulaParserGrammar : : createTotalRewardFormula ( ) const {
@ -269,19 +283,14 @@ namespace storm {
return std : : shared_ptr < storm : : logic : : Formula const > ( new storm : : logic : : AtomicLabelFormula ( label ) ) ;
}
std : : shared_ptr < storm : : logic : : Formula const > FormulaParserGrammar : : createEventuallyFormula ( boost : : optional < std : : vector < std : : tuple < boost : : optional < storm : : logic : : TimeBound > , boost : : optional < storm : : logic : : TimeBound > , boost : : optional < std : : string > > > > const & timeBounds , storm : : logic : : FormulaContext context , std : : shared_ptr < storm : : logic : : Formula const > const & subformula ) const {
//std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createEventuallyFormula(boost::optional<std::tuple<boost::optional<storm::logic::TimeBound>, boost::optional<storm::logic::TimeBound>, boost::optional<std::string>>> const& timeBound, storm::logic::FormulaContext context, std::shared_ptr<storm::logic::Formula const> const& subformula) const {
std : : shared_ptr < storm : : logic : : Formula const > FormulaParserGrammar : : createEventuallyFormula ( boost : : optional < std : : vector < std : : tuple < boost : : optional < storm : : logic : : TimeBound > , boost : : optional < storm : : logic : : TimeBound > , std : : shared_ptr < storm : : logic : : TimeBoundReference > > > > const & timeBounds , storm : : logic : : FormulaContext context , std : : shared_ptr < storm : : logic : : Formula const > const & subformula ) const {
if ( timeBounds & & ! timeBounds . get ( ) . empty ( ) ) {
std : : vector < boost : : optional < storm : : logic : : TimeBound > > lowerBounds , upperBounds ;
std : : vector < storm : : logic : : TimeBoundReference > timeBoundReferences ;
for ( auto const & timeBound : timeBounds . get ( ) ) {
lowerBounds . push_back ( std : : get < 0 > ( timeBound ) ) ;
upperBounds . push_back ( std : : get < 1 > ( timeBound ) ) ;
if ( std : : get < 2 > ( timeBound ) ) {
timeBoundReferences . emplace_back ( std : : get < 2 > ( timeBound ) . get ( ) ) ;
} else {
timeBoundReferences . emplace_back ( storm : : logic : : TimeBoundType : : Time ) ;
}
timeBoundReferences . emplace_back ( * std : : get < 2 > ( timeBound ) ) ;
}
return std : : shared_ptr < storm : : logic : : Formula const > ( new storm : : logic : : BoundedUntilFormula ( createBooleanLiteralFormula ( true ) , subformula , lowerBounds , upperBounds , timeBoundReferences ) ) ;
} else {
@ -297,14 +306,16 @@ namespace storm {
return std : : shared_ptr < storm : : logic : : Formula const > ( new storm : : logic : : NextFormula ( subformula ) ) ;
}
std : : shared_ptr < storm : : logic : : Formula const > FormulaParserGrammar : : createUntilFormula ( std : : shared_ptr < storm : : logic : : Formula const > const & leftSubformula , boost : : optional < std : : tuple < boost : : optional < storm : : logic : : TimeBound > , boost : : optional < storm : : logic : : TimeBound > , boost : : optional < std : : string > > > const & timeBound , std : : shared_ptr < storm : : logic : : Formula const > const & rightSubformula ) {
if ( timeBound ) {
if ( std : : get < 2 > ( timeBound . get ( ) ) ) {
return std : : shared_ptr < storm : : logic : : Formula const > ( new storm : : logic : : BoundedUntilFormula ( leftSubformula , rightSubformula , std : : get < 0 > ( timeBound . get ( ) ) , std : : get < 1 > ( timeBound . get ( ) ) , storm : : logic : : TimeBoundReference ( std : : get < 2 > ( timeBound . get ( ) ) . get ( ) ) ) ) ;
} else {
return std : : shared_ptr < storm : : logic : : Formula const > ( new storm : : logic : : BoundedUntilFormula ( leftSubformula , rightSubformula , std : : get < 0 > ( timeBound . get ( ) ) , std : : get < 1 > ( timeBound . get ( ) ) , storm : : logic : : TimeBoundReference ( storm : : logic : : TimeBoundType : : Time ) ) ) ;
std : : shared_ptr < storm : : logic : : Formula const > FormulaParserGrammar : : createUntilFormula ( std : : shared_ptr < storm : : logic : : Formula const > const & leftSubformula , boost : : optional < std : : vector < std : : tuple < boost : : optional < storm : : logic : : TimeBound > , boost : : optional < storm : : logic : : TimeBound > , std : : shared_ptr < storm : : logic : : TimeBoundReference > > > > const & timeBounds , std : : shared_ptr < storm : : logic : : Formula const > const & rightSubformula ) {
if ( timeBounds & & ! timeBounds . get ( ) . empty ( ) ) {
std : : vector < boost : : optional < storm : : logic : : TimeBound > > lowerBounds , upperBounds ;
std : : vector < storm : : logic : : TimeBoundReference > timeBoundReferences ;
for ( auto const & timeBound : timeBounds . get ( ) ) {
lowerBounds . push_back ( std : : get < 0 > ( timeBound ) ) ;
upperBounds . push_back ( std : : get < 1 > ( timeBound ) ) ;
timeBoundReferences . emplace_back ( * std : : get < 2 > ( timeBound ) ) ;
}
return std : : shared_ptr < storm : : logic : : Formula const > ( new storm : : logic : : BoundedUntilFormula ( leftSubformula , rightSubformula , lowerBounds , upperBounds , timeBoundReferences ) ) ;
} else {
return std : : shared_ptr < storm : : logic : : Formula const > ( new storm : : logic : : UntilFormula ( leftSubformula , rightSubformula ) ) ;
}