Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
BuilderOptions.cpp
Go to the documentation of this file.
2
4
7
10
11namespace storm {
12namespace builder {
13
14LabelOrExpression::LabelOrExpression(storm::expressions::Expression const& expression) : labelOrExpression(expression) {
15 // Intentionally left empty.
16}
17
18LabelOrExpression::LabelOrExpression(std::string const& label) : labelOrExpression(label) {
19 // Intentionally left empty.
20}
21
23 return labelOrExpression.which() == 0;
24}
25
26std::string const& LabelOrExpression::getLabel() const {
27 return boost::get<std::string>(labelOrExpression);
28}
29
31 return labelOrExpression.which() == 1;
32}
33
35 return boost::get<storm::expressions::Expression>(labelOrExpression);
36}
37
38BuilderOptions::BuilderOptions(bool buildAllRewardModels, bool buildAllLabels)
39 : buildAllRewardModels(buildAllRewardModels),
40 buildAllLabels(buildAllLabels),
41 applyMaximalProgressAssumption(false),
42 buildChoiceLabels(false),
43 buildStateValuations(false),
44 buildObservationValuations(false),
45 buildChoiceOrigins(false),
46 scaleAndLiftTransitionRewards(true),
47 explorationChecks(false),
48 inferObservationsFromActions(false),
49 addOverlappingGuardsLabel(false),
50 addOutOfBoundsState(false),
51 reservedBitsForUnboundedVariables(32),
52 showProgress(false),
53 showProgressDelay(0),
54 stochasticTolerance(0.0) {
55 // Intentionally left empty.
56}
57
59 : BuilderOptions({formula.asSharedPointer()}, modelDescription) {
60 // Intentionally left empty.
61}
62
63BuilderOptions::BuilderOptions(std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas,
64 storm::storage::SymbolicModelDescription const& modelDescription)
65 : BuilderOptions() {
66 if (!formulas.empty()) {
67 for (auto const& formula : formulas) {
68 this->preserveFormula(*formula, modelDescription);
69 }
70 if (formulas.size() == 1) {
71 this->setTerminalStatesFromFormula(*formulas.front());
72 }
73 }
74
75 if (modelDescription.hasModel()) {
76 this->setApplyMaximalProgressAssumption(modelDescription.getModelType() == storm::storage::SymbolicModelDescription::ModelType::MA);
77 this->setBuildChoiceOrigins(modelDescription.getModelType() == storm::storage::SymbolicModelDescription::ModelType::POMDP);
78 this->setBuildChoiceLabels(modelDescription.getModelType() == storm::storage::SymbolicModelDescription::ModelType::POMDP);
79 }
80}
81
83 // If we already had terminal states, we need to erase them.
84 if (hasTerminalStates()) {
86 }
87
88 // Determine the reward models we need to build.
89 std::set<std::string> referencedRewardModels = formula.getReferencedRewardModels();
90 for (auto const& rewardModelName : referencedRewardModels) {
91 rewardModelNames.emplace(rewardModelName);
92 }
93
94 // Extract all the labels used in the formula.
95 std::vector<std::shared_ptr<storm::logic::AtomicLabelFormula const>> atomicLabelFormulas = formula.getAtomicLabelFormulas();
96 for (auto const& formula : atomicLabelFormulas) {
97 addLabel(formula->getLabel());
98 }
99
100 // Extract all the expressions used in the formula.
101 std::vector<std::shared_ptr<storm::logic::AtomicExpressionFormula const>> atomicExpressionFormulas = formula.getAtomicExpressionFormulas();
102 for (auto const& formula : atomicExpressionFormulas) {
103 addLabel(formula->getExpression());
104 }
105
106 scaleAndLiftTransitionRewards =
107 scaleAndLiftTransitionRewards && storm::logic::LiftableTransitionRewardsVisitor(modelDescription).areTransitionRewardsLiftable(formula);
108}
109
112 formula, [this](storm::expressions::Expression const& expr, bool inverted) { this->addTerminalExpression(expr, inverted); },
113 [this](std::string const& label, bool inverted) { this->addTerminalLabel(label, inverted); });
114}
115
116std::set<std::string> const& BuilderOptions::getRewardModelNames() const {
117 return rewardModelNames;
118}
119
120std::set<std::string> const& BuilderOptions::getLabelNames() const {
121 return labelNames;
122}
123
124std::vector<std::pair<std::string, storm::expressions::Expression>> const& BuilderOptions::getExpressionLabels() const {
125 return expressionLabels;
126}
127
128std::vector<std::pair<LabelOrExpression, bool>> const& BuilderOptions::getTerminalStates() const {
129 return terminalStates;
130}
131
133 return !terminalStates.empty();
134}
135
137 terminalStates.clear();
138}
139
141 return applyMaximalProgressAssumption;
142}
143
145 return buildChoiceLabels;
146}
147
149 return buildStateValuations;
150}
151
153 return buildObservationValuations;
154}
155
157 return buildChoiceOrigins;
158}
159
161 return buildAllRewardModels;
162}
163
165 return buildAllLabels;
166}
167
169 return inferObservationsFromActions;
170}
171
173 return scaleAndLiftTransitionRewards;
174}
175
177 return addOutOfBoundsState;
178}
179
181 return reservedBitsForUnboundedVariables;
182}
183
185 return addOverlappingGuardsLabel;
186}
187
189 buildAllRewardModels = newValue;
190 return *this;
191}
192
194 return explorationChecks;
195}
196
198 return showProgress;
199}
200
202 return showProgressDelay;
203}
204
206 return stochasticTolerance;
207}
208
210 explorationChecks = newValue;
211 return *this;
212}
213
214BuilderOptions& BuilderOptions::addRewardModel(std::string const& rewardModelName) {
215 STORM_LOG_THROW(!buildAllRewardModels, storm::exceptions::InvalidSettingsException, "Cannot add reward model, because all reward models are built anyway.");
216 rewardModelNames.emplace(rewardModelName);
217 return *this;
218}
219
221 buildAllLabels = newValue;
222 return *this;
223}
224
226 std::stringstream stream;
227 stream << expression;
228 expressionLabels.emplace_back(stream.str(), expression);
229 return *this;
230}
231
232BuilderOptions& BuilderOptions::addLabel(std::string const& labelName) {
233 STORM_LOG_THROW(!buildAllLabels, storm::exceptions::InvalidSettingsException, "Cannot add label, because all labels are built anyway.");
234 labelNames.insert(labelName);
235 return *this;
236}
237
239 terminalStates.push_back(std::make_pair(LabelOrExpression(expression), value));
240 return *this;
241}
242
243BuilderOptions& BuilderOptions::addTerminalLabel(std::string const& label, bool value) {
244 terminalStates.push_back(std::make_pair(LabelOrExpression(label), value));
245 return *this;
246}
247
249 applyMaximalProgressAssumption = newValue;
250 return *this;
251}
252
254 buildChoiceLabels = newValue;
255 return *this;
256}
257
259 buildStateValuations = newValue;
260 return *this;
261}
262
264 buildObservationValuations = newValue;
265 return *this;
266}
267
269 buildChoiceOrigins = newValue;
270 return *this;
271}
272
274 scaleAndLiftTransitionRewards = newValue;
275 return *this;
276}
277
279 addOutOfBoundsState = newValue;
280 return *this;
281}
282
284 reservedBitsForUnboundedVariables = newValue;
285 return *this;
286}
287
289 addOverlappingGuardsLabel = newValue;
290 return *this;
291}
292
294 stochasticTolerance = newValue;
295 return *this;
296}
297
299 showProgress = newValue;
300 return *this;
301}
302
304 showProgressDelay = newValue;
305 return *this;
306}
307
309 std::function<storm::expressions::Expression(storm::expressions::Expression const&)> const& substitutionFunction) {
310 for (auto& e : expressionLabels) {
311 e.second = substitutionFunction(e.second);
312 }
313
314 for (auto& t : terminalStates) {
315 if (t.first.isExpression()) {
316 t.first = LabelOrExpression(substitutionFunction(t.first.getExpression()));
317 }
318 }
319 return *this;
320}
321
322} // namespace builder
323} // namespace storm
uint64_t getReservedBitsForUnboundedVariables() const
std::set< std::string > const & getRewardModelNames() const
Which reward models are built.
BuilderOptions & setBuildAllLabels(bool newValue=true)
Should all reward models be built?
BuilderOptions & setExplorationChecks(bool newValue=true)
Should extra checks be performed during exploration.
BuilderOptions & addTerminalExpression(storm::expressions::Expression const &expression, bool value)
BuilderOptions & setAddOutOfBoundsState(bool newValue=true)
Should a state for out of bounds be constructed.
BuilderOptions & setReservedBitsForUnboundedVariables(uint64_t value)
Sets the number of bits that will be reserved for unbounded integer variables.
BuilderOptions & setBuildChoiceLabels(bool newValue=true)
Should the choice labels be built?
BuilderOptions & addRewardModel(std::string const &rewardModelName)
Add an additional reward model to build.
BuilderOptions & setBuildAllRewardModels(bool newValue=true)
Should all reward models be built?
BuilderOptions & setBuildChoiceOrigins(bool newValue=true)
Should the origins the different choices be built?
double getStochasticTolerance() const
Some distributions may not sum to one.
BuilderOptions & setShowProgressDelay(uint64_t newValue)
Sets the delay (in seconds) between progress reports during state space exploration.
BuilderOptions & setBuildStateValuations(bool newValue=true)
Should the state valuation mapping be built?
BuilderOptions(bool buildAllRewardModels=false, bool buildAllLabels=false)
Creates an object representing the default options.
std::vector< std::pair< std::string, storm::expressions::Expression > > const & getExpressionLabels() const
Which expression labels are built.
BuilderOptions & substituteExpressions(std::function< storm::expressions::Expression(storm::expressions::Expression const &)> const &substitutionFunction)
Substitutes all expressions occurring in these options.
std::vector< std::pair< LabelOrExpression, bool > > const & getTerminalStates() const
BuilderOptions & setApplyMaximalProgressAssumption(bool newValue=true)
Should the maximal progress assumption be applied when building a Markov Automaton?
BuilderOptions & setStochasticTolerance(double newValue)
Sets the tolerance used for checking whether a distribution sums to one.
void preserveFormula(storm::logic::Formula const &formula, storm::storage::SymbolicModelDescription const &modelDescription=storm::storage::SymbolicModelDescription())
Changes the options in a way that ensures that the given formula can be checked on the model once it ...
BuilderOptions & addLabel(storm::expressions::Expression const &expression)
BuilderOptions & setBuildObservationValuations(bool newValue=true)
Should a observation valuation mapping be built?
void setTerminalStatesFromFormula(storm::logic::Formula const &formula)
Analyzes the given formula and sets an expression for the states states of the model that can be trea...
BuilderOptions & setAddOverlappingGuardsLabel(bool newValue=true)
Should a state be labelled for overlapping guards.
BuilderOptions & addTerminalLabel(std::string const &label, bool value)
BuilderOptions & setScaleAndLiftTransitionRewards(bool newValue=true)
Should extra checks be performed during exploration.
BuilderOptions & setShowProgress(bool newValue=true)
Sets whether the progress of state space exploration should be printed.
std::set< std::string > const & getLabelNames() const
Which labels are built.
LabelOrExpression(storm::expressions::Expression const &expression)
storm::expressions::Expression const & getExpression() const
std::string const & getLabel() const
std::vector< std::shared_ptr< AtomicExpressionFormula const > > getAtomicExpressionFormulas() const
Definition Formula.cpp:500
std::vector< std::shared_ptr< AtomicLabelFormula const > > getAtomicLabelFormulas() const
Definition Formula.cpp:506
std::set< std::string > getReferencedRewardModels() const
Definition Formula.cpp:518
std::shared_ptr< Formula const > asSharedPointer()
Definition Formula.cpp:571
bool areTransitionRewardsLiftable(Formula const &f) const
Returns true, when lifting transition rewards to action rewards (by scaling with the transition proba...
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
void getTerminalStatesFromFormula(storm::logic::Formula const &formula, std::function< void(storm::expressions::Expression const &, bool)> const &terminalExpressionCallback, std::function< void(std::string const &, bool)> const &terminalLabelCallback)
Traverses the formula.