- java.lang.Object
-
- org.logicng.knowledgecompilation.bdds.jbuddy.BDDReordering
-
public class BDDReordering extends Object
This class encapsulates the reordering mechanism on BDDs.The class is initialized with the BDD kernel on which it performs all operations. This means that all reordering operations initiated on this object will affect all BDDs created by its kernel.
There are three types operations which can be performed here:
- Swapping two variables in the kernel can be performed via
swapVariables(int, int) - Reordering all variables can be performed via
reorder(org.logicng.knowledgecompilation.bdds.jbuddy.BDDReorderingMethod) - Reordering during construction of the BDD can be configured via
setReorderDuringConstruction(org.logicng.knowledgecompilation.bdds.jbuddy.BDDReorderingMethod, int)
The docuentationgives more information on variable blocks. To make all variables freely movable,addVariableBlockAll()can be used.- Since:
- 2.0.0
- Version:
- 2.0.0
- Swapping two variables in the kernel can be performed via
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classBDDReordering.BDDSizePairprotected static classBDDReordering.InteractionMatrixprotected static classBDDReordering.LevelData
-
Field Summary
Fields Modifier and Type Field Description protected intbddreorderTimesprotected intblockIdprotected int[]extRootsprotected intextRootSizeprotected BDDReordering.InteractionMatrixinteractionMatrixprotected BDDKernelkprotected BDDReordering.LevelData[]levelsprotected booleanreorderDisabledprotected BDDReorderingMethodreorderMethodprotected booleanresizedInMakenodeprotected intusedNodesNextReorderprotected intusednumAfterprotected intusednumBeforeprotected BDDTreevarTree
-
Constructor Summary
Constructors Constructor Description BDDReordering(BDDKernel k)Creates a new reordering object for the given kernel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddDependencies(int[] dep)protected voidaddrefRec(int r, int[] dep)voidaddVariableBlock(int first, int last, boolean fixed)Adds a variable block starting at variablefirstand ending in variablelast(both inclusive).voidaddVariableBlockAll()Adds a single variable block for all variables known by the kernel.protected voidblockdown(BDDTree left)Swaps adjacent blocksprotected voidcheckReorder()protected voidclrVarBlocks()protected voiddisableReorder()protected voidenableReorder()protected voidinit()protected intmarkRoots()protected intnodehashReorder(int var, int l, int h)voidreorder(BDDReorderingMethod method)Reorders the levels in the kernel using the given reordering method.protected voidreorderAuto()protected voidreorderBlock(BDDTree t, BDDReorderingMethod method)protected voidreorderDone()protected intreorderDownSimple(int var0)protected intreorderGain()protected voidreorderGbc()protected intreorderInit()protected voidreorderLocalGbc(int var0)protected intreorderMakenode(int var, int low, int high)protected intreorderNodenum()protected BDDTreereorderRandom(BDDTree t)protected booleanreorderReady()protected voidreorderRehashAll()protected voidreorderSetLevellookup()protected BDDTreereorderSift(BDDTree t)Find sifting sequence based on the number of nodes at each levelprotected voidreorderSiftBestpos(BDDTree blk, int middlePos)Move a specific block up and down in the order and place at last in the best positionprotected BDDTreereorderSiftite(BDDTree t)Do sifting iteratively until no more improvement can be foundprotected BDDTreereorderSiftSeq(BDDTree t, BDDTree[] seq, int num)Go through all blocks in a specific sequence and find best position for each of themprotected voidreorderSwap(int toBeProcessed, int var0)protected Pair<BDDTree,BDDTree>reorderSwapwin3(BDDTree thisTree)protected voidreorderVardown(int var)protected voidreorderVarup(int var)protected BDDTreereorderWin2(BDDTree t)protected BDDTreereorderWin2ite(BDDTree t)protected BDDTreereorderWin3(BDDTree t)protected BDDTreereorderWin3ite(BDDTree t)voidsetReorderDuringConstruction(BDDReorderingMethod method, int num)Activates or deactivates the automatic reordering during the construction of a BDD.protected intsiftTestCmp(BDDReordering.BDDSizePair a, BDDReordering.BDDSizePair b)voidswapVariables(int v1, int v2)Swaps the variablesv1andv2.protected intvar(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.protected intvarseqCmp(Integer aa, Integer bb)
-
-
-
Field Detail
-
k
protected final BDDKernel k
-
reorderMethod
protected BDDReorderingMethod reorderMethod
-
bddreorderTimes
protected int bddreorderTimes
-
reorderDisabled
protected boolean reorderDisabled
-
varTree
protected BDDTree varTree
-
blockId
protected int blockId
-
extRoots
protected int[] extRoots
-
extRootSize
protected int extRootSize
-
levels
protected BDDReordering.LevelData[] levels
-
interactionMatrix
protected BDDReordering.InteractionMatrix interactionMatrix
-
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)- Parameters:
v1- the first variable to swapv2- 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 ofaddVariableBlock(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_NONEfor themethodparameter, otherwise the reordering is activated with the given method. The reordering is executed at mostnumtimes.- Parameters:
method- the method to be used for reorderingnum- the maximum number of reorders to be performed
-
addVariableBlock
public void addVariableBlock(int first, int last, boolean fixed)Adds a variable block starting at variablefirstand ending in variablelast(both inclusive).Variable blocks are used in the
BDD reorderingor in the automatic reordering during the construction of the BDD (configured bysetReorderDuringConstruction(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:Areaching fromv1tov5Breaching fromv6tov7A1reaching fromv1tov2A2reaching fromv3tov3A3reaching fromv4tov5
AandBcan never be mixed up in the order. So during reordering the variablesv6andv7can either be moved to the front (beforeA) or remain at their position. Furthermore, for examplev1andv2will always stay together and neitherv3nor any other variable can be moved in between them. On the other hand, the blocksA1,A2, andA3can be swapped arbitrarily.These are valid result of a reordering based on the above blocks:
v3, v1, v2, v4, v5, v6, v7v6, v7, v4, v5, v3, v1, v2v6, v7, v1, v2, v3, v4, v5
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
Awas fixed, the blocksA1,A2, andA3would not be allowed to be swapped. Let's assume blockAto be fixed and that we have two other unfixed blocks:A11reaching fromv1tov1A12reaching fromv2tov2
v2, v1, v3, v4, v5, v6, v7(blockAis fixed, but "grandchildren" are still allowed to be reorderedv6, v7, v2, v1, v3, v4, v5
v3, v2, v1, v4, v5, v6, v7(blockAis fixed, so it's child blocks must be be reorderedv1, 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
firstand thelastvariable must be known by the kernel and the levelfirstmust be lower than the level oflast.- 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)
-
reorderBlock
protected void reorderBlock(BDDTree t, BDDReorderingMethod method)
-
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 treeseq- the sequencenum- 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 blockmiddlePos- the middle position in the block
-
siftTestCmp
protected int siftTestCmp(BDDReordering.BDDSizePair a, BDDReordering.BDDSizePair b)
-
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()
-
-