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.

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