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.

144 lines
8.7 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/logic/Formulas.h"
  4. #include "src/solver/GmmxxLinearEquationSolver.h"
  5. #include "src/modelchecker/reachability/SparseDtmcEliminationModelChecker.h"
  6. #include "src/modelchecker/ExplicitQuantitativeCheckResult.h"
  7. #include "src/settings/SettingsManager.h"
  8. #include "src/settings/SettingMemento.h"
  9. #include "src/parser/AutoParser.h"
  10. TEST(SparseDtmcEliminationModelCheckerTest, Die) {
  11. std::shared_ptr<storm::models::AbstractModel<double>> abstractModel = storm::parser::AutoParser::parseModel(STORM_CPP_BASE_PATH "/examples/dtmc/die/die.tra", STORM_CPP_BASE_PATH "/examples/dtmc/die/die.lab", "", STORM_CPP_BASE_PATH "/examples/dtmc/die/die.coin_flips.trans.rew");
  12. ASSERT_EQ(abstractModel->getType(), storm::models::DTMC);
  13. std::shared_ptr<storm::models::Dtmc<double>> dtmc = abstractModel->as<storm::models::Dtmc<double>>();
  14. ASSERT_EQ(dtmc->getNumberOfStates(), 13ull);
  15. ASSERT_EQ(dtmc->getNumberOfTransitions(), 20ull);
  16. storm::modelchecker::SparseDtmcEliminationModelChecker<double> checker(*dtmc);
  17. auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("one");
  18. auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  19. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*eventuallyFormula);
  20. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  21. EXPECT_NEAR(1.0/6.0, quantitativeResult1[0], storm::settings::gmmxxEquationSolverSettings().getPrecision());
  22. labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("two");
  23. eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  24. result = checker.check(*eventuallyFormula);
  25. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  26. EXPECT_NEAR(1.0/6.0, quantitativeResult2[0], storm::settings::gmmxxEquationSolverSettings().getPrecision());
  27. labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("three");
  28. eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  29. result = checker.check(*eventuallyFormula);
  30. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  31. EXPECT_NEAR(1.0/6.0, quantitativeResult3[0], storm::settings::gmmxxEquationSolverSettings().getPrecision());
  32. auto done = std::make_shared<storm::logic::AtomicLabelFormula>("done");
  33. auto reachabilityRewardFormula = std::make_shared<storm::logic::ReachabilityRewardFormula>(done);
  34. result = checker.check(*reachabilityRewardFormula);
  35. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  36. EXPECT_NEAR(11.0/3.0, quantitativeResult4[0], storm::settings::gmmxxEquationSolverSettings().getPrecision());
  37. }
  38. TEST(SparseDtmcEliminationModelCheckerTest, Crowds) {
  39. std::shared_ptr<storm::models::AbstractModel<double>> abstractModel = storm::parser::AutoParser::parseModel(STORM_CPP_BASE_PATH "/examples/dtmc/crowds/crowds5_5.tra", STORM_CPP_BASE_PATH "/examples/dtmc/crowds/crowds5_5.lab", "", "");
  40. ASSERT_EQ(abstractModel->getType(), storm::models::DTMC);
  41. std::shared_ptr<storm::models::Dtmc<double>> dtmc = abstractModel->as<storm::models::Dtmc<double>>();
  42. ASSERT_EQ(8607ull, dtmc->getNumberOfStates());
  43. ASSERT_EQ(15113ull, dtmc->getNumberOfTransitions());
  44. storm::modelchecker::SparseDtmcEliminationModelChecker<double> checker(*dtmc);
  45. auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("observe0Greater1");
  46. auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  47. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*eventuallyFormula);
  48. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  49. EXPECT_NEAR(0.3328800375801578281, quantitativeResult1[0], storm::settings::gmmxxEquationSolverSettings().getPrecision());
  50. labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("observeIGreater1");
  51. eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  52. result = checker.check(*eventuallyFormula);
  53. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  54. EXPECT_NEAR(0.1522194965, quantitativeResult2[0], storm::settings::gmmxxEquationSolverSettings().getPrecision());
  55. labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("observeOnlyTrueSender");
  56. eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  57. result = checker.check(*eventuallyFormula);
  58. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  59. EXPECT_NEAR(0.32153724292835045, quantitativeResult3[0], storm::settings::gmmxxEquationSolverSettings().getPrecision());
  60. labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("observe0Greater1");
  61. eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  62. auto labelFormula2 = std::make_shared<storm::logic::AtomicLabelFormula>("observeIGreater1");
  63. auto eventuallyFormula2 = std::make_shared<storm::logic::EventuallyFormula>(labelFormula2);
  64. auto conditionalFormula = std::make_shared<storm::logic::ConditionalPathFormula>(eventuallyFormula, eventuallyFormula2);
  65. result = checker.check(*conditionalFormula);
  66. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  67. EXPECT_NEAR(0.15330064292476167, quantitativeResult4[0], storm::settings::gmmxxEquationSolverSettings().getPrecision());
  68. labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("observeOnlyTrueSender");
  69. eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  70. labelFormula2 = std::make_shared<storm::logic::AtomicLabelFormula>("observe0Greater1");
  71. eventuallyFormula2 = std::make_shared<storm::logic::EventuallyFormula>(labelFormula2);
  72. conditionalFormula = std::make_shared<storm::logic::ConditionalPathFormula>(eventuallyFormula, eventuallyFormula2);
  73. result = checker.check(*conditionalFormula);
  74. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult5 = result->asExplicitQuantitativeCheckResult<double>();
  75. EXPECT_NEAR(0.96592521978041668, quantitativeResult5[0], storm::settings::gmmxxEquationSolverSettings().getPrecision());
  76. }
  77. TEST(SparseDtmcEliminationModelCheckerTest, SynchronousLeader) {
  78. std::shared_ptr<storm::models::AbstractModel<double>> abstractModel = storm::parser::AutoParser::parseModel(STORM_CPP_BASE_PATH "/examples/dtmc/synchronous_leader/leader4_8.tra", STORM_CPP_BASE_PATH "/examples/dtmc/synchronous_leader/leader4_8.lab", "", STORM_CPP_BASE_PATH "/examples/dtmc/synchronous_leader/leader4_8.pick.trans.rew");
  79. ASSERT_EQ(abstractModel->getType(), storm::models::DTMC);
  80. std::shared_ptr<storm::models::Dtmc<double>> dtmc = abstractModel->as<storm::models::Dtmc<double>>();
  81. ASSERT_EQ(12400ull, dtmc->getNumberOfStates());
  82. ASSERT_EQ(16495ull, dtmc->getNumberOfTransitions());
  83. storm::modelchecker::SparseDtmcEliminationModelChecker<double> checker(*dtmc);
  84. auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("elected");
  85. auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  86. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*eventuallyFormula);
  87. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  88. EXPECT_NEAR(1.0, quantitativeResult1[0], storm::settings::gmmxxEquationSolverSettings().getPrecision());
  89. labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("elected");
  90. auto reachabilityRewardFormula = std::make_shared<storm::logic::ReachabilityRewardFormula>(labelFormula);
  91. result = checker.check(*reachabilityRewardFormula);
  92. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  93. EXPECT_NEAR(1.0448979, quantitativeResult3[0], storm::settings::gmmxxEquationSolverSettings().getPrecision());
  94. }