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.

164 lines
9.0 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/models/sparse/StandardRewardModel.h"
  4. #include "src/models/sparse/MarkovAutomaton.h"
  5. #include "src/settings/SettingMemento.h"
  6. #include "src/parser/PrismParser.h"
  7. #include "src/builder/ExplicitModelBuilder.h"
  8. #include "src/generator/JaniNextStateGenerator.h"
  9. #include "src/storage/jani/Model.h"
  10. #include "src/settings/modules/IOSettings.h"
  11. TEST(ExplicitJaniModelBuilderTest, Dtmc) {
  12. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/die.pm");
  13. storm::jani::Model janiModel = program.toJani();
  14. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  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. janiModel = program.toJani();
  19. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  20. EXPECT_EQ(677ul, model->getNumberOfStates());
  21. EXPECT_EQ(867ul, model->getNumberOfTransitions());
  22. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm");
  23. janiModel = program.toJani();
  24. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  25. EXPECT_EQ(8607ul, model->getNumberOfStates());
  26. EXPECT_EQ(15113ul, model->getNumberOfTransitions());
  27. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader-3-5.pm");
  28. janiModel = program.toJani();
  29. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  30. EXPECT_EQ(273ul, model->getNumberOfStates());
  31. EXPECT_EQ(397ul, model->getNumberOfTransitions());
  32. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/nand-5-2.pm");
  33. janiModel = program.toJani();
  34. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  35. EXPECT_EQ(1728ul, model->getNumberOfStates());
  36. EXPECT_EQ(2505ul, model->getNumberOfTransitions());
  37. }
  38. TEST(ExplicitJaniModelBuilderTest, Ctmc) {
  39. // Set the PRISM compatibility mode temporarily. It is set to its old value once the returned object is destructed.
  40. std::unique_ptr<storm::settings::SettingMemento> enablePrismCompatibility = storm::settings::mutableIOSettings().overridePrismCompatibilityMode(true);
  41. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/cluster2.sm");
  42. storm::jani::Model janiModel = program.toJani();
  43. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  44. EXPECT_EQ(276ul, model->getNumberOfStates());
  45. EXPECT_EQ(1120ul, model->getNumberOfTransitions());
  46. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/embedded2.sm");
  47. janiModel = program.toJani();
  48. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  49. EXPECT_EQ(3478ul, model->getNumberOfStates());
  50. EXPECT_EQ(14639ul, model->getNumberOfTransitions());
  51. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/polling2.sm");
  52. janiModel = program.toJani();
  53. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  54. EXPECT_EQ(12ul, model->getNumberOfStates());
  55. EXPECT_EQ(22ul, model->getNumberOfTransitions());
  56. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/fms2.sm");
  57. janiModel = program.toJani();
  58. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  59. EXPECT_EQ(810ul, model->getNumberOfStates());
  60. EXPECT_EQ(3699ul, model->getNumberOfTransitions());
  61. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/tandem5.sm");
  62. janiModel = program.toJani();
  63. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  64. EXPECT_EQ(66ul, model->getNumberOfStates());
  65. EXPECT_EQ(189ul, model->getNumberOfTransitions());
  66. }
  67. TEST(ExplicitJaniModelBuilderTest, Mdp) {
  68. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/two_dice.nm");
  69. storm::jani::Model janiModel = program.toJani();
  70. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  71. EXPECT_EQ(169ul, model->getNumberOfStates());
  72. EXPECT_EQ(436ul, model->getNumberOfTransitions());
  73. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader3.nm");
  74. janiModel = program.toJani();
  75. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  76. EXPECT_EQ(364ul, model->getNumberOfStates());
  77. EXPECT_EQ(654ul, model->getNumberOfTransitions());
  78. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/coin2-2.nm");
  79. janiModel = program.toJani();
  80. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  81. EXPECT_EQ(272ul, model->getNumberOfStates());
  82. EXPECT_EQ(492ul, model->getNumberOfTransitions());
  83. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/csma2-2.nm");
  84. janiModel = program.toJani();
  85. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  86. EXPECT_EQ(1038ul, model->getNumberOfStates());
  87. EXPECT_EQ(1282ul, model->getNumberOfTransitions());
  88. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/firewire3-0.5.nm");
  89. janiModel = program.toJani();
  90. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  91. EXPECT_EQ(4093ul, model->getNumberOfStates());
  92. EXPECT_EQ(5585ul, model->getNumberOfTransitions());
  93. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/wlan0-2-2.nm");
  94. janiModel = program.toJani();
  95. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  96. EXPECT_EQ(37ul, model->getNumberOfStates());
  97. EXPECT_EQ(59ul, model->getNumberOfTransitions());
  98. }
  99. TEST(ExplicitJaniModelBuilderTest, Ma) {
  100. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/simple.ma");
  101. storm::jani::Model janiModel = program.toJani();
  102. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  103. EXPECT_EQ(5ul, model->getNumberOfStates());
  104. EXPECT_EQ(8ul, model->getNumberOfTransitions());
  105. ASSERT_TRUE(model->isOfType(storm::models::ModelType::MarkovAutomaton));
  106. EXPECT_EQ(4ul, model->as<storm::models::sparse::MarkovAutomaton<double>>()->getMarkovianStates().getNumberOfSetBits());
  107. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/hybrid_states.ma");
  108. janiModel = program.toJani();
  109. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  110. EXPECT_EQ(5ul, model->getNumberOfStates());
  111. EXPECT_EQ(13ul, model->getNumberOfTransitions());
  112. ASSERT_TRUE(model->isOfType(storm::models::ModelType::MarkovAutomaton));
  113. EXPECT_EQ(5ul, model->as<storm::models::sparse::MarkovAutomaton<double>>()->getMarkovianStates().getNumberOfSetBits());
  114. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/stream2.ma");
  115. janiModel = program.toJani();
  116. model = storm::builder::ExplicitModelBuilder<double>(janiModel).build();
  117. EXPECT_EQ(12ul, model->getNumberOfStates());
  118. EXPECT_EQ(14ul, model->getNumberOfTransitions());
  119. ASSERT_TRUE(model->isOfType(storm::models::ModelType::MarkovAutomaton));
  120. EXPECT_EQ(7ul, model->as<storm::models::sparse::MarkovAutomaton<double>>()->getMarkovianStates().getNumberOfSetBits());
  121. }
  122. TEST(ExplicitJaniModelBuilderTest, FailComposition) {
  123. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/system_composition.nm");
  124. storm::jani::Model janiModel = program.toJani();
  125. ASSERT_THROW(storm::builder::ExplicitModelBuilder<double>(janiModel).build(), storm::exceptions::WrongFormatException);
  126. }
  127. TEST(ExplicitJaniModelBuilderTest, IllegalSynchronizingWrites) {
  128. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/coin2-2-illegalSynchronizingWrite.nm");
  129. storm::jani::Model janiModel = program.toJani();
  130. storm::generator::NextStateGeneratorOptions options;
  131. options.setExplorationChecks(true);
  132. std::shared_ptr<storm::generator::NextStateGenerator<double, uint32_t>> nextStateGenerator = std::make_shared<storm::generator::JaniNextStateGenerator<double, uint32_t>>(janiModel, options);
  133. ASSERT_THROW(storm::builder::ExplicitModelBuilder<double>(nextStateGenerator).build(), storm::exceptions::WrongFormatException);
  134. }