- java.lang.Object
-
- org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel
-
public class BDDKernel extends Object
The jBuddy kernel.- Since:
- 1.4.0
- Version:
- 2.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceBDDKernel.BddOperationprotected static classBDDKernel.BddReorderRequestReplaces the calls in Buddy for setjmp and longjmp.static classBDDKernel.BDDStatisticsA class for BDD statistics.protected static classBDDKernel.Operand
-
Field Summary
Fields Modifier and Type Field Description protected BDDCacheappexcacheprotected BDDCacheapplycachestatic intBDD_ABORTstatic intBDD_FALSEstatic intBDD_TRUEstatic intCACHEID_FORALLstatic intCACHEID_PATHCOU_ONEstatic intCACHEID_PATHCOU_ZEROstatic intCACHEID_RESTRICTstatic intCACHEID_SATCOUprotected intcachesizeprotected FormulaFactoryfprotected intfreenumprotected intfreeposprotected intgbcollectnumprotected SortedMap<Integer,Variable>idx2varprotected BDDCacheitecacheprotected int[]level2varstatic intMARKHIDEstatic intMARKOFFstatic intMARKONprotected intmaxnodeincreasestatic intMAXREFstatic intMAXVARprotected intminfreenodesprotected BDDCachemisccacheprotected int[]nodesprotected intnodesizeprotected BDDPrimeprimeprotected longproducedprotected BDDCachequantcacheprotected intquantlastprotected int[]quantvarsetprotected intquantvarsetIDprotected int[]refstackprotected intrefstacktopprotected BDDReorderingreorderingprotected BDDCachereplacecacheprotected SortedMap<Variable,Integer>var2idxprotected int[]var2levelprotected intvarnumprotected int[]vars
-
Constructor Summary
Constructors Constructor Description BDDKernel(FormulaFactory f, int numVars, int nodeSize, int cacheSize)Constructor for the BDD kernel.BDDKernel(FormulaFactory f, List<Variable> ordering, int nodeSize, int cacheSize)Constructor for the BDD kernel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intaddRef(int root, BDDHandler handler)Adds a reference for a given node.protected intapply(int l, int r, BDDKernel.Operand op)protected intapplyRec(int l, int r, BDDKernel.Operand op)protected voiddecRef(int n)voiddelRef(int root)Deletes a reference for a given node.protected intdoWithPotentialReordering(BDDKernel.BddOperation operation)FormulaFactoryfactory()Returns the formula factory.protected voidgbc()protected voidgbcRehash()int[]getCurrentVarOrder()Returns the current ordering of the variables.intgetIndexForVariable(Variable var)Returns the index for the given variable or -1 if the variable is unknown.intgetLevel(Variable var)Returns the level of the given variable or -1 if the variable is unknown.intgetOrAddVarIndex(Variable variable)Returns the index for the given variable.BDDPrimegetPrime()BDDReorderinggetReordering()Returns the reordering object for this kernel.VariablegetVariableForIndex(int idx)Returns the variable for the given index ornullif no such index exists.protected inthash(int node)protected booleanhasref(int n)protected inthigh(int node)SortedMap<Integer,Variable>idx2var()Returns the mapping from indices to variables.protected voidincRef(int n)protected voidinitOperators(int cachesize)protected voidinitRef()protected booleanisConst(int n)protected booleanisOne(int n)protected booleanisZero(int n)protected intlevel(int node)protected intlow(int node)protected intmakeNode(int level, int low, int high)protected voidmark(int i)protected intmarkCount(int i)protected booleanmarked(int n)protected intnext(int node)protected intnodehash(int lvl, int l, int h)protected voidnodeResize(boolean doRehash)protected intpair(int a, int b)protected voidpopref(int n)protected intpushRef(int n)protected intreadRef(int n)protected intrefcou(int node)protected voidresetCaches()protected voidsetHash(int node, int hash)protected voidsetHigh(int node, int high)protected voidsetLevel(int node, int level)protected voidsetLow(int node, int low)protected voidsetMark(int n)protected voidsetNext(int node, int next)protected voidsetNumberOfVars(int num)Sets the number of variables to use.protected voidsetRefcou(int node, int refcou)BDDKernel.BDDStatisticsstatistics()Returns the statistics for this BDD Kernel.protected inttriple(int a, int b, int c)protected voidunmark(int i)protected voidunmarkNode(int n)SortedMap<Variable,Integer>var2idx()Returns the mapping from variables to indices.protected voidvarResize()
-
-
-
Field Detail
-
BDD_ABORT
public static final int BDD_ABORT
- See Also:
- Constant Field Values
-
BDD_TRUE
public static final int BDD_TRUE
- See Also:
- Constant Field Values
-
BDD_FALSE
public static final int BDD_FALSE
- See Also:
- Constant Field Values
-
MAXVAR
public static final int MAXVAR
- See Also:
- Constant Field Values
-
MAXREF
public static final int MAXREF
- See Also:
- Constant Field Values
-
MARKON
public static final int MARKON
- See Also:
- Constant Field Values
-
MARKOFF
public static final int MARKOFF
- See Also:
- Constant Field Values
-
MARKHIDE
public static final int MARKHIDE
- See Also:
- Constant Field Values
-
CACHEID_RESTRICT
public static final int CACHEID_RESTRICT
- See Also:
- Constant Field Values
-
CACHEID_SATCOU
public static final int CACHEID_SATCOU
- See Also:
- Constant Field Values
-
CACHEID_PATHCOU_ONE
public static final int CACHEID_PATHCOU_ONE
- See Also:
- Constant Field Values
-
CACHEID_PATHCOU_ZERO
public static final int CACHEID_PATHCOU_ZERO
- See Also:
- Constant Field Values
-
CACHEID_FORALL
public static final int CACHEID_FORALL
- See Also:
- Constant Field Values
-
prime
protected final BDDPrime prime
-
f
protected final FormulaFactory f
-
reordering
protected BDDReordering reordering
-
nodes
protected int[] nodes
-
vars
protected int[] vars
-
minfreenodes
protected final int minfreenodes
-
gbcollectnum
protected int gbcollectnum
-
cachesize
protected final int cachesize
-
nodesize
protected int nodesize
-
maxnodeincrease
protected final int maxnodeincrease
-
freepos
protected int freepos
-
freenum
protected int freenum
-
produced
protected long produced
-
varnum
protected int varnum
-
refstack
protected int[] refstack
-
refstacktop
protected int refstacktop
-
level2var
protected int[] level2var
-
var2level
protected int[] var2level
-
quantvarset
protected int[] quantvarset
-
quantvarsetID
protected int quantvarsetID
-
quantlast
protected int quantlast
-
applycache
protected BDDCache applycache
-
itecache
protected BDDCache itecache
-
quantcache
protected BDDCache quantcache
-
appexcache
protected BDDCache appexcache
-
replacecache
protected BDDCache replacecache
-
misccache
protected BDDCache misccache
-
-
Constructor Detail
-
BDDKernel
public BDDKernel(FormulaFactory f, int numVars, int nodeSize, int cacheSize)
Constructor for the BDD kernel.- Parameters:
f- the formula factory to usenumVars- the number of variablesnodeSize- the initial number of nodes in the nodetablecacheSize- 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 useordering- the variable orderingnodeSize- the initial number of nodes in the nodetablecacheSize- 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 ornullif 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
-
doWithPotentialReordering
protected int doWithPotentialReordering(BDDKernel.BddOperation operation)
-
apply
protected int apply(int l, int r, BDDKernel.Operand op)
-
applyRec
protected int applyRec(int l, int r, BDDKernel.Operand op) throws BDDKernel.BddReorderRequest- Throws:
BDDKernel.BddReorderRequest
-
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 nodercan 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'sBDDHandler.newRefAdded()method is called. If the generation gets aborted due to the handler, the method will returnBDD_ABORTas result. Ifnullis passed as handler, the generation will continue without interruption.- Parameters:
root- the nodehandler- 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)
-
makeNode
protected int makeNode(int level, int low, int high) throws BDDKernel.BddReorderRequest- Throws:
BDDKernel.BddReorderRequest
-
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
-
getPrime
public BDDPrime getPrime()
-
-