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.

230 lines
12 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  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/parser/AutoParser.h"
  6. TEST(SparseMdpPrctlModelCheckerTest, Dice) {
  7. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  8. storm::parser::AutoParser<double> parser(STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.tra", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.lab", "", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.flip.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(), 169ull);
  12. ASSERT_EQ(mdp->getNumberOfTransitions(), 436ull);
  13. storm::modelchecker::prctl::SparseMdpPrctlModelChecker<double> mc(*mdp, new storm::solver::AbstractNondeterministicLinearEquationSolver<double>());
  14. storm::property::prctl::Ap<double>* apFormula = new storm::property::prctl::Ap<double>("two");
  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. std::vector<double> result = mc.checkNoBoundOperator(*probFormula);
  18. ASSERT_LT(std::abs(result[0] - 0.0277777612209320068), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  19. delete probFormula;
  20. apFormula = new storm::property::prctl::Ap<double>("two");
  21. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  22. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  23. result = mc.checkNoBoundOperator(*probFormula);
  24. ASSERT_LT(std::abs(result[0] - 0.0277777612209320068), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  25. delete probFormula;
  26. apFormula = new storm::property::prctl::Ap<double>("three");
  27. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  28. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  29. result = mc.checkNoBoundOperator(*probFormula);
  30. ASSERT_LT(std::abs(result[0] - 0.0555555224418640136), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  31. delete probFormula;
  32. apFormula = new storm::property::prctl::Ap<double>("three");
  33. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  34. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  35. result = mc.checkNoBoundOperator(*probFormula);
  36. ASSERT_LT(std::abs(result[0] - 0.0555555224418640136), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  37. delete probFormula;
  38. apFormula = new storm::property::prctl::Ap<double>("four");
  39. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  40. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  41. result = mc.checkNoBoundOperator(*probFormula);
  42. ASSERT_LT(std::abs(result[0] - 0.083333283662796020508), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  43. delete probFormula;
  44. apFormula = new storm::property::prctl::Ap<double>("four");
  45. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  46. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  47. result = mc.checkNoBoundOperator(*probFormula);
  48. ASSERT_LT(std::abs(result[0] - 0.083333283662796020508), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  49. delete probFormula;
  50. apFormula = new storm::property::prctl::Ap<double>("done");
  51. storm::property::prctl::ReachabilityReward<double>* reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  52. storm::property::prctl::RewardNoBoundOperator<double>* rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  53. result = mc.checkNoBoundOperator(*rewardFormula);
  54. ASSERT_LT(std::abs(result[0] - 7.3333294987678527832), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  55. delete rewardFormula;
  56. apFormula = new storm::property::prctl::Ap<double>("done");
  57. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  58. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  59. result = mc.checkNoBoundOperator(*rewardFormula);;
  60. ASSERT_LT(std::abs(result[0] - 7.3333294987678527832), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  61. delete rewardFormula;
  62. storm::parser::AutoParser<double> stateRewardParser(STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.tra", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.lab", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.flip.state.rew", "");
  63. ASSERT_EQ(stateRewardParser.getType(), storm::models::MDP);
  64. std::shared_ptr<storm::models::Mdp<double>> stateRewardMdp = stateRewardParser.getModel<storm::models::Mdp<double>>();
  65. storm::modelchecker::prctl::SparseMdpPrctlModelChecker<double> stateRewardModelChecker(*stateRewardMdp, new storm::solver::AbstractNondeterministicLinearEquationSolver<double>());
  66. apFormula = new storm::property::prctl::Ap<double>("done");
  67. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  68. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  69. result = stateRewardModelChecker.checkNoBoundOperator(*rewardFormula);
  70. ASSERT_LT(std::abs(result[0] - 7.3333294987678527832), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  71. delete rewardFormula;
  72. apFormula = new storm::property::prctl::Ap<double>("done");
  73. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  74. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  75. result = stateRewardModelChecker.checkNoBoundOperator(*rewardFormula);
  76. ASSERT_LT(std::abs(result[0] - 7.3333294987678527832), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  77. delete rewardFormula;
  78. storm::parser::AutoParser<double> stateAndTransitionRewardParser(STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.tra", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.lab", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.flip.state.rew", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.flip.trans.rew");
  79. ASSERT_EQ(stateAndTransitionRewardParser.getType(), storm::models::MDP);
  80. std::shared_ptr<storm::models::Mdp<double>> stateAndTransitionRewardMdp = stateAndTransitionRewardParser.getModel<storm::models::Mdp<double>>();
  81. storm::modelchecker::prctl::SparseMdpPrctlModelChecker<double> stateAndTransitionRewardModelChecker(*stateAndTransitionRewardMdp, new storm::solver::AbstractNondeterministicLinearEquationSolver<double>());
  82. apFormula = new storm::property::prctl::Ap<double>("done");
  83. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  84. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  85. result = stateAndTransitionRewardModelChecker.checkNoBoundOperator(*rewardFormula);
  86. ASSERT_LT(std::abs(result[0] - (2 * 7.3333294987678527832)), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  87. delete rewardFormula;
  88. apFormula = new storm::property::prctl::Ap<double>("done");
  89. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  90. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  91. result = stateAndTransitionRewardModelChecker.checkNoBoundOperator(*rewardFormula);
  92. ASSERT_LT(std::abs(result[0] - (2 * 7.3333294987678527832)), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  93. delete rewardFormula;
  94. }
  95. TEST(SparseMdpPrctlModelCheckerTest, AsynchronousLeader) {
  96. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  97. storm::parser::AutoParser<double> parser(STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader4.tra", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader4.lab", "", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader4.trans.rew");
  98. ASSERT_EQ(parser.getType(), storm::models::MDP);
  99. std::shared_ptr<storm::models::Mdp<double>> mdp = parser.getModel<storm::models::Mdp<double>>();
  100. ASSERT_EQ(mdp->getNumberOfStates(), 3172ull);
  101. ASSERT_EQ(mdp->getNumberOfTransitions(), 7144ull);
  102. storm::modelchecker::prctl::SparseMdpPrctlModelChecker<double> mc(*mdp, new storm::solver::AbstractNondeterministicLinearEquationSolver<double>());
  103. storm::property::prctl::Ap<double>* apFormula = new storm::property::prctl::Ap<double>("elected");
  104. storm::property::prctl::Eventually<double>* eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  105. storm::property::prctl::ProbabilisticNoBoundOperator<double>* probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, true);
  106. std::vector<double> result = mc.checkNoBoundOperator(*probFormula);
  107. ASSERT_LT(std::abs(result[0] - 1), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  108. delete probFormula;
  109. apFormula = new storm::property::prctl::Ap<double>("elected");
  110. eventuallyFormula = new storm::property::prctl::Eventually<double>(apFormula);
  111. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(eventuallyFormula, false);
  112. result = mc.checkNoBoundOperator(*probFormula);
  113. ASSERT_LT(std::abs(result[0] - 1), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  114. delete probFormula;
  115. apFormula = new storm::property::prctl::Ap<double>("elected");
  116. storm::property::prctl::BoundedEventually<double>* boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 25);
  117. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, false);
  118. result = mc.checkNoBoundOperator(*probFormula);
  119. ASSERT_LT(std::abs(result[0] - 0.0625), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  120. delete probFormula;
  121. apFormula = new storm::property::prctl::Ap<double>("elected");
  122. boundedEventuallyFormula = new storm::property::prctl::BoundedEventually<double>(apFormula, 25);
  123. probFormula = new storm::property::prctl::ProbabilisticNoBoundOperator<double>(boundedEventuallyFormula, true);
  124. result = mc.checkNoBoundOperator(*probFormula);
  125. ASSERT_LT(std::abs(result[0] - 0.0625), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  126. delete probFormula;
  127. apFormula = new storm::property::prctl::Ap<double>("elected");
  128. storm::property::prctl::ReachabilityReward<double>* reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  129. storm::property::prctl::RewardNoBoundOperator<double>* rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, true);
  130. result = mc.checkNoBoundOperator(*rewardFormula);;
  131. ASSERT_LT(std::abs(result[0] - 4.28568908480604982), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  132. delete rewardFormula;
  133. apFormula = new storm::property::prctl::Ap<double>("elected");
  134. reachabilityRewardFormula = new storm::property::prctl::ReachabilityReward<double>(apFormula);
  135. rewardFormula = new storm::property::prctl::RewardNoBoundOperator<double>(reachabilityRewardFormula, false);
  136. result = mc.checkNoBoundOperator(*rewardFormula);;
  137. ASSERT_LT(std::abs(result[0] - 4.2856904354441400784), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  138. delete rewardFormula;
  139. }