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.

244 lines
12 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/settings/Settings.h"
  4. #include "src/modelchecker/prctl/SparseMdpPrctlModelChecker.h"
  5. #include "src/solver/AbstractNondeterministicLinearEquationSolver.h"
  6. #include "src/parser/AutoParser.h"
  7. TEST(SparseMdpPrctlModelCheckerTest, AsynchronousLeader) {
  8. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  9. storm::parser::AutoParser<double> parser(STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader7.tra", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader7.lab", "", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader7.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(), 2095783u);
  13. ASSERT_EQ(mdp->getNumberOfTransitions(), 7714385u);
  14. storm::modelchecker::prctl::SparseMdpPrctlModelChecker<double> mc(*mdp, new storm::solver::AbstractNondeterministicLinearEquationSolver<double>());
  15. storm::property::prctl::Ap<double>* apFormula = new storm::property::prctl::Ap<double>("elected");
  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. LOG4CPLUS_WARN(logger, "Model Checking Pmin=? [F elected] on asynchronous_leader/leader7...");
  19. std::vector<double>* result = mc.checkNoBoundOperator(*probFormula);
  20. LOG4CPLUS_WARN(logger, "Done.");
  21. ASSERT_NE(nullptr, result);
  22. ASSERT_LT(std::abs((*result)[0] - 1), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  23. delete probFormula;
  24. delete result;
  25. apFormula = new storm::property::prctl::Ap<double>("elected");
  26. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  27. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  28. LOG4CPLUS_WARN(logger, "Model Checking Pmax=? [F elected] on asynchronous_leader/leader7...");
  29. result = mc.checkNoBoundOperator(*probFormula);
  30. LOG4CPLUS_WARN(logger, "Done.");
  31. ASSERT_NE(nullptr, result);
  32. ASSERT_LT(std::abs((*result)[0] - 1), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  33. delete probFormula;
  34. delete result;
  35. apFormula = new storm::property::prctl::Ap<double>("elected");
  36. storm::property::prctl::BoundedEventually<double>* boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 25);
  37. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, true);
  38. LOG4CPLUS_WARN(logger, "Model Checking Pmin=? [F<=25 elected] on asynchronous_leader/leader7...");
  39. result = mc.checkNoBoundOperator(*probFormula);
  40. LOG4CPLUS_WARN(logger, "Done.");
  41. ASSERT_NE(nullptr, result);
  42. ASSERT_LT(std::abs((*result)[0] - 0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  43. delete probFormula;
  44. delete result;
  45. apFormula = new storm::property::prctl::Ap<double>("elected");
  46. boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 25);
  47. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, false);
  48. LOG4CPLUS_WARN(logger, "Model Checking Pmax=? [F<=25 elected] on asynchronous_leader/leader7...");
  49. result = mc.checkNoBoundOperator(*probFormula);
  50. LOG4CPLUS_WARN(logger, "Done.");
  51. ASSERT_NE(nullptr, result);
  52. ASSERT_LT(std::abs((*result)[0] - 0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  53. delete probFormula;
  54. delete result;
  55. apFormula = new storm::property::prctl::Ap<double>("elected");
  56. storm::property::prctl::ReachabilityReward<double>* reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  57. storm::property::prctl::RewardNoBoundOperator<double>* rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  58. LOG4CPLUS_WARN(logger, "Model Checking Rmin=? [F elected] on asynchronous_leader/leader7...");
  59. result = mc.checkNoBoundOperator(*rewardFormula);
  60. LOG4CPLUS_WARN(logger, "Done.");
  61. ASSERT_LT(std::abs((*result)[0] - 6.172433512), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  62. delete rewardFormula;
  63. delete result;
  64. apFormula = new storm::property::prctl::Ap<double>("elected");
  65. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  66. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  67. LOG4CPLUS_WARN(logger, "Model Checking Rmax=? [F elected] on asynchronous_leader/leader7...");
  68. result = mc.checkNoBoundOperator(*rewardFormula);
  69. LOG4CPLUS_WARN(logger, "Done");
  70. ASSERT_NE(nullptr, result);
  71. ASSERT_LT(std::abs((*result)[0] - 6.1724344), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  72. delete rewardFormula;
  73. delete result;
  74. }
  75. TEST(SparseMdpPrctlModelCheckerTest, Consensus) {
  76. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  77. // Increase the maximal number of iterations, because the solver does not converge otherwise.
  78. // This is done in the main cpp unit
  79. storm::parser::AutoParser<double> parser(STORM_CPP_BASE_PATH "/examples/mdp/consensus/coin4_6.tra", STORM_CPP_BASE_PATH "/examples/mdp/consensus/coin4_6.lab", STORM_CPP_BASE_PATH "/examples/mdp/consensus/coin4_6.steps.state.rew", "");
  80. ASSERT_EQ(parser.getType(), storm::models::MDP);
  81. std::shared_ptr<storm::models::Mdp<double>> mdp = parser.getModel<storm::models::Mdp<double>>();
  82. ASSERT_EQ(mdp->getNumberOfStates(), 63616u);
  83. ASSERT_EQ(mdp->getNumberOfTransitions(), 213472u);
  84. storm::modelchecker::prctl::SparseMdpPrctlModelChecker<double> mc(*mdp, new storm::solver::AbstractNondeterministicLinearEquationSolver<double>());
  85. storm::property::prctl::Ap<double>* apFormula = new storm::property::prctl::Ap<double>("finished");
  86. storm::property::prctl::Eventually<double>* eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  87. storm::property::prctl::ProbabilisticNoBoundOperator<double>* probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  88. LOG4CPLUS_WARN(logger, "Model Checking Pmin=? [F finished] on consensus/coin4_6...");
  89. std::vector<double>* result = mc.checkNoBoundOperator(*probFormula);
  90. LOG4CPLUS_WARN(logger, "Done.");
  91. ASSERT_NE(nullptr, result);
  92. ASSERT_LT(std::abs((*result)[31168] - 1), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  93. delete probFormula;
  94. delete result;
  95. apFormula = new storm::property::prctl::Ap<double>("finished");
  96. storm::property::prctl::Ap<double>* apFormula2 = new storm::property::prctl::Ap<double>("all_coins_equal_0");
  97. storm::property::prctl::And<double>* andFormula = new storm::property::prctl::And<double>(apFormula, apFormula2);
  98. eventuallyFormula = new storm::property::prctl::Eventually<double>(andFormula);
  99. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  100. LOG4CPLUS_WARN(logger, "Model Checking Pmin=? [F finished & all_coins_equal_0] on consensus/coin4_6...");
  101. result = mc.checkNoBoundOperator(*probFormula);
  102. LOG4CPLUS_WARN(logger, "Done.");
  103. ASSERT_NE(nullptr, result);
  104. ASSERT_LT(std::abs((*result)[31168] - 0.43742828319177884388579), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  105. delete probFormula;
  106. delete result;
  107. apFormula = new storm::property::prctl::Ap<double>("finished");
  108. apFormula2 = new storm::property::prctl::Ap<double>("all_coins_equal_1");
  109. andFormula = new storm::property::prctl::And<double>(apFormula, apFormula2);
  110. eventuallyFormula = new storm::property::prctl::Eventually<double>(andFormula);
  111. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  112. LOG4CPLUS_WARN(logger, "Model Checking Pmax=? [F finished & all_coins_equal_1] on consensus/coin4_6...");
  113. result = mc.checkNoBoundOperator(*probFormula);
  114. LOG4CPLUS_WARN(logger, "Done.");
  115. ASSERT_NE(nullptr, result);
  116. ASSERT_LT(std::abs((*result)[31168] - 0.52932863686144482340267813924583606421947479248047), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  117. delete probFormula;
  118. delete result;
  119. apFormula = new storm::property::prctl::Ap<double>("finished");
  120. apFormula2 = new storm::property::prctl::Ap<double>("agree");
  121. storm::property::prctl::Not<double>* notFormula = new storm::property::prctl::Not<double>(apFormula2);
  122. andFormula = new storm::property::prctl::And<double>(apFormula, notFormula);
  123. eventuallyFormula = new storm::property::prctl::Eventually<double>(andFormula);
  124. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  125. LOG4CPLUS_WARN(logger, "Model Checking Pmax=? [F finished & !agree] on consensus/coin4_6...");
  126. result = mc.checkNoBoundOperator(*probFormula);
  127. LOG4CPLUS_WARN(logger, "Done.");
  128. ASSERT_NE(nullptr, result);
  129. ASSERT_LT(std::abs((*result)[31168] - 0.1041409700076474653673841), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  130. delete probFormula;
  131. delete result;
  132. apFormula = new storm::property::prctl::Ap<double>("finished");
  133. storm::property::prctl::BoundedEventually<double>* boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 50);
  134. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, true);
  135. LOG4CPLUS_WARN(logger, "Model Checking Pmin=? [F<=50 finished] on consensus/coin4_6...");
  136. result = mc.checkNoBoundOperator(*probFormula);
  137. LOG4CPLUS_WARN(logger, "Done.");
  138. ASSERT_NE(nullptr, result);
  139. ASSERT_LT(std::abs((*result)[31168] - 0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  140. delete probFormula;
  141. delete result;
  142. apFormula = new storm::property::prctl::Ap<double>("finished");
  143. boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 50);
  144. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, false);
  145. LOG4CPLUS_WARN(logger, "Model Checking Pmax=? [F<=50 finished] on consensus/coin4_6...");
  146. result = mc.checkNoBoundOperator(*probFormula);
  147. LOG4CPLUS_WARN(logger, "Done.");
  148. ASSERT_NE(nullptr, result);
  149. ASSERT_LT(std::abs((*result)[31168] - 0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  150. delete probFormula;
  151. delete result;
  152. apFormula = new storm::property::prctl::Ap<double>("finished");
  153. storm::property::prctl::ReachabilityReward<double>* reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  154. storm::property::prctl::RewardNoBoundOperator<double>* rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  155. LOG4CPLUS_WARN(logger, "Model Checking Rmin=? [F finished] on consensus/coin4_6...");
  156. result = mc.checkNoBoundOperator(*rewardFormula);
  157. LOG4CPLUS_WARN(logger, "Done.");
  158. ASSERT_NE(nullptr, result);
  159. ASSERT_LT(std::abs((*result)[31168] - 1725.5933133943854045), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  160. delete rewardFormula;
  161. delete result;
  162. apFormula = new storm::property::prctl::Ap<double>("finished");
  163. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  164. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  165. LOG4CPLUS_WARN(logger, "Model Checking Rmax=? [F finished] on consensus/coin4_6...");
  166. result = mc.checkNoBoundOperator(*rewardFormula);
  167. LOG4CPLUS_WARN(logger, "Done.");
  168. ASSERT_NE(nullptr, result);
  169. ASSERT_LT(std::abs((*result)[31168] - 2183.1424220082612919213715), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  170. delete rewardFormula;
  171. delete result;
  172. }