Module logicng

Class BDDReordering

    • Field Detail

      • bddreorderTimes

        protected int bddreorderTimes
      • reorderDisabled

        protected boolean reorderDisabled
      • varTree

        protected BDDTree varTree
      • blockId

        protected int blockId
      • extRoots

        protected int[] extRoots
      • extRootSize

        protected int extRootSize
      • usednumBefore

        protected int usednumBefore
      • usednumAfter

        protected int usednumAfter
      • resizedInMakenode

        protected boolean resizedInMakenode
      • usedNodesNextReorder

        protected int usedNodesNextReorder
    • Constructor Detail

      • BDDReordering

        public BDDReordering​(BDDKernel k)
        Creates a new reordering object for the given kernel.
        Parameters:
        k - the kernel
    • Method Detail

      • init

        protected void init()
      • swapVariables

        public void swapVariables​(int v1,
                                  int v2)
        Swaps the variables v1 and v2. This affects all BDDs created by the kernel.
        Parameters:
        v1 - the first variable to swap
        v2 - the second variable to swap
      • reorder

        public void reorder​(BDDReorderingMethod method)
        Reorders the levels in the kernel using the given reordering method. Only blocks of variables will be reordered. See the documentation of addVariableBlock(int, int, boolean) to learn more about such variable blocks. Without the definition of any block, nothing will be reordered.

        If the reordering should be performed without any restrictions, addVariableBlockAll() can be called before this method.

        Parameters:
        method - the method to be used for the reordering
      • setReorderDuringConstruction

        public void setReorderDuringConstruction​(BDDReorderingMethod method,
                                                 int num)
        Activates or deactivates the automatic reordering during the construction of a BDD.

        Automatic reordering can be deactivated by passing BDDReorderingMethod.BDD_REORDER_NONE for the method parameter, otherwise the reordering is activated with the given method. The reordering is executed at most num times.

        Parameters:
        method - the method to be used for reordering
        num - the maximum number of reorders to be performed
      • addVariableBlock

        public void addVariableBlock​(int first,
                                     int last,
                                     boolean fixed)
        Adds a variable block starting at variable first and ending in variable last (both inclusive).

        Variable blocks are used in the BDD reordering or in the automatic reordering during the construction of the BDD (configured by setReorderDuringConstruction(org.logicng.knowledgecompilation.bdds.jbuddy.BDDReorderingMethod, int)). Variable blocks can be nested, i.e. one block can contain an arbitrary number of ("child") blocks. Furthermore, a variable block can also be a single variable.

        During reordering, the child blocks of a parent block can be reordered, but they are kept together. So no other block can be moved in between the child blocks. Furthermore, variables in a block which are not in a child block will be left untouched.

        Example: Lets assume we have a BDD with the variable ordering v1, v2, v3, v4, v5, v6, v7. We create the following blocks:

        • A reaching from v1 to v5
        • B reaching from v6 to v7
        • A1 reaching from v1 to v2
        • A2 reaching from v3 to v3
        • A3 reaching from v4 to v5
        This means that the variables of A and B can never be mixed up in the order. So during reordering the variables v6 and v7 can either be moved to the front (before A) or remain at their position. Furthermore, for example v1 and v2 will always stay together and neither v3 nor any other variable can be moved in between them. On the other hand, the blocks A1, A2, and A3 can be swapped arbitrarily.

        These are valid result of a reordering based on the above blocks:

        • v3, v1, v2, v4, v5, v6, v7
        • v6, v7, v4, v5, v3, v1, v2
        • v6, v7, v1, v2, v3, v4, v5
        These however would be illegal:
        • v2, v1, v3, v4, v5, v6, v7 (variables in a block which are not in a child block will not be reordered)
        • v1, v3, v2, v4, v5, v6, v7 (variables of different block will not be mixed up)

        If a block is fixed (the example above assumed always blocks which are not fixed), its immediate child blocks will remain in their order. E.g. if block A was fixed, the blocks A1, A2, and A3 would not be allowed to be swapped. Let's assume block A to be fixed and that we have two other unfixed blocks:

        • A11 reaching from v1 to v1
        • A12 reaching from v2 to v2
        These are examples for legal reorderings:
        • v2, v1, v3, v4, v5, v6, v7 (block A is fixed, but "grandchildren" are still allowed to be reordered
        • v6, v7, v2, v1, v3, v4, v5
        These are examples for illegal reorderings:
        • v3, v2, v1, v4, v5, v6, v7 (block A is fixed, so it's child blocks must be be reordered
        • v1, v2, v4, v5, v3, v6, v7

        Each block (including all nested blocks) must be defined by a separate call to this method. The blocks may be added in an arbitrary order, so it is not required to add them top-down or bottom-up. However, the blocks must not intersect, except of one block containing the other. Furthermore, both the first and the last variable must be known by the kernel and the level first must be lower than the level of last.

        Parameters:
        first - the variable at which the block starts (inclusive)
        last - the variable at which the block ends (inclusive)
        fixed - whether the block should be fixed or not
      • addVariableBlockAll

        public void addVariableBlockAll()
        Adds a single variable block for all variables known by the kernel.
      • var

        protected int var​(int n)
        IMPORTANT: The semantics of the "level" field in the BddNode struct changes during variable reordering in order to make a fast variable swap possible when two variables are independent. Instead of referring to the level of the node it refers to the *variable* !!!
        Parameters:
        n - the variable number
        Returns:
        the level of this variable
      • reorderNodenum

        protected int reorderNodenum()
      • nodehashReorder

        protected int nodehashReorder​(int var,
                                      int l,
                                      int h)
      • reorderDone

        protected void reorderDone()
      • reorderSiftite

        protected BDDTree reorderSiftite​(BDDTree t)
        Do sifting iteratively until no more improvement can be found
        Parameters:
        t - the input BDD tree
        Returns:
        the sifted BDD tree
      • reorderSift

        protected BDDTree reorderSift​(BDDTree t)
        Find sifting sequence based on the number of nodes at each level
        Parameters:
        t - the input BDD tree
        Returns:
        the sifted BDD tree
      • reorderSiftSeq

        protected BDDTree reorderSiftSeq​(BDDTree t,
                                         BDDTree[] seq,
                                         int num)
        Go through all blocks in a specific sequence and find best position for each of them
        Parameters:
        t - the input BDD tree
        seq - the sequence
        num - the current position in the sequence
        Returns:
        the sifted BDD tree
      • reorderSiftBestpos

        protected void reorderSiftBestpos​(BDDTree blk,
                                          int middlePos)
        Move a specific block up and down in the order and place at last in the best position
        Parameters:
        blk - the block
        middlePos - the middle position in the block
      • blockdown

        protected void blockdown​(BDDTree left)
        Swaps adjacent blocks
        Parameters:
        left - the left BDD tree
      • reorderVarup

        protected void reorderVarup​(int var)
      • reorderVardown

        protected void reorderVardown​(int var)
      • reorderDownSimple

        protected int reorderDownSimple​(int var0)
      • reorderSwap

        protected void reorderSwap​(int toBeProcessed,
                                   int var0)
      • reorderMakenode

        protected int reorderMakenode​(int var,
                                      int low,
                                      int high)
      • reorderLocalGbc

        protected void reorderLocalGbc​(int var0)
      • reorderRehashAll

        protected void reorderRehashAll()
      • reorderSetLevellookup

        protected void reorderSetLevellookup()
      • clrVarBlocks

        protected void clrVarBlocks()
      • disableReorder

        protected void disableReorder()
      • enableReorder

        protected void enableReorder()
      • reorderReady

        protected boolean reorderReady()
      • reorderAuto

        protected void reorderAuto()
      • reorderInit

        protected int reorderInit()
      • markRoots

        protected int markRoots()
      • reorderGbc

        protected void reorderGbc()
      • checkReorder

        protected void checkReorder()
      • addrefRec

        protected void addrefRec​(int r,
                                 int[] dep)
      • addDependencies

        protected void addDependencies​(int[] dep)
      • reorderGain

        protected int reorderGain()