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.

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