Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
AddExpressionAdapter.cpp
Go to the documentation of this file.
2
3#include "storm-config.h"
12
13namespace storm {
14namespace adapters {
15
16template<storm::dd::DdType Type, typename ValueType>
18 std::shared_ptr<storm::dd::DdManager<Type>> ddManager,
19 std::shared_ptr<std::map<storm::expressions::Variable, storm::expressions::Variable>> const& variableMapping)
20 : ddManager(ddManager), variableMapping(variableMapping) {
21 // Intentionally left empty.
22}
23
24template<storm::dd::DdType Type, typename ValueType>
26 if (expression.hasBooleanType()) {
27 return boost::any_cast<storm::dd::Bdd<Type>>(expression.accept(*this, boost::none)).template toAdd<ValueType>();
28 } else {
29 return boost::any_cast<storm::dd::Add<Type, ValueType>>(expression.accept(*this, boost::none));
30 }
31}
32
33template<storm::dd::DdType Type, typename ValueType>
35 STORM_LOG_THROW(expression.hasBooleanType(), storm::exceptions::InvalidArgumentException, "Expected expression of boolean type.");
36 return boost::any_cast<storm::dd::Bdd<Type>>(expression.accept(*this, boost::none));
37}
38
39template<storm::dd::DdType Type, typename ValueType>
41 valueMapping[variable] = value;
42}
43
44template<storm::dd::DdType Type, typename ValueType>
46 if (expression.hasBooleanType()) {
47 storm::dd::Bdd<Type> elseDd = boost::any_cast<storm::dd::Bdd<Type>>(expression.getElseExpression()->accept(*this, data));
48 storm::dd::Bdd<Type> thenDd = boost::any_cast<storm::dd::Bdd<Type>>(expression.getThenExpression()->accept(*this, data));
49 storm::dd::Bdd<Type> conditionDd = boost::any_cast<storm::dd::Bdd<Type>>(expression.getCondition()->accept(*this, data));
50 return conditionDd.ite(thenDd, elseDd);
51 } else {
52 storm::dd::Add<Type, ValueType> elseDd = boost::any_cast<storm::dd::Add<Type, ValueType>>(expression.getElseExpression()->accept(*this, data));
53 storm::dd::Add<Type, ValueType> thenDd = boost::any_cast<storm::dd::Add<Type, ValueType>>(expression.getThenExpression()->accept(*this, data));
54 storm::dd::Bdd<Type> conditionDd = boost::any_cast<storm::dd::Bdd<Type>>(expression.getCondition()->accept(*this, data));
55 return conditionDd.ite(thenDd, elseDd);
56 }
57}
58
59template<storm::dd::DdType Type, typename ValueType>
61 storm::dd::Bdd<Type> leftResult = boost::any_cast<storm::dd::Bdd<Type>>(expression.getFirstOperand()->accept(*this, data));
62 storm::dd::Bdd<Type> rightResult = boost::any_cast<storm::dd::Bdd<Type>>(expression.getSecondOperand()->accept(*this, data));
63
65 switch (expression.getOperatorType()) {
67 result = (leftResult && rightResult);
68 break;
70 result = (leftResult || rightResult);
71 break;
73 result = (leftResult.iff(rightResult));
74 break;
76 result = (!leftResult || rightResult);
77 break;
79 result = (leftResult.exclusiveOr(rightResult));
80 break;
81 }
82
83 return result;
84}
85
86template<storm::dd::DdType Type, typename ValueType>
88 storm::dd::Add<Type, ValueType> leftResult = boost::any_cast<storm::dd::Add<Type, ValueType>>(expression.getFirstOperand()->accept(*this, data));
89 storm::dd::Add<Type, ValueType> rightResult = boost::any_cast<storm::dd::Add<Type, ValueType>>(expression.getSecondOperand()->accept(*this, data));
90
92 switch (expression.getOperatorType()) {
94 result = leftResult + rightResult;
95 break;
97 result = leftResult - rightResult;
98 break;
100 result = leftResult * rightResult;
101 break;
103 result = leftResult / rightResult;
104 break;
106 result = leftResult.maximum(rightResult);
107 break;
109 result = leftResult.minimum(rightResult);
110 break;
112 result = leftResult.pow(rightResult);
113 break;
115 result = leftResult.mod(rightResult);
116 break;
118 result = leftResult.logxy(rightResult);
119 break;
120 default:
121 STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Cannot translate expression containing power operator.");
122 }
123
124 return result;
125}
126
127template<storm::dd::DdType Type, typename ValueType>
129 storm::dd::Add<Type, ValueType> leftResult = boost::any_cast<storm::dd::Add<Type, ValueType>>(expression.getFirstOperand()->accept(*this, data));
130 storm::dd::Add<Type, ValueType> rightResult = boost::any_cast<storm::dd::Add<Type, ValueType>>(expression.getSecondOperand()->accept(*this, data));
131
133 switch (expression.getRelationType()) {
135 result = leftResult.equals(rightResult);
136 break;
138 result = leftResult.notEquals(rightResult);
139 break;
141 result = leftResult.less(rightResult);
142 break;
144 result = leftResult.lessOrEqual(rightResult);
145 break;
147 result = leftResult.greater(rightResult);
148 break;
150 result = leftResult.greaterOrEqual(rightResult);
151 break;
152 }
153
154 return result;
155}
156
157template<storm::dd::DdType Type, typename ValueType>
159 auto valueIt = valueMapping.find(expression.getVariable());
160 if (valueIt != valueMapping.end()) {
161 return ddManager->getConstant(valueIt->second);
162 } else {
163 auto const& variablePair = variableMapping->find(expression.getVariable());
164 STORM_LOG_THROW(variablePair != variableMapping->end(), storm::exceptions::InvalidArgumentException,
165 "Cannot translate the given expression, because it contains the variable '" << expression.getVariableName()
166 << "' for which no DD counterpart is known.");
167 if (expression.hasBooleanType()) {
168 return ddManager->template getIdentity<ValueType>(variablePair->second).toBdd();
169 } else {
170 return ddManager->template getIdentity<ValueType>(variablePair->second);
171 }
172 }
173}
174
175template<storm::dd::DdType Type, typename ValueType>
177 storm::dd::Bdd<Type> result = boost::any_cast<storm::dd::Bdd<Type>>(expression.getOperand()->accept(*this, data));
178
179 switch (expression.getOperatorType()) {
181 result = !result;
182 break;
183 }
184
185 return result;
186}
187
188template<storm::dd::DdType Type, typename ValueType>
190 storm::dd::Add<Type, ValueType> result = boost::any_cast<storm::dd::Add<Type, ValueType>>(expression.getOperand()->accept(*this, data));
191
192 switch (expression.getOperatorType()) {
194 result = -result;
195 break;
197 result = result.floor();
198 break;
200 result = result.ceil();
201 break;
202 default:
203 STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Cannot translate expression containing floor/ceil operator.");
204 }
205
206 return result;
207}
208
209template<storm::dd::DdType Type, typename ValueType>
211 return expression.getValue() ? ddManager->getBddOne() : ddManager->getBddZero();
212}
213
214template<storm::dd::DdType Type, typename ValueType>
216 return ddManager->getConstant(storm::utility::convertNumber<ValueType>(expression.getValue()));
217}
218
219template<storm::dd::DdType Type, typename ValueType>
221 return ddManager->getConstant(storm::utility::convertNumber<ValueType>(expression.getValue()));
222}
223
224// Explicitly instantiate the symbolic expression adapter
229} // namespace adapters
230} // 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:122
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:92
Add< LibraryType, ValueType > floor() const
Retrieves the function that floors all values in the current ADD.
Definition Add.cpp:137
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:107
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:132
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:164
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:112
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:169
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:117
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:127
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:97
Add< LibraryType, ValueType > ceil() const
Retrieves the function that ceils all values in the current ADD.
Definition Add.cpp:142
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:102
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:107
Bdd< LibraryType > iff(Bdd< LibraryType > const &other) const
Performs a logical iff of the current and the given BDD.
Definition Bdd.cpp:146
Bdd< LibraryType > exclusiveOr(Bdd< LibraryType > const &other) const
Performs a logical exclusive-or of the current and the given BDD.
Definition Bdd.cpp:151
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