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.

190 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/models/sparse/StandardRewardModel.h"
  7. #include "src/modelchecker/prctl/SparseMdpPrctlModelChecker.h"
  8. #include "src/modelchecker/results/ExplicitQuantitativeCheckResult.h"
  9. #include "src/settings/SettingsManager.h"
  10. #include "src/settings/modules/GeneralSettings.h"
  11. #include "src/settings/modules/GmmxxEquationSolverSettings.h"
  12. #include "src/settings/modules/NativeEquationSolverSettings.h"
  13. #include "src/parser/AutoParser.h"
  14. TEST(GmmxxMdpPrctlModelCheckerTest, Dice) {
  15. std::shared_ptr<storm::models::sparse::Model<double>> abstractModel = storm::parser::AutoParser::parseModel(STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.tra", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.lab", "", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.flip.trans.rew");
  16. // A parser that we use for conveniently constructing the formulas.
  17. storm::parser::FormulaParser formulaParser;
  18. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Mdp);
  19. std::shared_ptr<storm::models::sparse::Mdp<double>> mdp = abstractModel->as<storm::models::sparse::Mdp<double>>();
  20. ASSERT_EQ(mdp->getNumberOfStates(), 169ull);
  21. ASSERT_EQ(mdp->getNumberOfTransitions(), 436ull);
  22. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> checker(*mdp, std::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::GmmxxMinMaxLinearEquationSolverFactory<double>()));
  23. std::shared_ptr<storm::logic::Formula> formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"two\"]");
  24. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  25. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  26. EXPECT_NEAR(0.0277777612209320068, quantitativeResult1[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  27. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"two\"]");
  28. result = checker.check(*formula);
  29. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  30. EXPECT_NEAR(0.0277777612209320068, quantitativeResult2[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  31. formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"three\"]");
  32. result = checker.check(*formula);
  33. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  34. EXPECT_NEAR(0.0555555224418640136, quantitativeResult3[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  35. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"three\"]");
  36. result = checker.check(*formula);
  37. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  38. EXPECT_NEAR(0.0555555224418640136, quantitativeResult4[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  39. formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"four\"]");
  40. result = checker.check(*formula);
  41. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult5 = result->asExplicitQuantitativeCheckResult<double>();
  42. EXPECT_NEAR(0.083333283662796020508, quantitativeResult5[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  43. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"four\"]");
  44. result = checker.check(*formula);
  45. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult6 = result->asExplicitQuantitativeCheckResult<double>();
  46. EXPECT_NEAR(0.083333283662796020508, quantitativeResult6[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  47. formula = formulaParser.parseSingleFormulaFromString("Rmin=? [F \"done\"]");
  48. result = checker.check(*formula);
  49. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult7 = result->asExplicitQuantitativeCheckResult<double>();
  50. EXPECT_NEAR(7.333329499, quantitativeResult7[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  51. formula = formulaParser.parseSingleFormulaFromString("Rmax=? [F \"done\"]");
  52. result = checker.check(*formula);
  53. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult8 = result->asExplicitQuantitativeCheckResult<double>();
  54. EXPECT_NEAR(7.333329499, quantitativeResult8[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  55. abstractModel = storm::parser::AutoParser::parseModel(STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.tra", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.lab", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.flip.state.rew", "");
  56. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Mdp);
  57. std::shared_ptr<storm::models::sparse::Mdp<double>> stateRewardMdp = abstractModel->as<storm::models::sparse::Mdp<double>>();
  58. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> stateRewardModelChecker(*mdp, std::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::GmmxxMinMaxLinearEquationSolverFactory<double>()));
  59. formula = formulaParser.parseSingleFormulaFromString("Rmin=? [F \"done\"]");
  60. result = stateRewardModelChecker.check(*formula);
  61. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult9 = result->asExplicitQuantitativeCheckResult<double>();
  62. EXPECT_NEAR(7.333329499, quantitativeResult9[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  63. formula = formulaParser.parseSingleFormulaFromString("Rmax=? [F \"done\"]");
  64. result = stateRewardModelChecker.check(*formula);
  65. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult10 = result->asExplicitQuantitativeCheckResult<double>();
  66. EXPECT_NEAR(7.333329499, quantitativeResult10[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  67. abstractModel = storm::parser::AutoParser::parseModel(STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.tra", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.lab", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.flip.state.rew", STORM_CPP_BASE_PATH "/examples/mdp/two_dice/two_dice.flip.trans.rew");
  68. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Mdp);
  69. std::shared_ptr<storm::models::sparse::Mdp<double>> stateAndTransitionRewardMdp = abstractModel->as<storm::models::sparse::Mdp<double>>();
  70. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> stateAndTransitionRewardModelChecker(*stateAndTransitionRewardMdp, std::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::GmmxxMinMaxLinearEquationSolverFactory<double>()));
  71. formula = formulaParser.parseSingleFormulaFromString("Rmin=? [F \"done\"]");
  72. result = stateAndTransitionRewardModelChecker.check(*formula);
  73. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult11 = result->asExplicitQuantitativeCheckResult<double>();
  74. EXPECT_NEAR(14.666658998, quantitativeResult11[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  75. formula = formulaParser.parseSingleFormulaFromString("Rmax=? [F \"done\"]");
  76. result = stateAndTransitionRewardModelChecker.check(*formula);
  77. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult12 = result->asExplicitQuantitativeCheckResult<double>();
  78. EXPECT_NEAR(14.666658998, quantitativeResult12[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  79. }
  80. TEST(GmmxxMdpPrctlModelCheckerTest, AsynchronousLeader) {
  81. std::shared_ptr<storm::models::sparse::Model<double>> abstractModel = storm::parser::AutoParser::parseModel(STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader4.tra", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader4.lab", "", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader4.trans.rew");
  82. // A parser that we use for conveniently constructing the formulas.
  83. storm::parser::FormulaParser formulaParser;
  84. ASSERT_EQ(storm::models::ModelType::Mdp, abstractModel->getType());
  85. std::shared_ptr<storm::models::sparse::Mdp<double>> mdp = abstractModel->as<storm::models::sparse::Mdp<double>>();
  86. ASSERT_EQ(3172ull, mdp->getNumberOfStates());
  87. ASSERT_EQ(7144ull, mdp->getNumberOfTransitions());
  88. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> checker(*mdp, std::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::GmmxxMinMaxLinearEquationSolverFactory<double>()));
  89. std::shared_ptr<storm::logic::Formula> formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"elected\"]");
  90. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  91. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  92. EXPECT_NEAR(1, quantitativeResult1[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  93. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"elected\"]");
  94. result = checker.check(*formula);
  95. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  96. EXPECT_NEAR(1, quantitativeResult2[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  97. formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F<=25 \"elected\"]");
  98. result = checker.check(*formula);
  99. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  100. EXPECT_NEAR(0.0625, quantitativeResult3[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  101. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F<=25 \"elected\"]");
  102. result = checker.check(*formula);
  103. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  104. EXPECT_NEAR(0.0625, quantitativeResult4[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  105. formula = formulaParser.parseSingleFormulaFromString("Rmin=? [F \"elected\"]");
  106. result = checker.check(*formula);
  107. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult5 = result->asExplicitQuantitativeCheckResult<double>();
  108. EXPECT_NEAR(4.285689611, quantitativeResult5[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  109. formula = formulaParser.parseSingleFormulaFromString("Rmax=? [F \"elected\"]");
  110. result = checker.check(*formula);
  111. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult6 = result->asExplicitQuantitativeCheckResult<double>();
  112. EXPECT_NEAR(4.285689611, quantitativeResult6[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  113. }