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.

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