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.

245 lines
11 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/utility/Settings.h"
  4. #include "src/modelchecker/prctl/GmmxxMdpPrctlModelChecker.h"
  5. #include "src/parser/AutoParser.h"
  6. TEST(GmmxxMdpPrctlModelCheckerTest, 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::GmmxxMdpPrctlModelChecker<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(GmmxxMdpPrctlModelCheckerTest, Consensus) {
  75. storm::settings::Settings* s = storm::settings::instance();
  76. s->set<unsigned>("maxiter", 20000);
  77. 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", "");
  78. ASSERT_EQ(parser.getType(), storm::models::MDP);
  79. std::shared_ptr<storm::models::Mdp<double>> mdp = parser.getModel<storm::models::Mdp<double>>();
  80. ASSERT_EQ(mdp->getNumberOfStates(), 63616u);
  81. ASSERT_EQ(mdp->getNumberOfTransitions(), 213472u);
  82. storm::modelchecker::prctl::GmmxxMdpPrctlModelChecker<double> mc(*mdp);
  83. storm::property::prctl::Ap<double>* apFormula = new storm::property::prctl::Ap<double>("finished");
  84. storm::property::prctl::Eventually<double>* eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  85. storm::property::prctl::ProbabilisticNoBoundOperator<double>* probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  86. LOG4CPLUS_WARN(logger, "Model Checking Pmin=? [F finished] on consensus/coin4_6...");
  87. std::vector<double>* result = mc.checkNoBoundOperator(*probFormula);
  88. LOG4CPLUS_WARN(logger, "Done.");
  89. ASSERT_NE(nullptr, result);
  90. ASSERT_LT(std::abs((*result)[31168] - 1), s->get<double>("precision"));
  91. delete probFormula;
  92. delete result;
  93. apFormula = new storm::property::prctl::Ap<double>("finished");
  94. storm::property::prctl::Ap<double>* apFormula2 = new storm::property::prctl::Ap<double>("all_coins_equal_0");
  95. storm::property::prctl::And<double>* andFormula = new storm::property::prctl::And<double>(apFormula, apFormula2);
  96. eventuallyFormula = new storm::property::prctl::Eventually<double>(andFormula);
  97. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  98. LOG4CPLUS_WARN(logger, "Model Checking Pmin=? [F finished & all_coins_equal_0] on consensus/coin4_6...");
  99. result = mc.checkNoBoundOperator(*probFormula);
  100. LOG4CPLUS_WARN(logger, "Done.");
  101. ASSERT_NE(nullptr, result);
  102. ASSERT_LT(std::abs((*result)[31168] - 0.43742828319177884388579), s->get<double>("precision"));
  103. delete probFormula;
  104. delete result;
  105. apFormula = new storm::property::prctl::Ap<double>("finished");
  106. apFormula2 = new storm::property::prctl::Ap<double>("all_coins_equal_1");
  107. andFormula = new storm::property::prctl::And<double>(apFormula, apFormula2);
  108. eventuallyFormula = new storm::property::prctl::Eventually<double>(andFormula);
  109. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  110. LOG4CPLUS_WARN(logger, "Model Checking Pmax=? [F finished & all_coins_equal_1] on consensus/coin4_6...");
  111. result = mc.checkNoBoundOperator(*probFormula);
  112. LOG4CPLUS_WARN(logger, "Done.");
  113. ASSERT_NE(nullptr, result);
  114. ASSERT_LT(std::abs((*result)[31168] - 0.52932863686144482340267813924583606421947479248047), s->get<double>("precision"));
  115. delete probFormula;
  116. delete result;
  117. apFormula = new storm::property::prctl::Ap<double>("finished");
  118. apFormula2 = new storm::property::prctl::Ap<double>("agree");
  119. storm::property::prctl::Not<double>* notFormula = new storm::property::prctl::Not<double>(apFormula2);
  120. andFormula = new storm::property::prctl::And<double>(apFormula, notFormula);
  121. eventuallyFormula = new storm::property::prctl::Eventually<double>(andFormula);
  122. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  123. LOG4CPLUS_WARN(logger, "Model Checking Pmax=? [F finished & !agree] on consensus/coin4_6...");
  124. result = mc.checkNoBoundOperator(*probFormula);
  125. LOG4CPLUS_WARN(logger, "Done.");
  126. ASSERT_NE(nullptr, result);
  127. ASSERT_LT(std::abs((*result)[31168] - 0.1041409700076474653673841), s->get<double>("precision"));
  128. delete probFormula;
  129. delete result;
  130. apFormula = new storm::property::prctl::Ap<double>("finished");
  131. storm::property::prctl::BoundedEventually<double>* boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 50);
  132. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, true);
  133. LOG4CPLUS_WARN(logger, "Model Checking Pmin=? [F<=50 finished] on consensus/coin4_6...");
  134. result = mc.checkNoBoundOperator(*probFormula);
  135. LOG4CPLUS_WARN(logger, "Done.");
  136. ASSERT_NE(nullptr, result);
  137. ASSERT_LT(std::abs((*result)[31168] - 0), s->get<double>("precision"));
  138. delete probFormula;
  139. delete result;
  140. apFormula = new storm::property::prctl::Ap<double>("finished");
  141. boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 50);
  142. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, false);
  143. LOG4CPLUS_WARN(logger, "Model Checking Pmax=? [F<=50 finished] on consensus/coin4_6...");
  144. result = mc.checkNoBoundOperator(*probFormula);
  145. LOG4CPLUS_WARN(logger, "Done.");
  146. ASSERT_NE(nullptr, result);
  147. ASSERT_LT(std::abs((*result)[31168] - 0), s->get<double>("precision"));
  148. delete probFormula;
  149. delete result;
  150. apFormula = new storm::property::prctl::Ap<double>("finished");
  151. storm::property::prctl::ReachabilityReward<double>* reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  152. storm::property::prctl::RewardNoBoundOperator<double>* rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  153. LOG4CPLUS_WARN(logger, "Model Checking Rmin=? [F finished] on consensus/coin4_6...");
  154. result = mc.checkNoBoundOperator(*rewardFormula);
  155. LOG4CPLUS_WARN(logger, "Done.");
  156. ASSERT_NE(nullptr, result);
  157. ASSERT_LT(std::abs((*result)[31168] - 1725.5933133943854045), s->get<double>("precision"));
  158. delete rewardFormula;
  159. delete result;
  160. apFormula = new storm::property::prctl::Ap<double>("finished");
  161. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  162. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  163. LOG4CPLUS_WARN(logger, "Model Checking Rmax=? [F finished] on consensus/coin4_6...");
  164. result = mc.checkNoBoundOperator(*rewardFormula);
  165. LOG4CPLUS_WARN(logger, "Done.");
  166. ASSERT_NE(nullptr, result);
  167. ASSERT_LT(std::abs((*result)[31168] - 2183.1424220082612919213715), s->get<double>("precision"));
  168. delete rewardFormula;
  169. delete result;
  170. }