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.

192 lines
11 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/TopologicalValueIterationEquationSolverSettings.h"
  12. #include "src/settings/SettingMemento.h"
  13. #include "src/parser/AutoParser.h"
  14. #include "storm-config.h"
  15. TEST(TopologicalValueIterationMdpPrctlModelCheckerTest, Dice) {
  16. //storm::settings::Settings* s = storm::settings::Settings::getInstance();
  17. std::shared_ptr<storm::models::sparse::Mdp<double>> mdp = 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")->as<storm::models::sparse::Mdp<double>>();
  18. // A parser that we use for conveniently constructing the formulas.
  19. storm::parser::FormulaParser formulaParser;
  20. ASSERT_EQ(mdp->getNumberOfStates(), 169ull);
  21. ASSERT_EQ(mdp->getNumberOfTransitions(), 436ull);
  22. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> mc(*mdp, std::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::MinMaxLinearEquationSolverFactory<double>(storm::solver::EquationSolverTypeSelection::Topological)));
  23. std::shared_ptr<const storm::logic::Formula> formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"two\"]");
  24. std::unique_ptr<storm::modelchecker::CheckResult> result = mc.check(*formula);
  25. ASSERT_NEAR(0.0277777612209320068, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  26. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"two\"]");
  27. result = mc.check(*formula);
  28. ASSERT_NEAR(0.0277777612209320068, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  29. formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"three\"]");
  30. result = mc.check(*formula);
  31. ASSERT_NEAR(0.0555555224418640136, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  32. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"three\"]");
  33. result = mc.check(*formula);
  34. ASSERT_NEAR(0.0555555224418640136, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  35. formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"four\"]");
  36. result = mc.check(*formula);
  37. ASSERT_NEAR(0.083333283662796020508, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  38. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"four\"]");
  39. result = mc.check(*formula);
  40. ASSERT_NEAR(0.083333283662796020508, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  41. formula = formulaParser.parseSingleFormulaFromString("Rmin=? [F \"done\"]");
  42. result = mc.check(*formula);
  43. #ifdef STORM_HAVE_CUDA
  44. ASSERT_NEAR(7.333329499, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  45. #else
  46. ASSERT_NEAR(7.33332904, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  47. #endif
  48. formula = formulaParser.parseSingleFormulaFromString("Rmax=? [F \"done\"]");
  49. result = mc.check(*formula);
  50. #ifdef STORM_HAVE_CUDA
  51. ASSERT_NEAR(7.333329499, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  52. #else
  53. ASSERT_NEAR(7.33333151, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  54. #endif
  55. // ------------- state rewards --------------
  56. std::shared_ptr<storm::models::sparse::Mdp<double>> stateRewardMdp = 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", "")->as<storm::models::sparse::Mdp<double>>();
  57. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> stateRewardModelChecker(*stateRewardMdp, std::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::MinMaxLinearEquationSolverFactory<double>(storm::solver::EquationSolverTypeSelection::Topological)));
  58. formula = formulaParser.parseSingleFormulaFromString("Rmin=? [F \"done\"]");
  59. result = stateRewardModelChecker.check(*formula);
  60. #ifdef STORM_HAVE_CUDA
  61. ASSERT_NEAR(7.333329499, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  62. #else
  63. ASSERT_NEAR(7.33332904, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  64. #endif
  65. formula = formulaParser.parseSingleFormulaFromString("Rmax=? [F \"done\"]");
  66. result = stateRewardModelChecker.check(*formula);
  67. #ifdef STORM_HAVE_CUDA
  68. ASSERT_NEAR(7.333329499, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  69. #else
  70. ASSERT_NEAR(7.33333151, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  71. #endif
  72. // -------------------------------- state and transition reward ------------------------
  73. std::shared_ptr<storm::models::sparse::Mdp<double>> stateAndTransitionRewardMdp = 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")->as<storm::models::sparse::Mdp<double>>();
  74. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> stateAndTransitionRewardModelChecker(*stateAndTransitionRewardMdp, std::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::MinMaxLinearEquationSolverFactory<double>(storm::solver::EquationSolverTypeSelection::Topological)));
  75. formula = formulaParser.parseSingleFormulaFromString("Rmin=? [F \"done\"]");
  76. result = stateAndTransitionRewardModelChecker.check(*formula);
  77. #ifdef STORM_HAVE_CUDA
  78. ASSERT_NEAR(14.666658998, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  79. #else
  80. ASSERT_NEAR(14.6666581, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  81. #endif
  82. formula = formulaParser.parseSingleFormulaFromString("Rmax=? [F \"done\"]");
  83. result = stateAndTransitionRewardModelChecker.check(*formula);
  84. #ifdef STORM_HAVE_CUDA
  85. ASSERT_NEAR(14.666658998, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  86. #else
  87. ASSERT_NEAR(14.666663, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  88. #endif
  89. }
  90. TEST(TopologicalValueIterationMdpPrctlModelCheckerTest, AsynchronousLeader) {
  91. std::shared_ptr<storm::models::sparse::Mdp<double>> mdp = 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")->as<storm::models::sparse::Mdp<double>>();
  92. // A parser that we use for conveniently constructing the formulas.
  93. storm::parser::FormulaParser formulaParser;
  94. ASSERT_EQ(mdp->getNumberOfStates(), 3172ull);
  95. ASSERT_EQ(mdp->getNumberOfTransitions(), 7144ull);
  96. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> mc(*mdp, std::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::MinMaxLinearEquationSolverFactory<double>(storm::solver::EquationSolverTypeSelection::Topological)));
  97. std::shared_ptr<const storm::logic::Formula> formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"elected\"]");
  98. std::unique_ptr<storm::modelchecker::CheckResult> result = mc.check(*formula);
  99. ASSERT_LT(std::abs(result->asExplicitQuantitativeCheckResult<double>()[0] - 1),
  100. storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  101. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"elected\"]");
  102. result = mc.check(*formula);
  103. ASSERT_NEAR(1, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  104. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F<=25 \"elected\"]");
  105. result = mc.check(*formula);
  106. ASSERT_NEAR(0.0625, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  107. formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F<=25 \"elected\"]");
  108. result = mc.check(*formula);
  109. ASSERT_NEAR(0.0625, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  110. formula = formulaParser.parseSingleFormulaFromString("Rmin=? [F \"elected\"]");
  111. result = mc.check(*formula);
  112. #ifdef STORM_HAVE_CUDA
  113. ASSERT_NEAR(4.285689611, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  114. #else
  115. ASSERT_NEAR(4.285701547, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  116. #endif
  117. formula = formulaParser.parseSingleFormulaFromString("Rmax=? [F \"elected\"]");
  118. result = mc.check(*formula);
  119. #ifdef STORM_HAVE_CUDA
  120. ASSERT_NEAR(4.285689611, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  121. #else
  122. ASSERT_NEAR(4.285703591, result->asExplicitQuantitativeCheckResult<double>()[0], storm::settings::topologicalValueIterationEquationSolverSettings().getPrecision());
  123. #endif
  124. }