Browse Source

Some fixes in formulas

Additional test case for reward formulas
main
Lanchid 12 years ago
parent
commit
b66e1a34db
  1. 2
      src/formula/ProbabilisticBoundOperator.h
  2. 2
      src/formula/RewardBoundOperator.h
  3. 16
      src/parser/PrctlParser.cpp
  4. 27
      test/parser/PrctlParserTest.cpp
  5. 0
      test/parser/prctl_files/probabilisticFormula.prctl
  6. 0
      test/parser/prctl_files/propositionalFormula.prctl
  7. 1
      test/parser/prctl_files/rewardFormula.prctl

2
src/formula/ProbabilisticBoundOperator.h

@ -59,7 +59,7 @@ public:
*/ */
ProbabilisticBoundOperator( ProbabilisticBoundOperator(
typename BoundOperator<T>::ComparisonType comparisonRelation, T bound, PctlPathFormula<T>* pathFormula) : typename BoundOperator<T>::ComparisonType comparisonRelation, T bound, PctlPathFormula<T>* pathFormula) :
BoundOperator<T>(BoundOperator<T>::LESS, bound, pathFormula) {
BoundOperator<T>(comparisonRelation, bound, pathFormula) {
// Intentionally left empty // Intentionally left empty
} }

2
src/formula/RewardBoundOperator.h

@ -57,7 +57,7 @@ public:
*/ */
RewardBoundOperator( RewardBoundOperator(
typename BoundOperator<T>::ComparisonType comparisonRelation, T bound, PctlPathFormula<T>* pathFormula) : typename BoundOperator<T>::ComparisonType comparisonRelation, T bound, PctlPathFormula<T>* pathFormula) :
BoundOperator<T>(BoundOperator<T>::LESS, bound, pathFormula) {
BoundOperator<T>(comparisonRelation, bound, pathFormula) {
// Intentionally left empty // Intentionally left empty
} }

16
src/parser/PrctlParser.cpp

@ -47,17 +47,21 @@ struct PrctlParser::PrctlGrammar : qi::grammar<Iterator, storm::formula::PctlFor
probabilisticBoundOperator = ( probabilisticBoundOperator = (
(qi::lit("P") >> qi::lit(">") >> qi::double_ >> qi::lit("[") >> pathFormula >> qi::lit("]"))[qi::_val = (qi::lit("P") >> qi::lit(">") >> qi::double_ >> qi::lit("[") >> pathFormula >> qi::lit("]"))[qi::_val =
phoenix::new_<storm::formula::ProbabilisticBoundOperator<double> >(storm::formula::BoundOperator<double>::GREATER, qi::_1, qi::_2)] | phoenix::new_<storm::formula::ProbabilisticBoundOperator<double> >(storm::formula::BoundOperator<double>::GREATER, qi::_1, qi::_2)] |
("P>=" >> qi::double_ >> '[' >> pathFormula >> ']')[qi::_val =
(qi::lit("P") >> qi::lit(">=") >> qi::double_ >> '[' >> pathFormula >> ']')[qi::_val =
phoenix::new_<storm::formula::ProbabilisticBoundOperator<double> >(storm::formula::BoundOperator<double>::GREATER_EQUAL, qi::_1, qi::_2)] | phoenix::new_<storm::formula::ProbabilisticBoundOperator<double> >(storm::formula::BoundOperator<double>::GREATER_EQUAL, qi::_1, qi::_2)] |
("P<" >> qi::double_ >> '[' >> pathFormula >> ']')[qi::_val =
(qi::lit("P") >> qi::lit("<") >> qi::double_ >> '[' >> pathFormula >> ']')[qi::_val =
phoenix::new_<storm::formula::ProbabilisticBoundOperator<double> >(storm::formula::BoundOperator<double>::LESS, qi::_1, qi::_2)] | phoenix::new_<storm::formula::ProbabilisticBoundOperator<double> >(storm::formula::BoundOperator<double>::LESS, qi::_1, qi::_2)] |
("P<=" >> qi::double_ >> '[' >> pathFormula >> ']')[qi::_val =
(qi::lit("P") >> qi::lit("<=") >> qi::double_ >> '[' >> pathFormula >> ']')[qi::_val =
phoenix::new_<storm::formula::ProbabilisticBoundOperator<double> >(storm::formula::BoundOperator<double>::LESS_EQUAL, qi::_1, qi::_2)] phoenix::new_<storm::formula::ProbabilisticBoundOperator<double> >(storm::formula::BoundOperator<double>::LESS_EQUAL, qi::_1, qi::_2)]
); );
rewardBoundOperator = ( rewardBoundOperator = (
("R>=" >> qi::double_ >> '[' >> pathFormula >> ']')[qi::_val =
(qi::lit("R") >> qi::lit(">") >> qi::double_ >> '[' >> pathFormula >> ']')[qi::_val =
phoenix::new_<storm::formula::RewardBoundOperator<double> >(storm::formula::BoundOperator<double>::GREATER, qi::_1, qi::_2)] |
(qi::lit("R") >> qi::lit(">=") >> qi::double_ >> '[' >> pathFormula >> ']')[qi::_val =
phoenix::new_<storm::formula::RewardBoundOperator<double> >(storm::formula::BoundOperator<double>::GREATER_EQUAL, qi::_1, qi::_2)] | phoenix::new_<storm::formula::RewardBoundOperator<double> >(storm::formula::BoundOperator<double>::GREATER_EQUAL, qi::_1, qi::_2)] |
("R<=" >> qi::double_ >> '[' >> pathFormula >> ']')[qi::_val =
(qi::lit("R") >> qi::lit("<") >> qi::double_ >> '[' >> pathFormula >> ']')[qi::_val =
phoenix::new_<storm::formula::RewardBoundOperator<double> >(storm::formula::BoundOperator<double>::LESS, qi::_1, qi::_2)] |
(qi::lit("R") >> qi::lit("<=")>> qi::double_ >> '[' >> pathFormula >> ']')[qi::_val =
phoenix::new_<storm::formula::RewardBoundOperator<double> >(storm::formula::BoundOperator<double>::LESS_EQUAL, qi::_1, qi::_2)] phoenix::new_<storm::formula::RewardBoundOperator<double> >(storm::formula::BoundOperator<double>::LESS_EQUAL, qi::_1, qi::_2)]
); );
@ -76,7 +80,7 @@ struct PrctlParser::PrctlGrammar : qi::grammar<Iterator, storm::formula::PctlFor
phoenix::new_<storm::formula::BoundedEventually<double>>(qi::_2, qi::_1)]; phoenix::new_<storm::formula::BoundedEventually<double>>(qi::_2, qi::_1)];
globally = ('G' >> stateFormula)[qi::_val = globally = ('G' >> stateFormula)[qi::_val =
phoenix::new_<storm::formula::Globally<double> >(qi::_1)]; phoenix::new_<storm::formula::Globally<double> >(qi::_1)];
until = (stateFormula >> 'U' >> stateFormula)[qi::_val =
until = (stateFormula >> qi::lit("U") >> stateFormula)[qi::_val =
phoenix::new_<storm::formula::Until<double>>(qi::_1, qi::_2)]; phoenix::new_<storm::formula::Until<double>>(qi::_1, qi::_2)];
boundedUntil = (stateFormula >> "U<=" >> qi::int_ >> stateFormula)[qi::_val = boundedUntil = (stateFormula >> "U<=" >> qi::int_ >> stateFormula)[qi::_val =
phoenix::new_<storm::formula::BoundedUntil<double>>(qi::_1, qi::_3, qi::_2)]; phoenix::new_<storm::formula::BoundedUntil<double>>(qi::_1, qi::_3, qi::_2)];

