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.

132 lines
5.9 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/parser/AutoParser.h"
  4. #include "src/storage/MaximalEndComponentDecomposition.h"
  5. TEST(MaximalEndComponentDecomposition, FullSystem1) {
  6. storm::parser::AutoParser<double> parser(STORM_CPP_BASE_PATH "/examples/ma/tiny/tiny1.tra", STORM_CPP_BASE_PATH "/examples/ma/tiny/tiny1.lab", "", "");
  7. std::shared_ptr<storm::models::MarkovAutomaton<double>> markovAutomaton = parser.getModel<storm::models::MarkovAutomaton<double>>();
  8. storm::storage::MaximalEndComponentDecomposition<double> mecDecomposition;
  9. ASSERT_NO_THROW(mecDecomposition = storm::storage::MaximalEndComponentDecomposition<double>(*markovAutomaton));
  10. ASSERT_EQ(2, mecDecomposition.size());
  11. // Now, because there is no ordering we have to check the contents of the MECs in a symmetrical way.
  12. storm::storage::MaximalEndComponent const& mec1 = mecDecomposition[0];
  13. if (mec1.containsState(3)) {
  14. ASSERT_TRUE(mec1.containsState(8));
  15. ASSERT_TRUE(mec1.containsState(9));
  16. ASSERT_TRUE(mec1.containsState(10));
  17. ASSERT_FALSE(mec1.containsState(0));
  18. ASSERT_FALSE(mec1.containsState(1));
  19. ASSERT_FALSE(mec1.containsState(2));
  20. ASSERT_FALSE(mec1.containsState(4));
  21. ASSERT_FALSE(mec1.containsState(5));
  22. ASSERT_FALSE(mec1.containsState(6));
  23. ASSERT_FALSE(mec1.containsState(7));
  24. } else if (mec1.containsState(4)) {
  25. ASSERT_TRUE(mec1.containsState(5));
  26. ASSERT_TRUE(mec1.containsState(6));
  27. ASSERT_TRUE(mec1.containsState(7));
  28. ASSERT_FALSE(mec1.containsState(0));
  29. ASSERT_FALSE(mec1.containsState(1));
  30. ASSERT_FALSE(mec1.containsState(2));
  31. ASSERT_FALSE(mec1.containsState(3));
  32. ASSERT_FALSE(mec1.containsState(8));
  33. ASSERT_FALSE(mec1.containsState(9));
  34. ASSERT_FALSE(mec1.containsState(10));
  35. } else {
  36. // This case must never happen as the only two existing MECs contain either 3 or 4.
  37. ASSERT_TRUE(false);
  38. }
  39. storm::storage::MaximalEndComponent const& mec2 = mecDecomposition[1];
  40. if (mec2.containsState(3)) {
  41. ASSERT_TRUE(mec2.containsState(8));
  42. ASSERT_TRUE(mec2.containsState(9));
  43. ASSERT_TRUE(mec2.containsState(10));
  44. ASSERT_FALSE(mec2.containsState(0));
  45. ASSERT_FALSE(mec2.containsState(1));
  46. ASSERT_FALSE(mec2.containsState(2));
  47. ASSERT_FALSE(mec2.containsState(4));
  48. ASSERT_FALSE(mec2.containsState(5));
  49. ASSERT_FALSE(mec2.containsState(6));
  50. ASSERT_FALSE(mec2.containsState(7));
  51. } else if (mec2.containsState(4)) {
  52. ASSERT_TRUE(mec2.containsState(5));
  53. ASSERT_TRUE(mec2.containsState(6));
  54. ASSERT_TRUE(mec2.containsState(7));
  55. ASSERT_FALSE(mec2.containsState(0));
  56. ASSERT_FALSE(mec2.containsState(1));
  57. ASSERT_FALSE(mec2.containsState(2));
  58. ASSERT_FALSE(mec2.containsState(3));
  59. ASSERT_FALSE(mec2.containsState(8));
  60. ASSERT_FALSE(mec2.containsState(9));
  61. ASSERT_FALSE(mec2.containsState(10));
  62. } else {
  63. // This case must never happen as the only two existing MECs contain either 3 or 4.
  64. ASSERT_TRUE(false);
  65. }
  66. }
  67. TEST(MaximalEndComponentDecomposition, FullSystem2) {
  68. storm::parser::AutoParser<double> parser(STORM_CPP_BASE_PATH "/examples/ma/tiny/tiny2.tra", STORM_CPP_BASE_PATH "/examples/ma/tiny/tiny2.lab", "", "");
  69. std::shared_ptr<storm::models::MarkovAutomaton<double>> markovAutomaton = parser.getModel<storm::models::MarkovAutomaton<double>>();
  70. storm::storage::MaximalEndComponentDecomposition<double> mecDecomposition;
  71. ASSERT_NO_THROW(mecDecomposition = storm::storage::MaximalEndComponentDecomposition<double>(*markovAutomaton));
  72. ASSERT_EQ(1, mecDecomposition.size());
  73. // Now, because there is no ordering we have to check the contents of the MECs in a symmetrical way.
  74. storm::storage::MaximalEndComponent const& mec1 = mecDecomposition[0];
  75. if (mec1.containsState(4)) {
  76. ASSERT_TRUE(mec1.containsState(5));
  77. ASSERT_TRUE(mec1.containsState(6));
  78. ASSERT_TRUE(mec1.containsState(7));
  79. ASSERT_FALSE(mec1.containsState(0));
  80. ASSERT_FALSE(mec1.containsState(1));
  81. ASSERT_FALSE(mec1.containsState(2));
  82. ASSERT_FALSE(mec1.containsState(3));
  83. ASSERT_FALSE(mec1.containsState(8));
  84. ASSERT_FALSE(mec1.containsState(9));
  85. ASSERT_FALSE(mec1.containsState(10));
  86. } else {
  87. // This case must never happen as the only two existing MECs contain 4.
  88. ASSERT_TRUE(false);
  89. }
  90. }
  91. TEST(MaximalEndComponentDecomposition, Subsystem) {
  92. storm::parser::AutoParser<double> parser(STORM_CPP_BASE_PATH "/examples/ma/tiny/tiny1.tra", STORM_CPP_BASE_PATH "/examples/ma/tiny/tiny1.lab", "", "");
  93. std::shared_ptr<storm::models::MarkovAutomaton<double>> markovAutomaton = parser.getModel<storm::models::MarkovAutomaton<double>>();
  94. storm::storage::BitVector subsystem(markovAutomaton->getNumberOfStates(), true);
  95. subsystem.set(7, false);
  96. storm::storage::MaximalEndComponentDecomposition<double> mecDecomposition;
  97. ASSERT_NO_THROW(mecDecomposition = storm::storage::MaximalEndComponentDecomposition<double>(*markovAutomaton, subsystem));
  98. ASSERT_EQ(1, mecDecomposition.size());
  99. storm::storage::MaximalEndComponent const& mec1 = mecDecomposition[0];
  100. if (mec1.containsState(3)) {
  101. ASSERT_TRUE(mec1.containsState(8));
  102. ASSERT_TRUE(mec1.containsState(9));
  103. ASSERT_TRUE(mec1.containsState(10));
  104. ASSERT_FALSE(mec1.containsState(0));
  105. ASSERT_FALSE(mec1.containsState(1));
  106. ASSERT_FALSE(mec1.containsState(2));
  107. ASSERT_FALSE(mec1.containsState(4));
  108. ASSERT_FALSE(mec1.containsState(5));
  109. ASSERT_FALSE(mec1.containsState(6));
  110. ASSERT_FALSE(mec1.containsState(7));
  111. } else {
  112. // This case must never happen as the only two existing MEC contains 3.
  113. ASSERT_TRUE(false);
  114. }
  115. }