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.

442 lines
26 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/EigenLinearEquationSolver.h"
  6. #include "src/models/sparse/StandardRewardModel.h"
  7. #include "src/modelchecker/prctl/SparseDtmcPrctlModelChecker.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/EigenEquationSolverSettings.h"
  12. #include "src/settings/modules/NativeEquationSolverSettings.h"
  13. #include "src/settings/SettingMemento.h"
  14. #include "src/parser/AutoParser.h"
  15. #include "src/parser/PrismParser.h"
  16. #include "src/builder/ExplicitModelBuilder.h"
  17. #include "src/storage/expressions/ExpressionManager.h"
  18. TEST(EigenDtmcPrctlModelCheckerTest, Die) {
  19. std::shared_ptr<storm::models::sparse::Model<double>> abstractModel = storm::parser::AutoParser<>::parseModel(STORM_CPP_BASE_PATH "/examples/dtmc/die/die.tra", STORM_CPP_BASE_PATH "/examples/dtmc/die/die.lab", "", STORM_CPP_BASE_PATH "/examples/dtmc/die/die.coin_flips.trans.rew");
  20. // A parser that we use for conveniently constructing the formulas.
  21. auto expManager = std::make_shared<storm::expressions::ExpressionManager>();
  22. storm::parser::FormulaParser formulaParser(expManager);
  23. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Dtmc);
  24. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = abstractModel->as<storm::models::sparse::Dtmc<double>>();
  25. ASSERT_EQ(dtmc->getNumberOfStates(), 13ull);
  26. ASSERT_EQ(dtmc->getNumberOfTransitions(), 20ull);
  27. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc, std::make_unique<storm::solver::EigenLinearEquationSolverFactory<double>>());
  28. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("P=? [F \"one\"]");
  29. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  30. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  31. EXPECT_NEAR(1.0 / 6.0, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  32. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"two\"]");
  33. result = checker.check(*formula);
  34. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  35. EXPECT_NEAR(1.0 / 6.0, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  36. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"three\"]");
  37. result = checker.check(*formula);
  38. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  39. EXPECT_NEAR(1.0 / 6.0, quantitativeResult3[0], storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  40. formula = formulaParser.parseSingleFormulaFromString("R=? [F \"done\"]");
  41. result = checker.check(*formula);
  42. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  43. EXPECT_NEAR(11.0 / 3.0, quantitativeResult4[0], storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  44. }
  45. #ifdef STORM_HAVE_CARL
  46. TEST(EigenDtmcPrctlModelCheckerTest, Die_RationalNumber) {
  47. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/die.pm");
  48. storm::generator::NextStateGeneratorOptions options;
  49. options.setBuildAllLabels().setBuildAllRewardModels();
  50. std::shared_ptr<storm::models::sparse::Model<storm::RationalNumber>> model = storm::builder::ExplicitModelBuilder<storm::RationalNumber>(program, options).build();
  51. // A parser that we use for conveniently constructing the formulas.
  52. auto expManager = std::make_shared<storm::expressions::ExpressionManager>();
  53. storm::parser::FormulaParser formulaParser(expManager);
  54. ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc);
  55. std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalNumber>> dtmc = model->as<storm::models::sparse::Dtmc<storm::RationalNumber>>();
  56. ASSERT_EQ(dtmc->getNumberOfStates(), 13ull);
  57. ASSERT_EQ(dtmc->getNumberOfTransitions(), 20ull);
  58. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<storm::RationalNumber>> checker(*dtmc, std::make_unique<storm::solver::EigenLinearEquationSolverFactory<storm::RationalNumber>>());
  59. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("P=? [F \"one\"]");
  60. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  61. storm::modelchecker::ExplicitQuantitativeCheckResult<storm::RationalNumber>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<storm::RationalNumber>();
  62. EXPECT_EQ(storm::RationalNumber(1) / storm::RationalNumber(6), quantitativeResult1[0]);
  63. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"two\"]");
  64. result = checker.check(*formula);
  65. storm::modelchecker::ExplicitQuantitativeCheckResult<storm::RationalNumber>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<storm::RationalNumber>();
  66. EXPECT_EQ(storm::RationalNumber(1) / storm::RationalNumber(6), quantitativeResult2[0]);
  67. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"three\"]");
  68. result = checker.check(*formula);
  69. storm::modelchecker::ExplicitQuantitativeCheckResult<storm::RationalNumber>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<storm::RationalNumber>();
  70. EXPECT_EQ(storm::RationalNumber(1) / storm::RationalNumber(6), quantitativeResult3[0]);
  71. formula = formulaParser.parseSingleFormulaFromString("R=? [F \"done\"]");
  72. result = checker.check(*formula);
  73. storm::modelchecker::ExplicitQuantitativeCheckResult<storm::RationalNumber>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<storm::RationalNumber>();
  74. EXPECT_EQ(storm::RationalNumber(11) / storm::RationalNumber(3), quantitativeResult4[0]);
  75. }
  76. TEST(EigenDtmcPrctlModelCheckerTest, Die_RationalFunction) {
  77. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/parametric_die.pm");
  78. storm::generator::NextStateGeneratorOptions options;
  79. options.setBuildAllLabels().setBuildAllRewardModels();
  80. std::shared_ptr<storm::models::sparse::Model<storm::RationalFunction>> model = storm::builder::ExplicitModelBuilder<storm::RationalFunction>(program, options).build();
  81. // A parser that we use for conveniently constructing the formulas.
  82. auto expManager = std::make_shared<storm::expressions::ExpressionManager>();
  83. storm::parser::FormulaParser formulaParser(expManager);
  84. ASSERT_EQ(model->getType(), storm::models::ModelType::Dtmc);
  85. std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc = model->as<storm::models::sparse::Dtmc<storm::RationalFunction>>();
  86. ASSERT_EQ(dtmc->getNumberOfStates(), 13ull);
  87. ASSERT_EQ(dtmc->getNumberOfTransitions(), 20ull);
  88. std::map<storm::RationalFunctionVariable, storm::RationalNumber> instantiation;
  89. std::set<storm::RationalFunctionVariable> variables = storm::models::sparse::getProbabilityParameters(*dtmc);
  90. ASSERT_EQ(variables.size(), 1ull);
  91. instantiation.emplace(*variables.begin(), storm::RationalNumber(1) / storm::RationalNumber(2));
  92. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<storm::RationalFunction>> checker(*dtmc, std::make_unique<storm::solver::EigenLinearEquationSolverFactory<storm::RationalFunction>>());
  93. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("P=? [F \"one\"]");
  94. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  95. storm::modelchecker::ExplicitQuantitativeCheckResult<storm::RationalFunction>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<storm::RationalFunction>();
  96. EXPECT_EQ(storm::RationalNumber(1) / storm::RationalNumber(6), quantitativeResult1[0].evaluate(instantiation));
  97. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"two\"]");
  98. result = checker.check(*formula);
  99. storm::modelchecker::ExplicitQuantitativeCheckResult<storm::RationalFunction>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<storm::RationalFunction>();
  100. EXPECT_EQ(storm::RationalNumber(1) / storm::RationalNumber(6), quantitativeResult2[0].evaluate(instantiation));
  101. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"three\"]");
  102. result = checker.check(*formula);
  103. storm::modelchecker::ExplicitQuantitativeCheckResult<storm::RationalFunction>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<storm::RationalFunction>();
  104. EXPECT_EQ(storm::RationalNumber(1) / storm::RationalNumber(6), quantitativeResult3[0].evaluate(instantiation));
  105. formula = formulaParser.parseSingleFormulaFromString("R=? [F \"done\"]");
  106. result = checker.check(*formula);
  107. storm::modelchecker::ExplicitQuantitativeCheckResult<storm::RationalFunction>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<storm::RationalFunction>();
  108. EXPECT_EQ(storm::RationalNumber(11) / storm::RationalNumber(3), quantitativeResult4[0].evaluate(instantiation));
  109. }
  110. #endif
  111. TEST(EigenDtmcPrctlModelCheckerTest, Crowds) {
  112. std::shared_ptr<storm::models::sparse::Model<double>> abstractModel = storm::parser::AutoParser<>::parseModel(STORM_CPP_BASE_PATH "/examples/dtmc/crowds/crowds5_5.tra", STORM_CPP_BASE_PATH "/examples/dtmc/crowds/crowds5_5.lab", "", "");
  113. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Dtmc);
  114. // A parser that we use for conveniently constructing the formulas.
  115. auto expManager = std::make_shared<storm::expressions::ExpressionManager>();
  116. storm::parser::FormulaParser formulaParser(expManager);
  117. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = abstractModel->as<storm::models::sparse::Dtmc<double>>();
  118. ASSERT_EQ(8607ull, dtmc->getNumberOfStates());
  119. ASSERT_EQ(15113ull, dtmc->getNumberOfTransitions());
  120. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc, std::unique_ptr<storm::solver::LinearEquationSolverFactory<double>>(new storm::solver::EigenLinearEquationSolverFactory<double>()));
  121. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observe0Greater1\"]");
  122. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  123. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  124. EXPECT_NEAR(0.3328800375801578281, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  125. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observeIGreater1\"]");
  126. result = checker.check(*formula);
  127. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  128. EXPECT_NEAR(0.1522194965, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  129. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observeOnlyTrueSender\"]");
  130. result = checker.check(*formula);
  131. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  132. EXPECT_NEAR(0.32153724292835045, quantitativeResult3[0], storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  133. }
  134. TEST(EigenDtmcPrctlModelCheckerTest, SynchronousLeader) {
  135. std::shared_ptr<storm::models::sparse::Model<double>> abstractModel = storm::parser::AutoParser<>::parseModel(STORM_CPP_BASE_PATH "/examples/dtmc/synchronous_leader/leader4_8.tra", STORM_CPP_BASE_PATH "/examples/dtmc/synchronous_leader/leader4_8.lab", "", STORM_CPP_BASE_PATH "/examples/dtmc/synchronous_leader/leader4_8.pick.trans.rew");
  136. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Dtmc);
  137. // A parser that we use for conveniently constructing the formulas.
  138. auto expManager = std::make_shared<storm::expressions::ExpressionManager>();
  139. storm::parser::FormulaParser formulaParser(expManager);
  140. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = abstractModel->as<storm::models::sparse::Dtmc<double>>();
  141. ASSERT_EQ(12400ull, dtmc->getNumberOfStates());
  142. ASSERT_EQ(16495ull, dtmc->getNumberOfTransitions());
  143. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc, std::make_unique<storm::solver::EigenLinearEquationSolverFactory<double>>());
  144. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("P=? [F \"elected\"]");
  145. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  146. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  147. EXPECT_NEAR(1.0, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  148. formula = formulaParser.parseSingleFormulaFromString("P=? [F<=20 \"elected\"]");
  149. result = checker.check(*formula);
  150. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  151. EXPECT_NEAR(0.9999965911265462636, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  152. formula = formulaParser.parseSingleFormulaFromString("R=? [F \"elected\"]");
  153. result = checker.check(*formula);
  154. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  155. EXPECT_NEAR(1.0448979591836789, quantitativeResult3[0], storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision());
  156. }
  157. TEST(EigenDtmcPrctlModelCheckerTest, LRASingleBscc) {
  158. storm::storage::SparseMatrixBuilder<double> matrixBuilder;
  159. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc;
  160. // A parser that we use for conveniently constructing the formulas.
  161. auto expManager = std::make_shared<storm::expressions::ExpressionManager>();
  162. storm::parser::FormulaParser formulaParser(expManager);
  163. {
  164. matrixBuilder = storm::storage::SparseMatrixBuilder<double>(2, 2, 2);
  165. matrixBuilder.addNextValue(0, 1, 1.);
  166. matrixBuilder.addNextValue(1, 0, 1.);
  167. storm::storage::SparseMatrix<double> transitionMatrix = matrixBuilder.build();
  168. storm::models::sparse::StateLabeling ap(2);
  169. ap.addLabel("a");
  170. ap.addLabelToState("a", 1);
  171. dtmc.reset(new storm::models::sparse::Dtmc<double>(transitionMatrix, ap));
  172. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc, std::make_unique<storm::solver::EigenLinearEquationSolverFactory<double>>());
  173. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("LRA=? [\"a\"]");
  174. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  175. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  176. EXPECT_NEAR(.5, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  177. EXPECT_NEAR(.5, quantitativeResult1[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  178. }
  179. {
  180. matrixBuilder = storm::storage::SparseMatrixBuilder<double>(2, 2, 4);
  181. matrixBuilder.addNextValue(0, 0, .5);
  182. matrixBuilder.addNextValue(0, 1, .5);
  183. matrixBuilder.addNextValue(1, 0, .5);
  184. matrixBuilder.addNextValue(1, 1, .5);
  185. storm::storage::SparseMatrix<double> transitionMatrix = matrixBuilder.build();
  186. storm::models::sparse::StateLabeling ap(2);
  187. ap.addLabel("a");
  188. ap.addLabelToState("a", 1);
  189. dtmc.reset(new storm::models::sparse::Dtmc<double>(transitionMatrix, ap));
  190. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc, std::make_unique<storm::solver::EigenLinearEquationSolverFactory<double>>());
  191. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("LRA=? [\"a\"]");
  192. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  193. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  194. EXPECT_NEAR(.5, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  195. EXPECT_NEAR(.5, quantitativeResult1[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  196. }
  197. {
  198. matrixBuilder = storm::storage::SparseMatrixBuilder<double>(3, 3, 3);
  199. matrixBuilder.addNextValue(0, 1, 1);
  200. matrixBuilder.addNextValue(1, 2, 1);
  201. matrixBuilder.addNextValue(2, 0, 1);
  202. storm::storage::SparseMatrix<double> transitionMatrix = matrixBuilder.build();
  203. storm::models::sparse::StateLabeling ap(3);
  204. ap.addLabel("a");
  205. ap.addLabelToState("a", 2);
  206. dtmc.reset(new storm::models::sparse::Dtmc<double>(transitionMatrix, ap));
  207. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc, std::make_unique<storm::solver::EigenLinearEquationSolverFactory<double>>());
  208. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("LRA=? [\"a\"]");
  209. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  210. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  211. EXPECT_NEAR(1. / 3., quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  212. EXPECT_NEAR(1. / 3., quantitativeResult1[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  213. EXPECT_NEAR(1. / 3., quantitativeResult1[2], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  214. }
  215. }
  216. TEST(EigenDtmcPrctlModelCheckerTest, LRA) {
  217. storm::storage::SparseMatrixBuilder<double> matrixBuilder;
  218. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc;
  219. // A parser that we use for conveniently constructing the formulas.
  220. auto expManager = std::make_shared<storm::expressions::ExpressionManager>();
  221. storm::parser::FormulaParser formulaParser(expManager);
  222. {
  223. matrixBuilder = storm::storage::SparseMatrixBuilder<double>(15, 15, 20, true);
  224. matrixBuilder.addNextValue(0, 1, 1);
  225. matrixBuilder.addNextValue(1, 4, 0.7);
  226. matrixBuilder.addNextValue(1, 6, 0.3);
  227. matrixBuilder.addNextValue(2, 0, 1);
  228. matrixBuilder.addNextValue(3, 5, 0.8);
  229. matrixBuilder.addNextValue(3, 9, 0.2);
  230. matrixBuilder.addNextValue(4, 3, 1);
  231. matrixBuilder.addNextValue(5, 3, 1);
  232. matrixBuilder.addNextValue(6, 7, 1);
  233. matrixBuilder.addNextValue(7, 8, 1);
  234. matrixBuilder.addNextValue(8, 6, 1);
  235. matrixBuilder.addNextValue(9, 10, 1);
  236. matrixBuilder.addNextValue(10, 9, 1);
  237. matrixBuilder.addNextValue(11, 9, 1);
  238. matrixBuilder.addNextValue(12, 5, 0.4);
  239. matrixBuilder.addNextValue(12, 8, 0.3);
  240. matrixBuilder.addNextValue(12, 11, 0.3);
  241. matrixBuilder.addNextValue(13, 7, 0.7);
  242. matrixBuilder.addNextValue(13, 12, 0.3);
  243. matrixBuilder.addNextValue(14, 12, 1);
  244. storm::storage::SparseMatrix<double> transitionMatrix = matrixBuilder.build();
  245. storm::models::sparse::StateLabeling ap(15);
  246. ap.addLabel("a");
  247. ap.addLabelToState("a", 1);
  248. ap.addLabelToState("a", 4);
  249. ap.addLabelToState("a", 5);
  250. ap.addLabelToState("a", 7);
  251. ap.addLabelToState("a", 11);
  252. ap.addLabelToState("a", 13);
  253. ap.addLabelToState("a", 14);
  254. dtmc.reset(new storm::models::sparse::Dtmc<double>(transitionMatrix, ap));
  255. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc, std::make_unique<storm::solver::EigenLinearEquationSolverFactory<double>>());
  256. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("LRA=? [\"a\"]");
  257. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  258. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  259. EXPECT_NEAR(0.3 / 3., quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  260. EXPECT_NEAR(0.0, quantitativeResult1[3], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  261. EXPECT_NEAR(1. / 3., quantitativeResult1[6], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  262. EXPECT_NEAR(0.0, quantitativeResult1[9], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  263. EXPECT_NEAR(0.3 / 3., quantitativeResult1[12], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  264. EXPECT_NEAR(.79 / 3., quantitativeResult1[13], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  265. EXPECT_NEAR(0.3 / 3., quantitativeResult1[14], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  266. }
  267. }
  268. TEST(EigenDtmcPrctlModelCheckerTest, Conditional) {
  269. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/modelchecker/test_conditional.pm");
  270. storm::generator::NextStateGeneratorOptions options;
  271. options.setBuildAllLabels().setBuildAllRewardModels();
  272. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(program, options).build();
  273. ASSERT_TRUE(model->getType() == storm::models::ModelType::Dtmc);
  274. ASSERT_EQ(4ul, model->getNumberOfStates());
  275. ASSERT_EQ(5ul, model->getNumberOfTransitions());
  276. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = model->as<storm::models::sparse::Dtmc<double>>();
  277. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc, std::make_unique<storm::solver::EigenLinearEquationSolverFactory<double>>());
  278. // A parser that we use for conveniently constructing the formulas.
  279. auto expManager = std::make_shared<storm::expressions::ExpressionManager>();
  280. storm::parser::FormulaParser formulaParser(expManager);
  281. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("P=? [F \"target\"]");
  282. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  283. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  284. EXPECT_NEAR(0.5, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  285. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"target\" || F \"condition\"]");
  286. result = checker.check(*formula);
  287. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  288. EXPECT_NEAR(storm::utility::one<double>(), quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  289. formula = formulaParser.parseSingleFormulaFromString("R=? [F \"target\"]");
  290. result = checker.check(*formula);
  291. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  292. EXPECT_EQ(storm::utility::infinity<double>(), quantitativeResult3[0]);
  293. formula = formulaParser.parseSingleFormulaFromString("R=? [F \"target\" || F \"condition\"]");
  294. result = checker.check(*formula);
  295. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  296. EXPECT_NEAR(storm::utility::one<double>(), quantitativeResult4[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  297. }