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.

77 lines
4.7 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/parser/AutoParser.h"
  4. #include "src/models/Dtmc.h"
  5. #include "src/storage/StronglyConnectedComponentDecomposition.h"
  6. #include "src/models/MarkovAutomaton.h"
  7. TEST(StronglyConnectedComponentDecomposition, FullSystem1) {
  8. std::shared_ptr<storm::models::AbstractModel<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::MarkovAutomaton<double>> markovAutomaton = abstractModel->as<storm::models::MarkovAutomaton<double>>();
  10. storm::storage::StronglyConnectedComponentDecomposition<double> sccDecomposition;
  11. ASSERT_NO_THROW(sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(*markovAutomaton));
  12. ASSERT_EQ(5, sccDecomposition.size());
  13. ASSERT_NO_THROW(sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(*markovAutomaton, true));
  14. ASSERT_EQ(2, sccDecomposition.size());
  15. ASSERT_NO_THROW(sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(*markovAutomaton, true, true));
  16. ASSERT_EQ(2, sccDecomposition.size());
  17. markovAutomaton = nullptr;
  18. }
  19. TEST(StronglyConnectedComponentDecomposition, FullSystem2) {
  20. std::shared_ptr<storm::models::AbstractModel<double>> abstractModel = storm::parser::AutoParser::parseModel(STORM_CPP_BASE_PATH "/examples/ma/tiny/tiny2.tra", STORM_CPP_BASE_PATH "/examples/ma/tiny/tiny2.lab", "", "");
  21. std::shared_ptr<storm::models::MarkovAutomaton<double>> markovAutomaton = abstractModel->as<storm::models::MarkovAutomaton<double>>();
  22. storm::storage::StronglyConnectedComponentDecomposition<double> sccDecomposition;
  23. ASSERT_NO_THROW(sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(*markovAutomaton, true, false));
  24. ASSERT_EQ(sccDecomposition.size(), 2);
  25. // Now, because there is no ordering we have to check the contents of the MECs in a symmetrical way.
  26. storm::storage::StateBlock const& scc1 = sccDecomposition[0];
  27. storm::storage::StateBlock const& scc2 = sccDecomposition[1];
  28. std::vector<uint_fast64_t> correctScc1 = {1, 3, 8, 9, 10};
  29. std::vector<uint_fast64_t> correctScc2 = {4, 5, 6, 7};
  30. ASSERT_TRUE(scc1 == storm::storage::StateBlock(correctScc1.begin(), correctScc1.end()) || scc1 == storm::storage::StateBlock(correctScc2.begin(), correctScc2.end()));
  31. ASSERT_TRUE(scc2 == storm::storage::StateBlock(correctScc1.begin(), correctScc1.end()) || scc2 == storm::storage::StateBlock(correctScc2.begin(), correctScc2.end()));
  32. ASSERT_NO_THROW(sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(*markovAutomaton, true, true));
  33. ASSERT_EQ(1, sccDecomposition.size());
  34. markovAutomaton = nullptr;
  35. }
  36. TEST(StronglyConnectedComponentDecomposition, MatrixBasedSystem) {
  37. std::shared_ptr<storm::models::Dtmc<double>> dtmc = storm::parser::AutoParser::parseModel(STORM_CPP_BASE_PATH "/examples/dtmc/scc/scc.tra", STORM_CPP_BASE_PATH "/examples/dtmc/scc/scc.lab", "", "")->as<storm::models::Dtmc<double>>();
  38. storm::storage::StronglyConnectedComponentDecomposition<double> sccDecomposition;
  39. ASSERT_NO_THROW(sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(*dtmc, true, false));
  40. ASSERT_EQ(sccDecomposition.size(), 3);
  41. // Now, because there is no ordering we have to check the contents of the MECs in a symmetrical way.
  42. storm::storage::StateBlock const& scc1 = sccDecomposition[0];
  43. storm::storage::StateBlock const& scc2 = sccDecomposition[1];
  44. storm::storage::StateBlock const& scc3 = sccDecomposition[2];
  45. std::vector<uint_fast64_t> correctScc1 = { 1, 2, 3, 4 };
  46. std::vector<uint_fast64_t> correctScc2 = { 5, 6, 7, 8 };
  47. std::vector<uint_fast64_t> correctScc3 = { 0 };
  48. ASSERT_TRUE(scc1 == storm::storage::StateBlock(correctScc1.begin(), correctScc1.end()) || scc1 == storm::storage::StateBlock(correctScc2.begin(), correctScc2.end()) || scc1 == storm::storage::StateBlock(correctScc3.begin(), correctScc3.end()));
  49. ASSERT_TRUE(scc2 == storm::storage::StateBlock(correctScc1.begin(), correctScc1.end()) || scc2 == storm::storage::StateBlock(correctScc2.begin(), correctScc2.end()) || scc2 == storm::storage::StateBlock(correctScc3.begin(), correctScc3.end()));
  50. ASSERT_TRUE(scc3 == storm::storage::StateBlock(correctScc1.begin(), correctScc1.end()) || scc3 == storm::storage::StateBlock(correctScc2.begin(), correctScc2.end()) || scc3 == storm::storage::StateBlock(correctScc3.begin(), correctScc3.end()));
  51. ASSERT_NO_THROW(sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(*dtmc, true, true));
  52. ASSERT_EQ(2, sccDecomposition.size());
  53. dtmc = nullptr;
  54. }