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.

283 lines
18 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/solver/GmmxxLinearEquationSolver.h"
  9. #include "src/modelchecker/csl/SparseCtmcCslModelChecker.h"
  10. #include "src/modelchecker/results/ExplicitQuantitativeCheckResult.h"
  11. #include "src/settings/SettingsManager.h"
  12. TEST(GmmxxCtmcCslModelCheckerTest, 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. #ifdef WINDOWS
  21. storm::builder::ExplicitPrismModelBuilder<double>::Options options;
  22. #else
  23. typename storm::builder::ExplicitPrismModelBuilder<double>::Options options;
  24. #endif
  25. options.buildRewards = true;
  26. options.rewardModelName = "num_repairs";
  27. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>::translateProgram(program, options);
  28. ASSERT_EQ(storm::models::ModelType::Ctmc, model->getType());
  29. std::shared_ptr<storm::models::sparse::Ctmc<double>> ctmc = model->as<storm::models::sparse::Ctmc<double>>();
  30. uint_fast64_t initialState = *ctmc->getInitialStates().begin();
  31. // Create model checker.
  32. storm::modelchecker::SparseCtmcCslModelChecker<double> modelchecker(*ctmc, std::unique_ptr<storm::utility::solver::LinearEquationSolverFactory<double>>(new storm::utility::solver::GmmxxLinearEquationSolverFactory<double>()));
  33. // Start checking properties.
  34. formula = formulaParser.parseFromString("P=? [ F<=100 !\"minimum\"]");
  35. std::unique_ptr<storm::modelchecker::CheckResult> checkResult = modelchecker.check(*formula);
  36. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  37. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult1 = checkResult->asExplicitQuantitativeCheckResult<double>();
  38. EXPECT_NEAR(5.5461254704419085E-5, quantitativeCheckResult1[initialState], storm::settings::generalSettings().getPrecision());
  39. formula = formulaParser.parseFromString("P=? [ F[100,100] !\"minimum\"]");
  40. checkResult = modelchecker.check(*formula);
  41. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  42. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult2 = checkResult->asExplicitQuantitativeCheckResult<double>();
  43. EXPECT_NEAR(2.3397873548343415E-6, quantitativeCheckResult2[initialState], storm::settings::generalSettings().getPrecision());
  44. formula = formulaParser.parseFromString("P=? [ F[100,2000] !\"minimum\"]");
  45. checkResult = modelchecker.check(*formula);
  46. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  47. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult3 = checkResult->asExplicitQuantitativeCheckResult<double>();
  48. EXPECT_NEAR(0.001105335651670241, quantitativeCheckResult3[initialState], storm::settings::generalSettings().getPrecision());
  49. formula = formulaParser.parseFromString("P=? [ \"minimum\" U<=10 \"premium\"]");
  50. checkResult = modelchecker.check(*formula);
  51. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  52. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult4 = checkResult->asExplicitQuantitativeCheckResult<double>();
  53. EXPECT_NEAR(1, quantitativeCheckResult4[initialState], storm::settings::generalSettings().getPrecision());
  54. formula = formulaParser.parseFromString("P=? [ !\"minimum\" U[1,inf] \"minimum\"]");
  55. checkResult = modelchecker.check(*formula);
  56. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  57. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult5 = checkResult->asExplicitQuantitativeCheckResult<double>();
  58. EXPECT_NEAR(0, quantitativeCheckResult5[initialState], storm::settings::generalSettings().getPrecision());
  59. formula = formulaParser.parseFromString("P=? [ \"minimum\" U[1,inf] !\"minimum\"]");
  60. checkResult = modelchecker.check(*formula);
  61. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  62. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult6 = checkResult->asExplicitQuantitativeCheckResult<double>();
  63. EXPECT_NEAR(0.9999999033633374, quantitativeCheckResult6[initialState], storm::settings::generalSettings().getPrecision());
  64. formula = formulaParser.parseFromString("R=? [C<=100]");
  65. checkResult = modelchecker.check(*formula);
  66. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  67. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult7 = checkResult->asExplicitQuantitativeCheckResult<double>();
  68. EXPECT_NEAR(0.8602815057967503, quantitativeCheckResult7[initialState], storm::settings::generalSettings().getPrecision());
  69. formula = formulaParser.parseFromString("LRA=? [\"minimum\"]");
  70. checkResult = modelchecker.check(*formula);
  71. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  72. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult8 = checkResult->asExplicitQuantitativeCheckResult<double>();
  73. EXPECT_NEAR(0.99999766034263426, quantitativeCheckResult8[initialState], storm::settings::generalSettings().getPrecision());
  74. }
  75. TEST(GmmxxCtmcCslModelCheckerTest, Embedded) {
  76. // Set the PRISM compatibility mode temporarily. It is set to its old value once the returned object is destructed.
  77. std::unique_ptr<storm::settings::SettingMemento> enablePrismCompatibility = storm::settings::mutableGeneralSettings().overridePrismCompatibilityMode(true);
  78. // Parse the model description.
  79. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/embedded2.sm");
  80. storm::parser::FormulaParser formulaParser(program.getManager().getSharedPointer());
  81. std::shared_ptr<storm::logic::Formula> formula(nullptr);
  82. // Build the model.
  83. #ifdef WINDOWS
  84. storm::builder::ExplicitPrismModelBuilder<double>::Options options;
  85. #else
  86. typename storm::builder::ExplicitPrismModelBuilder<double>::Options options;
  87. #endif
  88. options.buildRewards = true;
  89. options.rewardModelName = "up";
  90. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>::translateProgram(program, options);
  91. ASSERT_EQ(storm::models::ModelType::Ctmc, model->getType());
  92. std::shared_ptr<storm::models::sparse::Ctmc<double>> ctmc = model->as<storm::models::sparse::Ctmc<double>>();
  93. uint_fast64_t initialState = *ctmc->getInitialStates().begin();
  94. // Create model checker.
  95. storm::modelchecker::SparseCtmcCslModelChecker<double> modelchecker(*ctmc, std::unique_ptr<storm::utility::solver::LinearEquationSolverFactory<double>>(new storm::utility::solver::GmmxxLinearEquationSolverFactory<double>()));
  96. // Start checking properties.
  97. formula = formulaParser.parseFromString("P=? [ F<=10000 \"down\"]");
  98. std::unique_ptr<storm::modelchecker::CheckResult> checkResult = modelchecker.check(*formula);
  99. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  100. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult1 = checkResult->asExplicitQuantitativeCheckResult<double>();
  101. EXPECT_NEAR(0.0019216435246119591, quantitativeCheckResult1[initialState], storm::settings::generalSettings().getPrecision());
  102. formula = formulaParser.parseFromString("P=? [ !\"down\" U<=10000 \"fail_actuators\"]");
  103. checkResult = modelchecker.check(*formula);
  104. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  105. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult2 = checkResult->asExplicitQuantitativeCheckResult<double>();
  106. EXPECT_NEAR(3.7079151806696567E-6, quantitativeCheckResult2[initialState], storm::settings::generalSettings().getPrecision());
  107. formula = formulaParser.parseFromString("P=? [ !\"down\" U<=10000 \"fail_io\"]");
  108. checkResult = modelchecker.check(*formula);
  109. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  110. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult3 = checkResult->asExplicitQuantitativeCheckResult<double>();
  111. EXPECT_NEAR(0.001556839327673734, quantitativeCheckResult3[initialState], storm::settings::generalSettings().getPrecision());
  112. formula = formulaParser.parseFromString("P=? [ !\"down\" U<=10000 \"fail_sensors\"]");
  113. checkResult = modelchecker.check(*formula);
  114. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  115. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult4 = checkResult->asExplicitQuantitativeCheckResult<double>();
  116. EXPECT_NEAR(4.429620626755424E-5, quantitativeCheckResult4[initialState], storm::settings::generalSettings().getPrecision());
  117. formula = formulaParser.parseFromString("R=? [C<=10000]");
  118. checkResult = modelchecker.check(*formula);
  119. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  120. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult5 = checkResult->asExplicitQuantitativeCheckResult<double>();
  121. EXPECT_NEAR(2.7745274082080154, quantitativeCheckResult5[initialState], storm::settings::generalSettings().getPrecision());
  122. formula = formulaParser.parseFromString("LRA=? [\"fail_sensors\"]");
  123. checkResult = modelchecker.check(*formula);
  124. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  125. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult6 = checkResult->asExplicitQuantitativeCheckResult<double>();
  126. EXPECT_NEAR(0.93458866427696596, quantitativeCheckResult6[initialState], storm::settings::generalSettings().getPrecision());
  127. }
  128. TEST(GmmxxCtmcCslModelCheckerTest, Polling) {
  129. // Set the PRISM compatibility mode temporarily. It is set to its old value once the returned object is destructed.
  130. std::unique_ptr<storm::settings::SettingMemento> enablePrismCompatibility = storm::settings::mutableGeneralSettings().overridePrismCompatibilityMode(true);
  131. // Parse the model description.
  132. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/polling2.sm");
  133. storm::parser::FormulaParser formulaParser(program.getManager().getSharedPointer());
  134. std::shared_ptr<storm::logic::Formula> formula(nullptr);
  135. // Build the model.
  136. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>::translateProgram(program);
  137. ASSERT_EQ(storm::models::ModelType::Ctmc, model->getType());
  138. std::shared_ptr<storm::models::sparse::Ctmc<double>> ctmc = model->as<storm::models::sparse::Ctmc<double>>();
  139. uint_fast64_t initialState = *ctmc->getInitialStates().begin();
  140. // Create model checker.
  141. storm::modelchecker::SparseCtmcCslModelChecker<double> modelchecker(*ctmc, std::unique_ptr<storm::utility::solver::LinearEquationSolverFactory<double>>(new storm::utility::solver::GmmxxLinearEquationSolverFactory<double>()));
  142. // Start checking properties.
  143. formula = formulaParser.parseFromString("P=?[ F<=10 \"target\"]");
  144. std::unique_ptr<storm::modelchecker::CheckResult> checkResult = modelchecker.check(*formula);
  145. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  146. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult1 = checkResult->asExplicitQuantitativeCheckResult<double>();
  147. EXPECT_NEAR(1, quantitativeCheckResult1[initialState], storm::settings::generalSettings().getPrecision());
  148. formula = formulaParser.parseFromString("LRA=?[\"target\"]");
  149. checkResult = modelchecker.check(*formula);
  150. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  151. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult2 = checkResult->asExplicitQuantitativeCheckResult<double>();
  152. EXPECT_NEAR(0.20079750055570736, quantitativeCheckResult2[initialState], storm::settings::generalSettings().getPrecision());
  153. }
  154. TEST(GmmxxCtmcCslModelCheckerTest, Fms) {
  155. // Set the PRISM compatibility mode temporarily. It is set to its old value once the returned object is destructed.
  156. std::unique_ptr<storm::settings::SettingMemento> enablePrismCompatibility = storm::settings::mutableGeneralSettings().overridePrismCompatibilityMode(true);
  157. // No properties to check at this point.
  158. }
  159. TEST(GmmxxCtmcCslModelCheckerTest, Tandem) {
  160. // Set the PRISM compatibility mode temporarily. It is set to its old value once the returned object is destructed.
  161. std::unique_ptr<storm::settings::SettingMemento> enablePrismCompatibility = storm::settings::mutableGeneralSettings().overridePrismCompatibilityMode(true);
  162. // Parse the model description.
  163. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/tandem5.sm");
  164. storm::parser::FormulaParser formulaParser(program.getManager().getSharedPointer());
  165. std::shared_ptr<storm::logic::Formula> formula(nullptr);
  166. // Build the model.
  167. #ifdef WINDOWS
  168. storm::builder::ExplicitPrismModelBuilder<double>::Options options;
  169. #else
  170. typename storm::builder::ExplicitPrismModelBuilder<double>::Options options;
  171. #endif
  172. options.buildRewards = true;
  173. options.rewardModelName = "customers";
  174. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>::translateProgram(program, options);
  175. ASSERT_EQ(storm::models::ModelType::Ctmc, model->getType());
  176. std::shared_ptr<storm::models::sparse::Ctmc<double>> ctmc = model->as<storm::models::sparse::Ctmc<double>>();
  177. uint_fast64_t initialState = *ctmc->getInitialStates().begin();
  178. // Create model checker.
  179. storm::modelchecker::SparseCtmcCslModelChecker<double> modelchecker(*ctmc, std::unique_ptr<storm::utility::solver::LinearEquationSolverFactory<double>>(new storm::utility::solver::GmmxxLinearEquationSolverFactory<double>()));
  180. // Start checking properties.
  181. formula = formulaParser.parseFromString("P=? [ F<=10 \"network_full\" ]");
  182. std::unique_ptr<storm::modelchecker::CheckResult> checkResult = modelchecker.check(*formula);
  183. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  184. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult1 = checkResult->asExplicitQuantitativeCheckResult<double>();
  185. EXPECT_NEAR(0.015446370562428037, quantitativeCheckResult1[initialState], storm::settings::generalSettings().getPrecision());
  186. formula = formulaParser.parseFromString("P=? [ F<=10 \"first_queue_full\" ]");
  187. checkResult = modelchecker.check(*formula);
  188. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  189. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult2 = checkResult->asExplicitQuantitativeCheckResult<double>();
  190. EXPECT_NEAR(0.999999837225515, quantitativeCheckResult2[initialState], storm::settings::generalSettings().getPrecision());
  191. formula = formulaParser.parseFromString("P=? [\"second_queue_full\" U<=1 !\"second_queue_full\"]");
  192. checkResult = modelchecker.check(*formula);
  193. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  194. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult3 = checkResult->asExplicitQuantitativeCheckResult<double>();
  195. EXPECT_NEAR(1, quantitativeCheckResult3[initialState], storm::settings::generalSettings().getPrecision());
  196. formula = formulaParser.parseFromString("R=? [I=10]");
  197. checkResult = modelchecker.check(*formula);
  198. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  199. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult4 = checkResult->asExplicitQuantitativeCheckResult<double>();
  200. EXPECT_NEAR(5.679243850315877, quantitativeCheckResult4[initialState], storm::settings::generalSettings().getPrecision());
  201. formula = formulaParser.parseFromString("R=? [C<=10]");
  202. checkResult = modelchecker.check(*formula);
  203. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  204. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult5 = checkResult->asExplicitQuantitativeCheckResult<double>();
  205. EXPECT_NEAR(55.44792186036232, quantitativeCheckResult5[initialState], storm::settings::generalSettings().getPrecision());
  206. formula = formulaParser.parseFromString("R=? [F \"first_queue_full\"&\"second_queue_full\"]");
  207. checkResult = modelchecker.check(*formula);
  208. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  209. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult6 = checkResult->asExplicitQuantitativeCheckResult<double>();
  210. EXPECT_NEAR(262.85103661561755, quantitativeCheckResult6[initialState], storm::settings::generalSettings().getPrecision());
  211. formula = formulaParser.parseFromString("LRA=? [\"first_queue_full\"]");
  212. checkResult = modelchecker.check(*formula);
  213. ASSERT_TRUE(checkResult->isExplicitQuantitativeCheckResult());
  214. storm::modelchecker::ExplicitQuantitativeCheckResult<double> quantitativeCheckResult7 = checkResult->asExplicitQuantitativeCheckResult<double>();
  215. EXPECT_NEAR(0.9100373532, quantitativeCheckResult7[initialState], storm::settings::generalSettings().getPrecision());
  216. }