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.

302 lines
16 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/settings/SettingMemento.h"
  4. #include "src/settings/SettingsManager.h"
  5. #include "src/settings/modules/IOSettings.h"
  6. #include "src/models/symbolic/Dtmc.h"
  7. #include "src/models/symbolic/Ctmc.h"
  8. #include "src/models/symbolic/Mdp.h"
  9. #include "src/models/symbolic/StandardRewardModel.h"
  10. #include "src/parser/PrismParser.h"
  11. #include "src/builder/DdPrismModelBuilder.h"
  12. TEST(DdPrismModelBuilderTest_Sylvan, Dtmc) {
  13. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/die.pm");
  14. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::Sylvan>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  15. EXPECT_EQ(13ul, model->getNumberOfStates());
  16. EXPECT_EQ(20ul, model->getNumberOfTransitions());
  17. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm");
  18. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  19. EXPECT_EQ(677ul, model->getNumberOfStates());
  20. EXPECT_EQ(867ul, model->getNumberOfTransitions());
  21. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm");
  22. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  23. EXPECT_EQ(8607ul, model->getNumberOfStates());
  24. EXPECT_EQ(15113ul, model->getNumberOfTransitions());
  25. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader-3-5.pm");
  26. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  27. EXPECT_EQ(273ul, model->getNumberOfStates());
  28. EXPECT_EQ(397ul, model->getNumberOfTransitions());
  29. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/nand-5-2.pm");
  30. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  31. EXPECT_EQ(1728ul, model->getNumberOfStates());
  32. EXPECT_EQ(2505ul, model->getNumberOfTransitions());
  33. }
  34. TEST(DdPrismModelBuilderTest_Cudd, Dtmc) {
  35. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/die.pm");
  36. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  37. EXPECT_EQ(13ul, model->getNumberOfStates());
  38. EXPECT_EQ(20ul, model->getNumberOfTransitions());
  39. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm");
  40. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  41. EXPECT_EQ(677ul, model->getNumberOfStates());
  42. EXPECT_EQ(867ul, model->getNumberOfTransitions());
  43. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm");
  44. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  45. EXPECT_EQ(8607ul, model->getNumberOfStates());
  46. EXPECT_EQ(15113ul, model->getNumberOfTransitions());
  47. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader-3-5.pm");
  48. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  49. EXPECT_EQ(273ul, model->getNumberOfStates());
  50. EXPECT_EQ(397ul, model->getNumberOfTransitions());
  51. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/nand-5-2.pm");
  52. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  53. EXPECT_EQ(1728ul, model->getNumberOfStates());
  54. EXPECT_EQ(2505ul, model->getNumberOfTransitions());
  55. }
  56. TEST(DdPrismModelBuilderTest_Sylvan, Ctmc) {
  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::mutableIOSettings().overridePrismCompatibilityMode(true);
  59. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/cluster2.sm");
  60. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::Sylvan>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  61. EXPECT_EQ(276ul, model->getNumberOfStates());
  62. EXPECT_EQ(1120ul, model->getNumberOfTransitions());
  63. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/embedded2.sm");
  64. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  65. EXPECT_EQ(3478ul, model->getNumberOfStates());
  66. EXPECT_EQ(14639ul, model->getNumberOfTransitions());
  67. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/polling2.sm");
  68. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  69. EXPECT_EQ(12ul, model->getNumberOfStates());
  70. EXPECT_EQ(22ul, model->getNumberOfTransitions());
  71. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/fms2.sm");
  72. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  73. EXPECT_EQ(810ul, model->getNumberOfStates());
  74. EXPECT_EQ(3699ul, model->getNumberOfTransitions());
  75. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/tandem5.sm");
  76. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  77. EXPECT_EQ(66ul, model->getNumberOfStates());
  78. EXPECT_EQ(189ul, model->getNumberOfTransitions());
  79. }
  80. TEST(DdPrismModelBuilderTest_Cudd, Ctmc) {
  81. // Set the PRISM compatibility mode temporarily. It is set to its old value once the returned object is destructed.
  82. std::unique_ptr<storm::settings::SettingMemento> enablePrismCompatibility = storm::settings::mutableIOSettings().overridePrismCompatibilityMode(true);
  83. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/cluster2.sm");
  84. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  85. EXPECT_EQ(276ul, model->getNumberOfStates());
  86. EXPECT_EQ(1120ul, model->getNumberOfTransitions());
  87. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/embedded2.sm");
  88. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  89. EXPECT_EQ(3478ul, model->getNumberOfStates());
  90. EXPECT_EQ(14639ul, model->getNumberOfTransitions());
  91. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/polling2.sm");
  92. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  93. EXPECT_EQ(12ul, model->getNumberOfStates());
  94. EXPECT_EQ(22ul, model->getNumberOfTransitions());
  95. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/fms2.sm");
  96. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  97. EXPECT_EQ(810ul, model->getNumberOfStates());
  98. EXPECT_EQ(3699ul, model->getNumberOfTransitions());
  99. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/tandem5.sm");
  100. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  101. EXPECT_EQ(66ul, model->getNumberOfStates());
  102. EXPECT_EQ(189ul, model->getNumberOfTransitions());
  103. }
  104. TEST(DdPrismModelBuilderTest_Sylvan, Mdp) {
  105. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/two_dice.nm");
  106. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::Sylvan>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  107. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  108. std::shared_ptr<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>> mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>>();
  109. EXPECT_EQ(169ul, mdp->getNumberOfStates());
  110. EXPECT_EQ(436ul, mdp->getNumberOfTransitions());
  111. EXPECT_EQ(254ul, mdp->getNumberOfChoices());
  112. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader3.nm");
  113. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  114. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  115. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>>();
  116. EXPECT_EQ(364ul, mdp->getNumberOfStates());
  117. EXPECT_EQ(654ul, mdp->getNumberOfTransitions());
  118. EXPECT_EQ(573ul, mdp->getNumberOfChoices());
  119. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/coin2-2.nm");
  120. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  121. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  122. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>>();
  123. EXPECT_EQ(272ul, mdp->getNumberOfStates());
  124. EXPECT_EQ(492ul, mdp->getNumberOfTransitions());
  125. EXPECT_EQ(400ul, mdp->getNumberOfChoices());
  126. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/csma2-2.nm");
  127. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  128. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  129. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>>();
  130. EXPECT_EQ(1038ul, mdp->getNumberOfStates());
  131. EXPECT_EQ(1282ul, mdp->getNumberOfTransitions());
  132. EXPECT_EQ(1054ul, mdp->getNumberOfChoices());
  133. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/firewire3-0.5.nm");
  134. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  135. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  136. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>>();
  137. EXPECT_EQ(4093ul, mdp->getNumberOfStates());
  138. EXPECT_EQ(5585ul, mdp->getNumberOfTransitions());
  139. EXPECT_EQ(5519ul, mdp->getNumberOfChoices());
  140. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/wlan0-2-2.nm");
  141. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  142. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  143. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>>();
  144. EXPECT_EQ(37ul, mdp->getNumberOfStates());
  145. EXPECT_EQ(59ul, mdp->getNumberOfTransitions());
  146. EXPECT_EQ(59ul, mdp->getNumberOfChoices());
  147. }
  148. TEST(DdPrismModelBuilderTest_Cudd, Mdp) {
  149. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/two_dice.nm");
  150. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  151. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  152. std::shared_ptr<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>> mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
  153. EXPECT_EQ(169ul, mdp->getNumberOfStates());
  154. EXPECT_EQ(436ul, mdp->getNumberOfTransitions());
  155. EXPECT_EQ(254ul, mdp->getNumberOfChoices());
  156. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader3.nm");
  157. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  158. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  159. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
  160. EXPECT_EQ(364ul, mdp->getNumberOfStates());
  161. EXPECT_EQ(654ul, mdp->getNumberOfTransitions());
  162. EXPECT_EQ(573ul, mdp->getNumberOfChoices());
  163. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/coin2-2.nm");
  164. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  165. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  166. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
  167. EXPECT_EQ(272ul, mdp->getNumberOfStates());
  168. EXPECT_EQ(492ul, mdp->getNumberOfTransitions());
  169. EXPECT_EQ(400ul, mdp->getNumberOfChoices());
  170. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/csma2-2.nm");
  171. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  172. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  173. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
  174. EXPECT_EQ(1038ul, mdp->getNumberOfStates());
  175. EXPECT_EQ(1282ul, mdp->getNumberOfTransitions());
  176. EXPECT_EQ(1054ul, mdp->getNumberOfChoices());
  177. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/firewire3-0.5.nm");
  178. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  179. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  180. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
  181. EXPECT_EQ(4093ul, mdp->getNumberOfStates());
  182. EXPECT_EQ(5585ul, mdp->getNumberOfTransitions());
  183. EXPECT_EQ(5519ul, mdp->getNumberOfChoices());
  184. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/wlan0-2-2.nm");
  185. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  186. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  187. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
  188. EXPECT_EQ(37ul, mdp->getNumberOfStates());
  189. EXPECT_EQ(59ul, mdp->getNumberOfTransitions());
  190. EXPECT_EQ(59ul, mdp->getNumberOfChoices());
  191. }
  192. TEST(DdPrismModelBuilderTest_Sylvan, Composition) {
  193. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/system_composition.nm");
  194. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::Sylvan>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  195. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  196. std::shared_ptr<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>> mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>>();
  197. EXPECT_EQ(21ul, mdp->getNumberOfStates());
  198. EXPECT_EQ(61ul, mdp->getNumberOfTransitions());
  199. EXPECT_EQ(61ul, mdp->getNumberOfChoices());
  200. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/system_composition2.nm");
  201. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().build(program);
  202. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  203. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>>();
  204. EXPECT_EQ(8ul, mdp->getNumberOfStates());
  205. EXPECT_EQ(21ul, mdp->getNumberOfTransitions());
  206. EXPECT_EQ(21ul, mdp->getNumberOfChoices());
  207. }
  208. TEST(DdPrismModelBuilderTest_Cudd, Composition) {
  209. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/system_composition.nm");
  210. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  211. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  212. std::shared_ptr<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>> mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
  213. EXPECT_EQ(21ul, mdp->getNumberOfStates());
  214. EXPECT_EQ(61ul, mdp->getNumberOfTransitions());
  215. EXPECT_EQ(61ul, mdp->getNumberOfChoices());
  216. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/system_composition2.nm");
  217. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().build(program);
  218. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  219. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
  220. EXPECT_EQ(8ul, mdp->getNumberOfStates());
  221. EXPECT_EQ(21ul, mdp->getNumberOfTransitions());
  222. EXPECT_EQ(21ul, mdp->getNumberOfChoices());
  223. }