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.

225 lines
12 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/solver/NativeNondeterministicLinearEquationSolver.h"
  4. #include "src/settings/Settings.h"
  5. #include "src/modelchecker/prctl/SparseMdpPrctlModelChecker.h"
  6. #include "src/modelchecker/prctl/TopologicalValueIterationMdpPrctlModelChecker.h"
  7. #include "src/parser/AutoParser.h"
  8. TEST(TopologicalValueIterationMdpPrctlModelCheckerTest, Dice) {
  9. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  10. 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");
  11. //storm::parser::AutoParser<double> parser(STORM_CPP_BASE_PATH "/examples/mdp/scc/scc.tra", STORM_CPP_BASE_PATH "/examples/mdp/scc/scc.lab", "");
  12. ASSERT_EQ(parser.getType(), storm::models::MDP);
  13. std::shared_ptr<storm::models::Mdp<double>> mdp = parser.getModel<storm::models::Mdp<double>>();
  14. ASSERT_EQ(mdp->getNumberOfStates(), 169ull);
  15. ASSERT_EQ(mdp->getNumberOfTransitions(), 436ull);
  16. storm::modelchecker::prctl::TopologicalValueIterationMdpPrctlModelChecker<double> mc(*mdp);
  17. storm::property::prctl::Ap<double>* apFormula = new storm::property::prctl::Ap<double>("two");
  18. storm::property::prctl::Eventually<double>* eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  19. storm::property::prctl::ProbabilisticNoBoundOperator<double>* probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  20. std::vector<double> result = mc.checkNoBoundOperator(*probFormula);
  21. ASSERT_LT(std::abs(result[0] - 0.0277777612209320068), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  22. delete probFormula;
  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->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  28. delete probFormula;
  29. apFormula = new storm::property::prctl::Ap<double>("three");
  30. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  31. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  32. result = mc.checkNoBoundOperator(*probFormula);
  33. ASSERT_LT(std::abs(result[0] - 0.0555555224418640136), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  34. delete probFormula;
  35. apFormula = new storm::property::prctl::Ap<double>("three");
  36. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  37. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  38. result = mc.checkNoBoundOperator(*probFormula);
  39. ASSERT_LT(std::abs(result[0] - 0.0555555224418640136), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  40. delete probFormula;
  41. apFormula = new storm::property::prctl::Ap<double>("four");
  42. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  43. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  44. result = mc.checkNoBoundOperator(*probFormula);
  45. ASSERT_LT(std::abs(result[0] - 0.083333283662796020508), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  46. delete probFormula;
  47. apFormula = new storm::property::prctl::Ap<double>("four");
  48. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  49. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  50. result = mc.checkNoBoundOperator(*probFormula);
  51. ASSERT_LT(std::abs(result[0] - 0.083333283662796020508), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  52. delete probFormula;
  53. apFormula = new storm::property::prctl::Ap<double>("done");
  54. storm::property::prctl::ReachabilityReward<double>* reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  55. storm::property::prctl::RewardNoBoundOperator<double>* rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  56. result = mc.checkNoBoundOperator(*rewardFormula);
  57. ASSERT_LT(std::abs(result[0] - 7.33332904), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  58. delete rewardFormula;
  59. apFormula = new storm::property::prctl::Ap<double>("done");
  60. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  61. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  62. result = mc.checkNoBoundOperator(*rewardFormula);;
  63. ASSERT_LT(std::abs(result[0] - 7.33333151), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  64. delete rewardFormula;
  65. 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", "");
  66. ASSERT_EQ(stateRewardParser.getType(), storm::models::MDP);
  67. std::shared_ptr<storm::models::Mdp<double>> stateRewardMdp = stateRewardParser.getModel<storm::models::Mdp<double>>();
  68. storm::modelchecker::prctl::TopologicalValueIterationMdpPrctlModelChecker<double> stateRewardModelChecker(*stateRewardMdp);
  69. apFormula = new storm::property::prctl::Ap<double>("done");
  70. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  71. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  72. result = stateRewardModelChecker.checkNoBoundOperator(*rewardFormula);
  73. ASSERT_LT(std::abs(result[0] - 7.33332904), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  74. delete rewardFormula;
  75. apFormula = new storm::property::prctl::Ap<double>("done");
  76. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  77. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  78. result = stateRewardModelChecker.checkNoBoundOperator(*rewardFormula);
  79. ASSERT_LT(std::abs(result[0] - 7.33333151), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  80. delete rewardFormula;
  81. 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");
  82. ASSERT_EQ(stateAndTransitionRewardParser.getType(), storm::models::MDP);
  83. std::shared_ptr<storm::models::Mdp<double>> stateAndTransitionRewardMdp = stateAndTransitionRewardParser.getModel<storm::models::Mdp<double>>();
  84. storm::modelchecker::prctl::TopologicalValueIterationMdpPrctlModelChecker<double> stateAndTransitionRewardModelChecker(*stateAndTransitionRewardMdp);
  85. apFormula = new storm::property::prctl::Ap<double>("done");
  86. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  87. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  88. result = stateAndTransitionRewardModelChecker.checkNoBoundOperator(*rewardFormula);
  89. ASSERT_LT(std::abs(result[0] - 14.6666581), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  90. delete rewardFormula;
  91. apFormula = new storm::property::prctl::Ap<double>("done");
  92. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  93. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  94. result = stateAndTransitionRewardModelChecker.checkNoBoundOperator(*rewardFormula);
  95. ASSERT_LT(std::abs(result[0] - 14.666663), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  96. delete rewardFormula;
  97. }
  98. TEST(TopologicalValueIterationMdpPrctlModelCheckerTest, AsynchronousLeader) {
  99. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  100. 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");
  101. ASSERT_EQ(parser.getType(), storm::models::MDP);
  102. std::shared_ptr<storm::models::Mdp<double>> mdp = parser.getModel<storm::models::Mdp<double>>();
  103. ASSERT_EQ(mdp->getNumberOfStates(), 3172ull);
  104. ASSERT_EQ(mdp->getNumberOfTransitions(), 7144ull);
  105. storm::modelchecker::prctl::TopologicalValueIterationMdpPrctlModelChecker<double> mc(*mdp);
  106. storm::property::prctl::Ap<double>* apFormula = new storm::property::prctl::Ap<double>("elected");
  107. storm::property::prctl::Eventually<double>* eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  108. storm::property::prctl::ProbabilisticNoBoundOperator<double>* probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  109. std::vector<double> result = mc.checkNoBoundOperator(*probFormula);
  110. ASSERT_LT(std::abs(result[0] - 1), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  111. delete probFormula;
  112. apFormula = new storm::property::prctl::Ap<double>("elected");
  113. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  114. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  115. result = mc.checkNoBoundOperator(*probFormula);
  116. ASSERT_LT(std::abs(result[0] - 1), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  117. delete probFormula;
  118. apFormula = new storm::property::prctl::Ap<double>("elected");
  119. storm::property::prctl::BoundedEventually<double>* boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 25);
  120. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, false);
  121. result = mc.checkNoBoundOperator(*probFormula);
  122. ASSERT_LT(std::abs(result[0] - 0.0625), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  123. delete probFormula;
  124. apFormula = new storm::property::prctl::Ap<double>("elected");
  125. boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 25);
  126. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, true);
  127. result = mc.checkNoBoundOperator(*probFormula);
  128. ASSERT_LT(std::abs(result[0] - 0.0625), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  129. delete probFormula;
  130. apFormula = new storm::property::prctl::Ap<double>("elected");
  131. storm::property::prctl::ReachabilityReward<double>* reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  132. storm::property::prctl::RewardNoBoundOperator<double>* rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  133. result = mc.checkNoBoundOperator(*rewardFormula);;
  134. ASSERT_LT(std::abs(result[0] - 4.285689611), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  135. delete rewardFormula;
  136. apFormula = new storm::property::prctl::Ap<double>("elected");
  137. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  138. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  139. result = mc.checkNoBoundOperator(*rewardFormula);;
  140. ASSERT_LT(std::abs(result[0] - 4.285689611), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  141. delete rewardFormula;
  142. }