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.

125 lines
6.6 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/solver/GmmxxLinearEquationSolver.h"
  4. #include "src/modelchecker/prctl/SparseDtmcPrctlModelChecker.h"
  5. #include "src/settings/Settings.h"
  6. #include "src/settings/InternalOptionMemento.h"
  7. #include "src/parser/AutoParser.h"
  8. TEST(GmmxxDtmcPrctlModelCheckerTest, Die) {
  9. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  10. storm::settings::InternalOptionMemento deadlockOption("fixDeadlocks", true);
  11. ASSERT_TRUE(s->isSet("fixDeadlocks"));
  12. std::shared_ptr<storm::models::AbstractModel<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");
  13. ASSERT_EQ(abstractModel->getType(), storm::models::DTMC);
  14. std::shared_ptr<storm::models::Dtmc<double>> dtmc = abstractModel->as<storm::models::Dtmc<double>>();
  15. ASSERT_EQ(dtmc->getNumberOfStates(), 13ull);
  16. ASSERT_EQ(dtmc->getNumberOfTransitions(), 20ull);
  17. storm::modelchecker::prctl::SparseDtmcPrctlModelChecker<double> mc(*dtmc, new storm::solver::GmmxxLinearEquationSolver<double>());
  18. auto apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("one");
  19. auto eventuallyFormula = std::make_shared<storm::properties::prctl::Eventually<double>>(apFormula);
  20. std::vector<double> result = eventuallyFormula->check(mc, false);
  21. ASSERT_LT(std::abs(result[0] - ((double)1.0/6.0)), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  22. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("two");
  23. eventuallyFormula = std::make_shared<storm::properties::prctl::Eventually<double>>(apFormula);
  24. result = eventuallyFormula->check(mc, false);
  25. ASSERT_LT(std::abs(result[0] - ((double)1.0/6.0)), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  26. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("three");
  27. eventuallyFormula = std::make_shared<storm::properties::prctl::Eventually<double>>(apFormula);
  28. result = eventuallyFormula->check(mc, false);
  29. ASSERT_LT(std::abs(result[0] - ((double)1.0/6.0)), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  30. auto done = std::make_shared<storm::properties::prctl::Ap<double>>("done");
  31. auto reachabilityRewardFormula = std::make_shared<storm::properties::prctl::ReachabilityReward<double>>(done);
  32. result = reachabilityRewardFormula->check(mc, false);
  33. ASSERT_LT(std::abs(result[0] - ((double)11/3)), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  34. }
  35. TEST(GmmxxDtmcPrctlModelCheckerTest, Crowds) {
  36. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  37. storm::settings::InternalOptionMemento deadlockOption("fixDeadlocks", true);
  38. ASSERT_TRUE(s->isSet("fixDeadlocks"));
  39. std::shared_ptr<storm::models::AbstractModel<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. ASSERT_EQ(abstractModel->getType(), storm::models::DTMC);
  41. std::shared_ptr<storm::models::Dtmc<double>> dtmc = abstractModel->as<storm::models::Dtmc<double>>();
  42. ASSERT_EQ(8607ull, dtmc->getNumberOfStates());
  43. ASSERT_EQ(15113ull, dtmc->getNumberOfTransitions());
  44. storm::modelchecker::prctl::SparseDtmcPrctlModelChecker<double> mc(*dtmc, new storm::solver::GmmxxLinearEquationSolver<double>());
  45. auto apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("observe0Greater1");
  46. auto eventuallyFormula = std::make_shared<storm::properties::prctl::Eventually<double>>(apFormula);
  47. std::vector<double> result = eventuallyFormula->check(mc, false);
  48. ASSERT_LT(std::abs(result[0] - 0.3328800375801578281), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  49. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("observeIGreater1");
  50. eventuallyFormula = std::make_shared<storm::properties::prctl::Eventually<double>>(apFormula);
  51. result = eventuallyFormula->check(mc, false);
  52. ASSERT_LT(std::abs(result[0] - 0.1522194965), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  53. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("observeOnlyTrueSender");
  54. eventuallyFormula = std::make_shared<storm::properties::prctl::Eventually<double>>(apFormula);
  55. result = eventuallyFormula->check(mc, false);
  56. ASSERT_LT(std::abs(result[0] - 0.32153724292835045), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  57. }
  58. TEST(GmmxxDtmcPrctlModelCheckerTest, SynchronousLeader) {
  59. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  60. storm::settings::InternalOptionMemento deadlockOption("fixDeadlocks", true);
  61. ASSERT_TRUE(s->isSet("fixDeadlocks"));
  62. std::shared_ptr<storm::models::AbstractModel<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");
  63. ASSERT_EQ(abstractModel->getType(), storm::models::DTMC);
  64. std::shared_ptr<storm::models::Dtmc<double>> dtmc = abstractModel->as<storm::models::Dtmc<double>>();
  65. ASSERT_EQ(12400ull, dtmc->getNumberOfStates());
  66. ASSERT_EQ(16495ull, dtmc->getNumberOfTransitions());
  67. storm::modelchecker::prctl::SparseDtmcPrctlModelChecker<double> mc(*dtmc, new storm::solver::GmmxxLinearEquationSolver<double>());
  68. auto apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("elected");
  69. auto eventuallyFormula = std::make_shared<storm::properties::prctl::Eventually<double>>(apFormula);
  70. std::vector<double> result = eventuallyFormula->check(mc, false);
  71. ASSERT_LT(std::abs(result[0] - 1.0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  72. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("elected");
  73. auto boundedUntilFormula = std::make_shared<storm::properties::prctl::BoundedUntil<double>>(std::make_shared<storm::properties::prctl::Ap<double>>("true"), apFormula, 20);
  74. result = boundedUntilFormula->check(mc, false);
  75. ASSERT_LT(std::abs(result[0] - 0.9999965911265462636), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  76. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("elected");
  77. auto reachabilityRewardFormula = std::make_shared<storm::properties::prctl::ReachabilityReward<double>>(apFormula);
  78. result = reachabilityRewardFormula->check(mc, false);
  79. ASSERT_LT(std::abs(result[0] - 1.044879046), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  80. }