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.

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