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.

76 lines
3.7 KiB

  1. #include "gtest/gtest.h"
  2. #include "src/transformer/NeutralECRemover.h"
  3. TEST(NeutralECRemover, SimpleModelTest) {
  4. storm::storage::SparseMatrixBuilder<double> builder(12, 5, 19, true, true, 5);
  5. ASSERT_NO_THROW(builder.newRowGroup(0));
  6. ASSERT_NO_THROW(builder.addNextValue(0, 0, 1.0));
  7. ASSERT_NO_THROW(builder.addNextValue(1, 1, 0.3));
  8. ASSERT_NO_THROW(builder.addNextValue(1, 2, 0.1));
  9. ASSERT_NO_THROW(builder.addNextValue(1, 3, 0.4));
  10. ASSERT_NO_THROW(builder.addNextValue(1, 4, 0.2));
  11. ASSERT_NO_THROW(builder.newRowGroup(2));
  12. ASSERT_NO_THROW(builder.addNextValue(2, 1, 0.7));
  13. ASSERT_NO_THROW(builder.addNextValue(2, 3, 0.3));
  14. ASSERT_NO_THROW(builder.addNextValue(3, 1, 0.1));
  15. ASSERT_NO_THROW(builder.addNextValue(3, 4, 0.9));
  16. ASSERT_NO_THROW(builder.addNextValue(4, 1, 0.2));
  17. ASSERT_NO_THROW(builder.addNextValue(4, 4, 0.8));
  18. ASSERT_NO_THROW(builder.newRowGroup(5));
  19. ASSERT_NO_THROW(builder.addNextValue(5, 2, 1.0));
  20. ASSERT_NO_THROW(builder.newRowGroup(6));
  21. ASSERT_NO_THROW(builder.addNextValue(6, 1, 1.0));
  22. ASSERT_NO_THROW(builder.addNextValue(7, 2, 1.0));
  23. ASSERT_NO_THROW(builder.addNextValue(8, 3, 1.0));
  24. ASSERT_NO_THROW(builder.newRowGroup(9));
  25. ASSERT_NO_THROW(builder.addNextValue(9, 4, 1.0));
  26. ASSERT_NO_THROW(builder.addNextValue(10, 1, 0.4));
  27. ASSERT_NO_THROW(builder.addNextValue(10, 4, 0.6));
  28. ASSERT_NO_THROW(builder.addNextValue(11, 3, 1));
  29. storm::storage::SparseMatrix<double> matrix;
  30. ASSERT_NO_THROW(matrix = builder.build());
  31. std::vector<double> vector = {0.0, 0.0, 0.0, -12.0, 0.0, 0.0, 42.0, 1.0, 2.7, 0.0, 0.0, -1.0};
  32. storm::storage::BitVector allowEmptyRows(5, true);
  33. allowEmptyRows.set(1, false);
  34. allowEmptyRows.set(4, false);
  35. auto res = storm::transformer::NeutralECRemover<double>::transform(matrix, vector, allowEmptyRows);
  36. // Expected data
  37. storm::storage::SparseMatrixBuilder<double> expectedBuilder(8, 3, 8, true, true, 3);
  38. ASSERT_NO_THROW(expectedBuilder.newRowGroup(0));
  39. ASSERT_NO_THROW(expectedBuilder.addNextValue(0, 2, 1.0));
  40. ASSERT_NO_THROW(expectedBuilder.addNextValue(2, 0, 1.0));
  41. ASSERT_NO_THROW(expectedBuilder.newRowGroup(3));
  42. ASSERT_NO_THROW(expectedBuilder.addNextValue(3, 0, 0.4));
  43. ASSERT_NO_THROW(expectedBuilder.addNextValue(3, 2, 0.5));
  44. ASSERT_NO_THROW(expectedBuilder.newRowGroup(5));
  45. ASSERT_NO_THROW(expectedBuilder.addNextValue(5, 0, 1.0));
  46. ASSERT_NO_THROW(expectedBuilder.addNextValue(6, 0, 0.3));
  47. ASSERT_NO_THROW(expectedBuilder.addNextValue(6, 2, 0.7));
  48. ASSERT_NO_THROW(expectedBuilder.addNextValue(7, 2, 1.0));
  49. storm::storage::SparseMatrix<double> expectedMatrix;
  50. ASSERT_NO_THROW(expectedMatrix = expectedBuilder.build());
  51. std::vector<double> expectedVector = {42.0, 1.0, 2.7, 0.0, 0.0, -1.0, 0.0, -12.0};
  52. std::vector<uint_fast64_t> expectedNewToOldRowMapping = {6,7,8,1,0,11,2,3};
  53. std::vector<uint_fast64_t> expectedOldToNewStateMapping = {1,2,std::numeric_limits<uint_fast64_t>::max(), 0, 2};
  54. // Note that there are other possible solutions that yield equivalent matrices / vectors.
  55. // In particular, the ordering within the row groups depends on the MEC decomposition implementation.
  56. // However, this is not checked here...
  57. EXPECT_EQ(expectedMatrix, res.matrix);
  58. EXPECT_EQ(expectedVector, res.vector);
  59. EXPECT_EQ(expectedNewToOldRowMapping, res.newToOldRowMapping);
  60. EXPECT_EQ(expectedOldToNewStateMapping, res.oldToNewStateMapping);
  61. //std::cout << "Original matrix:" << std::endl << matrix << std::endl << std::endl << "Computation Result: " << std::endl << res.matrix << std::endl<< std::endl << "expected Matrix" << std::endl<< expectedMatrix << std::endl;
  62. }