Storm 1.11.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
FormulaParserGrammar.cpp
Go to the documentation of this file.
2
3#include <memory>
4
6
7namespace storm {
8namespace parser {
9
10FormulaParserGrammar::FormulaParserGrammar(std::shared_ptr<storm::expressions::ExpressionManager const> const& manager)
11 : FormulaParserGrammar::base_type(start), constManager(manager), manager(nullptr), expressionParser(*manager, keywords_, true, true), propertyCount(0) {
12 initialize();
13}
14
15FormulaParserGrammar::FormulaParserGrammar(std::shared_ptr<storm::expressions::ExpressionManager> const& manager)
16 : FormulaParserGrammar::base_type(start), constManager(manager), manager(manager), expressionParser(*manager, keywords_, true, true), propertyCount(0) {
17 initialize();
18}
19
20qi::symbols<char, storm::expressions::Expression> const& FormulaParserGrammar::getIdentifiers() const {
21 return identifiers_;
22}
23
24void FormulaParserGrammar::initialize() {
25 // Register all variables so we can parse them in the expressions.
26 for (auto variableTypePair : *constManager) {
27 addIdentifierExpression(variableTypePair.first.getName(), variableTypePair.first);
28 }
29 // Set the identifier mapping to actually generate expressions.
30 expressionParser.setIdentifierMapping(&identifiers_);
31
32 keywords_.name("keyword");
33 nonStandardKeywords_.name("non-standard Storm-specific keyword");
34 relationalOperator_.name("relational operator");
35 optimalityOperator_.name("optimality operator");
36 operatorKeyword_.name("Operator keyword");
37 filterType_.name("filter type");
38
39 // Auxiliary helpers
40 isPathFormula = qi::eps(qi::_r1 == FormulaKind::Path);
41 noAmbiguousNonAssociativeOperator =
42 !(qi::lit(qi::_r2)[qi::_pass = phoenix::bind(&FormulaParserGrammar::raiseAmbiguousNonAssociativeOperatorError, phoenix::ref(*this), qi::_r1, qi::_r2)]);
43 noAmbiguousNonAssociativeOperator.name("no ambiguous non-associative operator");
44 identifier %= qi::as_string[qi::raw[qi::lexeme[((qi::alpha | qi::char_('_') | qi::char_('.')) >> *(qi::alnum | qi::char_('_')))]]];
45 identifier.name("identifier");
46 label %= qi::as_string[qi::raw[qi::lexeme[((qi::alpha | qi::char_('_')) >> *(qi::alnum | qi::char_('_')))]]];
47 label.name("label");
48 quotedString %= qi::as_string[qi::lexeme[qi::omit[qi::char_('"')] > qi::raw[*(!qi::char_('"') >> qi::char_)] > qi::omit[qi::lit('"')]]];
49 quotedString.name("quoted string");
50
51 // PCTL-like Operator Formulas
52 operatorInformation =
53 (-optimalityOperator_)[qi::_a = qi::_1] >>
54 ((qi::lit("=") >
55 qi::lit("?"))[qi::_val = phoenix::bind(&FormulaParserGrammar::createOperatorInformation, phoenix::ref(*this), qi::_a, boost::none, boost::none)] |
56 (relationalOperator_ >
57 expressionParser)[qi::_val = phoenix::bind(&FormulaParserGrammar::createOperatorInformation, phoenix::ref(*this), qi::_a, qi::_1, qi::_2)]);
58 operatorInformation.name("operator information");
59 operatorSubFormula =
60 (((qi::eps(qi::_r1 == storm::logic::FormulaContext::Probability) > formula(FormulaKind::Path, qi::_r1)) |
61 (qi::eps(qi::_r1 == storm::logic::FormulaContext::Reward) >
62 (longRunAverageRewardFormula | eventuallyFormula(qi::_r1) | discountedCumulativeRewardFormula | discountedTotalRewardFormula |
63 cumulativeRewardFormula | instantaneousRewardFormula | totalRewardFormula)) |
64 (qi::eps(qi::_r1 == storm::logic::FormulaContext::Time) > eventuallyFormula(qi::_r1)) |
65 (qi::eps(qi::_r1 == storm::logic::FormulaContext::LongRunAverage) > formula(FormulaKind::State, storm::logic::FormulaContext::LongRunAverage))) >>
66 -(qi::lit("||") >
67 formula(FormulaKind::Path, storm::logic::FormulaContext::Probability)))[qi::_val = phoenix::bind(&FormulaParserGrammar::createConditionalFormula,
68 phoenix::ref(*this), qi::_1, qi::_2, qi::_r1)];
69 operatorSubFormula.name("operator subformula");
70 rewardModelName = qi::eps(qi::_r1 == storm::logic::FormulaContext::Reward) >> (qi::lit("{\"") > label > qi::lit("\"}"));
71 rewardModelName.name("reward model name");
72 operatorFormula =
73 (operatorKeyword_[qi::_a = qi::_1] > -rewardModelName(qi::_a) > operatorInformation > qi::lit("[") > operatorSubFormula(qi::_a) >
74 qi::lit("]"))[qi::_val = phoenix::bind(&FormulaParserGrammar::createOperatorFormula, phoenix::ref(*this), qi::_a, qi::_2, qi::_3, qi::_4)];
75 operatorFormula.name("operator formula");
76
77 // Atomic propositions
78 labelFormula =
79 (qi::lit("\"") >> label >> qi::lit("\""))[qi::_val = phoenix::bind(&FormulaParserGrammar::createAtomicLabelFormula, phoenix::ref(*this), qi::_1)];
80 labelFormula.name("label formula");
81 expressionFormula = expressionParser[qi::_val = phoenix::bind(&FormulaParserGrammar::createAtomicExpressionFormula, phoenix::ref(*this), qi::_1)];
82 expressionFormula.name("expression formula");
83
84 basicPropositionalFormula =
85 expressionFormula // try as expression first, e.g. '(false)=false' is an atomic expression formula. Also should be checked before operator formulas and
86 // others. Otherwise, e.g. variable "Random" would be parsed as reward operator 'R' (followed by andom)
87 | (qi::lit("(") >>
88 (formula(qi::_r1, qi::_r2) > qi::lit(")"))) // If we're starting with '(' but this is not an expression, we must have a formula inside the brackets
89 | labelFormula | negationPropositionalFormula(qi::_r1, qi::_r2) | operatorFormula |
90 (isPathFormula(qi::_r1) >> prefixOperatorPathFormula(qi::_r2)) // Needed for e.g. F "a" & X "a" = F ("a" & (X "a"))
91 | multiOperatorFormula // Has to come after prefixOperatorPathFormula to avoid confusion with multiBoundedPathFormula
92 | quantileFormula | gameFormula;
93
94 // Propositional Logic operators
95 // To correctly parse the operator precedences (! binds stronger than & binds stronger than |), we run through different "precedence levels" starting with
96 // the strongest binding operator.
97 negationPropositionalFormula =
98 (qi::lit("!") >
99 basicPropositionalFormula(qi::_r1, qi::_r2))[qi::_val = phoenix::bind(&FormulaParserGrammar::createUnaryBooleanStateOrPathFormula, phoenix::ref(*this),
101 basicPropositionalFormula.name("basic propositional formula");
102 andLevelPropositionalFormula =
103 basicPropositionalFormula(qi::_r1, qi::_r2)[qi::_val = qi::_1] >>
104 *(qi::lit("&") > basicPropositionalFormula(
105 qi::_r1, qi::_r2)[qi::_val = phoenix::bind(&FormulaParserGrammar::createBinaryBooleanStateOrPathFormula, phoenix::ref(*this),
106 qi::_val, qi::_1, storm::logic::BinaryBooleanStateFormula::OperatorType::And)]);
107 andLevelPropositionalFormula.name("and precedence level propositional formula");
108 orLevelPropositionalFormula =
109 andLevelPropositionalFormula(qi::_r1, qi::_r2)[qi::_val = qi::_1] >>
110 *((!qi::lit("||") >> qi::lit("|")) // Make sure to not confuse with conditional operator "||"
111 > andLevelPropositionalFormula(
112 qi::_r1, qi::_r2)[qi::_val = phoenix::bind(&FormulaParserGrammar::createBinaryBooleanStateOrPathFormula, phoenix::ref(*this), qi::_val, qi::_1,
113 storm::logic::BinaryBooleanStateFormula::OperatorType::Or)]);
114 orLevelPropositionalFormula.name("or precedence level propositional formula");
115 propositionalFormula = orLevelPropositionalFormula(qi::_r1, qi::_r2);
116
117 // Path operators
118 // Again need to parse precedences correctly. Propositional formulae bind stronger than temporal operators.
119 basicPathFormula = propositionalFormula(FormulaKind::Path, qi::_r1) // Bracketed case is handled here as well
120 | prefixOperatorPathFormula(
121 qi::_r1); // Needs to be checked *after* atomic expression formulas. Otherwise e.g. variable Fail would be parsed as "F (ail)"
122 prefixOperatorPathFormula =
123 eventuallyFormula(qi::_r1) | nextFormula(qi::_r1) | globallyFormula(qi::_r1) | hoaPathFormula(qi::_r1) | multiBoundedPathFormula(qi::_r1);
124 basicPathFormula.name("basic path formula");
125 timeBoundReference =
126 (-qi::lit("rew") >>
127 rewardModelName(storm::logic::FormulaContext::Reward))[qi::_val = phoenix::bind(&FormulaParserGrammar::createTimeBoundReference, phoenix::ref(*this),
129 (qi::lit("rew") >>
130 -rewardModelName(storm::logic::FormulaContext::Reward))[qi::_val = phoenix::bind(&FormulaParserGrammar::createTimeBoundReference, phoenix::ref(*this),
132 (qi::lit("steps"))[qi::_val = phoenix::bind(&FormulaParserGrammar::createTimeBoundReference, phoenix::ref(*this), storm::logic::TimeBoundType::Steps,
133 boost::none)] |
134 (-qi::lit("time"))[qi::_val = phoenix::bind(&FormulaParserGrammar::createTimeBoundReference, phoenix::ref(*this), storm::logic::TimeBoundType::Time,
135 boost::none)];
136 timeBoundReference.name("time bound reference");
137 timeBound = ((timeBoundReference >> qi::lit("[")) > expressionParser > qi::lit(",") > expressionParser >
138 qi::lit("]"))[qi::_val = phoenix::bind(&FormulaParserGrammar::createTimeBoundFromInterval, phoenix::ref(*this), qi::_2, qi::_3, qi::_1)] |
139 (timeBoundReference >> (qi::lit("<=")[(qi::_a = true, qi::_b = false)] | qi::lit("<")[(qi::_a = true, qi::_b = true)] |
140 qi::lit(">=")[(qi::_a = false, qi::_b = false)] | qi::lit(">")[(qi::_a = false, qi::_b = true)]) >>
141 expressionParser)[qi::_val = phoenix::bind(&FormulaParserGrammar::createTimeBoundFromSingleBound, phoenix::ref(*this), qi::_2, qi::_a, qi::_b,
142 qi::_1)] |
143 (timeBoundReference >> qi::lit("=") >>
144 expressionParser)[qi::_val = phoenix::bind(&FormulaParserGrammar::createTimeBoundFromInterval, phoenix::ref(*this), qi::_2, qi::_2, qi::_1)];
145 timeBound.name("time bound");
146 timeBounds = (timeBound % qi::lit(",")) | (((-qi::lit("^") >> qi::lit("{")) >> (timeBound % qi::lit(","))) >> qi::lit("}"));
147 timeBounds.name("time bounds");
148 eventuallyFormula =
149 (qi::lit("F") > (-timeBounds) >
150 basicPathFormula(qi::_r1))[qi::_val = phoenix::bind(&FormulaParserGrammar::createEventuallyFormula, phoenix::ref(*this), qi::_1, qi::_r1, qi::_2)];
151 eventuallyFormula.name("eventually formula");
152 nextFormula = (qi::lit("X") > basicPathFormula(qi::_r1))[qi::_val = phoenix::bind(&FormulaParserGrammar::createNextFormula, phoenix::ref(*this), qi::_1)];
153 nextFormula.name("next formula");
154 globallyFormula =
155 (qi::lit("G") > basicPathFormula(qi::_r1))[qi::_val = phoenix::bind(&FormulaParserGrammar::createGloballyFormula, phoenix::ref(*this), qi::_1)];
156 globallyFormula.name("globally formula");
157 hoaPathFormula =
158 qi::lit("HOA:") > qi::lit("{") > quotedString[qi::_val = phoenix::bind(&FormulaParserGrammar::createHOAPathFormula, phoenix::ref(*this), qi::_1)] >>
159 *(qi::lit(",") > quotedString > qi::lit("->") >
160 formula(FormulaKind::State, qi::_r1))[phoenix::bind(&FormulaParserGrammar::addHoaAPMapping, phoenix::ref(*this), *qi::_val, qi::_1, qi::_2)] >
161 qi::lit("}");
162 multiBoundedPathFormulaOperand = pathFormula(
163 qi::_r1)[qi::_pass = phoenix::bind(&FormulaParserGrammar::isValidMultiBoundedPathFormulaOperand, phoenix::ref(*this), qi::_1)][qi::_val = qi::_1];
164 multiBoundedPathFormulaOperand.name("multi bounded path formula operand");
165 multiBoundedPathFormula = ((qi::lit("multi") > qi::lit("(")) >> (multiBoundedPathFormulaOperand(qi::_r1) % qi::lit(",")) >>
166 qi::lit(")"))[qi::_val = phoenix::bind(&FormulaParserGrammar::createMultiBoundedPathFormula, phoenix::ref(*this), qi::_1)];
167 multiBoundedPathFormula.name("multi bounded path formula");
168 untilLevelPathFormula =
169 basicPathFormula(qi::_r1)[qi::_val = qi::_1] >>
170 -((qi::lit("U") > (-timeBounds) >
171 basicPathFormula(qi::_r1))[qi::_val = phoenix::bind(&FormulaParserGrammar::createUntilFormula, phoenix::ref(*this), qi::_val, qi::_1, qi::_2)]) >>
172 (qi::eps > noAmbiguousNonAssociativeOperator(qi::_val, std::string("U"))); // Do not parse a U b U c
173 untilLevelPathFormula.name("until precedence level path formula");
174 pathFormula = untilLevelPathFormula(qi::_r1);
175 pathFormula.name("path formula");
176
177 // Quantitative path formulae (reward)
178 discountedTotalRewardFormula =
179 (qi::lit("Cdiscount=") >>
180 expressionParser)[qi::_val = phoenix::bind(&FormulaParserGrammar::createDiscountedTotalRewardFormula, phoenix::ref(*this), qi::_1)];
181 discountedTotalRewardFormula.name("discounted total reward formula");
182 discountedCumulativeRewardFormula =
183 (qi::lit("C") >> timeBounds >> qi::lit("discount=") >>
184 expressionParser)[qi::_val = phoenix::bind(&FormulaParserGrammar::createDiscountedCumulativeRewardFormula, phoenix::ref(*this), qi::_2, qi::_1)];
185 discountedCumulativeRewardFormula.name("discounted cumulative reward formula");
186 longRunAverageRewardFormula = (qi::lit("LRA") | qi::lit("S") |
187 qi::lit("MP"))[qi::_val = phoenix::bind(&FormulaParserGrammar::createLongRunAverageRewardFormula, phoenix::ref(*this))];
188 longRunAverageRewardFormula.name("long run average reward formula");
189 instantaneousRewardFormula =
190 (qi::lit("I=") > expressionParser)[qi::_val = phoenix::bind(&FormulaParserGrammar::createInstantaneousRewardFormula, phoenix::ref(*this), qi::_1)];
191 instantaneousRewardFormula.name("instantaneous reward formula");
192 cumulativeRewardFormula =
193 (qi::lit("C") >> timeBounds)[qi::_val = phoenix::bind(&FormulaParserGrammar::createCumulativeRewardFormula, phoenix::ref(*this), qi::_1)];
194 cumulativeRewardFormula.name("cumulative reward formula");
195 totalRewardFormula = (qi::lit("C"))[qi::_val = phoenix::bind(&FormulaParserGrammar::createTotalRewardFormula, phoenix::ref(*this))];
196 totalRewardFormula.name("total reward formula");
197
198 // Game Formulae
199 playerCoalition = (-((identifier[phoenix::push_back(qi::_a, qi::_1)] | qi::uint_[phoenix::push_back(qi::_a, qi::_1)]) %
200 ','))[qi::_val = phoenix::bind(&FormulaParserGrammar::createPlayerCoalition, phoenix::ref(*this), qi::_a)];
201 playerCoalition.name("player coalition");
202 gameFormula = (qi::lit("<<") > playerCoalition > qi::lit(">>") >
203 operatorFormula)[qi::_val = phoenix::bind(&FormulaParserGrammar::createGameFormula, phoenix::ref(*this), qi::_1, qi::_2)];
204 gameFormula.name("game formula");
205
206 // Multi-objective, quantiles
207 multiOperatorFormula = (qi::lit("multi") > qi::lit("(") > (operatorFormula % qi::lit(",")) >
208 qi::lit(")"))[qi::_val = phoenix::bind(&FormulaParserGrammar::createMultiOperatorFormula, phoenix::ref(*this), qi::_1)];
209 multiOperatorFormula.name("multi-objective operator formula");
210 quantileBoundVariable = (-optimalityOperator_ >> identifier >>
211 qi::lit(","))[qi::_val = phoenix::bind(&FormulaParserGrammar::createQuantileBoundVariables, phoenix::ref(*this), qi::_1, qi::_2)];
212 quantileBoundVariable.name("quantile bound variable");
213 quantileFormula = (qi::lit("quantile") > qi::lit("(") > *(quantileBoundVariable) >
214 operatorFormula[qi::_pass = phoenix::bind(&FormulaParserGrammar::isBooleanReturnType, phoenix::ref(*this), qi::_1, true)] >
215 qi::lit(")"))[qi::_val = phoenix::bind(&FormulaParserGrammar::createQuantileFormula, phoenix::ref(*this), qi::_1, qi::_2)];
216 quantileFormula.name("Quantile formula");
217
218 // General formulae
219 formula = (isPathFormula(qi::_r1) >> pathFormula(qi::_r2) | propositionalFormula(qi::_r1, qi::_r2));
220 formula.name("formula");
221
222 topLevelFormula = formula(FormulaKind::State, storm::logic::FormulaContext::Undefined);
223 topLevelFormula.name("top-level formula");
224
225 formulaName = qi::lit("\"") >> identifier >> qi::lit("\"") >> qi::lit(":");
226 formulaName.name("formula name");
227
228 constantDefinition =
229 (qi::lit("const") > -(qi::lit("int")[qi::_a = ConstantDataType::Integer] | qi::lit("bool")[qi::_a = ConstantDataType::Bool] |
230 qi::lit("double")[qi::_a = ConstantDataType::Rational]) >>
231 identifier >> -(qi::lit("=") > expressionParser))[phoenix::bind(&FormulaParserGrammar::addConstant, phoenix::ref(*this), qi::_1, qi::_a, qi::_2)];
232 constantDefinition.name("constant definition");
233
234#pragma clang diagnostic push
235#pragma clang diagnostic ignored "-Woverloaded-shift-op-parentheses"
236
237 filterProperty =
238 (-formulaName >> qi::lit("filter") > qi::lit("(") > filterType_ > qi::lit(",") > topLevelFormula > qi::lit(",") >
239 formula(FormulaKind::State, storm::logic::FormulaContext::Undefined) >
240 qi::lit(")"))[qi::_val = phoenix::bind(&FormulaParserGrammar::createProperty, phoenix::ref(*this), qi::_1, qi::_2, qi::_3, qi::_4)] |
241 (-formulaName >>
242 topLevelFormula)[qi::_val = phoenix::bind(&FormulaParserGrammar::createPropertyWithDefaultFilterTypeAndStates, phoenix::ref(*this), qi::_1, qi::_2)];
243 filterProperty.name("filter property");
244
245#pragma clang diagnostic pop
246
247 start = (qi::eps >> filterProperty[phoenix::push_back(qi::_val, qi::_1)] |
248 qi::eps(phoenix::bind(&FormulaParserGrammar::areConstantDefinitionsAllowed, phoenix::ref(*this))) >> constantDefinition | qi::eps) %
249 +(qi::char_("\n;")) >>
250 qi::skip(storm::spirit_encoding::space_type() | qi::lit("//") >> *(qi::char_ - (qi::eol | qi::eoi)))[qi::eps] >> qi::eoi;
251 start.name("start");
252
253 // Enable the following lines to print debug output for most the rules.
254 // debug(rewardModelName)
255 // debug(operatorFormula)
256 // debug(labelFormula)
257 // debug(expressionFormula)
258 // debug(basicPropositionalFormula)
259 // debug(negationPropositionalFormula)
260 // debug(andLevelPropositionalFormula)
261 // debug(orLevelPropositionalFormula)
262 // debug(propositionalFormula)
263 // debug(timeBoundReference)
264 // debug(timeBound)
265 // debug(timeBounds)
266 // debug(eventuallyFormula)
267 // debug(nextFormula)
268 // debug(globallyFormula)
269 // debug(hoaPathFormula)
270 // debug(multiBoundedPathFormula)
271 // debug(prefixOperatorPathFormula)
272 // debug(basicPathFormula)
273 // debug(untilLevelPathFormula)
274 // debug(pathFormula)
275 // debug(longRunAverageRewardFormula)
276 // debug(instantaneousRewardFormula)
277 // debug(cumulativeRewardFormula)
278 // debug(totalRewardFormula)
279 // debug(playerCoalition)
280 // debug(gameFormula)
281 // debug(multiOperatorFormula)
282 // debug(quantileBoundVariable)
283 // debug(quantileFormula)
284 // debug(formula)
285 // debug(topLevelFormula)
286 // debug(formulaName)
287 // debug(filterProperty)
288 // debug(constantDefinition )
289 // debug(start)
290 // debug(discountedCumulativeRewardFormula)
291 // debug(discountedTotalRewardFormula)
292
293 // Enable error reporting.
294 qi::on_error<qi::fail>(rewardModelName, handler(qi::_1, qi::_2, qi::_3, qi::_4));
295 qi::on_error<qi::fail>(operatorFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
296 qi::on_error<qi::fail>(labelFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
297 qi::on_error<qi::fail>(expressionFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
298 qi::on_error<qi::fail>(basicPropositionalFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
299 qi::on_error<qi::fail>(negationPropositionalFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
300 qi::on_error<qi::fail>(andLevelPropositionalFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
301 qi::on_error<qi::fail>(orLevelPropositionalFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
302 qi::on_error<qi::fail>(propositionalFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
303 qi::on_error<qi::fail>(timeBoundReference, handler(qi::_1, qi::_2, qi::_3, qi::_4));
304 qi::on_error<qi::fail>(timeBound, handler(qi::_1, qi::_2, qi::_3, qi::_4));
305 qi::on_error<qi::fail>(timeBounds, handler(qi::_1, qi::_2, qi::_3, qi::_4));
306 qi::on_error<qi::fail>(eventuallyFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
307 qi::on_error<qi::fail>(nextFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
308 qi::on_error<qi::fail>(globallyFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
309 qi::on_error<qi::fail>(hoaPathFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
310 qi::on_error<qi::fail>(multiBoundedPathFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
311 qi::on_error<qi::fail>(prefixOperatorPathFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
312 qi::on_error<qi::fail>(basicPathFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
313 qi::on_error<qi::fail>(untilLevelPathFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
314 qi::on_error<qi::fail>(pathFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
315 qi::on_error<qi::fail>(longRunAverageRewardFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
316 qi::on_error<qi::fail>(instantaneousRewardFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
317 qi::on_error<qi::fail>(cumulativeRewardFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
318 qi::on_error<qi::fail>(totalRewardFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
319 qi::on_error<qi::fail>(discountedCumulativeRewardFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
320 qi::on_error<qi::fail>(discountedTotalRewardFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
321 qi::on_error<qi::fail>(playerCoalition, handler(qi::_1, qi::_2, qi::_3, qi::_4));
322 qi::on_error<qi::fail>(gameFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
323 qi::on_error<qi::fail>(multiOperatorFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
324 qi::on_error<qi::fail>(quantileBoundVariable, handler(qi::_1, qi::_2, qi::_3, qi::_4));
325 qi::on_error<qi::fail>(quantileFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
326 qi::on_error<qi::fail>(formula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
327 qi::on_error<qi::fail>(topLevelFormula, handler(qi::_1, qi::_2, qi::_3, qi::_4));
328 qi::on_error<qi::fail>(formulaName, handler(qi::_1, qi::_2, qi::_3, qi::_4));
329 qi::on_error<qi::fail>(filterProperty, handler(qi::_1, qi::_2, qi::_3, qi::_4));
330 qi::on_error<qi::fail>(constantDefinition, handler(qi::_1, qi::_2, qi::_3, qi::_4));
331 qi::on_error<qi::fail>(start, handler(qi::_1, qi::_2, qi::_3, qi::_4));
332}
333
334void FormulaParserGrammar::addIdentifierExpression(std::string const& identifier, storm::expressions::Expression const& expression) {
335 STORM_LOG_WARN_COND(keywords_.find(identifier) == nullptr,
336 "Identifier `" << identifier << "' coincides with a reserved keyword or operator. Property expressions using the variable or constant '"
337 << identifier << "' will not be parsed correctly.");
338 STORM_LOG_WARN_COND(nonStandardKeywords_.find(identifier) == nullptr,
339 "Identifier `" << identifier << "' coincides with a reserved keyword or operator. Property expressions using the variable or constant '"
340 << identifier << "' might not be parsed correctly.");
341 this->identifiers_.add(identifier, expression);
342}
343
344void FormulaParserGrammar::addConstant(std::string const& name, ConstantDataType type, boost::optional<storm::expressions::Expression> const& expression) {
345 STORM_LOG_ASSERT(manager, "Mutable expression manager required to define new constants.");
347 STORM_LOG_THROW(!manager->hasVariable(name), storm::exceptions::WrongFormatException,
348 "Invalid constant definition '" << name << "' in property: variable already exists.");
349
350 if (type == ConstantDataType::Bool) {
351 newVariable = manager->declareBooleanVariable(name);
352 } else if (type == ConstantDataType::Integer) {
353 newVariable = manager->declareIntegerVariable(name);
354 } else {
355 newVariable = manager->declareRationalVariable(name);
356 }
357
358 if (expression) {
359 addIdentifierExpression(name, expression.get());
360 } else {
361 undefinedConstants.insert(newVariable);
362 addIdentifierExpression(name, newVariable);
363 }
364}
365
366bool FormulaParserGrammar::areConstantDefinitionsAllowed() const {
367 return static_cast<bool>(manager);
368}
369
370std::shared_ptr<storm::logic::TimeBoundReference> FormulaParserGrammar::createTimeBoundReference(storm::logic::TimeBoundType const& type,
371 boost::optional<std::string> const& rewardModelName) const {
373 return std::make_shared<storm::logic::TimeBoundReference>(rewardModelName);
374 } else {
375 return std::make_shared<storm::logic::TimeBoundReference>(type);
376 }
377}
378
379std::tuple<boost::optional<storm::logic::TimeBound>, boost::optional<storm::logic::TimeBound>, std::shared_ptr<storm::logic::TimeBoundReference>>
380FormulaParserGrammar::createTimeBoundFromInterval(storm::expressions::Expression const& lowerBound, storm::expressions::Expression const& upperBound,
381 std::shared_ptr<storm::logic::TimeBoundReference> const& timeBoundReference) const {
382 // As soon as it somehow does not break everything anymore, I will change return types here.
383
384 storm::logic::TimeBound lower(false, lowerBound);
385 storm::logic::TimeBound upper(false, upperBound);
386 return std::make_tuple(lower, upper, timeBoundReference);
387}
388
389std::tuple<boost::optional<storm::logic::TimeBound>, boost::optional<storm::logic::TimeBound>, std::shared_ptr<storm::logic::TimeBoundReference>>
390FormulaParserGrammar::createTimeBoundFromSingleBound(storm::expressions::Expression const& bound, bool upperBound, bool strict,
391 std::shared_ptr<storm::logic::TimeBoundReference> const& timeBoundReference) const {
392 // As soon as it somehow does not break everything anymore, I will change return types here.
393 if (upperBound) {
394 return std::make_tuple(boost::none, storm::logic::TimeBound(strict, bound), timeBoundReference);
395 } else {
396 return std::make_tuple(storm::logic::TimeBound(strict, bound), boost::none, timeBoundReference);
397 }
398}
399
400std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createInstantaneousRewardFormula(storm::expressions::Expression const& timeBound) const {
401 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::InstantaneousRewardFormula(timeBound));
402}
403
404std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createCumulativeRewardFormula(
405 std::vector<std::tuple<boost::optional<storm::logic::TimeBound>, boost::optional<storm::logic::TimeBound>,
406 std::shared_ptr<storm::logic::TimeBoundReference>>> const& timeBounds) const {
407 std::vector<storm::logic::TimeBound> bounds;
408 std::vector<storm::logic::TimeBoundReference> timeBoundReferences;
409 for (auto const& timeBound : timeBounds) {
410 STORM_LOG_THROW(!std::get<0>(timeBound), storm::exceptions::WrongFormatException, "Cumulative reward formulas with lower time bound are not allowed.");
411 STORM_LOG_THROW(std::get<1>(timeBound), storm::exceptions::WrongFormatException, "Cumulative reward formulas require an upper bound.");
412 bounds.push_back(std::get<1>(timeBound).get());
413 timeBoundReferences.emplace_back(*std::get<2>(timeBound));
414 }
415 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::CumulativeRewardFormula(bounds, timeBoundReferences));
416}
417
418std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createDiscountedCumulativeRewardFormula(
419 storm::expressions::Expression const& discountFactor,
420 std::vector<std::tuple<boost::optional<storm::logic::TimeBound>, boost::optional<storm::logic::TimeBound>,
421 std::shared_ptr<storm::logic::TimeBoundReference>>> const& timeBounds) const {
422 std::vector<storm::logic::TimeBound> bounds;
423 std::vector<storm::logic::TimeBoundReference> timeBoundReferences;
424 for (auto const& timeBound : timeBounds) {
425 STORM_LOG_THROW(!std::get<0>(timeBound), storm::exceptions::WrongFormatException, "Cumulative reward formulas with lower time bound are not allowed.");
426 STORM_LOG_THROW(std::get<1>(timeBound), storm::exceptions::WrongFormatException, "Cumulative reward formulas require an upper bound.");
427 bounds.push_back(std::get<1>(timeBound).get());
428 timeBoundReferences.emplace_back(*std::get<2>(timeBound));
429 }
430 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::DiscountedCumulativeRewardFormula(discountFactor, bounds, timeBoundReferences));
431}
432
433std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createTotalRewardFormula() const {
434 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::TotalRewardFormula());
435}
436
437std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createDiscountedTotalRewardFormula(
438 storm::expressions::Expression const& discountFactor) const {
439 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::DiscountedTotalRewardFormula(discountFactor));
440}
441
442std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createLongRunAverageRewardFormula() const {
443 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::LongRunAverageRewardFormula());
444}
445
446std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createAtomicExpressionFormula(storm::expressions::Expression const& expression) const {
447 STORM_LOG_THROW(expression.hasBooleanType(), storm::exceptions::WrongFormatException,
448 "Expected expression " + expression.toString() + " to be of boolean type.");
449 if (expression.isLiteral()) {
450 return createBooleanLiteralFormula(expression.evaluateAsBool());
451 }
452 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::AtomicExpressionFormula(expression));
453}
454
455std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createBooleanLiteralFormula(bool literal) const {
456 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::BooleanLiteralFormula(literal));
457}
458
459std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createAtomicLabelFormula(std::string const& label) const {
460 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::AtomicLabelFormula(label));
461}
462
463std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createEventuallyFormula(
464 boost::optional<std::vector<std::tuple<boost::optional<storm::logic::TimeBound>, boost::optional<storm::logic::TimeBound>,
465 std::shared_ptr<storm::logic::TimeBoundReference>>>> const& timeBounds,
466 storm::logic::FormulaContext context, std::shared_ptr<storm::logic::Formula const> const& subformula) const {
467 if (timeBounds && !timeBounds.get().empty()) {
468 std::vector<boost::optional<storm::logic::TimeBound>> lowerBounds, upperBounds;
469 std::vector<storm::logic::TimeBoundReference> timeBoundReferences;
470 for (auto const& timeBound : timeBounds.get()) {
471 lowerBounds.push_back(std::get<0>(timeBound));
472 upperBounds.push_back(std::get<1>(timeBound));
473 timeBoundReferences.emplace_back(*std::get<2>(timeBound));
474 }
475 return std::shared_ptr<storm::logic::Formula const>(
476 new storm::logic::BoundedUntilFormula(createBooleanLiteralFormula(true), subformula, lowerBounds, upperBounds, timeBoundReferences));
477 } else {
478 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::EventuallyFormula(subformula, context));
479 }
480}
481
482std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createGloballyFormula(std::shared_ptr<storm::logic::Formula const> const& subformula) const {
483 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::GloballyFormula(subformula));
484}
485
486std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createNextFormula(std::shared_ptr<storm::logic::Formula const> const& subformula) const {
487 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::NextFormula(subformula));
488}
489
490std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createUntilFormula(
491 std::shared_ptr<storm::logic::Formula const> const& leftSubformula,
492 boost::optional<std::vector<std::tuple<boost::optional<storm::logic::TimeBound>, boost::optional<storm::logic::TimeBound>,
493 std::shared_ptr<storm::logic::TimeBoundReference>>>> const& timeBounds,
494 std::shared_ptr<storm::logic::Formula const> const& rightSubformula) {
495 if (timeBounds && !timeBounds.get().empty()) {
496 std::vector<boost::optional<storm::logic::TimeBound>> lowerBounds, upperBounds;
497 std::vector<storm::logic::TimeBoundReference> timeBoundReferences;
498 for (auto const& timeBound : timeBounds.get()) {
499 lowerBounds.push_back(std::get<0>(timeBound));
500 upperBounds.push_back(std::get<1>(timeBound));
501 timeBoundReferences.emplace_back(*std::get<2>(timeBound));
502 }
503 return std::shared_ptr<storm::logic::Formula const>(
504 new storm::logic::BoundedUntilFormula(leftSubformula, rightSubformula, lowerBounds, upperBounds, timeBoundReferences));
505 } else {
506 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::UntilFormula(leftSubformula, rightSubformula));
507 }
508}
509
510std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createHOAPathFormula(std::string const& automatonFile) const {
511 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::HOAPathFormula(automatonFile));
512}
513
514void FormulaParserGrammar::addHoaAPMapping(storm::logic::Formula const& hoaFormula, const std::string& ap,
515 std::shared_ptr<storm::logic::Formula const>& expression) const {
516 // taking a const Formula reference and doing static_ and const_cast from Formula to allow non-const access to
517 // qi::_val of the hoaPathFormula rule
518 storm::logic::HOAPathFormula& hoaFormula_ = static_cast<storm::logic::HOAPathFormula&>(const_cast<storm::logic::Formula&>(hoaFormula));
519 hoaFormula_.addAPMapping(ap, expression);
520}
521
522std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createConditionalFormula(
523 std::shared_ptr<storm::logic::Formula const> const& leftSubformula, boost::optional<std::shared_ptr<storm::logic::Formula const>> const& rightSubformula,
524 storm::logic::FormulaContext context) const {
525 if (rightSubformula) {
526 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::ConditionalFormula(leftSubformula, rightSubformula.get(), context));
527 } else {
528 // If there is no rhs, just return the lhs
529 return leftSubformula;
530 }
531}
532
533storm::logic::OperatorInformation FormulaParserGrammar::createOperatorInformation(boost::optional<storm::OptimizationDirection> const& optimizationDirection,
534 boost::optional<storm::logic::ComparisonType> const& comparisonType,
535 boost::optional<storm::expressions::Expression> const& threshold) const {
536 if (comparisonType && threshold) {
538 return storm::logic::OperatorInformation(optimizationDirection, storm::logic::Bound(comparisonType.get(), threshold.get()));
539 } else {
540 return storm::logic::OperatorInformation(optimizationDirection, boost::none);
541 }
542}
543
544std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createOperatorFormula(storm::logic::FormulaContext const& context,
545 boost::optional<std::string> const& rewardModelName,
546 storm::logic::OperatorInformation const& operatorInformation,
547 std::shared_ptr<storm::logic::Formula const> const& subformula) {
548 switch (context) {
550 STORM_LOG_ASSERT(!rewardModelName, "Probability operator with reward information parsed");
551 return createProbabilityOperatorFormula(operatorInformation, subformula);
553 return createRewardOperatorFormula(rewardModelName, operatorInformation, subformula);
555 STORM_LOG_ASSERT(!rewardModelName, "LRA operator with reward information parsed");
556 return createLongRunAverageOperatorFormula(operatorInformation, subformula);
558 STORM_LOG_ASSERT(!rewardModelName, "Time operator with reward model name parsed");
559 return createTimeOperatorFormula(operatorInformation, subformula);
560 default:
561 STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "Unexpected formula context.");
562 }
563}
564
565std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createLongRunAverageOperatorFormula(
566 storm::logic::OperatorInformation const& operatorInformation, std::shared_ptr<storm::logic::Formula const> const& subformula) const {
567 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::LongRunAverageOperatorFormula(subformula, operatorInformation));
568}
569
570std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createRewardOperatorFormula(
571 boost::optional<std::string> const& rewardModelName, storm::logic::OperatorInformation const& operatorInformation,
572 std::shared_ptr<storm::logic::Formula const> const& subformula) const {
573 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::RewardOperatorFormula(subformula, rewardModelName, operatorInformation));
574}
575
576std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createTimeOperatorFormula(
577 storm::logic::OperatorInformation const& operatorInformation, std::shared_ptr<storm::logic::Formula const> const& subformula) const {
578 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::TimeOperatorFormula(subformula, operatorInformation));
579}
580
581std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createProbabilityOperatorFormula(
582 storm::logic::OperatorInformation const& operatorInformation, std::shared_ptr<storm::logic::Formula const> const& subformula) {
583 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::ProbabilityOperatorFormula(subformula, operatorInformation));
584}
585
586std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createBinaryBooleanStateFormula(
587 std::shared_ptr<storm::logic::Formula const> const& leftSubformula, std::shared_ptr<storm::logic::Formula const> const& rightSubformula,
589 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::BinaryBooleanStateFormula(operatorType, leftSubformula, rightSubformula));
590}
591
592std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createUnaryBooleanStateFormula(
593 std::shared_ptr<storm::logic::Formula const> const& subformula, boost::optional<storm::logic::UnaryBooleanStateFormula::OperatorType> const& operatorType) {
594 if (operatorType) {
595 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::UnaryBooleanStateFormula(operatorType.get(), subformula));
596 } else {
597 return subformula;
598 }
599}
600
601std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createBinaryBooleanPathFormula(
602 std::shared_ptr<storm::logic::Formula const> const& leftSubformula, std::shared_ptr<storm::logic::Formula const> const& rightSubformula,
604 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::BinaryBooleanPathFormula(operatorType, leftSubformula, rightSubformula));
605}
606
607std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createUnaryBooleanPathFormula(
608 std::shared_ptr<storm::logic::Formula const> const& subformula, boost::optional<storm::logic::UnaryBooleanPathFormula::OperatorType> const& operatorType) {
609 if (operatorType) {
610 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::UnaryBooleanPathFormula(operatorType.get(), subformula));
611 } else {
612 return subformula;
613 }
614}
615
616std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createBinaryBooleanStateOrPathFormula(
617 std::shared_ptr<storm::logic::Formula const> const& leftSubformula, std::shared_ptr<storm::logic::Formula const> const& rightSubformula,
619 if (leftSubformula->isStateFormula() && rightSubformula->isStateFormula()) {
620 return createBinaryBooleanStateFormula(leftSubformula, rightSubformula, operatorType);
621 } else if (leftSubformula->isPathFormula() || rightSubformula->isPathFormula()) {
622 return createBinaryBooleanPathFormula(leftSubformula, rightSubformula, operatorType);
623 }
624 STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "Subformulas have unexpected type.");
625}
626
627std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createUnaryBooleanStateOrPathFormula(
628 std::shared_ptr<storm::logic::Formula const> const& subformula, boost::optional<storm::logic::UnaryBooleanOperatorType> const& operatorType) {
629 if (subformula->isStateFormula()) {
630 return createUnaryBooleanStateFormula(subformula, operatorType);
631 } else if (subformula->isPathFormula()) {
632 return createUnaryBooleanPathFormula(subformula, operatorType);
633 }
634 STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "Subformulas have unexpected type.");
635}
636
637bool FormulaParserGrammar::isValidMultiBoundedPathFormulaOperand(std::shared_ptr<storm::logic::Formula const> const& operand) {
638 if (operand->isBoundedUntilFormula()) {
639 if (!operand->asBoundedUntilFormula().isMultiDimensional()) {
640 return true;
641 }
642 STORM_LOG_ERROR("Composition of multidimensional bounded until formula must consist of single dimension subformulas. Got '" << *operand
643 << "' instead.");
644 }
645 return false;
646}
647
648std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createMultiBoundedPathFormula(
649 std::vector<std::shared_ptr<storm::logic::Formula const>> const& subformulas) {
650 std::vector<std::shared_ptr<storm::logic::Formula const>> leftSubformulas, rightSubformulas;
651 std::vector<boost::optional<storm::logic::TimeBound>> lowerBounds, upperBounds;
652 std::vector<storm::logic::TimeBoundReference> timeBoundReferences;
653 for (auto const& subformula : subformulas) {
654 STORM_LOG_THROW(subformula->isBoundedUntilFormula(), storm::exceptions::WrongFormatException,
655 "multi-path formulas require bounded until (or eventually) subformulae. Got '" << *subformula << "' instead.");
656 auto const& f = subformula->asBoundedUntilFormula();
657 STORM_LOG_THROW(!f.isMultiDimensional(), storm::exceptions::WrongFormatException,
658 "Composition of multidimensional bounded until formula must consist of single dimension subformulas. Got '" << f << "' instead.");
659 leftSubformulas.push_back(f.getLeftSubformula().asSharedPointer());
660 rightSubformulas.push_back(f.getRightSubformula().asSharedPointer());
661 if (f.hasLowerBound()) {
662 lowerBounds.emplace_back(storm::logic::TimeBound(f.isLowerBoundStrict(), f.getLowerBound()));
663 } else {
664 lowerBounds.emplace_back();
665 }
666 if (f.hasUpperBound()) {
667 upperBounds.emplace_back(storm::logic::TimeBound(f.isUpperBoundStrict(), f.getUpperBound()));
668 } else {
669 upperBounds.emplace_back();
670 }
671 timeBoundReferences.push_back(f.getTimeBoundReference());
672 }
673 return std::shared_ptr<storm::logic::Formula const>(
674 new storm::logic::BoundedUntilFormula(leftSubformulas, rightSubformulas, lowerBounds, upperBounds, timeBoundReferences));
675}
676
677std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createMultiOperatorFormula(
678 std::vector<std::shared_ptr<storm::logic::Formula const>> const& subformulas) {
679 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::MultiObjectiveFormula(subformulas));
680}
681
682storm::expressions::Variable FormulaParserGrammar::createQuantileBoundVariables(boost::optional<storm::solver::OptimizationDirection> const& dir,
683 std::string const& variableName) {
684 STORM_LOG_ASSERT(manager, "Mutable expression manager required to define quantile bound variable.");
686 if (manager->hasVariable(variableName)) {
687 var = manager->getVariable(variableName);
688 STORM_LOG_THROW(quantileFormulaVariables.count(var) > 0, storm::exceptions::WrongFormatException,
689 "Invalid quantile variable name '" << variableName << "' in quantile formula: variable already exists.");
690 } else {
691 var = manager->declareRationalVariable(variableName);
692 quantileFormulaVariables.insert(var);
693 }
694 STORM_LOG_WARN_COND(!dir.is_initialized(), "Optimization direction '"
695 << dir.get() << "' for quantile variable " << variableName
696 << " is ignored. This information will be derived from the subformula of the quantile.");
697 addIdentifierExpression(variableName, var);
698 return var;
699}
700
701std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createQuantileFormula(std::vector<storm::expressions::Variable> const& boundVariables,
702 std::shared_ptr<storm::logic::Formula const> const& subformula) {
703 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::QuantileFormula(boundVariables, subformula));
704}
705
706std::set<storm::expressions::Variable> FormulaParserGrammar::getUndefinedConstants(std::shared_ptr<storm::logic::Formula const> const& formula) const {
707 std::set<storm::expressions::Variable> result;
708 std::set<storm::expressions::Variable> usedVariables = formula->getUsedVariables();
709 std::set_intersection(usedVariables.begin(), usedVariables.end(), undefinedConstants.begin(), undefinedConstants.end(),
710 std::inserter(result, result.begin()));
711 return result;
712}
713
714storm::jani::Property FormulaParserGrammar::createProperty(boost::optional<std::string> const& propertyName, storm::modelchecker::FilterType const& filterType,
715 std::shared_ptr<storm::logic::Formula const> const& formula,
716 std::shared_ptr<storm::logic::Formula const> const& states) {
717 storm::jani::FilterExpression filterExpression(formula, filterType, states);
718
719 ++propertyCount;
720 if (propertyName) {
721 return storm::jani::Property(propertyName.get(), filterExpression, this->getUndefinedConstants(formula));
722 } else {
723 return storm::jani::Property(std::to_string(propertyCount - 1), filterExpression, this->getUndefinedConstants(formula));
724 }
725}
726
727storm::jani::Property FormulaParserGrammar::createPropertyWithDefaultFilterTypeAndStates(boost::optional<std::string> const& propertyName,
728 std::shared_ptr<storm::logic::Formula const> const& formula) {
729 ++propertyCount;
730 if (propertyName) {
731 return storm::jani::Property(propertyName.get(), formula, this->getUndefinedConstants(formula));
732 } else {
733 return storm::jani::Property(std::to_string(propertyCount), formula, this->getUndefinedConstants(formula));
734 }
735}
736
737storm::logic::PlayerCoalition FormulaParserGrammar::createPlayerCoalition(
738 std::vector<std::variant<std::string, storm::storage::PlayerIndex>> const& playerIds) const {
739 return storm::logic::PlayerCoalition(playerIds);
740}
741
742std::shared_ptr<storm::logic::Formula const> FormulaParserGrammar::createGameFormula(storm::logic::PlayerCoalition const& coalition,
743 std::shared_ptr<storm::logic::Formula const> const& subformula) const {
744 return std::shared_ptr<storm::logic::Formula const>(new storm::logic::GameFormula(coalition, subformula));
745}
746
747bool FormulaParserGrammar::isBooleanReturnType(std::shared_ptr<storm::logic::Formula const> const& formula, bool raiseErrorMessage) {
748 if (formula->hasQualitativeResult()) {
749 return true;
750 }
751 STORM_LOG_ERROR_COND(!raiseErrorMessage, "Formula " << *formula << " does not have a Boolean return type.");
752 return false;
753}
754
755bool FormulaParserGrammar::raiseAmbiguousNonAssociativeOperatorError(std::shared_ptr<storm::logic::Formula const> const& formula, std::string const& op) {
756 STORM_LOG_ERROR("Ambiguous use of non-associative operator '" << op << "' in formula '" << *formula << " U ... '");
757 return true;
758}
759
760} // namespace parser
761} // namespace storm
bool evaluateAsBool(Valuation const *valuation=nullptr) const
Evaluates the expression under the valuation of variables given by the valuation and returns the resu...
bool hasBooleanType() const
Retrieves whether the expression has a boolean return type.
bool isLiteral() const
Retrieves whether the expression is a literal.
std::string toString() const
Converts the expression into a string.
void addAPMapping(const std::string &ap, const std::shared_ptr< Formula const > &formula)
void setIdentifierMapping(qi::symbols< char, storm::expressions::Expression > const *identifiers_)
Sets an identifier mapping that is used to determine valid variables in the expression.
qi::symbols< char, storm::expressions::Expression > const & getIdentifiers() const
FormulaParserGrammar(std::shared_ptr< storm::expressions::ExpressionManager const > const &manager)
void addIdentifierExpression(std::string const &identifier, storm::expressions::Expression const &expression)
Adds an identifier and the expression it is supposed to be replaced with.
#define STORM_LOG_ERROR(message)
Definition logging.h:26
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_WARN_COND(cond, message)
Definition macros.h:38
#define STORM_LOG_ERROR_COND(cond, message)
Definition macros.h:52
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
LabParser.cpp.