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.

134 lines
6.2 KiB

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