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.

327 lines
17 KiB

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