Storm
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
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) : formula(formula), hint(new ModelCheckerHint()) {
39 this->onlyInitialStatesRelevant = onlyInitialStatesRelevant;
40 this->produceSchedulers = false;
41 this->qualitative = false;
42 this->robustUncertainty = true;
43
45 }
46
51 template<typename NewFormulaType>
52 CheckTask<NewFormulaType, ValueType> substituteFormula(NewFormulaType const& newFormula) const {
53 CheckTask<NewFormulaType, ValueType> result(newFormula, this->optimizationDirection, this->playerCoalition, this->rewardModel,
54 this->onlyInitialStatesRelevant, this->bound, this->qualitative, this->produceSchedulers, this->hint,
55 this->robustUncertainty);
57 return result;
58 }
59
65 if (formula.get().isOperatorFormula()) {
66 storm::logic::OperatorFormula const& operatorFormula = formula.get().asOperatorFormula();
67 if (operatorFormula.hasOptimalityType()) {
68 this->optimizationDirection = operatorFormula.getOptimalityType();
69 }
70
71 if (operatorFormula.hasBound()) {
72 this->bound = operatorFormula.getBound();
73 }
74
75 if (operatorFormula.hasOptimalityType()) {
76 this->optimizationDirection = operatorFormula.getOptimalityType();
77 } else if (operatorFormula.hasBound()) {
78 this->optimizationDirection = operatorFormula.getComparisonType() == storm::logic::ComparisonType::Less ||
80 ? OptimizationDirection::Maximize
81 : OptimizationDirection::Minimize;
82 }
83
84 if (formula.get().isProbabilityOperatorFormula()) {
85 storm::logic::ProbabilityOperatorFormula const& probabilityOperatorFormula = formula.get().asProbabilityOperatorFormula();
86
87 if (probabilityOperatorFormula.hasBound()) {
88 if (storm::utility::isZero(probabilityOperatorFormula.template getThresholdAs<ValueType>()) ||
89 storm::utility::isOne(probabilityOperatorFormula.template getThresholdAs<ValueType>())) {
90 this->qualitative = true;
91 }
92 }
93 } else if (formula.get().isRewardOperatorFormula()) {
94 storm::logic::RewardOperatorFormula const& rewardOperatorFormula = formula.get().asRewardOperatorFormula();
95 this->rewardModel = rewardOperatorFormula.getOptionalRewardModelName();
96
97 if (rewardOperatorFormula.hasBound()) {
98 if (storm::utility::isZero(rewardOperatorFormula.template getThresholdAs<ValueType>())) {
99 this->qualitative = true;
100 }
101 }
102 }
103 }
104 }
105
111 CheckTask result(*this);
113 // switch from min to max and vice-versa
115 }
116
117 if (isBoundSet()) {
118 // invert bound comparison type (retain strictness),
119 // convert threshold to 1- threshold
120 result.bound = storm::logic::Bound(storm::logic::invertPreserveStrictness(getBound().comparisonType), 1 - getBound().threshold);
121 }
122
123 return result;
124 }
125
130 template<typename NewValueType>
132 return CheckTask<FormulaType, NewValueType>(this->formula, this->optimizationDirection, this->playerCoalition, this->rewardModel,
133 this->onlyInitialStatesRelevant, this->bound, this->qualitative, this->produceSchedulers, this->hint,
134 this->robustUncertainty);
135 }
136
140 FormulaType const& getFormula() const {
141 return formula.get();
142 }
143
148 return static_cast<bool>(optimizationDirection);
149 }
150
155 return optimizationDirection.get();
156 }
157
162 optimizationDirection = dir;
163 }
164
168 bool isPlayerCoalitionSet() const {
169 return static_cast<bool>(playerCoalition);
170 }
171
176 return playerCoalition.get();
177 }
178
183 playerCoalition = coalition;
184 return *this;
185 }
186
190 bool isRewardModelSet() const {
191 return static_cast<bool>(rewardModel);
192 }
193
197 std::string const& getRewardModel() const {
198 return rewardModel.get();
199 }
200
205 return onlyInitialStatesRelevant;
206 }
207
212 this->onlyInitialStatesRelevant = value;
213 return *this;
214 }
215
219 bool isBoundSet() const {
220 return static_cast<bool>(bound);
221 }
222
226 ValueType getBoundThreshold() const {
227 STORM_LOG_THROW(!bound.get().threshold.containsVariables(), storm::exceptions::InvalidOperationException,
228 "Cannot evaluate threshold '" << bound.get().threshold << "' as it contains undefined constants.");
229 return bound.get().template evaluateThresholdAs<ValueType>();
230 }
231
236 return bound.get().comparisonType;
237 }
238
243 return bound.get();
244 }
245
249 boost::optional<storm::logic::Bound> const& getOptionalBound() const {
250 return bound;
251 }
252
257 bool isQualitativeSet() const {
258 return qualitative;
259 }
260
265 void setQualitative(bool value) {
266 qualitative = value;
267 }
268
272 void setProduceSchedulers(bool produceSchedulers = true) {
273 this->produceSchedulers = produceSchedulers;
274 }
275
280 return produceSchedulers;
281 }
282
286 void setHint(std::shared_ptr<ModelCheckerHint> const& hint) {
287 this->hint = hint;
288 }
289
293 ModelCheckerHint const& getHint() const {
294 return *hint;
295 }
296
298 return *hint;
299 }
300
305 return this->substituteFormula<storm::logic::Formula>(this->getFormula());
306 }
307
308 bool getRobustUncertainty() const {
309 return robustUncertainty;
310 }
311
312 void setRobustUncertainty(bool robust = true) {
313 robustUncertainty = robust;
314 }
315
316 private:
332 CheckTask(std::reference_wrapper<FormulaType const> const& formula, boost::optional<storm::OptimizationDirection> const& optimizationDirection,
333 boost::optional<storm::logic::PlayerCoalition> playerCoalition, boost::optional<std::string> const& rewardModel, bool onlyInitialStatesRelevant,
334 boost::optional<storm::logic::Bound> const& bound, bool qualitative, bool produceSchedulers, std::shared_ptr<ModelCheckerHint> const& hint,
335 bool robust)
336 : formula(formula),
337 optimizationDirection(optimizationDirection),
338 playerCoalition(playerCoalition),
339 rewardModel(rewardModel),
340 onlyInitialStatesRelevant(onlyInitialStatesRelevant),
341 bound(bound),
342 qualitative(qualitative),
343 produceSchedulers(produceSchedulers),
344 hint(hint),
345 robustUncertainty(robust) {
346 // Intentionally left empty.
347 }
348
349 // The formula that is to be checked.
350 std::reference_wrapper<FormulaType const> formula;
351
352 // If set, the probabilities will be minimized/maximized.
353 boost::optional<storm::OptimizationDirection> optimizationDirection;
354
355 // If set, the given coalitions of players will be assumed.
356 boost::optional<storm::logic::PlayerCoalition> playerCoalition;
357
358 // If set, the reward property has to be interpreted over this model.
359 boost::optional<std::string> rewardModel;
360
361 // If set to true, the model checker may decide to only compute the values for the initial states.
362 bool onlyInitialStatesRelevant;
363
364 // The bound with which the states will be compared.
365 boost::optional<storm::logic::Bound> bound;
366
367 // A flag specifying whether the property needs to be checked qualitatively, i.e. compared with bounds 0/1.
368 bool qualitative;
369
370 // If supported by the model checker and the model formalism, schedulers to achieve a value will be produced
371 // if this flag is set.
372 bool produceSchedulers;
373
374 // A hint that might contain information that speeds up the modelchecking process (if supported by the model checker)
375 std::shared_ptr<ModelCheckerHint> hint;
376
378 bool robustUncertainty;
379};
380
381} // namespace modelchecker
382} // namespace storm
383
384#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:219
CheckTask< FormulaType, ValueType > & setOnlyInitialStatesRelevant(bool value=true)
Sets whether only initial states are relevant.
Definition CheckTask.h:211
void setOptimizationDirection(storm::OptimizationDirection const &dir)
Sets the optimization direction.
Definition CheckTask.h:161
ValueType getBoundThreshold() const
Retrieves the value of the bound (if set).
Definition CheckTask.h:226
ModelCheckerHint & getHint()
Definition CheckTask.h:297
storm::logic::ComparisonType const & getBoundComparisonType() const
Retrieves the comparison type of the bound (if set).
Definition CheckTask.h:235
void setRobustUncertainty(bool robust=true)
Definition CheckTask.h:312
bool isOptimizationDirectionSet() const
Retrieves whether an optimization direction was set.
Definition CheckTask.h:147
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:52
CheckTask< FormulaType, ValueType > & setPlayerCoalition(storm::logic::PlayerCoalition const &coalition)
Sets the player coalition.
Definition CheckTask.h:182
bool isRewardModelSet() const
Retrieves whether a reward model was set.
Definition CheckTask.h:190
boost::optional< storm::logic::Bound > const & getOptionalBound() const
Retrieves the bound.
Definition CheckTask.h:249
bool isQualitativeSet() const
Retrieves whether the computation only needs to be performed qualitatively, because the values will o...
Definition CheckTask.h:257
std::string const & getRewardModel() const
Retrieves the reward model over which to perform the checking (if set).
Definition CheckTask.h:197
FormulaType const & getFormula() const
Retrieves the formula from this task.
Definition CheckTask.h:140
ModelCheckerHint const & getHint() const
Retrieves a hint that might contain information that speeds up the modelchecking process (if supporte...
Definition CheckTask.h:293
CheckTask negate() const
Negate the optimization direction and the bound threshold, if those exist.
Definition CheckTask.h:110
CheckTask< FormulaType, NewValueType > convertValueType() const
Copies the check task from the source while replacing the considered ValueType the new one.
Definition CheckTask.h:131
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:286
bool isProduceSchedulersSet() const
Retrieves whether scheduler(s) are to be produced (if supported).
Definition CheckTask.h:279
void setProduceSchedulers(bool produceSchedulers=true)
Sets whether to produce schedulers (if supported).
Definition CheckTask.h:272
storm::logic::PlayerCoalition const & getPlayerCoalition() const
Retrieves the player coalition (if set).
Definition CheckTask.h:175
CheckTask(FormulaType const &formula, bool onlyInitialStatesRelevant=false)
Creates a task object with the default options for the given formula.
Definition CheckTask.h:38
storm::logic::Bound const & getBound() const
Retrieves the bound (if set).
Definition CheckTask.h:242
storm::OptimizationDirection const & getOptimizationDirection() const
Retrieves the optimization direction (if set).
Definition CheckTask.h:154
bool isPlayerCoalitionSet() const
Retrieves whether a player coalition was set.
Definition CheckTask.h:168
bool isOnlyInitialStatesRelevantSet() const
Retrieves whether only the initial states are relevant in the computation.
Definition CheckTask.h:204
void updateOperatorInformation()
If the currently specified formula is an OperatorFormula, this method updates the information that is...
Definition CheckTask.h:64
void setQualitative(bool value)
sets whether the computation only needs to be performed qualitatively, because the values will only b...
Definition CheckTask.h:265
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:36
bool isZero(ValueType const &a)
Definition constants.cpp:41
LabParser.cpp.
Definition cli.cpp:18