27
test/parser/PrctlParserTest.cpp

@ -26,10 +26,10 @@ TEST(PrctlParserTest, apOnly) {
} }
TEST(PrctlParserTest, formulaTest1) {
TEST(PrctlParserTest, propositionalFormula) {
storm::parser::PrctlParser* prctlParser = nullptr; storm::parser::PrctlParser* prctlParser = nullptr;
ASSERT_NO_THROW( ASSERT_NO_THROW(
prctlParser = new storm::parser::PrctlParser(STORM_CPP_TESTS_BASE_PATH "/parser/prctl_files/testFormula1.prctl")
prctlParser = new storm::parser::PrctlParser(STORM_CPP_TESTS_BASE_PATH "/parser/prctl_files/propositionalFormula.prctl")
); );
ASSERT_NE(prctlParser->getFormula(), nullptr); ASSERT_NE(prctlParser->getFormula(), nullptr);
@ -41,16 +41,33 @@ TEST(PrctlParserTest, formulaTest1) {
} }
TEST(PrctlParserTest, formulaTest2) {
TEST(PrctlParserTest, probabilisticFormula) {
storm::parser::PrctlParser* prctlParser = nullptr; storm::parser::PrctlParser* prctlParser = nullptr;
ASSERT_NO_THROW( ASSERT_NO_THROW(
prctlParser = new storm::parser::PrctlParser(STORM_CPP_TESTS_BASE_PATH "/parser/prctl_files/testFormula2.prctl")
prctlParser = new storm::parser::PrctlParser(STORM_CPP_TESTS_BASE_PATH "/parser/prctl_files/probabilisticFormula.prctl")
); );
ASSERT_NE(prctlParser->getFormula(), nullptr); ASSERT_NE(prctlParser->getFormula(), nullptr);
ASSERT_EQ(prctlParser->getFormula()->toString(), "P<0.500000 [F a]");
ASSERT_EQ(prctlParser->getFormula()->toString(), "P > 0.500000 [F a]");
delete prctlParser;
}
TEST(PrctlParserTest, rewardFormula) {
storm::parser::PrctlParser* prctlParser = nullptr;
ASSERT_NO_THROW(
prctlParser = new storm::parser::PrctlParser(STORM_CPP_TESTS_BASE_PATH "/parser/prctl_files/rewardFormula.prctl")
);
ASSERT_NE(prctlParser->getFormula(), nullptr);
storm::formula::RewardBoundOperator<double>* op = static_cast<storm::formula::RewardBoundOperator<double>*>(prctlParser->getFormula());
ASSERT_EQ(storm::formula::BoundOperator<double>::GREATER_EQUAL, op->getComparisonOperator());
ASSERT_EQ(prctlParser->getFormula()->toString(), "R >= 15.000000 [(a U !b)]");
delete prctlParser; delete prctlParser;

0
test/parser/prctl_files/testFormula2.prctl → test/parser/prctl_files/probabilisticFormula.prctl

0
test/parser/prctl_files/testFormula1.prctl → test/parser/prctl_files/propositionalFormula.prctl

1
test/parser/prctl_files/rewardFormula.prctl

@ -0,0 +1 @@
R >= 15 [ a U !b ]
Loading…
Cancel
Save