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.

155 lines
12 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/storage/dd/CuddDd.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/sparse/Dtmc.h"
  8. #include "src/models/sparse/Mdp.h"
  9. #include "src/builder/DdPrismModelBuilder.h"
  10. #include "src/builder/ExplicitPrismModelBuilder.h"
  11. #include "src/utility/graph.h"
  12. TEST(GraphTest, SymbolicProb01) {
  13. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm");
  14. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  15. ASSERT_TRUE(model->getType() == storm::models::ModelType::Dtmc);
  16. std::pair<storm::dd::Bdd<storm::dd::DdType::CUDD>, storm::dd::Bdd<storm::dd::DdType::CUDD>> statesWithProbability01;
  17. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01(*model->as<storm::models::symbolic::Dtmc<storm::dd::DdType::CUDD>>(), model->getReachableStates(), model->getStates("observe0Greater1")));
  18. EXPECT_EQ(4409, statesWithProbability01.first.getNonZeroCount());
  19. EXPECT_EQ(1316, statesWithProbability01.second.getNonZeroCount());
  20. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01(*model->as<storm::models::symbolic::Dtmc<storm::dd::DdType::CUDD>>(), model->getReachableStates(), model->getStates("observeIGreater1")));
  21. EXPECT_EQ(1091, statesWithProbability01.first.getNonZeroCount());
  22. EXPECT_EQ(4802, statesWithProbability01.second.getNonZeroCount());
  23. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01(*model->as<storm::models::symbolic::Dtmc<storm::dd::DdType::CUDD>>(), model->getReachableStates(), model->getStates("observeOnlyTrueSender")));
  24. EXPECT_EQ(5829, statesWithProbability01.first.getNonZeroCount());
  25. EXPECT_EQ(1032, statesWithProbability01.second.getNonZeroCount());
  26. }
  27. TEST(GraphTest, SymbolicProb01MinMax) {
  28. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader3.nm");
  29. std::shared_ptr<storm::models::symbolic::Model<storm::dd::DdType::CUDD>> model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  30. ASSERT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  31. std::pair<storm::dd::Bdd<storm::dd::DdType::CUDD>, storm::dd::Bdd<storm::dd::DdType::CUDD>> statesWithProbability01;
  32. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Min(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>(), model->getReachableStates(), model->getStates("elected")));
  33. EXPECT_EQ(0, statesWithProbability01.first.getNonZeroCount());
  34. EXPECT_EQ(364, statesWithProbability01.second.getNonZeroCount());
  35. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Max(*model->as<storm::models::symbolic::Mdp<storm::dd::DdType::CUDD>>(), model->getReachableStates(), model->getStates("elected")));
  36. EXPECT_EQ(0, statesWithProbability01.first.getNonZeroCount());
  37. EXPECT_EQ(364, statesWithProbability01.second.getNonZeroCount());
  38. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/coin2-2.nm");
  39. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  40. ASSERT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  41. 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")));
  42. EXPECT_EQ(77, statesWithProbability01.first.getNonZeroCount());
  43. EXPECT_EQ(149, statesWithProbability01.second.getNonZeroCount());
  44. 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")));
  45. EXPECT_EQ(74, statesWithProbability01.first.getNonZeroCount());
  46. EXPECT_EQ(198, statesWithProbability01.second.getNonZeroCount());
  47. 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")));
  48. EXPECT_EQ(94, statesWithProbability01.first.getNonZeroCount());
  49. EXPECT_EQ(33, statesWithProbability01.second.getNonZeroCount());
  50. 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")));
  51. EXPECT_EQ(83, statesWithProbability01.first.getNonZeroCount());
  52. EXPECT_EQ(35, statesWithProbability01.second.getNonZeroCount());
  53. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/csma2-2.nm");
  54. model = storm::builder::DdPrismModelBuilder<storm::dd::DdType::CUDD>::translateProgram(program);
  55. ASSERT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  56. 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")));
  57. EXPECT_EQ(993, statesWithProbability01.first.getNonZeroCount());
  58. EXPECT_EQ(16, 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("collision_max_backoff")));
  60. EXPECT_EQ(993, statesWithProbability01.first.getNonZeroCount());
  61. EXPECT_EQ(16, statesWithProbability01.second.getNonZeroCount());
  62. }
  63. TEST(GraphTest, ExplicitProb01) {
  64. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/crowds-5-5.pm");
  65. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>::translateProgram(program);
  66. ASSERT_TRUE(model->getType() == storm::models::ModelType::Dtmc);
  67. std::pair<storm::storage::BitVector, storm::storage::BitVector> statesWithProbability01;
  68. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01(*model->as<storm::models::sparse::Dtmc<double>>(), storm::storage::BitVector(model->getNumberOfStates(), true), model->getStates("observe0Greater1")));
  69. EXPECT_EQ(4409, statesWithProbability01.first.getNumberOfSetBits());
  70. EXPECT_EQ(1316, statesWithProbability01.second.getNumberOfSetBits());
  71. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01(*model->as<storm::models::sparse::Dtmc<double>>(), storm::storage::BitVector(model->getNumberOfStates(), true), model->getStates("observeIGreater1")));
  72. EXPECT_EQ(1091, statesWithProbability01.first.getNumberOfSetBits());
  73. EXPECT_EQ(4802, statesWithProbability01.second.getNumberOfSetBits());
  74. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01(*model->as<storm::models::sparse::Dtmc<double>>(), storm::storage::BitVector(model->getNumberOfStates(), true), model->getStates("observeOnlyTrueSender")));
  75. EXPECT_EQ(5829, statesWithProbability01.first.getNumberOfSetBits());
  76. EXPECT_EQ(1032, statesWithProbability01.second.getNumberOfSetBits());
  77. }
  78. TEST(GraphTest, ExplicitProb01MinMax) {
  79. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/leader3.nm");
  80. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>::translateProgram(program);
  81. ASSERT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  82. std::pair<storm::storage::BitVector, storm::storage::BitVector> statesWithProbability01;
  83. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Min(*model->as<storm::models::sparse::Mdp<double>>(), storm::storage::BitVector(model->getNumberOfStates(), true), model->getStates("elected")));
  84. EXPECT_EQ(0, statesWithProbability01.first.getNumberOfSetBits());
  85. EXPECT_EQ(364, statesWithProbability01.second.getNumberOfSetBits());
  86. ASSERT_NO_THROW(statesWithProbability01 = storm::utility::graph::performProb01Max(*model->as<storm::models::sparse::Mdp<double>>(), storm::storage::BitVector(model->getNumberOfStates(), true), model->getStates("elected")));
  87. EXPECT_EQ(0, statesWithProbability01.first.getNumberOfSetBits());
  88. EXPECT_EQ(364, statesWithProbability01.second.getNumberOfSetBits());
  89. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/coin2-2.nm");
  90. model = storm::builder::ExplicitPrismModelBuilder<double>::translateProgram(program);
  91. ASSERT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  92. 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")));
  93. EXPECT_EQ(77, statesWithProbability01.first.getNumberOfSetBits());
  94. EXPECT_EQ(149, statesWithProbability01.second.getNumberOfSetBits());
  95. 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")));
  96. EXPECT_EQ(74, statesWithProbability01.first.getNumberOfSetBits());
  97. EXPECT_EQ(198, statesWithProbability01.second.getNumberOfSetBits());
  98. 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")));
  99. EXPECT_EQ(94, statesWithProbability01.first.getNumberOfSetBits());
  100. EXPECT_EQ(33, statesWithProbability01.second.getNumberOfSetBits());
  101. 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")));
  102. EXPECT_EQ(83, statesWithProbability01.first.getNumberOfSetBits());
  103. EXPECT_EQ(35, statesWithProbability01.second.getNumberOfSetBits());
  104. program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/csma2-2.nm");
  105. model = storm::builder::ExplicitPrismModelBuilder<double>::translateProgram(program);
  106. ASSERT_TRUE(model->getType() == storm::models::ModelType::Mdp);
  107. 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")));
  108. EXPECT_EQ(993, statesWithProbability01.first.getNumberOfSetBits());
  109. EXPECT_EQ(16, statesWithProbability01.second.getNumberOfSetBits());
  110. 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")));
  111. EXPECT_EQ(993, statesWithProbability01.first.getNumberOfSetBits());
  112. EXPECT_EQ(16, statesWithProbability01.second.getNumberOfSetBits());
  113. }