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.

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