Storm 1.11.1.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>
24class LinearEquationSolverFactory;
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>
40class LinearEquationSolver;
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);
65 SolveGoal(OptimizationDirection d, storm::logic::ComparisonType boundComparisonType, SolutionType const& boundThreshold,
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
88 SolutionType const& thresholdValue() const;
89
90 bool hasRelevantValues() const;
91
94
97
98 private:
99 boost::optional<OptimizationDirection> optimizationDirection;
100
101 boost::optional<storm::logic::ComparisonType> comparisonType;
102 boost::optional<SolutionType> threshold;
103 boost::optional<storm::storage::BitVector> relevantValueVector;
104 UncertaintyResolutionMode uncertaintyResolutionMode;
105};
106
107template<typename ValueType, typename MatrixType, typename SolutionType>
108std::unique_ptr<storm::solver::MinMaxLinearEquationSolver<ValueType, SolutionType>> configureMinMaxLinearEquationSolver(
110 MatrixType&& matrix, OptimizationDirectionSetting optimizationDirectionSetting = OptimizationDirectionSetting::Unset) {
111 std::unique_ptr<storm::solver::MinMaxLinearEquationSolver<ValueType, SolutionType>> solver = factory.create(env, std::forward<MatrixType>(matrix));
112 solver->setOptimizationDirection((optimizationDirectionSetting == OptimizationDirectionSetting::Unset) ? goal.direction()
113 : convert(optimizationDirectionSetting));
114 if (goal.isBounded()) {
115 if (goal.boundIsALowerBound()) {
116 solver->setTerminationCondition(std::make_unique<TerminateIfFilteredExtremumExceedsThreshold<SolutionType>>(
117 goal.relevantValues(), goal.boundIsStrict(), goal.thresholdValue(), true));
118 } else {
119 solver->setTerminationCondition(std::make_unique<TerminateIfFilteredExtremumBelowThreshold<SolutionType>>(
120 goal.relevantValues(), goal.boundIsStrict(), goal.thresholdValue(), false));
121 }
122 }
123 if (goal.hasRelevantValues()) {
124 solver->setRelevantValues(std::move(goal.relevantValues()));
125 }
126 return solver;
127}
128
129template<typename ValueType, typename MatrixType, typename SolutionType>
130std::unique_ptr<storm::solver::LinearEquationSolver<ValueType>> configureLinearEquationSolver(
132 MatrixType&& matrix) {
133 std::unique_ptr<storm::solver::LinearEquationSolver<ValueType>> solver = factory.create(env, std::forward<MatrixType>(matrix));
134 if (goal.isBounded()) {
135 solver->setTerminationCondition(std::make_unique<TerminateIfFilteredExtremumExceedsThreshold<ValueType>>(goal.relevantValues(), goal.boundIsStrict(),
136 goal.thresholdValue(), goal.minimize()));
137 }
138 return solver;
139}
140
141template<typename MatrixType>
142std::unique_ptr<storm::solver::LinearEquationSolver<storm::RationalFunction>> configureLinearEquationSolver(
144 MatrixType&& matrix) {
145 std::unique_ptr<storm::solver::LinearEquationSolver<storm::RationalFunction>> solver = factory.create(env, std::forward<MatrixType>(matrix));
146 return solver;
147}
148
149} // namespace solver
150} // 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:32
storm::storage::BitVector const & getInitialStates() const
Retrieves the initial states of the model.
Definition Model.cpp:179
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.
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
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
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:108
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:130