#include "src/utility/solver.h" #include "src/solver/SymbolicGameSolver.h" #include #include "src/solver/SymbolicLinearEquationSolver.h" #include "src/solver/SymbolicMinMaxLinearEquationSolver.h" #include "src/solver/NativeLinearEquationSolver.h" #include "src/solver/GmmxxLinearEquationSolver.h" #include "src/solver/NativeMinMaxLinearEquationSolver.h" #include "src/solver/GmmxxMinMaxLinearEquationSolver.h" #include "src/solver/TopologicalMinMaxLinearEquationSolver.h" #include "src/solver/GurobiLpSolver.h" #include "src/solver/GlpkLpSolver.h" #include "src/settings/SettingsManager.h" #include "src/settings/modules/GeneralSettings.h" #include "src/settings/modules/NativeEquationSolverSettings.h" #include "src/exceptions/InvalidSettingsException.h" namespace storm { namespace utility { namespace solver { template std::unique_ptr> SymbolicLinearEquationSolverFactory::create(storm::dd::Add const& A, storm::dd::Bdd const& allRows, std::set const& rowMetaVariables, std::set const& columnMetaVariables, std::vector> const& rowColumnMetaVariablePairs) const { return std::unique_ptr>(new storm::solver::SymbolicLinearEquationSolver(A, allRows, rowMetaVariables, columnMetaVariables, rowColumnMetaVariablePairs)); } template std::unique_ptr> SymbolicMinMaxLinearEquationSolverFactory::create(storm::dd::Add const& A, storm::dd::Bdd const& allRows, storm::dd::Bdd const& illegalMask, std::set const& rowMetaVariables, std::set const& columnMetaVariables, std::set const& choiceVariables, std::vector> const& rowColumnMetaVariablePairs) const { return std::unique_ptr>(new storm::solver::SymbolicMinMaxLinearEquationSolver(A, allRows, illegalMask, rowMetaVariables, columnMetaVariables, choiceVariables, rowColumnMetaVariablePairs)); } template std::unique_ptr> SymbolicGameSolverFactory::create(storm::dd::Add const& A, storm::dd::Bdd const& allRows, std::set const& rowMetaVariables, std::set const& columnMetaVariables, std::vector> const& rowColumnMetaVariablePairs, std::set const& player1Variables, std::set const& player2Variables) const { return std::unique_ptr>(new storm::solver::SymbolicGameSolver(A, allRows, rowMetaVariables, columnMetaVariables, rowColumnMetaVariablePairs, player1Variables, player2Variables)); } template std::unique_ptr> LinearEquationSolverFactory::create(storm::storage::SparseMatrix const& matrix) const { storm::solver::EquationSolverType equationSolver = storm::settings::generalSettings().getEquationSolver(); switch (equationSolver) { case storm::solver::EquationSolverType::Gmmxx: return std::unique_ptr>(new storm::solver::GmmxxLinearEquationSolver(matrix)); case storm::solver::EquationSolverType::Native: return std::unique_ptr>(new storm::solver::NativeLinearEquationSolver(matrix)); default: return std::unique_ptr>(new storm::solver::GmmxxLinearEquationSolver(matrix)); } } template std::unique_ptr> GmmxxLinearEquationSolverFactory::create(storm::storage::SparseMatrix const& matrix) const { return std::unique_ptr>(new storm::solver::GmmxxLinearEquationSolver(matrix)); } template NativeLinearEquationSolverFactory::NativeLinearEquationSolverFactory() { switch (storm::settings::nativeEquationSolverSettings().getLinearEquationSystemMethod()) { case settings::modules::NativeEquationSolverSettings::LinearEquationMethod::Jacobi: this->method = storm::solver::NativeLinearEquationSolverSolutionMethod::Jacobi; break; case settings::modules::NativeEquationSolverSettings::LinearEquationMethod::GaussSeidel: this->method = storm::solver::NativeLinearEquationSolverSolutionMethod::GaussSeidel; case settings::modules::NativeEquationSolverSettings::LinearEquationMethod::SOR: this->method = storm::solver::NativeLinearEquationSolverSolutionMethod::SOR; } omega = storm::settings::nativeEquationSolverSettings().getOmega(); } template NativeLinearEquationSolverFactory::NativeLinearEquationSolverFactory(typename storm::solver::NativeLinearEquationSolverSolutionMethod method, ValueType omega) : method(method), omega(omega) { // Intentionally left empty. } template std::unique_ptr> NativeLinearEquationSolverFactory::create(storm::storage::SparseMatrix const& matrix) const { return std::unique_ptr>(new storm::solver::NativeLinearEquationSolver(matrix, method)); } template MinMaxLinearEquationSolverFactory::MinMaxLinearEquationSolverFactory(storm::solver::EquationSolverTypeSelection solver) { prefTech = storm::solver::MinMaxTechniqueSelection::FROMSETTINGS; setSolverType(solver); std::cout << toString(prefTech) << std::endl; } template void MinMaxLinearEquationSolverFactory::setSolverType(storm::solver::EquationSolverTypeSelection solverTypeSel) { if(solverTypeSel == storm::solver::EquationSolverTypeSelection::FROMSETTINGS) { this->solverType = storm::settings::generalSettings().getEquationSolver(); } else { this->solverType = storm::solver::convert(solverTypeSel); } } template void MinMaxLinearEquationSolverFactory::setPreferredTechnique(storm::solver::MinMaxTechniqueSelection preferredTech) { this->prefTech = preferredTech; } template std::unique_ptr> MinMaxLinearEquationSolverFactory::create(storm::storage::SparseMatrix const& matrix, bool trackPolicy) const { std::cout << toString(prefTech) << std::endl; std::unique_ptr> p1; switch (solverType) { case storm::solver::EquationSolverType::Gmmxx: { p1.reset(new storm::solver::GmmxxMinMaxLinearEquationSolver(matrix, this->prefTech)); break; } case storm::solver::EquationSolverType::Native: { p1.reset(new storm::solver::NativeMinMaxLinearEquationSolver(matrix, this->prefTech)); break; } case storm::solver::EquationSolverType::Topological: { STORM_LOG_THROW(prefTech != storm::solver::MinMaxTechniqueSelection::PolicyIteration, storm::exceptions::NotImplementedException, "Policy iteration for topological solver is not supported."); p1.reset(new storm::solver::TopologicalMinMaxLinearEquationSolver(matrix)); break; } } p1->setPolicyTracking(trackPolicy); return p1; } std::unique_ptr LpSolverFactory::create(std::string const& name) const { storm::solver::LpSolverType lpSolver = storm::settings::generalSettings().getLpSolver(); switch (lpSolver) { case storm::solver::LpSolverType::Gurobi: return std::unique_ptr(new storm::solver::GurobiLpSolver(name)); case storm::solver::LpSolverType::Glpk: return std::unique_ptr(new storm::solver::GlpkLpSolver(name)); default: return std::unique_ptr(new storm::solver::GurobiLpSolver(name)); } } std::unique_ptr GlpkLpSolverFactory::create(std::string const& name) const { return std::unique_ptr(new storm::solver::GlpkLpSolver(name)); } std::unique_ptr GurobiLpSolverFactory::create(std::string const& name) const { return std::unique_ptr(new storm::solver::GurobiLpSolver(name)); } std::unique_ptr getLpSolver(std::string const& name) { std::unique_ptr factory(new LpSolverFactory()); return factory->create(name); } template class SymbolicLinearEquationSolverFactory; template class SymbolicMinMaxLinearEquationSolverFactory; template class SymbolicGameSolverFactory; template class LinearEquationSolverFactory; template class GmmxxLinearEquationSolverFactory; template class NativeLinearEquationSolverFactory; template class MinMaxLinearEquationSolverFactory; } } }