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.

134 lines
7.4 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/GeneralSettings.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/storage/dd/CuddDd.h"
  11. #include "src/storage/dd/CuddAdd.h"
  12. #include "src/storage/dd/CuddBdd.h"
  13. #include "src/parser/PrismParser.h"
  14. #include "src/builder/DdPrismModelBuilder.h"
  15. TEST(DdPrismModelBuilderTest, Dtmc) {
  16. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/die.pm");
  17. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  18. EXPECT_EQ(13ul, model->getNumberOfStates());
  19. EXPECT_EQ(20ul, model->getNumberOfTransitions());
  20. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm");
  21. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  22. EXPECT_EQ(677ul, model->getNumberOfStates());
  23. EXPECT_EQ(867ul, model->getNumberOfTransitions());
  24. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm");
  25. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  26. EXPECT_EQ(8607ul, model->getNumberOfStates());
  27. EXPECT_EQ(15113ul, model->getNumberOfTransitions());
  28. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader-3-5.pm");
  29. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  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. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  34. EXPECT_EQ(1728ul, model->getNumberOfStates());
  35. EXPECT_EQ(2505ul, model->getNumberOfTransitions());
  36. }
  37. TEST(DdPrismModelBuilderTest, Ctmc) {
  38. // Set the PRISM compatibility mode temporarily. It is set to its old value once the returned object is destructed.
  39. std::unique_ptr<storm::settings::SettingMemento> enablePrismCompatibility = storm::settings::mutableGeneralSettings().overridePrismCompatibilityMode(true);
  40. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/cluster2.sm");
  41. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  42. EXPECT_EQ(276ul, model->getNumberOfStates());
  43. EXPECT_EQ(1120ul, model->getNumberOfTransitions());
  44. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/embedded2.sm");
  45. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  46. EXPECT_EQ(3478ul, model->getNumberOfStates());
  47. EXPECT_EQ(14639ul, model->getNumberOfTransitions());
  48. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/polling2.sm");
  49. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  50. EXPECT_EQ(12ul, model->getNumberOfStates());
  51. EXPECT_EQ(22ul, model->getNumberOfTransitions());
  52. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/fms2.sm");
  53. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  54. EXPECT_EQ(810ul, model->getNumberOfStates());
  55. EXPECT_EQ(3699ul, model->getNumberOfTransitions());
  56. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/tandem5.sm");
  57. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  58. EXPECT_EQ(66ul, model->getNumberOfStates());
  59. EXPECT_EQ(189ul, model->getNumberOfTransitions());
  60. }
  61. TEST(DdPrismModelBuilderTest, Mdp) {
  62. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/two_dice.nm");
  63. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  64. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  65. std::shared_ptr<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>> mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
  66. EXPECT_EQ(169ul, mdp->getNumberOfStates());
  67. EXPECT_EQ(436ul, mdp->getNumberOfTransitions());
  68. EXPECT_EQ(254ul, mdp->getNumberOfChoices());
  69. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader3.nm");
  70. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  71. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  72. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
  73. EXPECT_EQ(364ul, mdp->getNumberOfStates());
  74. EXPECT_EQ(654ul, mdp->getNumberOfTransitions());
  75. EXPECT_EQ(573ul, mdp->getNumberOfChoices());
  76. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/coin2-2.nm");
  77. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  78. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  79. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
  80. EXPECT_EQ(272ul, mdp->getNumberOfStates());
  81. EXPECT_EQ(492ul, mdp->getNumberOfTransitions());
  82. EXPECT_EQ(400ul, mdp->getNumberOfChoices());
  83. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/csma2-2.nm");
  84. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  85. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  86. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
  87. EXPECT_EQ(1038ul, mdp->getNumberOfStates());
  88. EXPECT_EQ(1282ul, mdp->getNumberOfTransitions());
  89. EXPECT_EQ(1054ul, mdp->getNumberOfChoices());
  90. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/firewire3-0.5.nm");
  91. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  92. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  93. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
  94. EXPECT_EQ(4093ul, mdp->getNumberOfStates());
  95. EXPECT_EQ(5585ul, mdp->getNumberOfTransitions());
  96. EXPECT_EQ(5519ul, mdp->getNumberOfChoices());
  97. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/wlan0-2-2.nm");
  98. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  99. EXPECT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  100. mdp = model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>();
  101. EXPECT_EQ(37ul, mdp->getNumberOfStates());
  102. EXPECT_EQ(59ul, mdp->getNumberOfTransitions());
  103. EXPECT_EQ(59ul, mdp->getNumberOfChoices());
  104. }