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.

143 lines
8.6 KiB

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