Storm
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
10
13
14namespace storm {
15namespace storage {
16template<typename ValueType>
17class SparseMatrix;
18}
19
20namespace solver {
21
22template<typename ValueType>
23class LinearEquationSolverFactory;
24} // namespace solver
25
26namespace modelchecker {
27template<typename FormulaType, typename ValueType>
28class CheckTask;
29}
30namespace models {
31namespace sparse {
32template<typename ValueType, typename RewardModelType>
33class Model;
34}
35} // namespace models
36
37namespace solver {
38template<typename ValueType>
39class LinearEquationSolver;
40
41template<typename ValueType, typename SolutionType = ValueType>
42class SolveGoal {
43 public:
44 SolveGoal();
45
46 template<typename RewardModelType, typename FormulaType>
49 if (checkTask.isOptimizationDirectionSet()) {
50 optimizationDirection = checkTask.getOptimizationDirection();
51 }
52 if (checkTask.isOnlyInitialStatesRelevantSet()) {
53 relevantValueVector = model.getInitialStates();
54 }
55 if (checkTask.isBoundSet()) {
56 comparisonType = checkTask.getBoundComparisonType();
57 threshold = checkTask.getBoundThreshold();
58 }
59 robustAgainstUncertainty = checkTask.getRobustUncertainty();
60 }
61
62 SolveGoal(bool minimize);
64 SolveGoal(OptimizationDirection d, storm::logic::ComparisonType boundComparisonType, SolutionType const& boundThreshold,
67
71 void oneMinus();
72
73 bool hasDirection() const;
74
75 bool minimize() const;
76
78
79 bool isRobust() const;
80
81 bool isBounded() const;
82
83 bool boundIsALowerBound() const;
84
85 bool boundIsStrict() const;
86
87 SolutionType const& thresholdValue() const;
88
89 bool hasRelevantValues() const;
90
93
96
97 private:
98 boost::optional<OptimizationDirection> optimizationDirection;
99
100 boost::optional<storm::logic::ComparisonType> comparisonType;
101 boost::optional<SolutionType> threshold;
102 boost::optional<storm::storage::BitVector> relevantValueVector;
103 bool robustAgainstUncertainty = true; // If set to false, the uncertainty is interpreted as controllable.
104};
105
106template<typename ValueType, typename MatrixType, typename SolutionType>
107std::unique_ptr<storm::solver::MinMaxLinearEquationSolver<ValueType, SolutionType>> configureMinMaxLinearEquationSolver(
109 MatrixType&& matrix) {
110 std::unique_ptr<storm::solver::MinMaxLinearEquationSolver<ValueType, SolutionType>> solver = factory.create(env, std::forward<MatrixType>(matrix));
111 solver->setOptimizationDirection(goal.direction());
112 if (goal.isBounded()) {
113 if (goal.boundIsALowerBound()) {
114 solver->setTerminationCondition(std::make_unique<TerminateIfFilteredExtremumExceedsThreshold<SolutionType>>(
115 goal.relevantValues(), goal.boundIsStrict(), goal.thresholdValue(), true));
116 } else {
117 solver->setTerminationCondition(std::make_unique<TerminateIfFilteredExtremumBelowThreshold<SolutionType>>(
118 goal.relevantValues(), goal.boundIsStrict(), goal.thresholdValue(), false));
119 }
120 }
121 if (goal.hasRelevantValues()) {
122 solver->setRelevantValues(std::move(goal.relevantValues()));
123 }
124 return solver;
125}
126
127template<typename ValueType, typename MatrixType, typename SolutionType>
128std::unique_ptr<storm::solver::LinearEquationSolver<ValueType>> configureLinearEquationSolver(
130 MatrixType&& matrix) {
131 std::unique_ptr<storm::solver::LinearEquationSolver<ValueType>> solver = factory.create(env, std::forward<MatrixType>(matrix));
132 if (goal.isBounded()) {
133 solver->setTerminationCondition(std::make_unique<TerminateIfFilteredExtremumExceedsThreshold<ValueType>>(goal.relevantValues(), goal.boundIsStrict(),
134 goal.thresholdValue(), goal.minimize()));
135 }
136 return solver;
137}
138
139template<typename MatrixType>
140std::unique_ptr<storm::solver::LinearEquationSolver<storm::RationalFunction>> configureLinearEquationSolver(
142 MatrixType&& matrix) {
143 std::unique_ptr<storm::solver::LinearEquationSolver<storm::RationalFunction>> solver = factory.create(env, std::forward<MatrixType>(matrix));
144 return solver;
145}
146
147} // namespace solver
148} // namespace storm
bool isBoundSet() const
Retrieves whether there is a bound with which the values for the states will be compared.
Definition CheckTask.h:219
ValueType getBoundThreshold() const
Retrieves the value of the bound (if set).
Definition CheckTask.h:226
storm::logic::ComparisonType const & getBoundComparisonType() const
Retrieves the comparison type of the bound (if set).
Definition CheckTask.h:235
bool isOptimizationDirectionSet() const
Retrieves whether an optimization direction was set.
Definition CheckTask.h:147
storm::OptimizationDirection const & getOptimizationDirection() const
Retrieves the optimization direction (if set).
Definition CheckTask.h:154
bool isOnlyInitialStatesRelevantSet() const
Retrieves whether only the initial states are relevant in the computation.
Definition CheckTask.h:204
Base class for all sparse models.
Definition Model.h:33
storm::storage::BitVector const & getInitialStates() const
Retrieves the initial states of the model.
Definition Model.cpp:177
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
bool boundIsALowerBound() const
void oneMinus()
Flips the comparison type, the direction, and computes the new threshold as 1 - old threshold.
Definition SolveGoal.cpp:57
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:47
void restrictRelevantValues(storm::storage::BitVector const &filter)
storm::storage::BitVector & relevantValues()
void setRelevantValues(storm::storage::BitVector &&values)
bool hasDirection() const
Definition SolveGoal.cpp:52
OptimizationDirection direction() const
Definition SolveGoal.cpp:92
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
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:128
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)
Definition SolveGoal.h:107
LabParser.cpp.
Definition cli.cpp:18