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.

137 lines
8.0 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/models/sparse/StandardRewardModel.h"
  6. #include "src/modelchecker/reachability/SparseDtmcEliminationModelChecker.h"
  7. #include "src/modelchecker/results/ExplicitQuantitativeCheckResult.h"
  8. #include "src/settings/SettingsManager.h"
  9. #include "src/settings/modules/GeneralSettings.h"
  10. #include "src/settings/SettingMemento.h"
  11. #include "src/parser/AutoParser.h"
  12. TEST(SparseDtmcEliminationModelCheckerTest, Die) {
  13. std::shared_ptr<storm::models::sparse::Model<double>> abstractModel = storm::parser::AutoParser<>::parseModel(STORM_CPP_BASE_PATH "/examples/dtmc/die/die.tra", STORM_CPP_BASE_PATH "/examples/dtmc/die/die.lab", "", STORM_CPP_BASE_PATH "/examples/dtmc/die/die.coin_flips.trans.rew");
  14. // A parser that we use for conveniently constructing the formulas.
  15. storm::parser::FormulaParser formulaParser;
  16. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Dtmc);
  17. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = abstractModel->as<storm::models::sparse::Dtmc<double>>();
  18. ASSERT_EQ(dtmc->getNumberOfStates(), 13ull);
  19. ASSERT_EQ(dtmc->getNumberOfTransitions(), 20ull);
  20. storm::modelchecker::SparseDtmcEliminationModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc);
  21. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("P=? [F \"one\"]");
  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 / 6.0, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
  25. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"two\"]");
  26. result = checker.check(*formula);
  27. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  28. EXPECT_NEAR(1.0 / 6.0, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
  29. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"three\"]");
  30. result = checker.check(*formula);
  31. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  32. EXPECT_NEAR(1.0 / 6.0, quantitativeResult3[0], storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
  33. formula = formulaParser.parseSingleFormulaFromString("R=? [F \"done\"]");
  34. result = checker.check(*formula);
  35. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  36. EXPECT_NEAR(11.0 / 3.0, quantitativeResult4[0], storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
  37. }
  38. TEST(SparseDtmcEliminationModelCheckerTest, Crowds) {
  39. std::shared_ptr<storm::models::sparse::Model<double>> abstractModel = storm::parser::AutoParser<>::parseModel(STORM_CPP_BASE_PATH "/examples/dtmc/crowds/crowds5_5.tra", STORM_CPP_BASE_PATH "/examples/dtmc/crowds/crowds5_5.lab", "", "");
  40. // A parser that we use for conveniently constructing the formulas.
  41. storm::parser::FormulaParser formulaParser;
  42. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Dtmc);
  43. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = abstractModel->as<storm::models::sparse::Dtmc<double>>();
  44. ASSERT_EQ(8607ull, dtmc->getNumberOfStates());
  45. ASSERT_EQ(15113ull, dtmc->getNumberOfTransitions());
  46. storm::modelchecker::SparseDtmcEliminationModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc);
  47. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observe0Greater1\"]");
  48. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  49. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  50. EXPECT_NEAR(0.3328800375801578281, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
  51. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observeIGreater1\"]");
  52. result = checker.check(*formula);
  53. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  54. EXPECT_NEAR(0.1522194965, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
  55. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observeOnlyTrueSender\"]");
  56. result = checker.check(*formula);
  57. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  58. EXPECT_NEAR(0.32153724292835045, quantitativeResult3[0], storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
  59. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observe0Greater1\" || F \"observeIGreater1\"]");
  60. result = checker.check(storm::modelchecker::CheckTask<storm::logic::Formula>(*formula).setOnlyInitialStatesRelevant(true));
  61. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  62. EXPECT_NEAR(0.15330064292476167, quantitativeResult4[0], storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
  63. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observeOnlyTrueSender\" || F \"observe0Greater1\"]");
  64. result = checker.check(storm::modelchecker::CheckTask<storm::logic::Formula>(*formula).setOnlyInitialStatesRelevant(true));
  65. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult5 = result->asExplicitQuantitativeCheckResult<double>();
  66. EXPECT_NEAR(0.96592521978041668, quantitativeResult5[0], storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
  67. }
  68. TEST(SparseDtmcEliminationModelCheckerTest, SynchronousLeader) {
  69. std::shared_ptr<storm::models::sparse::Model<double>> abstractModel = storm::parser::AutoParser<>::parseModel(STORM_CPP_BASE_PATH "/examples/dtmc/synchronous_leader/leader4_8.tra", STORM_CPP_BASE_PATH "/examples/dtmc/synchronous_leader/leader4_8.lab", "", STORM_CPP_BASE_PATH "/examples/dtmc/synchronous_leader/leader4_8.pick.trans.rew");
  70. // A parser that we use for conveniently constructing the formulas.
  71. storm::parser::FormulaParser formulaParser;
  72. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Dtmc);
  73. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = abstractModel->as<storm::models::sparse::Dtmc<double>>();
  74. ASSERT_EQ(12400ull, dtmc->getNumberOfStates());
  75. ASSERT_EQ(16495ull, dtmc->getNumberOfTransitions());
  76. storm::modelchecker::SparseDtmcEliminationModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc);
  77. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("P=? [F \"elected\"]");
  78. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  79. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  80. EXPECT_NEAR(1.0, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
  81. formula = formulaParser.parseSingleFormulaFromString("R=? [F \"elected\"]");
  82. result = checker.check(*formula);
  83. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  84. EXPECT_NEAR(1.0448979, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision());
  85. }