Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Variable.cpp
Go to the documentation of this file.
3
4namespace storm {
5namespace jani {
6
7Variable::Variable(std::string const& name, JaniType const& type, storm::expressions::Variable const& variable, storm::expressions::Expression const& init,
8 bool transient)
9 : name(name), type(type.clone()), variable(variable), init(init), transient(transient) {
10 // Intentionally left empty
11}
12
13Variable::Variable(std::string const& name, JaniType const& type, storm::expressions::Variable const& variable)
14 : name(name), type(type.clone()), variable(variable), init(), transient(false) {
15 // Intentionally left empty
16}
17
19 // Intentionally left empty.
20}
21
22std::unique_ptr<Variable> Variable::clone() const {
23 return std::make_unique<Variable>(name, *type, variable, init, transient);
24}
25
27 return variable;
28}
29
31 variable = newVariable;
32}
33
34std::string const& Variable::getName() const {
35 return name;
36}
37
38void Variable::setName(std::string const& newName) {
39 name = newName;
40}
41
43 return transient;
44}
45
47 return init.isInitialized();
48}
49
51 STORM_LOG_ASSERT(hasInitExpression(), "Tried to get the init expression of a variable that doesn't have any.");
52 return this->init;
53}
54
56 this->init = initialExpression;
57}
58
59void Variable::substitute(std::map<storm::expressions::Variable, storm::expressions::Expression> const& substitution,
60 bool const substituteTranscendentalNumbers) {
61 if (this->hasInitExpression()) {
62 this->setInitExpression(substituteJaniExpression(this->getInitExpression(), substitution, substituteTranscendentalNumbers));
63 }
64 type->substitute(substitution, substituteTranscendentalNumbers);
65}
66
68 return *type;
69}
70
72 return *type;
73}
74
77
78 if (getType().isBoundedType()) {
79 auto const& boundedType = getType().asBoundedType();
80
81 if (boundedType.hasLowerBound()) {
82 range = boundedType.getLowerBound() <= this->getExpressionVariable();
83 }
84 if (boundedType.hasUpperBound()) {
85 if (range.isInitialized()) {
86 range = range && this->getExpressionVariable() <= boundedType.getUpperBound();
87 } else {
88 range = this->getExpressionVariable() <= boundedType.getUpperBound();
89 }
90 }
91 }
92 return range;
93}
94
95std::shared_ptr<Variable> Variable::makeVariable(std::string const& name, JaniType const& type, storm::expressions::Variable const& variable,
96 boost::optional<storm::expressions::Expression> const& initValue, bool transient) {
97 if (initValue) {
98 return std::make_shared<Variable>(name, type, variable, initValue.get(), transient);
99 } else {
100 STORM_LOG_ASSERT(!transient, "Expecting variable without init value to be not a transient variable");
101 return std::make_shared<Variable>(name, type, variable);
102 }
103}
104
105std::shared_ptr<Variable> Variable::makeBasicTypeVariable(std::string const& name, BasicType::Type const& type, storm::expressions::Variable const& variable,
106 boost::optional<storm::expressions::Expression> const& initValue, bool transient) {
107 return makeVariable(name, BasicType(type), variable, initValue, transient);
108}
109
110std::shared_ptr<Variable> Variable::makeBooleanVariable(std::string const& name, storm::expressions::Variable const& variable,
111 boost::optional<storm::expressions::Expression> const& initValue, bool transient) {
112 return makeVariable(name, BasicType(BasicType::Type::Bool), variable, initValue, transient);
113}
114
115std::shared_ptr<Variable> Variable::makeIntegerVariable(std::string const& name, storm::expressions::Variable const& variable,
116 boost::optional<storm::expressions::Expression> const& initValue, bool transient) {
117 return makeVariable(name, BasicType(BasicType::Type::Int), variable, initValue, transient);
118}
119
120std::shared_ptr<Variable> Variable::makeRealVariable(std::string const& name, storm::expressions::Variable const& variable,
121 boost::optional<storm::expressions::Expression> const& initValue, bool transient) {
122 return makeVariable(name, BasicType(BasicType::Type::Real), variable, initValue, transient);
123}
124
125std::shared_ptr<Variable> Variable::makeBoundedVariable(std::string const& name, BoundedType::BaseType const& type,
126 storm::expressions::Variable const& variable,
127 boost::optional<storm::expressions::Expression> const& initValue, bool transient,
128 boost::optional<storm::expressions::Expression> const& lowerBound,
129 boost::optional<storm::expressions::Expression> const& upperBound) {
130 return makeVariable(name,
131 storm::jani::BoundedType(type, lowerBound ? lowerBound.get() : storm::expressions::Expression(),
132 upperBound ? upperBound.get() : storm::expressions::Expression()),
133 variable, initValue, transient);
134}
135
136std::shared_ptr<Variable> Variable::makeBoundedIntegerVariable(std::string const& name, storm::expressions::Variable const& variable,
137 boost::optional<storm::expressions::Expression> const& initValue, bool transient,
138 boost::optional<storm::expressions::Expression> const& lowerBound,
139 boost::optional<storm::expressions::Expression> const& upperBound) {
140 return makeBoundedVariable(name, BoundedType::BaseType::Int, variable, initValue, transient, lowerBound, upperBound);
141}
142
143std::shared_ptr<Variable> Variable::makeBoundedRealVariable(std::string const& name, storm::expressions::Variable const& variable,
144 boost::optional<storm::expressions::Expression> const& initValue, bool transient,
145 boost::optional<storm::expressions::Expression> const& lowerBound,
146 boost::optional<storm::expressions::Expression> const& upperBound) {
147 return makeBoundedVariable(name, BoundedType::BaseType::Real, variable, initValue, transient, lowerBound, upperBound);
148}
149
150std::shared_ptr<Variable> Variable::makeArrayVariable(std::string const& name, JaniType const& baseType, storm::expressions::Variable const& variable,
151 boost::optional<storm::expressions::Expression> const& initValue, bool transient) {
152 return makeVariable(name, ArrayType(baseType), variable, initValue, transient);
153}
154
155std::shared_ptr<Variable> Variable::makeClockVariable(std::string const& name, storm::expressions::Variable const& variable,
156 boost::optional<storm::expressions::Expression> const& initValue, bool transient) {
157 return makeVariable(name, ClockType(), variable, initValue, transient);
158}
159
160std::shared_ptr<Variable> Variable::makeContinuousVariable(std::string const& name, storm::expressions::Variable const& variable,
161 boost::optional<storm::expressions::Expression> const& initValue, bool transient) {
162 return makeVariable(name, ContinuousType(), variable, initValue, transient);
163}
164
165bool operator==(Variable const& lhs, Variable const& rhs) {
166 return lhs.getExpressionVariable() == rhs.getExpressionVariable();
167}
168
169bool operator!=(Variable const& lhs, Variable const& rhs) {
170 return !(lhs == rhs);
171}
172} // namespace jani
173} // namespace storm
bool isInitialized() const
Checks whether the object encapsulates a base-expression.
BoundedType const & asBoundedType() const
Definition JaniType.cpp:39
Variable(std::string const &name, JaniType const &type, storm::expressions::Variable const &variable, storm::expressions::Expression const &init, bool transient=false)
Creates a new variable with initial value construct.
Definition Variable.cpp:7
void setName(std::string const &newName)
Sets the name of the variable.
Definition Variable.cpp:38
void setExpressionVariable(storm::expressions::Variable const &newVariable)
Sets the associated expression variable.
Definition Variable.cpp:30
static std::shared_ptr< Variable > makeArrayVariable(std::string const &name, JaniType const &baseType, storm::expressions::Variable const &variable, boost::optional< storm::expressions::Expression > const &initValue, bool transient)
Definition Variable.cpp:150
static std::shared_ptr< Variable > makeContinuousVariable(std::string const &name, storm::expressions::Variable const &variable, boost::optional< storm::expressions::Expression > const &initValue, bool transient)
Definition Variable.cpp:160
static std::shared_ptr< Variable > makeIntegerVariable(std::string const &name, storm::expressions::Variable const &variable, boost::optional< storm::expressions::Expression > const &initValue, bool transient)
Definition Variable.cpp:115
static std::shared_ptr< Variable > makeRealVariable(std::string const &name, storm::expressions::Variable const &variable, boost::optional< storm::expressions::Expression > const &initValue, bool transient)
Definition Variable.cpp:120
static std::shared_ptr< Variable > makeBooleanVariable(std::string const &name, storm::expressions::Variable const &variable, boost::optional< storm::expressions::Expression > const &initValue, bool transient)
Definition Variable.cpp:110
static std::shared_ptr< Variable > makeBoundedIntegerVariable(std::string const &name, storm::expressions::Variable const &variable, boost::optional< storm::expressions::Expression > const &initValue, bool transient, boost::optional< storm::expressions::Expression > const &lowerBound, boost::optional< storm::expressions::Expression > const &upperBound)
Definition Variable.cpp:136
bool hasInitExpression() const
Retrieves whether an initial expression is set.
Definition Variable.cpp:46
std::unique_ptr< Variable > clone() const
Clones the variable.
Definition Variable.cpp:22
storm::expressions::Variable const & getExpressionVariable() const
Retrieves the associated expression variable.
Definition Variable.cpp:26
static std::shared_ptr< Variable > makeBoundedRealVariable(std::string const &name, storm::expressions::Variable const &variable, boost::optional< storm::expressions::Expression > const &initValue, bool transient, boost::optional< storm::expressions::Expression > const &lowerBound, boost::optional< storm::expressions::Expression > const &upperBound)
Definition Variable.cpp:143
JaniType & getType()
Definition Variable.cpp:67
storm::expressions::Expression getRangeExpression() const
Retrieves an expression characterizing the legal range of the variable.
Definition Variable.cpp:75
bool isTransient() const
Definition Variable.cpp:42
static std::shared_ptr< Variable > makeVariable(std::string const &name, JaniType const &type, storm::expressions::Variable const &variable, boost::optional< storm::expressions::Expression > const &initValue, bool transient)
Convenience functions to call the appropriate constructor and return a shared pointer to the variable...
Definition Variable.cpp:95
storm::expressions::Expression const & getInitExpression() const
Retrieves the initial expression Should only be called if an initial expression is set for this varia...
Definition Variable.cpp:50
void setInitExpression(storm::expressions::Expression const &initialExpression)
Sets the initial expression for this variable.
Definition Variable.cpp:55
static std::shared_ptr< Variable > makeBasicTypeVariable(std::string const &name, BasicType::Type const &type, storm::expressions::Variable const &variable, boost::optional< storm::expressions::Expression > const &initValue, bool transient)
Definition Variable.cpp:105
static std::shared_ptr< Variable > makeBoundedVariable(std::string const &name, BoundedType::BaseType const &type, storm::expressions::Variable const &variable, boost::optional< storm::expressions::Expression > const &initValue, bool transient, boost::optional< storm::expressions::Expression > const &lowerBound, boost::optional< storm::expressions::Expression > const &upperBound)
Definition Variable.cpp:125
std::string const & getName() const
Retrieves the name of the variable.
Definition Variable.cpp:34
void substitute(std::map< storm::expressions::Variable, storm::expressions::Expression > const &substitution, bool const substituteTranscendentalNumbers)
Substitutes all variables in all expressions according to the given substitution.
Definition Variable.cpp:59
static std::shared_ptr< Variable > makeClockVariable(std::string const &name, storm::expressions::Variable const &variable, boost::optional< storm::expressions::Expression > const &initValue, bool transient)
Definition Variable.cpp:155
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
bool operator!=(SynchronizationVector const &vector1, SynchronizationVector const &vector2)
storm::expressions::Expression substituteJaniExpression(storm::expressions::Expression const &expression, std::map< storm::expressions::Variable, storm::expressions::Expression > const &identifierToExpressionMap, bool const substituteTranscendentalNumbers)
bool operator==(SynchronizationVector const &vector1, SynchronizationVector const &vector2)
LabParser.cpp.
Definition cli.cpp:18