Storm 1.13.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SolveGoal.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4
5#include <boost/optional.hpp>
6
11
14
15namespace storm {
16namespace storage {
17template<typename ValueType>
18class SparseMatrix;
19}
20
21namespace solver {
22
23template<typename ValueType>
25} // namespace solver
26
27namespace modelchecker {
28template<typename FormulaType, typename ValueType>
29class CheckTask;
30}
31namespace models {
32namespace sparse {
33template<typename ValueType, typename RewardModelType>
34class Model;
35}
36} // namespace models
37
38namespace solver {
39template<typename ValueType>
41
42template<typename ValueType, typename SolutionType = ValueType>
43class SolveGoal {
44 public:
45 SolveGoal();
46
47 template<typename RewardModelType, typename FormulaType>
50 if (checkTask.isOptimizationDirectionSet()) {
51 optimizationDirection = checkTask.getOptimizationDirection();
52 }
53 if (checkTask.isOnlyInitialStatesRelevantSet()) {
54 relevantValueVector = model.getInitialStates();
55 }
56 if (checkTask.isBoundSet()) {
57 comparisonType = checkTask.getBoundComparisonType();
58 threshold = checkTask.getBoundThreshold();
59 }
60 uncertaintyResolutionMode = checkTask.getUncertaintyResolutionMode();
61 }
62
63 SolveGoal(bool minimize);
68
72 void oneMinus();
73
74 bool hasDirection() const;
75
76 bool minimize() const;
77
79
81
82 bool isBounded() const;
83
84 bool boundIsALowerBound() const;
85
86 bool boundIsStrict() const;
87
89
90 SolutionType const& thresholdValue() const;
91
92 bool hasRelevantValues() const;
93
96
99
100 private:
101 boost::optional<OptimizationDirection> optimizationDirection;
102
103 boost::optional<storm::logic::ComparisonType> comparisonType;
104 boost::optional<SolutionType> threshold;
105 boost::optional<storm::storage::BitVector> relevantValueVector;
106 UncertaintyResolutionMode uncertaintyResolutionMode;
107};
108
109template<typename ValueType, typename MatrixType, typename SolutionType>
110std::unique_ptr<storm::solver::MinMaxLinearEquationSolver<ValueType, SolutionType>> configureMinMaxLinearEquationSolver(
112 MatrixType&& matrix, OptimizationDirectionSetting optimizationDirectionSetting = OptimizationDirectionSetting::Unset) {
113 std::unique_ptr<storm::solver::MinMaxLinearEquationSolver<ValueType, SolutionType>> solver = factory.create(env, std::forward<MatrixType>(matrix));
114 solver->setOptimizationDirection((optimizationDirectionSetting == OptimizationDirectionSetting::Unset) ? goal.direction()
115 : convert(optimizationDirectionSetting));
116 if (goal.isBounded()) {
117 if (goal.boundIsALowerBound()) {
118 solver->setTerminationCondition(std::make_unique<TerminateIfFilteredExtremumExceedsThreshold<SolutionType>>(
119 goal.relevantValues(), goal.boundIsStrict(), goal.thresholdValue(), true));
120 } else {
121 solver->setTerminationCondition(std::make_unique<TerminateIfFilteredExtremumBelowThreshold<SolutionType>>(
122 goal.relevantValues(), goal.boundIsStrict(), goal.thresholdValue(), false));
123 }
124 }
125 if (goal.hasRelevantValues()) {
126 solver->setRelevantValues(std::move(goal.relevantValues()));
127 }
128 return solver;
129}
130
131template<typename ValueType, typename MatrixType, typename SolutionType>
132std::unique_ptr<storm::solver::LinearEquationSolver<ValueType>> configureLinearEquationSolver(
134 MatrixType&& matrix) {
135 std::unique_ptr<storm::solver::LinearEquationSolver<ValueType>> solver = factory.create(env, std::forward<MatrixType>(matrix));
136 if (goal.isBounded()) {
137 solver->setTerminationCondition(std::make_unique<TerminateIfFilteredExtremumExceedsThreshold<ValueType>>(goal.relevantValues(), goal.boundIsStrict(),
138 goal.thresholdValue(), goal.minimize()));
139 }
140 return solver;
141}
142
143template<typename MatrixType>
144std::unique_ptr<storm::solver::LinearEquationSolver<storm::RationalFunction>> configureLinearEquationSolver(
146 MatrixType&& matrix) {
147 std::unique_ptr<storm::solver::LinearEquationSolver<storm::RationalFunction>> solver = factory.create(env, std::forward<MatrixType>(matrix));
148 return solver;
149}
150
151} // namespace solver
152} // namespace storm
bool isBoundSet() const
Retrieves whether there is a bound with which the values for the states will be compared.
Definition CheckTask.h:221
ValueType getBoundThreshold() const
Retrieves the value of the bound (if set).
Definition CheckTask.h:228
storm::logic::ComparisonType const & getBoundComparisonType() const
Retrieves the comparison type of the bound (if set).
Definition CheckTask.h:237
bool isOptimizationDirectionSet() const
Retrieves whether an optimization direction was set.
Definition CheckTask.h:149
storm::OptimizationDirection const & getOptimizationDirection() const
Retrieves the optimization direction (if set).
Definition CheckTask.h:156
bool isOnlyInitialStatesRelevantSet() const
Retrieves whether only the initial states are relevant in the computation.
Definition CheckTask.h:206
UncertaintyResolutionMode getUncertaintyResolutionMode() const
Retrieves the mode which decides how the uncertainty will be resolved.
Definition CheckTask.h:306
Base class for all sparse models.
Definition Model.h:30
storm::storage::BitVector const & getInitialStates() const
Retrieves the initial states of the model.
Definition Model.cpp:178
std::unique_ptr< LinearEquationSolver< ValueType > > create(Environment const &env, storm::storage::SparseMatrix< ValueType > const &matrix) const
Creates a new linear equation solver instance with the given matrix.
An interface that represents an abstract linear equation solver.
std::unique_ptr< MinMaxLinearEquationSolver< ValueType, SolutionType > > create(Environment const &env, storm::storage::SparseMatrix< ValueType > const &matrix) const
UncertaintyResolutionMode getUncertaintyResolutionMode() const
bool boundIsALowerBound() const
void oneMinus()
Flips the comparison type, the direction, and computes the new threshold as 1 - old threshold.
Definition SolveGoal.cpp:54
SolutionType const & thresholdValue() const
bool hasRelevantValues() const
SolveGoal(storm::models::sparse::Model< ValueType, RewardModelType > const &model, storm::modelchecker::CheckTask< FormulaType, SolutionType > const &checkTask)
Definition SolveGoal.h:48
void restrictRelevantValues(storm::storage::BitVector const &filter)
storm::storage::BitVector & relevantValues()
void setRelevantValues(storm::storage::BitVector &&values)
bool hasDirection() const
Definition SolveGoal.cpp:49
OptimizationDirection direction() const
Definition SolveGoal.cpp:89
storm::logic::ComparisonType boundComparisonType() const
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
A class that holds a possibly non-square matrix in the compressed row storage format.
OptimizationDirection convert(OptimizationDirectionSetting s)
std::unique_ptr< storm::solver::MinMaxLinearEquationSolver< ValueType, SolutionType > > configureMinMaxLinearEquationSolver(Environment const &env, SolveGoal< ValueType, SolutionType > &&goal, storm::solver::MinMaxLinearEquationSolverFactory< ValueType, SolutionType > const &factory, MatrixType &&matrix, OptimizationDirectionSetting optimizationDirectionSetting=OptimizationDirectionSetting::Unset)
Definition SolveGoal.h:110
bool constexpr minimize(OptimizationDirection d)
std::unique_ptr< storm::solver::LinearEquationSolver< ValueType > > configureLinearEquationSolver(Environment const &env, SolveGoal< ValueType, SolutionType > &&goal, storm::solver::LinearEquationSolverFactory< ValueType > const &factory, MatrixType &&matrix)
Definition SolveGoal.h:132