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.

172 lines
12 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/SymbolicDtmcPrctlModelChecker.h"
  6. #include "src/modelchecker/results/SymbolicQualitativeCheckResult.h"
  7. #include "src/modelchecker/results/SymbolicQuantitativeCheckResult.h"
  8. #include "src/parser/PrismParser.h"
  9. #include "src/builder/DdPrismModelBuilder.h"
  10. #include "src/models/symbolic/Dtmc.h"
  11. #include "src/settings/SettingsManager.h"
  12. TEST(SymbolicDtmcPrctlModelCheckerTest, Die) {
  13. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/die.pm");
  14. // Build the die model with its reward model.
  15. #ifdef WINDOWS
  16. storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::Options options;
  17. #else
  18. typename storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::Options options;
  19. #endif
  20. options.buildRewards = true;
  21. options.rewardModelName = "coin_flips";
  22. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program, options);
  23. EXPECT_EQ(13ul, model->getNumberOfStates());
  24. EXPECT_EQ(20ul, model->getNumberOfTransitions());
  25. ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc);
  26. std::shared_ptr<storm::models::symbolic::Dtmc<storm::dd::DdType::CUDD>> dtmc = model->as<storm::models::symbolic::Dtmc<storm::dd::DdType::CUDD>>();
  27. storm::modelchecker::SymbolicDtmcPrctlModelChecker<storm::dd::DdType::CUDD, double> checker(*dtmc, std::unique_ptr<storm::utility::solver::SymbolicLinearEquationSolverFactory<storm::dd::DdType::CUDD, double>>(new storm::utility::solver::SymbolicLinearEquationSolverFactory<storm::dd::DdType::CUDD, double>()));
  28. auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("one");
  29. auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  30. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*eventuallyFormula);
  31. result->filter(storm::modelchecker::SymbolicQualitativeCheckResult<storm::dd::DdType::CUDD>(model->getReachableStates(), model->getInitialStates()));
  32. storm::modelchecker::SymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>& quantitativeResult1 = result->asSymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>();
  33. EXPECT_NEAR(1.0/6.0, quantitativeResult1.getMin(), storm::settings::nativeEquationSolverSettings().getPrecision());
  34. EXPECT_NEAR(1.0/6.0, quantitativeResult1.getMax(), storm::settings::nativeEquationSolverSettings().getPrecision());
  35. labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("two");
  36. eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  37. result = checker.check(*eventuallyFormula);
  38. result->filter(storm::modelchecker::SymbolicQualitativeCheckResult<storm::dd::DdType::CUDD>(model->getReachableStates(), model->getInitialStates()));
  39. storm::modelchecker::SymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>& quantitativeResult2 = result->asSymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>();
  40. EXPECT_NEAR(1.0/6.0, quantitativeResult2.getMin(), storm::settings::nativeEquationSolverSettings().getPrecision());
  41. EXPECT_NEAR(1.0/6.0, quantitativeResult2.getMax(), storm::settings::nativeEquationSolverSettings().getPrecision());
  42. labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("three");
  43. eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  44. result = checker.check(*eventuallyFormula);
  45. result->filter(storm::modelchecker::SymbolicQualitativeCheckResult<storm::dd::DdType::CUDD>(model->getReachableStates(), model->getInitialStates()));
  46. storm::modelchecker::SymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>& quantitativeResult3 = result->asSymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>();
  47. EXPECT_NEAR(1.0/6.0, quantitativeResult3.getMin(), storm::settings::nativeEquationSolverSettings().getPrecision());
  48. EXPECT_NEAR(1.0/6.0, quantitativeResult3.getMax(), storm::settings::nativeEquationSolverSettings().getPrecision());
  49. auto done = std::make_shared<storm::logic::AtomicLabelFormula>("done");
  50. auto reachabilityRewardFormula = std::make_shared<storm::logic::ReachabilityRewardFormula>(done);
  51. result = checker.check(*reachabilityRewardFormula);
  52. result->filter(storm::modelchecker::SymbolicQualitativeCheckResult<storm::dd::DdType::CUDD>(model->getReachableStates(), model->getInitialStates()));
  53. storm::modelchecker::SymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>& quantitativeResult4 = result->asSymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>();
  54. EXPECT_NEAR(3.6666622161865234, quantitativeResult4.getMin(), storm::settings::nativeEquationSolverSettings().getPrecision());
  55. EXPECT_NEAR(3.6666622161865234, quantitativeResult4.getMax(), storm::settings::nativeEquationSolverSettings().getPrecision());
  56. }
  57. TEST(SymbolicDtmcPrctlModelCheckerTest, Crowds) {
  58. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm");
  59. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  60. EXPECT_EQ(8607ul, model->getNumberOfStates());
  61. EXPECT_EQ(15113ul, model->getNumberOfTransitions());
  62. ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc);
  63. std::shared_ptr<storm::models::symbolic::Dtmc<storm::dd::DdType::CUDD>> dtmc = model->as<storm::models::symbolic::Dtmc<storm::dd::DdType::CUDD>>();
  64. storm::modelchecker::SymbolicDtmcPrctlModelChecker<storm::dd::DdType::CUDD, double> checker(*dtmc, std::unique_ptr<storm::utility::solver::SymbolicLinearEquationSolverFactory<storm::dd::DdType::CUDD, double>>(new storm::utility::solver::SymbolicLinearEquationSolverFactory<storm::dd::DdType::CUDD, double>()));
  65. auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("observe0Greater1");
  66. auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  67. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*eventuallyFormula);
  68. result->filter(storm::modelchecker::SymbolicQualitativeCheckResult<storm::dd::DdType::CUDD>(model->getReachableStates(), model->getInitialStates()));
  69. storm::modelchecker::SymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>& quantitativeResult1 = result->asSymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>();
  70. EXPECT_NEAR(0.33288236360191303, quantitativeResult1.getMin(), storm::settings::nativeEquationSolverSettings().getPrecision());
  71. EXPECT_NEAR(0.33288236360191303, quantitativeResult1.getMax(), storm::settings::nativeEquationSolverSettings().getPrecision());
  72. labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("observeIGreater1");
  73. eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  74. result = checker.check(*eventuallyFormula);
  75. result->filter(storm::modelchecker::SymbolicQualitativeCheckResult<storm::dd::DdType::CUDD>(model->getReachableStates(), model->getInitialStates()));
  76. storm::modelchecker::SymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>& quantitativeResult2 = result->asSymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>();
  77. EXPECT_NEAR(0.15222081144084315, quantitativeResult2.getMin(), storm::settings::nativeEquationSolverSettings().getPrecision());
  78. EXPECT_NEAR(0.15222081144084315, quantitativeResult2.getMax(), storm::settings::nativeEquationSolverSettings().getPrecision());
  79. labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("observeOnlyTrueSender");
  80. eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  81. result = checker.check(*eventuallyFormula);
  82. result->filter(storm::modelchecker::SymbolicQualitativeCheckResult<storm::dd::DdType::CUDD>(model->getReachableStates(), model->getInitialStates()));
  83. storm::modelchecker::SymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>& quantitativeResult3 = result->asSymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>();
  84. EXPECT_NEAR(0.3215392962289586, quantitativeResult3.getMin(), storm::settings::nativeEquationSolverSettings().getPrecision());
  85. EXPECT_NEAR(0.3215392962289586, quantitativeResult3.getMax(), storm::settings::nativeEquationSolverSettings().getPrecision());
  86. }
  87. TEST(SymbolicDtmcPrctlModelCheckerTest, SynchronousLeader) {
  88. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader-3-5.pm");
  89. // Build the die model with its reward model.
  90. #ifdef WINDOWS
  91. storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::Options options;
  92. #else
  93. typename storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::Options options;
  94. #endif
  95. options.buildRewards = true;
  96. options.rewardModelName = "num_rounds";
  97. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program, options);
  98. EXPECT_EQ(273ul, model->getNumberOfStates());
  99. EXPECT_EQ(397ul, model->getNumberOfTransitions());
  100. ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc);
  101. std::shared_ptr<storm::models::symbolic::Dtmc<storm::dd::DdType::CUDD>> dtmc = model->as<storm::models::symbolic::Dtmc<storm::dd::DdType::CUDD>>();
  102. storm::modelchecker::SymbolicDtmcPrctlModelChecker<storm::dd::DdType::CUDD, double> checker(*dtmc, std::unique_ptr<storm::utility::solver::SymbolicLinearEquationSolverFactory<storm::dd::DdType::CUDD, double>>(new storm::utility::solver::SymbolicLinearEquationSolverFactory<storm::dd::DdType::CUDD, double>()));
  103. auto labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("elected");
  104. auto eventuallyFormula = std::make_shared<storm::logic::EventuallyFormula>(labelFormula);
  105. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*eventuallyFormula);
  106. result->filter(storm::modelchecker::SymbolicQualitativeCheckResult<storm::dd::DdType::CUDD>(model->getReachableStates(), model->getInitialStates()));
  107. storm::modelchecker::SymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>& quantitativeResult1 = result->asSymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>();
  108. EXPECT_NEAR(1.0, quantitativeResult1.getMin(), storm::settings::nativeEquationSolverSettings().getPrecision());
  109. EXPECT_NEAR(1.0, quantitativeResult1.getMax(), storm::settings::nativeEquationSolverSettings().getPrecision());
  110. labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("elected");
  111. auto trueFormula = std::make_shared<storm::logic::BooleanLiteralFormula>(true);
  112. auto boundedUntilFormula = std::make_shared<storm::logic::BoundedUntilFormula>(trueFormula, labelFormula, 20);
  113. result = checker.check(*boundedUntilFormula);
  114. result->filter(storm::modelchecker::SymbolicQualitativeCheckResult<storm::dd::DdType::CUDD>(model->getReachableStates(), model->getInitialStates()));
  115. storm::modelchecker::SymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>& quantitativeResult2 = result->asSymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>();
  116. EXPECT_NEAR(0.99999989760000074, quantitativeResult2.getMin(), storm::settings::nativeEquationSolverSettings().getPrecision());
  117. EXPECT_NEAR(0.99999989760000074, quantitativeResult2.getMax(), storm::settings::nativeEquationSolverSettings().getPrecision());
  118. labelFormula = std::make_shared<storm::logic::AtomicLabelFormula>("elected");
  119. auto reachabilityRewardFormula = std::make_shared<storm::logic::ReachabilityRewardFormula>(labelFormula);
  120. result = checker.check(*reachabilityRewardFormula);
  121. result->filter(storm::modelchecker::SymbolicQualitativeCheckResult<storm::dd::DdType::CUDD>(model->getReachableStates(), model->getInitialStates()));
  122. storm::modelchecker::SymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>& quantitativeResult3 = result->asSymbolicQuantitativeCheckResult<storm::dd::DdType::CUDD>();
  123. EXPECT_NEAR(1.0416666666666643, quantitativeResult3.getMin(), storm::settings::nativeEquationSolverSettings().getPrecision());
  124. EXPECT_NEAR(1.0416666666666643, quantitativeResult3.getMax(), storm::settings::nativeEquationSolverSettings().getPrecision());
  125. }