Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
AddExpressionAdapter.cpp
Go to the documentation of this file.
2
6
10
11#include "storm-config.h"
13
15
16namespace storm {
17namespace adapters {
18
19template<storm::dd::DdType Type, typename ValueType>
21 std::shared_ptr<storm::dd::DdManager<Type>> ddManager,
22 std::shared_ptr<std::map<storm::expressions::Variable, storm::expressions::Variable>> const& variableMapping)
23 : ddManager(ddManager), variableMapping(variableMapping) {
24 // Intentionally left empty.
25}
26
27template<storm::dd::DdType Type, typename ValueType>
29 if (expression.hasBooleanType()) {
30 return boost::any_cast<storm::dd::Bdd<Type>>(expression.accept(*this, boost::none)).template toAdd<ValueType>();
31 } else {
32 return boost::any_cast<storm::dd::Add<Type, ValueType>>(expression.accept(*this, boost::none));
33 }
34}
35
36template<storm::dd::DdType Type, typename ValueType>
38 STORM_LOG_THROW(expression.hasBooleanType(), storm::exceptions::InvalidArgumentException, "Expected expression of boolean type.");
39 return boost::any_cast<storm::dd::Bdd<Type>>(expression.accept(*this, boost::none));
40}
41
42template<storm::dd::DdType Type, typename ValueType>
44 valueMapping[variable] = value;
45}
46
47template<storm::dd::DdType Type, typename ValueType>
49 if (expression.hasBooleanType()) {
50 storm::dd::Bdd<Type> elseDd = boost::any_cast<storm::dd::Bdd<Type>>(expression.getElseExpression()->accept(*this, data));
51 storm::dd::Bdd<Type> thenDd = boost::any_cast<storm::dd::Bdd<Type>>(expression.getThenExpression()->accept(*this, data));
52 storm::dd::Bdd<Type> conditionDd = boost::any_cast<storm::dd::Bdd<Type>>(expression.getCondition()->accept(*this, data));
53 return conditionDd.ite(thenDd, elseDd);
54 } else {
55 storm::dd::Add<Type, ValueType> elseDd = boost::any_cast<storm::dd::Add<Type, ValueType>>(expression.getElseExpression()->accept(*this, data));
56 storm::dd::Add<Type, ValueType> thenDd = boost::any_cast<storm::dd::Add<Type, ValueType>>(expression.getThenExpression()->accept(*this, data));
57 storm::dd::Bdd<Type> conditionDd = boost::any_cast<storm::dd::Bdd<Type>>(expression.getCondition()->accept(*this, data));
58 return conditionDd.ite(thenDd, elseDd);
59 }
60}
61
62template<storm::dd::DdType Type, typename ValueType>
64 storm::dd::Bdd<Type> leftResult = boost::any_cast<storm::dd::Bdd<Type>>(expression.getFirstOperand()->accept(*this, data));
65 storm::dd::Bdd<Type> rightResult = boost::any_cast<storm::dd::Bdd<Type>>(expression.getSecondOperand()->accept(*this, data));
66
68 switch (expression.getOperatorType()) {
70 result = (leftResult && rightResult);
71 break;
73 result = (leftResult || rightResult);
74 break;
76 result = (leftResult.iff(rightResult));
77 break;
79 result = (!leftResult || rightResult);
80 break;
82 result = (leftResult.exclusiveOr(rightResult));
83 break;
84 }
85
86 return result;
87}
88
89template<storm::dd::DdType Type, typename ValueType>
91 storm::dd::Add<Type, ValueType> leftResult = boost::any_cast<storm::dd::Add<Type, ValueType>>(expression.getFirstOperand()->accept(*this, data));
92 storm::dd::Add<Type, ValueType> rightResult = boost::any_cast<storm::dd::Add<Type, ValueType>>(expression.getSecondOperand()->accept(*this, data));
93
95 switch (expression.getOperatorType()) {
97 result = leftResult + rightResult;
98 break;
100 result = leftResult - rightResult;
101 break;
103 result = leftResult * rightResult;
104 break;
106 result = leftResult / rightResult;
107 break;
109 result = leftResult.maximum(rightResult);
110 break;
112 result = leftResult.minimum(rightResult);
113 break;
115 result = leftResult.pow(rightResult);
116 break;
118 result = leftResult.mod(rightResult);
119 break;
121 result = leftResult.logxy(rightResult);
122 break;
123 default:
124 STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Cannot translate expression containing power operator.");
125 }
126
127 return result;
128}
129
130template<storm::dd::DdType Type, typename ValueType>
132 storm::dd::Add<Type, ValueType> leftResult = boost::any_cast<storm::dd::Add<Type, ValueType>>(expression.getFirstOperand()->accept(*this, data));
133 storm::dd::Add<Type, ValueType> rightResult = boost::any_cast<storm::dd::Add<Type, ValueType>>(expression.getSecondOperand()->accept(*this, data));
134
136 switch (expression.getRelationType()) {
138 result = leftResult.equals(rightResult);
139 break;
141 result = leftResult.notEquals(rightResult);
142 break;
144 result = leftResult.less(rightResult);
145 break;
147 result = leftResult.lessOrEqual(rightResult);
148 break;
150 result = leftResult.greater(rightResult);
151 break;
153 result = leftResult.greaterOrEqual(rightResult);
154 break;
155 }
156
157 return result;
158}
159
160template<storm::dd::DdType Type, typename ValueType>
162 auto valueIt = valueMapping.find(expression.getVariable());
163 if (valueIt != valueMapping.end()) {
164 return ddManager->getConstant(valueIt->second);
165 } else {
166 auto const& variablePair = variableMapping->find(expression.getVariable());
167 STORM_LOG_THROW(variablePair != variableMapping->end(), storm::exceptions::InvalidArgumentException,
168 "Cannot translate the given expression, because it contains the variable '" << expression.getVariableName()
169 << "' for which no DD counterpart is known.");
170 if (expression.hasBooleanType()) {
171 return ddManager->template getIdentity<ValueType>(variablePair->second).toBdd();
172 } else {
173 return ddManager->template getIdentity<ValueType>(variablePair->second);
174 }
175 }
176}
177
178template<storm::dd::DdType Type, typename ValueType>
180 storm::dd::Bdd<Type> result = boost::any_cast<storm::dd::Bdd<Type>>(expression.getOperand()->accept(*this, data));
181
182 switch (expression.getOperatorType()) {
184 result = !result;
185 break;
186 }
187
188 return result;
189}
190
191template<storm::dd::DdType Type, typename ValueType>
193 storm::dd::Add<Type, ValueType> result = boost::any_cast<storm::dd::Add<Type, ValueType>>(expression.getOperand()->accept(*this, data));
194
195 switch (expression.getOperatorType()) {
197 result = -result;
198 break;
200 result = result.floor();
201 break;
203 result = result.ceil();
204 break;
205 default:
206 STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Cannot translate expression containing floor/ceil operator.");
207 }
208
209 return result;
210}
211
212template<storm::dd::DdType Type, typename ValueType>
214 return expression.getValue() ? ddManager->getBddOne() : ddManager->getBddZero();
215}
216
217template<storm::dd::DdType Type, typename ValueType>
219 return ddManager->getConstant(storm::utility::convertNumber<ValueType>(expression.getValue()));
220}
221
222template<storm::dd::DdType Type, typename ValueType>
224 return ddManager->getConstant(storm::utility::convertNumber<ValueType>(expression.getValue()));
225}
226
227// Explicitly instantiate the symbolic expression adapter
230
231#ifdef STORM_HAVE_CARL
234#endif
235} // namespace adapters
236} // namespace storm
storm::dd::Add< Type, ValueType > translateExpression(storm::expressions::Expression const &expression)
storm::dd::Bdd< Type > translateBooleanExpression(storm::expressions::Expression const &expression)
virtual boost::any visit(storm::expressions::IfThenElseExpression const &expression, boost::any const &data) override
void setValue(storm::expressions::Variable const &variable, ValueType const &value)
AddExpressionAdapter(std::shared_ptr< storm::dd::DdManager< Type > > ddManager, std::shared_ptr< std::map< storm::expressions::Variable, storm::expressions::Variable > > const &variableMapping)
Add< LibraryType, ValueType > pow(Add< LibraryType, ValueType > const &other) const
Retrieves the function that represents the current ADD to the power of the given ADD.
Definition Add.cpp:126
Bdd< LibraryType > equals(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one that have identical function values.
Definition Add.cpp:96
Add< LibraryType, ValueType > floor() const
Retrieves the function that floors all values in the current ADD.
Definition Add.cpp:141
Bdd< LibraryType > lessOrEqual(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are les...
Definition Add.cpp:111
Add< LibraryType, ValueType > logxy(Add< LibraryType, ValueType > const &other) const
Retrieves the function that represents the logarithm of the current ADD to the bases given by the sec...
Definition Add.cpp:136
Add< LibraryType, ValueType > minimum(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to the minimum of the function values of the two ADD...
Definition Add.cpp:168
Bdd< LibraryType > greater(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are gre...
Definition Add.cpp:116
Add< LibraryType, ValueType > maximum(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to the maximum of the function values of the two ADD...
Definition Add.cpp:173
Bdd< LibraryType > greaterOrEqual(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are gre...
Definition Add.cpp:121
Add< LibraryType, ValueType > mod(Add< LibraryType, ValueType > const &other) const
Retrieves the function that represents the current ADD modulo the given ADD.
Definition Add.cpp:131
Bdd< LibraryType > notEquals(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one that have distinct function values.
Definition Add.cpp:101
Add< LibraryType, ValueType > ceil() const
Retrieves the function that ceils all values in the current ADD.
Definition Add.cpp:146
Bdd< LibraryType > less(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one whose function value in the first ADD are les...
Definition Add.cpp:106
Bdd< LibraryType > ite(Bdd< LibraryType > const &thenBdd, Bdd< LibraryType > const &elseBdd) const
Performs an if-then-else with the given operands, i.e.
Definition Bdd.cpp:113
Bdd< LibraryType > iff(Bdd< LibraryType > const &other) const
Performs a logical iff of the current and the given BDD.
Definition Bdd.cpp:152
Bdd< LibraryType > exclusiveOr(Bdd< LibraryType > const &other) const
Performs a logical exclusive-or of the current and the given BDD.
Definition Bdd.cpp:157
bool hasBooleanType() const
Retrieves whether the expression has a boolean type.
OperatorType getOperatorType() const
Retrieves the operator associated with the expression.
std::shared_ptr< BaseExpression const > const & getSecondOperand() const
Retrieves the second operand of the expression.
std::shared_ptr< BaseExpression const > const & getFirstOperand() const
Retrieves the first operand of the expression.
OperatorType getOperatorType() const
Retrieves the operator associated with the expression.
RelationType getRelationType() const
Retrieves the relation associated with the expression.
bool getValue() const
Retrieves the value of the boolean literal.
bool hasBooleanType() const
Retrieves whether the expression has a boolean return type.
boost::any accept(ExpressionVisitor &visitor, boost::any const &data) const
Accepts the given visitor.
std::shared_ptr< BaseExpression const > getElseExpression() const
Retrieves the else expression of the if-then-else expression.
std::shared_ptr< BaseExpression const > getCondition() const
Retrieves the condition expression of the if-then-else expression.
std::shared_ptr< BaseExpression const > getThenExpression() const
Retrieves the then expression of the if-then-else expression.
int_fast64_t getValue() const
Retrieves the value of the integer literal.
storm::RationalNumber getValue() const
Retrieves the value of the double literal.
OperatorType getOperatorType() const
Retrieves the operator associated with this expression.
virtual std::shared_ptr< BaseExpression const > getOperand(uint_fast64_t operandIndex) const override
Retrieves the given operand from the expression.
OperatorType getOperatorType() const
Retrieves the operator associated with this expression.
Variable const & getVariable() const
Retrieves the variable associated with this expression.
std::string const & getVariableName() const
Retrieves the name of the variable associated with this expression.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
LabParser.cpp.
Definition cli.cpp:18