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.

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