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.

519 lines
32 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/solver/StandardMinMaxLinearEquationSolver.h"
  6. #include "src/models/sparse/StandardRewardModel.h"
  7. #include "src/modelchecker/prctl/SparseMdpPrctlModelChecker.h"
  8. #include "src/modelchecker/results/ExplicitQuantitativeCheckResult.h"
  9. #include "src/settings/SettingsManager.h"
  10. #include "src/settings/modules/GeneralSettings.h"
  11. #include "src/settings/modules/NativeEquationSolverSettings.h"
  12. #include "src/parser/AutoParser.h"
  13. TEST(SparseMdpPrctlModelCheckerTest, Dice) {
  14. std::shared_ptr<storm::models::sparse::Model<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");
  15. // A parser that we use for conveniently constructing the formulas.
  16. storm::parser::FormulaParser formulaParser;
  17. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Mdp);
  18. std::shared_ptr<storm::models::sparse::Mdp<double>> mdp = abstractModel->as<storm::models::sparse::Mdp<double>>();
  19. ASSERT_EQ(mdp->getNumberOfStates(), 169ull);
  20. ASSERT_EQ(mdp->getNumberOfTransitions(), 436ull);
  21. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> checker(*mdp, std::make_unique<storm::solver::NativeMinMaxLinearEquationSolverFactory<double>>());
  22. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"two\"]");
  23. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  24. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  25. EXPECT_NEAR(0.0277777612209320068, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  26. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"two\"]");
  27. result = checker.check(*formula);
  28. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  29. EXPECT_NEAR(0.0277777612209320068, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  30. formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"three\"]");
  31. result = checker.check(*formula);
  32. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  33. EXPECT_NEAR(0.0555555224418640136, quantitativeResult3[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  34. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"three\"]");
  35. result = checker.check(*formula);
  36. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  37. EXPECT_NEAR(0.0555555224418640136, quantitativeResult4[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  38. formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"four\"]");
  39. result = checker.check(*formula);
  40. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult5 = result->asExplicitQuantitativeCheckResult<double>();
  41. EXPECT_NEAR(0.083333283662796020508, quantitativeResult5[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  42. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"four\"]");
  43. result = checker.check(*formula);
  44. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult6 = result->asExplicitQuantitativeCheckResult<double>();
  45. EXPECT_NEAR(0.083333283662796020508, quantitativeResult6[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  46. formula = formulaParser.parseSingleFormulaFromString("Rmin=? [F \"done\"]");
  47. result = checker.check(*formula);
  48. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult7 = result->asExplicitQuantitativeCheckResult<double>();
  49. EXPECT_NEAR(7.333329499, quantitativeResult7[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  50. formula = formulaParser.parseSingleFormulaFromString("Rmax=? [F \"done\"]");
  51. result = checker.check(*formula);
  52. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult8 = result->asExplicitQuantitativeCheckResult<double>();
  53. EXPECT_NEAR(7.333329499, quantitativeResult8[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  54. 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", "");
  55. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Mdp);
  56. std::shared_ptr<storm::models::sparse::Mdp<double>> stateRewardMdp = abstractModel->as<storm::models::sparse::Mdp<double>>();
  57. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> stateRewardModelChecker(*stateRewardMdp, std::make_unique<storm::solver::NativeMinMaxLinearEquationSolverFactory<double>>());
  58. formula = formulaParser.parseSingleFormulaFromString("Rmin=? [F \"done\"]");
  59. result = stateRewardModelChecker.check(*formula);
  60. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult9 = result->asExplicitQuantitativeCheckResult<double>();
  61. EXPECT_NEAR(7.333329499, quantitativeResult9[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  62. formula = formulaParser.parseSingleFormulaFromString("Rmax=? [F \"done\"]");
  63. result = stateRewardModelChecker.check(*formula);
  64. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult10 = result->asExplicitQuantitativeCheckResult<double>();
  65. EXPECT_NEAR(7.333329499, quantitativeResult10[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  66. 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");
  67. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Mdp);
  68. std::shared_ptr<storm::models::sparse::Mdp<double>> stateAndTransitionRewardMdp = abstractModel->as<storm::models::sparse::Mdp<double>>();
  69. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> stateAndTransitionRewardModelChecker(*stateAndTransitionRewardMdp, std::make_unique<storm::solver::NativeMinMaxLinearEquationSolverFactory<double>>());
  70. formula = formulaParser.parseSingleFormulaFromString("Rmin=? [F \"done\"]");
  71. result = stateAndTransitionRewardModelChecker.check(*formula);
  72. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult11 = result->asExplicitQuantitativeCheckResult<double>();
  73. EXPECT_NEAR(14.666658998, quantitativeResult11[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  74. formula = formulaParser.parseSingleFormulaFromString("Rmax=? [F \"done\"]");
  75. result = stateAndTransitionRewardModelChecker.check(*formula);
  76. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult12 = result->asExplicitQuantitativeCheckResult<double>();
  77. EXPECT_NEAR(14.666658998, quantitativeResult12[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  78. }
  79. TEST(SparseMdpPrctlModelCheckerTest, AsynchronousLeader) {
  80. std::shared_ptr<storm::models::sparse::Model<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");
  81. // A parser that we use for conveniently constructing the formulas.
  82. storm::parser::FormulaParser formulaParser;
  83. ASSERT_EQ(storm::models::ModelType::Mdp, abstractModel->getType());
  84. std::shared_ptr<storm::models::sparse::Mdp<double>> mdp = abstractModel->as<storm::models::sparse::Mdp<double>>();
  85. ASSERT_EQ(3172ull, mdp->getNumberOfStates());
  86. ASSERT_EQ(7144ull, mdp->getNumberOfTransitions());
  87. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> checker(*mdp, std::make_unique<storm::solver::NativeMinMaxLinearEquationSolverFactory<double>>());
  88. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F \"elected\"]");
  89. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  90. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  91. EXPECT_NEAR(1, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  92. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"elected\"]");
  93. result = checker.check(*formula);
  94. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  95. EXPECT_NEAR(1, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  96. formula = formulaParser.parseSingleFormulaFromString("Pmin=? [F<=25 \"elected\"]");
  97. result = checker.check(*formula);
  98. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  99. EXPECT_NEAR(0.0625, quantitativeResult3[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  100. formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F<=25 \"elected\"]");
  101. result = checker.check(*formula);
  102. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  103. EXPECT_NEAR(0.0625, quantitativeResult4[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  104. formula = formulaParser.parseSingleFormulaFromString("Rmin=? [F \"elected\"]");
  105. result = checker.check(*formula);
  106. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult5 = result->asExplicitQuantitativeCheckResult<double>();
  107. EXPECT_NEAR(4.285689611, quantitativeResult5[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  108. formula = formulaParser.parseSingleFormulaFromString("Rmax=? [F \"elected\"]");
  109. result = checker.check(*formula);
  110. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult6 = result->asExplicitQuantitativeCheckResult<double>();
  111. EXPECT_NEAR(4.285689611, quantitativeResult6[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  112. }
  113. TEST(SparseMdpPrctlModelCheckerTest, LRA_SingleMec) {
  114. storm::storage::SparseMatrixBuilder<double> matrixBuilder;
  115. std::shared_ptr<storm::models::sparse::Mdp<double>> mdp;
  116. // A parser that we use for conveniently constructing the formulas.
  117. storm::parser::FormulaParser formulaParser;
  118. {
  119. matrixBuilder = storm::storage::SparseMatrixBuilder<double>(2, 2, 2);
  120. matrixBuilder.addNextValue(0, 1, 1.);
  121. matrixBuilder.addNextValue(1, 0, 1.);
  122. storm::storage::SparseMatrix<double> transitionMatrix = matrixBuilder.build();
  123. storm::models::sparse::StateLabeling ap(2);
  124. ap.addLabel("a");
  125. ap.addLabelToState("a", 1);
  126. mdp.reset(new storm::models::sparse::Mdp<double>(transitionMatrix, ap));
  127. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> checker(*mdp, std::make_unique<storm::solver::NativeMinMaxLinearEquationSolverFactory<double>>());
  128. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"a\"]");
  129. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  130. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  131. EXPECT_NEAR(.5, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  132. EXPECT_NEAR(.5, quantitativeResult1[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  133. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"a\"]");
  134. result = checker.check(*formula);
  135. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  136. EXPECT_NEAR(.5, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  137. EXPECT_NEAR(.5, quantitativeResult2[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  138. }
  139. {
  140. matrixBuilder = storm::storage::SparseMatrixBuilder<double>(2, 2, 4);
  141. matrixBuilder.addNextValue(0, 0, .5);
  142. matrixBuilder.addNextValue(0, 1, .5);
  143. matrixBuilder.addNextValue(1, 0, .5);
  144. matrixBuilder.addNextValue(1, 1, .5);
  145. storm::storage::SparseMatrix<double> transitionMatrix = matrixBuilder.build();
  146. storm::models::sparse::StateLabeling ap(2);
  147. ap.addLabel("a");
  148. ap.addLabelToState("a", 1);
  149. mdp.reset(new storm::models::sparse::Mdp<double>(transitionMatrix, ap));
  150. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> checker(*mdp, std::make_unique<storm::solver::NativeMinMaxLinearEquationSolverFactory<double>>());
  151. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"a\"]");
  152. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  153. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  154. EXPECT_NEAR(.5, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  155. EXPECT_NEAR(.5, quantitativeResult1[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  156. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"a\"]");
  157. result = checker.check(*formula);
  158. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  159. EXPECT_NEAR(.5, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  160. EXPECT_NEAR(.5, quantitativeResult2[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  161. }
  162. {
  163. matrixBuilder = storm::storage::SparseMatrixBuilder<double>(4, 3, 4, true, true, 3);
  164. matrixBuilder.newRowGroup(0);
  165. matrixBuilder.addNextValue(0, 1, 1);
  166. matrixBuilder.newRowGroup(1);
  167. matrixBuilder.addNextValue(1, 0, 1);
  168. matrixBuilder.addNextValue(2, 2, 1);
  169. matrixBuilder.newRowGroup(3);
  170. matrixBuilder.addNextValue(3, 0, 1);
  171. storm::storage::SparseMatrix<double> transitionMatrix = matrixBuilder.build();
  172. storm::models::sparse::StateLabeling ap(3);
  173. ap.addLabel("a");
  174. ap.addLabelToState("a", 2);
  175. ap.addLabel("b");
  176. ap.addLabelToState("b", 0);
  177. ap.addLabel("c");
  178. ap.addLabelToState("c", 0);
  179. ap.addLabelToState("c", 2);
  180. mdp.reset(new storm::models::sparse::Mdp<double>(transitionMatrix, ap));
  181. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> checker(*mdp, std::make_unique<storm::solver::NativeMinMaxLinearEquationSolverFactory<double>>());
  182. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"a\"]");
  183. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  184. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  185. EXPECT_NEAR(1. / 3., quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  186. EXPECT_NEAR(1. / 3., quantitativeResult1[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  187. EXPECT_NEAR(1. / 3., quantitativeResult1[2], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  188. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"a\"]");
  189. result = checker.check(*formula);
  190. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  191. EXPECT_NEAR(0.0, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  192. EXPECT_NEAR(0.0, quantitativeResult2[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  193. EXPECT_NEAR(0.0, quantitativeResult2[2], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  194. formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"b\"]");
  195. result = checker.check(*formula);
  196. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  197. EXPECT_NEAR(0.5, quantitativeResult3[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  198. EXPECT_NEAR(0.5, quantitativeResult3[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  199. EXPECT_NEAR(0.5, quantitativeResult3[2], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  200. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"b\"]");
  201. result = checker.check(*formula);
  202. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  203. EXPECT_NEAR(1. / 3., quantitativeResult4[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  204. EXPECT_NEAR(1. / 3., quantitativeResult4[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  205. EXPECT_NEAR(1. / 3., quantitativeResult4[2], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  206. formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"c\"]");
  207. result = checker.check(*formula);
  208. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult5 = result->asExplicitQuantitativeCheckResult<double>();
  209. EXPECT_NEAR(2. / 3., quantitativeResult5[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  210. EXPECT_NEAR(2. / 3., quantitativeResult5[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  211. EXPECT_NEAR(2. / 3., quantitativeResult5[2], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  212. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"c\"]");
  213. result = checker.check(*formula);
  214. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult6 = result->asExplicitQuantitativeCheckResult<double>();
  215. EXPECT_NEAR(0.5, quantitativeResult6[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  216. EXPECT_NEAR(0.5, quantitativeResult6[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  217. EXPECT_NEAR(0.5, quantitativeResult6[2], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  218. }
  219. }
  220. TEST(SparseMdpPrctlModelCheckerTest, LRA) {
  221. storm::storage::SparseMatrixBuilder<double> matrixBuilder;
  222. std::shared_ptr<storm::models::sparse::Mdp<double>> mdp;
  223. // A parser that we use for conveniently constructing the formulas.
  224. storm::parser::FormulaParser formulaParser;
  225. {
  226. matrixBuilder = storm::storage::SparseMatrixBuilder<double>(4, 3, 4, true, true, 3);
  227. matrixBuilder.newRowGroup(0);
  228. matrixBuilder.addNextValue(0, 1, 1);
  229. matrixBuilder.newRowGroup(1);
  230. matrixBuilder.addNextValue(1, 1, 1);
  231. matrixBuilder.addNextValue(2, 2, 1);
  232. matrixBuilder.newRowGroup(3);
  233. matrixBuilder.addNextValue(3, 2, 1);
  234. storm::storage::SparseMatrix<double> transitionMatrix = matrixBuilder.build();
  235. storm::models::sparse::StateLabeling ap(3);
  236. ap.addLabel("a");
  237. ap.addLabelToState("a", 0);
  238. ap.addLabel("b");
  239. ap.addLabelToState("b", 1);
  240. ap.addLabel("c");
  241. ap.addLabelToState("c", 2);
  242. mdp.reset(new storm::models::sparse::Mdp<double>(transitionMatrix, ap));
  243. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> checker(*mdp, std::make_unique<storm::solver::NativeMinMaxLinearEquationSolverFactory<double>>());
  244. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"a\"]");
  245. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  246. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  247. EXPECT_NEAR(0.0, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  248. EXPECT_NEAR(0.0, quantitativeResult1[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  249. EXPECT_NEAR(0.0, quantitativeResult1[2], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  250. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"a\"]");
  251. result = checker.check(*formula);
  252. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  253. EXPECT_NEAR(0.0, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  254. EXPECT_NEAR(0.0, quantitativeResult2[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  255. EXPECT_NEAR(0.0, quantitativeResult2[2], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  256. formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"b\"]");
  257. result = checker.check(*formula);
  258. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  259. EXPECT_NEAR(1.0, quantitativeResult3[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  260. EXPECT_NEAR(1.0, quantitativeResult3[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  261. EXPECT_NEAR(0.0, quantitativeResult3[2], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  262. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"b\"]");
  263. result = checker.check(*formula);
  264. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  265. EXPECT_NEAR(0.0, quantitativeResult4[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  266. EXPECT_NEAR(0.0, quantitativeResult4[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  267. EXPECT_NEAR(0.0, quantitativeResult4[2], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  268. formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"c\"]");
  269. result = checker.check(*formula);
  270. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult5 = result->asExplicitQuantitativeCheckResult<double>();
  271. EXPECT_NEAR(1.0, quantitativeResult5[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  272. EXPECT_NEAR(1.0, quantitativeResult5[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  273. EXPECT_NEAR(1.0, quantitativeResult5[2], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  274. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"c\"]");
  275. result = checker.check(*formula);
  276. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult6 = result->asExplicitQuantitativeCheckResult<double>();
  277. EXPECT_NEAR(0.0, quantitativeResult6[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  278. EXPECT_NEAR(0.0, quantitativeResult6[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  279. EXPECT_NEAR(1.0, quantitativeResult6[2], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  280. }
  281. {
  282. matrixBuilder = storm::storage::SparseMatrixBuilder<double>(22, 15, 28, true, true, 15);
  283. matrixBuilder.newRowGroup(0);
  284. matrixBuilder.addNextValue(0, 1, 1);
  285. matrixBuilder.newRowGroup(1);
  286. matrixBuilder.addNextValue(1, 0, 1);
  287. matrixBuilder.addNextValue(2, 2, 1);
  288. matrixBuilder.addNextValue(3, 4, 0.7);
  289. matrixBuilder.addNextValue(3, 6, 0.3);
  290. matrixBuilder.newRowGroup(4);
  291. matrixBuilder.addNextValue(4, 0, 1);
  292. matrixBuilder.newRowGroup(5);
  293. matrixBuilder.addNextValue(5, 4, 1);
  294. matrixBuilder.addNextValue(6, 5, 0.8);
  295. matrixBuilder.addNextValue(6, 9, 0.2);
  296. matrixBuilder.newRowGroup(7);
  297. matrixBuilder.addNextValue(7, 3, 1);
  298. matrixBuilder.addNextValue(8, 5, 1);
  299. matrixBuilder.newRowGroup(9);
  300. matrixBuilder.addNextValue(9, 3, 1);
  301. matrixBuilder.newRowGroup(10);
  302. matrixBuilder.addNextValue(10, 7, 1);
  303. matrixBuilder.newRowGroup(11);
  304. matrixBuilder.addNextValue(11, 6, 1);
  305. matrixBuilder.addNextValue(12, 8, 1);
  306. matrixBuilder.newRowGroup(13);
  307. matrixBuilder.addNextValue(13, 6, 1);
  308. matrixBuilder.newRowGroup(14);
  309. matrixBuilder.addNextValue(14, 10, 1);
  310. matrixBuilder.newRowGroup(15);
  311. matrixBuilder.addNextValue(15, 9, 1);
  312. matrixBuilder.addNextValue(16, 11, 1);
  313. matrixBuilder.newRowGroup(17);
  314. matrixBuilder.addNextValue(17, 9, 1);
  315. matrixBuilder.newRowGroup(18);
  316. matrixBuilder.addNextValue(18, 5, 0.4);
  317. matrixBuilder.addNextValue(18, 8, 0.3);
  318. matrixBuilder.addNextValue(18, 11, 0.3);
  319. matrixBuilder.newRowGroup(19);
  320. matrixBuilder.addNextValue(19, 7, 0.7);
  321. matrixBuilder.addNextValue(19, 12, 0.3);
  322. matrixBuilder.newRowGroup(20);
  323. matrixBuilder.addNextValue(20, 12, 0.1);
  324. matrixBuilder.addNextValue(20, 13, 0.9);
  325. matrixBuilder.addNextValue(21, 12, 1);
  326. storm::storage::SparseMatrix<double> transitionMatrix = matrixBuilder.build();
  327. storm::models::sparse::StateLabeling ap(15);
  328. ap.addLabel("a");
  329. ap.addLabelToState("a", 1);
  330. ap.addLabelToState("a", 4);
  331. ap.addLabelToState("a", 5);
  332. ap.addLabelToState("a", 7);
  333. ap.addLabelToState("a", 11);
  334. ap.addLabelToState("a", 13);
  335. ap.addLabelToState("a", 14);
  336. mdp.reset(new storm::models::sparse::Mdp<double>(transitionMatrix, ap));
  337. storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> checker(*mdp, std::make_unique<storm::solver::NativeMinMaxLinearEquationSolverFactory<double>>());
  338. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"a\"]");
  339. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  340. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  341. EXPECT_NEAR(37. / 60., quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  342. EXPECT_NEAR(2. / 3., quantitativeResult1[3], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  343. EXPECT_NEAR(0.5, quantitativeResult1[6], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  344. EXPECT_NEAR(1. / 3., quantitativeResult1[9], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  345. EXPECT_NEAR(31. / 60., quantitativeResult1[12], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  346. EXPECT_NEAR(101. / 200., quantitativeResult1[13], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  347. EXPECT_NEAR(31. / 60., quantitativeResult1[14], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  348. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"a\"]");
  349. result = checker.check(*formula);
  350. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  351. EXPECT_NEAR(0.3 / 3., quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  352. EXPECT_NEAR(0.0, quantitativeResult2[3], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  353. EXPECT_NEAR(1. / 3., quantitativeResult2[6], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  354. EXPECT_NEAR(0.0, quantitativeResult2[9], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  355. EXPECT_NEAR(0.3 / 3., quantitativeResult2[12], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  356. EXPECT_NEAR(.79 / 3., quantitativeResult2[13], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  357. EXPECT_NEAR(0.3 / 3., quantitativeResult2[14], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  358. }
  359. }