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.

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