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.

243 lines
11 KiB

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