#include "src/utility/solver.h" #include #include "src/solver/SymbolicLinearEquationSolver.h" #include "src/solver/SymbolicMinMaxLinearEquationSolver.h" #include "src/solver/SymbolicGameSolver.h" #include "src/solver/NativeLinearEquationSolver.h" #include "src/solver/GmmxxLinearEquationSolver.h" #include "src/solver/GameSolver.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/solver/Z3SmtSolver.h" #include "src/solver/MathsatSmtSolver.h" #include "src/settings/SettingsManager.h" #include "src/settings/modules/MarkovChainSettings.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::getModule().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::getModule().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; break; case settings::modules::NativeEquationSolverSettings::LinearEquationMethod::SOR: this->method = storm::solver::NativeLinearEquationSolverSolutionMethod::SOR; break; } omega = storm::settings::getModule().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); } template MinMaxLinearEquationSolverFactory& MinMaxLinearEquationSolverFactory::setSolverType(storm::solver::EquationSolverTypeSelection solverTypeSel) { if(solverTypeSel == storm::solver::EquationSolverTypeSelection::FROMSETTINGS) { this->solverType = storm::settings::getModule().getEquationSolver(); } else { this->solverType = storm::solver::convert(solverTypeSel); } return *this; } template MinMaxLinearEquationSolverFactory& MinMaxLinearEquationSolverFactory::setPreferredTechnique(storm::solver::MinMaxTechniqueSelection preferredTech) { this->prefTech = preferredTech; return *this; } template std::unique_ptr> MinMaxLinearEquationSolverFactory::create(storm::storage::SparseMatrix const& matrix, bool trackScheduler) const { 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->setTrackScheduler(trackScheduler); return p1; } template std::unique_ptr> GameSolverFactory::create(storm::storage::SparseMatrix const& player1Matrix, storm::storage::SparseMatrix const& player2Matrix) const { return std::unique_ptr>(new storm::solver::GameSolver(player1Matrix, player2Matrix)); } std::unique_ptr LpSolverFactory::create(std::string const& name, storm::solver::LpSolverTypeSelection solvT) const { storm::solver::LpSolverType t; if(solvT == storm::solver::LpSolverTypeSelection::FROMSETTINGS) { t = storm::settings::getModule().getLpSolver(); } else { t = convert(solvT); } switch (t) { 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)); } } std::unique_ptr LpSolverFactory::create(std::string const& name) const { return LpSolverFactory::create(name, storm::solver::LpSolverTypeSelection::FROMSETTINGS); } std::unique_ptr GlpkLpSolverFactory::create(std::string const& name) const { return LpSolverFactory::create(name, storm::solver::LpSolverTypeSelection::Glpk); } std::unique_ptr GurobiLpSolverFactory::create(std::string const& name) const { return LpSolverFactory::create(name, storm::solver::LpSolverTypeSelection::Gurobi); } std::unique_ptr getLpSolver(std::string const& name, storm::solver::LpSolverTypeSelection solvType) { std::unique_ptr factory(new LpSolverFactory()); return factory->create(name, solvType); } std::unique_ptr SmtSolverFactory::create(storm::expressions::ExpressionManager& manager) const { storm::solver::SmtSolverType smtSolverType = storm::settings::getModule().getSmtSolver(); switch (smtSolverType) { case storm::solver::SmtSolverType::Z3: return std::unique_ptr(new storm::solver::Z3SmtSolver(manager)); case storm::solver::SmtSolverType::Mathsat: return std::unique_ptr(new storm::solver::MathsatSmtSolver(manager)); } } std::unique_ptr Z3SmtSolverFactory::create(storm::expressions::ExpressionManager& manager) const { return std::unique_ptr(new storm::solver::Z3SmtSolver(manager)); } std::unique_ptr MathsatSmtSolverFactory::create(storm::expressions::ExpressionManager& manager) const { return std::unique_ptr(new storm::solver::MathsatSmtSolver(manager)); } std::unique_ptr getSmtSolver(storm::expressions::ExpressionManager& manager) { std::unique_ptr factory(new MathsatSmtSolverFactory()); return factory->create(manager); } template class SymbolicLinearEquationSolverFactory; template class SymbolicLinearEquationSolverFactory; template class SymbolicMinMaxLinearEquationSolverFactory; template class SymbolicMinMaxLinearEquationSolverFactory; template class SymbolicGameSolverFactory; template class SymbolicGameSolverFactory; template class LinearEquationSolverFactory; template class GmmxxLinearEquationSolverFactory; template class NativeLinearEquationSolverFactory; template class MinMaxLinearEquationSolverFactory; template class GameSolverFactory; } } }