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.

128 lines
7.2 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/settings/Settings.h"
  4. #include "src/modelchecker/prctl/SparseMdpPrctlModelChecker.h"
  5. #include "src/solver/NativeNondeterministicLinearEquationSolver.h"
  6. #include "src/parser/AutoParser.h"
  7. TEST(SparseMdpPrctlModelCheckerTest, AsynchronousLeader) {
  8. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  9. std::shared_ptr<storm::models::AbstractModel<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");
  10. ASSERT_EQ(abstractModel->getType(), storm::models::MDP);
  11. std::shared_ptr<storm::models::Mdp<double>> mdp = abstractModel->as<storm::models::Mdp<double>>();
  12. ASSERT_EQ(2095783ull, mdp->getNumberOfStates());
  13. ASSERT_EQ(7714385ull, mdp->getNumberOfTransitions());
  14. storm::modelchecker::prctl::SparseMdpPrctlModelChecker<double> mc(*mdp, std::shared_ptr<storm::solver::NativeNondeterministicLinearEquationSolver<double>>(new storm::solver::NativeNondeterministicLinearEquationSolver<double>()));
  15. auto apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("elected");
  16. auto eventuallyFormula = std::make_shared<storm::properties::prctl::Eventually<double>>(apFormula);
  17. std::vector<double> result = mc.checkOptimizingOperator(*eventuallyFormula, true);
  18. ASSERT_LT(std::abs(result[0] - 1.0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  19. result = mc.checkOptimizingOperator(*eventuallyFormula, false);
  20. ASSERT_LT(std::abs(result[0] - 1.0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  21. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("elected");
  22. auto boundedEventuallyFormula = std::make_shared<storm::properties::prctl::BoundedEventually<double>>(apFormula, 25);
  23. result = mc.checkOptimizingOperator(*boundedEventuallyFormula, true);
  24. ASSERT_LT(std::abs(result[0] - 0.0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  25. result = mc.checkOptimizingOperator(*boundedEventuallyFormula, false);
  26. ASSERT_LT(std::abs(result[0] - 0.0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  27. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("elected");
  28. auto reachabilityRewardFormula = std::make_shared<storm::properties::prctl::ReachabilityReward<double>>(apFormula);
  29. result = mc.checkOptimizingOperator(*reachabilityRewardFormula, true);
  30. ASSERT_LT(std::abs(result[0] - 6.172433512), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  31. result = mc.checkOptimizingOperator(*reachabilityRewardFormula, false);
  32. ASSERT_LT(std::abs(result[0] - 6.1724344), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  33. }
  34. TEST(SparseMdpPrctlModelCheckerTest, Consensus) {
  35. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  36. // Increase the maximal number of iterations, because the solver does not converge otherwise.
  37. // This is done in the main cpp unit
  38. std::shared_ptr<storm::models::AbstractModel<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", "");
  39. ASSERT_EQ(abstractModel->getType(), storm::models::MDP);
  40. std::shared_ptr<storm::models::Mdp<double>> mdp = abstractModel->as<storm::models::Mdp<double>>();
  41. ASSERT_EQ(63616ull, mdp->getNumberOfStates());
  42. ASSERT_EQ(213472ull, mdp->getNumberOfTransitions());
  43. storm::modelchecker::prctl::SparseMdpPrctlModelChecker<double> mc(*mdp, std::shared_ptr<storm::solver::NativeNondeterministicLinearEquationSolver<double>>(new storm::solver::NativeNondeterministicLinearEquationSolver<double>()));
  44. auto apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("finished");
  45. auto eventuallyFormula = std::make_shared<storm::properties::prctl::Eventually<double>>(apFormula);
  46. std::vector<double> result = mc.checkOptimizingOperator(*eventuallyFormula, true);
  47. ASSERT_LT(std::abs(result[31168] - 1.0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  48. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("finished");
  49. auto apFormula2 = std::make_shared<storm::properties::prctl::Ap<double>>("all_coins_equal_0");
  50. auto andFormula = std::make_shared<storm::properties::prctl::And<double>>(apFormula, apFormula2);
  51. eventuallyFormula = std::make_shared<storm::properties::prctl::Eventually<double>>(andFormula);
  52. result = mc.checkOptimizingOperator(*eventuallyFormula, true);
  53. ASSERT_LT(std::abs(result[31168] - 0.4374282832), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  54. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("finished");
  55. apFormula2 = std::make_shared<storm::properties::prctl::Ap<double>>("all_coins_equal_1");
  56. andFormula = std::make_shared<storm::properties::prctl::And<double>>(apFormula, apFormula2);
  57. eventuallyFormula = std::make_shared<storm::properties::prctl::Eventually<double>>(andFormula);
  58. result = mc.checkOptimizingOperator(*eventuallyFormula, false);
  59. ASSERT_LT(std::abs(result[31168] - 0.5293286369), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  60. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("finished");
  61. apFormula2 = std::make_shared<storm::properties::prctl::Ap<double>>("agree");
  62. auto notFormula = std::make_shared<storm::properties::prctl::Not<double>>(apFormula2);
  63. andFormula = std::make_shared<storm::properties::prctl::And<double>>(apFormula, notFormula);
  64. eventuallyFormula = std::make_shared<storm::properties::prctl::Eventually<double>>(andFormula);
  65. result = mc.checkOptimizingOperator(*eventuallyFormula, false);
  66. ASSERT_LT(std::abs(result[31168] - 0.10414097), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  67. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("finished");
  68. auto boundedEventuallyFormula = std::make_shared<storm::properties::prctl::BoundedEventually<double>>(apFormula, 50ull);
  69. result = mc.checkOptimizingOperator(*boundedEventuallyFormula, true);
  70. ASSERT_LT(std::abs(result[31168] - 0.0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  71. result = mc.checkOptimizingOperator(*boundedEventuallyFormula, false);
  72. ASSERT_LT(std::abs(result[31168] - 0.0), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  73. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("finished");
  74. auto reachabilityRewardFormula = std::make_shared<storm::properties::prctl::ReachabilityReward<double>>(apFormula);
  75. result = mc.checkOptimizingOperator(*reachabilityRewardFormula, true);
  76. ASSERT_LT(std::abs(result[31168] - 1725.593313), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  77. result = mc.checkOptimizingOperator(*reachabilityRewardFormula, false);
  78. ASSERT_LT(std::abs(result[31168] - 2183.142422), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  79. }