Module logicng

Class BDD


  • public class BDD
    extends Object
    The internal representation of a BDD.
    Since:
    1.4.0
    Version:
    2.4.0
    • Constructor Detail

      • BDD

        public BDD​(int index,
                   BDDKernel kernel)
        Constructs a new BDD with a given index.
        Parameters:
        index - the index
        kernel - the kernel of this BDD
    • Method Detail

      • index

        public int index()
        Returns the index of this BDD.

        The index marks the entry point of this BDD in the underlying kernel.

        Returns:
        the index of this BDD
      • underlyingKernel

        public BDDKernel underlyingKernel()
        Returns the BDD Kernel of this factory. The Kernel should only be accessed when you know, what you are doing.
        Returns:
        the BDD Kernel
      • apply

        public <T> T apply​(BDDFunction<T> function)
        Applies a given function on this BDD and returns the result.
        Type Parameters:
        T - the result type of the function
        Parameters:
        function - the function
        Returns:
        the result of the function application
      • toFormula

        public Formula toFormula()
        Returns a formula representation of this BDD. This is done by using the Shannon expansion.
        Returns:
        the formula for this BDD
      • toFormula

        public Formula toFormula​(boolean followPathsToTrue)
        Returns a formula representation of this BDD. This is done by using the Shannon expansion. If followPathsToTrue is activated, the paths leading to the true terminal are followed to generate the formula. If followPathsToTrue is deactivated, the paths leading to the false terminal are followed to generate the formula and the resulting formula is negated. Depending on the formula and the number of satisfying assignments, the generated formula can be more compact using the true paths or false paths, respectively.
        Parameters:
        followPathsToTrue - the extraction style
        Returns:
        the formula for this BDD
      • negate

        public BDD negate()
        Returns a new BDD which is the negation of this BDD.
        Returns:
        the negation of this BDD
      • implies

        public BDD implies​(BDD other)
        Returns a new BDD which is the implication of this BDD to the given other BDD. Both BDDs must use the same kernel.
        Parameters:
        other - the other BDD
        Returns:
        the implication from this BDD to the other BDD
        Throws:
        IllegalArgumentException - if the two BDDs don't have the same kernel
      • impliedBy

        public BDD impliedBy​(BDD other)
        Returns a new BDD which is the implication of the other given BDD to this BDD. Both BDDs must use the same kernel.
        Parameters:
        other - the other BDD
        Returns:
        the implication from the other BDD to this BDD
        Throws:
        IllegalArgumentException - if the two BDDs don't have the same kernel
      • equivalence

        public BDD equivalence​(BDD other)
        Returns a new BDD which is the equivalence of this BDD and the other given BDD. Both BDDs must use the same kernel.
        Parameters:
        other - the other BDD
        Returns:
        the equivalence of this and the other BDD
        Throws:
        IllegalArgumentException - if the two BDDs don't have the same kernel
      • and

        public BDD and​(BDD other)
        Returns a new BDD which is the conjunction of this BDD and the given other BDD. Both BDDs must use the same kernel.
        Parameters:
        other - the other BDD
        Returns:
        the conjunction of the two BDDs
        Throws:
        IllegalArgumentException - if the two BDDs don't have the same kernel
      • or

        public BDD or​(BDD other)
        Returns a new BDD which is the disjunction of this BDD and the given other BDD. Both BDDs must use the same kernel.
        Parameters:
        other - the other BDD
        Returns:
        the disjunction of the two BDDs
        Throws:
        IllegalArgumentException - if the two BDDs don't have the same kernel
      • isTautology

        public boolean isTautology()
        Returns true if this BDD is a tautology, false otherwise.
        Returns:
        true if this BDD is a tautology, false otherwise
      • isContradiction

        public boolean isContradiction()
        Returns true if this BDD is a contradiction, false otherwise.
        Returns:
        true if this BDD is a contradiction, false otherwise
      • modelCount

        public BigInteger modelCount()
        Returns the model count of this BDD.
        Returns:
        the model count
      • enumerateAllModels

        public List<Assignment> enumerateAllModels()
        Enumerates all models of this BDD.
        Returns:
        the list of all models
      • enumerateAllModels

        public List<Assignment> enumerateAllModels​(Variable... variables)
        Enumerates all models of this BDD wrt. a given set of variables.
        Parameters:
        variables - the variables
        Returns:
        the list of all models
      • enumerateAllModels

        public List<Assignment> enumerateAllModels​(Collection<Variable> variables)
        Enumerates all models of this BDD wrt. a given set of variables.
        Parameters:
        variables - the variables
        Returns:
        the list of all models
      • cnf

        public Formula cnf()
        Returns a CNF formula for this BDD.
        Returns:
        the CNF for the formula represented by this BDD
      • numberOfClausesCNF

        public BigInteger numberOfClausesCNF()
        Returns the number of clauses for the CNF formula of the BDD.
        Returns:
        the number of clauses for the CNF formula of the BDD
      • dnf

        public Formula dnf()
        Returns a DNF formula for this BDD.
        Returns:
        the DNF for the formula represented by this BDD
      • restrict

        public BDD restrict​(Collection<Literal> restriction)
        Restricts the BDD.
        Parameters:
        restriction - the restriction
        Returns:
        the restricted BDD
      • restrict

        public BDD restrict​(Literal... restriction)
        Restricts the BDD.
        Parameters:
        restriction - the restriction
        Returns:
        the restricted BDD
      • exists

        public BDD exists​(Collection<Variable> variables)
        Existential quantifier elimination for a given set of variables.
        Parameters:
        variables - the variables to eliminate
        Returns:
        the BDD with the eliminated variables
      • exists

        public BDD exists​(Variable... variables)
        Existential quantifier elimination for a given set of variables.
        Parameters:
        variables - the variables to eliminate
        Returns:
        the BDD with the eliminated variables
      • forall

        public BDD forall​(Collection<Variable> variables)
        Universal quantifier elimination for a given set of variables.
        Parameters:
        variables - the variables to eliminate
        Returns:
        the BDD with the eliminated variables
      • forall

        public BDD forall​(Variable... variables)
        Universal quantifier elimination for a given set of variables.
        Parameters:
        variables - the variables to eliminate
        Returns:
        the BDD with the eliminated variables
      • model

        public Assignment model()
        Returns an arbitrary model of this BDD or null if there is none.
        Returns:
        an arbitrary model of this BDD
      • model

        public Assignment model​(boolean defaultValue,
                                Collection<Variable> variables)
        Returns an arbitrary model of this BDD which contains at least the given variables or null if there is none. If a variable is a don't care variable, it will be assigned with the given default value.
        Parameters:
        defaultValue - the default value for don't care variables
        variables - the set of variable which has to be contained in the model
        Returns:
        an arbitrary model of this BDD
      • model

        public Assignment model​(boolean defaultValue,
                                Variable... variables)
        Returns an arbitrary model of this BDD which contains at least the given variables or null if there is none. If a variable is a don't care variable, it will be assigned with the given default value.
        Parameters:
        defaultValue - the default value for don't care variables
        variables - the set of variable which has to be contained in the model
        Returns:
        an arbitrary model of this BDD
      • fullModel

        public Assignment fullModel()
        Returns a full model of this BDD or null if there is none.
        Returns:
        a full model of this BDD
      • pathCountOne

        public BigInteger pathCountOne()
        Returns the number of paths leading to the terminal 'one' node.
        Returns:
        the number of paths leading to the terminal 'one' node
      • pathCountZero

        public BigInteger pathCountZero()
        Returns the number of paths leading to the terminal 'zero' node.
        Returns:
        the number of paths leading to the terminal 'zero' node
      • support

        public SortedSet<Variable> support()
        Returns all the variables this BDD depends on.
        Returns:
        all the variables that this BDD depends on
      • nodeCount

        public int nodeCount()
        Returns the number of distinct nodes for this BDD.
        Returns:
        the number of distinct nodes
      • variableProfile

        public SortedMap<Variable,​Integer> variableProfile()
        Returns how often each variable occurs in this BDD.
        Returns:
        how often each variable occurs in the BDD
      • getVariableOrder

        public List<Variable> getVariableOrder()
        Returns the variable order of this BDD.
        Returns:
        the variable order
      • swapVariables

        public void swapVariables​(Variable first,
                                  Variable second)
        Swaps two variables in a BDD. Beware that if the BDDKernel of this BDD was used for multiple BDDs, the variables are swapped in all of these BDDs.
        Parameters:
        first - the first variable to swap
        second - the second variable to swap
      • getReordering

        public BDDReordering getReordering()
        Returns the reordering object for the BDD kernel.
        Returns:
        the reordering object
      • toLngBdd

        public BDDNode toLngBdd()
        Returns a LogicNG internal BDD data structure of this BDD.
        Returns:
        the BDD as LogicNG data structure
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object