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.

177 lines
11 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/modelchecker/prctl/SparseMdpPrctlModelChecker.h"
  4. #include "src/utility/solver.h"
  5. #include "src/modelchecker/results/ExplicitQuantitativeCheckResult.h"
  6. #include "src/settings/SettingsManager.h"
  7. #include "src/settings/SettingMemento.h"
  8. #include "src/parser/AutoParser.h"
  9. TEST(DISABLED_TopologicalValueIterationMdpPrctlModelCheckerTest, AsynchronousLeader) {
  10. std::shared_ptr<storm::models::sparse::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::sparse::Mdp<double>>();
  11. ASSERT_EQ(mdp->getNumberOfStates(), 2095783ull);
  12. ASSERT_EQ(mdp->getNumberOfTransitions(), 7714385ull);
  13. storm::modelchecker::SparseMdpPrctlModelChecker<double> mc(*mdp, std::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::TopologicalMinMaxLinearEquationSolverFactory<double>()));
  14. auto apFormula = std::make_shared<storm::logic::AtomicLabelFormula>("elected");
  15. auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(apFormula);
  16. auto probFormula = std::make_shared<storm::logic::ProbabilityOperatorFormula>(storm::logic::OptimalityType::Minimize, eventuallyFormula);
  17. std::unique_ptr<storm::modelchecker::CheckResult> result = mc.check(*probFormula);
  18. ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult<double>()[0] - 1.0),
  19. storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  20. probFormula.reset();
  21. apFormula = std::make_shared<storm::logic::AtomicLabelFormula>("elected");
  22. eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(apFormula);
  23. probFormula = std::make_shared<storm::logic::ProbabilityOperatorFormula>(storm::logic::OptimalityType::Maximize, eventuallyFormula);
  24. result = mc.check(*probFormula);
  25. ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult<double>()[0] - 1.0),
  26. storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  27. probFormula.reset();
  28. apFormula = std::make_shared<storm::logic::AtomicLabelFormula>("elected");
  29. auto boundedEventuallyFormula = std::make_shared<storm::logic::BoundedUntilFormula>(std::make_shared<storm::logic::BooleanLiteralFormula>(true), apFormula, 25);
  30. probFormula = std::make_shared<storm::logic::ProbabilityOperatorFormula>(storm::logic::OptimalityType::Minimize, boundedEventuallyFormula);
  31. result = mc.check(*probFormula);
  32. ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult<double>()[0] - 0.0),
  33. storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  34. probFormula.reset();
  35. apFormula = std::make_shared<storm::logic::AtomicLabelFormula>("elected");
  36. boundedEventuallyFormula = std::make_shared<storm::logic::BoundedUntilFormula>(std::make_shared<storm::logic::BooleanLiteralFormula>(true), apFormula, 25);
  37. probFormula = std::make_shared<storm::logic::ProbabilityOperatorFormula>(storm::logic::OptimalityType::Maximize, boundedEventuallyFormula);
  38. result = mc.check(*probFormula);
  39. ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult<double>()[0] - 0.0),
  40. storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  41. probFormula.reset();
  42. apFormula = std::make_shared<storm::logic::AtomicLabelFormula>("elected");
  43. auto reachabilityRewardFormula = std::make_shared<storm::logic::ReachabilityRewardFormula>(apFormula);
  44. auto rewardFormula = std::make_shared<storm::logic::RewardOperatorFormula>(storm::logic::OptimalityType::Minimize, reachabilityRewardFormula);
  45. result = mc.check(*rewardFormula);
  46. ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult<double>()[0] - 6.172433512),
  47. storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  48. rewardFormula.reset();
  49. apFormula = std::make_shared<storm::logic::AtomicLabelFormula>("elected");
  50. reachabilityRewardFormula = std::make_shared<storm::logic::ReachabilityRewardFormula>(apFormula);
  51. rewardFormula = std::make_shared<storm::logic::RewardOperatorFormula>(storm::logic::OptimalityType::Maximize, reachabilityRewardFormula);
  52. result = mc.check(*rewardFormula);
  53. ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult<double>()[0] - 6.1724344),
  54. storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  55. rewardFormula.reset();
  56. }
  57. TEST(DISABLED_TopologicalValueIterationMdpPrctlModelCheckerTest, Consensus) {
  58. // Increase the maximal number of iterations, because the solver does not converge otherwise.
  59. // This is done in the main cpp unit
  60. std::shared_ptr<storm::models::sparse::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::sparse::Mdp<double>>();
  61. ASSERT_EQ(mdp->getNumberOfStates(), 63616ull);
  62. ASSERT_EQ(mdp->getNumberOfTransitions(), 213472ull);
  63. storm::modelchecker::SparseMdpPrctlModelChecker<double> mc(*mdp, std::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::TopologicalMinMaxLinearEquationSolverFactory<double>()));
  64. auto apFormula = std::make_shared<storm::logic::AtomicLabelFormula>("finished");
  65. auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(apFormula);
  66. auto probFormula = std::make_shared<storm::logic::ProbabilityOperatorFormula>(storm::logic::OptimalityType::Minimize, eventuallyFormula);
  67. auto result = mc.check(*probFormula);
  68. ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult<double>()[31168] - 1.0),
  69. storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  70. probFormula.reset();
  71. apFormula = std::make_shared<storm::logic::AtomicLabelFormula>("finished");
  72. auto apFormula2 = std::make_shared<storm::logic::AtomicLabelFormula>("all_coins_equal_0");
  73. auto andFormula = std::make_shared<storm::logic::BinaryBooleanStateFormula>(storm::logic::BinaryBooleanStateFormula::OperatorType::And, apFormula, apFormula2);
  74. eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(andFormula);
  75. probFormula = std::make_shared<storm::logic::ProbabilityOperatorFormula>(storm::logic::OptimalityType::Minimize, eventuallyFormula);
  76. result = mc.check(*probFormula);
  77. ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult<double>()[31168] - 0.4374282832),
  78. storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  79. probFormula.reset();
  80. apFormula = std::make_shared<storm::logic::AtomicLabelFormula>("finished");
  81. apFormula2 = std::make_shared<storm::logic::AtomicLabelFormula>("all_coins_equal_1");
  82. andFormula = std::make_shared<storm::logic::BinaryBooleanStateFormula>(storm::logic::BinaryBooleanStateFormula::OperatorType::And, apFormula, apFormula2);
  83. eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(andFormula);
  84. probFormula = std::make_shared<storm::logic::ProbabilityOperatorFormula>(storm::logic::OptimalityType::Maximize, eventuallyFormula);
  85. result = mc.check(*probFormula);
  86. ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult<double>()[31168] - 0.5293286369),
  87. storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  88. probFormula.reset();
  89. apFormula = std::make_shared<storm::logic::AtomicLabelFormula>("finished");
  90. apFormula2 = std::make_shared<storm::logic::AtomicLabelFormula>("agree");
  91. auto notFormula = std::make_shared<storm::logic::UnaryBooleanStateFormula>(storm::logic::UnaryBooleanStateFormula::OperatorType::Not, apFormula2);
  92. andFormula = std::make_shared<storm::logic::BinaryBooleanStateFormula>(storm::logic::BinaryBooleanStateFormula::OperatorType::And, apFormula, notFormula);
  93. eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(andFormula);
  94. probFormula = std::make_shared<storm::logic::ProbabilityOperatorFormula>(storm::logic::OptimalityType::Maximize, eventuallyFormula);
  95. result = mc.check(*probFormula);
  96. ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult<double>()[31168] - 0.10414097),
  97. storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  98. probFormula.reset();
  99. apFormula = std::make_shared<storm::logic::AtomicLabelFormula>("finished");
  100. auto boundedEventuallyFormula = std::make_shared<storm::logic::BoundedUntilFormula>(std::make_shared<storm::logic::BooleanLiteralFormula>(true), apFormula, 50ull);
  101. probFormula = std::make_shared<storm::logic::ProbabilityOperatorFormula>(storm::logic::OptimalityType::Minimize, eventuallyFormula);
  102. result = mc.check(*probFormula);
  103. ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult<double>()[31168] - 0.0),
  104. storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  105. probFormula.reset();
  106. apFormula = std::make_shared<storm::logic::AtomicLabelFormula>("finished");
  107. boundedEventuallyFormula = std::make_shared<storm::logic::BoundedUntilFormula>(std::make_shared<storm::logic::BooleanLiteralFormula>(true), apFormula, 50ull);
  108. probFormula = std::make_shared<storm::logic::ProbabilityOperatorFormula>(storm::logic::OptimalityType::Maximize, eventuallyFormula);
  109. result = mc.check(*probFormula);
  110. ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult<double>()[31168] - 0.0),
  111. storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  112. probFormula.reset();
  113. apFormula = std::make_shared<storm::logic::AtomicLabelFormula>("finished");
  114. auto reachabilityRewardFormula = std::make_shared<storm::logic::ReachabilityRewardFormula>(apFormula);
  115. auto rewardFormula = std::make_shared<storm::logic::RewardOperatorFormula>(storm::logic::OptimalityType::Minimize, reachabilityRewardFormula);
  116. result = mc.check(*rewardFormula);
  117. ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult<double>()[31168] - 1725.593313),
  118. storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  119. probFormula.reset();
  120. apFormula = std::make_shared<storm::logic::AtomicLabelFormula>("finished");
  121. reachabilityRewardFormula = std::make_shared<storm::logic::ReachabilityRewardFormula>(apFormula);
  122. rewardFormula = std::make_shared<storm::logic::RewardOperatorFormula>(storm::logic::OptimalityType::Maximize, reachabilityRewardFormula);
  123. result = mc.check(*rewardFormula);
  124. ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult<double>()[31168] - 2183.142422),
  125. storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  126. probFormula.reset();
  127. }