20template<
typename ValueType,
typename SolutionType>
22 : direction(direction),
23 trackScheduler(false),
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).");
43 return internalSolveEquations(env, d, x, b);
46template<
typename ValueType,
typename SolutionType>
48 std::vector<ValueType>
const& b)
const {
49 STORM_LOG_THROW(
isSet(this->direction), storm::exceptions::IllegalFunctionCallException,
"Optimization direction not set.");
50 STORM_LOG_THROW(
isSet(this->uncertaintyResolutionMode) || !storm::IsIntervalType<ValueType>, storm::exceptions::IllegalFunctionCallException,
51 "Uncertainty resolution mode not set.");
52 solveEquations(env,
convert(this->direction), x, b);
55template<
typename ValueType,
typename SolutionType>
60template<
typename ValueType,
typename SolutionType>
65template<
typename ValueType,
typename SolutionType>
67 uniqueSolution = value;
70template<
typename ValueType,
typename SolutionType>
72 return uniqueSolution || noEndComponents;
75template<
typename ValueType,
typename SolutionType>
77 noEndComponents = value;
80template<
typename ValueType,
typename SolutionType>
82 return noEndComponents;
85template<
typename ValueType,
typename SolutionType>
87 this->trackScheduler = trackScheduler;
88 if (!this->trackScheduler) {
89 schedulerChoices = boost::none;
93template<
typename ValueType,
typename SolutionType>
95 return this->trackScheduler;
98template<
typename ValueType,
typename SolutionType>
100 return static_cast<bool>(schedulerChoices);
103template<
typename ValueType,
typename SolutionType>
105 STORM_LOG_THROW(hasScheduler(), storm::exceptions::IllegalFunctionCallException,
"Cannot retrieve scheduler, because none was generated.");
107 uint_fast64_t state = 0;
108 for (
auto const& schedulerChoice : schedulerChoices.get()) {
109 result.
setChoice(schedulerChoice, state);
115template<
typename ValueType,
typename SolutionType>
117 STORM_LOG_THROW(hasScheduler(), storm::exceptions::IllegalFunctionCallException,
"Cannot retrieve scheduler choices, because they were not generated.");
118 return schedulerChoices.get();
121template<
typename ValueType,
typename SolutionType>
123 STORM_LOG_THROW(hasScheduler(), storm::exceptions::IllegalFunctionCallException,
124 "Cannot retrieve robust index into scheduler choices, because they were not generated.");
125 return robustSchedulerIndex.get();
128template<
typename ValueType,
typename SolutionType>
130 if (cachingEnabled && !value) {
134 cachingEnabled = value;
137template<
typename ValueType,
typename SolutionType>
139 return cachingEnabled;
142template<
typename ValueType,
typename SolutionType>
147template<
typename ValueType,
typename SolutionType>
149 initialScheduler = std::move(choices);
152template<
typename ValueType,
typename SolutionType>
154 return static_cast<bool>(initialScheduler);
157template<
typename ValueType,
typename SolutionType>
159 return initialScheduler.get();
162template<
typename ValueType,
typename SolutionType>
164 Environment const&, boost::optional<storm::solver::OptimizationDirection>
const& direction,
bool const& hasInitialScheduler)
const {
168template<
typename ValueType,
typename SolutionType>
170 this->requirementsChecked = value;
173template<
typename ValueType,
typename SolutionType>
175 return requirementsChecked;
178template<
typename ValueType,
typename SolutionType>
180 STORM_LOG_ASSERT(this->hasInitialScheduler(),
"Expecting an initial scheduler to be set before setting the states for which the choices are fixed");
181 this->choiceFixedForRowGroup = std::move(schedulerFixedForRowGroup);
184template<
typename ValueType,
typename SolutionType>
189template<
typename ValueType,
typename SolutionType>
191 this->requirementsChecked = value;
194template<
typename ValueType,
typename SolutionType>
196 return this->requirementsChecked;
199template<
typename ValueType,
typename SolutionType>
201 this->uncertaintyResolutionMode = uncertaintyResolutionMode;
204template<
typename ValueType,
typename SolutionType>
206 return this->uncertaintyResolutionMode;
209template<
typename ValueType,
typename SolutionType>
211 Environment const& env,
bool hasUniqueSolution,
bool hasNoEndComponents, boost::optional<storm::solver::OptimizationDirection>
const& direction,
212 bool hasInitialScheduler,
bool trackScheduler)
const {
214 std::unique_ptr<MinMaxLinearEquationSolver<ValueType, SolutionType>> solver = this->create(env);
215 solver->setTrackScheduler(trackScheduler);
216 solver->setHasUniqueSolution(hasUniqueSolution);
217 solver->setHasNoEndComponents(hasNoEndComponents);
218 return solver->getRequirements(env, direction, hasInitialScheduler);
221template<
typename ValueType,
typename SolutionType>
224 std::unique_ptr<MinMaxLinearEquationSolver<ValueType, SolutionType>> solver = this->create(env);
225 solver->setMatrix(matrix);
229template<
typename ValueType,
typename SolutionType>
232 std::unique_ptr<MinMaxLinearEquationSolver<ValueType, SolutionType>> solver = this->create(env);
233 solver->setMatrix(std::move(matrix));
237template<
typename ValueType,
typename SolutionType>
243template<
typename ValueType,
typename SolutionType>
246 std::unique_ptr<MinMaxLinearEquationSolver<ValueType, SolutionType>> result;
249 if (method == MinMaxMethod::ValueIteration || method == MinMaxMethod::PolicyIteration || method == MinMaxMethod::RationalSearch ||
250 method == MinMaxMethod::IntervalIteration || method == MinMaxMethod::SoundValueIteration || method == MinMaxMethod::OptimisticValueIteration ||
251 method == MinMaxMethod::GuessingValueIteration || method == MinMaxMethod::ViToPi) {
252 result = std::make_unique<IterativeMinMaxLinearEquationSolver<ValueType, SolutionType>>(
253 std::make_unique<GeneralLinearEquationSolverFactory<SolutionType>>());
254 }
else if (method == MinMaxMethod::Topological) {
255 if constexpr (std::is_same_v<ValueType, storm::Interval>) {
256 STORM_LOG_ERROR(
"Topological method not implemented for ValueType==Interval.");
258 result = std::make_unique<TopologicalMinMaxLinearEquationSolver<ValueType, SolutionType>>();
260 }
else if (method == MinMaxMethod::LinearProgramming || method == MinMaxMethod::ViToLp) {
261 if constexpr (std::is_same_v<ValueType, storm::Interval>) {
264 result = std::make_unique<LpMinMaxLinearEquationSolver<ValueType>>(storm::utility::solver::getLpSolverFactory<ValueType>());
266 }
else if (method == MinMaxMethod::Acyclic) {
267 if constexpr (std::is_same_v<ValueType, storm::Interval>) {
268 STORM_LOG_ERROR(
"Acyclic method not implemented for ValueType==Interval");
270 result = std::make_unique<AcyclicMinMaxLinearEquationSolver<ValueType>>();
273 STORM_LOG_THROW(
false, storm::exceptions::InvalidSettingsException,
"Unsupported technique.");
275 result->setRequirementsChecked(this->isRequirementsCheckedSet());
282 std::unique_ptr<MinMaxLinearEquationSolver<storm::RationalNumber>> result;
283 auto method = getMethod(env);
284 if (method == MinMaxMethod::ValueIteration || method == MinMaxMethod::PolicyIteration || method == MinMaxMethod::RationalSearch ||
285 method == MinMaxMethod::IntervalIteration || method == MinMaxMethod::SoundValueIteration || method == MinMaxMethod::OptimisticValueIteration ||
286 method == MinMaxMethod::GuessingValueIteration || method == MinMaxMethod::ViToPi) {
287 result = std::make_unique<IterativeMinMaxLinearEquationSolver<storm::RationalNumber>>(
288 std::make_unique<GeneralLinearEquationSolverFactory<storm::RationalNumber>>());
289 }
else if (method == MinMaxMethod::LinearProgramming || method == MinMaxMethod::ViToLp) {
290 result = std::make_unique<LpMinMaxLinearEquationSolver<storm::RationalNumber>>(storm::utility::solver::getLpSolverFactory<storm::RationalNumber>());
291 }
else if (method == MinMaxMethod::Acyclic) {
292 result = std::make_unique<AcyclicMinMaxLinearEquationSolver<storm::RationalNumber>>();
293 }
else if (method == MinMaxMethod::Topological) {
294 result = std::make_unique<TopologicalMinMaxLinearEquationSolver<storm::RationalNumber>>();
296 STORM_LOG_THROW(
false, storm::exceptions::InvalidSettingsException,
"Unsupported technique.");
298 result->setRequirementsChecked(this->isRequirementsCheckedSet());
302template<
typename ValueType,
typename SolutionType>
306 if (storm::IsIntervalType<ValueType> && method != MinMaxMethod::ValueIteration) {
307 STORM_LOG_WARN(
"Selected method is not supported for this solver and interval models, switching to robust value iteration.");
308 method = MinMaxMethod::ValueIteration;
SolverEnvironment & solver()
storm::solver::MinMaxMethod const & getMethod() const
MinMaxSolverEnvironment & minMax()
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.
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)
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.
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.
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.
void setCachingEnabled(bool value)
Sets whether some of the generated data during solver calls should be cached.
bool isRequirementsCheckedSet() const
Retrieves whether the solver is aware that the requirements were checked.
bool isCachingEnabled() const
Retrieves whether some of the generated data during solver calls should be cached.
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