Module logicng

Class BDDKernel


  • public class BDDKernel
    extends Object
    The jBuddy kernel.
    Since:
    1.4.0
    Version:
    2.0.0
    • Constructor Detail

      • BDDKernel

        public BDDKernel​(FormulaFactory f,
                         int numVars,
                         int nodeSize,
                         int cacheSize)
        Constructor for the BDD kernel.
        Parameters:
        f - the formula factory to use
        numVars - the number of variables
        nodeSize - the initial number of nodes in the nodetable
        cacheSize - the fixed size of the internal caches
      • BDDKernel

        public BDDKernel​(FormulaFactory f,
                         List<Variable> ordering,
                         int nodeSize,
                         int cacheSize)
        Constructor for the BDD kernel.
        Parameters:
        f - the formula factory to use
        ordering - the variable ordering
        nodeSize - the initial number of nodes in the nodetable
        cacheSize - the fixed size of the internal caches
    • Method Detail

      • setNumberOfVars

        protected void setNumberOfVars​(int num)
        Sets the number of variables to use. It may be called more than one time, but only to increase the number of variables.
        Parameters:
        num - the number of variables to use
      • getOrAddVarIndex

        public int getOrAddVarIndex​(Variable variable)
        Returns the index for the given variable.

        If the variable hasn't been seen before, the next free variable index is assigned to it. If no free variables are left, an illegal argument exception is thrown.

        Parameters:
        variable - the variable
        Returns:
        the index for the variable
        Throws:
        IllegalArgumentException - if the variable does not yet exist in the kernel and there are no free variable indices left
      • factory

        public FormulaFactory factory()
        Returns the formula factory.
        Returns:
        the formula factory
      • getReordering

        public BDDReordering getReordering()
        Returns the reordering object for this kernel.
        Returns:
        the reordering object
      • var2idx

        public SortedMap<Variable,​Integer> var2idx()
        Returns the mapping from variables to indices.
        Returns:
        the mapping from variables to indices
      • idx2var

        public SortedMap<Integer,​Variable> idx2var()
        Returns the mapping from indices to variables.
        Returns:
        the mapping from indices to variables
      • getIndexForVariable

        public int getIndexForVariable​(Variable var)
        Returns the index for the given variable or -1 if the variable is unknown.
        Parameters:
        var - the variable
        Returns:
        the index for the given variable
      • getVariableForIndex

        public Variable getVariableForIndex​(int idx)
        Returns the variable for the given index or null if no such index exists.
        Parameters:
        idx - the index
        Returns:
        the variable for the given index
      • getLevel

        public int getLevel​(Variable var)
        Returns the level of the given variable or -1 if the variable is unknown.
        Parameters:
        var - the variable
        Returns:
        the level of the given variable
      • getCurrentVarOrder

        public int[] getCurrentVarOrder()
        Returns the current ordering of the variables.
        Returns:
        the current variable ordering
      • addRef

        public int addRef​(int root,
                          BDDHandler handler)
        Adds a reference for a given node. Reference counting is done on externally referenced nodes only and the count for a specific node r can and must be increased using this function to avoid losing the node in the next garbage collection. If a BDD handler is given, the handler's BDDHandler.newRefAdded() method is called. If the generation gets aborted due to the handler, the method will return BDD_ABORT as result. If null is passed as handler, the generation will continue without interruption.
        Parameters:
        root - the node
        handler - the BDD handler
        Returns:
        return the node
        Throws:
        IllegalArgumentException - if the root node was invalid
      • delRef

        public void delRef​(int root)
        Deletes a reference for a given node.
        Parameters:
        root - the node
        Throws:
        IllegalArgumentException - if the root node was invalid
      • decRef

        protected void decRef​(int n)
      • incRef

        protected void incRef​(int n)
      • unmark

        protected void unmark​(int i)
      • markCount

        protected int markCount​(int i)
      • gbc

        protected void gbc()
      • gbcRehash

        protected void gbcRehash()
      • mark

        protected void mark​(int i)
      • nodeResize

        protected void nodeResize​(boolean doRehash)
      • refcou

        protected int refcou​(int node)
      • level

        protected int level​(int node)
      • low

        protected int low​(int node)
      • high

        protected int high​(int node)
      • hash

        protected int hash​(int node)
      • next

        protected int next​(int node)
      • setRefcou

        protected void setRefcou​(int node,
                                 int refcou)
      • setLevel

        protected void setLevel​(int node,
                                int level)
      • setLow

        protected void setLow​(int node,
                              int low)
      • setHigh

        protected void setHigh​(int node,
                               int high)
      • setHash

        protected void setHash​(int node,
                               int hash)
      • setNext

        protected void setNext​(int node,
                               int next)
      • initRef

        protected void initRef()
      • pushRef

        protected int pushRef​(int n)
      • readRef

        protected int readRef​(int n)
      • popref

        protected void popref​(int n)
      • hasref

        protected boolean hasref​(int n)
      • isConst

        protected boolean isConst​(int n)
      • isOne

        protected boolean isOne​(int n)
      • isZero

        protected boolean isZero​(int n)
      • marked

        protected boolean marked​(int n)
      • setMark

        protected void setMark​(int n)
      • unmarkNode

        protected void unmarkNode​(int n)
      • nodehash

        protected int nodehash​(int lvl,
                               int l,
                               int h)
      • pair

        protected int pair​(int a,
                           int b)
      • triple

        protected int triple​(int a,
                             int b,
                             int c)
      • initOperators

        protected void initOperators​(int cachesize)
      • resetCaches

        protected void resetCaches()
      • varResize

        protected void varResize()
      • statistics

        public BDDKernel.BDDStatistics statistics()
        Returns the statistics for this BDD Kernel.
        Returns:
        the statistics