#ifndef STORM_STORAGE_DD_DDMANAGER_H_ #define STORM_STORAGE_DD_DDMANAGER_H_ #include #include #include "src/storage/dd/DdType.h" #include "src/storage/dd/DdMetaVariable.h" #include "src/storage/dd/Bdd.h" #include "src/storage/dd/Add.h" #include "src/storage/dd/AddIterator.h" #include "src/storage/expressions/Variable.h" #include "src/storage/dd/cudd/InternalCuddDdManager.h" #include "src/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: 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; /*! * 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 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. * @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) 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 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; /*! * Adds an integer meta variable with the given range. * * @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); /*! * Adds a boolean meta variable. * * @param variableName The name of the new variable. */ std::pair addMetaVariable(std::string const& variableName); /*! * 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; /*! * 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; 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_ */