14namespace abstraction {
18template<storm::dd::DdType DdType>
20 std::unique_ptr<storm::solver::SmtSolver>&& smtSolver)
21 : abstractionInformation(abstractionInformation),
22 equivalenceChecker(
std::move(smtSolver)),
23 locationVariables(abstractionInformation.getLocationExpressionVariables()),
24 abstractedVariables(abstractionInformation.getAbstractedVariables()) {
28template<storm::dd::DdType DdType>
30 return boost::any_cast<storm::dd::Bdd<DdType>>(expression.
accept(*
this, boost::none));
33template<storm::dd::DdType DdType>
36 "Expressions of this kind are currently not supported by the abstraction expression translator.");
39template<storm::dd::DdType DdType>
43 std::set<storm::expressions::Variable> variablesInExpression;
46 std::set<storm::expressions::Variable> tmp;
47 std::set_intersection(variablesInExpression.begin(), variablesInExpression.end(), locationVariables.begin(), locationVariables.end(),
48 std::inserter(tmp, tmp.begin()));
49 bool hasLocationVariables = !tmp.empty();
52 std::set_intersection(variablesInExpression.begin(), variablesInExpression.end(), abstractedVariables.begin(), abstractedVariables.end(),
53 std::inserter(tmp, tmp.begin()));
54 bool hasAbstractedVariables = !tmp.empty();
56 STORM_LOG_THROW(hasLocationVariables || hasAbstractedVariables, storm::exceptions::NotSupportedException,
57 "Expressions without variables are currently not supported by the abstraction expression translator.");
59 if (hasAbstractedVariables && !hasLocationVariables) {
60 for (uint64_t predicateIndex = 0; predicateIndex < abstractionInformation.get().getNumberOfPredicates(); ++predicateIndex) {
61 if (equivalenceChecker.areEquivalent(abstractionInformation.get().getPredicateByIndex(predicateIndex), expression.
toExpression())) {
62 return abstractionInformation.get().encodePredicateAsSource(predicateIndex);
63 }
else if (equivalenceChecker.areEquivalent(abstractionInformation.get().getPredicateByIndex(predicateIndex), !expression.
toExpression())) {
64 return !abstractionInformation.get().encodePredicateAsSource(predicateIndex);
74 case BinaryBooleanFunctionExpression::OperatorType::And:
76 case BinaryBooleanFunctionExpression::OperatorType::Or:
78 case BinaryBooleanFunctionExpression::OperatorType::Xor:
80 case BinaryBooleanFunctionExpression::OperatorType::Implies:
81 return !left || right;
82 case BinaryBooleanFunctionExpression::OperatorType::Iff:
83 return (left && right) || (!left && !right);
88template<storm::dd::DdType DdType>
91 "Expressions of this kind are currently not supported by the abstraction expression translator.");
94template<storm::dd::DdType DdType>
98 std::set<storm::expressions::Variable> variablesInExpression;
101 std::set<storm::expressions::Variable> tmp;
102 std::set_intersection(variablesInExpression.begin(), variablesInExpression.end(), locationVariables.begin(), locationVariables.end(),
103 std::inserter(tmp, tmp.begin()));
104 bool hasLocationVariables = !tmp.empty();
107 std::set_intersection(variablesInExpression.begin(), variablesInExpression.end(), abstractedVariables.begin(), abstractedVariables.end(),
108 std::inserter(tmp, tmp.begin()));
109 bool hasAbstractedVariables = !tmp.empty();
111 STORM_LOG_THROW(hasLocationVariables || hasAbstractedVariables, storm::exceptions::NotSupportedException,
112 "Expressions without variables are currently not supported by the abstraction expression translator.");
113 STORM_LOG_THROW(!hasLocationVariables || !hasAbstractedVariables, storm::exceptions::NotSupportedException,
114 "Expressions with two types (location variables and abstracted variables) of variables are currently not supported by the abstraction "
115 "expression translator.");
117 if (hasLocationVariables) {
122 case RelationType::Equal:
123 return left.
equals(right);
124 case RelationType::NotEqual:
126 case RelationType::Less:
127 return left.
less(right);
128 case RelationType::LessOrEqual:
130 case RelationType::Greater:
132 case RelationType::GreaterOrEqual:
136 for (uint64_t predicateIndex = 0; predicateIndex < abstractionInformation.get().getNumberOfPredicates(); ++predicateIndex) {
137 if (equivalenceChecker.areEquivalent(abstractionInformation.get().getPredicateByIndex(predicateIndex), expression.
toExpression())) {
138 return abstractionInformation.get().encodePredicateAsSource(predicateIndex);
139 }
else if (equivalenceChecker.areEquivalent(abstractionInformation.get().getPredicateByIndex(predicateIndex), !expression.
toExpression())) {
140 return !abstractionInformation.get().encodePredicateAsSource(predicateIndex);
147 "Expressions of this kind are currently not supported by the abstraction expression translator (" << expression <<
").");
152template<storm::dd::DdType DdType>
154 if (abstractedVariables.find(expression.
getVariable()) != abstractedVariables.end()) {
155 for (uint64_t predicateIndex = 0; predicateIndex < abstractionInformation.get().getNumberOfPredicates(); ++predicateIndex) {
156 if (equivalenceChecker.areEquivalent(abstractionInformation.get().getPredicateByIndex(predicateIndex), expression.
toExpression())) {
157 return abstractionInformation.get().encodePredicateAsSource(predicateIndex);
158 }
else if (equivalenceChecker.areEquivalent(abstractionInformation.get().getPredicateByIndex(predicateIndex), !expression.
toExpression())) {
159 return !abstractionInformation.get().encodePredicateAsSource(predicateIndex);
164 "Expressions of this kind are currently not supported by the abstraction expression translator.");
166 return abstractionInformation.get().getDdManager().template getIdentity<double>(
167 abstractionInformation.get().getDdLocationMetaVariable(expression.
getVariable(),
true));
171template<storm::dd::DdType DdType>
175 std::set<storm::expressions::Variable> variablesInExpression;
178 std::set<storm::expressions::Variable> tmp;
179 std::set_intersection(variablesInExpression.begin(), variablesInExpression.end(), locationVariables.begin(), locationVariables.end(),
180 std::inserter(tmp, tmp.begin()));
181 bool hasLocationVariables = !tmp.empty();
184 std::set_intersection(variablesInExpression.begin(), variablesInExpression.end(), abstractedVariables.begin(), abstractedVariables.end(),
185 std::inserter(tmp, tmp.begin()));
186 bool hasAbstractedVariables = !tmp.empty();
188 STORM_LOG_THROW(hasLocationVariables || hasAbstractedVariables, storm::exceptions::NotSupportedException,
189 "Expressions without variables are currently not supported by the abstraction expression translator.");
191 if (hasAbstractedVariables && !hasLocationVariables) {
192 for (uint64_t predicateIndex = 0; predicateIndex < abstractionInformation.get().getNumberOfPredicates(); ++predicateIndex) {
193 if (equivalenceChecker.areEquivalent(abstractionInformation.get().getPredicateByIndex(predicateIndex), expression.
toExpression())) {
194 return abstractionInformation.get().encodePredicateAsSource(predicateIndex);
195 }
else if (equivalenceChecker.areEquivalent(abstractionInformation.get().getPredicateByIndex(predicateIndex), !expression.
toExpression())) {
196 return !abstractionInformation.get().encodePredicateAsSource(predicateIndex);
205 case UnaryBooleanFunctionExpression::OperatorType::Not:
211template<storm::dd::DdType DdType>
214 "Expressions of this kind are currently not supported by the abstraction expression translator.");
217template<storm::dd::DdType DdType>
219 if (expression.
isTrue()) {
220 return abstractionInformation.get().getDdManager().getBddOne();
222 return abstractionInformation.get().getDdManager().getBddZero();
226template<storm::dd::DdType DdType>
228 return abstractionInformation.get().getDdManager().template getConstant<double>(expression.
getValue());
231template<storm::dd::DdType DdType>
234 "Expressions of this kind are currently not supported by the abstraction expression translator.");
Bdd< LibraryType > equals(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one that have identical function values.
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...
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...
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...
Bdd< LibraryType > notEquals(Add< LibraryType, ValueType > const &other) const
Retrieves the function that maps all evaluations to one that have distinct function values.
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...
Bdd< LibraryType > exclusiveOr(Bdd< LibraryType > const &other) const
Performs a logical exclusive-or of the current and the given BDD.
Expression toExpression() const
Converts the base expression to a proper expression.
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.
virtual void gatherVariables(std::set< storm::expressions::Variable > &variables) const override
Retrieves the set of all variables that appear in the expression.
RelationType getRelationType() const
Retrieves the relation associated with the expression.
virtual bool isTrue() const override
Checks if the expression is equal to the boolean literal true.
void addConstraints(std::vector< storm::expressions::Expression > const &constraints)
boost::any accept(ExpressionVisitor &visitor, boost::any const &data) const
Accepts the given visitor.
int_fast64_t getValue() const
Retrieves the value of the integer 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.
virtual void gatherVariables(std::set< storm::expressions::Variable > &variables) const override
Retrieves the set of all variables that appear in the expression.
Variable const & getVariable() const
Retrieves the variable associated with this expression.
ExpressionTranslator(AbstractionInformation< DdType > &abstractionInformation, std::unique_ptr< storm::solver::SmtSolver > &&smtSolver)
storm::dd::Bdd< DdType > translate(storm::expressions::Expression const &expression)
virtual boost::any visit(storm::expressions::IfThenElseExpression const &expression, boost::any const &data)
#define STORM_LOG_THROW(cond, exception, message)