#ifndef STORM_STORAGE_DD_BDD_H_ #define STORM_STORAGE_DD_BDD_H_ #include "src/storage/dd/Dd.h" #include "src/storage/dd/DdType.h" #include "src/storage/dd/cudd/InternalCuddBdd.h" #include "src/storage/dd/sylvan/InternalSylvanBdd.h" namespace storm { namespace logic { enum class ComparisonType; } namespace dd { template class Add; class Odd; template class Bdd : public Dd { public: friend class DdManager; template friend class Add; // Instantiate all copy/move constructors/assignments with the default implementation. Bdd() = default; Bdd(Bdd const& other) = default; Bdd& operator=(Bdd const& other) = default; Bdd(Bdd&& other) = default; Bdd& operator=(Bdd&& other) = default; /*! * Constructs a BDD representation of all encodings that are in the requested relation with the given value. * * @param ddManager The DD manager responsible for the resulting BDD. * @param explicitValues The explicit values to compare to the given value. * @param odd The ODD used for the translation from the explicit representation to a symbolic one. * @param metaVariables The meta variables to use for the symbolic encoding. * @param comparisonType The relation that needs to hold for the values (wrt. to the given value). * @param value The value to compare with. */ static Bdd fromVector(std::shared_ptr const> ddManager, std::vector const& explicitValues, storm::dd::Odd const& odd, std::set const& metaVariables, storm::logic::ComparisonType comparisonType, double value); /*! * Retrieves whether the two BDDs represent the same function. * * @param other The BDD that is to be compared with the current one. * @return True if the BDDs represent the same function. */ bool operator==(Bdd const& other) const; /*! * Retrieves whether the two BDDs represent different functions. * * @param other The BDD that is to be compared with the current one. * @return True if the BDDs represent the different functions. */ bool operator!=(Bdd const& other) const; /*! * Performs an if-then-else with the given operands, i.e. maps all valuations that are mapped to a non-zero * function value to the function values specified by the first DD and all others to the function values * specified by the second DD. * * @param thenBdd The BDD defining the 'then' part. * @param elseBdd The BDD defining the 'else' part. * @return The resulting BDD. */ Bdd ite(Bdd const& thenBdd, Bdd const& elseBdd) const; /*! * Performs a logical or of the current and the given BDD. * * @param other The second BDD used for the operation. * @return The logical or of the operands. */ Bdd operator||(Bdd const& other) const; /*! * Performs a logical or of the current and the given BDD and assigns it to the current BDD. * * @param other The second BDD used for the operation. * @return A reference to the current BDD after the operation */ Bdd& operator|=(Bdd const& other); /*! * Performs a logical and of the current and the given BDD. * * @param other The second BDD used for the operation. * @return The logical and of the operands. */ Bdd operator&&(Bdd const& other) const; /*! * Performs a logical and of the current and the given BDD and assigns it to the current BDD. * * @param other The second BDD used for the operation. * @return A reference to the current BDD after the operation */ Bdd& operator&=(Bdd const& other); /*! * Performs a logical iff of the current and the given BDD. * * @param other The second BDD used for the operation. * @return The logical iff of the operands. */ Bdd iff(Bdd const& other) const; /*! * Performs a logical exclusive-or of the current and the given BDD. * * @param other The second BDD used for the operation. * @return The logical exclusive-or of the operands. */ Bdd exclusiveOr(Bdd const& other) const; /*! * Performs a logical implication of the current and the given BDD. * * @param other The second BDD used for the operation. * @return The logical implication of the operands. */ Bdd implies(Bdd const& other) const; /*! * Logically inverts the current BDD. * * @return The resulting BDD. */ Bdd operator!() const; /*! * Logically complements the current BDD. * * @return A reference to the current BDD after the operation. */ Bdd& complement(); /*! * Existentially abstracts from the given meta variables. * * @param metaVariables The meta variables from which to abstract. */ Bdd existsAbstract(std::set const& metaVariables) const; /*! * Universally abstracts from the given meta variables. * * @param metaVariables The meta variables from which to abstract. */ Bdd universalAbstract(std::set const& metaVariables) const; /*! * Computes the logical and of the current and the given BDD and existentially abstracts from the given set * of variables. * * @param other The second BDD for the logical and. * @param existentialVariables The variables from which to existentially abstract. * @return A BDD representing the result. */ Bdd andExists(Bdd const& other, std::set const& existentialVariables) const; /*! * Computes the constraint of the current BDD with the given constraint. That is, the function value of the * resulting BDD will be the same as the current ones for all assignments mapping to one in the constraint * and may be different otherwise. * * @param constraint The constraint to use for the operation. * @return The resulting BDD. */ Bdd constrain(Bdd const& constraint) const; /*! * Computes the restriction of the current BDD with the given constraint. That is, the function value of the * resulting DD will be the same as the current ones for all assignments mapping to one in the constraint * and may be different otherwise. * * @param constraint The constraint to use for the operation. * @return The resulting BDD. */ Bdd restrict(Bdd const& constraint) const; /*! * Swaps the given pairs of meta variables in the BDD. The pairs of meta variables must be guaranteed to have * the same number of underlying BDD variables. * * @param metaVariablePairs A vector of meta variable pairs that are to be swapped for one another. * @return The resulting BDD. */ Bdd swapVariables(std::vector> const& metaVariablePairs) const; /*! * Retrieves whether this DD represents the constant one function. * * @return True if this DD represents the constant one function. */ bool isOne() const; /*! * Retrieves whether this DD represents the constant zero function. * * @return True if this DD represents the constant zero function. */ bool isZero() const; /*! * Converts a BDD to an equivalent ADD. * * @return The corresponding ADD. */ template Add toAdd() const; /*! * Converts the BDD to a bit vector. The given offset-labeled DD is used to determine the correct row of * each entry. * * @param rowOdd The ODD used for determining the correct row. * @return The bit vector that is represented by this BDD. */ storm::storage::BitVector toVector(storm::dd::Odd const& rowOdd) const; virtual Bdd getSupport() const override; virtual uint_fast64_t getNonZeroCount() const override; virtual uint_fast64_t getLeafCount() const override; virtual uint_fast64_t getNodeCount() const override; virtual uint_fast64_t getIndex() const override; virtual void exportToDot(std::string const& filename) const override; /*! * Retrieves the cube of all given meta variables. * * @param metaVariables The variables for which to create the cube. * @return The resulting cube. */ static Bdd getCube(DdManager const& manager, std::set const& metaVariables); /*! * Creates an ODD based on the current BDD. * * @return The corresponding ODD. */ Odd createOdd() const; /*! * Filters the given explicit vector using the symbolic representation of which values to select. * * @param selectedValues A symbolic representation of which values to select. * @param values The value vector from which to select the values. * @return The resulting vector. */ template std::vector filterExplicitVector(Odd const& odd, std::vector const& values) const; private: /*! * We provide a conversion operator from the BDD to its internal type to ease calling the internal functions. */ operator InternalBdd() const; /*! * Creates a DD that encapsulates the given internal BDD. * * @param ddManager The manager responsible for this DD. * @param internalBdd The internal BDD to store. * @param containedMetaVariables The meta variables that appear in the DD. */ Bdd(std::shared_ptr const> ddManager, InternalBdd const& internalBdd, std::set const& containedMetaVariables = std::set()); /*! * Builds a BDD representing the values that make the given filter function evaluate to true. * * @param ddManager The manager responsible for the BDD. * @param values The values that are to be checked against the filter function. * @param odd The ODD used for the translation. * @param metaVariables The meta variables used for the translation. * @param filter The filter that evaluates whether an encoding is to be mapped to 0 or 1. * @return The resulting (CUDD) BDD. */ template static Bdd fromVector(std::shared_ptr const> ddManager, std::vector const& values, Odd const& odd, std::set const& metaVariables, std::function const& filter); // The internal BDD that depends on the chosen library. InternalBdd internalBdd; }; } } #endif /* STORM_STORAGE_DD_BDD_H_ */