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.5 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/solver/NativeLinearEquationSolver.h"
  4. #include "src/settings/SettingsManager.h"
  5. #include "src/settings/modules/NativeEquationSolverSettings.h"
  6. TEST(NativeLinearEquationSolver, SolveWithStandardOptions) {
  7. ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder);
  8. storm::storage::SparseMatrixBuilder<double> builder;
  9. ASSERT_NO_THROW(builder.addNextValue(0, 0, 4));
  10. ASSERT_NO_THROW(builder.addNextValue(0, 1, 2));
  11. ASSERT_NO_THROW(builder.addNextValue(0, 2, -1));
  12. ASSERT_NO_THROW(builder.addNextValue(1, 0, 1));
  13. ASSERT_NO_THROW(builder.addNextValue(1, 1, -5));
  14. ASSERT_NO_THROW(builder.addNextValue(1, 2, 2));
  15. ASSERT_NO_THROW(builder.addNextValue(2, 0, -1));
  16. ASSERT_NO_THROW(builder.addNextValue(2, 1, 2));
  17. ASSERT_NO_THROW(builder.addNextValue(2, 2, 4));
  18. storm::storage::SparseMatrix<double> A;
  19. ASSERT_NO_THROW(A = builder.build());
  20. std::vector<double> x(3);
  21. std::vector<double> b = {11, -16, 1};
  22. ASSERT_NO_THROW(storm::solver::NativeLinearEquationSolver<double> solver(A));
  23. storm::solver::NativeLinearEquationSolver<double> solver(A);
  24. ASSERT_NO_THROW(solver.solveEquationSystem(x, b));
  25. ASSERT_LT(std::abs(x[0] - 1), storm::settings::nativeEquationSolverSettings().getPrecision());
  26. ASSERT_LT(std::abs(x[1] - 3), storm::settings::nativeEquationSolverSettings().getPrecision());
  27. ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::nativeEquationSolverSettings().getPrecision());
  28. }
  29. TEST(NativeLinearEquationSolver, MatrixVectorMultplication) {
  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::NativeLinearEquationSolver<double> solver(A);
  45. ASSERT_NO_THROW(solver.performMatrixVectorMultiplication(x, nullptr, 4));
  46. ASSERT_LT(std::abs(x[0] - 1), storm::settings::nativeEquationSolverSettings().getPrecision());
  47. }