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.

157 lines
8.1 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/settings/Settings.h"
  4. #include "src/parser/AutoParser.h"
  5. #include "src/utility/graph.h"
  6. #include "src/storage/StronglyConnectedComponentDecomposition.h"
  7. TEST(GraphTest, PerformProb01) {
  8. storm::parser::AutoParser<double> parser(STORM_CPP_BASE_PATH "/examples/dtmc/crowds/crowds20_5.tra", STORM_CPP_BASE_PATH "/examples/dtmc/crowds/crowds20_5.lab", "", "");
  9. std::shared_ptr<storm::models::Dtmc<double>> dtmc = parser.getModel<storm::models::Dtmc<double>>();
  10. storm::storage::BitVector trueStates(dtmc->getNumberOfStates(), true);
  11. LOG4CPLUS_WARN(logger, "Computing prob01 (3 times) for crowds/crowds20_5...");
  12. std::pair<storm::storage::BitVector, storm::storage::BitVector> prob01(storm::utility::graph::performProb01(*dtmc, trueStates, storm::storage::BitVector(dtmc->getLabeledStates("observe0Greater1"))));
  13. ASSERT_EQ(prob01.first.getNumberOfSetBits(), 1724414ull);
  14. ASSERT_EQ(prob01.second.getNumberOfSetBits(), 46046ull);
  15. prob01 = storm::utility::graph::performProb01(*dtmc, trueStates, storm::storage::BitVector(dtmc->getLabeledStates("observeIGreater1")));
  16. ASSERT_EQ(prob01.first.getNumberOfSetBits(), 574016ull);
  17. ASSERT_EQ(prob01.second.getNumberOfSetBits(), 825797ull);
  18. prob01 = storm::utility::graph::performProb01(*dtmc, trueStates, storm::storage::BitVector(dtmc->getLabeledStates("observeOnlyTrueSender")));
  19. ASSERT_EQ(prob01.first.getNumberOfSetBits(), 1785309ull);
  20. ASSERT_EQ(prob01.second.getNumberOfSetBits(), 40992ull);
  21. LOG4CPLUS_WARN(logger, "Done.");
  22. dtmc = nullptr;
  23. storm::parser::AutoParser<double> parser2(STORM_CPP_BASE_PATH "/examples/dtmc/synchronous_leader/leader6_8.tra", STORM_CPP_BASE_PATH "/examples/dtmc/synchronous_leader/leader6_8.lab", "", "");
  24. std::shared_ptr<storm::models::Dtmc<double>> dtmc2 = parser2.getModel<storm::models::Dtmc<double>>();
  25. trueStates = storm::storage::BitVector(dtmc2->getNumberOfStates(), true);
  26. LOG4CPLUS_WARN(logger, "Computing prob01 for synchronous_leader/leader6_8...");
  27. prob01 = storm::utility::graph::performProb01(*dtmc2, trueStates, storm::storage::BitVector(dtmc2->getLabeledStates("elected")));
  28. LOG4CPLUS_WARN(logger, "Done.");
  29. ASSERT_EQ(prob01.first.getNumberOfSetBits(), 0ull);
  30. ASSERT_EQ(prob01.second.getNumberOfSetBits(), 1312334ull);
  31. dtmc2 = nullptr;
  32. }
  33. TEST(GraphTest, PerformProb01MinMax) {
  34. storm::parser::AutoParser<double> parser(STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader7.tra", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader7.lab", "", "");
  35. std::shared_ptr<storm::models::Mdp<double>> mdp = parser.getModel<storm::models::Mdp<double>>();
  36. storm::storage::BitVector trueStates(mdp->getNumberOfStates(), true);
  37. LOG4CPLUS_WARN(logger, "Computing prob01min for asynchronous_leader/leader7...");
  38. std::pair<storm::storage::BitVector, storm::storage::BitVector> prob01(storm::utility::graph::performProb01Min(*mdp, trueStates, mdp->getLabeledStates("elected")));
  39. LOG4CPLUS_WARN(logger, "Done.");
  40. ASSERT_EQ(prob01.first.getNumberOfSetBits(), 0ull);
  41. ASSERT_EQ(prob01.second.getNumberOfSetBits(), 2095783ull);
  42. LOG4CPLUS_WARN(logger, "Computing prob01max for asynchronous_leader/leader7...");
  43. prob01 = storm::utility::graph::performProb01Max(*mdp, trueStates, mdp->getLabeledStates("elected"));
  44. LOG4CPLUS_WARN(logger, "Done.");
  45. ASSERT_EQ(prob01.first.getNumberOfSetBits(), 0ull);
  46. ASSERT_EQ(prob01.second.getNumberOfSetBits(), 2095783ull);
  47. mdp = nullptr;
  48. storm::parser::AutoParser<double> parser2(STORM_CPP_BASE_PATH "/examples/mdp/consensus/coin4_6.tra", STORM_CPP_BASE_PATH "/examples/mdp/consensus/coin4_6.lab", "", "");
  49. std::shared_ptr<storm::models::Mdp<double>> mdp2 = parser2.getModel<storm::models::Mdp<double>>();
  50. trueStates = storm::storage::BitVector(mdp2->getNumberOfStates(), true);
  51. LOG4CPLUS_WARN(logger, "Computing prob01min for consensus/coin4_6...");
  52. prob01 = storm::utility::graph::performProb01Min(*mdp2, trueStates, mdp2->getLabeledStates("finished"));
  53. LOG4CPLUS_WARN(logger, "Done.");
  54. ASSERT_EQ(prob01.first.getNumberOfSetBits(), 0ull);
  55. ASSERT_EQ(prob01.second.getNumberOfSetBits(), 63616ull);
  56. LOG4CPLUS_WARN(logger, "Computing prob01max for consensus/coin4_6...");
  57. prob01 = storm::utility::graph::performProb01Max(*mdp2, trueStates, mdp2->getLabeledStates("finished"));
  58. LOG4CPLUS_WARN(logger, "Done.");
  59. ASSERT_EQ(prob01.first.getNumberOfSetBits(), 0ull);
  60. ASSERT_EQ(prob01.second.getNumberOfSetBits(), 63616ull);
  61. mdp2 = nullptr;
  62. }
  63. TEST(GraphTest, PerformSCCDecompositionAndGetDependencyGraph) {
  64. storm::parser::AutoParser<double> parser(STORM_CPP_BASE_PATH "/examples/dtmc/crowds/crowds20_5.tra", STORM_CPP_BASE_PATH "/examples/dtmc/crowds/crowds20_5.lab", "", "");
  65. std::shared_ptr<storm::models::Dtmc<double>> dtmc = parser.getModel<storm::models::Dtmc<double>>();
  66. LOG4CPLUS_WARN(logger, "Computing SCC decomposition of crowds/crowds20_5...");
  67. storm::storage::StronglyConnectedComponentDecomposition<double> sccDecomposition(*dtmc);
  68. LOG4CPLUS_WARN(logger, "Done.");
  69. ASSERT_EQ(sccDecomposition.size(), 1290297ull);
  70. LOG4CPLUS_WARN(logger, "Extracting SCC dependency graph of crowds/crowds20_5...");
  71. storm::storage::SparseMatrix<bool> sccDependencyGraph(std::move(dtmc->extractPartitionDependencyGraph(sccDecomposition)));
  72. LOG4CPLUS_WARN(logger, "Done.");
  73. ASSERT_EQ(sccDependencyGraph.getNonZeroEntryCount(), 1371253ull);
  74. dtmc = nullptr;
  75. storm::parser::AutoParser<double> parser2(STORM_CPP_BASE_PATH "/examples/dtmc/synchronous_leader/leader6_8.tra", STORM_CPP_BASE_PATH "/examples/dtmc/synchronous_leader/leader6_8.lab", "", "");
  76. std::shared_ptr<storm::models::Dtmc<double>> dtmc2 = parser2.getModel<storm::models::Dtmc<double>>();
  77. LOG4CPLUS_WARN(logger, "Computing SCC decomposition of synchronous_leader/leader6_8...");
  78. sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(*dtmc2);
  79. LOG4CPLUS_WARN(logger, "Done.");
  80. ASSERT_EQ(sccDecomposition.size(), 1279673ull);
  81. LOG4CPLUS_WARN(logger, "Extracting SCC dependency graph of synchronous_leader/leader6_8...");
  82. sccDependencyGraph = std::move(dtmc2->extractPartitionDependencyGraph(sccDecomposition));
  83. LOG4CPLUS_WARN(logger, "Done.");
  84. ASSERT_EQ(sccDependencyGraph.getNonZeroEntryCount(), 1535367ull);
  85. dtmc2 = nullptr;
  86. storm::parser::AutoParser<double> parser3(STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader6.tra", STORM_CPP_BASE_PATH "/examples/mdp/asynchronous_leader/leader6.lab", "", "");
  87. std::shared_ptr<storm::models::Mdp<double>> mdp = parser3.getModel<storm::models::Mdp<double>>();
  88. LOG4CPLUS_WARN(logger, "Computing SCC decomposition of asynchronous_leader/leader6...");
  89. sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(*mdp);
  90. LOG4CPLUS_WARN(logger, "Done.");
  91. ASSERT_EQ(sccDecomposition.size(), 146844ull);
  92. LOG4CPLUS_WARN(logger, "Extracting SCC dependency graph of asynchronous_leader/leader6...");
  93. sccDependencyGraph = std::move(mdp->extractPartitionDependencyGraph(sccDecomposition));
  94. LOG4CPLUS_WARN(logger, "Done.");
  95. ASSERT_EQ(sccDependencyGraph.getNonZeroEntryCount(), 489918ull);
  96. mdp = nullptr;
  97. storm::parser::AutoParser<double> parser4(STORM_CPP_BASE_PATH "/examples/mdp/consensus/coin4_6.tra", STORM_CPP_BASE_PATH "/examples/mdp/consensus/coin4_6.lab", "", "");
  98. std::shared_ptr<storm::models::Mdp<double>> mdp2 = parser4.getModel<storm::models::Mdp<double>>();
  99. LOG4CPLUS_WARN(logger, "Computing SCC decomposition of consensus/coin4_6...");
  100. sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(*mdp2);
  101. LOG4CPLUS_WARN(logger, "Done.");
  102. ASSERT_EQ(sccDecomposition.size(), 2611ull);
  103. LOG4CPLUS_WARN(logger, "Extracting SCC dependency graph of consensus/coin4_6...");
  104. sccDependencyGraph = std::move(mdp2->extractPartitionDependencyGraph(sccDecomposition));
  105. LOG4CPLUS_WARN(logger, "Done.");
  106. ASSERT_EQ(sccDependencyGraph.getNonZeroEntryCount(), 7888ull);
  107. mdp2 = nullptr;
  108. }