Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
BuilderOptions.cpp
Go to the documentation of this file.
2
4
7
10
13
14namespace storm {
15namespace builder {
16
17LabelOrExpression::LabelOrExpression(storm::expressions::Expression const& expression) : labelOrExpression(expression) {
18 // Intentionally left empty.
19}
20
21LabelOrExpression::LabelOrExpression(std::string const& label) : labelOrExpression(label) {
22 // Intentionally left empty.
23}
24
26 return labelOrExpression.which() == 0;
27}
28
29std::string const& LabelOrExpression::getLabel() const {
30 return boost::get<std::string>(labelOrExpression);
31}
32
34 return labelOrExpression.which() == 1;
35}
36
38 return boost::get<storm::expressions::Expression>(labelOrExpression);
39}
40
41BuilderOptions::BuilderOptions(bool buildAllRewardModels, bool buildAllLabels)
42 : buildAllRewardModels(buildAllRewardModels),
43 buildAllLabels(buildAllLabels),
44 applyMaximalProgressAssumption(false),
45 buildChoiceLabels(false),
46 buildStateValuations(false),
47 buildObservationValuations(false),
48 buildChoiceOrigins(false),
49 scaleAndLiftTransitionRewards(true),
50 explorationChecks(false),
51 inferObservationsFromActions(false),
52 addOverlappingGuardsLabel(false),
53 addOutOfBoundsState(false),
54 reservedBitsForUnboundedVariables(32),
55 showProgress(false),
56 showProgressDelay(0) {
57 // Intentionally left empty.
58}
59
61 : BuilderOptions({formula.asSharedPointer()}, modelDescription) {
62 // Intentionally left empty.
63}
64
65BuilderOptions::BuilderOptions(std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas,
66 storm::storage::SymbolicModelDescription const& modelDescription)
67 : BuilderOptions() {
68 if (!formulas.empty()) {
69 for (auto const& formula : formulas) {
70 this->preserveFormula(*formula, modelDescription);
71 }
72 if (formulas.size() == 1) {
73 this->setTerminalStatesFromFormula(*formulas.front());
74 }
75 }
76
78 if (modelDescription.hasModel()) {
82 }
83 showProgress = generalSettings.isVerboseSet();
84 showProgressDelay = generalSettings.getShowProgressDelay();
85}
86
88 // If we already had terminal states, we need to erase them.
89 if (hasTerminalStates()) {
91 }
92
93 // Determine the reward models we need to build.
94 std::set<std::string> referencedRewardModels = formula.getReferencedRewardModels();
95 for (auto const& rewardModelName : referencedRewardModels) {
96 rewardModelNames.emplace(rewardModelName);
97 }
98
99 // Extract all the labels used in the formula.
100 std::vector<std::shared_ptr<storm::logic::AtomicLabelFormula const>> atomicLabelFormulas = formula.getAtomicLabelFormulas();
101 for (auto const& formula : atomicLabelFormulas) {
102 addLabel(formula->getLabel());
103 }
104
105 // Extract all the expressions used in the formula.
106 std::vector<std::shared_ptr<storm::logic::AtomicExpressionFormula const>> atomicExpressionFormulas = formula.getAtomicExpressionFormulas();
107 for (auto const& formula : atomicExpressionFormulas) {
108 addLabel(formula->getExpression());
109 }
110
111 scaleAndLiftTransitionRewards =
112 scaleAndLiftTransitionRewards && storm::logic::LiftableTransitionRewardsVisitor(modelDescription).areTransitionRewardsLiftable(formula);
113}
114
117 formula, [this](storm::expressions::Expression const& expr, bool inverted) { this->addTerminalExpression(expr, inverted); },
118 [this](std::string const& label, bool inverted) { this->addTerminalLabel(label, inverted); });
119}
120
121std::set<std::string> const& BuilderOptions::getRewardModelNames() const {
122 return rewardModelNames;
123}
124
125std::set<std::string> const& BuilderOptions::getLabelNames() const {
126 return labelNames;
127}
128
129std::vector<std::pair<std::string, storm::expressions::Expression>> const& BuilderOptions::getExpressionLabels() const {
130 return expressionLabels;
131}
132
133std::vector<std::pair<LabelOrExpression, bool>> const& BuilderOptions::getTerminalStates() const {
134 return terminalStates;
135}
136
138 return !terminalStates.empty();
139}
140
142 terminalStates.clear();
143}
144
146 return applyMaximalProgressAssumption;
147}
148
150 return buildChoiceLabels;
151}
152
154 return buildStateValuations;
155}
156
158 return buildObservationValuations;
159}
160
162 return buildChoiceOrigins;
163}
164
166 return buildAllRewardModels;
167}
168
170 return buildAllLabels;
171}
172
174 return inferObservationsFromActions;
175}
176
178 return scaleAndLiftTransitionRewards;
179}
180
182 return addOutOfBoundsState;
183}
184
186 return reservedBitsForUnboundedVariables;
187}
188
190 return addOverlappingGuardsLabel;
191}
192
194 buildAllRewardModels = newValue;
195 return *this;
196}
197
199 return explorationChecks;
200}
201
203 return showProgress;
204}
205
207 return showProgressDelay;
208}
209
211 explorationChecks = newValue;
212 return *this;
213}
214
215BuilderOptions& BuilderOptions::addRewardModel(std::string const& rewardModelName) {
216 STORM_LOG_THROW(!buildAllRewardModels, storm::exceptions::InvalidSettingsException, "Cannot add reward model, because all reward models are built anyway.");
217 rewardModelNames.emplace(rewardModelName);
218 return *this;
219}
220
222 buildAllLabels = newValue;
223 return *this;
224}
225
227 std::stringstream stream;
228 stream << expression;
229 expressionLabels.emplace_back(stream.str(), expression);
230 return *this;
231}
232
233BuilderOptions& BuilderOptions::addLabel(std::string const& labelName) {
234 STORM_LOG_THROW(!buildAllLabels, storm::exceptions::InvalidSettingsException, "Cannot add label, because all labels are built anyway.");
235 labelNames.insert(labelName);
236 return *this;
237}
238
240 terminalStates.push_back(std::make_pair(LabelOrExpression(expression), value));
241 return *this;
242}
243
244BuilderOptions& BuilderOptions::addTerminalLabel(std::string const& label, bool value) {
245 terminalStates.push_back(std::make_pair(LabelOrExpression(label), value));
246 return *this;
247}
248
250 applyMaximalProgressAssumption = newValue;
251 return *this;
252}
253
255 buildChoiceLabels = newValue;
256 return *this;
257}
258
260 buildStateValuations = newValue;
261 return *this;
262}
263
265 buildObservationValuations = newValue;
266 return *this;
267}
268
270 buildChoiceOrigins = newValue;
271 return *this;
272}
273
275 scaleAndLiftTransitionRewards = newValue;
276 return *this;
277}
278
280 addOutOfBoundsState = newValue;
281 return *this;
282}
283
285 reservedBitsForUnboundedVariables = newValue;
286 return *this;
287}
288
290 addOverlappingGuardsLabel = newValue;
291 return *this;
292}
293
295 std::function<storm::expressions::Expression(storm::expressions::Expression const&)> const& substitutionFunction) {
296 for (auto& e : expressionLabels) {
297 e.second = substitutionFunction(e.second);
298 }
299
300 for (auto& t : terminalStates) {
301 if (t.first.isExpression()) {
302 t.first = LabelOrExpression(substitutionFunction(t.first.getExpression()));
303 }
304 }
305 return *this;
306}
307
308} // namespace builder
309} // 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?
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:477
std::vector< std::shared_ptr< AtomicLabelFormula const > > getAtomicLabelFormulas() const
Definition Formula.cpp:483
std::set< std::string > getReferencedRewardModels() const
Definition Formula.cpp:495
std::shared_ptr< Formula const > asSharedPointer()
Definition Formula.cpp:548
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.
SettingsType const & getModule()
Get module.
LabParser.cpp.
Definition cli.cpp:18