20template<
typename ValueType,
typename SolutionType>
24 uniqueSolution(false),
25 noEndComponents(false),
26 cachingEnabled(false),
27 requirementsChecked(false),
32template<
typename ValueType,
typename SolutionType>
37template<
typename ValueType,
typename SolutionType>
39 std::vector<ValueType>
const& b)
const {
41 "The requirements of the solver have not been marked as checked. Please provide the appropriate check or mark the requirements "
42 "as checked (if applicable).");
52template<
typename ValueType,
typename SolutionType>
54 std::vector<ValueType>
const& b)
const {
57 "Uncertainty resolution mode not set.");
61template<
typename ValueType,
typename SolutionType>
66template<
typename ValueType,
typename SolutionType>
71template<
typename ValueType,
typename SolutionType>
73 uniqueSolution = value;
76template<
typename ValueType,
typename SolutionType>
78 return uniqueSolution || noEndComponents;
81template<
typename ValueType,
typename SolutionType>
83 noEndComponents = value;
86template<
typename ValueType,
typename SolutionType>
88 return noEndComponents;
91template<
typename ValueType,
typename SolutionType>
94 if (!this->trackScheduler) {
99template<
typename ValueType,
typename SolutionType>
101 return this->trackScheduler;
104template<
typename ValueType,
typename SolutionType>
109template<
typename ValueType,
typename SolutionType>
111 STORM_LOG_THROW(
hasScheduler(), storm::exceptions::IllegalFunctionCallException,
"Cannot retrieve scheduler, because none was generated.");
113 uint_fast64_t state = 0;
115 result.
setChoice(schedulerChoice, state);
121template<
typename ValueType,
typename SolutionType>
123 STORM_LOG_THROW(
hasScheduler(), storm::exceptions::IllegalFunctionCallException,
"Cannot retrieve scheduler choices, because they were not generated.");
127template<
typename ValueType,
typename SolutionType>
130 "Cannot retrieve robust index into scheduler choices, because they were not generated.");
134template<
typename ValueType,
typename SolutionType>
136 if (cachingEnabled && !value) {
140 cachingEnabled = value;
143template<
typename ValueType,
typename SolutionType>
145 return cachingEnabled;
148template<
typename ValueType,
typename SolutionType>
153template<
typename ValueType,
typename SolutionType>
158template<
typename ValueType,
typename SolutionType>
163template<
typename ValueType,
typename SolutionType>
168template<
typename ValueType,
typename SolutionType>
174template<
typename ValueType,
typename SolutionType>
176 this->requirementsChecked = value;
179template<
typename ValueType,
typename SolutionType>
181 return requirementsChecked;
184template<
typename ValueType,
typename SolutionType>
190template<
typename ValueType,
typename SolutionType>
195template<
typename ValueType,
typename SolutionType>
197 this->requirementsChecked = value;
200template<
typename ValueType,
typename SolutionType>
202 return this->requirementsChecked;
205template<
typename ValueType,
typename SolutionType>
207 this->uncertaintyResolutionMode = uncertaintyResolutionMode;
210template<
typename ValueType,
typename SolutionType>
212 return this->uncertaintyResolutionMode;
215template<
typename ValueType,
typename SolutionType>
217 Environment const& env,
bool hasUniqueSolution,
bool hasNoEndComponents, boost::optional<storm::solver::OptimizationDirection>
const& direction,
218 bool hasInitialScheduler,
bool trackScheduler)
const {
220 std::unique_ptr<MinMaxLinearEquationSolver<ValueType, SolutionType>>
solver = this->
create(env);
221 solver->setTrackScheduler(trackScheduler);
222 solver->setHasUniqueSolution(hasUniqueSolution);
223 solver->setHasNoEndComponents(hasNoEndComponents);
224 return solver->getRequirements(env, direction, hasInitialScheduler);
227template<
typename ValueType,
typename SolutionType>
230 std::unique_ptr<MinMaxLinearEquationSolver<ValueType, SolutionType>>
solver = this->
create(env);
231 solver->setMatrix(matrix);
235template<
typename ValueType,
typename SolutionType>
238 std::unique_ptr<MinMaxLinearEquationSolver<ValueType, SolutionType>>
solver = this->
create(env);
239 solver->setMatrix(std::move(matrix));
243template<
typename ValueType,
typename SolutionType>
249template<
typename ValueType,
typename SolutionType>
252 std::unique_ptr<MinMaxLinearEquationSolver<ValueType, SolutionType>> result;
255 if (method == MinMaxMethod::ValueIteration || method == MinMaxMethod::PolicyIteration || method == MinMaxMethod::RationalSearch ||
256 method == MinMaxMethod::IntervalIteration || method == MinMaxMethod::SoundValueIteration || method == MinMaxMethod::OptimisticValueIteration ||
257 method == MinMaxMethod::GuessingValueIteration || method == MinMaxMethod::ViToPi) {
258 result = std::make_unique<IterativeMinMaxLinearEquationSolver<ValueType, SolutionType>>(
259 std::make_unique<GeneralLinearEquationSolverFactory<SolutionType>>());
260 }
else if (method == MinMaxMethod::Topological) {
264 result = std::make_unique<TopologicalMinMaxLinearEquationSolver<ValueType, SolutionType>>();
266 }
else if (method == MinMaxMethod::LinearProgramming || method == MinMaxMethod::ViToLp) {
272 }
else if (method == MinMaxMethod::Acyclic) {
274 STORM_LOG_ERROR(
"Acyclic method not implemented for ValueType==Interval");
276 result = std::make_unique<AcyclicMinMaxLinearEquationSolver<ValueType>>();
279 STORM_LOG_THROW(
false, storm::exceptions::InvalidSettingsException,
"Unsupported technique.");
281 result->setRequirementsChecked(this->isRequirementsCheckedSet());
289 std::unique_ptr<MinMaxLinearEquationSolver<storm::RationalNumber>> result;
291 if (method == MinMaxMethod::ValueIteration || method == MinMaxMethod::PolicyIteration || method == MinMaxMethod::RationalSearch ||
292 method == MinMaxMethod::IntervalIteration || method == MinMaxMethod::SoundValueIteration || method == MinMaxMethod::OptimisticValueIteration ||
293 method == MinMaxMethod::GuessingValueIteration || method == MinMaxMethod::ViToPi) {
294 result = std::make_unique<IterativeMinMaxLinearEquationSolver<storm::RationalNumber>>(
295 std::make_unique<GeneralLinearEquationSolverFactory<storm::RationalNumber>>());
296 }
else if (method == MinMaxMethod::LinearProgramming || method == MinMaxMethod::ViToLp) {
298 }
else if (method == MinMaxMethod::Acyclic) {
299 result = std::make_unique<AcyclicMinMaxLinearEquationSolver<storm::RationalNumber>>();
300 }
else if (method == MinMaxMethod::Topological) {
301 result = std::make_unique<TopologicalMinMaxLinearEquationSolver<storm::RationalNumber>>();
303 STORM_LOG_THROW(
false, storm::exceptions::InvalidSettingsException,
"Unsupported technique.");
310template<
typename ValueType,
typename SolutionType>
315 STORM_LOG_WARN(
"Selected method is not supported for this solver and interval models, switching to robust value iteration.");
316 method = MinMaxMethod::ValueIteration;
SolverEnvironment & solver()
storm::solver::MinMaxMethod const & getMethod() const
MinMaxSolverEnvironment & minMax()
uint64_t getShowProgressDelay() const
bool isVerboseSet() const
void clearSolutionBounds() const
void finalizeSolutionBounds(std::vector< ValueType > const &x) const
virtual std::unique_ptr< MinMaxLinearEquationSolver< ValueType, SolutionType > > create(Environment const &env) const override
GeneralMinMaxLinearEquationSolverFactory()
MinMaxMethod getMethod(Environment env) const
MinMaxLinearEquationSolverRequirements getRequirements(Environment const &env, bool hasUniqueSolution=false, bool hasNoEndComponents=false, boost::optional< storm::solver::OptimizationDirection > const &direction=boost::none, bool hasInitialScheduler=false, bool trackScheduler=false) const
Retrieves the requirements of the solver that would be created when calling create() right now.
std::unique_ptr< MinMaxLinearEquationSolver< ValueType, SolutionType > > create(Environment const &env, storm::storage::SparseMatrix< ValueType > const &matrix) const
bool isRequirementsCheckedSet() const
void setRequirementsChecked(bool value=true)
MinMaxLinearEquationSolverFactory()
A class representing the interface that all min-max linear equation solvers shall implement.
virtual ~MinMaxLinearEquationSolver()
virtual void setSchedulerFixedForRowGroup(storm::storage::BitVector &&schedulerFixedForRowGroup)
Sets the states for which the choices are fixed.
void unsetOptimizationDirection()
Unsets the optimization direction to use for calls to methods that do not explicitly provide one.
storm::storage::Scheduler< ValueType > computeScheduler() const
Retrieves the generated scheduler.
void setHasUniqueSolution(bool value=true)
Sets whether the solution to the min max equation system is known to be unique.
bool solveEquations(Environment const &env, OptimizationDirection d, std::vector< SolutionType > &x, std::vector< ValueType > const &b) const
Solves the equation system x = min/max(A*x + b) given by the parameters.
boost::optional< std::vector< uint_fast64_t > > robustSchedulerIndex
virtual void clearCache() const
Clears the currently cached data that has been stored during previous calls of the solver.
void setOptimizationDirection(OptimizationDirection direction)
Sets an optimization direction to use for calls to methods that do not explicitly provide one.
MinMaxLinearEquationSolver(OptimizationDirectionSetting direction=OptimizationDirectionSetting::Unset)
OptimizationDirectionSetting direction
The optimization direction to use for calls to functions that do not provide it explicitly....
boost::optional< std::vector< uint_fast64_t > > initialScheduler
void setInitialScheduler(std::vector< uint_fast64_t > &&choices)
Sets a valid initial scheduler that is required by some solvers (see requirements of solvers).
bool hasScheduler() const
Retrieves whether the solver generated a scheduler.
std::vector< uint_fast64_t > const & getSchedulerChoices() const
Retrieves the generated (deterministic) choices of the optimal scheduler.
std::vector< uint_fast64_t > const & getInitialScheduler() const
Retrieves the initial scheduler if one was set.
bool trackScheduler
Whether we generate a scheduler during solving.
void setRequirementsChecked(bool value=true)
Notifies the solver that the requirements for solving equations have been checked.
bool hasUniqueSolution() const
Retrieves whether the solution to the min max equation system is assumed to be unique.
virtual MinMaxLinearEquationSolverRequirements getRequirements(Environment const &env, boost::optional< storm::solver::OptimizationDirection > const &direction=boost::none, bool const &hasInitialScheduler=false) const
Retrieves the requirements of this solver for solving equations with the current settings.
boost::optional< storm::storage::BitVector > choiceFixedForRowGroup
void setHasNoEndComponents(bool value=true)
Sets whether the min max equation system is known to not have any end components.
std::vector< uint_fast64_t > const & getRobustSchedulerIndex() const
Retrieves the generated robust index into the scheduler.
void setUncertaintyResolutionMode(UncertaintyResolutionMode uncertaintyResolutionMode)
Sets how the uncertainty should be resolved.
UncertaintyResolutionMode getUncertaintyResolutionMode() const
Retrieves the mode indicating how the uncertainty should be resolved.
bool isTrackSchedulerSet() const
Retrieves whether this solver is set to generate schedulers.
bool hasNoEndComponents() const
Retrieves whether the min max equation system is known to not have any end components.
virtual bool internalSolveEquations(Environment const &env, OptimizationDirection d, std::vector< ValueType > &x, std::vector< ValueType > const &b) const=0
void setCachingEnabled(bool value)
Sets whether some of the generated data during solver calls should be cached.
bool isRequirementsCheckedSet() const
bool isCachingEnabled() const
Retrieves whether some of the generated data during solver calls should be cached.
boost::optional< std::vector< uint_fast64_t > > schedulerChoices
bool hasInitialScheduler() const
Returns true iff an initial scheduler is set.
void setTrackScheduler(bool trackScheduler=true)
Sets whether schedulers are generated when solving equation systems.
A bit vector that is internally represented as a vector of 64-bit values.
This class defines which action is chosen in a particular state of a non-deterministic model.
void setChoice(SchedulerChoice< ValueType > const &choice, uint_fast64_t modelState, uint_fast64_t memoryState=0)
Sets the choice defined by the scheduler for the given state.
A class that holds a possibly non-square matrix in the compressed row storage format.
#define STORM_LOG_WARN(message)
#define STORM_LOG_ERROR(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
#define STORM_LOG_WARN_COND_DEBUG(cond, message)
OptimizationDirection convert(OptimizationDirectionSetting s)
bool isSet(OptimizationDirectionSetting s)
OptimizationDirectionSetting
UncertaintyResolutionMode
std::unique_ptr< LpSolverFactory< ValueType > > getLpSolverFactory(storm::Environment const &env, storm::solver::LpSolverTypeSelection solvType)
constexpr bool IsIntervalType
Helper to check if a type is an interval.