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.

148 lines
8.5 KiB

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