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.

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