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.

162 lines
9.3 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/settings/Settings.h"
  4. #include "src/modelchecker/prctl/TopologicalValueIterationMdpPrctlModelChecker.h"
  5. #include "src/solver/NativeNondeterministicLinearEquationSolver.h"
  6. #include "src/parser/AutoParser.h"
  7. TEST(TopologicalValueIterationMdpPrctlModelCheckerTest, AsynchronousLeader) {
  8. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  9. std::shared_ptr<storm::models::Mdp<double>> mdp = storm::parser::AutoParser::parseModel(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")->as<storm::models::Mdp<double>>();
  10. ASSERT_EQ(mdp->getNumberOfStates(), 2095783ull);
  11. ASSERT_EQ(mdp->getNumberOfTransitions(), 7714385ull);
  12. storm::modelchecker::prctl::TopologicalValueIterationMdpPrctlModelChecker<double> mc(*mdp);
  13. storm::property::prctl::Ap<double>* apFormula = new storm::property::prctl::Ap<double>("elected");
  14. storm::property::prctl::Eventually<double>* eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  15. storm::property::prctl::ProbabilisticNoBoundOperator<double>* probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  16. std::vector<double> result = mc.checkNoBoundOperator(*probFormula);
  17. ASSERT_LT(std::abs(result[0] - 1.0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  18. delete probFormula;
  19. apFormula = new storm::property::prctl::Ap<double>("elected");
  20. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  21. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  22. result = mc.checkNoBoundOperator(*probFormula);
  23. ASSERT_LT(std::abs(result[0] - 1.0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  24. delete probFormula;
  25. apFormula = new storm::property::prctl::Ap<double>("elected");
  26. storm::property::prctl::BoundedEventually<double>* boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 25);
  27. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, true);
  28. result = mc.checkNoBoundOperator(*probFormula);
  29. ASSERT_LT(std::abs(result[0] - 0.0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  30. delete probFormula;
  31. apFormula = new storm::property::prctl::Ap<double>("elected");
  32. boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 25);
  33. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, false);
  34. result = mc.checkNoBoundOperator(*probFormula);
  35. ASSERT_LT(std::abs(result[0] - 0.0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  36. delete probFormula;
  37. apFormula = new storm::property::prctl::Ap<double>("elected");
  38. storm::property::prctl::ReachabilityReward<double>* reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  39. storm::property::prctl::RewardNoBoundOperator<double>* rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  40. result = mc.checkNoBoundOperator(*rewardFormula);
  41. ASSERT_LT(std::abs(result[0] - 6.172433512), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  42. delete rewardFormula;
  43. apFormula = new storm::property::prctl::Ap<double>("elected");
  44. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  45. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  46. result = mc.checkNoBoundOperator(*rewardFormula);
  47. ASSERT_LT(std::abs(result[0] - 6.1724344), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  48. delete rewardFormula;
  49. }
  50. TEST(TopologicalValueIterationMdpPrctlModelCheckerTest, Consensus) {
  51. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  52. // Increase the maximal number of iterations, because the solver does not converge otherwise.
  53. // This is done in the main cpp unit
  54. std::shared_ptr<storm::models::Mdp<double>> mdp = storm::parser::AutoParser::parseModel(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", "")->as<storm::models::Mdp<double>>();
  55. ASSERT_EQ(mdp->getNumberOfStates(), 63616ull);
  56. ASSERT_EQ(mdp->getNumberOfTransitions(), 213472ull);
  57. storm::modelchecker::prctl::TopologicalValueIterationMdpPrctlModelChecker<double> mc(*mdp);
  58. storm::property::prctl::Ap<double>* apFormula = new storm::property::prctl::Ap<double>("finished");
  59. storm::property::prctl::Eventually<double>* eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  60. storm::property::prctl::ProbabilisticNoBoundOperator<double>* probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  61. std::vector<double> result = mc.checkNoBoundOperator(*probFormula);
  62. ASSERT_LT(std::abs(result[31168] - 1.0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  63. delete probFormula;
  64. apFormula = new storm::property::prctl::Ap<double>("finished");
  65. storm::property::prctl::Ap<double>* apFormula2 = new storm::property::prctl::Ap<double>("all_coins_equal_0");
  66. storm::property::prctl::And<double>* andFormula = new storm::property::prctl::And<double>(apFormula, apFormula2);
  67. eventuallyFormula = new storm::property::prctl::Eventually<double>(andFormula);
  68. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  69. result = mc.checkNoBoundOperator(*probFormula);
  70. ASSERT_LT(std::abs(result[31168] - 0.4374282832), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  71. delete probFormula;
  72. apFormula = new storm::property::prctl::Ap<double>("finished");
  73. apFormula2 = new storm::property::prctl::Ap<double>("all_coins_equal_1");
  74. andFormula = new storm::property::prctl::And<double>(apFormula, apFormula2);
  75. eventuallyFormula = new storm::property::prctl::Eventually<double>(andFormula);
  76. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  77. result = mc.checkNoBoundOperator(*probFormula);
  78. ASSERT_LT(std::abs(result[31168] - 0.5293286369), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  79. delete probFormula;
  80. apFormula = new storm::property::prctl::Ap<double>("finished");
  81. apFormula2 = new storm::property::prctl::Ap<double>("agree");
  82. storm::property::prctl::Not<double>* notFormula = new storm::property::prctl::Not<double>(apFormula2);
  83. andFormula = new storm::property::prctl::And<double>(apFormula, notFormula);
  84. eventuallyFormula = new storm::property::prctl::Eventually<double>(andFormula);
  85. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  86. result = mc.checkNoBoundOperator(*probFormula);
  87. ASSERT_LT(std::abs(result[31168] - 0.10414097), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  88. delete probFormula;
  89. apFormula = new storm::property::prctl::Ap<double>("finished");
  90. storm::property::prctl::BoundedEventually<double>* boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 50ull);
  91. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, true);
  92. result = mc.checkNoBoundOperator(*probFormula);
  93. ASSERT_LT(std::abs(result[31168] - 0.0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  94. delete probFormula;
  95. apFormula = new storm::property::prctl::Ap<double>("finished");
  96. boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 50ull);
  97. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, false);
  98. result = mc.checkNoBoundOperator(*probFormula);
  99. ASSERT_LT(std::abs(result[31168] - 0.0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  100. delete probFormula;
  101. apFormula = new storm::property::prctl::Ap<double>("finished");
  102. storm::property::prctl::ReachabilityReward<double>* reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  103. storm::property::prctl::RewardNoBoundOperator<double>* rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  104. result = mc.checkNoBoundOperator(*rewardFormula);
  105. ASSERT_LT(std::abs(result[31168] - 1725.593313), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  106. delete rewardFormula;
  107. apFormula = new storm::property::prctl::Ap<double>("finished");
  108. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  109. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  110. result = mc.checkNoBoundOperator(*rewardFormula);
  111. ASSERT_LT(std::abs(result[31168] - 2183.142422), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  112. delete rewardFormula;
  113. }