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.

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