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