Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
RestrictSyntaxVisitor.cpp
Go to the documentation of this file.
1#include <map>
2#include <string>
3#include <unordered_map>
4
9
10namespace storm {
11namespace expressions {
13 // Intentionally left empty.
14}
15
17 return Expression(boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getBaseExpression().accept(*this, boost::none)));
18}
19
20boost::any RestrictSyntaxVisitor::visit(IfThenElseExpression const &expression, boost::any const &data) {
21 std::shared_ptr<BaseExpression const> conditionExpression =
22 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getCondition()->accept(*this, data));
23 std::shared_ptr<BaseExpression const> thenExpression =
24 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getThenExpression()->accept(*this, data));
25 std::shared_ptr<BaseExpression const> elseExpression =
26 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getElseExpression()->accept(*this, data));
27
28 // If the arguments did not change, we simply push the expression itself.
29 if (conditionExpression.get() == expression.getCondition().get() && thenExpression.get() == expression.getThenExpression().get() &&
30 elseExpression.get() == expression.getElseExpression().get()) {
31 return expression.getSharedPointer();
32 } else {
33 return std::const_pointer_cast<BaseExpression const>(std::shared_ptr<BaseExpression>(
34 new IfThenElseExpression(expression.getManager(), expression.getType(), conditionExpression, thenExpression, elseExpression)));
35 }
36}
37
38boost::any RestrictSyntaxVisitor::visit(BinaryBooleanFunctionExpression const &expression, boost::any const &data) {
39 std::shared_ptr<BaseExpression const> firstExpression =
40 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getFirstOperand()->accept(*this, data));
41 std::shared_ptr<BaseExpression const> secondExpression =
42 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getSecondOperand()->accept(*this, data));
43
44 // If the arguments did not change, we simply push the expression itself.
45 if (firstExpression.get() == expression.getFirstOperand().get() && secondExpression.get() == expression.getSecondOperand().get()) {
46 return expression.getSharedPointer();
47 } else {
48 return std::const_pointer_cast<BaseExpression const>(std::shared_ptr<BaseExpression>(new BinaryBooleanFunctionExpression(
49 expression.getManager(), expression.getType(), firstExpression, secondExpression, expression.getOperatorType())));
50 }
51}
52
53boost::any RestrictSyntaxVisitor::visit(BinaryNumericalFunctionExpression const &expression, boost::any const &data) {
54 std::shared_ptr<BaseExpression const> firstExpression =
55 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getFirstOperand()->accept(*this, data));
56 std::shared_ptr<BaseExpression const> secondExpression =
57 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getSecondOperand()->accept(*this, data));
58
59 // If the arguments did not change, we simply push the expression itself.
60 if (firstExpression.get() == expression.getFirstOperand().get() && secondExpression.get() == expression.getSecondOperand().get()) {
61 return expression.getSharedPointer();
62 } else {
63 return std::const_pointer_cast<BaseExpression const>(std::shared_ptr<BaseExpression>(new BinaryNumericalFunctionExpression(
64 expression.getManager(), expression.getType(), firstExpression, secondExpression, expression.getOperatorType())));
65 }
66}
67
68boost::any RestrictSyntaxVisitor::visit(BinaryRelationExpression const &expression, boost::any const &data) {
69 std::shared_ptr<BaseExpression const> firstExpression =
70 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getFirstOperand()->accept(*this, data));
71 std::shared_ptr<BaseExpression const> secondExpression =
72 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getSecondOperand()->accept(*this, data));
73
74 // If the arguments did not change, we simply push the expression itself.
75 if (firstExpression.get() == expression.getFirstOperand().get() && secondExpression.get() == expression.getSecondOperand().get()) {
76 return expression.getSharedPointer();
77 } else {
78 return std::const_pointer_cast<BaseExpression const>(std::shared_ptr<BaseExpression>(
79 new BinaryRelationExpression(expression.getManager(), expression.getType(), firstExpression, secondExpression, expression.getRelationType())));
80 }
81}
82
83boost::any RestrictSyntaxVisitor::visit(VariableExpression const &expression, boost::any const &) {
84 return expression.getSharedPointer();
85}
86
87boost::any RestrictSyntaxVisitor::visit(UnaryBooleanFunctionExpression const &expression, boost::any const &data) {
88 std::shared_ptr<BaseExpression const> operandExpression =
89 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getOperand()->accept(*this, data));
90
91 // If the argument did not change, we simply push the expression itself.
92 if (operandExpression.get() == expression.getOperand().get()) {
93 return expression.getSharedPointer();
94 } else {
95 return std::const_pointer_cast<BaseExpression const>(std::shared_ptr<BaseExpression>(
96 new UnaryBooleanFunctionExpression(expression.getManager(), expression.getType(), operandExpression, expression.getOperatorType())));
97 }
98}
99
100boost::any RestrictSyntaxVisitor::visit(UnaryNumericalFunctionExpression const &expression, boost::any const &data) {
101 std::shared_ptr<BaseExpression const> operandExpression =
102 boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getOperand()->accept(*this, data));
103
104 // If the argument did not change, we simply push the expression itself.
105 if (operandExpression.get() == expression.getOperand().get()) {
106 return expression.getSharedPointer();
107 } else {
108 return std::const_pointer_cast<BaseExpression const>(std::shared_ptr<BaseExpression>(
109 new UnaryNumericalFunctionExpression(expression.getManager(), expression.getType(), operandExpression, expression.getOperatorType())));
110 }
111}
112
113boost::any RestrictSyntaxVisitor::visit(PredicateExpression const &expression, boost::any const &data) {
114 std::vector<Expression> newExpressions;
115 for (uint64_t i = 0; i < expression.getArity(); ++i) {
116 newExpressions.emplace_back(boost::any_cast<std::shared_ptr<BaseExpression const>>(expression.getOperand(i)->accept(*this, data)));
117 }
118 std::vector<Expression> newSumExpressions;
119 for (auto const &expr : newExpressions) {
120 newSumExpressions.push_back(ite(expr, expression.getManager().integer(1), expression.getManager().integer(0)));
121 }
122
125 finalexpr = storm::expressions::sum(newSumExpressions) > expression.getManager().integer(0);
127 finalexpr = storm::expressions::sum(newSumExpressions) <= expression.getManager().integer(1);
129 finalexpr = storm::expressions::sum(newSumExpressions) == expression.getManager().integer(1);
130 } else {
131 STORM_LOG_ASSERT(false, "Unknown predicate type.");
132 }
133 return std::const_pointer_cast<BaseExpression const>(finalexpr.getBaseExpressionPointer());
134}
135
136boost::any RestrictSyntaxVisitor::visit(BooleanLiteralExpression const &expression, boost::any const &) {
137 return expression.getSharedPointer();
138}
139
140boost::any RestrictSyntaxVisitor::visit(IntegerLiteralExpression const &expression, boost::any const &) {
141 return expression.getSharedPointer();
142}
143
144boost::any RestrictSyntaxVisitor::visit(RationalLiteralExpression const &expression, boost::any const &) {
145 return expression.getSharedPointer();
146}
147
148} // namespace expressions
149} // namespace storm
virtual boost::any accept(ExpressionVisitor &visitor, boost::any const &data) const =0
Accepts the given visitor by calling its visit method.
ExpressionManager const & getManager() const
Retrieves the manager responsible for this expression.
Type const & getType() const
Retrieves the type of the expression.
std::shared_ptr< BaseExpression const > getSharedPointer() const
Retrieves a shared pointer to this 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.
OperatorType getOperatorType() const
Retrieves the operator associated with the expression.
RelationType getRelationType() const
Retrieves the relation associated with the expression.
std::shared_ptr< BaseExpression const > const & getBaseExpressionPointer() const
Retrieves a pointer to the base expression underlying this expression object.
BaseExpression const & getBaseExpression() const
Retrieves the base expression underlying this expression object.
Expression integer(int_fast64_t value) const
Creates an expression that characterizes the given integer literal.
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.
The base class of all binary expressions.
virtual std::shared_ptr< BaseExpression const > getOperand(uint_fast64_t operandIndex) const override
Retrieves the given operand from the expression.
PredicateType getPredicateType() const
Retrieves the relation associated with the expression.
virtual uint_fast64_t getArity() const override
Returns the arity of the expression.
virtual boost::any visit(IfThenElseExpression const &expression, boost::any const &data) override
RestrictSyntaxVisitor()
Creates a new simplification visitor that replaces predicates by other (simpler?) predicates.
Expression substitute(Expression const &expression)
Simplifies based on the configuration.
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.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
Expression ite(Expression const &condition, Expression const &thenExpression, Expression const &elseExpression)
Expression sum(std::vector< storm::expressions::Expression > const &expressions)
LabParser.cpp.
Definition cli.cpp:18