72std::vector<std::shared_ptr<Variable>>& VariableSet::getVariableVectorForType(
JaniType const& type) {
76 return booleanVariables;
78 return unboundedIntegerVariables;
85 return boundedIntegerVariables;
87 STORM_LOG_THROW(
false, storm::exceptions::InvalidTypeException,
"Cannot add variable of bounded real type.");
90 return arrayVariables;
92 return clockVariables;
94 return continuousVariables;
96 STORM_LOG_THROW(
false, storm::exceptions::InvalidTypeException,
"Unhandled variable type" << type);
101 "Cannot add variable with name '" << variable.
getName() <<
"', because a variable with that name already exists.");
102 std::shared_ptr<Variable> newVariable = variable.
clone();
103 variables.push_back(newVariable);
105 transientVariables.push_back(newVariable);
110 auto& variableVectorForType = getVariableVectorForType(variable.
getType());
111 variableVectorForType.push_back(newVariable);
116 if (!arrayVariables.empty()) {
117 for (
auto const& arrVar : arrayVariables) {
118 nameToVariable.erase(arrVar->getName());
119 variableToVariable.erase(arrVar->getExpressionVariable());
121 std::vector<std::shared_ptr<Variable>> newVariables;
122 for (
auto const& v : variables) {
123 if (!v->getType().isArrayType()) {
124 newVariables.push_back(v);
127 variables = std::move(newVariables);
128 newVariables.clear();
129 for (
auto const& v : transientVariables) {
130 if (!v->getType().isArrayType()) {
131 newVariables.push_back(v);
134 transientVariables = std::move(newVariables);
137 std::vector<std::shared_ptr<Variable>> result = std::move(arrayVariables);
138 arrayVariables.clear();
143 return nameToVariable.find(name) != nameToVariable.end();
151 auto it = nameToVariable.find(name);
152 STORM_LOG_THROW(it != nameToVariable.end(), storm::exceptions::InvalidArgumentException,
"Unable to retrieve unknown variable '" << name <<
"'.");
156template<
typename VarType>
158 for (
auto vIt = varVec.begin(); vIt != varVec.end(); ++vIt) {
159 if ((*vIt)->getExpressionVariable() == variable) {
167 auto vToVIt = variableToVariable.find(variable);
168 STORM_LOG_THROW(vToVIt != variableToVariable.end(), storm::exceptions::InvalidArgumentException,
169 "Unable to erase unknown variable '" << variable.
getName() <<
"'.");
170 std::shared_ptr<Variable> janiVar = std::move(vToVIt->second);
171 variableToVariable.erase(vToVIt);
173 nameToVariable.erase(janiVar->getName());
176 if (janiVar->isTransient()) {
199 auto it = variableToVariable.find(variable);
200 STORM_LOG_THROW(it != variableToVariable.end(), storm::exceptions::InvalidArgumentException,
201 "Unable to retrieve unknown variable '" << variable.
getName() <<
"'.");
206 return variableToVariable.find(variable) != variableToVariable.end();
210 for (
auto const& variable : variables) {
211 if (variable->isTransient()) {
219 return !booleanVariables.empty();
223 return !boundedIntegerVariables.empty();
227 return !unboundedIntegerVariables.empty();
231 return !realVariables.empty();
235 return !arrayVariables.empty();
239 return !clockVariables.empty();
243 return !continuousVariables.empty();
247 for (
auto const& variable : realVariables) {
248 if (!variable->isTransient()) {
256 for (
auto const& variable : unboundedIntegerVariables) {
257 if (!variable->isTransient()) {
270 return variables.size();
278 uint_fast64_t result = 0;
279 for (
auto const& variable : variables) {
280 if (variable->isTransient()) {
288 uint_fast64_t result = 0;
289 for (
auto const& variable : realVariables) {
290 if (variable->isTransient()) {
298 uint_fast64_t result = 0;
299 for (
auto const& variable : unboundedIntegerVariables) {
300 if (variable->isTransient()) {
308 uint_fast64_t result = 0;
309 for (
auto const& variable : transientVariables) {
310 auto const& type = variable->getType();
325 for (
auto const& variable : this->variables) {
326 if (variable->hasInitExpression() && variable->getInitExpression().containsVariable(variables)) {
329 auto const& varType = variable->getType();
330 auto const& type = varType.
isArrayType() ? varType.asArrayType().getBaseTypeRecursive() : varType;
333 if (boundedType.hasLowerBound() && boundedType.getLowerBound().containsVariable(variables)) {
336 if (boundedType.hasUpperBound() && boundedType.getUpperBound().containsVariable(variables)) {
345 std::map<std::string, std::reference_wrapper<Variable const>> result;
347 for (
auto const& variable : variables) {
348 result.emplace(variable->getName(), *variable);
355 bool const substituteTranscendentalNumbers) {
356 for (
auto& variable : variables) {
357 variable->substitute(substitution, substituteTranscendentalNumbers);
362 for (
auto& variable : variables) {
363 auto varIt = substitution.find(variable->getExpressionVariable());
364 if (varIt != substitution.end()) {
365 STORM_LOG_ASSERT(varIt->second.isVariable(),
"Expected that variables are only substituted by other variables. However, we substitute "
366 << varIt->first.getName() <<
" by " << varIt->second <<
".");
367 variable->setExpressionVariable(varIt->second.getBaseExpression().asVariableExpression().getVariable());
static iterator make_iterator(input_iterator it)
boost::transform_iterator< Dereferencer< value_type >, input_iterator > iterator
std::string const & getName() const
Retrieves the name of the variable.
bool isIntegerType() const
BaseType const & getBaseType() const
bool isIntegerType() const
virtual bool isContinuousType() const
virtual bool isArrayType() const
virtual bool isBoundedType() const
virtual bool isBasicType() const
BoundedType const & asBoundedType() const
virtual bool isClockType() const
BasicType const & asBasicType() const
std::unique_ptr< Variable > clone() const
Clones the variable.
storm::expressions::Variable const & getExpressionVariable() const
Retrieves the associated expression variable.
std::string const & getName() const
Retrieves the name of the variable.
bool containsArrayVariables() const
Retrieves whether the set of variables contains a Array variable.
detail::Variables< Variable > getBoundedIntegerVariables()
Retrieves the bounded integer variables in this set.
bool containsNonTransientRealVariables() const
Retrieves whether the set of variables contains a non-transient real variable.
Variable const & addVariable(Variable const &variable)
Adds the given variable to this set.
bool hasVariable(std::string const &name) const
Retrieves whether this variable set contains a variable with the given name.
uint64_t getNumberOfUnboundedIntegerTransientVariables() const
Retrieves the number of unbounded integer transient variables in this variable set.
detail::Variables< Variable > getUnboundedIntegerVariables()
Retrieves the unbounded integer variables in this set.
detail::Variables< Variable > getRealVariables()
Retrieves the real variables in this set.
uint64_t getNumberOfNumericalTransientVariables() const
Retrieves the number of numerical (i.e.
VariableSet()
Creates an empty variable set.
void substitute(std::map< storm::expressions::Variable, storm::expressions::Expression > const &substitution, bool const substituteTranscendentalNumbers)
Applies the given substitution to all variables in this set.
detail::Variables< Variable >::iterator end()
Retrieves the end iterator to the variables in this set.
bool hasTransientVariable() const
Retrieves whether this variable set contains a transient variable.
bool containsContinuousVariables() const
Retrieves whether the set of variables contains a clock variable.
bool containsBooleanVariable() const
Retrieves whether the set of variables contains a boolean variable.
std::shared_ptr< Variable > eraseVariable(storm::expressions::Variable const &variable)
Erases the given variable from this set.
Variable const & getVariable(std::string const &name) const
Retrieves the variable with the given name.
detail::Variables< Variable > getContinuousVariables()
Retrieves the continous variables in this set.
uint64_t getNumberOfVariables() const
Total number of variables, including transient variables.
bool containsUnboundedIntegerVariables() const
Retrieves whether the set of variables contains an unbounded integer variable.
uint64_t getNumberOfNontransientVariables() const
bool containsNonTransientUnboundedIntegerVariables() const
Retrieves whether the set of variables contains a non-transient unbounded integer variable.
bool containsBoundedIntegerVariable() const
Retrieves whether the set of variables contains a bounded integer variable.
std::vector< std::shared_ptr< Variable > > dropAllArrayVariables()
Removes all array variables in this set.
bool containsRealVariables() const
Retrieves whether the set of variables contains a real variable.
bool empty() const
Retrieves whether this variable set is empty.
detail::Variables< Variable > getClockVariables()
Retrieves the clock variables in this set.
uint64_t getNumberOfTransientVariables() const
Retrieves the number of transient variables in this variable set.
bool containsVariablesInBoundExpressionsOrInitialValues(std::set< storm::expressions::Variable > const &variables) const
Checks whether any of the provided variables appears in bound expressions or initial values of the va...
void substituteExpressionVariables(std::map< storm::expressions::Variable, storm::expressions::Expression > const &substitution)
Substitutes the actual variables according to the given substitution.
detail::Variables< Variable >::iterator begin()
Retrieves an iterator to the variables in this set.
bool containsClockVariables() const
Retrieves whether the set of variables contains a clock variable.
std::map< std::string, std::reference_wrapper< Variable const > > getNameToVariableMap() const
Retrieves a mapping from variable names to (references of) the variable objects.
detail::Variables< Variable > getBooleanVariables()
Retrieves the boolean variables in this set.
detail::Variables< Variable > getArrayVariables()
Retrieves the Array variables in this set.
uint64_t getNumberOfRealTransientVariables() const
Retrieves the number of real transient variables in this variable set.
detail::ConstVariables< Variable > getTransientVariables() const
Retrieves the transient variables in this variable set.
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
storm::adapters::DereferenceIteratorAdapter< std::vector< std::shared_ptr< VariableType > > const > ConstVariables
storm::adapters::DereferenceIteratorAdapter< std::vector< std::shared_ptr< VariableType > > > Variables
void eraseFromVariableVector(std::vector< std::shared_ptr< VarType > > &varVec, storm::expressions::Variable const &variable)