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.

64 lines
3.0 KiB

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