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.

240 lines
13 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. #include "storm-config.h"
  9. TEST(TopologicalValueIterationMdpPrctlModelCheckerTest, Dice) {
  10. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  11. std::shared_ptr<storm::models::Mdp<double>> mdp = storm::parser::AutoParser::parseModel(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")->as<storm::models::Mdp<double>>();
  12. ASSERT_EQ(mdp->getNumberOfStates(), 169ull);
  13. ASSERT_EQ(mdp->getNumberOfTransitions(), 436ull);
  14. storm::modelchecker::prctl::TopologicalValueIterationMdpPrctlModelChecker<double> mc(*mdp);
  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_LT(std::abs(result[0] - 0.0277777612209320068), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  20. delete probFormula;
  21. apFormula = new storm::property::prctl::Ap<double>("two");
  22. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  23. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  24. result = mc.checkNoBoundOperator(*probFormula);
  25. ASSERT_LT(std::abs(result[0] - 0.0277777612209320068), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  26. delete probFormula;
  27. apFormula = new storm::property::prctl::Ap<double>("three");
  28. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  29. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  30. result = mc.checkNoBoundOperator(*probFormula);
  31. ASSERT_LT(std::abs(result[0] - 0.0555555224418640136), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  32. delete probFormula;
  33. apFormula = new storm::property::prctl::Ap<double>("three");
  34. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  35. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  36. result = mc.checkNoBoundOperator(*probFormula);
  37. ASSERT_LT(std::abs(result[0] - 0.0555555224418640136), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  38. delete probFormula;
  39. apFormula = new storm::property::prctl::Ap<double>("four");
  40. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  41. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  42. result = mc.checkNoBoundOperator(*probFormula);
  43. ASSERT_LT(std::abs(result[0] - 0.083333283662796020508), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  44. delete probFormula;
  45. apFormula = new storm::property::prctl::Ap<double>("four");
  46. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  47. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  48. result = mc.checkNoBoundOperator(*probFormula);
  49. ASSERT_LT(std::abs(result[0] - 0.083333283662796020508), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  50. delete probFormula;
  51. apFormula = new storm::property::prctl::Ap<double>("done");
  52. storm::property::prctl::ReachabilityReward<double>* reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  53. storm::property::prctl::RewardNoBoundOperator<double>* rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  54. result = mc.checkNoBoundOperator(*rewardFormula);
  55. #ifdef STORM_HAVE_CUDAFORSTORM
  56. ASSERT_LT(std::abs(result[0] - 7.333329499), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  57. #else
  58. ASSERT_LT(std::abs(result[0] - 7.33332904), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  59. #endif
  60. delete rewardFormula;
  61. apFormula = new storm::property::prctl::Ap<double>("done");
  62. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  63. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  64. result = mc.checkNoBoundOperator(*rewardFormula);;
  65. #ifdef STORM_HAVE_CUDAFORSTORM
  66. ASSERT_LT(std::abs(result[0] - 7.333329499), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  67. #else
  68. ASSERT_LT(std::abs(result[0] - 7.33333151), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  69. #endif
  70. delete rewardFormula;
  71. std::shared_ptr<storm::models::Mdp<double>> stateRewardMdp = storm::parser::AutoParser::parseModel(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", "")->as<storm::models::Mdp<double>>();
  72. storm::modelchecker::prctl::TopologicalValueIterationMdpPrctlModelChecker<double> stateRewardModelChecker(*stateRewardMdp);
  73. apFormula = new storm::property::prctl::Ap<double>("done");
  74. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  75. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  76. result = stateRewardModelChecker.checkNoBoundOperator(*rewardFormula);
  77. #ifdef STORM_HAVE_CUDAFORSTORM
  78. ASSERT_LT(std::abs(result[0] - 7.333329499), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  79. #else
  80. ASSERT_LT(std::abs(result[0] - 7.33332904), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  81. #endif
  82. delete rewardFormula;
  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. #ifdef STORM_HAVE_CUDAFORSTORM
  88. ASSERT_LT(std::abs(result[0] - 7.333329499), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  89. #else
  90. ASSERT_LT(std::abs(result[0] - 7.33333151), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  91. #endif
  92. delete rewardFormula;
  93. std::shared_ptr<storm::models::Mdp<double>> stateAndTransitionRewardMdp = storm::parser::AutoParser::parseModel(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")->as<storm::models::Mdp<double>>();
  94. storm::modelchecker::prctl::TopologicalValueIterationMdpPrctlModelChecker<double> stateAndTransitionRewardModelChecker(*stateAndTransitionRewardMdp);
  95. apFormula = new storm::property::prctl::Ap<double>("done");
  96. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  97. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  98. result = stateAndTransitionRewardModelChecker.checkNoBoundOperator(*rewardFormula);
  99. #ifdef STORM_HAVE_CUDAFORSTORM
  100. ASSERT_LT(std::abs(result[0] - 14.666658998), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  101. #else
  102. ASSERT_LT(std::abs(result[0] - 14.6666581), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  103. #endif
  104. delete rewardFormula;
  105. apFormula = new storm::property::prctl::Ap<double>("done");
  106. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  107. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  108. result = stateAndTransitionRewardModelChecker.checkNoBoundOperator(*rewardFormula);
  109. #ifdef STORM_HAVE_CUDAFORSTORM
  110. ASSERT_LT(std::abs(result[0] - 14.666658998), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  111. #else
  112. ASSERT_LT(std::abs(result[0] - 14.666663), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  113. #endif
  114. delete rewardFormula;
  115. }
  116. TEST(TopologicalValueIterationMdpPrctlModelCheckerTest, AsynchronousLeader) {
  117. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  118. std::shared_ptr<storm::models::Mdp<double>> mdp = storm::parser::AutoParser::parseModel(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")->as<storm::models::Mdp<double>>();
  119. ASSERT_EQ(mdp->getNumberOfStates(), 3172ull);
  120. ASSERT_EQ(mdp->getNumberOfTransitions(), 7144ull);
  121. storm::modelchecker::prctl::TopologicalValueIterationMdpPrctlModelChecker<double> mc(*mdp);
  122. storm::property::prctl::Ap<double>* apFormula = new storm::property::prctl::Ap<double>("elected");
  123. storm::property::prctl::Eventually<double>* eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  124. storm::property::prctl::ProbabilisticNoBoundOperator<double>* probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  125. std::vector<double> result = mc.checkNoBoundOperator(*probFormula);
  126. ASSERT_LT(std::abs(result[0] - 1), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  127. delete probFormula;
  128. apFormula = new storm::property::prctl::Ap<double>("elected");
  129. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  130. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  131. result = mc.checkNoBoundOperator(*probFormula);
  132. ASSERT_LT(std::abs(result[0] - 1), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  133. delete probFormula;
  134. apFormula = new storm::property::prctl::Ap<double>("elected");
  135. storm::property::prctl::BoundedEventually<double>* boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 25);
  136. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, false);
  137. result = mc.checkNoBoundOperator(*probFormula);
  138. ASSERT_LT(std::abs(result[0] - 0.0625), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  139. delete probFormula;
  140. apFormula = new storm::property::prctl::Ap<double>("elected");
  141. boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 25);
  142. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, true);
  143. result = mc.checkNoBoundOperator(*probFormula);
  144. ASSERT_LT(std::abs(result[0] - 0.0625), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  145. delete probFormula;
  146. apFormula = new storm::property::prctl::Ap<double>("elected");
  147. storm::property::prctl::ReachabilityReward<double>* reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  148. storm::property::prctl::RewardNoBoundOperator<double>* rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  149. result = mc.checkNoBoundOperator(*rewardFormula);
  150. #ifdef STORM_HAVE_CUDAFORSTORM
  151. ASSERT_LT(std::abs(result[0] - 4.285689611), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  152. #else
  153. ASSERT_LT(std::abs(result[0] - 4.285701547), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  154. #endif
  155. delete rewardFormula;
  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. #ifdef STORM_HAVE_CUDAFORSTORM
  161. ASSERT_LT(std::abs(result[0] - 4.285689611), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  162. #else
  163. ASSERT_LT(std::abs(result[0] - 4.285703591), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  164. #endif
  165. delete rewardFormula;
  166. }