#ifndef STORM_STORAGE_DD_DDMANAGER_H_ #define STORM_STORAGE_DD_DDMANAGER_H_ #include #include #include #include "storm/storage/dd/DdType.h" #include "storm/storage/dd/DdMetaVariable.h" #include "storm/storage/dd/MetaVariablePosition.h" #include "storm/storage/dd/Bdd.h" #include "storm/storage/dd/Add.h" #include "storm/storage/dd/AddIterator.h" #include "storm/storage/expressions/Variable.h" #include "storm/storage/dd/cudd/InternalCuddDdManager.h" #include "storm/storage/dd/sylvan/InternalSylvanDdManager.h" namespace storm { namespace dd { // Declare DdManager class so we can then specialize it for the different DD types. template class DdManager : public std::enable_shared_from_this> { public: friend class Bdd; template friend class Add; template friend class AddIterator; /*! * Creates an empty manager without any meta variables. */ DdManager(); // Explictly forbid copying a DdManager, but allow moving it. DdManager(DdManager const& other) = delete; DdManager& operator=(DdManager const& other) = delete; DdManager(DdManager&& other) = default; DdManager& operator=(DdManager&& other) = default; std::shared_ptr> asSharedPointer(); std::shared_ptr const> asSharedPointer() const; /*! * Retrieves a BDD representing the constant one function. * * @return A BDD representing the constant one function. */ Bdd getBddOne() const; /*! * Retrieves an ADD representing the constant one function. * * @return An ADD representing the constant one function. */ template Add getAddOne() const; /*! * Retrieves a BDD representing the constant zero function. * * @return A BDD representing the constant zero function. */ Bdd getBddZero() const; /*! * Retrieves an ADD representing the constant zero function. * * @return An ADD representing the constant zero function. */ template Add getAddZero() const; /*! * Retrieves an ADD representing the an undefined value. * * @return An ADD representing an undefined value. */ template Add getAddUndefined() const; /*! * Retrieves an ADD representing the constant infinity function. * * @return An ADD representing the constant infinity function. */ template Add getInfinity() const; /*! * Retrieves an ADD representing the constant function with the given value. * * @return An ADD representing the constant function with the given value. */ template Add getConstant(ValueType const& value) const; /*! * Retrieves the BDD representing the function that maps all inputs which have the given meta variable equal * to the given value one. * * @param variable The expression variable associated with the meta variable. * @param value The value the meta variable is supposed to have. * @param mostSignificantBitAtTop A flag indicating whether the most significant bit of the value is to be * encoded with the topmost variable or the bottommost. * @return The DD representing the function that maps all inputs which have the given meta variable equal * to the given value one. */ Bdd getEncoding(storm::expressions::Variable const& variable, int_fast64_t value, bool mostSignificantBitAtTop = true) const; /*! * Retrieves the BDD representing the range of the meta variable, i.e., a function that maps all legal values * of the range of the meta variable to one. * * @param variable The expression variable associated with the meta variable. * @return The range of the meta variable. */ Bdd getRange(storm::expressions::Variable const& variable) const; /*! * Retrieves the ADD representing the identity of the meta variable, i.e., a function that maps all legal * values of the range of the meta variable to the values themselves. * * @param variable The expression variable associated with the meta variable. * @return The identity of the meta variable. */ template Add getIdentity(storm::expressions::Variable const& variable) const; /*! * Retrieves a BDD that is the cube of the variables representing the given meta variable. * * @param variable The expression variable associated with the meta variable. * @return The cube of the meta variable. */ Bdd getCube(storm::expressions::Variable const& variable) const; /*! * Retrieves a BDD that is the cube of the variables representing the given meta variables. * * @param variables The expression variables associated with the meta variables. * @return The cube of the meta variables. */ Bdd getCube(std::set const& variables) const; /*! * Adds an integer meta variable with the given range with two layers (a 'normal' and a 'primed' one). * * @param variableName The name of the new variable. * @param low The lowest value of the range of the variable. * @param high The highest value of the range of the variable. */ std::pair addMetaVariable(std::string const& variableName, int_fast64_t low, int_fast64_t high, boost::optional> const& position = boost::none); /*! * Creates a meta variable with the given number of layers. * * @param variableName The name of the variable. * @param numberOfLayers The number of layers of this variable (must be greater or equal 1). */ std::vector addMetaVariable(std::string const& variableName, int_fast64_t low, int_fast64_t high, uint64_t numberOfLayers, boost::optional> const& position = boost::none); /*! * Creates a meta variable with the given number of layers. * * @param variableName The name of the variable. * @param numberOfLayers The number of layers of this variable (must be greater or equal 1). */ std::vector addBitVectorMetaVariable(std::string const& variableName, uint64_t bits, uint64_t numberOfLayers, boost::optional> const& position = boost::none); /*! * Adds a boolean meta variable with two layers (a 'normal' and a 'primed' one). * * @param variableName The name of the new variable. */ std::pair addMetaVariable(std::string const& variableName, boost::optional> const& position = boost::none); /*! * Creates a meta variable with the given number of layers. * * @param variableName The name of the variable. * @param numberOfLayers The number of layers of this variable (must be greater or equal 1). */ std::vector addMetaVariable(std::string const& variableName, uint64_t numberOfLayers, boost::optional> const& position = boost::none); /*! * Retrieves the names of all meta variables that have been added to the manager. * * @return The set of all meta variable names of the manager. */ std::set getAllMetaVariableNames() const; /*! * Retrieves the number of meta variables that are contained in this manager. * * @return The number of meta variables contained in this manager. */ std::size_t getNumberOfMetaVariables() const; /*! * Retrieves whether the given meta variable name is already in use. * * @param variableName The name of the variable. * @return True if the given meta variable name is managed by this manager. */ bool hasMetaVariable(std::string const& variableName) const; /*! * Retrieves the given meta variable by name. * * @param variableName The name of the variable. * @return The meta variable. */ storm::expressions::Variable getMetaVariable(std::string const& variableName) const; /*! * Checks whether this manager supports the ordered insertion of variables, i.e. inserting variables at * positions between already existing variables. * * @return True iff the manager supports ordered insertion. */ bool supportsOrderedInsertion() const; /*! * Sets whether or not dynamic reordering is allowed for the DDs managed by this manager (if supported). * * @param value If set to true, dynamic reordering is allowed and forbidden otherwise. */ void allowDynamicReordering(bool value); /*! * Retrieves whether dynamic reordering is currently allowed (if supported). * * @return True iff dynamic reordering is currently allowed. */ bool isDynamicReorderingAllowed() const; /*! * Triggers a reordering of the DDs managed by this manager (if supported). */ void triggerReordering(); /*! * Retrieves the meta variable with the given name if it exists. * * @param variable The expression variable associated with the meta variable. * @return The corresponding meta variable. */ DdMetaVariable const& getMetaVariable(storm::expressions::Variable const& variable) const; /*! * Retrieves the set of meta variables contained in the DD. * * @return All contained meta variables. */ std::set getAllMetaVariables() const; /*! * Retrieves the (sorted) list of the variable indices of the DD variables given by the meta variable set. * * @param manager The manager responsible for the DD. * @param metaVariable The set of meta variables for which to retrieve the index list. * @return The sorted list of variable indices. */ std::vector getSortedVariableIndices() const; /*! * Retrieves the (sorted) list of the variable indices of the DD variables given by the meta variable set. * * @param manager The manager responsible for the DD. * @param metaVariable The set of meta variables for which to retrieve the index list. * @return The sorted list of variable indices. */ std::vector getSortedVariableIndices(std::set const& metaVariables) const; /*! * Retrieves the internal DD manager. * * @return The internal DD manager. */ InternalDdManager& getInternalDdManager(); /*! * Retrieves the internal DD manager. * * @return The internal DD manager. */ InternalDdManager const& getInternalDdManager() const; /*! * Performs a debug check if available. */ void debugCheck() const; private: /*! * Retrieves a list of names of the DD variables in the order of their index. * * @return A list of DD variable names. */ std::vector getDdVariableNames() const; /*! * Retrieves a list of expression variables in the order of their index. * * @return A list of DD variables. */ std::vector getDdVariables() const; /*! * Retrieves the underlying expression manager. * * @return The underlying expression manager. */ storm::expressions::ExpressionManager const& getExpressionManager() const; /*! * Retrieves the underlying expression manager. * * @return The underlying expression manager. */ storm::expressions::ExpressionManager& getExpressionManager(); /*! * Retrieves a pointer to the internal DD manager. * * @return A pointer to the internal DD manager. */ InternalDdManager* getInternalDdManagerPointer(); /*! * Retrieves a pointer to the internal DD manager. * * @return A pointer to the internal DD manager. */ InternalDdManager const* getInternalDdManagerPointer() const; // ATTENTION: as the DD packages typically perform garbage collection, the order of members is crucial here: // First, the references to the DDs of the meta variables need to be disposed of and *then* the manager. // The DD manager that is customized according to the selected library type. InternalDdManager internalDdManager; // A mapping from variables to the meta variable information. std::unordered_map> metaVariableMap; // The manager responsible for the variables. std::shared_ptr manager; }; } } #endif /* STORM_STORAGE_DD_DDMANAGER_H_ */