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.

228 lines
15 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/settings/SettingMemento.h"
  4. #include "src/parser/PrismParser.h"
  5. #include "src/parser/FormulaParser.h"
  6. #include "src/logic/Formulas.h"
  7. #include "src/builder/ExplicitPrismModelBuilder.h"
  8. #include "src/utility/solver.h"
  9. #include "src/modelchecker/csl/SparseCtmcCslModelChecker.h"
  10. #include "src/modelchecker/results/ExplicitQuantitativeCheckResult.h"
  11. #include "src/settings/SettingsManager.h"
  12. TEST(SparseCtmcCslModelCheckerTest, Cluster) {
  13. // Set the PRISM compatibility mode temporarily. It is set to its old value once the returned object is destructed.
  14. std::unique_ptr<storm::settings::SettingMemento> enablePrismCompatibility = storm::settings::mutableGeneralSettings().overridePrismCompatibilityMode(true);
  15. // Parse the model description.
  16. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/cluster2.sm");
  17. storm::parser::FormulaParser formulaParser(program.getManager().getSharedPointer());
  18. std::shared_ptr<storm::logic::Formula> formula(nullptr);
  19. // Build the model.
  20. typename storm::builder::ExplicitPrismModelBuilder<double>::Options options;
  21. options.buildRewards = true;
  22. options.rewardModelName = "num_repairs";
  23. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>::translateProgram(program, options);
  24. ASSERT_EQ(storm::models::ModelType::Ctmc, model->getType());
  25. std::shared_ptr<storm::models::sparse::Ctmc<double>> ctmc = model->as<storm::models::sparse::Ctmc<double>>();
  26. uint_fast64_t initialState = *ctmc->getInitialStates().begin();
  27. // Create model checker.
  28. storm::modelchecker::SparseCtmcCslModelChecker<double> modelchecker(*ctmc, std::unique_ptr<storm::utility::solver::LinearEquationSolverFactory<double>>(new storm::utility::solver::NativeLinearEquationSolverFactory<double>()));
  29. // Start checking properties.
  30. formula = formulaParser.parseFromString("P=? [ F<=100 !\"minimum\"]");
  31. std::unique_ptr<storm::modelchecker::CheckResult> checkResult = modelchecker.check(*formula);
  32. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  33. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult1 = checkResult->asExplicitQuantitativeCheckResult<double>();
  34. EXPECT_NEAR(5.5461254704419085E-5, quantitativeCheckResult1[initialState], storm::settings::generalSettings().getPrecision());
  35. formula = formulaParser.parseFromString("P=? [ F[100,100] !\"minimum\"]");
  36. checkResult = modelchecker.check(*formula);
  37. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  38. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult2 = checkResult->asExplicitQuantitativeCheckResult<double>();
  39. EXPECT_NEAR(2.3397873548343415E-6, quantitativeCheckResult2[initialState], storm::settings::generalSettings().getPrecision());
  40. formula = formulaParser.parseFromString("P=? [ \"minimum\" U<=10 \"premium\"]");
  41. checkResult = modelchecker.check(*formula);
  42. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  43. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult3 = checkResult->asExplicitQuantitativeCheckResult<double>();
  44. EXPECT_NEAR(1, quantitativeCheckResult3[initialState], storm::settings::generalSettings().getPrecision());
  45. formula = formulaParser.parseFromString("P=? [ !\"minimum\" U[1,inf] \"minimum\"]");
  46. checkResult = modelchecker.check(*formula);
  47. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  48. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult4 = checkResult->asExplicitQuantitativeCheckResult<double>();
  49. EXPECT_NEAR(0, quantitativeCheckResult4[initialState], storm::settings::generalSettings().getPrecision());
  50. formula = formulaParser.parseFromString("R=? [C<=100]");
  51. checkResult = modelchecker.check(*formula);
  52. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  53. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult5 = checkResult->asExplicitQuantitativeCheckResult<double>();
  54. EXPECT_NEAR(0.8602815057967503, quantitativeCheckResult5[initialState], storm::settings::generalSettings().getPrecision());
  55. }
  56. TEST(SparseCtmcCslModelCheckerTest, Embedded) {
  57. // Set the PRISM compatibility mode temporarily. It is set to its old value once the returned object is destructed.
  58. std::unique_ptr<storm::settings::SettingMemento> enablePrismCompatibility = storm::settings::mutableGeneralSettings().overridePrismCompatibilityMode(true);
  59. // Parse the model description.
  60. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/embedded2.sm");
  61. storm::parser::FormulaParser formulaParser(program.getManager().getSharedPointer());
  62. std::shared_ptr<storm::logic::Formula> formula(nullptr);
  63. // Build the model.
  64. typename storm::builder::ExplicitPrismModelBuilder<double>::Options options;
  65. options.buildRewards = true;
  66. options.rewardModelName = "up";
  67. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>::translateProgram(program, options);
  68. ASSERT_EQ(storm::models::ModelType::Ctmc, model->getType());
  69. std::shared_ptr<storm::models::sparse::Ctmc<double>> ctmc = model->as<storm::models::sparse::Ctmc<double>>();
  70. uint_fast64_t initialState = *ctmc->getInitialStates().begin();
  71. // Create model checker.
  72. storm::modelchecker::SparseCtmcCslModelChecker<double> modelchecker(*ctmc, std::unique_ptr<storm::utility::solver::LinearEquationSolverFactory<double>>(new storm::utility::solver::NativeLinearEquationSolverFactory<double>()));
  73. // Start checking properties.
  74. formula = formulaParser.parseFromString("P=? [ F<=10000 \"down\"]");
  75. std::unique_ptr<storm::modelchecker::CheckResult> checkResult = modelchecker.check(*formula);
  76. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  77. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult1 = checkResult->asExplicitQuantitativeCheckResult<double>();
  78. EXPECT_NEAR(0.0019216435246119591, quantitativeCheckResult1[initialState], storm::settings::generalSettings().getPrecision());
  79. formula = formulaParser.parseFromString("P=? [ !\"down\" U<=10000 \"fail_actuators\"]");
  80. checkResult = modelchecker.check(*formula);
  81. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  82. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult2 = checkResult->asExplicitQuantitativeCheckResult<double>();
  83. EXPECT_NEAR(3.7079151806696567E-6, quantitativeCheckResult2[initialState], storm::settings::generalSettings().getPrecision());
  84. formula = formulaParser.parseFromString("P=? [ !\"down\" U<=10000 \"fail_io\"]");
  85. checkResult = modelchecker.check(*formula);
  86. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  87. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult3 = checkResult->asExplicitQuantitativeCheckResult<double>();
  88. EXPECT_NEAR(0.001556839327673734, quantitativeCheckResult3[initialState], storm::settings::generalSettings().getPrecision());
  89. formula = formulaParser.parseFromString("P=? [ !\"down\" U<=10000 \"fail_sensors\"]");
  90. checkResult = modelchecker.check(*formula);
  91. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  92. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult4 = checkResult->asExplicitQuantitativeCheckResult<double>();
  93. EXPECT_NEAR(4.429620626755424E-5, quantitativeCheckResult4[initialState], storm::settings::generalSettings().getPrecision());
  94. formula = formulaParser.parseFromString("R=? [C<=10000]");
  95. checkResult = modelchecker.check(*formula);
  96. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  97. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult5 = checkResult->asExplicitQuantitativeCheckResult<double>();
  98. EXPECT_NEAR(2.7720429852369946, quantitativeCheckResult5[initialState], storm::settings::generalSettings().getPrecision());
  99. }
  100. TEST(SparseCtmcCslModelCheckerTest, Polling) {
  101. // Set the PRISM compatibility mode temporarily. It is set to its old value once the returned object is destructed.
  102. std::unique_ptr<storm::settings::SettingMemento> enablePrismCompatibility = storm::settings::mutableGeneralSettings().overridePrismCompatibilityMode(true);
  103. // Parse the model description.
  104. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/polling2.sm");
  105. storm::parser::FormulaParser formulaParser(program.getManager().getSharedPointer());
  106. std::shared_ptr<storm::logic::Formula> formula(nullptr);
  107. // Build the model.
  108. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>::translateProgram(program);
  109. ASSERT_EQ(storm::models::ModelType::Ctmc, model->getType());
  110. std::shared_ptr<storm::models::sparse::Ctmc<double>> ctmc = model->as<storm::models::sparse::Ctmc<double>>();
  111. uint_fast64_t initialState = *ctmc->getInitialStates().begin();
  112. // Create model checker.
  113. storm::modelchecker::SparseCtmcCslModelChecker<double> modelchecker(*ctmc, std::unique_ptr<storm::utility::solver::LinearEquationSolverFactory<double>>(new storm::utility::solver::NativeLinearEquationSolverFactory<double>()));
  114. // Start checking properties.
  115. formula = formulaParser.parseFromString("P=?[ F<=10 \"target\"]");
  116. std::unique_ptr<storm::modelchecker::CheckResult> checkResult = modelchecker.check(*formula);
  117. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  118. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult1 = checkResult->asExplicitQuantitativeCheckResult<double>();
  119. EXPECT_NEAR(1, quantitativeCheckResult1[initialState], storm::settings::generalSettings().getPrecision());
  120. }
  121. TEST(SparseCtmcCslModelCheckerTest, Fms) {
  122. // Set the PRISM compatibility mode temporarily. It is set to its old value once the returned object is destructed.
  123. std::unique_ptr<storm::settings::SettingMemento> enablePrismCompatibility = storm::settings::mutableGeneralSettings().overridePrismCompatibilityMode(true);
  124. // No properties to check at this point.
  125. }
  126. TEST(SparseCtmcCslModelCheckerTest, Tandem) {
  127. // Set the PRISM compatibility mode temporarily. It is set to its old value once the returned object is destructed.
  128. std::unique_ptr<storm::settings::SettingMemento> enablePrismCompatibility = storm::settings::mutableGeneralSettings().overridePrismCompatibilityMode(true);
  129. // Parse the model description.
  130. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/tandem5.sm");
  131. storm::parser::FormulaParser formulaParser(program.getManager().getSharedPointer());
  132. std::shared_ptr<storm::logic::Formula> formula(nullptr);
  133. // Build the model with the customers reward structure.
  134. typename storm::builder::ExplicitPrismModelBuilder<double>::Options options;
  135. options.buildRewards = true;
  136. options.rewardModelName = "customers";
  137. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>::translateProgram(program, options);
  138. ASSERT_EQ(storm::models::ModelType::Ctmc, model->getType());
  139. std::shared_ptr<storm::models::sparse::Ctmc<double>> ctmc = model->as<storm::models::sparse::Ctmc<double>>();
  140. uint_fast64_t initialState = *ctmc->getInitialStates().begin();
  141. // Create model checker.
  142. storm::modelchecker::SparseCtmcCslModelChecker<double> modelchecker(*ctmc, std::unique_ptr<storm::utility::solver::LinearEquationSolverFactory<double>>(new storm::utility::solver::NativeLinearEquationSolverFactory<double>()));
  143. // Start checking properties.
  144. formula = formulaParser.parseFromString("P=? [ F<=10 \"network_full\" ]");
  145. std::unique_ptr<storm::modelchecker::CheckResult> checkResult = modelchecker.check(*formula);
  146. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  147. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult1 = checkResult->asExplicitQuantitativeCheckResult<double>();
  148. EXPECT_NEAR(0.015446370562428037, quantitativeCheckResult1[initialState], storm::settings::generalSettings().getPrecision());
  149. formula = formulaParser.parseFromString("P=? [ F<=10 \"first_queue_full\" ]");
  150. checkResult = modelchecker.check(*formula);
  151. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  152. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult2 = checkResult->asExplicitQuantitativeCheckResult<double>();
  153. EXPECT_NEAR(0.999999837225515, quantitativeCheckResult2[initialState], storm::settings::generalSettings().getPrecision());
  154. formula = formulaParser.parseFromString("P=? [\"second_queue_full\" U<=1 !\"second_queue_full\"]");
  155. checkResult = modelchecker.check(*formula);
  156. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  157. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult3 = checkResult->asExplicitQuantitativeCheckResult<double>();
  158. EXPECT_NEAR(1, quantitativeCheckResult3[initialState], storm::settings::generalSettings().getPrecision());
  159. formula = formulaParser.parseFromString("R=? [I=10]");
  160. checkResult = modelchecker.check(*formula);
  161. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  162. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult4 = checkResult->asExplicitQuantitativeCheckResult<double>();
  163. EXPECT_NEAR(5.679243850315877, quantitativeCheckResult4[initialState], storm::settings::generalSettings().getPrecision());
  164. formula = formulaParser.parseFromString("R=? [C<=10]");
  165. checkResult = modelchecker.check(*formula);
  166. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  167. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult5 = checkResult->asExplicitQuantitativeCheckResult<double>();
  168. EXPECT_NEAR(55.44792186036232, quantitativeCheckResult5[initialState], storm::settings::generalSettings().getPrecision());
  169. formula = formulaParser.parseFromString("R=? [F \"first_queue_full\"&\"second_queue_full\"]");
  170. checkResult = modelchecker.check(*formula);
  171. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  172. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult6 = checkResult->asExplicitQuantitativeCheckResult<double>();
  173. EXPECT_NEAR(262.78584491454814, quantitativeCheckResult6[initialState], storm::settings::generalSettings().getPrecision());
  174. }