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.

129 lines
8.2 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/logic/Formulas.h"
  4. #include "src/utility/solver.h"
  5. #include "src/modelchecker/prctl/SparseDtmcPrctlModelChecker.h"
  6. #include "src/modelchecker/results/ExplicitQuantitativeCheckResult.h"
  7. #include "src/settings/SettingsManager.h"
  8. #include "src/settings/SettingMemento.h"
  9. #include "src/parser/AutoParser.h"
  10. TEST(SparseDtmcPrctlModelCheckerTest, Die) {
  11. 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");
  12. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Dtmc);
  13. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = abstractModel->as<storm::models::sparse::Dtmc<double>>();
  14. ASSERT_EQ(dtmc->getNumberOfStates(), 13ull);
  15. ASSERT_EQ(dtmc->getNumberOfTransitions(), 20ull);
  16. storm::modelchecker::SparseDtmcPrctlModelChecker<double> checker(*dtmc, std::unique_ptr<storm::utility::solver::LinearEquationSolverFactory<double>>(new storm::utility::solver::NativeLinearEquationSolverFactory<double>()));
  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::nativeEquationSolverSettings().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::nativeEquationSolverSettings().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::nativeEquationSolverSettings().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(3.6666650772094727, quantitativeResult4[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  37. }
  38. TEST(SparseDtmcPrctlModelCheckerTest, Crowds) {
  39. 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", "", "");
  40. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Dtmc);
  41. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = abstractModel->as<storm::models::sparse::Dtmc<double>>();
  42. ASSERT_EQ(8607ull, dtmc->getNumberOfStates());
  43. ASSERT_EQ(15113ull, dtmc->getNumberOfTransitions());
  44. storm::modelchecker::SparseDtmcPrctlModelChecker<double> checker(*dtmc, std::unique_ptr<storm::utility::solver::LinearEquationSolverFactory<double>>(new storm::utility::solver::NativeLinearEquationSolverFactory<double>()));
  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.33288205191646525, quantitativeResult1[0], storm::settings::nativeEquationSolverSettings().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.15222066094730619, quantitativeResult2[0], storm::settings::nativeEquationSolverSettings().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.32153900158185761, quantitativeResult3[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  60. }
  61. TEST(SparseDtmcPrctlModelCheckerTest, SynchronousLeader) {
  62. 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");
  63. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Dtmc);
  64. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = abstractModel->as<storm::models::sparse::Dtmc<double>>();
  65. ASSERT_EQ(12400ull, dtmc->getNumberOfStates());
  66. ASSERT_EQ(16495ull, dtmc->getNumberOfTransitions());
  67. storm::modelchecker::SparseDtmcPrctlModelChecker<double> checker(*dtmc, std::unique_ptr<storm::utility::solver::LinearEquationSolverFactory<double>>(new storm::utility::solver::NativeLinearEquationSolverFactory<double>()));
  68. auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("elected");
  69. auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  70. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*eventuallyFormula);
  71. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  72. EXPECT_NEAR(1.0, quantitativeResult1[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  73. labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("elected");
  74. auto trueFormula = std::make_shared<storm::logic::BooleanLiteralFormula>(true);
  75. auto boundedUntilFormula = std::make_shared<storm::logic::BoundedUntilFormula>(trueFormula, labelFormula, 20);
  76. result = checker.check(*boundedUntilFormula);
  77. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  78. EXPECT_NEAR(0.9999965911265462636, quantitativeResult2[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  79. labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("elected");
  80. auto reachabilityRewardFormula = std::make_shared<storm::logic::ReachabilityRewardFormula>(labelFormula);
  81. result = checker.check(*reachabilityRewardFormula);
  82. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  83. EXPECT_NEAR(1.0448979589010925, quantitativeResult3[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  84. }