diff --git a/src/storage/dd/CuddBdd.cpp b/src/storage/dd/CuddBdd.cpp index 476cd0880..98d50132a 100644 --- a/src/storage/dd/CuddBdd.cpp +++ b/src/storage/dd/CuddBdd.cpp @@ -367,6 +367,30 @@ namespace storm { return result; } + std::pair, std::unordered_map, storm::expressions::Variable>> Bdd::toExpression(storm::expressions::ExpressionManager& manager, std::unordered_map const& indexToExpressionMap) const { + std::pair, std::unordered_map, storm::expressions::Variable>> result; + + // Create (and maintain) a mapping from the DD nodes to a counter that says the how-many-th node (within the + // nodes of equal index) the node was. + std::unordered_map nodeToCounterMap; + this->toExpressionRec(this->getCuddDdNode(), this->getDdManager()->getCuddManager(), manager, result.first, result.second, nodeToCounterMap); + + return result; + } + + void Bdd::toExpressionRec(DdNode const* f, Cudd const& ddManager, storm::expressions::ExpressionManager& manager, std::vector& expressions, std::unordered_map, storm::expressions::Variable>& countIndexToVariablePair, std::unordered_map& nodeToCounterMap) const { + DdNode const* F = Cudd_Regular(f); + + // Terminal cases. + if (F == Cudd_ReadOne(ddManager.getManager())) { + + } + + // Non-terminal cases. + // (1) Check if we have seen the node before. + auto nodeIt = nodeToCounterMap.find(); + } + void Bdd::toVectorRec(DdNode const* dd, Cudd const& manager, storm::storage::BitVector& result, Odd const& rowOdd, bool complement, uint_fast64_t currentRowLevel, uint_fast64_t maxLevel, uint_fast64_t currentRowOffset, std::vector const& ddRowVariableIndices) const { // If there are no more values to select, we can directly return. if (dd == Cudd_ReadLogicZero(manager.getManager()) && !complement) { diff --git a/src/storage/dd/CuddBdd.h b/src/storage/dd/CuddBdd.h index 6ad869428..a8e434958 100644 --- a/src/storage/dd/CuddBdd.h +++ b/src/storage/dd/CuddBdd.h @@ -1,6 +1,7 @@ #ifndef STORM_STORAGE_DD_CUDDBDD_H_ #define STORM_STORAGE_DD_CUDDBDD_H_ +#include #include #include "src/storage/dd/Bdd.h" @@ -303,6 +304,17 @@ namespace storm { */ storm::storage::BitVector toVector(storm::dd::Odd const& rowOdd) const; + /*! + * Translates the function the BDD is representing to a set of expressions that characterize the function. + * + * @param manager The manager that is used to build the expression and, in particular, create new variables in. + * @param indexToExpressionMap A mapping from indices (of DD variables) to expressions with which they are + * to be replaced. + * @return A pair consisting of the created expressions and a mapping from pairs (i, j) to variables such + * that the i-th variable of level j is represented by the mapped-to variable. + */ + std::pair, std::unordered_map, storm::expressions::Variable>> toExpression(storm::expressions::ExpressionManager& manager, std::unordered_map const& indexToExpressionMap) const; + private: /*! * Retrieves the CUDD BDD object associated with this DD. @@ -370,6 +382,8 @@ namespace storm { */ void toVectorRec(DdNode const* dd, Cudd const& manager, storm::storage::BitVector& result, Odd const& rowOdd, bool complement, uint_fast64_t currentRowLevel, uint_fast64_t maxLevel, uint_fast64_t currentRowOffset, std::vector const& ddRowVariableIndices) const; + void toExpressionRec(DdNode const* dd, Cudd const& ddManager, storm::expressions::ExpressionManager& manager, std::vector& expressions, std::unordered_map, storm::expressions::Variable>& countIndexToVariablePair, std::unordered_map& nodeToCounterMap) const; + // The BDD created by CUDD. BDD cuddBdd; };