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.

265 lines
20 KiB

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