Storm 2.0.0.3
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->produceCertificate = 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,
57 this->produceCertificate, this->hint, 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,
136 this->produceCertificate, this->hint, 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 setProduceCertificate(bool produceCertificate = true) {
289 this->produceCertificate = produceCertificate;
290 }
291
296 return produceCertificate;
297 }
298
302 void setHint(std::shared_ptr<ModelCheckerHint> const& hint) {
303 this->hint = hint;
304 }
305
309 ModelCheckerHint const& getHint() const {
310 return *hint;
311 }
312
314 return *hint;
315 }
316
321 return uncertaintyResolutionMode;
322 }
323
328 this->uncertaintyResolutionMode = uncertaintyResolutionMode;
329 }
330
335 return isSet(this->uncertaintyResolutionMode);
336 }
337
342 return this->template substituteFormula<storm::logic::Formula>(this->getFormula());
343 }
344
345 private:
362 CheckTask(std::reference_wrapper<FormulaType const> const& formula, boost::optional<storm::OptimizationDirection> const& optimizationDirection,
363 boost::optional<storm::logic::PlayerCoalition> playerCoalition, boost::optional<std::string> const& rewardModel, bool onlyInitialStatesRelevant,
364 boost::optional<storm::logic::Bound> const& bound, bool qualitative, bool produceSchedulers, bool produceCertificate,
365 std::shared_ptr<ModelCheckerHint> const& hint, UncertaintyResolutionMode uncertaintyResolutionMode)
366 : formula(formula),
367 optimizationDirection(optimizationDirection),
368 playerCoalition(playerCoalition),
369 rewardModel(rewardModel),
370 onlyInitialStatesRelevant(onlyInitialStatesRelevant),
371 bound(bound),
372 qualitative(qualitative),
373 produceSchedulers(produceSchedulers),
374 produceCertificate(produceCertificate),
375 hint(hint),
376 uncertaintyResolutionMode(uncertaintyResolutionMode) {
377 // Intentionally left empty.
378 }
379
380 // The formula that is to be checked.
381 std::reference_wrapper<FormulaType const> formula;
382
383 // If set, the probabilities will be minimized/maximized.
384 boost::optional<storm::OptimizationDirection> optimizationDirection;
385
386 // If set, the given coalitions of players will be assumed.
387 boost::optional<storm::logic::PlayerCoalition> playerCoalition;
388
389 // If set, the reward property has to be interpreted over this model.
390 boost::optional<std::string> rewardModel;
391
392 // If set to true, the model checker may decide to only compute the values for the initial states.
393 bool onlyInitialStatesRelevant;
394
395 // The bound with which the states will be compared.
396 boost::optional<storm::logic::Bound> bound;
397
398 // A flag specifying whether the property needs to be checked qualitatively, i.e. compared with bounds 0/1.
399 bool qualitative;
400
401 // If supported by the model checker and the model formalism, schedulers to achieve a value will be produced
402 // if this flag is set.
403 bool produceSchedulers;
404
405 // If supported by the model checker and the model formalisms, a certificate is produced if this flag is set.
406 bool produceCertificate;
407
408 // A hint that might contain information that speeds up the modelchecking process (if supported by the model checker)
409 std::shared_ptr<ModelCheckerHint> hint;
410
411 // Whether uncertainty should be resolved be minimizing, maximizing, acting robust or cooperative.
412 UncertaintyResolutionMode uncertaintyResolutionMode;
413};
414
415} // namespace modelchecker
416} // namespace storm
RewardOperatorFormula & asRewardOperatorFormula()
Definition Formula.cpp:514
ProbabilityOperatorFormula & asProbabilityOperatorFormula()
Definition Formula.cpp:506
OperatorFormula & asOperatorFormula()
Definition Formula.cpp:522
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
void setProduceCertificate(bool produceCertificate=true)
Sets whether to produce certificates (if supported).
Definition CheckTask.h:288
ValueType getBoundThreshold() const
Retrieves the value of the bound (if set).
Definition CheckTask.h:228
ModelCheckerHint & getHint()
Definition CheckTask.h:313
bool isProduceCertificateSet() const
Retrieves whether certificate(s) are to be produced (if supported).
Definition CheckTask.h:295
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:327
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:309
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:334
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: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:302
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:320
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:39
ComparisonType invertPreserveStrictness(ComparisonType t)
bool isOne(ValueType const &a)
Definition constants.cpp:39
bool isZero(ValueType const &a)
Definition constants.cpp:44
The contract of a DD backend.
solver::UncertaintyResolutionMode UncertaintyResolutionMode
solver::OptimizationDirection OptimizationDirection