Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
UnaryBooleanFunctionExpression.cpp
Go to the documentation of this file.
2#include "ExpressionVisitor.h"
7
8namespace storm {
9namespace expressions {
11 std::shared_ptr<BaseExpression const> const& operand, OperatorType operatorType)
12 : UnaryExpression(manager, type, operand), operatorType(operatorType) {
13 // Intentionally left empty.
14}
15
19
28
30 STORM_LOG_THROW(this->hasBooleanType(), storm::exceptions::InvalidTypeException, "Unable to evaluate expression as boolean.");
31
32 bool result = this->getOperand()->evaluateAsBool(valuation);
33 switch (this->getOperatorType()) {
35 result = !result;
36 break;
37 }
38 return result;
39}
40
41std::shared_ptr<BaseExpression const> UnaryBooleanFunctionExpression::simplify() const {
42 std::shared_ptr<BaseExpression const> operandSimplified = this->getOperand()->simplify();
43 switch (this->getOperatorType()) {
45 if (operandSimplified->isTrue()) {
46 return std::shared_ptr<BaseExpression>(new BooleanLiteralExpression(this->getManager(), false));
47 } else if (operandSimplified->isFalse()) {
48 return std::shared_ptr<BaseExpression>(new BooleanLiteralExpression(this->getManager(), true));
49 }
50 }
51
52 if (operandSimplified.get() == this->getOperand().get()) {
53 return this->shared_from_this();
54 } else {
55 return std::shared_ptr<BaseExpression>(
56 new UnaryBooleanFunctionExpression(this->getManager(), this->getType(), operandSimplified, this->getOperatorType()));
57 }
58}
59
60boost::any UnaryBooleanFunctionExpression::accept(ExpressionVisitor& visitor, boost::any const& data) const {
61 return visitor.visit(*this, data);
62}
63
67
68void UnaryBooleanFunctionExpression::printToStream(std::ostream& stream) const {
69 stream << "!(" << *this->getOperand() << ")";
70}
71} // namespace expressions
72} // namespace storm
bool hasBooleanType() const
Retrieves whether the expression has a boolean type.
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 > simplify() const override
Simplifies the expression according to some simple rules.
OperatorType getOperatorType() const
Retrieves the operator associated with this expression.
OperatorType
An enum type specifying the different functions applicable.
virtual boost::any accept(ExpressionVisitor &visitor, boost::any const &data) const override
Accepts the given visitor by calling its visit method.
virtual bool evaluateAsBool(Valuation const *valuation=nullptr) const override
Evaluates the expression under the valuation of unknowns (variables and constants) given by the valua...
UnaryBooleanFunctionExpression(ExpressionManager const &manager, Type const &type, std::shared_ptr< BaseExpression const > const &operand, OperatorType operatorType)
Creates a unary boolean function expression with the given return type, operand and operator.
virtual storm::expressions::OperatorType getOperator() const override
Retrieves the operator of a function application.
virtual void printToStream(std::ostream &stream) const override
Prints the expression to the given stream.
std::shared_ptr< BaseExpression const > const & getOperand() const
Retrieves the operand of the unary expression.
The base class of all valuations of variables.
Definition Valuation.h:16
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
LabParser.cpp.
Definition cli.cpp:18