Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
VariableExpression.cpp
Go to the documentation of this file.
2#include "ExpressionVisitor.h"
3#include "Valuation.h"
6
7namespace storm {
8namespace expressions {
9VariableExpression::VariableExpression(Variable const& variable) : BaseExpression(variable.getManager(), variable.getType()), variable(variable) {
10 // Intentionally left empty.
11}
12
13std::string const& VariableExpression::getVariableName() const {
14 return variable.getName();
15}
16
18 return variable;
19}
20
21bool VariableExpression::evaluateAsBool(Valuation const* valuation) const {
22 STORM_LOG_ASSERT(valuation != nullptr, "Evaluating expressions with unknowns without valuation.");
23 STORM_LOG_THROW(this->hasBooleanType(), storm::exceptions::InvalidTypeException, "Cannot evaluate expression as boolean: return type is not a boolean.");
24
25 return valuation->getBooleanValue(this->getVariable());
26}
27
28int_fast64_t VariableExpression::evaluateAsInt(Valuation const* valuation) const {
29 STORM_LOG_ASSERT(valuation != nullptr, "Evaluating expressions with unknowns without valuation.");
30 STORM_LOG_THROW(this->hasIntegerType(), storm::exceptions::InvalidTypeException, "Cannot evaluate expression as integer: return type is not an integer.");
31
32 return valuation->getIntegerValue(this->getVariable());
33}
34
35double VariableExpression::evaluateAsDouble(Valuation const* valuation) const {
36 STORM_LOG_ASSERT(valuation != nullptr, "Evaluating expressions with unknowns without valuation.");
37 STORM_LOG_THROW(this->hasNumericalType(), storm::exceptions::InvalidTypeException, "Cannot evaluate expression as double: return type is not a double.");
38
39 if (this->getType().isIntegerType()) {
40 return static_cast<double>(valuation->getIntegerValue(this->getVariable()));
41 } else {
42 return valuation->getRationalValue(this->getVariable());
43 }
44}
45
46std::string const& VariableExpression::getIdentifier() const {
47 return this->getVariableName();
48}
49
51 return true;
52}
53
55 return true;
56}
57
58void VariableExpression::gatherVariables(std::set<storm::expressions::Variable>& variables) const {
59 variables.insert(this->getVariable());
60}
61
62std::shared_ptr<BaseExpression const> VariableExpression::simplify() const {
63 return this->shared_from_this();
64}
65
66boost::any VariableExpression::accept(ExpressionVisitor& visitor, boost::any const& data) const {
67 return visitor.visit(*this, data);
68}
69
71 return true;
72}
73
74void VariableExpression::printToStream(std::ostream& stream) const {
75 stream << this->getVariableName();
76}
77} // namespace expressions
78} // namespace storm
The base class of all expression classes.
bool hasBooleanType() const
Retrieves whether the expression has a boolean type.
bool hasIntegerType() const
Retrieves whether the expression has an integer type.
bool hasNumericalType() const
Retrieves whether the expression has a numerical type, i.e., integer or double.
Type const & getType() const
Retrieves the type of the expression.
virtual boost::any visit(IfThenElseExpression const &expression, boost::any const &data)=0
The base class of all valuations of variables.
Definition Valuation.h:16
virtual int_fast64_t getIntegerValue(Variable const &integerVariable) const =0
Retrieves the value of the given integer variable.
virtual double getRationalValue(Variable const &rationalVariable) const =0
Retrieves the value of the given rational variable.
virtual bool getBooleanValue(Variable const &booleanVariable) const =0
Retrieves the value of the given boolean variable.
virtual void printToStream(std::ostream &stream) const override
Prints the expression to the given stream.
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 std::string const & getIdentifier() const override
Retrieves the identifier associated with this expression.
VariableExpression(Variable const &variable)
Creates a variable expression with the given return type and variable name.
virtual boost::any accept(ExpressionVisitor &visitor, boost::any const &data) const override
Accepts the given visitor by calling its visit method.
virtual std::shared_ptr< BaseExpression const > simplify() const override
Simplifies the expression according to some simple rules.
virtual bool containsVariables() const override
Retrieves whether the expression contains a variable.
virtual bool isVariableExpression() const override
virtual bool isVariable() const override
Retrieves whether the expression is a variable.
virtual bool evaluateAsBool(Valuation const *valuation=nullptr) const override
Evaluates the expression under the valuation of unknowns (variables and constants) given by the valua...
Variable const & getVariable() const
Retrieves the variable associated with this expression.
virtual double evaluateAsDouble(Valuation const *valuation=nullptr) const override
Evaluates the expression under the valuation of unknowns (variables and constants) given by the valua...
std::string const & getVariableName() const
Retrieves the name of the variable associated with this expression.
virtual void gatherVariables(std::set< storm::expressions::Variable > &variables) const override
Retrieves the set of all variables that appear in the expression.
std::string const & getName() const
Retrieves the name of the variable.
Definition Variable.cpp:46
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
LabParser.cpp.
Definition cli.cpp:18