TimQu
7 years ago
6 changed files with 205 additions and 705 deletions
-
417src/test/storm/solver/EigenLinearEquationSolverTest.cpp
-
124src/test/storm/solver/GmmxxMinMaxLinearEquationSolverTest.cpp
-
69src/test/storm/solver/LpMinMaxLinearEquationSolverTest.cpp
-
175src/test/storm/solver/MinMaxLinearEquationSolverTest.cpp
-
95src/test/storm/solver/NativeMinMaxLinearEquationSolverTest.cpp
-
30src/test/storm/testmacros.h
@ -1,417 +0,0 @@ |
|||
#include "gtest/gtest.h"
|
|||
#include "storm-config.h"
|
|||
|
|||
#include "storm/solver/EigenLinearEquationSolver.h"
|
|||
#include "storm/settings/SettingsManager.h"
|
|||
|
|||
#include "storm/utility/constants.h"
|
|||
#include "storm/settings/modules/EigenEquationSolverSettings.h"
|
|||
|
|||
TEST(EigenLinearEquationSolver, SolveWithStandardOptions) { |
|||
ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder); |
|||
storm::storage::SparseMatrixBuilder<double> builder; |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, -2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 0, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, 5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 0, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 2, 3)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<double> x(3); |
|||
std::vector<double> b = {16, -4, -7}; |
|||
|
|||
ASSERT_NO_THROW(storm::solver::EigenLinearEquationSolver<double> solver(A)); |
|||
|
|||
storm::solver::EigenLinearEquationSolver<double> solver(A); |
|||
ASSERT_NO_THROW(solver.solveEquations(env, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
} |
|||
|
|||
TEST(EigenLinearEquationSolver, SparseLU) { |
|||
ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder); |
|||
storm::storage::SparseMatrixBuilder<double> builder; |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, -2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 0, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, 5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 0, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 2, 3)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<double> x(3); |
|||
std::vector<double> b = {16, -4, -7}; |
|||
|
|||
storm::solver::EigenLinearEquationSolver<double> solver(A); |
|||
solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::SparseLU); |
|||
solver.getSettings().setMaximalNumberOfIterations(10000); |
|||
solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::None); |
|||
ASSERT_NO_THROW(solver.solveEquations(env, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
} |
|||
|
|||
#ifdef STORM_HAVE_CARL
|
|||
TEST(EigenLinearEquationSolver, SparseLU_RationalNumber) { |
|||
ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<storm::RationalNumber> builder); |
|||
storm::storage::SparseMatrixBuilder<storm::RationalNumber> builder; |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, -2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 0, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, 5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 0, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 2, 3)); |
|||
|
|||
storm::storage::SparseMatrix<storm::RationalNumber> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<storm::RationalNumber> x(3); |
|||
std::vector<storm::RationalNumber> b = {16, -4, -7}; |
|||
|
|||
storm::solver::EigenLinearEquationSolver<storm::RationalNumber> solver(A); |
|||
ASSERT_NO_THROW(solver.solveEquations(env, x, b)); |
|||
ASSERT_TRUE(storm::utility::isOne(x[0])); |
|||
ASSERT_TRUE(x[1] == 3); |
|||
ASSERT_TRUE(x[2] == -1); |
|||
} |
|||
|
|||
TEST(EigenLinearEquationSolver, SparseLU_RationalFunction) { |
|||
ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<storm::RationalFunction> builder); |
|||
storm::storage::SparseMatrixBuilder<storm::RationalFunction> builder; |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, storm::RationalFunction(2))); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, storm::RationalFunction(4))); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, storm::RationalFunction(-2))); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 0, storm::RationalFunction(4))); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, storm::RationalFunction(-1))); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, storm::RationalFunction(5))); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 0, storm::RationalFunction(-1))); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, storm::RationalFunction(-1))); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 2, storm::RationalFunction(3))); |
|||
|
|||
storm::storage::SparseMatrix<storm::RationalFunction> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<storm::RationalFunction> x(3); |
|||
std::vector<storm::RationalFunction> b = {storm::RationalFunction(16), storm::RationalFunction(-4), storm::RationalFunction(-7)}; |
|||
|
|||
storm::solver::EigenLinearEquationSolver<storm::RationalFunction> solver(A); |
|||
ASSERT_NO_THROW(solver.solveEquations(env, x, b)); |
|||
ASSERT_TRUE(storm::utility::isOne(x[0])); |
|||
ASSERT_TRUE(x[1] == storm::RationalFunction(3)); |
|||
ASSERT_TRUE(x[2] == storm::RationalFunction(-1)); |
|||
} |
|||
#endif
|
|||
|
|||
TEST(EigenLinearEquationSolver, DGMRES) { |
|||
ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder); |
|||
storm::storage::SparseMatrixBuilder<double> builder; |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, -2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 0, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, 5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 0, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 2, 3)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<double> x(3); |
|||
std::vector<double> b = {16, -4, -7}; |
|||
|
|||
storm::solver::EigenLinearEquationSolver<double> solver(A); |
|||
solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::DGMRES); |
|||
solver.getSettings().setPrecision(1e-6); |
|||
solver.getSettings().setMaximalNumberOfIterations(10000); |
|||
solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::None); |
|||
solver.getSettings().setNumberOfIterationsUntilRestart(50); |
|||
|
|||
ASSERT_NO_THROW(solver.solveEquations(env, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
} |
|||
|
|||
TEST(EigenLinearEquationSolver, DGMRES_Ilu) { |
|||
ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder); |
|||
storm::storage::SparseMatrixBuilder<double> builder; |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, -2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 0, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, 5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 0, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 2, 3)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<double> x(3); |
|||
std::vector<double> b = {16, -4, -7}; |
|||
|
|||
storm::solver::EigenLinearEquationSolver<double> solver(A); |
|||
solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::DGMRES); |
|||
solver.getSettings().setPrecision(1e-6); |
|||
solver.getSettings().setMaximalNumberOfIterations(10000); |
|||
solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::Ilu); |
|||
ASSERT_NO_THROW(solver.solveEquations(env, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
} |
|||
|
|||
TEST(EigenLinearEquationSolver, DGMRES_Diagonal) { |
|||
ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder); |
|||
storm::storage::SparseMatrixBuilder<double> builder; |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, -2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 0, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, 5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 0, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 2, 3)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<double> x(3); |
|||
std::vector<double> b = {16, -4, -7}; |
|||
|
|||
storm::solver::EigenLinearEquationSolver<double> solver(A); |
|||
solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::DGMRES); |
|||
solver.getSettings().setPrecision(1e-6); |
|||
solver.getSettings().setMaximalNumberOfIterations(10000); |
|||
solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::Diagonal); |
|||
ASSERT_NO_THROW(solver.solveEquations(env, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
} |
|||
|
|||
TEST(EigenLinearEquationSolver, GMRES) { |
|||
ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder); |
|||
storm::storage::SparseMatrixBuilder<double> builder; |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, -2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 0, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, 5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 0, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 2, 3)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<double> x(3); |
|||
std::vector<double> b = {16, -4, -7}; |
|||
|
|||
storm::solver::EigenLinearEquationSolver<double> solver(A); |
|||
solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::GMRES); |
|||
solver.getSettings().setPrecision(1e-6); |
|||
solver.getSettings().setMaximalNumberOfIterations(10000); |
|||
solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::None); |
|||
solver.getSettings().setNumberOfIterationsUntilRestart(50); |
|||
|
|||
ASSERT_NO_THROW(solver.solveEquations(env, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
} |
|||
|
|||
TEST(EigenLinearEquationSolver, GMRES_Ilu) { |
|||
ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder); |
|||
storm::storage::SparseMatrixBuilder<double> builder; |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, -2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 0, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, 5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 0, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 2, 3)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<double> x(3); |
|||
std::vector<double> b = {16, -4, -7}; |
|||
|
|||
storm::solver::EigenLinearEquationSolver<double> solver(A); |
|||
solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::GMRES); |
|||
solver.getSettings().setPrecision(1e-6); |
|||
solver.getSettings().setMaximalNumberOfIterations(10000); |
|||
solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::Ilu); |
|||
ASSERT_NO_THROW(solver.solveEquations(env, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
} |
|||
|
|||
TEST(EigenLinearEquationSolver, GMRES_Diagonal) { |
|||
ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder); |
|||
storm::storage::SparseMatrixBuilder<double> builder; |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, -2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 0, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, 5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 0, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 2, 3)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<double> x(3); |
|||
std::vector<double> b = {16, -4, -7}; |
|||
|
|||
storm::solver::EigenLinearEquationSolver<double> solver(A); |
|||
solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::GMRES); |
|||
solver.getSettings().setPrecision(1e-6); |
|||
solver.getSettings().setMaximalNumberOfIterations(10000); |
|||
solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::Diagonal); |
|||
ASSERT_NO_THROW(solver.solveEquations(env, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
} |
|||
|
|||
TEST(EigenLinearEquationSolver, BiCGSTAB) { |
|||
ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder); |
|||
storm::storage::SparseMatrixBuilder<double> builder; |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, -2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 0, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, 5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 0, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 2, 3)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<double> x(3); |
|||
std::vector<double> b = {16, -4, -7}; |
|||
|
|||
storm::solver::EigenLinearEquationSolver<double> solver(A); |
|||
solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::BiCGSTAB); |
|||
solver.getSettings().setPrecision(1e-6); |
|||
solver.getSettings().setMaximalNumberOfIterations(10000); |
|||
solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::None); |
|||
|
|||
ASSERT_NO_THROW(solver.solveEquations(env, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
} |
|||
|
|||
TEST(EigenLinearEquationSolver, BiCGSTAB_Ilu) { |
|||
ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder); |
|||
storm::storage::SparseMatrixBuilder<double> builder; |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, -2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 0, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, 5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 0, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 2, 3)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<double> x(3); |
|||
std::vector<double> b = {16, -4, -7}; |
|||
|
|||
storm::solver::EigenLinearEquationSolver<double> solver(A); |
|||
solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::BiCGSTAB); |
|||
solver.getSettings().setPrecision(1e-6); |
|||
solver.getSettings().setMaximalNumberOfIterations(10000); |
|||
solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::Ilu); |
|||
ASSERT_NO_THROW(solver.solveEquations(env, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
} |
|||
|
|||
TEST(EigenLinearEquationSolver, BiCGSTAB_Diagonal) { |
|||
ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder); |
|||
storm::storage::SparseMatrixBuilder<double> builder; |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, -2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 0, 4)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, 5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 0, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, -1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 2, 3)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<double> x(3); |
|||
std::vector<double> b = {16, -4, -7}; |
|||
|
|||
storm::solver::EigenLinearEquationSolver<double> solver(A); |
|||
solver.getSettings().setSolutionMethod(storm::solver::EigenLinearEquationSolverSettings<double>::SolutionMethod::BiCGSTAB); |
|||
solver.getSettings().setPrecision(1e-6); |
|||
solver.getSettings().setMaximalNumberOfIterations(10000); |
|||
solver.getSettings().setPreconditioner(storm::solver::EigenLinearEquationSolverSettings<double>::Preconditioner::Diagonal); |
|||
ASSERT_NO_THROW(solver.solveEquations(env, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[1] - 3), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
ASSERT_LT(std::abs(x[2] - (-1)), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
} |
|||
|
|||
TEST(EigenLinearEquationSolver, MatrixVectorMultiplication) { |
|||
ASSERT_NO_THROW(storm::storage::SparseMatrixBuilder<double> builder); |
|||
storm::storage::SparseMatrixBuilder<double> builder; |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, 0.5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 4, 0.5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, 0.5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 4, 0.5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 3, 0.5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 4, 0.5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(3, 4, 1)); |
|||
ASSERT_NO_THROW(builder.addNextValue(4, 4, 1)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<double> x(5); |
|||
x[4] = 1; |
|||
|
|||
storm::solver::EigenLinearEquationSolver<double> solver(A); |
|||
ASSERT_NO_THROW(solver.repeatedMultiply(x, nullptr, 4)); |
|||
ASSERT_LT(std::abs(x[0] - 1), storm::settings::getModule<storm::settings::modules::EigenEquationSolverSettings>().getPrecision()); |
|||
} |
@ -1,124 +0,0 @@ |
|||
#include "gtest/gtest.h"
|
|||
#include "storm-config.h"
|
|||
|
|||
#include "storm/solver/StandardMinMaxLinearEquationSolver.h"
|
|||
#include "storm/settings/SettingsManager.h"
|
|||
#include "storm/settings/modules/GmmxxEquationSolverSettings.h"
|
|||
#include "storm/storage/SparseMatrix.h"
|
|||
|
|||
TEST(GmmxxMinMaxLinearEquationSolver, SolveWithStandardOptions) { |
|||
storm::storage::SparseMatrixBuilder<double> builder(0, 0, 0, false, true); |
|||
ASSERT_NO_THROW(builder.newRowGroup(0)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 0.9)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build(2)); |
|||
|
|||
std::vector<double> x(1); |
|||
std::vector<double> b = {0.099, 0.5}; |
|||
|
|||
auto factory = storm::solver::GmmxxMinMaxLinearEquationSolverFactory<double>(); |
|||
auto solver = factory.create(A); |
|||
solver->setHasUniqueSolution(); |
|||
ASSERT_NO_THROW(solver->solveEquations(storm::OptimizationDirection::Minimize, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision()); |
|||
|
|||
ASSERT_NO_THROW(solver->solveEquations(storm::OptimizationDirection::Maximize, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 0.989991), storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision()); |
|||
} |
|||
|
|||
// TODO add better tests here.
|
|||
TEST(GmmxxMinMaxLinearEquationSolver, SolveWithStandardOptionsAndEarlyTermination) { |
|||
storm::storage::SparseMatrixBuilder<double> builder(0, 0, 0, false, true); |
|||
ASSERT_NO_THROW(builder.newRowGroup(0)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 0.9)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build(2)); |
|||
|
|||
std::vector<double> x(1); |
|||
std::vector<double> b = {0.099, 0.5}; |
|||
|
|||
double bound = 0.8; |
|||
|
|||
auto factory = storm::solver::GmmxxMinMaxLinearEquationSolverFactory<double>(); |
|||
auto solver = factory.create(A); |
|||
solver->setLowerBound(0.0); |
|||
solver->setUpperBound(1.0); |
|||
|
|||
solver->setTerminationCondition(std::make_unique<storm::solver::TerminateIfFilteredExtremumExceedsThreshold<double>>(storm::storage::BitVector(A.getRowGroupCount(), true), false, bound, true)); |
|||
ASSERT_NO_THROW(solver->solveEquations(storm::OptimizationDirection::Minimize, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision()); |
|||
|
|||
ASSERT_NO_THROW(solver->solveEquations(storm::OptimizationDirection::Maximize, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 0.989991), 0.989991 - bound - storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision()); |
|||
|
|||
bound = 0.6; |
|||
solver->setTerminationCondition(std::make_unique<storm::solver::TerminateIfFilteredExtremumExceedsThreshold<double>>(storm::storage::BitVector(A.getRowGroupCount(), true), false, bound, true)); |
|||
|
|||
ASSERT_NO_THROW(solver->solveEquations(storm::OptimizationDirection::Maximize, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 0.989991), 0.989991 - bound - storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision()); |
|||
} |
|||
|
|||
TEST(GmmxxMinMaxLinearEquationSolver, MatrixVectorMultiplication) { |
|||
storm::storage::SparseMatrixBuilder<double> builder(0, 0, 0, false, true); |
|||
ASSERT_NO_THROW(builder.newRowGroup(0)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 0.9)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, 0.099)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, 0.001)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, 0.5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, 0.5)); |
|||
ASSERT_NO_THROW(builder.newRowGroup(2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, 1)); |
|||
ASSERT_NO_THROW(builder.newRowGroup(3)); |
|||
ASSERT_NO_THROW(builder.addNextValue(3, 2, 1)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<double> x = {0, 1, 0}; |
|||
|
|||
auto factory = storm::solver::GmmxxMinMaxLinearEquationSolverFactory<double>(); |
|||
auto solver = factory.create(A); |
|||
|
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Minimize, x, nullptr, 1)); |
|||
ASSERT_LT(std::abs(x[0] - 0.099), storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision()); |
|||
|
|||
x = {0, 1, 0}; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Minimize, x, nullptr, 2)); |
|||
ASSERT_LT(std::abs(x[0] - 0.1881), storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision()); |
|||
|
|||
x = {0, 1, 0}; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Minimize, x, nullptr, 20)); |
|||
ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision()); |
|||
|
|||
x = {0, 1, 0}; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Maximize, x, nullptr, 1)); |
|||
ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision()); |
|||
|
|||
x = {0, 1, 0}; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Maximize, x, nullptr, 20)); |
|||
ASSERT_LT(std::abs(x[0] - 0.9238082658), storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision()); |
|||
} |
|||
|
|||
TEST(GmmxxMinMaxLinearEquationSolver, SolveWithPolicyIteration) { |
|||
storm::storage::SparseMatrixBuilder<double> builder(0, 0, 0, false, true); |
|||
ASSERT_NO_THROW(builder.newRowGroup(0)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 0.9)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build(2)); |
|||
|
|||
std::vector<double> x(1); |
|||
std::vector<double> b = { 0.099, 0.5 }; |
|||
|
|||
auto factory = storm::solver::GmmxxMinMaxLinearEquationSolverFactory<double>(storm::solver::MinMaxMethodSelection::PolicyIteration); |
|||
auto solver = factory.create(A); |
|||
solver->setHasUniqueSolution(); |
|||
|
|||
ASSERT_NO_THROW(solver->solveEquations(storm::OptimizationDirection::Minimize, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision()); |
|||
|
|||
ASSERT_NO_THROW(solver->solveEquations(storm::OptimizationDirection::Maximize, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 0.99), storm::settings::getModule<storm::settings::modules::GmmxxEquationSolverSettings>().getPrecision()); |
|||
} |
@ -1,69 +0,0 @@ |
|||
#include "gtest/gtest.h"
|
|||
#include "storm-config.h"
|
|||
|
|||
#include "storm/solver/LpMinMaxLinearEquationSolver.h"
|
|||
#include "storm/settings/SettingsManager.h"
|
|||
#include "storm/settings/modules/GeneralSettings.h"
|
|||
|
|||
#include "storm/storage/SparseMatrix.h"
|
|||
|
|||
TEST(LpMinMaxLinearEquationSolver, SolveWithStandardOptions) { |
|||
storm::storage::SparseMatrixBuilder<double> builder(0, 0, 0, false, true); |
|||
ASSERT_NO_THROW(builder.newRowGroup(0)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 0.9)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build(2)); |
|||
|
|||
std::vector<double> x(1); |
|||
std::vector<double> b = {0.099, 0.5}; |
|||
|
|||
auto factory = storm::solver::LpMinMaxLinearEquationSolverFactory<double>(); |
|||
auto solver = factory.create(A); |
|||
ASSERT_NO_THROW(solver->solveEquations(storm::OptimizationDirection::Minimize, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision()); |
|||
|
|||
ASSERT_NO_THROW(solver->solveEquations(storm::OptimizationDirection::Maximize, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 0.99), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision()); |
|||
} |
|||
|
|||
TEST(LpMinMaxLinearEquationSolver, MatrixVectorMultiplication) { |
|||
storm::storage::SparseMatrixBuilder<double> builder(0, 0, 0, false, true); |
|||
ASSERT_NO_THROW(builder.newRowGroup(0)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 0.9)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, 0.099)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, 0.001)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, 0.5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, 0.5)); |
|||
ASSERT_NO_THROW(builder.newRowGroup(2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, 1)); |
|||
ASSERT_NO_THROW(builder.newRowGroup(3)); |
|||
ASSERT_NO_THROW(builder.addNextValue(3, 2, 1)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<double> x = {0, 1, 0}; |
|||
|
|||
auto factory = storm::solver::LpMinMaxLinearEquationSolverFactory<double>(); |
|||
auto solver = factory.create(A); |
|||
|
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Minimize, x, nullptr, 1)); |
|||
ASSERT_LT(std::abs(x[0] - 0.099), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision()); |
|||
|
|||
x = {0, 1, 0}; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Minimize, x, nullptr, 2)); |
|||
ASSERT_LT(std::abs(x[0] - 0.1881), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision()); |
|||
|
|||
x = {0, 1, 0}; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Minimize, x, nullptr, 20)); |
|||
ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision()); |
|||
|
|||
x = {0, 1, 0}; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Maximize, x, nullptr, 1)); |
|||
ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision()); |
|||
|
|||
x = {0, 1, 0}; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Maximize, x, nullptr, 20)); |
|||
ASSERT_LT(std::abs(x[0] - 0.9238082658), storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision()); |
|||
} |
@ -0,0 +1,175 @@ |
|||
#include "gtest/gtest.h"
|
|||
#include "storm-config.h"
|
|||
|
|||
#include "test/storm/testmacros.h"
|
|||
|
|||
#include "storm/solver/MinMaxLinearEquationSolver.h"
|
|||
#include "storm/environment/solver/MinMaxSolverEnvironment.h"
|
|||
#include "storm/solver/SolverSelectionOptions.h"
|
|||
#include "storm/storage/SparseMatrix.h"
|
|||
|
|||
#if GTEST_HAS_PARAM_TEST
|
|||
namespace { |
|||
|
|||
class DoubleViEnvironment { |
|||
public: |
|||
typedef double ValueType; |
|||
static storm::Environment createEnvironment() { |
|||
storm::Environment env; |
|||
env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration); |
|||
env.solver().minMax().setPrecision(storm::utility::convertNumber<storm::RationalNumber>(1e-8)); |
|||
return env; |
|||
} |
|||
}; |
|||
class DoubleSoundViEnvironment { |
|||
public: |
|||
typedef double ValueType; |
|||
static storm::Environment createEnvironment() { |
|||
storm::Environment env; |
|||
env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration); |
|||
env.solver().setForceSoundness(true); |
|||
env.solver().minMax().setPrecision(storm::utility::convertNumber<storm::RationalNumber>(1e-6)); |
|||
return env; |
|||
} |
|||
}; |
|||
class DoubleTopologicalViEnvironment { |
|||
public: |
|||
typedef double ValueType; |
|||
static storm::Environment createEnvironment() { |
|||
storm::Environment env; |
|||
env.solver().minMax().setMethod(storm::solver::MinMaxMethod::Topological); |
|||
env.solver().minMax().setPrecision(storm::utility::convertNumber<storm::RationalNumber>(1e-8)); |
|||
return env; |
|||
} |
|||
}; |
|||
class DoublePIEnvironment { |
|||
public: |
|||
typedef double ValueType; |
|||
static storm::Environment createEnvironment() { |
|||
storm::Environment env; |
|||
env.solver().minMax().setMethod(storm::solver::MinMaxMethod::PolicyIteration); |
|||
env.solver().minMax().setPrecision(storm::utility::convertNumber<storm::RationalNumber>(1e-8)); |
|||
return env; |
|||
} |
|||
}; |
|||
class RationalPIEnvironment { |
|||
public: |
|||
typedef storm::RationalNumber ValueType; |
|||
static storm::Environment createEnvironment() { |
|||
storm::Environment env; |
|||
env.solver().minMax().setMethod(storm::solver::MinMaxMethod::PolicyIteration); |
|||
return env; |
|||
} |
|||
}; |
|||
class RationalRationalSearchEnvironment { |
|||
public: |
|||
typedef storm::RationalNumber ValueType; |
|||
static storm::Environment createEnvironment() { |
|||
storm::Environment env; |
|||
env.solver().minMax().setMethod(storm::solver::MinMaxMethod::RationalSearch); |
|||
return env; |
|||
} |
|||
}; |
|||
|
|||
template<typename TestType> |
|||
class MinMaxLinearEquationSolverTest : public ::testing::Test { |
|||
public: |
|||
typedef typename TestType::ValueType ValueType; |
|||
MinMaxLinearEquationSolverTest() : _environment(TestType::createEnvironment()) {} |
|||
storm::Environment const& env() const { return _environment; } |
|||
ValueType precision() const { return storm::utility::convertNumber<ValueType>(1e-6);} |
|||
ValueType parseNumber(std::string const& input) const { return storm::utility::convertNumber<ValueType>(input);} |
|||
private: |
|||
storm::Environment _environment; |
|||
}; |
|||
|
|||
typedef ::testing::Types< |
|||
DoubleViEnvironment, |
|||
DoubleSoundViEnvironment, |
|||
DoubleTopologicalViEnvironment, |
|||
DoublePIEnvironment, |
|||
RationalPIEnvironment, |
|||
RationalRationalSearchEnvironment |
|||
> TestingTypes; |
|||
|
|||
TYPED_TEST_CASE(MinMaxLinearEquationSolverTest, TestingTypes); |
|||
|
|||
TYPED_TEST(MinMaxLinearEquationSolverTest, SolveEquations) { |
|||
typedef typename TestFixture::ValueType ValueType; |
|||
|
|||
storm::storage::SparseMatrixBuilder<ValueType> builder(0, 0, 0, false, true); |
|||
ASSERT_NO_THROW(builder.newRowGroup(0)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, this->parseNumber("0.9"))); |
|||
|
|||
storm::storage::SparseMatrix<ValueType> A; |
|||
ASSERT_NO_THROW(A = builder.build(2)); |
|||
|
|||
std::vector<ValueType> x(1); |
|||
std::vector<ValueType> b = {this->parseNumber("0.099"), this->parseNumber("0.5")}; |
|||
|
|||
auto factory = storm::solver::GeneralMinMaxLinearEquationSolverFactory<ValueType>(); |
|||
auto solver = factory.create(this->env(), A); |
|||
solver->setHasUniqueSolution(true); |
|||
solver->setBounds(this->parseNumber("0"), this->parseNumber("2")); |
|||
storm::solver::MinMaxLinearEquationSolverRequirements req = solver->getRequirements(this->env()); |
|||
req.clearBounds(); |
|||
ASSERT_TRUE(req.empty()); |
|||
ASSERT_NO_THROW(solver->solveEquations(this->env(), storm::OptimizationDirection::Minimize, x, b)); |
|||
STORM_EXPECT_NEAR(x[0], this->parseNumber("0.5"), this->precision()); |
|||
|
|||
ASSERT_NO_THROW(solver->solveEquations(this->env(), storm::OptimizationDirection::Maximize, x, b)); |
|||
STORM_EXPECT_NEAR(x[0], this->parseNumber("0.99"), this->precision()); |
|||
} |
|||
|
|||
TYPED_TEST(MinMaxLinearEquationSolverTest, MatrixVectorMultiplication) { |
|||
typedef typename TestFixture::ValueType ValueType; |
|||
|
|||
storm::storage::SparseMatrixBuilder<ValueType> builder(0, 0, 0, false, true); |
|||
ASSERT_NO_THROW(builder.newRowGroup(0)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, this->parseNumber("0.9"))); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, this->parseNumber("0.099"))); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, this->parseNumber("0.001"))); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, this->parseNumber("0.5"))); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, this->parseNumber("0.5"))); |
|||
ASSERT_NO_THROW(builder.newRowGroup(2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, this->parseNumber("1"))); |
|||
ASSERT_NO_THROW(builder.newRowGroup(3)); |
|||
ASSERT_NO_THROW(builder.addNextValue(3, 2, this->parseNumber("1"))); |
|||
|
|||
storm::storage::SparseMatrix<ValueType> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<ValueType> initialX = {this->parseNumber("0"), this->parseNumber("1"), this->parseNumber("0")}; |
|||
std::vector<ValueType> x; |
|||
|
|||
auto factory = storm::solver::GeneralMinMaxLinearEquationSolverFactory<ValueType>(); |
|||
auto solver = factory.create(this->env(), A); |
|||
|
|||
x = initialX; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Minimize, x, nullptr, 1)); |
|||
STORM_EXPECT_NEAR(x[0], this->parseNumber("0.099"), this->precision()); |
|||
|
|||
x = initialX; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Minimize, x, nullptr, 2)); |
|||
STORM_EXPECT_NEAR(x[0], this->parseNumber("0.1881"), this->precision()); |
|||
|
|||
x = initialX; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Minimize, x, nullptr, 20)); |
|||
STORM_EXPECT_NEAR(x[0], this->parseNumber("0.5"), this->precision()); |
|||
|
|||
x = initialX; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Maximize, x, nullptr, 1)); |
|||
STORM_EXPECT_NEAR(x[0], this->parseNumber("0.5"), this->precision()); |
|||
|
|||
x = initialX; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Maximize, x, nullptr, 20)); |
|||
STORM_EXPECT_NEAR(x[0], this->parseNumber("0.9238082658"), this->precision()); |
|||
} |
|||
|
|||
} |
|||
#else
|
|||
TEST(MinMaxLinearEquationSolverTest, ValueParameterizedTestsAreNotSupportedOnThisPlatform) {} |
|||
#endif
|
|||
|
|||
|
|||
|
@ -1,95 +0,0 @@ |
|||
#include "gtest/gtest.h"
|
|||
#include "storm-config.h"
|
|||
|
|||
#include "storm/solver/StandardMinMaxLinearEquationSolver.h"
|
|||
#include "storm/settings/SettingsManager.h"
|
|||
|
|||
#include "storm/settings/modules/NativeEquationSolverSettings.h"
|
|||
#include "storm/storage/SparseMatrix.h"
|
|||
|
|||
TEST(NativeMinMaxLinearEquationSolver, SolveWithStandardOptions) { |
|||
storm::storage::SparseMatrixBuilder<double> builder(0, 0, 0, false, true); |
|||
ASSERT_NO_THROW(builder.newRowGroup(0)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 0.9)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build(2)); |
|||
|
|||
std::vector<double> x(1); |
|||
std::vector<double> b = {0.099, 0.5}; |
|||
|
|||
auto factory = storm::solver::NativeMinMaxLinearEquationSolverFactory<double>(); |
|||
auto solver = factory.create(A); |
|||
solver->setHasUniqueSolution(); |
|||
|
|||
ASSERT_NO_THROW(solver->solveEquations(storm::OptimizationDirection::Minimize, x, b)); |
|||
|
|||
ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision()); |
|||
|
|||
ASSERT_NO_THROW(solver->solveEquations(storm::OptimizationDirection::Maximize, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 0.989991), storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision()); |
|||
} |
|||
|
|||
TEST(NativeMinMaxLinearEquationSolver, MatrixVectorMultiplication) { |
|||
storm::storage::SparseMatrixBuilder<double> builder(0, 0, 0, false, true); |
|||
ASSERT_NO_THROW(builder.newRowGroup(0)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 0.9)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 1, 0.099)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 2, 0.001)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 1, 0.5)); |
|||
ASSERT_NO_THROW(builder.addNextValue(1, 2, 0.5)); |
|||
ASSERT_NO_THROW(builder.newRowGroup(2)); |
|||
ASSERT_NO_THROW(builder.addNextValue(2, 1, 1)); |
|||
ASSERT_NO_THROW(builder.newRowGroup(3)); |
|||
ASSERT_NO_THROW(builder.addNextValue(3, 2, 1)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build()); |
|||
|
|||
std::vector<double> x = {0, 1, 0}; |
|||
|
|||
auto factory = storm::solver::NativeMinMaxLinearEquationSolverFactory<double>(); |
|||
auto solver = factory.create(A); |
|||
|
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Minimize, x, nullptr, 1)); |
|||
ASSERT_LT(std::abs(x[0] - 0.099), storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision()); |
|||
|
|||
x = {0, 1, 0}; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Minimize, x, nullptr, 2)); |
|||
ASSERT_LT(std::abs(x[0] - 0.1881), storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision()); |
|||
|
|||
x = {0, 1, 0}; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Minimize, x, nullptr, 20)); |
|||
ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision()); |
|||
|
|||
x = {0, 1, 0}; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Maximize, x, nullptr, 1)); |
|||
ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision()); |
|||
|
|||
x = {0, 1, 0}; |
|||
ASSERT_NO_THROW(solver->repeatedMultiply(storm::OptimizationDirection::Maximize, x, nullptr, 20)); |
|||
ASSERT_LT(std::abs(x[0] - 0.9238082658), storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision()); |
|||
} |
|||
|
|||
TEST(NativeMinMaxLinearEquationSolver, SolveWithPolicyIteration) { |
|||
storm::storage::SparseMatrixBuilder<double> builder(0, 0, 0, false, true); |
|||
ASSERT_NO_THROW(builder.newRowGroup(0)); |
|||
ASSERT_NO_THROW(builder.addNextValue(0, 0, 0.9)); |
|||
|
|||
storm::storage::SparseMatrix<double> A; |
|||
ASSERT_NO_THROW(A = builder.build(2)); |
|||
|
|||
std::vector<double> x(1); |
|||
std::vector<double> b = { 0.099, 0.5 }; |
|||
|
|||
auto factory = storm::solver::NativeMinMaxLinearEquationSolverFactory<double>(storm::solver::MinMaxMethodSelection::PolicyIteration); |
|||
auto solver = factory.create(A); |
|||
solver->setLowerBound(0.0); |
|||
solver->setUpperBound(1.0); |
|||
|
|||
ASSERT_NO_THROW(solver->solveEquations(storm::OptimizationDirection::Minimize, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 0.5), storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision()); |
|||
|
|||
ASSERT_NO_THROW(solver->solveEquations(storm::OptimizationDirection::Maximize, x, b)); |
|||
ASSERT_LT(std::abs(x[0] - 0.99), storm::settings::getModule<storm::settings::modules::NativeEquationSolverSettings>().getPrecision()); |
|||
} |
@ -0,0 +1,30 @@ |
|||
#pragma once |
|||
|
|||
#include <type_traits> |
|||
#include <typeinfo> |
|||
|
|||
#include "storm/utility/constants.h" |
|||
#include "gtest/gtest.h" |
|||
|
|||
#define STORM_EXPECT_NEAR(val1, val2, abs_error) \ |
|||
do { \ |
|||
if (std::is_same<typename std::remove_const<typename std::remove_reference<decltype(val1)>::type>::type, double>::value) { \ |
|||
EXPECT_NEAR(storm::utility::convertNumber<double>(val1), \ |
|||
storm::utility::convertNumber<double>(val2), \ |
|||
storm::utility::convertNumber<double>(abs_error)); \ |
|||
} else if (storm::utility::isZero(abs_error)) { \ |
|||
EXPECT_EQ(val1, val2); \ |
|||
} else { \ |
|||
auto valueDifference = val1; \ |
|||
valueDifference -= val2; \ |
|||
valueDifference = storm::utility::abs(valueDifference); \ |
|||
EXPECT_LT(storm::utility::abs(valueDifference), abs_error); \ |
|||
if (valueDifference > abs_error) { \ |
|||
std::cout << "Expected " << val2 \ |
|||
<< " (approx " << storm::utility::convertNumber<double>(val2) \ |
|||
<< ") but got " << val1 \ |
|||
<< " (approx " << storm::utility::convertNumber<double>(val1) \ |
|||
<< ")." << std::endl; \ |
|||
} \ |
|||
} \ |
|||
} while (false) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue