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.

156 lines
8.0 KiB

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