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