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.

80 lines
4.3 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/parser/AutoParser.h"
  4. #include "src/storage/SparseMatrix.h"
  5. #include "src/storage/StronglyConnectedComponentDecomposition.h"
  6. #include "src/models/sparse/MarkovAutomaton.h"
  7. TEST(StronglyConnectedComponentDecomposition, SmallSystemFromMatrix) {
  8. storm::storage::SparseMatrixBuilder<double> matrixBuilder(6, 6);
  9. ASSERT_NO_THROW(matrixBuilder.addNextValue(0, 0, 0.3));
  10. ASSERT_NO_THROW(matrixBuilder.addNextValue(0, 5, 0.7));
  11. ASSERT_NO_THROW(matrixBuilder.addNextValue(1, 2, 1.0));
  12. ASSERT_NO_THROW(matrixBuilder.addNextValue(2, 1, 0.4));
  13. ASSERT_NO_THROW(matrixBuilder.addNextValue(2, 2, 0.3));
  14. ASSERT_NO_THROW(matrixBuilder.addNextValue(2, 3, 0.3));
  15. ASSERT_NO_THROW(matrixBuilder.addNextValue(3, 4, 1.0));
  16. ASSERT_NO_THROW(matrixBuilder.addNextValue(4, 3, 0.5));
  17. ASSERT_NO_THROW(matrixBuilder.addNextValue(4, 4, 0.5));
  18. ASSERT_NO_THROW(matrixBuilder.addNextValue(5, 1, 1.0));
  19. storm::storage::SparseMatrix<double> matrix;
  20. ASSERT_NO_THROW(matrix = matrixBuilder.build());
  21. storm::storage::BitVector allBits(6, true);
  22. storm::storage::StronglyConnectedComponentDecomposition<double> sccDecomposition;
  23. ASSERT_NO_THROW(sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(matrix, allBits, false, false));
  24. ASSERT_EQ(4ul, sccDecomposition.size());
  25. ASSERT_NO_THROW(sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(matrix, allBits, true, false));
  26. ASSERT_EQ(3ul, sccDecomposition.size());
  27. ASSERT_NO_THROW(sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(matrix, allBits, true, true));
  28. ASSERT_EQ(1ul, sccDecomposition.size());
  29. }
  30. TEST(StronglyConnectedComponentDecomposition, FullSystem1) {
  31. 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", "", "");
  32. std::shared_ptr<storm::models::sparse::MarkovAutomaton<double>> markovAutomaton = abstractModel->as<storm::models::sparse::MarkovAutomaton<double>>();
  33. storm::storage::StronglyConnectedComponentDecomposition<double> sccDecomposition;
  34. ASSERT_NO_THROW(sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(*markovAutomaton));
  35. ASSERT_EQ(5ul, sccDecomposition.size());
  36. ASSERT_NO_THROW(sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(*markovAutomaton, true));
  37. ASSERT_EQ(2ul, sccDecomposition.size());
  38. ASSERT_NO_THROW(sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(*markovAutomaton, true, true));
  39. ASSERT_EQ(2ul, sccDecomposition.size());
  40. markovAutomaton = nullptr;
  41. }
  42. TEST(StronglyConnectedComponentDecomposition, FullSystem2) {
  43. 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", "", "");
  44. std::shared_ptr<storm::models::sparse::MarkovAutomaton<double>> markovAutomaton = abstractModel->as<storm::models::sparse::MarkovAutomaton<double>>();
  45. storm::storage::StronglyConnectedComponentDecomposition<double> sccDecomposition;
  46. ASSERT_NO_THROW(sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(*markovAutomaton, true, false));
  47. ASSERT_EQ(2ul, sccDecomposition.size());
  48. // Now, because there is no ordering we have to check the contents of the MECs in a symmetrical way.
  49. storm::storage::StateBlock const& scc1 = sccDecomposition[0];
  50. storm::storage::StateBlock const& scc2 = sccDecomposition[1];
  51. storm::storage::StateBlock correctScc1 = {1, 3, 8, 9, 10};
  52. storm::storage::StateBlock correctScc2 = {4, 5, 6, 7};
  53. ASSERT_TRUE(scc1 == storm::storage::StateBlock(correctScc1.begin(), correctScc1.end()) || scc1 == storm::storage::StateBlock(correctScc2.begin(), correctScc2.end()));
  54. ASSERT_TRUE(scc2 == storm::storage::StateBlock(correctScc1.begin(), correctScc1.end()) || scc2 == storm::storage::StateBlock(correctScc2.begin(), correctScc2.end()));
  55. ASSERT_NO_THROW(sccDecomposition = storm::storage::StronglyConnectedComponentDecomposition<double>(*markovAutomaton, true, true));
  56. ASSERT_EQ(1ul, sccDecomposition.size());
  57. markovAutomaton = nullptr;
  58. }