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.

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