Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
TransientVariableInformation.cpp
Go to the documentation of this file.
2
4
11
16
17#include <cmath>
18
19namespace storm {
20namespace generator {
21
22template<>
24 boost::optional<storm::RationalFunction> const& lowerBound,
25 boost::optional<storm::RationalFunction> const& upperBound,
26 storm::RationalFunction const& defaultValue, bool global)
27 : variable(variable), lowerBound(lowerBound), upperBound(upperBound), defaultValue(defaultValue), global(global) {
28 // There is no '<=' for rational functions. Therefore, do not check the bounds for this ValueType
29}
30
31template<typename VariableType>
32TransientVariableData<VariableType>::TransientVariableData(storm::expressions::Variable const& variable, boost::optional<VariableType> const& lowerBound,
33 boost::optional<VariableType> const& upperBound, VariableType const& defaultValue, bool global)
34 : variable(variable), lowerBound(lowerBound), upperBound(upperBound), defaultValue(defaultValue), global(global) {
35 STORM_LOG_THROW(!lowerBound.is_initialized() || lowerBound.get() <= defaultValue, storm::exceptions::OutOfRangeException,
36 "The default value for transient variable " << variable.getName() << " is smaller than its lower bound.");
37 STORM_LOG_THROW(!upperBound.is_initialized() || defaultValue <= upperBound.get(), storm::exceptions::OutOfRangeException,
38 "The default value for transient variable " << variable.getName() << " is higher than its upper bound.");
39}
40
41template<typename VariableType>
42TransientVariableData<VariableType>::TransientVariableData(storm::expressions::Variable const& variable, VariableType const& defaultValue, bool global)
43 : variable(variable), defaultValue(defaultValue), global(global) {
44 // Intentionally left empty.
45}
46
47template<typename ValueType>
49 storm::jani::Model const& model, std::vector<std::reference_wrapper<storm::jani::Automaton const>> const& parallelAutomata) {
50 createVariablesForVariableSet(model.getGlobalVariables(), true);
51
52 for (auto const& automatonRef : parallelAutomata) {
53 createVariablesForAutomaton(automatonRef.get());
54 }
55
56 sortVariables();
57}
58
59template<typename ValueType>
61 arrayVariableToElementInformations.clear();
62 // Find for each replaced array variable the corresponding references in this variable information
63 for (auto const& arrayVariable : arrayEliminatorData.eliminatedArrayVariables) {
64 if (arrayVariable->isTransient()) {
65 auto findRes = arrayEliminatorData.replacements.find(arrayVariable->getExpressionVariable());
66 STORM_LOG_ASSERT(findRes != arrayEliminatorData.replacements.end(), "No replacement for array variable.");
67 auto const& replacements = findRes->second;
68 auto const& innerType = arrayVariable->getType().asArrayType().getBaseTypeRecursive();
69 if (innerType.isBasicType() && innerType.asBasicType().isBooleanType()) {
70 auto replInfo = convertArrayReplacement(replacements, booleanVariableInformation);
71 this->arrayVariableToElementInformations.emplace(arrayVariable->getExpressionVariable(), std::move(replInfo));
72 } else if ((innerType.isBasicType() && innerType.asBasicType().isIntegerType()) ||
73 (innerType.isBoundedType() && innerType.asBoundedType().isIntegerType())) {
74 auto replInfo = convertArrayReplacement(replacements, integerVariableInformation);
75 this->arrayVariableToElementInformations.emplace(arrayVariable->getExpressionVariable(), std::move(replInfo));
76 } else if ((innerType.isBasicType() && innerType.asBasicType().isRealType()) ||
77 (innerType.isBoundedType() && innerType.asBoundedType().isRealType())) {
78 auto replInfo = convertArrayReplacement(replacements, rationalVariableInformation);
79 this->arrayVariableToElementInformations.emplace(arrayVariable->getExpressionVariable(), std::move(replInfo));
80 } else {
81 STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, "Unhandled type of base variable.");
82 }
83 }
84 }
85}
86
87template<typename ValueType>
89 storm::expressions::Variable const& arrayVariable, std::vector<uint64_t> const& arrayIndexVector) const {
90 return booleanVariableInformation[arrayVariableToElementInformations.at(arrayVariable).getVariableInformationIndex(arrayIndexVector)];
91}
92
93template<typename ValueType>
95 storm::expressions::Variable const& arrayVariable, std::vector<uint64_t> const& arrayIndexVector) const {
96 return integerVariableInformation[arrayVariableToElementInformations.at(arrayVariable).getVariableInformationIndex(arrayIndexVector)];
97}
98
99template<typename ValueType>
101 storm::expressions::Variable const& arrayVariable, std::vector<uint64_t> const& arrayIndexVector) const {
102 return rationalVariableInformation[arrayVariableToElementInformations.at(arrayVariable).getVariableInformationIndex(arrayIndexVector)];
103}
104
105template<typename ValueType>
107 createVariablesForVariableSet(automaton.getVariables(), false);
108}
109
110template<typename ValueType>
111void TransientVariableInformation<ValueType>::createVariablesForVariableSet(storm::jani::VariableSet const& variableSet, bool global) {
112 for (auto const& variable : variableSet.getBooleanVariables()) {
113 if (variable.isTransient()) {
114 booleanVariableInformation.emplace_back(variable.getExpressionVariable(), variable.getInitExpression().evaluateAsBool(), global);
115 }
116 }
117 for (auto const& variable : variableSet.getBoundedIntegerVariables()) {
118 if (variable.isTransient()) {
119 boost::optional<int64_t> lowerBound;
120 boost::optional<int64_t> upperBound;
121 auto const& type = variable.getType().asBoundedType();
122 if (type.hasLowerBound()) {
123 lowerBound = type.getLowerBound().evaluateAsInt();
124 }
125 if (type.hasUpperBound()) {
126 upperBound = type.getUpperBound().evaluateAsInt();
127 }
128 integerVariableInformation.emplace_back(variable.getExpressionVariable(), lowerBound, upperBound, variable.getInitExpression().evaluateAsInt(),
129 global);
130 }
131 }
132 for (auto const& variable : variableSet.getUnboundedIntegerVariables()) {
133 if (variable.isTransient()) {
134 integerVariableInformation.emplace_back(variable.getExpressionVariable(), variable.getInitExpression().evaluateAsInt(), global);
135 }
136 }
137 for (auto const& variable : variableSet.getRealVariables()) {
138 if (variable.isTransient()) {
139 rationalVariableInformation.emplace_back(variable.getExpressionVariable(),
140 storm::utility::convertNumber<ValueType>(variable.getInitExpression().evaluateAsRational()), global);
141 }
142 }
143}
144
145template<typename ValueType>
146void TransientVariableInformation<ValueType>::sortVariables() {
147 // Sort the variables so we can make some assumptions when iterating over them (in the next-state generators).
148 std::sort(booleanVariableInformation.begin(), booleanVariableInformation.end(),
149 [](TransientVariableData<bool> const& a, TransientVariableData<bool> const& b) { return a.variable < b.variable; });
150 std::sort(integerVariableInformation.begin(), integerVariableInformation.end(),
151 [](TransientVariableData<int64_t> const& a, TransientVariableData<int64_t> const& b) { return a.variable < b.variable; });
152 std::sort(rationalVariableInformation.begin(), rationalVariableInformation.end(),
153 [](TransientVariableData<ValueType> const& a, TransientVariableData<ValueType> const& b) { return a.variable < b.variable; });
154}
155
156template<typename ValueType>
158 for (auto const& variableData : booleanVariableInformation) {
159 evaluator.setBooleanValue(variableData.variable, variableData.defaultValue);
160 }
161 for (auto const& variableData : integerVariableInformation) {
162 evaluator.setIntegerValue(variableData.variable, variableData.defaultValue);
163 }
164 for (auto const& variableData : rationalVariableInformation) {
165 evaluator.setRationalValue(variableData.variable, variableData.defaultValue);
166 }
167}
168
172
173} // namespace generator
174} // namespace storm
std::string const & getName() const
Retrieves the name of the variable.
Definition Variable.cpp:46
VariableSet & getVariables()
Retrieves the variables of this automaton.
Definition Automaton.cpp:59
VariableSet & getGlobalVariables()
Retrieves the variables of this automaton.
Definition Model.cpp:721
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
ArrayVariableReplacementInformation convertArrayReplacement(typename storm::jani::ArrayEliminatorData::Replacement const &replacement, InfoType const &relevantVariableInfo)
LabParser.cpp.
Definition cli.cpp:18
TransientVariableData(storm::expressions::Variable const &variable, boost::optional< VariableType > const &lowerBound, boost::optional< VariableType > const &upperBound, VariableType const &defaultValue, bool global=false)
void registerArrayVariableReplacements(storm::jani::ArrayEliminatorData const &arrayEliminatorData)
void setDefaultValuesInEvaluator(storm::expressions::ExpressionEvaluator< ValueType > &evaluator) const
TransientVariableData< int64_t > const & getIntegerArrayVariableReplacement(storm::expressions::Variable const &arrayVariable, std::vector< uint64_t > const &arrayIndexVector) const
TransientVariableData< bool > const & getBooleanArrayVariableReplacement(storm::expressions::Variable const &arrayVariable, std::vector< uint64_t > const &arrayIndexVector) const
TransientVariableData< ValueType > const & getRationalArrayVariableReplacement(storm::expressions::Variable const &arrayVariable, std::vector< uint64_t > const &arrayIndexVector) const
std::unordered_map< storm::expressions::Variable, Replacement > replacements
std::vector< std::shared_ptr< Variable > > eliminatedArrayVariables