You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

261 lines
12 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/modelchecker/prctl/SparseMdpPrctlModelChecker.h"
  4. #include "src/solver/GmmxxNondeterministicLinearEquationSolver.h"
  5. #include "src/utility/Settings.h"
  6. #include "src/parser/AutoParser.h"
  7. TEST(GmmxxMdpPrctlModelCheckerTest, Dice) {
  8. storm::settings::Settings* s = storm::settings::instance();
  9. storm::parser::AutoParser<double> parser(STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.tra", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.lab", "", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.flip.trans.rew");
  10. ASSERT_EQ(parser.getType(), storm::models::MDP);
  11. std::shared_ptr<storm::models::Mdp<double>> mdp = parser.getModel<storm::models::Mdp<double>>();
  12. ASSERT_EQ(mdp->getNumberOfStates(), 169u);
  13. ASSERT_EQ(mdp->getNumberOfTransitions(), 436u);
  14. storm::modelchecker::prctl::SparseMdpPrctlModelChecker<double> mc(*mdp, new storm::solver::GmmxxNondeterministicLinearEquationSolver<double>());
  15. storm::property::prctl::Ap<double>* apFormula = new storm::property::prctl::Ap<double>("two");
  16. storm::property::prctl::Eventually<double>* eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  17. storm::property::prctl::ProbabilisticNoBoundOperator<double>* probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  18. std::vector<double>* result = mc.checkNoBoundOperator(*probFormula);
  19. ASSERT_NE(nullptr, result);
  20. ASSERT_LT(std::abs((*result)[0] - 0.0277777612209320068), s->get<double>("precision"));
  21. delete probFormula;
  22. delete result;
  23. apFormula = new storm::property::prctl::Ap<double>("two");
  24. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  25. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  26. result = mc.checkNoBoundOperator(*probFormula);
  27. ASSERT_LT(std::abs((*result)[0] - 0.0277777612209320068), s->get<double>("precision"));
  28. delete probFormula;
  29. delete result;
  30. apFormula = new storm::property::prctl::Ap<double>("three");
  31. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  32. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  33. result = mc.checkNoBoundOperator(*probFormula);
  34. ASSERT_LT(std::abs((*result)[0] - 0.0555555224418640136), s->get<double>("precision"));
  35. delete probFormula;
  36. delete result;
  37. apFormula = new storm::property::prctl::Ap<double>("three");
  38. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  39. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  40. result = mc.checkNoBoundOperator(*probFormula);
  41. ASSERT_LT(std::abs((*result)[0] - 0.0555555224418640136), s->get<double>("precision"));
  42. delete probFormula;
  43. delete result;
  44. apFormula = new storm::property::prctl::Ap<double>("four");
  45. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  46. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  47. result = mc.checkNoBoundOperator(*probFormula);
  48. ASSERT_LT(std::abs((*result)[0] - 0.083333283662796020508), s->get<double>("precision"));
  49. delete probFormula;
  50. delete result;
  51. apFormula = new storm::property::prctl::Ap<double>("four");
  52. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  53. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  54. result = mc.checkNoBoundOperator(*probFormula);
  55. ASSERT_LT(std::abs((*result)[0] - 0.083333283662796020508), s->get<double>("precision"));
  56. delete probFormula;
  57. delete result;
  58. apFormula = new storm::property::prctl::Ap<double>("done");
  59. storm::property::prctl::ReachabilityReward<double>* reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  60. storm::property::prctl::RewardNoBoundOperator<double>* rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  61. result = mc.checkNoBoundOperator(*rewardFormula);
  62. ASSERT_LT(std::abs((*result)[0] - 7.3333294987678527832), s->get<double>("precision"));
  63. delete rewardFormula;
  64. delete result;
  65. apFormula = new storm::property::prctl::Ap<double>("done");
  66. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  67. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  68. result = mc.checkNoBoundOperator(*rewardFormula);;
  69. ASSERT_LT(std::abs((*result)[0] - 7.3333294987678527832), s->get<double>("precision"));
  70. delete rewardFormula;
  71. delete result;
  72. storm::parser::AutoParser<double> stateRewardParser(STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.tra", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.lab", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.flip.state.rew", "");
  73. ASSERT_EQ(stateRewardParser.getType(), storm::models::MDP);
  74. std::shared_ptr<storm::models::Mdp<double>> stateRewardMdp = stateRewardParser.getModel<storm::models::Mdp<double>>();
  75. storm::modelchecker::prctl::SparseMdpPrctlModelChecker<double> stateRewardModelChecker(*stateRewardMdp, new storm::solver::GmmxxNondeterministicLinearEquationSolver<double>());
  76. apFormula = new storm::property::prctl::Ap<double>("done");
  77. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  78. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  79. result = stateRewardModelChecker.checkNoBoundOperator(*rewardFormula);
  80. ASSERT_LT(std::abs((*result)[0] - 7.3333294987678527832), s->get<double>("precision"));
  81. delete rewardFormula;
  82. delete result;
  83. apFormula = new storm::property::prctl::Ap<double>("done");
  84. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  85. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  86. result = stateRewardModelChecker.checkNoBoundOperator(*rewardFormula);
  87. ASSERT_LT(std::abs((*result)[0] - 7.3333294987678527832), s->get<double>("precision"));
  88. delete rewardFormula;
  89. delete result;
  90. storm::parser::AutoParser<double> stateAndTransitionRewardParser(STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.tra", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.lab", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.flip.state.rew", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.flip.trans.rew");
  91. ASSERT_EQ(stateAndTransitionRewardParser.getType(), storm::models::MDP);
  92. std::shared_ptr<storm::models::Mdp<double>> stateAndTransitionRewardMdp = stateAndTransitionRewardParser.getModel<storm::models::Mdp<double>>();
  93. storm::modelchecker::prctl::SparseMdpPrctlModelChecker<double> stateAndTransitionRewardModelChecker(*stateAndTransitionRewardMdp, new storm::solver::GmmxxNondeterministicLinearEquationSolver<double>());
  94. apFormula = new storm::property::prctl::Ap<double>("done");
  95. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  96. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  97. result = stateAndTransitionRewardModelChecker.checkNoBoundOperator(*rewardFormula);
  98. ASSERT_LT(std::abs((*result)[0] - (2 * 7.3333294987678527832)), s->get<double>("precision"));
  99. delete rewardFormula;
  100. delete result;
  101. apFormula = new storm::property::prctl::Ap<double>("done");
  102. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  103. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  104. result = stateAndTransitionRewardModelChecker.checkNoBoundOperator(*rewardFormula);
  105. ASSERT_LT(std::abs((*result)[0] - (2 * 7.3333294987678527832)), s->get<double>("precision"));
  106. delete rewardFormula;
  107. delete result;
  108. }
  109. TEST(GmmxxMdpPrctlModelCheckerTest, AsynchronousLeader) {
  110. storm::settings::Settings* s = storm::settings::instance();
  111. storm::parser::AutoParser<double> parser(STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader4.tra", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader4.lab", "", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader4.trans.rew");
  112. ASSERT_EQ(parser.getType(), storm::models::MDP);
  113. std::shared_ptr<storm::models::Mdp<double>> mdp = parser.getModel<storm::models::Mdp<double>>();
  114. ASSERT_EQ(mdp->getNumberOfStates(), 3172u);
  115. ASSERT_EQ(mdp->getNumberOfTransitions(), 7144u);
  116. storm::modelchecker::prctl::SparseMdpPrctlModelChecker<double> mc(*mdp, new storm::solver::GmmxxNondeterministicLinearEquationSolver<double>());
  117. storm::property::prctl::Ap<double>* apFormula = new storm::property::prctl::Ap<double>("elected");
  118. storm::property::prctl::Eventually<double>* eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  119. storm::property::prctl::ProbabilisticNoBoundOperator<double>* probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  120. std::vector<double>* result = mc.checkNoBoundOperator(*probFormula);
  121. ASSERT_NE(nullptr, result);
  122. ASSERT_LT(std::abs((*result)[0] - 1), s->get<double>("precision"));
  123. delete probFormula;
  124. delete result;
  125. apFormula = new storm::property::prctl::Ap<double>("elected");
  126. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  127. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  128. result = mc.checkNoBoundOperator(*probFormula);
  129. ASSERT_NE(nullptr, result);
  130. ASSERT_LT(std::abs((*result)[0] - 1), s->get<double>("precision"));
  131. delete probFormula;
  132. delete result;
  133. apFormula = new storm::property::prctl::Ap<double>("elected");
  134. storm::property::prctl::BoundedEventually<double>* boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 25);
  135. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, true);
  136. result = mc.checkNoBoundOperator(*probFormula);
  137. ASSERT_NE(nullptr, result);
  138. ASSERT_LT(std::abs((*result)[0] - 0.0625), s->get<double>("precision"));
  139. delete probFormula;
  140. delete result;
  141. apFormula = new storm::property::prctl::Ap<double>("elected");
  142. boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 25);
  143. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, false);
  144. result = mc.checkNoBoundOperator(*probFormula);
  145. ASSERT_NE(nullptr, result);
  146. ASSERT_LT(std::abs((*result)[0] - 0.0625), s->get<double>("precision"));
  147. delete probFormula;
  148. delete result;
  149. apFormula = new storm::property::prctl::Ap<double>("elected");
  150. storm::property::prctl::ReachabilityReward<double>* reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  151. storm::property::prctl::RewardNoBoundOperator<double>* rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  152. result = mc.checkNoBoundOperator(*rewardFormula);;
  153. ASSERT_LT(std::abs((*result)[0] - 4.28568908480604982), s->get<double>("precision"));
  154. delete rewardFormula;
  155. delete result;
  156. apFormula = new storm::property::prctl::Ap<double>("elected");
  157. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  158. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  159. result = mc.checkNoBoundOperator(*rewardFormula);;
  160. ASSERT_NE(nullptr, result);
  161. ASSERT_LT(std::abs((*result)[0] - 4.2856904354441400784), s->get<double>("precision"));
  162. delete rewardFormula;
  163. delete result;
  164. }