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.

84 lines
4.0 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/solver/GmmxxMinMaxLinearEquationSolver.h"
  4. #include "src/settings/SettingsManager.h"
  5. TEST(GmmxxMinMaxLinearEquationSolver, 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::GmmxxMinMaxLinearEquationSolver<double> solver(A);
  14. ASSERT_NO_THROW(solver.solveEquationSystem(true, x, b));
  15. ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::gmmxxEquationSolverSettings().getPrecision());
  16. ASSERT_NO_THROW(solver.solveEquationSystem(false, x, b));
  17. ASSERT_LT(std::abs(x[0] - 0.989991), storm::settings::gmmxxEquationSolverSettings().getPrecision());
  18. }
  19. TEST(GmmxxMinMaxLinearEquationSolver, 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::GmmxxMinMaxLinearEquationSolver<double> solver(A));
  35. storm::solver::GmmxxMinMaxLinearEquationSolver<double> solver(A);
  36. ASSERT_NO_THROW(solver.performMatrixVectorMultiplication(true, x, nullptr, 1));
  37. ASSERT_LT(std::abs(x[0] - 0.099), storm::settings::gmmxxEquationSolverSettings().getPrecision());
  38. x = {0, 1, 0};
  39. ASSERT_NO_THROW(solver.performMatrixVectorMultiplication(true, x, nullptr, 2));
  40. ASSERT_LT(std::abs(x[0] - 0.1881), storm::settings::gmmxxEquationSolverSettings().getPrecision());
  41. x = {0, 1, 0};
  42. ASSERT_NO_THROW(solver.performMatrixVectorMultiplication(true, x, nullptr, 20));
  43. ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::gmmxxEquationSolverSettings().getPrecision());
  44. x = {0, 1, 0};
  45. ASSERT_NO_THROW(solver.performMatrixVectorMultiplication(false, x, nullptr, 1));
  46. ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::gmmxxEquationSolverSettings().getPrecision());
  47. x = {0, 1, 0};
  48. ASSERT_NO_THROW(solver.performMatrixVectorMultiplication(false, x, nullptr, 20));
  49. ASSERT_LT(std::abs(x[0] - 0.9238082658), storm::settings::gmmxxEquationSolverSettings().getPrecision());
  50. }
  51. TEST(GmmxxMinMaxLinearEquationSolver, SolveWithPolicyIteration) {
  52. storm::storage::SparseMatrixBuilder<double> builder(0, 0, 0, false, true);
  53. ASSERT_NO_THROW(builder.newRowGroup(0));
  54. ASSERT_NO_THROW(builder.addNextValue(0, 0, 0.9));
  55. storm::storage::SparseMatrix<double> A;
  56. ASSERT_NO_THROW(A = builder.build(2));
  57. std::vector<double> x(1);
  58. std::vector<double> b = { 0.099, 0.5 };
  59. storm::settings::modules::GmmxxEquationSolverSettings const& settings = storm::settings::gmmxxEquationSolverSettings();
  60. storm::solver::GmmxxMinMaxLinearEquationSolver<double> solver(A, settings.getPrecision(), settings.getMaximalIterationCount(), false, settings.getConvergenceCriterion() == storm::settings::modules::GmmxxEquationSolverSettings::ConvergenceCriterion::Relative);
  61. ASSERT_NO_THROW(solver.solveEquationSystem(true, x, b));
  62. ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::gmmxxEquationSolverSettings().getPrecision());
  63. ASSERT_NO_THROW(solver.solveEquationSystem(false, x, b));
  64. ASSERT_LT(std::abs(x[0] - 0.99), storm::settings::gmmxxEquationSolverSettings().getPrecision());
  65. }