Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
CheckTask.h
Go to the documentation of this file.
1#pragma once
2
3#include <boost/optional.hpp>
4#include <memory>
5
8
14
16
17namespace storm {
18namespace logic {
19class Formula;
20}
21
22namespace modelchecker {
23
25
26/*
27 * This class is used to customize the checking process of a formula.
28 */
29template<typename FormulaType = storm::logic::Formula, typename ValueType = double>
30class CheckTask {
31 public:
32 template<typename OtherFormulaType, typename OtherValueType>
33 friend class CheckTask;
34
38 CheckTask(FormulaType const& formula, bool onlyInitialStatesRelevant = false, UncertaintyResolutionMode = UncertaintyResolutionMode::Unset)
39 : formula(formula), hint(new ModelCheckerHint()) {
40 this->onlyInitialStatesRelevant = onlyInitialStatesRelevant;
41 this->produceSchedulers = false;
42 this->qualitative = false;
43 this->uncertaintyResolutionMode = UncertaintyResolutionMode::Unset;
44
46 }
47
52 template<typename NewFormulaType>
53 CheckTask<NewFormulaType, ValueType> substituteFormula(NewFormulaType const& newFormula) const {
54 CheckTask<NewFormulaType, ValueType> result(newFormula, this->optimizationDirection, this->playerCoalition, this->rewardModel,
55 this->onlyInitialStatesRelevant, this->bound, this->qualitative, this->produceSchedulers, this->hint,
56 this->uncertaintyResolutionMode);
58 return result;
59 }
60
66 if (formula.get().isOperatorFormula()) {
67 storm::logic::OperatorFormula const& operatorFormula = formula.get().asOperatorFormula();
68 if (operatorFormula.hasOptimalityType()) {
69 this->optimizationDirection = operatorFormula.getOptimalityType();
70 }
71
72 if (operatorFormula.hasBound()) {
73 this->bound = operatorFormula.getBound();
74 }
75
76 if (operatorFormula.hasOptimalityType()) {
77 this->optimizationDirection = operatorFormula.getOptimalityType();
78 } else if (operatorFormula.hasBound()) {
79 this->optimizationDirection = operatorFormula.getComparisonType() == storm::logic::ComparisonType::Less ||
81 ? OptimizationDirection::Maximize
82 : OptimizationDirection::Minimize;
83 }
84
85 if (formula.get().isProbabilityOperatorFormula()) {
86 storm::logic::ProbabilityOperatorFormula const& probabilityOperatorFormula = formula.get().asProbabilityOperatorFormula();
87
88 if (probabilityOperatorFormula.hasBound()) {
89 if (storm::utility::isZero(probabilityOperatorFormula.template getThresholdAs<ValueType>()) ||
90 storm::utility::isOne(probabilityOperatorFormula.template getThresholdAs<ValueType>())) {
91 this->qualitative = true;
92 }
93 }
94 } else if (formula.get().isRewardOperatorFormula()) {
95 storm::logic::RewardOperatorFormula const& rewardOperatorFormula = formula.get().asRewardOperatorFormula();
96 this->rewardModel = rewardOperatorFormula.getOptionalRewardModelName();
97
98 if (rewardOperatorFormula.hasBound()) {
99 if (storm::utility::isZero(rewardOperatorFormula.template getThresholdAs<ValueType>())) {
100 this->qualitative = true;
101 }
102 }
103 }
104 }
105 }
106
112 CheckTask result(*this);
114 // switch from min to max and vice-versa
116 }
117
118 if (isBoundSet()) {
119 // invert bound comparison type (retain strictness),
120 // convert threshold to 1- threshold
121 result.bound = storm::logic::Bound(storm::logic::invertPreserveStrictness(getBound().comparisonType), 1 - getBound().threshold);
122 }
123
124 return result;
125 }
126
131 template<typename NewValueType>
133 return CheckTask<FormulaType, NewValueType>(this->formula, this->optimizationDirection, this->playerCoalition, this->rewardModel,
134 this->onlyInitialStatesRelevant, this->bound, this->qualitative, this->produceSchedulers, this->hint,
135 this->uncertaintyResolutionMode);
136 }
137
141 FormulaType const& getFormula() const {
142 return formula.get();
143 }
144
149 return static_cast<bool>(optimizationDirection);
150 }
151
156 return optimizationDirection.get();
157 }
158
163 optimizationDirection = dir;
164 }
165
169 bool isPlayerCoalitionSet() const {
170 return static_cast<bool>(playerCoalition);
171 }
172
177 return playerCoalition.get();
178 }
179
184 playerCoalition = coalition;
185 return *this;
186 }
187
191 bool isRewardModelSet() const {
192 return static_cast<bool>(rewardModel);
193 }
194
198 std::string const& getRewardModel() const {
199 return rewardModel.get();
200 }
201
206 return onlyInitialStatesRelevant;
207 }
208
213 this->onlyInitialStatesRelevant = value;
214 return *this;
215 }
216
220 bool isBoundSet() const {
221 return static_cast<bool>(bound);
222 }
223
227 ValueType getBoundThreshold() const {
228 STORM_LOG_THROW(!bound.get().threshold.containsVariables(), storm::exceptions::InvalidOperationException,
229 "Cannot evaluate threshold '" << bound.get().threshold << "' as it contains undefined constants.");
230 return bound.get().template evaluateThresholdAs<ValueType>();
231 }
232
237 return bound.get().comparisonType;
238 }
239
244 return bound.get();
245 }
246
250 boost::optional<storm::logic::Bound> const& getOptionalBound() const {
251 return bound;
252 }
253
258 bool isQualitativeSet() const {
259 return qualitative;
260 }
261
266 void setQualitative(bool value) {
267 qualitative = value;
268 }
269
273 void setProduceSchedulers(bool produceSchedulers = true) {
274 this->produceSchedulers = produceSchedulers;
275 }
276
281 return produceSchedulers;
282 }
283
287 void setHint(std::shared_ptr<ModelCheckerHint> const& hint) {
288 this->hint = hint;
289 }
290
294 ModelCheckerHint const& getHint() const {
295 return *hint;
296 }
297
299 return *hint;
300 }
301
306 return uncertaintyResolutionMode;
307 }
308
313 this->uncertaintyResolutionMode = uncertaintyResolutionMode;
314 }
315
320 return isSet(this->uncertaintyResolutionMode);
321 }
322
327 return this->template substituteFormula<storm::logic::Formula>(this->getFormula());
328 }
329
330 private:
346 CheckTask(std::reference_wrapper<FormulaType const> const& formula, boost::optional<storm::OptimizationDirection> const& optimizationDirection,
347 boost::optional<storm::logic::PlayerCoalition> playerCoalition, boost::optional<std::string> const& rewardModel, bool onlyInitialStatesRelevant,
348 boost::optional<storm::logic::Bound> const& bound, bool qualitative, bool produceSchedulers, std::shared_ptr<ModelCheckerHint> const& hint,
349 UncertaintyResolutionMode uncertaintyResolutionMode)
350 : formula(formula),
351 optimizationDirection(optimizationDirection),
352 playerCoalition(playerCoalition),
353 rewardModel(rewardModel),
354 onlyInitialStatesRelevant(onlyInitialStatesRelevant),
355 bound(bound),
356 qualitative(qualitative),
357 produceSchedulers(produceSchedulers),
358 hint(hint),
359 uncertaintyResolutionMode(uncertaintyResolutionMode) {
360 // Intentionally left empty.
361 }
362
363 // The formula that is to be checked.
364 std::reference_wrapper<FormulaType const> formula;
365
366 // If set, the probabilities will be minimized/maximized.
367 boost::optional<storm::OptimizationDirection> optimizationDirection;
368
369 // If set, the given coalitions of players will be assumed.
370 boost::optional<storm::logic::PlayerCoalition> playerCoalition;
371
372 // If set, the reward property has to be interpreted over this model.
373 boost::optional<std::string> rewardModel;
374
375 // If set to true, the model checker may decide to only compute the values for the initial states.
376 bool onlyInitialStatesRelevant;
377
378 // The bound with which the states will be compared.
379 boost::optional<storm::logic::Bound> bound;
380
381 // A flag specifying whether the property needs to be checked qualitatively, i.e. compared with bounds 0/1.
382 bool qualitative;
383
384 // If supported by the model checker and the model formalism, schedulers to achieve a value will be produced
385 // if this flag is set.
386 bool produceSchedulers;
387
388 // A hint that might contain information that speeds up the modelchecking process (if supported by the model checker)
389 std::shared_ptr<ModelCheckerHint> hint;
390
391 // Whether uncertainty should be resolved be minimizing, maximizing, acting robust or cooperative.
392 UncertaintyResolutionMode uncertaintyResolutionMode;
393};
394
395} // namespace modelchecker
396} // namespace storm
RewardOperatorFormula & asRewardOperatorFormula()
Definition Formula.cpp:484
ProbabilityOperatorFormula & asProbabilityOperatorFormula()
Definition Formula.cpp:476
OperatorFormula & asOperatorFormula()
Definition Formula.cpp:492
Bound const & getBound() const
ComparisonType getComparisonType() const
storm::solver::OptimizationDirection const & getOptimalityType() const
boost::optional< std::string > const & getOptionalRewardModelName() const
Retrieves the optional representing the reward model name this property refers to.
bool isBoundSet() const
Retrieves whether there is a bound with which the values for the states will be compared.
Definition CheckTask.h:220
CheckTask< FormulaType, ValueType > & setOnlyInitialStatesRelevant(bool value=true)
Sets whether only initial states are relevant.
Definition CheckTask.h:212
void setOptimizationDirection(storm::OptimizationDirection const &dir)
Sets the optimization direction.
Definition CheckTask.h:162
ValueType getBoundThreshold() const
Retrieves the value of the bound (if set).
Definition CheckTask.h:227
ModelCheckerHint & getHint()
Definition CheckTask.h:298
storm::logic::ComparisonType const & getBoundComparisonType() const
Retrieves the comparison type of the bound (if set).
Definition CheckTask.h:236
void setUncertaintyResolutionMode(UncertaintyResolutionMode uncertaintyResolutionMode)
Sets the mode which decides how the uncertainty will be resolved.
Definition CheckTask.h:312
bool isOptimizationDirectionSet() const
Retrieves whether an optimization direction was set.
Definition CheckTask.h:148
CheckTask< NewFormulaType, ValueType > substituteFormula(NewFormulaType const &newFormula) const
Copies the check task from the source while replacing the formula with the new one.
Definition CheckTask.h:53
CheckTask< FormulaType, ValueType > & setPlayerCoalition(storm::logic::PlayerCoalition const &coalition)
Sets the player coalition.
Definition CheckTask.h:183
bool isRewardModelSet() const
Retrieves whether a reward model was set.
Definition CheckTask.h:191
boost::optional< storm::logic::Bound > const & getOptionalBound() const
Retrieves the bound.
Definition CheckTask.h:250
bool isQualitativeSet() const
Retrieves whether the computation only needs to be performed qualitatively, because the values will o...
Definition CheckTask.h:258
std::string const & getRewardModel() const
Retrieves the reward model over which to perform the checking (if set).
Definition CheckTask.h:198
FormulaType const & getFormula() const
Retrieves the formula from this task.
Definition CheckTask.h:141
ModelCheckerHint const & getHint() const
Retrieves a hint that might contain information that speeds up the modelchecking process (if supporte...
Definition CheckTask.h:294
CheckTask negate() const
Negate the optimization direction and the bound threshold, if those exist.
Definition CheckTask.h:111
bool isUncertaintyResolutionModeSet() const
Returns whether the mode, which decides how the uncertainty will be resolved, is set.
Definition CheckTask.h:319
CheckTask(FormulaType const &formula, bool onlyInitialStatesRelevant=false, UncertaintyResolutionMode=UncertaintyResolutionMode::Unset)
Creates a task object with the default options for the given formula.
Definition CheckTask.h:38
CheckTask< FormulaType, NewValueType > convertValueType() const
Copies the check task from the source while replacing the considered ValueType the new one.
Definition CheckTask.h:132
void setHint(std::shared_ptr< ModelCheckerHint > const &hint)
sets a hint that might contain information that speeds up the modelchecking process (if supported by ...
Definition CheckTask.h:287
bool isProduceSchedulersSet() const
Retrieves whether scheduler(s) are to be produced (if supported).
Definition CheckTask.h:280
void setProduceSchedulers(bool produceSchedulers=true)
Sets whether to produce schedulers (if supported).
Definition CheckTask.h:273
storm::logic::PlayerCoalition const & getPlayerCoalition() const
Retrieves the player coalition (if set).
Definition CheckTask.h:176
storm::logic::Bound const & getBound() const
Retrieves the bound (if set).
Definition CheckTask.h:243
storm::OptimizationDirection const & getOptimizationDirection() const
Retrieves the optimization direction (if set).
Definition CheckTask.h:155
bool isPlayerCoalitionSet() const
Retrieves whether a player coalition was set.
Definition CheckTask.h:169
bool isOnlyInitialStatesRelevantSet() const
Retrieves whether only the initial states are relevant in the computation.
Definition CheckTask.h:205
UncertaintyResolutionMode getUncertaintyResolutionMode() const
Retrieves the mode which decides how the uncertainty will be resolved.
Definition CheckTask.h:305
void updateOperatorInformation()
If the currently specified formula is an OperatorFormula, this method updates the information that is...
Definition CheckTask.h:65
void setQualitative(bool value)
sets whether the computation only needs to be performed qualitatively, because the values will only b...
Definition CheckTask.h:266
This class contains information that might accelerate the model checking process.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
ComparisonType invertPreserveStrictness(ComparisonType t)
bool isOne(ValueType const &a)
Definition constants.cpp:37
bool isZero(ValueType const &a)
Definition constants.cpp:42
solver::UncertaintyResolutionMode UncertaintyResolutionMode
solver::OptimizationDirection OptimizationDirection