11 std::shared_ptr<BaseExpression const>
const& thenExpression,
12 std::shared_ptr<BaseExpression const>
const& elseExpression)
13 :
BaseExpression(manager, type), condition(condition), thenExpression(thenExpression), elseExpression(elseExpression) {
18 STORM_LOG_THROW(operandIndex < 3, storm::exceptions::InvalidAccessException,
"Unable to access operand " << operandIndex <<
" in expression of arity 3.");
19 if (operandIndex == 0) {
21 }
else if (operandIndex == 1) {
45 bool conditionValue = this->condition->evaluateAsBool(valuation);
47 return this->thenExpression->evaluateAsBool(valuation);
49 return this->elseExpression->evaluateAsBool(valuation);
54 bool conditionValue = this->condition->evaluateAsBool(valuation);
56 return this->thenExpression->evaluateAsInt(valuation);
58 return this->elseExpression->evaluateAsInt(valuation);
63 bool conditionValue = this->condition->evaluateAsBool(valuation);
65 return this->thenExpression->evaluateAsDouble(valuation);
67 return this->elseExpression->evaluateAsDouble(valuation);
72 this->condition->gatherVariables(variables);
73 this->thenExpression->gatherVariables(variables);
74 this->elseExpression->gatherVariables(variables);
78 std::shared_ptr<BaseExpression const> conditionSimplified = this->condition->simplify();
79 if (conditionSimplified->isTrue()) {
80 return this->thenExpression->simplify();
81 }
else if (conditionSimplified->isFalse()) {
82 return this->elseExpression->simplify();
84 std::shared_ptr<BaseExpression const> thenExpressionSimplified = this->thenExpression->simplify();
85 std::shared_ptr<BaseExpression const> elseExpressionSimplified = this->elseExpression->simplify();
87 if (conditionSimplified.get() == this->condition.get() && thenExpressionSimplified.get() == this->thenExpression.get() &&
88 elseExpressionSimplified.get() == this->elseExpression.get()) {
89 return this->shared_from_this();
91 return std::shared_ptr<BaseExpression>(
98 return visitor.
visit(*
this, data);
106 return this->condition;
110 return this->thenExpression;
114 return this->elseExpression;
118 stream <<
"(" << *this->condition <<
" ? " << *this->thenExpression <<
" : " << *this->elseExpression <<
")";
The base class of all expression classes.
ExpressionManager const & getManager() const
Retrieves the manager responsible for this expression.
Type const & getType() const
Retrieves the type of the expression.
This class is responsible for managing a set of typed variables and all expressions using these varia...
virtual boost::any visit(IfThenElseExpression const &expression, boost::any const &data)=0
virtual std::shared_ptr< BaseExpression const > getOperand(uint_fast64_t operandIndex) const override
Retrieves the given operand from the expression.
std::shared_ptr< BaseExpression const > getElseExpression() const
Retrieves the else expression of the if-then-else expression.
IfThenElseExpression(ExpressionManager const &manager, Type const &type, std::shared_ptr< BaseExpression const > const &condition, std::shared_ptr< BaseExpression const > const &thenExpression, std::shared_ptr< BaseExpression const > const &elseExpression)
Creates an if-then-else expression with the given return type, condition and operands.
virtual bool isIfThenElseExpression() const override
virtual bool evaluateAsBool(Valuation const *valuation=nullptr) const override
Evaluates the expression under the valuation of unknowns (variables and constants) given by the valua...
virtual uint_fast64_t getArity() const override
Returns the arity of the expression.
virtual int_fast64_t evaluateAsInt(Valuation const *valuation=nullptr) const override
Evaluates the expression under the valuation of unknowns (variables and constants) given by the valua...
virtual bool isFunctionApplication() const override
Checks if the expression is a function application (of any sort).
virtual bool containsVariables() const override
Retrieves whether the expression contains a variable.
std::shared_ptr< BaseExpression const > getCondition() const
Retrieves the condition expression of the if-then-else expression.
virtual OperatorType getOperator() const override
Retrieves the operator of a function application.
virtual double evaluateAsDouble(Valuation const *valuation=nullptr) const override
Evaluates the expression under the valuation of unknowns (variables and constants) given by the valua...
virtual std::shared_ptr< BaseExpression const > simplify() const override
Simplifies the expression according to some simple rules.
virtual void printToStream(std::ostream &stream) const override
Prints the expression to the given stream.
virtual boost::any accept(ExpressionVisitor &visitor, boost::any const &data) const override
Accepts the given visitor by calling its visit method.
virtual void gatherVariables(std::set< storm::expressions::Variable > &variables) const override
Retrieves the set of all variables that appear in the expression.
std::shared_ptr< BaseExpression const > getThenExpression() const
Retrieves the then expression of the if-then-else expression.
The base class of all valuations of variables.
#define STORM_LOG_THROW(cond, exception, message)