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.

321 lines
18 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/GmmxxLinearEquationSolver.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/GmmxxEquationSolverSettings.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. TEST(GmmxxDtmcPrctlModelCheckerTest, Die) {
  18. 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");
  19. // A parser that we use for conveniently constructing the formulas.
  20. storm::parser::FormulaParser formulaParser;
  21. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Dtmc);
  22. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = abstractModel->as<storm::models::sparse::Dtmc<double>>();
  23. ASSERT_EQ(dtmc->getNumberOfStates(), 13ull);
  24. ASSERT_EQ(dtmc->getNumberOfTransitions(), 20ull);
  25. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc, std::make_unique<storm::solver::GmmxxLinearEquationSolverFactory<double>>());
  26. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("P=? [F \"one\"]");
  27. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  28. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  29. EXPECT_NEAR(1.0 / 6.0, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision());
  30. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"two\"]");
  31. result = checker.check(*formula);
  32. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  33. EXPECT_NEAR(1.0 / 6.0, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision());
  34. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"three\"]");
  35. result = checker.check(*formula);
  36. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  37. EXPECT_NEAR(1.0 / 6.0, quantitativeResult3[0], storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision());
  38. formula = formulaParser.parseSingleFormulaFromString("R=? [F \"done\"]");
  39. result = checker.check(*formula);
  40. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  41. EXPECT_NEAR(11.0 / 3.0, quantitativeResult4[0], storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision());
  42. }
  43. TEST(GmmxxDtmcPrctlModelCheckerTest, Crowds) {
  44. 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", "", "");
  45. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Dtmc);
  46. // A parser that we use for conveniently constructing the formulas.
  47. storm::parser::FormulaParser formulaParser;
  48. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = abstractModel->as<storm::models::sparse::Dtmc<double>>();
  49. ASSERT_EQ(8607ull, dtmc->getNumberOfStates());
  50. ASSERT_EQ(15113ull, dtmc->getNumberOfTransitions());
  51. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc, std::make_unique<storm::solver::GmmxxLinearEquationSolverFactory<double>>());
  52. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observe0Greater1\"]");
  53. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  54. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  55. EXPECT_NEAR(0.3328800375801578281, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision());
  56. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observeIGreater1\"]");
  57. result = checker.check(*formula);
  58. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  59. EXPECT_NEAR(0.1522194965, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision());
  60. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"observeOnlyTrueSender\"]");
  61. result = checker.check(*formula);
  62. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  63. EXPECT_NEAR(0.32153724292835045, quantitativeResult3[0], storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision());
  64. }
  65. TEST(GmmxxDtmcPrctlModelCheckerTest, SynchronousLeader) {
  66. 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");
  67. ASSERT_EQ(abstractModel->getType(), storm::models::ModelType::Dtmc);
  68. // A parser that we use for conveniently constructing the formulas.
  69. storm::parser::FormulaParser formulaParser;
  70. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = abstractModel->as<storm::models::sparse::Dtmc<double>>();
  71. ASSERT_EQ(12400ull, dtmc->getNumberOfStates());
  72. ASSERT_EQ(16495ull, dtmc->getNumberOfTransitions());
  73. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc, std::make_unique<storm::solver::GmmxxLinearEquationSolverFactory<double>>());
  74. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("P=? [F \"elected\"]");
  75. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  76. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  77. EXPECT_NEAR(1.0, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision());
  78. formula = formulaParser.parseSingleFormulaFromString("P=? [F<=20 \"elected\"]");
  79. result = checker.check(*formula);
  80. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  81. EXPECT_NEAR(0.9999965911265462636, quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision());
  82. formula = formulaParser.parseSingleFormulaFromString("R=? [F \"elected\"]");
  83. result = checker.check(*formula);
  84. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  85. EXPECT_NEAR(1.044879046, quantitativeResult3[0], storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision());
  86. }
  87. TEST(GmmxxDtmcPrctlModelCheckerTest, LRASingleBscc) {
  88. storm::storage::SparseMatrixBuilder<double> matrixBuilder;
  89. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc;
  90. // A parser that we use for conveniently constructing the formulas.
  91. storm::parser::FormulaParser formulaParser;
  92. {
  93. matrixBuilder = storm::storage::SparseMatrixBuilder<double>(2, 2, 2);
  94. matrixBuilder.addNextValue(0, 1, 1.);
  95. matrixBuilder.addNextValue(1, 0, 1.);
  96. storm::storage::SparseMatrix<double> transitionMatrix = matrixBuilder.build();
  97. storm::models::sparse::StateLabeling ap(2);
  98. ap.addLabel("a");
  99. ap.addLabelToState("a", 1);
  100. dtmc.reset(new storm::models::sparse::Dtmc<double>(transitionMatrix, ap));
  101. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc, std::make_unique<storm::solver::GmmxxLinearEquationSolverFactory<double>>());
  102. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("LRA=? [\"a\"]");
  103. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  104. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  105. EXPECT_NEAR(.5, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  106. EXPECT_NEAR(.5, quantitativeResult1[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  107. }
  108. {
  109. matrixBuilder = storm::storage::SparseMatrixBuilder<double>(2, 2, 4);
  110. matrixBuilder.addNextValue(0, 0, .5);
  111. matrixBuilder.addNextValue(0, 1, .5);
  112. matrixBuilder.addNextValue(1, 0, .5);
  113. matrixBuilder.addNextValue(1, 1, .5);
  114. storm::storage::SparseMatrix<double> transitionMatrix = matrixBuilder.build();
  115. storm::models::sparse::StateLabeling ap(2);
  116. ap.addLabel("a");
  117. ap.addLabelToState("a", 1);
  118. dtmc.reset(new storm::models::sparse::Dtmc<double>(transitionMatrix, ap));
  119. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc, std::make_unique<storm::solver::GmmxxLinearEquationSolverFactory<double>>());
  120. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("LRA=? [\"a\"]");
  121. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  122. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  123. EXPECT_NEAR(.5, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  124. EXPECT_NEAR(.5, quantitativeResult1[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  125. }
  126. {
  127. matrixBuilder = storm::storage::SparseMatrixBuilder<double>(3, 3, 3);
  128. matrixBuilder.addNextValue(0, 1, 1);
  129. matrixBuilder.addNextValue(1, 2, 1);
  130. matrixBuilder.addNextValue(2, 0, 1);
  131. storm::storage::SparseMatrix<double> transitionMatrix = matrixBuilder.build();
  132. storm::models::sparse::StateLabeling ap(3);
  133. ap.addLabel("a");
  134. ap.addLabelToState("a", 2);
  135. dtmc.reset(new storm::models::sparse::Dtmc<double>(transitionMatrix, ap));
  136. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc, std::make_unique<storm::solver::GmmxxLinearEquationSolverFactory<double>>());
  137. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("LRA=? [\"a\"]");
  138. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  139. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  140. EXPECT_NEAR(1. / 3., quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  141. EXPECT_NEAR(1. / 3., quantitativeResult1[1], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  142. EXPECT_NEAR(1. / 3., quantitativeResult1[2], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  143. }
  144. }
  145. TEST(GmmxxDtmcPrctlModelCheckerTest, LRA) {
  146. storm::storage::SparseMatrixBuilder<double> matrixBuilder;
  147. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc;
  148. // A parser that we use for conveniently constructing the formulas.
  149. storm::parser::FormulaParser formulaParser;
  150. {
  151. matrixBuilder = storm::storage::SparseMatrixBuilder<double>(15, 15, 20, true);
  152. matrixBuilder.addNextValue(0, 1, 1);
  153. matrixBuilder.addNextValue(1, 4, 0.7);
  154. matrixBuilder.addNextValue(1, 6, 0.3);
  155. matrixBuilder.addNextValue(2, 0, 1);
  156. matrixBuilder.addNextValue(3, 5, 0.8);
  157. matrixBuilder.addNextValue(3, 9, 0.2);
  158. matrixBuilder.addNextValue(4, 3, 1);
  159. matrixBuilder.addNextValue(5, 3, 1);
  160. matrixBuilder.addNextValue(6, 7, 1);
  161. matrixBuilder.addNextValue(7, 8, 1);
  162. matrixBuilder.addNextValue(8, 6, 1);
  163. matrixBuilder.addNextValue(9, 10, 1);
  164. matrixBuilder.addNextValue(10, 9, 1);
  165. matrixBuilder.addNextValue(11, 9, 1);
  166. matrixBuilder.addNextValue(12, 5, 0.4);
  167. matrixBuilder.addNextValue(12, 8, 0.3);
  168. matrixBuilder.addNextValue(12, 11, 0.3);
  169. matrixBuilder.addNextValue(13, 7, 0.7);
  170. matrixBuilder.addNextValue(13, 12, 0.3);
  171. matrixBuilder.addNextValue(14, 12, 1);
  172. storm::storage::SparseMatrix<double> transitionMatrix = matrixBuilder.build();
  173. storm::models::sparse::StateLabeling ap(15);
  174. ap.addLabel("a");
  175. ap.addLabelToState("a", 1);
  176. ap.addLabelToState("a", 4);
  177. ap.addLabelToState("a", 5);
  178. ap.addLabelToState("a", 7);
  179. ap.addLabelToState("a", 11);
  180. ap.addLabelToState("a", 13);
  181. ap.addLabelToState("a", 14);
  182. dtmc.reset(new storm::models::sparse::Dtmc<double>(transitionMatrix, ap));
  183. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc, std::make_unique<storm::solver::GmmxxLinearEquationSolverFactory<double>>());
  184. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("LRA=? [\"a\"]");
  185. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  186. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  187. EXPECT_NEAR(0.3 / 3., quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  188. EXPECT_NEAR(0.0, quantitativeResult1[3], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  189. EXPECT_NEAR(1. / 3., quantitativeResult1[6], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  190. EXPECT_NEAR(0.0, quantitativeResult1[9], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  191. EXPECT_NEAR(0.3 / 3., quantitativeResult1[12], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  192. EXPECT_NEAR(.79 / 3., quantitativeResult1[13], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  193. EXPECT_NEAR(0.3 / 3., quantitativeResult1[14], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  194. }
  195. }
  196. TEST(GmmxxDtmcPrctlModelCheckerTest, Conditional) {
  197. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/modelchecker/test_conditional.pm");
  198. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(program, storm::generator::NextStateGeneratorOptions(true, true)).build();
  199. ASSERT_TRUE(model->getType() == storm::models::ModelType::Dtmc);
  200. ASSERT_EQ(4ul, model->getNumberOfStates());
  201. ASSERT_EQ(5ul, model->getNumberOfTransitions());
  202. std::shared_ptr<storm::models::sparse::Dtmc<double>> dtmc = model->as<storm::models::sparse::Dtmc<double>>();
  203. storm::modelchecker::SparseDtmcPrctlModelChecker<storm::models::sparse::Dtmc<double>> checker(*dtmc, std::make_unique<storm::solver::GmmxxLinearEquationSolverFactory<double>>());
  204. // A parser that we use for conveniently constructing the formulas.
  205. storm::parser::FormulaParser formulaParser;
  206. std::shared_ptr<storm::logic::Formula const> formula = formulaParser.parseSingleFormulaFromString("P=? [F \"target\"]");
  207. std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(*formula);
  208. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult1 = result->asExplicitQuantitativeCheckResult<double>();
  209. EXPECT_NEAR(0.5, quantitativeResult1[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  210. formula = formulaParser.parseSingleFormulaFromString("P=? [F \"target\" || F \"condition\"]");
  211. result = checker.check(*formula);
  212. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult2 = result->asExplicitQuantitativeCheckResult<double>();
  213. EXPECT_NEAR(storm::utility::one<double>(), quantitativeResult2[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  214. formula = formulaParser.parseSingleFormulaFromString("R=? [F \"target\"]");
  215. result = checker.check(*formula);
  216. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult3 = result->asExplicitQuantitativeCheckResult<double>();
  217. EXPECT_EQ(storm::utility::infinity<double>(), quantitativeResult3[0]);
  218. formula = formulaParser.parseSingleFormulaFromString("R=? [F \"target\" || F \"condition\"]");
  219. result = checker.check(*formula);
  220. storm::modelchecker::ExplicitQuantitativeCheckResult<double>& quantitativeResult4 = result->asExplicitQuantitativeCheckResult<double>();
  221. EXPECT_NEAR(storm::utility::one<double>(), quantitativeResult4[0], storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision());
  222. }