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.

251 lines
18 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/parser/PrismParser.h"
  4. #include "src/models/symbolic/Dtmc.h"
  5. #include "src/models/symbolic/Mdp.h"
  6. #include "src/models/symbolic/StandardRewardModel.h"
  7. #include "src/models/sparse/Dtmc.h"
  8. #include "src/models/sparse/Mdp.h"
  9. #include "src/models/sparse/StandardRewardModel.h"
  10. #include "src/builder/DdPrismModelBuilder.h"
  11. #include "src/builder/ExplicitPrismModelBuilder.h"
  12. #include "src/utility/graph.h"
  13. #include "src/storage/dd/Add.h"
  14. #include "src/storage/dd/Bdd.h"
  15. #include "src/storage/dd/DdManager.h"
  16. TEST(GraphTest, SymbolicProb01_Cudd) {
  17. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm");
  18. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().translateProgram(program);
  19. ASSERT_TRUE(model->getType() == storm::models::ModelType::Dtmc);
  20. std::pair<storm::dd::Bdd<storm::dd::DdType::CUDD>, storm::dd::Bdd<storm::dd::DdType::CUDD>> statesWithProbability01;
  21. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01(*model->as<storm::models::symbolic::Dtmc<storm::dd::DdType::CUDD>>(), model->getReachableStates(), model->getStates("observe0Greater1")));
  22. EXPECT_EQ(4409ul, statesWithProbability01.first.getNonZeroCount());
  23. EXPECT_EQ(1316ul, statesWithProbability01.second.getNonZeroCount());
  24. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01(*model->as<storm::models::symbolic::Dtmc<storm::dd::DdType::CUDD>>(), model->getReachableStates(), model->getStates("observeIGreater1")));
  25. EXPECT_EQ(1091ul, statesWithProbability01.first.getNonZeroCount());
  26. EXPECT_EQ(4802ul, statesWithProbability01.second.getNonZeroCount());
  27. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01(*model->as<storm::models::symbolic::Dtmc<storm::dd::DdType::CUDD>>(), model->getReachableStates(), model->getStates("observeOnlyTrueSender")));
  28. EXPECT_EQ(5829ul, statesWithProbability01.first.getNonZeroCount());
  29. EXPECT_EQ(1032ul, statesWithProbability01.second.getNonZeroCount());
  30. }
  31. TEST(GraphTest, SymbolicProb01_Sylvan) {
  32. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm");
  33. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::Sylvan>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().translateProgram(program);
  34. ASSERT_TRUE(model->getType() == storm::models::ModelType::Dtmc);
  35. std::pair<storm::dd::Bdd<storm::dd::DdType::Sylvan>, storm::dd::Bdd<storm::dd::DdType::Sylvan>> statesWithProbability01;
  36. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01(*model->as<storm::models::symbolic::Dtmc<storm::dd::DdType::Sylvan>>(), model->getReachableStates(), model->getStates("observe0Greater1")));
  37. EXPECT_EQ(4409ul, statesWithProbability01.first.getNonZeroCount());
  38. EXPECT_EQ(1316ul, statesWithProbability01.second.getNonZeroCount());
  39. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01(*model->as<storm::models::symbolic::Dtmc<storm::dd::DdType::Sylvan>>(), model->getReachableStates(), model->getStates("observeIGreater1")));
  40. EXPECT_EQ(1091ul, statesWithProbability01.first.getNonZeroCount());
  41. EXPECT_EQ(4802ul, statesWithProbability01.second.getNonZeroCount());
  42. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01(*model->as<storm::models::symbolic::Dtmc<storm::dd::DdType::Sylvan>>(), model->getReachableStates(), model->getStates("observeOnlyTrueSender")));
  43. EXPECT_EQ(5829ul, statesWithProbability01.first.getNonZeroCount());
  44. EXPECT_EQ(1032ul, statesWithProbability01.second.getNonZeroCount());
  45. }
  46. TEST(GraphTest, SymbolicProb01MinMax_Cudd) {
  47. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader3.nm");
  48. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().translateProgram(program);
  49. ASSERT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  50. {
  51. std::pair<storm::dd::Bdd<storm::dd::DdType::CUDD>, storm::dd::Bdd<storm::dd::DdType::CUDD>> statesWithProbability01;
  52. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Min(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>(), model->getReachableStates(), model->getStates("elected")));
  53. EXPECT_EQ(0ul, statesWithProbability01.first.getNonZeroCount());
  54. EXPECT_EQ(364ul, statesWithProbability01.second.getNonZeroCount());
  55. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Max(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>(), model->getReachableStates(), model->getStates("elected")));
  56. EXPECT_EQ(0ul, statesWithProbability01.first.getNonZeroCount());
  57. EXPECT_EQ(364ul, statesWithProbability01.second.getNonZeroCount());
  58. }
  59. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/coin2-2.nm");
  60. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().translateProgram(program);
  61. ASSERT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  62. {
  63. std::pair<storm::dd::Bdd<storm::dd::DdType::CUDD>, storm::dd::Bdd<storm::dd::DdType::CUDD>> statesWithProbability01;
  64. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Min(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>(), model->getReachableStates(), model->getStates("all_coins_equal_0")));
  65. EXPECT_EQ(77ul, statesWithProbability01.first.getNonZeroCount());
  66. EXPECT_EQ(149ul, statesWithProbability01.second.getNonZeroCount());
  67. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Max(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>(), model->getReachableStates(), model->getStates("all_coins_equal_0")));
  68. EXPECT_EQ(74ul, statesWithProbability01.first.getNonZeroCount());
  69. EXPECT_EQ(198ul, statesWithProbability01.second.getNonZeroCount());
  70. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Min(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>(), model->getReachableStates(), model->getStates("all_coins_equal_1")));
  71. EXPECT_EQ(94ul, statesWithProbability01.first.getNonZeroCount());
  72. EXPECT_EQ(33ul, statesWithProbability01.second.getNonZeroCount());
  73. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Max(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>(), model->getReachableStates(), model->getStates("all_coins_equal_1")));
  74. EXPECT_EQ(83ul, statesWithProbability01.first.getNonZeroCount());
  75. EXPECT_EQ(35ul, statesWithProbability01.second.getNonZeroCount());
  76. }
  77. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/csma2-2.nm");
  78. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>().translateProgram(program);
  79. ASSERT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  80. {
  81. std::pair<storm::dd::Bdd<storm::dd::DdType::CUDD>, storm::dd::Bdd<storm::dd::DdType::CUDD>> statesWithProbability01;
  82. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Min(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>(), model->getReachableStates(), model->getStates("collision_max_backoff")));
  83. EXPECT_EQ(993ul, statesWithProbability01.first.getNonZeroCount());
  84. EXPECT_EQ(16ul, statesWithProbability01.second.getNonZeroCount());
  85. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Max(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>(), model->getReachableStates(), model->getStates("collision_max_backoff")));
  86. EXPECT_EQ(993ul, statesWithProbability01.first.getNonZeroCount());
  87. EXPECT_EQ(16ul, statesWithProbability01.second.getNonZeroCount());
  88. }
  89. }
  90. TEST(GraphTest, SymbolicProb01MinMax_Sylvan) {
  91. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader3.nm");
  92. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::Sylvan>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().translateProgram(program);
  93. ASSERT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  94. {
  95. std::pair<storm::dd::Bdd<storm::dd::DdType::Sylvan>, storm::dd::Bdd<storm::dd::DdType::Sylvan>> statesWithProbability01;
  96. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Min(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>>(), model->getReachableStates(), model->getStates("elected")));
  97. EXPECT_EQ(0ul, statesWithProbability01.first.getNonZeroCount());
  98. EXPECT_EQ(364ul, statesWithProbability01.second.getNonZeroCount());
  99. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Max(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>>(), model->getReachableStates(), model->getStates("elected")));
  100. EXPECT_EQ(0ul, statesWithProbability01.first.getNonZeroCount());
  101. EXPECT_EQ(364ul, statesWithProbability01.second.getNonZeroCount());
  102. }
  103. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/coin2-2.nm");
  104. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().translateProgram(program);
  105. ASSERT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  106. {
  107. std::pair<storm::dd::Bdd<storm::dd::DdType::Sylvan>, storm::dd::Bdd<storm::dd::DdType::Sylvan>> statesWithProbability01;
  108. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Min(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>>(), model->getReachableStates(), model->getStates("all_coins_equal_0")));
  109. EXPECT_EQ(77ul, statesWithProbability01.first.getNonZeroCount());
  110. EXPECT_EQ(149ul, statesWithProbability01.second.getNonZeroCount());
  111. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Max(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>>(), model->getReachableStates(), model->getStates("all_coins_equal_0")));
  112. EXPECT_EQ(74ul, statesWithProbability01.first.getNonZeroCount());
  113. EXPECT_EQ(198ul, statesWithProbability01.second.getNonZeroCount());
  114. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Min(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>>(), model->getReachableStates(), model->getStates("all_coins_equal_1")));
  115. EXPECT_EQ(94ul, statesWithProbability01.first.getNonZeroCount());
  116. EXPECT_EQ(33ul, statesWithProbability01.second.getNonZeroCount());
  117. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Max(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>>(), model->getReachableStates(), model->getStates("all_coins_equal_1")));
  118. EXPECT_EQ(83ul, statesWithProbability01.first.getNonZeroCount());
  119. EXPECT_EQ(35ul, statesWithProbability01.second.getNonZeroCount());
  120. }
  121. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/csma2-2.nm");
  122. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::Sylvan>().translateProgram(program);
  123. ASSERT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  124. {
  125. std::pair<storm::dd::Bdd<storm::dd::DdType::Sylvan>, storm::dd::Bdd<storm::dd::DdType::Sylvan>> statesWithProbability01;
  126. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Min(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>>(), model->getReachableStates(), model->getStates("collision_max_backoff")));
  127. EXPECT_EQ(993ul, statesWithProbability01.first.getNonZeroCount());
  128. EXPECT_EQ(16ul, statesWithProbability01.second.getNonZeroCount());
  129. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Max(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::Sylvan>>(), model->getReachableStates(), model->getStates("collision_max_backoff")));
  130. EXPECT_EQ(993ul, statesWithProbability01.first.getNonZeroCount());
  131. EXPECT_EQ(16ul, statesWithProbability01.second.getNonZeroCount());
  132. }
  133. }
  134. TEST(GraphTest, ExplicitProb01) {
  135. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm");
  136. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>(program).translate();
  137. ASSERT_TRUE(model->getType() == storm::models::ModelType::Dtmc);
  138. std::pair<storm::storage::BitVector, storm::storage::BitVector> statesWithProbability01;
  139. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01(*model->as<storm::models::sparse::Dtmc<double>>(), storm::storage::BitVector(model->getNumberOfStates(), true), model->getStates("observe0Greater1")));
  140. EXPECT_EQ(4409ul, statesWithProbability01.first.getNumberOfSetBits());
  141. EXPECT_EQ(1316ul, statesWithProbability01.second.getNumberOfSetBits());
  142. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01(*model->as<storm::models::sparse::Dtmc<double>>(), storm::storage::BitVector(model->getNumberOfStates(), true), model->getStates("observeIGreater1")));
  143. EXPECT_EQ(1091ul, statesWithProbability01.first.getNumberOfSetBits());
  144. EXPECT_EQ(4802ul, statesWithProbability01.second.getNumberOfSetBits());
  145. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01(*model->as<storm::models::sparse::Dtmc<double>>(), storm::storage::BitVector(model->getNumberOfStates(), true), model->getStates("observeOnlyTrueSender")));
  146. EXPECT_EQ(5829ul, statesWithProbability01.first.getNumberOfSetBits());
  147. EXPECT_EQ(1032ul, statesWithProbability01.second.getNumberOfSetBits());
  148. }
  149. TEST(GraphTest, ExplicitProb01MinMax) {
  150. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader3.nm");
  151. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>(program).translate();
  152. ASSERT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  153. std::pair<storm::storage::BitVector, storm::storage::BitVector> statesWithProbability01;
  154. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Min(*model->as<storm::models::sparse::Mdp<double>>(), storm::storage::BitVector(model->getNumberOfStates(), true), model->getStates("elected")));
  155. EXPECT_EQ(0ul, statesWithProbability01.first.getNumberOfSetBits());
  156. EXPECT_EQ(364ul, statesWithProbability01.second.getNumberOfSetBits());
  157. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Max(*model->as<storm::models::sparse::Mdp<double>>(), storm::storage::BitVector(model->getNumberOfStates(), true), model->getStates("elected")));
  158. EXPECT_EQ(0ul, statesWithProbability01.first.getNumberOfSetBits());
  159. EXPECT_EQ(364ul, statesWithProbability01.second.getNumberOfSetBits());
  160. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/coin2-2.nm");
  161. model = storm::builder::ExplicitPrismModelBuilder<double>(program).translate();
  162. ASSERT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  163. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Min(*model->as<storm::models::sparse::Mdp<double>>(), storm::storage::BitVector(model->getNumberOfStates(), true), model->getStates("all_coins_equal_0")));
  164. EXPECT_EQ(77ul, statesWithProbability01.first.getNumberOfSetBits());
  165. EXPECT_EQ(149ul, statesWithProbability01.second.getNumberOfSetBits());
  166. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Max(*model->as<storm::models::sparse::Mdp<double>>(), storm::storage::BitVector(model->getNumberOfStates(), true), model->getStates("all_coins_equal_0")));
  167. EXPECT_EQ(74ul, statesWithProbability01.first.getNumberOfSetBits());
  168. EXPECT_EQ(198ul, statesWithProbability01.second.getNumberOfSetBits());
  169. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Min(*model->as<storm::models::sparse::Mdp<double>>(), storm::storage::BitVector(model->getNumberOfStates(), true), model->getStates("all_coins_equal_1")));
  170. EXPECT_EQ(94ul, statesWithProbability01.first.getNumberOfSetBits());
  171. EXPECT_EQ(33ul, statesWithProbability01.second.getNumberOfSetBits());
  172. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Max(*model->as<storm::models::sparse::Mdp<double>>(), storm::storage::BitVector(model->getNumberOfStates(), true), model->getStates("all_coins_equal_1")));
  173. EXPECT_EQ(83ul, statesWithProbability01.first.getNumberOfSetBits());
  174. EXPECT_EQ(35ul, statesWithProbability01.second.getNumberOfSetBits());
  175. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/csma2-2.nm");
  176. model = storm::builder::ExplicitPrismModelBuilder<double>(program).translate();
  177. ASSERT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  178. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Min(*model->as<storm::models::sparse::Mdp<double>>(), storm::storage::BitVector(model->getNumberOfStates(), true), model->getStates("collision_max_backoff")));
  179. EXPECT_EQ(993ul, statesWithProbability01.first.getNumberOfSetBits());
  180. EXPECT_EQ(16ul, statesWithProbability01.second.getNumberOfSetBits());
  181. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Max(*model->as<storm::models::sparse::Mdp<double>>(), storm::storage::BitVector(model->getNumberOfStates(), true), model->getStates("collision_max_backoff")));
  182. EXPECT_EQ(993ul, statesWithProbability01.first.getNumberOfSetBits());
  183. EXPECT_EQ(16ul, statesWithProbability01.second.getNumberOfSetBits());
  184. }