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.

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