Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
BuilderOptions.cpp
Go to the documentation of this file.
2
4
7
10
14
15namespace storm {
16namespace builder {
17
18LabelOrExpression::LabelOrExpression(storm::expressions::Expression const& expression) : labelOrExpression(expression) {
19 // Intentionally left empty.
20}
21
22LabelOrExpression::LabelOrExpression(std::string const& label) : labelOrExpression(label) {
23 // Intentionally left empty.
24}
25
27 return labelOrExpression.which() == 0;
28}
29
30std::string const& LabelOrExpression::getLabel() const {
31 return boost::get<std::string>(labelOrExpression);
32}
33
35 return labelOrExpression.which() == 1;
36}
37
39 return boost::get<storm::expressions::Expression>(labelOrExpression);
40}
41
42BuilderOptions::BuilderOptions(bool buildAllRewardModels, bool buildAllLabels)
43 : buildAllRewardModels(buildAllRewardModels),
44 buildAllLabels(buildAllLabels),
45 applyMaximalProgressAssumption(false),
46 buildChoiceLabels(false),
47 buildStateValuations(false),
48 buildObservationValuations(false),
49 buildChoiceOrigins(false),
50 scaleAndLiftTransitionRewards(true),
51 explorationChecks(false),
52 inferObservationsFromActions(false),
53 addOverlappingGuardsLabel(false),
54 addOutOfBoundsState(false),
55 reservedBitsForUnboundedVariables(32),
56 showProgress(false),
57 showProgressDelay(0) {
58 // Note that we would like to move this out of here, but SJ doesn't want to change everything at once.
59 auto const& generalSettings = storm::settings::getModule<storm::settings::modules::GeneralSettings>();
60 stochasticTolerance = storm::utility::convertNumber<storm::RationalNumber>(generalSettings.getPrecision());
61}
62
64 : BuilderOptions({formula.asSharedPointer()}, modelDescription) {
65 // Intentionally left empty.
66}
67
68BuilderOptions::BuilderOptions(std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas,
69 storm::storage::SymbolicModelDescription const& modelDescription)
70 : BuilderOptions() {
71 if (!formulas.empty()) {
72 for (auto const& formula : formulas) {
73 this->preserveFormula(*formula, modelDescription);
74 }
75 if (formulas.size() == 1) {
76 this->setTerminalStatesFromFormula(*formulas.front());
77 }
78 }
79
80 auto const& generalSettings = storm::settings::getModule<storm::settings::modules::GeneralSettings>();
81 if (modelDescription.hasModel()) {
85 }
86 showProgress = generalSettings.isVerboseSet();
87 showProgressDelay = generalSettings.getShowProgressDelay();
88}
89
91 // If we already had terminal states, we need to erase them.
92 if (hasTerminalStates()) {
94 }
95
96 // Determine the reward models we need to build.
97 std::set<std::string> referencedRewardModels = formula.getReferencedRewardModels();
98 for (auto const& rewardModelName : referencedRewardModels) {
99 rewardModelNames.emplace(rewardModelName);
100 }
101
102 // Extract all the labels used in the formula.
103 std::vector<std::shared_ptr<storm::logic::AtomicLabelFormula const>> atomicLabelFormulas = formula.getAtomicLabelFormulas();
104 for (auto const& formula : atomicLabelFormulas) {
105 addLabel(formula->getLabel());
106 }
107
108 // Extract all the expressions used in the formula.
109 std::vector<std::shared_ptr<storm::logic::AtomicExpressionFormula const>> atomicExpressionFormulas = formula.getAtomicExpressionFormulas();
110 for (auto const& formula : atomicExpressionFormulas) {
111 addLabel(formula->getExpression());
112 }
113
114 scaleAndLiftTransitionRewards =
115 scaleAndLiftTransitionRewards && storm::logic::LiftableTransitionRewardsVisitor(modelDescription).areTransitionRewardsLiftable(formula);
116}
117
120 formula, [this](storm::expressions::Expression const& expr, bool inverted) { this->addTerminalExpression(expr, inverted); },
121 [this](std::string const& label, bool inverted) { this->addTerminalLabel(label, inverted); });
122}
123
124std::set<std::string> const& BuilderOptions::getRewardModelNames() const {
125 return rewardModelNames;
126}
127
128std::set<std::string> const& BuilderOptions::getLabelNames() const {
129 return labelNames;
130}
131
132std::vector<std::pair<std::string, storm::expressions::Expression>> const& BuilderOptions::getExpressionLabels() const {
133 return expressionLabels;
134}
135
136std::vector<std::pair<LabelOrExpression, bool>> const& BuilderOptions::getTerminalStates() const {
137 return terminalStates;
138}
139
141 return !terminalStates.empty();
142}
143
145 terminalStates.clear();
146}
147
149 return applyMaximalProgressAssumption;
150}
151
153 return buildChoiceLabels;
154}
155
157 return buildStateValuations;
158}
159
161 return buildObservationValuations;
162}
163
165 return buildChoiceOrigins;
166}
167
169 return buildAllRewardModels;
170}
171
173 return buildAllLabels;
174}
175
177 return inferObservationsFromActions;
178}
179
181 return scaleAndLiftTransitionRewards;
182}
183
185 return addOutOfBoundsState;
186}
187
189 return reservedBitsForUnboundedVariables;
190}
191
193 return addOverlappingGuardsLabel;
194}
195
197 buildAllRewardModels = newValue;
198 return *this;
199}
200
202 return explorationChecks;
203}
204
206 return showProgress;
207}
208
210 return showProgressDelay;
211}
212
213storm::RationalNumber const& BuilderOptions::getStochasticTolerance() const {
214 return stochasticTolerance;
215}
216
218 explorationChecks = newValue;
219 return *this;
220}
221
222BuilderOptions& BuilderOptions::addRewardModel(std::string const& rewardModelName) {
223 STORM_LOG_THROW(!buildAllRewardModels, storm::exceptions::InvalidSettingsException, "Cannot add reward model, because all reward models are built anyway.");
224 rewardModelNames.emplace(rewardModelName);
225 return *this;
226}
227
229 buildAllLabels = newValue;
230 return *this;
231}
232
234 std::stringstream stream;
235 stream << expression;
236 expressionLabels.emplace_back(stream.str(), expression);
237 return *this;
238}
239
240BuilderOptions& BuilderOptions::addLabel(std::string const& labelName) {
241 STORM_LOG_THROW(!buildAllLabels, storm::exceptions::InvalidSettingsException, "Cannot add label, because all labels are built anyway.");
242 labelNames.insert(labelName);
243 return *this;
244}
245
247 terminalStates.push_back(std::make_pair(LabelOrExpression(expression), value));
248 return *this;
249}
250
251BuilderOptions& BuilderOptions::addTerminalLabel(std::string const& label, bool value) {
252 terminalStates.push_back(std::make_pair(LabelOrExpression(label), value));
253 return *this;
254}
255
257 applyMaximalProgressAssumption = newValue;
258 return *this;
259}
260
262 buildChoiceLabels = newValue;
263 return *this;
264}
265
267 buildStateValuations = newValue;
268 return *this;
269}
270
272 buildObservationValuations = newValue;
273 return *this;
274}
275
277 buildChoiceOrigins = newValue;
278 return *this;
279}
280
282 scaleAndLiftTransitionRewards = newValue;
283 return *this;
284}
285
287 addOutOfBoundsState = newValue;
288 return *this;
289}
290
292 reservedBitsForUnboundedVariables = newValue;
293 return *this;
294}
295
297 addOverlappingGuardsLabel = newValue;
298 return *this;
299}
300
302 std::function<storm::expressions::Expression(storm::expressions::Expression const&)> const& substitutionFunction) {
303 for (auto& e : expressionLabels) {
304 e.second = substitutionFunction(e.second);
305 }
306
307 for (auto& t : terminalStates) {
308 if (t.first.isExpression()) {
309 t.first = LabelOrExpression(substitutionFunction(t.first.getExpression()));
310 }
311 }
312 return *this;
313}
314
315} // namespace builder
316} // 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? If not set, only required reward models are build.
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?
storm::RationalNumber const & getStochasticTolerance() const
Some distributions may not sum to one.
BuilderOptions & addRewardModel(std::string const &rewardModelName)
Add an additional reward model to build.
BuilderOptions & setBuildAllRewardModels(bool newValue=true)
Should all reward models be built? If not set, only required reward models are build.
BuilderOptions & setBuildChoiceOrigins(bool newValue=true)
Should the origins the different choices be built?
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?
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.
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:30
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.