Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
VariablesToConstantsTransformer.cpp
Go to the documentation of this file.
2
7
12
13namespace storm {
14
15namespace jani {
16namespace detail {
19 "Trying to convert variable " << variable.getName() << " to a constant, but the variable does not have an initial value.");
20 // For the name we use the name of the expression variable to assert uniqueness.
22}
23
24template<typename JaniStructureType>
25bool canTransformVariable(storm::jani::Variable const& variable, JaniStructureType const& janiStructure) {
26 // It does not make sense to do this for transient variables.
27 if (variable.isTransient()) {
28 return false;
29 }
30 // The jani specification only allows these two types of constants.
31 if (!(variable.getType().isBasicType() || variable.getType().isBoundedType())) {
32 return false;
33 }
34 // The variable should have a known initial value.
35 if (!variable.hasInitExpression()) {
36 return false;
37 }
38 // Finally, there should be no assignment that assignes a value to this variable.
39 auto assignmentTypes = storm::jani::AssignmentsFinder().find(janiStructure, variable);
40 return !assignmentTypes.hasEdgeAssignment && !assignmentTypes.hasEdgeDestinationAssignment && !assignmentTypes.hasLocationAssignment;
41}
42} // namespace detail
43
45 // It is dangerous to erase a variable from a set of variables while iterating over the set.
46 // Therefore, we store the variables and erase them later.
47 std::vector<storm::expressions::Variable> variablesToErase;
48 for (auto const& globalVar : model.getGlobalVariables()) {
49 if (detail::canTransformVariable(globalVar, model)) {
50 variablesToErase.push_back(globalVar.getExpressionVariable());
51 }
52 }
53 for (auto const& varToErase : variablesToErase) {
54 STORM_LOG_INFO("Transformed Variable " << varToErase.getName() << " to a constant since it is not assigned any value.");
55 auto erasedJaniVariable = model.getGlobalVariables().eraseVariable(varToErase);
56 auto createdConstant = detail::createConstantFromVariable(*erasedJaniVariable);
57 model.addConstant(createdConstant);
58 }
59 for (auto& aut : model.getAutomata()) {
60 variablesToErase.clear();
61 for (auto const& localVar : aut.getVariables()) {
62 if (detail::canTransformVariable(localVar, aut)) {
63 variablesToErase.push_back(localVar.getExpressionVariable());
64 }
65 }
66 for (auto const& varToErase : variablesToErase) {
67 STORM_LOG_INFO("Transformed Variable " << varToErase.getName() << " to a constant since it is not assigned any value.");
68 auto erasedJaniVariable = aut.getVariables().eraseVariable(varToErase);
69 auto createdConstant = detail::createConstantFromVariable(*erasedJaniVariable);
70 model.addConstant(createdConstant);
71 }
72 }
73}
74} // namespace jani
75} // namespace storm
std::string const & getName() const
Retrieves the name of the variable.
Definition Variable.cpp:46
ResultType find(Model const &model, storm::jani::Variable const &variable)
virtual bool isBoundedType() const
Definition JaniType.cpp:15
virtual bool isBasicType() const
Definition JaniType.cpp:11
VariableSet & getGlobalVariables()
Retrieves the variables of this automaton.
Definition Model.cpp:721
std::vector< Automaton > & getAutomata()
Retrieves the automata of the model.
Definition Model.cpp:872
void addConstant(Constant const &constant)
Adds the given constant to the model.
Definition Model.cpp:654
bool hasInitExpression() const
Retrieves whether an initial expression is set.
Definition Variable.cpp:46
storm::expressions::Variable const & getExpressionVariable() const
Retrieves the associated expression variable.
Definition Variable.cpp:26
JaniType & getType()
Definition Variable.cpp:67
bool isTransient() const
Definition Variable.cpp:42
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
std::string const & getName() const
Retrieves the name of the variable.
Definition Variable.cpp:34
std::shared_ptr< Variable > eraseVariable(storm::expressions::Variable const &variable)
Erases the given variable from this set.
void transform(Model &model)
Replaces each variable to which we never assign a value with a constant.
#define STORM_LOG_INFO(message)
Definition logging.h:29
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
bool canTransformVariable(storm::jani::Variable const &variable, JaniStructureType const &janiStructure)
storm::jani::Constant createConstantFromVariable(storm::jani::Variable const &variable)
LabParser.cpp.
Definition cli.cpp:18