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.

55 lines
2.4 KiB

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