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.

518 lines
30 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/utility/solver.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::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::MinMaxLinearEquationSolverFactory<double>(storm::solver::EquationSolverTypeSelection::Native)));
  22. std::shared_ptr<const storm::logic::Formula> 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::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::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::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::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::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::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::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::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::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::MinMaxLinearEquationSolverFactory<double>(storm::solver::EquationSolverTypeSelection::Native)));
  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::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::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::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::MinMaxLinearEquationSolverFactory<double>(storm::solver::EquationSolverTypeSelection::Native)));
  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::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::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::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::MinMaxLinearEquationSolverFactory<double>(storm::solver::EquationSolverTypeSelection::Native)));
  88. std::shared_ptr<const storm::logic::Formula> 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::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::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::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::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::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::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::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::MinMaxLinearEquationSolverFactory<double>(storm::solver::EquationSolverTypeSelection::Native)));
  128. std::shared_ptr<const storm::logic::Formula> formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"a\"]");
  129. std::unique_ptr<storm::modelchecker::CheckResult> result = std::move(checker.check(*formula));
  130. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  131. EXPECT_NEAR(.5, quantitativeResult1[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  132. EXPECT_NEAR(.5, quantitativeResult1[1], storm::settings::nativeEquationSolverSettings().getPrecision());
  133. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"a\"]");
  134. result = std::move(checker.check(*formula));
  135. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  136. EXPECT_NEAR(.5, quantitativeResult2[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  137. EXPECT_NEAR(.5, quantitativeResult2[1], storm::settings::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::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::MinMaxLinearEquationSolverFactory<double>(storm::solver::EquationSolverTypeSelection::Native)));
  151. std::shared_ptr<const storm::logic::Formula> formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"a\"]");
  152. std::unique_ptr<storm::modelchecker::CheckResult> result = std::move(checker.check(*formula));
  153. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  154. EXPECT_NEAR(.5, quantitativeResult1[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  155. EXPECT_NEAR(.5, quantitativeResult1[1], storm::settings::nativeEquationSolverSettings().getPrecision());
  156. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"a\"]");
  157. result = std::move(checker.check(*formula));
  158. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  159. EXPECT_NEAR(.5, quantitativeResult2[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  160. EXPECT_NEAR(.5, quantitativeResult2[1], storm::settings::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::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::MinMaxLinearEquationSolverFactory<double>(storm::solver::EquationSolverTypeSelection::Native)));
  182. std::shared_ptr<const storm::logic::Formula> formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"a\"]");
  183. std::unique_ptr<storm::modelchecker::CheckResult> result = std::move(checker.check(*formula));
  184. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  185. EXPECT_NEAR(1. / 3., quantitativeResult1[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  186. EXPECT_NEAR(1. / 3., quantitativeResult1[1], storm::settings::nativeEquationSolverSettings().getPrecision());
  187. EXPECT_NEAR(1. / 3., quantitativeResult1[2], storm::settings::nativeEquationSolverSettings().getPrecision());
  188. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"a\"]");
  189. result = std::move(checker.check(*formula));
  190. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  191. EXPECT_NEAR(0.0, quantitativeResult2[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  192. EXPECT_NEAR(0.0, quantitativeResult2[1], storm::settings::nativeEquationSolverSettings().getPrecision());
  193. EXPECT_NEAR(0.0, quantitativeResult2[2], storm::settings::nativeEquationSolverSettings().getPrecision());
  194. formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"b\"]");
  195. result = std::move(checker.check(*formula));
  196. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  197. EXPECT_NEAR(0.5, quantitativeResult3[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  198. EXPECT_NEAR(0.5, quantitativeResult3[1], storm::settings::nativeEquationSolverSettings().getPrecision());
  199. EXPECT_NEAR(0.5, quantitativeResult3[2], storm::settings::nativeEquationSolverSettings().getPrecision());
  200. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"b\"]");
  201. result = std::move(checker.check(*formula));
  202. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  203. EXPECT_NEAR(1. / 3., quantitativeResult4[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  204. EXPECT_NEAR(1. / 3., quantitativeResult4[1], storm::settings::nativeEquationSolverSettings().getPrecision());
  205. EXPECT_NEAR(1. / 3., quantitativeResult4[2], storm::settings::nativeEquationSolverSettings().getPrecision());
  206. formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"c\"]");
  207. result = std::move(checker.check(*formula));
  208. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult5 = result->asExplicitQuantitativeCheckResult<double>();
  209. EXPECT_NEAR(2. / 3., quantitativeResult5[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  210. EXPECT_NEAR(2. / 3., quantitativeResult5[1], storm::settings::nativeEquationSolverSettings().getPrecision());
  211. EXPECT_NEAR(2. / 3., quantitativeResult5[2], storm::settings::nativeEquationSolverSettings().getPrecision());
  212. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"c\"]");
  213. result = std::move(checker.check(*formula));
  214. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult6 = result->asExplicitQuantitativeCheckResult<double>();
  215. EXPECT_NEAR(0.5, quantitativeResult6[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  216. EXPECT_NEAR(0.5, quantitativeResult6[1], storm::settings::nativeEquationSolverSettings().getPrecision());
  217. EXPECT_NEAR(0.5, quantitativeResult6[2], storm::settings::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::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::MinMaxLinearEquationSolverFactory<double>(storm::solver::EquationSolverTypeSelection::Native)));
  244. std::shared_ptr<const storm::logic::Formula> formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"a\"]");
  245. std::unique_ptr<storm::modelchecker::CheckResult> result = std::move(checker.check(*formula));
  246. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  247. EXPECT_NEAR(0.0, quantitativeResult1[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  248. EXPECT_NEAR(0.0, quantitativeResult1[1], storm::settings::nativeEquationSolverSettings().getPrecision());
  249. EXPECT_NEAR(0.0, quantitativeResult1[2], storm::settings::nativeEquationSolverSettings().getPrecision());
  250. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"a\"]");
  251. result = std::move(checker.check(*formula));
  252. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  253. EXPECT_NEAR(0.0, quantitativeResult2[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  254. EXPECT_NEAR(0.0, quantitativeResult2[1], storm::settings::nativeEquationSolverSettings().getPrecision());
  255. EXPECT_NEAR(0.0, quantitativeResult2[2], storm::settings::nativeEquationSolverSettings().getPrecision());
  256. formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"b\"]");
  257. result = std::move(checker.check(*formula));
  258. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  259. EXPECT_NEAR(1.0, quantitativeResult3[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  260. EXPECT_NEAR(1.0, quantitativeResult3[1], storm::settings::nativeEquationSolverSettings().getPrecision());
  261. EXPECT_NEAR(0.0, quantitativeResult3[2], storm::settings::nativeEquationSolverSettings().getPrecision());
  262. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"b\"]");
  263. result = std::move(checker.check(*formula));
  264. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  265. EXPECT_NEAR(0.0, quantitativeResult4[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  266. EXPECT_NEAR(0.0, quantitativeResult4[1], storm::settings::nativeEquationSolverSettings().getPrecision());
  267. EXPECT_NEAR(0.0, quantitativeResult4[2], storm::settings::nativeEquationSolverSettings().getPrecision());
  268. formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"c\"]");
  269. result = std::move(checker.check(*formula));
  270. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult5 = result->asExplicitQuantitativeCheckResult<double>();
  271. EXPECT_NEAR(1.0, quantitativeResult5[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  272. EXPECT_NEAR(1.0, quantitativeResult5[1], storm::settings::nativeEquationSolverSettings().getPrecision());
  273. EXPECT_NEAR(1.0, quantitativeResult5[2], storm::settings::nativeEquationSolverSettings().getPrecision());
  274. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"c\"]");
  275. result = std::move(checker.check(*formula));
  276. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult6 = result->asExplicitQuantitativeCheckResult<double>();
  277. EXPECT_NEAR(0.0, quantitativeResult6[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  278. EXPECT_NEAR(0.0, quantitativeResult6[1], storm::settings::nativeEquationSolverSettings().getPrecision());
  279. EXPECT_NEAR(1.0, quantitativeResult6[2], storm::settings::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::unique_ptr<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(new storm::utility::solver::MinMaxLinearEquationSolverFactory<double>(storm::solver::EquationSolverTypeSelection::Native)));
  338. std::shared_ptr<const storm::logic::Formula> formula = formulaParser.parseSingleFormulaFromString("LRAmax=? [\"a\"]");
  339. std::unique_ptr<storm::modelchecker::CheckResult> result = std::move(checker.check(*formula));
  340. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  341. EXPECT_NEAR(37. / 60., quantitativeResult1[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  342. EXPECT_NEAR(2. / 3., quantitativeResult1[3], storm::settings::nativeEquationSolverSettings().getPrecision());
  343. EXPECT_NEAR(0.5, quantitativeResult1[6], storm::settings::nativeEquationSolverSettings().getPrecision());
  344. EXPECT_NEAR(1. / 3., quantitativeResult1[9], storm::settings::nativeEquationSolverSettings().getPrecision());
  345. EXPECT_NEAR(31. / 60., quantitativeResult1[12], storm::settings::nativeEquationSolverSettings().getPrecision());
  346. EXPECT_NEAR(101. / 200., quantitativeResult1[13], storm::settings::nativeEquationSolverSettings().getPrecision());
  347. EXPECT_NEAR(31. / 60., quantitativeResult1[14], storm::settings::nativeEquationSolverSettings().getPrecision());
  348. formula = formulaParser.parseSingleFormulaFromString("LRAmin=? [\"a\"]");
  349. result = std::move(checker.check(*formula));
  350. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  351. EXPECT_NEAR(0.3 / 3., quantitativeResult2[0], storm::settings::nativeEquationSolverSettings().getPrecision());
  352. EXPECT_NEAR(0.0, quantitativeResult2[3], storm::settings::nativeEquationSolverSettings().getPrecision());
  353. EXPECT_NEAR(1. / 3., quantitativeResult2[6], storm::settings::nativeEquationSolverSettings().getPrecision());
  354. EXPECT_NEAR(0.0, quantitativeResult2[9], storm::settings::nativeEquationSolverSettings().getPrecision());
  355. EXPECT_NEAR(0.3 / 3., quantitativeResult2[12], storm::settings::nativeEquationSolverSettings().getPrecision());
  356. EXPECT_NEAR(.79 / 3., quantitativeResult2[13], storm::settings::nativeEquationSolverSettings().getPrecision());
  357. EXPECT_NEAR(0.3 / 3., quantitativeResult2[14], storm::settings::nativeEquationSolverSettings().getPrecision());
  358. }
  359. }