#include "src/solver/MinMaxLinearEquationSolver.h" #include #include "src/solver/LinearEquationSolver.h" #include "src/solver/StandardMinMaxLinearEquationSolver.h" #include "src/solver/TopologicalMinMaxLinearEquationSolver.h" #include "src/settings/SettingsManager.h" #include "src/settings/modules/MinMaxEquationSolverSettings.h" #include "src/utility/macros.h" #include "src/exceptions/NotImplementedException.h" #include "src/exceptions/InvalidSettingsException.h" #include "src/exceptions/IllegalFunctionCallException.h" namespace storm { namespace solver { template MinMaxLinearEquationSolver::MinMaxLinearEquationSolver(OptimizationDirectionSetting direction) : direction(direction), trackScheduler(false), cachingEnabled(false) { // Intentionally left empty. } template MinMaxLinearEquationSolver::~MinMaxLinearEquationSolver() { // Intentionally left empty. } template void MinMaxLinearEquationSolver::solveEquations(std::vector& x, std::vector const& b) const { STORM_LOG_THROW(isSet(this->direction), storm::exceptions::IllegalFunctionCallException, "Optimization direction not set."); solveEquations(convert(this->direction), x, b); } template void MinMaxLinearEquationSolver::repeatedMultiply(std::vector& x, std::vector* b, uint_fast64_t n) const { STORM_LOG_THROW(isSet(this->direction), storm::exceptions::IllegalFunctionCallException, "Optimization direction not set."); return repeatedMultiply(convert(this->direction), x, b, n); } template void MinMaxLinearEquationSolver::setOptimizationDirection(OptimizationDirection d) { direction = convert(d); } template void MinMaxLinearEquationSolver::unsetOptimizationDirection() { direction = OptimizationDirectionSetting::Unset; } template void MinMaxLinearEquationSolver::setTrackScheduler(bool trackScheduler) { this->trackScheduler = trackScheduler; if (!this->trackScheduler) { scheduler = boost::none; } } template bool MinMaxLinearEquationSolver::isTrackSchedulerSet() const { return this->trackScheduler; } template bool MinMaxLinearEquationSolver::hasScheduler() const { return static_cast(scheduler); } template storm::storage::TotalScheduler const& MinMaxLinearEquationSolver::getScheduler() const { STORM_LOG_THROW(scheduler, storm::exceptions::IllegalFunctionCallException, "Cannot retrieve scheduler, because none was generated."); return *scheduler.get(); } template std::unique_ptr MinMaxLinearEquationSolver:: getScheduler() { STORM_LOG_THROW(scheduler, storm::exceptions::IllegalFunctionCallException, "Cannot retrieve scheduler, because none was generated."); return std::move(scheduler.get()); } template void MinMaxLinearEquationSolver::setCachingEnabled(bool value) { if(cachingEnabled && !value) { // caching will be turned off. Hence we clear the cache at this point clearCache(); } cachingEnabled = value; } template bool MinMaxLinearEquationSolver::isCachingEnabled() const { return cachingEnabled; } template void MinMaxLinearEquationSolver::clearCache() const { // Intentionally left empty. } template MinMaxLinearEquationSolverFactory::MinMaxLinearEquationSolverFactory(bool trackScheduler) : trackScheduler(trackScheduler) { // Intentionally left empty. } template std::unique_ptr> MinMaxLinearEquationSolverFactory::create(storm::storage::SparseMatrix&& matrix) const { return this->create(matrix); } template void MinMaxLinearEquationSolverFactory::setTrackScheduler(bool value) { this->trackScheduler = value; } template bool MinMaxLinearEquationSolverFactory::isTrackSchedulerSet() const { return trackScheduler; } template GeneralMinMaxLinearEquationSolverFactory::GeneralMinMaxLinearEquationSolverFactory(bool trackScheduler) : MinMaxLinearEquationSolverFactory(trackScheduler) { // Intentionally left empty. } template std::unique_ptr> GeneralMinMaxLinearEquationSolverFactory::create(storm::storage::SparseMatrix const& matrix) const { return selectSolver(matrix); } template std::unique_ptr> GeneralMinMaxLinearEquationSolverFactory::create(storm::storage::SparseMatrix&& matrix) const { return selectSolver(std::move(matrix)); } template template std::unique_ptr> GeneralMinMaxLinearEquationSolverFactory::selectSolver(MatrixType&& matrix) const { std::unique_ptr> result; auto method = storm::settings::getModule().getMinMaxEquationSolvingMethod(); if (method == MinMaxMethod::ValueIteration || method == MinMaxMethod::PolicyIteration) { result = std::make_unique>(std::forward(matrix), std::make_unique>()); } else if (method == MinMaxMethod::Topological) { result = std::make_unique>(std::forward(matrix)); } else { STORM_LOG_THROW(false, storm::exceptions::InvalidSettingsException, "Unsupported technique."); } return result; } #ifdef STORM_HAVE_CARL template<> template std::unique_ptr> GeneralMinMaxLinearEquationSolverFactory::selectSolver(MatrixType&& matrix) const { std::unique_ptr> result; auto method = storm::settings::getModule().getMinMaxEquationSolvingMethod(); STORM_LOG_THROW(method == MinMaxMethod::ValueIteration || method == MinMaxMethod::PolicyIteration, storm::exceptions::InvalidSettingsException, "For this data type only value iteration and policy iteration are available."); return std::make_unique>(std::forward(matrix), std::make_unique>()); } #endif template class MinMaxLinearEquationSolver; template class MinMaxLinearEquationSolver; template class MinMaxLinearEquationSolverFactory; template class GeneralMinMaxLinearEquationSolverFactory; #ifdef STORM_HAVE_CARL template class MinMaxLinearEquationSolver; template class MinMaxLinearEquationSolverFactory; template class GeneralMinMaxLinearEquationSolverFactory; #endif } }