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.

150 lines
8.8 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/solver/NativeNondeterministicLinearEquationSolver.h"
  4. #include "src/settings/Settings.h"
  5. #include "src/modelchecker/prctl/SparseMdpPrctlModelChecker.h"
  6. #include "src/parser/AutoParser.h"
  7. TEST(SparseMdpPrctlModelCheckerTest, Dice) {
  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/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");
  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(mdp->getNumberOfStates(), 169ull);
  13. ASSERT_EQ(mdp->getNumberOfTransitions(), 436ull);
  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>>("two");
  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] - 0.0277777612209320068), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  19. result = mc.checkOptimizingOperator(*eventuallyFormula, false);
  20. ASSERT_LT(std::abs(result[0] - 0.0277777612209320068), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  21. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("three");
  22. eventuallyFormula = std::make_shared<storm::properties::prctl::Eventually<double>>(apFormula);
  23. result = mc.checkOptimizingOperator(*eventuallyFormula, true);
  24. ASSERT_LT(std::abs(result[0] - 0.0555555224418640136), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  25. result = mc.checkOptimizingOperator(*eventuallyFormula, false);
  26. ASSERT_LT(std::abs(result[0] - 0.0555555224418640136), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  27. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("four");
  28. eventuallyFormula = std::make_shared<storm::properties::prctl::Eventually<double>>(apFormula);
  29. result = mc.checkOptimizingOperator(*eventuallyFormula, true);
  30. ASSERT_LT(std::abs(result[0] - 0.083333283662796020508), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  31. result = mc.checkOptimizingOperator(*eventuallyFormula, false);
  32. ASSERT_LT(std::abs(result[0] - 0.083333283662796020508), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  33. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("done");
  34. auto reachabilityRewardFormula = std::make_shared<storm::properties::prctl::ReachabilityReward<double>>(apFormula);
  35. result = mc.checkOptimizingOperator(*reachabilityRewardFormula, true);
  36. ASSERT_LT(std::abs(result[0] - 7.333329499), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  37. result = mc.checkOptimizingOperator(*reachabilityRewardFormula, false);
  38. ASSERT_LT(std::abs(result[0] - 7.333329499), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  39. abstractModel = 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", "");
  40. ASSERT_EQ(abstractModel->getType(), storm::models::MDP);
  41. std::shared_ptr<storm::models::Mdp<double>> stateRewardMdp = abstractModel->as<storm::models::Mdp<double>>();
  42. storm::modelchecker::prctl::SparseMdpPrctlModelChecker<double> stateRewardModelChecker(*stateRewardMdp, std::shared_ptr<storm::solver::NativeNondeterministicLinearEquationSolver<double>>(new storm::solver::NativeNondeterministicLinearEquationSolver<double>()));
  43. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("done");
  44. reachabilityRewardFormula = std::make_shared<storm::properties::prctl::ReachabilityReward<double>>(apFormula);
  45. result = stateRewardModelChecker.checkOptimizingOperator(*reachabilityRewardFormula, true);
  46. ASSERT_LT(std::abs(result[0] - 7.333329499), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  47. result = stateRewardModelChecker.checkOptimizingOperator(*reachabilityRewardFormula, false);
  48. ASSERT_LT(std::abs(result[0] - 7.333329499), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  49. abstractModel = 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");
  50. ASSERT_EQ(abstractModel->getType(), storm::models::MDP);
  51. std::shared_ptr<storm::models::Mdp<double>> stateAndTransitionRewardMdp = abstractModel->as<storm::models::Mdp<double>>();
  52. storm::modelchecker::prctl::SparseMdpPrctlModelChecker<double> stateAndTransitionRewardModelChecker(*stateAndTransitionRewardMdp, std::shared_ptr<storm::solver::NativeNondeterministicLinearEquationSolver<double>>(new storm::solver::NativeNondeterministicLinearEquationSolver<double>()));
  53. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("done");
  54. reachabilityRewardFormula = std::make_shared<storm::properties::prctl::ReachabilityReward<double>>(apFormula);
  55. result = stateAndTransitionRewardModelChecker.checkOptimizingOperator(*reachabilityRewardFormula, true);
  56. ASSERT_LT(std::abs(result[0] - 14.666658998), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  57. result = stateAndTransitionRewardModelChecker.checkOptimizingOperator(*reachabilityRewardFormula, false);
  58. ASSERT_LT(std::abs(result[0] - 14.666658998), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  59. }
  60. TEST(SparseMdpPrctlModelCheckerTest, AsynchronousLeader) {
  61. storm::settings::Settings* s = storm::settings::Settings::getInstance();
  62. std::shared_ptr<storm::models::AbstractModel<double>> abstractModel = 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");
  63. ASSERT_EQ(storm::models::MDP, abstractModel->getType());
  64. std::shared_ptr<storm::models::Mdp<double>> mdp = abstractModel->as<storm::models::Mdp<double>>();
  65. ASSERT_EQ(3172ull, mdp->getNumberOfStates());
  66. ASSERT_EQ(7144ull, mdp->getNumberOfTransitions());
  67. storm::modelchecker::prctl::SparseMdpPrctlModelChecker<double> mc(*mdp, std::shared_ptr<storm::solver::NativeNondeterministicLinearEquationSolver<double>>(new storm::solver::NativeNondeterministicLinearEquationSolver<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 = mc.checkOptimizingOperator(*eventuallyFormula, true);
  71. ASSERT_LT(std::abs(result[0] - 1), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  72. result = mc.checkOptimizingOperator(*eventuallyFormula, false);
  73. ASSERT_LT(std::abs(result[0] - 1), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  74. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("elected");
  75. auto boundedEventuallyFormula = std::make_shared<storm::properties::prctl::BoundedEventually<double>>(apFormula, 25);
  76. result = mc.checkOptimizingOperator(*boundedEventuallyFormula, true);
  77. ASSERT_LT(std::abs(result[0] - 0.0625), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  78. result = mc.checkOptimizingOperator(*boundedEventuallyFormula, false);
  79. ASSERT_LT(std::abs(result[0] - 0.0625), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  80. apFormula = std::make_shared<storm::properties::prctl::Ap<double>>("elected");
  81. auto reachabilityRewardFormula = std::make_shared<storm::properties::prctl::ReachabilityReward<double>>(apFormula);
  82. result = mc.checkOptimizingOperator(*reachabilityRewardFormula, true);
  83. ASSERT_LT(std::abs(result[0] - 4.285689611), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  84. result = mc.checkOptimizingOperator(*reachabilityRewardFormula, false);
  85. ASSERT_LT(std::abs(result[0] - 4.285689611), s->getOptionByLongName("precision").getArgument(0).getValueAsDouble());
  86. }