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.

142 lines
8.8 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/settings/SettingsManager.h"
  4. #include "src/settings/modules/NativeEquationSolverSettings.h"
  5. #include "src/modelchecker/prctl/SparseMdpPrctlModelChecker.h"
  6. #include "src/modelchecker/results/ExplicitQuantitativeCheckResult.h"
  7. #include "src/utility/solver.h"
  8. #include "src/parser/AutoParser.h"
  9. #include "src/models/sparse/StandardRewardModel.h"
  10. #include "src/parser/FormulaParser.h"
  11. TEST(GmxxMdpPrctlModelCheckerTest, AsynchronousLeader) {
  12. std::shared_ptr<storm::models::sparse::Model<double>> abstractModel = storm::parser::AutoParser<>::parseModel(STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader7.tra", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader7.lab", "", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader7.trans.rew");
  13. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Mdp);
  14. // A parser that we use for conveniently constructing the formulas.
  15. storm::parser::FormulaParser formulaParser;
  16. std::shared_ptr<storm::models::sparse::Mdp<double>> mdp = abstractModel->as<storm::models::sparse::Mdp<double>>();
  17. ASSERT_EQ(2095783ull, mdp->getNumberOfStates());
  18. ASSERT_EQ(7714385ull, mdp->getNumberOfTransitions());
  19. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> checker(*mdp, std::unique_ptr<storm::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::solver::MinMaxLinearEquationSolverFactory<double>(storm::solver::EquationSolverTypeSelection::Gmmxx)));
  20. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"elected\"]");
  21. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  22. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  23. EXPECT_NEAR(1.0, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  24. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"elected\"]");
  25. result = checker.check(*formula);
  26. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  27. EXPECT_NEAR(1.0, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  28. formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F<=25 \"elected\"]");
  29. result = checker.check(*formula);
  30. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  31. EXPECT_NEAR(0.0, quantitativeResult3[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  32. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F<=25 \"elected\"]");
  33. result = checker.check(*formula);
  34. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  35. EXPECT_NEAR(0.0, quantitativeResult4[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  36. formula = formulaParser.parseSingleFormulaFromString("Rmin=? [F \"elected\"]");
  37. result = checker.check(*formula);
  38. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeResult5 = result->asExplicitQuantitativeCheckResult<double>();
  39. EXPECT_NEAR(6.172433512, quantitativeResult5[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  40. formula = formulaParser.parseSingleFormulaFromString("Rmax=? [F \"elected\"]");
  41. result = checker.check(*formula);
  42. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeResult6 = result->asExplicitQuantitativeCheckResult<double>();
  43. EXPECT_NEAR(6.1724344, quantitativeResult6[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  44. }
  45. TEST(GmxxMdpPrctlModelCheckerTest, Consensus) {
  46. std::shared_ptr<storm::models::sparse::Model<double>> abstractModel = storm::parser::AutoParser<>::parseModel(STORM_CPP_BASE_PATH "/examples/mdp/consensus/coin4_6.tra", STORM_CPP_BASE_PATH "/examples/mdp/consensus/coin4_6.lab", STORM_CPP_BASE_PATH "/examples/mdp/consensus/coin4_6.steps.state.rew", "");
  47. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Mdp);
  48. // A parser that we use for conveniently constructing the formulas.
  49. storm::parser::FormulaParser formulaParser;
  50. std::shared_ptr<storm::models::sparse::Mdp<double>> mdp = abstractModel->as<storm::models::sparse::Mdp<double>>();
  51. ASSERT_EQ(63616ull, mdp->getNumberOfStates());
  52. ASSERT_EQ(213472ull, mdp->getNumberOfTransitions());
  53. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> checker(*mdp, std::unique_ptr<storm::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::solver::MinMaxLinearEquationSolverFactory<double>(storm::solver::EquationSolverTypeSelection::Gmmxx)));
  54. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"finished\"]");
  55. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  56. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  57. EXPECT_NEAR(1.0, quantitativeResult1[31168], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  58. formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"finished\" & \"all_coins_equal_0\"]");
  59. result = checker.check(*formula);
  60. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  61. EXPECT_NEAR(0.4374282832, quantitativeResult2[31168], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  62. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"finished\" & \"all_coins_equal_1\"]");
  63. result = checker.check(*formula);
  64. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  65. EXPECT_NEAR(0.5293286369, quantitativeResult3[31168], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  66. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"finished\" & !\"agree\"]");
  67. result = checker.check(*formula);
  68. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  69. EXPECT_NEAR(0.10414097, quantitativeResult4[31168], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  70. formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F<=50 \"finished\"]");
  71. result = checker.check(*formula);
  72. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeResult5 = result->asExplicitQuantitativeCheckResult<double>();
  73. EXPECT_NEAR(0.0, quantitativeResult5[31168], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  74. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F<=50 \"finished\"]");
  75. result = checker.check(*formula);
  76. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeResult6 = result->asExplicitQuantitativeCheckResult<double>();
  77. EXPECT_NEAR(0.0, quantitativeResult6[31168], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  78. formula = formulaParser.parseSingleFormulaFromString("Rmin=? [F \"finished\"]");
  79. result = checker.check(*formula);
  80. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeResult7 = result->asExplicitQuantitativeCheckResult<double>();
  81. EXPECT_NEAR(1725.593313, quantitativeResult7[31168], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  82. formula = formulaParser.parseSingleFormulaFromString("Rmax=? [F \"finished\"]");
  83. result = checker.check(*formula);
  84. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeResult8 = result->asExplicitQuantitativeCheckResult<double>();
  85. EXPECT_NEAR(2183.142422, quantitativeResult8[31168], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  86. }