10namespace expressions {
13 std::unordered_map<std::string, uint_fast64_t>::const_iterator nameIndexIteratorEnd,
VariableSelection const& selection)
14 : manager(manager), nameIndexIterator(nameIndexIterator), nameIndexIteratorEnd(nameIndexIteratorEnd), selection(selection) {
15 moveUntilNextSelectedElement(
false);
19 return this->nameIndexIterator == other.nameIndexIterator;
23 return !(*
this == other);
27 return currentElement;
31 moveUntilNextSelectedElement();
36 moveUntilNextSelectedElement();
40void VariableIterator::moveUntilNextSelectedElement(
bool atLeastOneStep) {
41 if (atLeastOneStep && nameIndexIterator != nameIndexIteratorEnd) {
46 while (nameIndexIterator != nameIndexIteratorEnd &&
52 if (nameIndexIterator != nameIndexIteratorEnd) {
58 : nameToIndexMapping(),
61 numberOfBooleanVariables(0),
62 numberOfIntegerVariables(0),
63 numberOfBitVectorVariables(0),
64 numberOfRationalVariables(0),
65 numberOfArrayVariables(0),
66 numberOfAuxiliaryVariables(0),
67 numberOfAuxiliaryBooleanVariables(0),
68 numberOfAuxiliaryIntegerVariables(0),
69 numberOfAuxiliaryBitVectorVariables(0),
70 numberOfAuxiliaryRationalVariables(0),
71 numberOfAuxiliaryArrayVariables(0),
72 freshVariableCounter(0) {
85 return Expression(std::make_shared<BooleanLiteralExpression>(*
this, value));
89 return Expression(std::make_shared<IntegerLiteralExpression>(*
this, value));
93 return Expression(std::make_shared<RationalLiteralExpression>(*
this, value));
97 return Expression(std::make_shared<RationalLiteralExpression>(*
this, value));
101 return this == &other;
108 return booleanType.get();
115 return integerType.get();
120 auto typeIterator = bitvectorTypes.find(type);
121 if (typeIterator == bitvectorTypes.end()) {
122 auto iteratorBoolPair = bitvectorTypes.insert(type);
123 return *iteratorBoolPair.first;
125 return *typeIterator;
132 return rationalType.get();
137 return *arrayTypes.insert(type).first;
141 if (!transcendentalNumberType) {
144 return transcendentalNumberType.get();
147bool ExpressionManager::isValidVariableName(std::string
const& name) {
148 return name.size() < 2 || name.at(0) !=
'_' || name.at(1) !=
'_';
151bool ExpressionManager::variableExists(std::string
const& name)
const {
152 auto nameIndexPair = nameToIndexMapping.find(name);
153 return nameIndexPair != nameToIndexMapping.end();
161 STORM_LOG_THROW(!variableExists(name), storm::exceptions::InvalidArgumentException,
"Variable with name '" << name <<
"' already exists.");
191 STORM_LOG_THROW(!checkName || isValidVariableName(name), storm::exceptions::InvalidArgumentException,
"Invalid variable name '" << name <<
"'.");
192 auto nameIndexPair = nameToIndexMapping.find(name);
193 if (nameIndexPair != nameToIndexMapping.end()) {
194 STORM_LOG_ASSERT(indexToTypeMapping.at(nameIndexPair->second) == variableType,
"Tried to declareOrGet variable '"
195 << name <<
"' of type '" << variableType
196 <<
"' but there is a variable with that name and different type '"
197 << indexToTypeMapping.at(nameIndexPair->second) <<
"'.");
203 offset = numberOfBooleanVariables++;
205 offset = numberOfIntegerVariables++ + numberOfBitVectorVariables;
207 offset = numberOfBitVectorVariables++ + numberOfIntegerVariables;
209 offset = numberOfRationalVariables++;
211 offset = numberOfArrayVariables++;
218 uint64_t newIndex = offset | variableType.
getMask() | (auxiliary ? auxiliaryMask : 0);
221 nameToIndexMapping[name] = newIndex;
222 indexToNameMapping[newIndex] = name;
223 indexToTypeMapping[newIndex] = variableType;
225 variableSet.insert(result);
231 auto nameIndexPair = nameToIndexMapping.find(name);
232 STORM_LOG_THROW(nameIndexPair != nameToIndexMapping.end(), storm::exceptions::InvalidArgumentException,
"Unknown variable '" << name <<
"'.");
245 return nameToIndexMapping.find(name) != nameToIndexMapping.end();
249 std::string newName = prefix + std::to_string(freshVariableCounter++);
267 return numberOfBooleanVariables;
269 return numberOfIntegerVariables;
271 return numberOfBitVectorVariables;
273 return numberOfRationalVariables;
275 return numberOfArrayVariables;
281 return numberOfBooleanVariables + numberOfIntegerVariables + numberOfBitVectorVariables + numberOfRationalVariables + numberOfArrayVariables;
285 return numberOfBooleanVariables;
289 return numberOfIntegerVariables;
293 return numberOfBitVectorVariables;
297 return numberOfRationalVariables;
301 return numberOfRationalVariables;
305 auto indexTypeNamePair = indexToNameMapping.find(index);
306 STORM_LOG_THROW(indexTypeNamePair != indexToNameMapping.end(), storm::exceptions::InvalidArgumentException,
"Unknown variable index '" << index <<
"'.");
307 return indexTypeNamePair->second;
311 auto indexTypePair = indexToTypeMapping.find(index);
312 STORM_LOG_ASSERT(indexTypePair != indexToTypeMapping.end(),
"Unable to retrieve type of unknown variable index '" << index <<
"'.");
313 return indexTypePair->second;
317 return index & offsetMask;
331 return this->shared_from_this();
335 return this->shared_from_this();
339 out <<
"manager {\n";
341 for (
auto const& variableTypePair : manager) {
342 out <<
"\t" << variableTypePair.second <<
" " << variableTypePair.first.getName() <<
" [offset " << variableTypePair.first.getOffset() <<
", "
343 << variableTypePair.first.getIndex() <<
" ]\n";
This class is responsible for managing a set of typed variables and all expressions using these varia...
Variable declareFreshIntegerVariable(bool auxiliary=false, std::string const &prefix="_x")
Declares a variable with integer type whose name is guaranteed to be unique and not yet in use.
Type const & getTranscendentalNumberType() const
Retrieves the transcendental numbers type (i.e.
Type const & getBitVectorType(std::size_t width) const
Retrieves the bit vector type of the given width.
std::set< Variable > const & getVariables() const
Retrieves the set of all variables known to this manager.
Type const & getArrayType(Type elementType) const
Retrieves the array type with the given element type.
uint_fast64_t getNumberOfIntegerVariables() const
Retrieves the number of integer variables.
uint_fast64_t getNumberOfBooleanVariables() const
Retrieves the number of boolean variables.
Variable declareFreshBooleanVariable(bool auxiliary=false, std::string const &prefix="_x")
Declares a variable with Boolean type whose name is guaranteed to be unique and not yet in use.
Variable declareRationalVariable(std::string const &name, bool auxiliary=false)
Declares a new rational variable with a name that must not yet exist and its corresponding type.
uint_fast64_t getNumberOfArrayVariables() const
Retrieves the number of array variables.
Variable declareBooleanVariable(std::string const &name, bool auxiliary=false)
Declares a new boolean variable with a name that must not yet exist and its corresponding type.
Expression integer(int_fast64_t value) const
Creates an expression that characterizes the given integer literal.
Type const & getVariableType(uint_fast64_t index) const
Retrieves the type of the variable with the given index.
bool hasVariable(std::string const &name) const
Retrieves whether a variable with the given name is known to the manager.
Variable declareOrGetVariable(std::string const &name, storm::expressions::Type const &variableType, bool auxiliary=false)
Declares a variable with the given name if it does not yet exist.
std::shared_ptr< ExpressionManager > clone() const
Creates a new expression manager with the same set of variables.
Type const & getBooleanType() const
Retrieves the boolean type.
const_iterator end() const
Retrieves an iterator that points beyond the last variable managed by this manager.
uint_fast64_t getOffset(uint_fast64_t index) const
Retrieves the offset of the variable with the given index within the group of equally typed variables...
const_iterator begin() const
Retrieves an iterator to all variables managed by this manager.
Variable declareVariable(std::string const &name, storm::expressions::Type const &variableType, bool auxiliary=false)
Declares a variable with a name that must not yet exist and its corresponding type.
ExpressionManager()
Creates a new manager that is unaware of any variables.
Type const & getIntegerType() const
Retrieves the unbounded integer type.
uint_fast64_t getNumberOfVariables() const
Retrieves the number of variables.
Variable declareFreshRationalVariable(bool auxiliary=false, std::string const &prefix="_x")
Declares a variable with rational type whose name is guaranteed to be unique and not yet in use.
Variable declareVariableCopy(Variable const &variable)
Declares a variable that is a copy of the provided variable (i.e.
Variable declareIntegerVariable(std::string const &name, bool auxiliary=false)
Declares a new integer variable with a name that must not yet exist and its corresponding type.
bool operator==(ExpressionManager const &other) const
Compares the two expression managers for equality, which holds iff they are the very same object.
uint_fast64_t getNumberOfRationalVariables() const
Retrieves the number of rational variables.
uint_fast64_t getNumberOfBitVectorVariables() const
Retrieves the number of bit vector variables.
Variable declareArrayVariable(std::string const &name, Type const &elementType, bool auxiliary=false)
Declares a new array variable with the given name and the given element type.
Expression getVariableExpression(std::string const &name) const
Retrieves an expression that represents the variable with the given name.
VariableIterator const_iterator
Expression rational(double value) const
Creates an expression that characterizes the given rational literal.
Variable declareFreshVariable(storm::expressions::Type const &variableType, bool auxiliary=false, std::string const &prefix="_x")
Declares a variable with the given type whose name is guaranteed to be unique and not yet in use.
std::string const & getVariableName(uint_fast64_t index) const
Retrieves the name of the variable with the given index.
std::shared_ptr< ExpressionManager > getSharedPointer()
Retrieves a shared pointer to the expression manager.
Type const & getRationalType() const
Retrieves the rational type.
Variable declareBitVectorVariable(std::string const &name, std::size_t width, bool auxiliary=false)
Declares a new bit vector variable with a name that must not yet exist and the bounded type of the gi...
Variable getVariable(std::string const &name) const
Retrieves the expression that represents the variable with the given name.
Expression boolean(bool value) const
Creates an expression that characterizes the given boolean literal.
bool isBooleanType() const
Checks whether this type is a boolean type.
bool isIntegerType() const
Checks whether this type is an integral type.
bool isArrayType() const
Checks whether this type is an array type.
std::string getStringRepresentation() const
Retrieves a string representation of the type.
uint64_t getMask() const
Retrieves the bit mask of the type.
bool isRationalType() const
Checks whether this type is a rational type.
bool isBitVectorType() const
Checks whether this type is a bitvector type.
Type const & getType() const
Retrieves the type of the variable.
std::string const & getName() const
Retrieves the name of the variable.
VariableIterator(ExpressionManager const &manager, std::unordered_map< std::string, uint_fast64_t >::const_iterator nameIndexIterator, std::unordered_map< std::string, uint_fast64_t >::const_iterator nameIndexIteratorEnd, VariableSelection const &selection)
bool operator!=(VariableIterator const &other)
bool operator==(VariableIterator const &other)
std::pair< storm::expressions::Variable, storm::expressions::Type > const value_type
VariableIterator & operator++()
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
std::ostream & operator<<(std::ostream &stream, BaseExpression const &expression)