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.

177 lines
12 KiB

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