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.

131 lines
7.4 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/settings/modules/IOSettings.h"
  9. TEST(ExplicitPrismModelBuilderTest, Dtmc) {
  10. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/die.pm");
  11. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(program).build();
  12. EXPECT_EQ(13ul, model->getNumberOfStates());
  13. EXPECT_EQ(20ul, model->getNumberOfTransitions());
  14. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm");
  15. model = storm::builder::ExplicitModelBuilder<double>(program).build();
  16. EXPECT_EQ(677ul, model->getNumberOfStates());
  17. EXPECT_EQ(867ul, model->getNumberOfTransitions());
  18. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm");
  19. model = storm::builder::ExplicitModelBuilder<double>(program).build();
  20. EXPECT_EQ(8607ul, model->getNumberOfStates());
  21. EXPECT_EQ(15113ul, model->getNumberOfTransitions());
  22. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader-3-5.pm");
  23. model = storm::builder::ExplicitModelBuilder<double>(program).build();
  24. EXPECT_EQ(273ul, model->getNumberOfStates());
  25. EXPECT_EQ(397ul, model->getNumberOfTransitions());
  26. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/nand-5-2.pm");
  27. model = storm::builder::ExplicitModelBuilder<double>(program).build();
  28. EXPECT_EQ(1728ul, model->getNumberOfStates());
  29. EXPECT_EQ(2505ul, model->getNumberOfTransitions());
  30. }
  31. TEST(ExplicitPrismModelBuilderTest, Ctmc) {
  32. // Set the PRISM compatibility mode temporarily. It is set to its old value once the returned object is destructed.
  33. std::unique_ptr<storm::settings::SettingMemento> enablePrismCompatibility = storm::settings::mutableIOSettings().overridePrismCompatibilityMode(true);
  34. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/cluster2.sm");
  35. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(program).build();
  36. EXPECT_EQ(276ul, model->getNumberOfStates());
  37. EXPECT_EQ(1120ul, model->getNumberOfTransitions());
  38. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/embedded2.sm");
  39. model = storm::builder::ExplicitModelBuilder<double>(program).build();
  40. EXPECT_EQ(3478ul, model->getNumberOfStates());
  41. EXPECT_EQ(14639ul, model->getNumberOfTransitions());
  42. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/polling2.sm");
  43. model = storm::builder::ExplicitModelBuilder<double>(program).build();
  44. EXPECT_EQ(12ul, model->getNumberOfStates());
  45. EXPECT_EQ(22ul, model->getNumberOfTransitions());
  46. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/fms2.sm");
  47. model = storm::builder::ExplicitModelBuilder<double>(program).build();
  48. EXPECT_EQ(810ul, model->getNumberOfStates());
  49. EXPECT_EQ(3699ul, model->getNumberOfTransitions());
  50. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/tandem5.sm");
  51. model = storm::builder::ExplicitModelBuilder<double>(program).build();
  52. EXPECT_EQ(66ul, model->getNumberOfStates());
  53. EXPECT_EQ(189ul, model->getNumberOfTransitions());
  54. }
  55. TEST(ExplicitPrismModelBuilderTest, Mdp) {
  56. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/two_dice.nm");
  57. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(program).build();
  58. EXPECT_EQ(169ul, model->getNumberOfStates());
  59. EXPECT_EQ(436ul, model->getNumberOfTransitions());
  60. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader3.nm");
  61. model = storm::builder::ExplicitModelBuilder<double>(program).build();
  62. EXPECT_EQ(364ul, model->getNumberOfStates());
  63. EXPECT_EQ(654ul, model->getNumberOfTransitions());
  64. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/coin2-2.nm");
  65. model = storm::builder::ExplicitModelBuilder<double>(program).build();
  66. EXPECT_EQ(272ul, model->getNumberOfStates());
  67. EXPECT_EQ(492ul, model->getNumberOfTransitions());
  68. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/csma2-2.nm");
  69. model = storm::builder::ExplicitModelBuilder<double>(program).build();
  70. EXPECT_EQ(1038ul, model->getNumberOfStates());
  71. EXPECT_EQ(1282ul, model->getNumberOfTransitions());
  72. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/firewire3-0.5.nm");
  73. model = storm::builder::ExplicitModelBuilder<double>(program).build();
  74. EXPECT_EQ(4093ul, model->getNumberOfStates());
  75. EXPECT_EQ(5585ul, model->getNumberOfTransitions());
  76. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/wlan0-2-2.nm");
  77. model = storm::builder::ExplicitModelBuilder<double>(program).build();
  78. EXPECT_EQ(37ul, model->getNumberOfStates());
  79. EXPECT_EQ(59ul, model->getNumberOfTransitions());
  80. }
  81. TEST(ExplicitPrismModelBuilderTest, Ma) {
  82. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/simple.ma");
  83. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(program).build();
  84. EXPECT_EQ(5ul, model->getNumberOfStates());
  85. EXPECT_EQ(8ul, model->getNumberOfTransitions());
  86. ASSERT_TRUE(model->isOfType(storm::models::ModelType::MarkovAutomaton));
  87. EXPECT_EQ(4ul, model->as<storm::models::sparse::MarkovAutomaton<double>>()->getMarkovianStates().getNumberOfSetBits());
  88. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/hybrid_states.ma");
  89. model = storm::builder::ExplicitModelBuilder<double>(program).build();
  90. EXPECT_EQ(5ul, model->getNumberOfStates());
  91. EXPECT_EQ(13ul, model->getNumberOfTransitions());
  92. ASSERT_TRUE(model->isOfType(storm::models::ModelType::MarkovAutomaton));
  93. EXPECT_EQ(5ul, model->as<storm::models::sparse::MarkovAutomaton<double>>()->getMarkovianStates().getNumberOfSetBits());
  94. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/stream2.ma");
  95. model = storm::builder::ExplicitModelBuilder<double>(program).build();
  96. EXPECT_EQ(12ul, model->getNumberOfStates());
  97. EXPECT_EQ(14ul, model->getNumberOfTransitions());
  98. ASSERT_TRUE(model->isOfType(storm::models::ModelType::MarkovAutomaton));
  99. EXPECT_EQ(7ul, model->as<storm::models::sparse::MarkovAutomaton<double>>()->getMarkovianStates().getNumberOfSetBits());
  100. }
  101. TEST(ExplicitPrismModelBuilderTest, FailComposition) {
  102. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/system_composition.nm");
  103. ASSERT_THROW(storm::builder::ExplicitModelBuilder<double>(program).build(), storm::exceptions::WrongFormatException);
  104. }