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.

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