Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
TransientVariableInformation.cpp
Go to the documentation of this file.
2
4
12
17
18#include <cmath>
19
20namespace storm {
21namespace generator {
22
23template<>
25 boost::optional<storm::RationalFunction> const& lowerBound,
26 boost::optional<storm::RationalFunction> const& upperBound,
29 // There is no '<=' for rational functions. Therefore, do not check the bounds for this ValueType
30}
31
32template<typename VariableType>
34 boost::optional<VariableType> const& upperBound, VariableType const& defaultValue, bool global)
36 STORM_LOG_THROW(!lowerBound.is_initialized() || lowerBound.get() <= defaultValue, storm::exceptions::OutOfRangeException,
37 "The default value for transient variable " << variable.getName() << " is smaller than its lower bound.");
38 STORM_LOG_THROW(!upperBound.is_initialized() || defaultValue <= upperBound.get(), storm::exceptions::OutOfRangeException,
39 "The default value for transient variable " << variable.getName() << " is higher than its upper bound.");
40}
41
42template<typename VariableType>
47
48template<typename ValueType>
54
55template<typename ValueType>
57 return booleanValues.empty() && integerValues.empty() && rationalValues.empty();
58}
59
60template<typename ValueType>
62 for (auto const& varValue : booleanValues) {
63 evaluator.setBooleanValue(varValue.first->variable, varValue.second);
64 }
65 for (auto const& varValue : integerValues) {
66 if (explorationChecks) {
67 STORM_LOG_THROW(!varValue.first->lowerBound.is_initialized() || varValue.first->lowerBound.get() <= varValue.second,
68 storm::exceptions::OutOfRangeException,
69 "The assigned value for transient variable " << varValue.first->variable.getName() << " is smaller than its lower bound.");
70 STORM_LOG_THROW(!varValue.first->upperBound.is_initialized() || varValue.second <= varValue.first->upperBound.get(),
71 storm::exceptions::OutOfRangeException,
72 "The assigned value for transient variable " << varValue.first->variable.getName() << " is higher than its upper bound.");
73 }
74 evaluator.setIntegerValue(varValue.first->variable, varValue.second);
75 }
76 for (auto const& varValue : rationalValues) {
77 evaluator.setRationalValue(varValue.first->variable, varValue.second);
78 }
79}
80
81template<typename ValueType>
84 auto writeValues = [stateIndex, &valuations](auto const& varInfos, auto const& varValues) {
85 auto varIt = varValues.begin();
86 auto const varIte = varValues.end();
87 for (auto const& varInfo : varInfos) {
88 bool const hasValue = varIt != varIte && varIt->first->variable == varInfo.variable;
89 auto const& value = hasValue ? varIt->second : varInfo.defaultValue;
90 if (hasValue) {
91 ++varIt;
92 }
93 if constexpr (std::is_same_v<std::remove_cvref_t<decltype(value)>, storm::RationalFunction>) {
95 storm::utility::isConstant(value), storm::exceptions::NotSupportedException,
96 "Non-constant variable valuations are not supported. Got value " << value << " for variable " << varInfo.variable.getName() << ".");
97 valuations.writeValue(stateIndex, varInfo.variable, storm::utility::convertNumber<storm::RationalNumber>(value));
98 } else {
99 valuations.writeValue(stateIndex, varInfo.variable, value);
100 }
101 }
102 };
103 writeValues(info.booleanVariableInformation, booleanValues);
104 writeValues(info.integerVariableInformation, integerValues);
106}
107
108template<typename ValueType>
110 storm::jani::Model const& model, std::vector<std::reference_wrapper<storm::jani::Automaton const>> const& parallelAutomata) {
111 createVariablesForVariableSet(model.getGlobalVariables(), true);
112
113 for (auto const& automatonRef : parallelAutomata) {
114 createVariablesForAutomaton(automatonRef.get());
115 }
116
117 sortVariables();
118}
119
120template<typename ValueType>
123 // Find for each replaced array variable the corresponding references in this variable information
124 for (auto const& arrayVariable : arrayEliminatorData.eliminatedArrayVariables) {
125 if (arrayVariable->isTransient()) {
126 auto findRes = arrayEliminatorData.replacements.find(arrayVariable->getExpressionVariable());
127 STORM_LOG_ASSERT(findRes != arrayEliminatorData.replacements.end(), "No replacement for array variable.");
128 auto const& replacements = findRes->second;
129 auto const& innerType = arrayVariable->getType().asArrayType().getBaseTypeRecursive();
130 if (innerType.isBasicType() && innerType.asBasicType().isBooleanType()) {
131 auto replInfo = convertArrayReplacement(replacements, booleanVariableInformation);
132 this->arrayVariableToElementInformations.emplace(arrayVariable->getExpressionVariable(), std::move(replInfo));
133 } else if ((innerType.isBasicType() && innerType.asBasicType().isIntegerType()) ||
134 (innerType.isBoundedType() && innerType.asBoundedType().isIntegerType())) {
135 auto replInfo = convertArrayReplacement(replacements, integerVariableInformation);
136 this->arrayVariableToElementInformations.emplace(arrayVariable->getExpressionVariable(), std::move(replInfo));
137 } else if ((innerType.isBasicType() && innerType.asBasicType().isRealType()) ||
138 (innerType.isBoundedType() && innerType.asBoundedType().isRealType())) {
139 auto replInfo = convertArrayReplacement(replacements, rationalVariableInformation);
140 this->arrayVariableToElementInformations.emplace(arrayVariable->getExpressionVariable(), std::move(replInfo));
141 } else {
142 STORM_LOG_THROW(false, storm::exceptions::UnexpectedException, "Unhandled type of base variable.");
143 }
144 }
145 }
146}
147
148template<typename ValueType>
150 storm::expressions::Variable const& arrayVariable, std::vector<uint64_t> const& arrayIndexVector) const {
151 return booleanVariableInformation[arrayVariableToElementInformations.at(arrayVariable).getVariableInformationIndex(arrayIndexVector)];
152}
153
154template<typename ValueType>
156 storm::expressions::Variable const& arrayVariable, std::vector<uint64_t> const& arrayIndexVector) const {
157 return integerVariableInformation[arrayVariableToElementInformations.at(arrayVariable).getVariableInformationIndex(arrayIndexVector)];
158}
159
160template<typename ValueType>
162 storm::expressions::Variable const& arrayVariable, std::vector<uint64_t> const& arrayIndexVector) const {
163 return rationalVariableInformation[arrayVariableToElementInformations.at(arrayVariable).getVariableInformationIndex(arrayIndexVector)];
164}
165
166template<typename ValueType>
167void TransientVariableInformation<ValueType>::createVariablesForAutomaton(storm::jani::Automaton const& automaton) {
168 createVariablesForVariableSet(automaton.getVariables(), false);
169}
170
171template<typename ValueType>
172void TransientVariableInformation<ValueType>::createVariablesForVariableSet(storm::jani::VariableSet const& variableSet, bool global) {
173 for (auto const& variable : variableSet.getBooleanVariables()) {
174 if (variable.isTransient()) {
175 booleanVariableInformation.emplace_back(variable.getExpressionVariable(), variable.getInitExpression().evaluateAsBool(), global);
176 }
177 }
178 for (auto const& variable : variableSet.getBoundedIntegerVariables()) {
179 if (variable.isTransient()) {
180 boost::optional<int64_t> lowerBound;
181 boost::optional<int64_t> upperBound;
182 auto const& type = variable.getType().asBoundedType();
183 if (type.hasLowerBound()) {
184 lowerBound = type.getLowerBound().evaluateAsInt();
185 }
186 if (type.hasUpperBound()) {
187 upperBound = type.getUpperBound().evaluateAsInt();
188 }
189 integerVariableInformation.emplace_back(variable.getExpressionVariable(), lowerBound, upperBound, variable.getInitExpression().evaluateAsInt(),
190 global);
191 }
192 }
193 for (auto const& variable : variableSet.getUnboundedIntegerVariables()) {
194 if (variable.isTransient()) {
195 integerVariableInformation.emplace_back(variable.getExpressionVariable(), variable.getInitExpression().evaluateAsInt(), global);
196 }
197 }
198 for (auto const& variable : variableSet.getRealVariables()) {
199 if (variable.isTransient()) {
200 rationalVariableInformation.emplace_back(variable.getExpressionVariable(),
201 storm::utility::convertNumber<ValueType>(variable.getInitExpression().evaluateAsRational()), global);
202 }
203 }
204}
205
206template<typename ValueType>
207void TransientVariableInformation<ValueType>::sortVariables() {
208 // Sort the variables so we can make some assumptions when iterating over them (in the next-state generators).
209 std::sort(booleanVariableInformation.begin(), booleanVariableInformation.end(),
210 [](TransientVariableData<bool> const& a, TransientVariableData<bool> const& b) { return a.variable < b.variable; });
211 std::sort(integerVariableInformation.begin(), integerVariableInformation.end(),
212 [](TransientVariableData<int64_t> const& a, TransientVariableData<int64_t> const& b) { return a.variable < b.variable; });
213 std::sort(rationalVariableInformation.begin(), rationalVariableInformation.end(),
214 [](TransientVariableData<ValueType> const& a, TransientVariableData<ValueType> const& b) { return a.variable < b.variable; });
215}
216
217template<typename ValueType>
219 for (auto const& variableData : booleanVariableInformation) {
220 evaluator.setBooleanValue(variableData.variable, variableData.defaultValue);
221 }
222 for (auto const& variableData : integerVariableInformation) {
223 evaluator.setIntegerValue(variableData.variable, variableData.defaultValue);
224 }
225 for (auto const& variableData : rationalVariableInformation) {
226 evaluator.setRationalValue(variableData.variable, variableData.defaultValue);
227 }
228}
229
236
237} // namespace generator
238} // namespace storm
VariableSet & getVariables()
Retrieves the variables of this automaton.
Definition Automaton.cpp:59
VariableSet & getGlobalVariables()
Retrieves the variables of this automaton.
Definition Model.cpp:717
detail::Variables< Variable > getBoundedIntegerVariables()
Retrieves the bounded integer variables in this set.
detail::Variables< Variable > getUnboundedIntegerVariables()
Retrieves the unbounded integer variables in this set.
detail::Variables< Variable > getRealVariables()
Retrieves the real variables in this set.
detail::Variables< Variable > getBooleanVariables()
Retrieves the boolean variables in this set.
Stores valuations of variables for a set of entities (e.g.
void writeValue(uint64_t entity, storm::expressions::Variable const &variable, ValueType const &value)
Directly writes value to the given variable of entity.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
ArrayVariableReplacementInformation convertArrayReplacement(typename storm::jani::ArrayEliminatorData::Replacement const &replacement, InfoType const &relevantVariableInfo)
bool isConstant(ValueType const &)
TargetType convertNumber(SourceType const &number)
carl::RationalFunction< Polynomial, true > RationalFunction
TransientVariableData(storm::expressions::Variable const &variable, boost::optional< VariableType > const &lowerBound, boost::optional< VariableType > const &upperBound, VariableType const &defaultValue, bool global=false)
std::vector< TransientVariableData< bool > > booleanVariableInformation
void registerArrayVariableReplacements(storm::jani::ArrayEliminatorData const &arrayEliminatorData)
void setDefaultValuesInEvaluator(storm::expressions::ExpressionEvaluator< ValueType > &evaluator) const
std::vector< TransientVariableData< ValueType > > rationalVariableInformation
std::unordered_map< storm::expressions::Variable, ArrayVariableReplacementInformation > arrayVariableToElementInformations
Replacements for each array variable.
TransientVariableData< int64_t > const & getIntegerArrayVariableReplacement(storm::expressions::Variable const &arrayVariable, std::vector< uint64_t > const &arrayIndexVector) const
std::vector< TransientVariableData< int64_t > > integerVariableInformation
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::vector< std::pair< TransientVariableData< ValueType > const *, ValueType > > rationalValues
std::vector< std::pair< TransientVariableData< bool > const *, bool > > booleanValues
void setInEvaluator(storm::expressions::ExpressionEvaluator< ValueType > &evaluator, bool explorationChecks) const
std::vector< std::pair< TransientVariableData< int64_t > const *, int64_t > > integerValues
void setInValuations(uint64_t const stateIndex, TransientVariableInformation< ValueType > const &info, storm::storage::sparse::ValuationsStorage &valuations) const
std::unordered_map< storm::expressions::Variable, Replacement > replacements
std::vector< std::shared_ptr< Variable > > eliminatedArrayVariables