Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Constant.cpp
Go to the documentation of this file.
4
7
8namespace storm {
9namespace jani {
10
12 storm::expressions::Expression const& constaintExpression) {
13 auto manager = var.getManager().clone();
14 auto smtSolver = storm::utility::solver::getSmtSolver(*manager);
15 smtSolver->add(var.getExpression().changeManager(*manager) == definingExpression.changeManager(*manager));
16 smtSolver->add(constaintExpression.changeManager(*manager));
17 return smtSolver->check() == storm::solver::SmtSolver::CheckResult::Sat;
18}
19
20Constant::Constant(std::string const& name, storm::expressions::Variable const& variable, storm::expressions::Expression const& definingExpression,
21 storm::expressions::Expression const& constraintExpression)
22 : name(name), variable(variable), definingExpression(definingExpression), constraintExpression(constraintExpression) {
23 if (definingExpression.isInitialized() && constraintExpression.isInitialized()) {
24 STORM_LOG_THROW(checkDefiningExpression(variable, definingExpression, constraintExpression), storm::exceptions::InvalidJaniException,
25 "The constant '" << name << "' was set to '" << definingExpression << "' which violates the constraint given for this constant: '"
26 << constraintExpression << "'.");
27 }
28}
29
30std::string const& Constant::getName() const {
31 return name;
32}
33
34bool Constant::isDefined() const {
35 return definingExpression.isInitialized();
36}
37
39 if (hasConstraint()) {
40 STORM_LOG_THROW(checkDefiningExpression(getExpressionVariable(), expression, constraintExpression), storm::exceptions::InvalidJaniException,
41 "The constant '" << name << "' was set to '" << expression << "' which violates the constraint given for this constant: '"
42 << constraintExpression << "'.");
43 }
44 this->definingExpression = expression;
45}
46
48 return variable.getType();
49}
50
52 return getType().isBooleanType();
53}
54
56 return getType().isIntegerType();
57}
58
60 return getType().isRationalType();
61}
62
64 return variable;
65}
66
68 STORM_LOG_ASSERT(isDefined(), "Tried to get the constant definition of undefined constant '" << variable.getName() << "'.");
69 return definingExpression;
70}
71
73 return constraintExpression.isInitialized();
74}
75
77 STORM_LOG_ASSERT(hasConstraint(), "Tried to get the constant constraint of unconstrained constant '" << variable.getName() << "'.");
78 return constraintExpression;
79}
80
82 if (isDefined()) {
83 STORM_LOG_THROW(checkDefiningExpression(getExpressionVariable(), definingExpression, expression), storm::exceptions::InvalidJaniException,
84 "The constant '" << name << "' was set to '" << definingExpression << "' which violates the constraint given for this constant: '"
85 << expression << "'.");
86 }
87 constraintExpression = expression;
88}
89
90} // namespace jani
91} // namespace storm
Expression changeManager(ExpressionManager const &newExpressionManager) const
Converts the expression to an expression over the variables of the provided expression manager.
bool isInitialized() const
Checks whether the object encapsulates a base-expression.
std::shared_ptr< ExpressionManager > clone() const
Creates a new expression manager with the same set of variables.
bool isBooleanType() const
Checks whether this type is a boolean type.
Definition Type.cpp:178
bool isIntegerType() const
Checks whether this type is an integral type.
Definition Type.cpp:182
bool isRationalType() const
Checks whether this type is a rational type.
Definition Type.cpp:214
ExpressionManager const & getManager() const
Retrieves the manager responsible for this variable.
Definition Variable.cpp:54
Type const & getType() const
Retrieves the type of the variable.
Definition Variable.cpp:50
storm::expressions::Expression getExpression() const
Retrieves an expression that represents the variable.
Definition Variable.cpp:34
std::string const & getName() const
Retrieves the name of the variable.
Definition Variable.cpp:46
std::string const & getName() const
Retrieves the name of the constant.
Definition Constant.cpp:30
bool isRealConstant() const
Retrieves whether the constant is a real constant.
Definition Constant.cpp:59
void define(storm::expressions::Expression const &expression)
Defines the constant with the given expression.
Definition Constant.cpp:38
bool hasConstraint() const
Retrieves whether there is a constraint for the possible values of this constant.
Definition Constant.cpp:72
storm::expressions::Expression const & getConstraintExpression() const
Retrieves the expression that constraints the possible values of this constant (if any).
Definition Constant.cpp:76
storm::expressions::Type const & getType() const
Retrieves the type of the constant.
Definition Constant.cpp:47
void setConstraintExpression(storm::expressions::Expression const &expression)
Sets a constraint expression.
Definition Constant.cpp:81
Constant(std::string const &name, storm::expressions::Variable const &variable, storm::expressions::Expression const &definingExpression=storm::expressions::Expression(), storm::expressions::Expression const &constraintExpression=storm::expressions::Expression())
Creates a constant.
Definition Constant.cpp:20
bool isIntegerConstant() const
Retrieves whether the constant is an integer constant.
Definition Constant.cpp:55
bool isBooleanConstant() const
Retrieves whether the constant is a boolean constant.
Definition Constant.cpp:51
storm::expressions::Variable const & getExpressionVariable() const
Retrieves the expression variable associated with this constant.
Definition Constant.cpp:63
bool isDefined() const
Retrieves whether the constant is defined in the sense that it has a defining expression.
Definition Constant.cpp:34
storm::expressions::Expression const & getExpression() const
Retrieves the expression that defines this constant (if any).
Definition Constant.cpp:67
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
bool checkDefiningExpression(storm::expressions::Variable const &var, storm::expressions::Expression const &definingExpression, storm::expressions::Expression const &constaintExpression)
Definition Constant.cpp:11
std::unique_ptr< storm::solver::SmtSolver > getSmtSolver(storm::expressions::ExpressionManager &manager)
Definition solver.cpp:154
LabParser.cpp.
Definition cli.cpp:18