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