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.

57 lines
2.4 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/solver/EliminationLinearEquationSolver.h"
  4. #include "src/settings/SettingsManager.h"
  5. #include "src/settings/modules/GmmxxEquationSolverSettings.h"
  6. TEST(EliminationLinearEquationSolver, Solve) {
  7. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  8. storm::storage::SparseMatrixBuilder<double> builder;
  9. ASSERT_NO_THROW(builder.addNextValue(0, 0, 2));
  10. ASSERT_NO_THROW(builder.addNextValue(0, 1, 4));
  11. ASSERT_NO_THROW(builder.addNextValue(0, 2, -2));
  12. ASSERT_NO_THROW(builder.addNextValue(1, 0, 4));
  13. ASSERT_NO_THROW(builder.addNextValue(1, 1, -1));
  14. ASSERT_NO_THROW(builder.addNextValue(1, 2, 5));
  15. ASSERT_NO_THROW(builder.addNextValue(2, 0, -1));
  16. ASSERT_NO_THROW(builder.addNextValue(2, 1, -1));
  17. ASSERT_NO_THROW(builder.addNextValue(2, 2, 3));
  18. storm::storage::SparseMatrix<double> A;
  19. ASSERT_NO_THROW(A = builder.build());
  20. std::vector<double> x(3);
  21. std::vector<double> b = {16, -4, -7};
  22. ASSERT_NO_THROW(storm::solver::EliminationLinearEquationSolver<double> solver(A));
  23. storm::solver::EliminationLinearEquationSolver<double> solver(A);
  24. ASSERT_NO_THROW(solver.solveEquations(x, b));
  25. ASSERT_LT(std::abs(x[0] - 1), 1e-15);
  26. ASSERT_LT(std::abs(x[1] - 3), 1e-15);
  27. ASSERT_LT(std::abs(x[2] - (-1)), 1e-15);
  28. }
  29. TEST(EliminationLinearEquationSolver, MatrixVectorMultiplication) {
  30. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  31. storm::storage::SparseMatrixBuilder<double> builder;
  32. ASSERT_NO_THROW(builder.addNextValue(0, 1, 0.5));
  33. ASSERT_NO_THROW(builder.addNextValue(0, 4, 0.5));
  34. ASSERT_NO_THROW(builder.addNextValue(1, 2, 0.5));
  35. ASSERT_NO_THROW(builder.addNextValue(1, 4, 0.5));
  36. ASSERT_NO_THROW(builder.addNextValue(2, 3, 0.5));
  37. ASSERT_NO_THROW(builder.addNextValue(2, 4, 0.5));
  38. ASSERT_NO_THROW(builder.addNextValue(3, 4, 1));
  39. ASSERT_NO_THROW(builder.addNextValue(4, 4, 1));
  40. storm::storage::SparseMatrix<double> A;
  41. ASSERT_NO_THROW(A = builder.build());
  42. std::vector<double> x(5);
  43. x[4] = 1;
  44. storm::solver::EliminationLinearEquationSolver<double> solver(A);
  45. ASSERT_NO_THROW(solver.repeatedMultiply(x, nullptr, 4));
  46. ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision());
  47. }