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.

88 lines
5.2 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/logic/Formulas.h"
  4. #include "src/modelchecker/exploration/SparseExplorationModelChecker.h"
  5. #include "src/modelchecker/results/ExplicitQuantitativeCheckResult.h"
  6. #include "src/parser/PrismParser.h"
  7. #include "src/parser/FormulaParser.h"
  8. #include "src/settings/SettingsManager.h"
  9. #include "src/settings/modules/ExplorationSettings.h"
  10. #include "src/models/sparse/Mdp.h"
  11. #include "src/models/sparse/StandardRewardModel.h"
  12. TEST(SparseExplorationModelCheckerTest, Dice) {
  13. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/two_dice.nm");
  14. // A parser that we use for conveniently constructing the formulas.
  15. storm::parser::FormulaParser formulaParser;
  16. storm::modelchecker::SparseExplorationModelChecker<storm::models::sparse::Mdp<double>, uint32_t> checker(program);
  17. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"two\"]");
  18. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(storm::modelchecker::CheckTask<>(*formula, true));
  19. storm::modelchecker::ExplicitQuantitativeCheckResult<double> const& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  20. EXPECT_NEAR(0.0277777612209320068, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::ExplorationSettings>().getPrecision());
  21. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"two\"]");
  22. result = checker.check(storm::modelchecker::CheckTask<>(*formula, true));
  23. storm::modelchecker::ExplicitQuantitativeCheckResult<double> const& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  24. EXPECT_NEAR(0.0277777612209320068, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::ExplorationSettings>().getPrecision());
  25. formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"three\"]");
  26. result = checker.check(storm::modelchecker::CheckTask<>(*formula, true));
  27. storm::modelchecker::ExplicitQuantitativeCheckResult<double> const& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  28. EXPECT_NEAR(0.0555555224418640136, quantitativeResult3[0], storm::settings::getModule<storm::settings::modules::ExplorationSettings>().getPrecision());
  29. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"three\"]");
  30. result = checker.check(storm::modelchecker::CheckTask<>(*formula, true));
  31. storm::modelchecker::ExplicitQuantitativeCheckResult<double> const& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  32. EXPECT_NEAR(0.0555555224418640136, quantitativeResult4[0], storm::settings::getModule<storm::settings::modules::ExplorationSettings>().getPrecision());
  33. formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"four\"]");
  34. result = checker.check(storm::modelchecker::CheckTask<>(*formula, true));
  35. storm::modelchecker::ExplicitQuantitativeCheckResult<double> const& quantitativeResult5 = result->asExplicitQuantitativeCheckResult<double>();
  36. EXPECT_NEAR(0.083333283662796020508, quantitativeResult5[0], storm::settings::getModule<storm::settings::modules::ExplorationSettings>().getPrecision());
  37. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"four\"]");
  38. result = checker.check(storm::modelchecker::CheckTask<>(*formula, true));
  39. storm::modelchecker::ExplicitQuantitativeCheckResult<double> const& quantitativeResult6 = result->asExplicitQuantitativeCheckResult<double>();
  40. EXPECT_NEAR(0.083333283662796020508, quantitativeResult6[0], storm::settings::getModule<storm::settings::modules::ExplorationSettings>().getPrecision());
  41. }
  42. TEST(SparseExplorationModelCheckerTest, AsynchronousLeader) {
  43. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader4.nm");
  44. // A parser that we use for conveniently constructing the formulas.
  45. storm::parser::FormulaParser formulaParser;
  46. storm::modelchecker::SparseExplorationModelChecker<storm::models::sparse::Mdp<double>, uint32_t> checker(program);
  47. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"elected\"]");
  48. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(storm::modelchecker::CheckTask<>(*formula, true));
  49. storm::modelchecker::ExplicitQuantitativeCheckResult<double> const& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  50. EXPECT_NEAR(1, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::ExplorationSettings>().getPrecision());
  51. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"elected\"]");
  52. result = checker.check(storm::modelchecker::CheckTask<>(*formula, true));
  53. storm::modelchecker::ExplicitQuantitativeCheckResult<double> const& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  54. EXPECT_NEAR(1, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::ExplorationSettings>().getPrecision());
  55. }