Class BDD
- java.lang.Object
-
- com.github.javabdd.BDD
-
- Direct Known Subclasses:
BDDFactoryIntImpl.IntBDD
public abstract class BDD extends Object
Binary Decision Diagrams (BDDs) are used for efficient computation of many common problems. This is done by giving a compact representation and a set of efficient operations on boolean functions f: {0,1}^n --> {0,1}.Use an implementation of BDDFactory to create BDD objects.
- See Also:
BDDFactory,BDDDomain.set()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBDD.AllSatIteratorIterator that returns all satisfying assignments as byte arrays.static classBDD.BDDIteratorBDDIterator is used to iterate through the satisfying assignments of a BDD.static classBDD.BDDToStringBDDToString is used to specify the printing behavior of BDDs with domains.
-
Constructor Summary
Constructors Modifier Constructor Description protectedBDD()Protected constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description BDD.AllSatIteratorallsat()Finds all satisfying variable assignments.BDDand(BDD that)Returns the logical 'and' of two BDDs.BDDandWith(BDD that)Makes this BDD be the logical 'and' of two BDDs.abstract BDDapply(BDD that, BDDFactory.BDDOp opr)Returns the result of applying the binary operatoroprto the two BDDs.abstract BDDapplyAll(BDD that, BDDFactory.BDDOp opr, BDDVarSet var)Applies the binary operatoroprto two BDDs and then performs a universal quantification of the variables from the variable setvar.abstract BDDapplyEx(BDD that, BDDFactory.BDDOp opr, BDDVarSet var)Applies the binary operatoroprto two BDDs and then performs an existential quantification of the variables from the variable setvar.abstract BDDapplyUni(BDD that, BDDFactory.BDDOp opr, BDDVarSet var)Applies the binary operatoroprto two BDDs and then performs a unique quantification of the variables from the variable setvar.abstract BDDapplyWith(BDD that, BDDFactory.BDDOp opr)Makes this BDD be the result of the binary operatoroprof two BDDs.BDDbiimp(BDD that)Returns the logical 'bi-implication' of two BDDs.BDDbiimpWith(BDD that)Makes this BDD be the logical 'bi-implication' of two BDDs.abstract BDDcompose(BDD g, int var)Functional composition.abstract BDDconstrain(BDD that)Generalized cofactor.booleanequals(Object o)abstract booleanequalsBDD(BDD that)Returns true if this BDD equals that BDD, false otherwise.abstract BDDexist(BDDVarSet var)Existential quantification of variables.abstract BDDforAll(BDDVarSet var)Universal quantification of variables.abstract voidfree()Frees this BDD.abstract BDDfullSatOne()Finds one satisfying variable assignment.abstract BDDFactorygetFactory()Returns the factory that created this BDD.abstract inthashCode()abstract BDDhigh()Gets the true branch of this BDD.abstract BDDid()Identity function.BDDimp(BDD that)Returns the logical 'implication' of two BDDs.BDDimpWith(BDD that)Makes this BDD be the logical 'implication' of two BDDs.abstract booleanisOne()Returns true if this BDD is the one (true) BDD.booleanisUniverse()Returns true if this BDD is the universe BDD.abstract booleanisZero()Returns true if this BDD is the zero (false) BDD.abstract BDDite(BDD thenBDD, BDD elseBDD)if-then-else operator.BDD.BDDIteratoriterator(BDDVarSet var)Returns an iteration of the satisfying assignments of this BDD.intlevel()Gets the level of this BDD.doublelogSatCount()Calculates the logarithm of the number of satisfying variable assignments.doublelogSatCount(BDDVarSet varset)Calculates the logarithm of the number of satisfying variable assignments to the variables in the given varset.abstract BDDlow()Gets the false branch of this BDD.abstract intnodeCount()Counts the number of distinct nodes used for this BDD.abstract BDDnot()Negates this BDD by exchanging all references to the zero-terminal with references to the one-terminal and vice-versa.BDDor(BDD that)Returns the logical 'or' of two BDDs.BDDorWith(BDD that)Makes this BDD be the logical 'or' of two BDDs.abstract doublepathCount()Counts the number of paths leading to the true terminal.voidprintDot()Prints this BDD in dot graph notation.protected intprintdot_rec(PrintStream out, int current, boolean[] visited, HashMap<BDD,Integer> map)voidprintSet()Prints the set of truth assignments specified by this BDD.voidprintSetWithDomains()Prints this BDD using a set notation as in printSet() but with the index of the finite domain blocks included instead of the BDD variables.BDDrelprod(BDD that, BDDVarSet var)Relational product.abstract BDDreplace(BDDPairing pair)Returns a BDD where all variables are replaced with the variables defined by pair.abstract BDDreplaceWith(BDDPairing pair)Replaces all variables in this BDD with the variables defined by pair.abstract BDDrestrict(BDD var)Restrict a set of variables to constant values.abstract BDDrestrictWith(BDD var)Mutates this BDD to restrict a set of variables to constant values.abstract doublesatCount()Calculates the number of satisfying variable assignments.doublesatCount(BDDVarSet varset)Calculates the number of satisfying variable assignments to the variables in the given varset.abstract BDDsatOne()Finds one satisfying variable assignment.abstract BDDsatOne(BDDVarSet var, boolean pol)Finds one satisfying variable assignment.BigInteger[]scanAllVar()Finds one satisfying assignment in this BDD of all the defined BDDDomain's.BigIntegerscanVar(BDDDomain d)Finds one satisfying assignment of the domaindin this BDD and returns that value.abstract BDDsimplify(BDD d)Coudert and Madre's restrict function.abstract BDDVarSetsupport()Returns the variable support of this BDD.StringtoString()StringtoStringWithDomains()Returns a string representation of this BDD using the defined domains.StringtoStringWithDomains(BDD.BDDToString ts)Returns a string representation of this BDD on the defined domains, using the given BDDToString converter.BDDVarSettoVarSet()Converts this BDD to a new BDDVarSet.abstract BDDunique(BDDVarSet var)Unique quantification of variables.abstract intvar()Gets the variable labeling the BDD.abstract int[]varProfile()Counts the number of times each variable occurs in this BDD.abstract BDDveccompose(BDDPairing pair)Simultaneous functional composition.BDDxor(BDD that)Returns the logical 'xor' of two BDDs.BDDxorWith(BDD that)Makes this BDD be the logical 'xor' of two BDDs.
-
-
-
Method Detail
-
getFactory
public abstract BDDFactory getFactory()
Returns the factory that created this BDD.- Returns:
- factory that created this BDD
-
isZero
public abstract boolean isZero()
Returns true if this BDD is the zero (false) BDD.- Returns:
- true if this BDD is the zero (false) BDD
-
isOne
public abstract boolean isOne()
Returns true if this BDD is the one (true) BDD.- Returns:
- true if this BDD is the one (true) BDD
-
isUniverse
public boolean isUniverse()
Returns true if this BDD is the universe BDD. The universal BDD differs from the one BDD in ZDD mode.- Returns:
- true if this BDD is the universe BDD
-
toVarSet
public BDDVarSet toVarSet()
Converts this BDD to a new BDDVarSet.This BDD must be a boolean function that represents the all-true minterm of the BDD variables of interest.
- Returns:
- the contents of this BDD as a new BDDVarSet
-
var
public abstract int var()
Gets the variable labeling the BDD.Compare to bdd_var.
- Returns:
- the index of the variable labeling the BDD
-
level
public int level()
Gets the level of this BDD.Compare to LEVEL() macro.
- Returns:
- the level of this BDD
-
high
public abstract BDD high()
Gets the true branch of this BDD.Compare to bdd_high.
- Returns:
- true branch of this BDD
-
low
public abstract BDD low()
Gets the false branch of this BDD.Compare to bdd_low.
- Returns:
- false branch of this BDD
-
id
public abstract BDD id()
Identity function. Returns a copy of this BDD. Use as the argument to the "xxxWith" style operators when you do not want to have the argument consumed.Compare to bdd_addref.
- Returns:
- copy of this BDD
-
not
public abstract BDD not()
Negates this BDD by exchanging all references to the zero-terminal with references to the one-terminal and vice-versa.Compare to bdd_not.
- Returns:
- the negated BDD
-
and
public BDD and(BDD that)
Returns the logical 'and' of two BDDs. This is a shortcut for calling "apply" with the "and" operator.Compare to bdd_and.
- Parameters:
that- BDD to 'and' with- Returns:
- the logical 'and' of two BDDs
-
andWith
public BDD andWith(BDD that)
Makes this BDD be the logical 'and' of two BDDs. The "that" BDD is consumed, and can no longer be used. This is a shortcut for calling "applyWith" with the "and" operator.Compare to bdd_and and bdd_delref.
- Parameters:
that- the BDD to 'and' with- Returns:
- the logical 'and' of the two BDDs
-
or
public BDD or(BDD that)
Returns the logical 'or' of two BDDs. This is a shortcut for calling "apply" with the "or" operator.Compare to bdd_or.
- Parameters:
that- the BDD to 'or' with- Returns:
- the logical 'or' of two BDDs
-
orWith
public BDD orWith(BDD that)
Makes this BDD be the logical 'or' of two BDDs. The "that" BDD is consumed, and can no longer be used. This is a shortcut for calling "applyWith" with the "or" operator.Compare to bdd_or and bdd_delref.
- Parameters:
that- the BDD to 'or' with- Returns:
- the logical 'or' of the two BDDs
-
xor
public BDD xor(BDD that)
Returns the logical 'xor' of two BDDs. This is a shortcut for calling "apply" with the "xor" operator.Compare to bdd_xor.
- Parameters:
that- the BDD to 'xor' with- Returns:
- the logical 'xor' of two BDDs
-
xorWith
public BDD xorWith(BDD that)
Makes this BDD be the logical 'xor' of two BDDs. The "that" BDD is consumed, and can no longer be used. This is a shortcut for calling "applyWith" with the "xor" operator.Compare to bdd_xor and bdd_delref.
- Parameters:
that- the BDD to 'xor' with- Returns:
- the logical 'xor' of the two BDDs
-
imp
public BDD imp(BDD that)
Returns the logical 'implication' of two BDDs. This is a shortcut for calling "apply" with the "imp" operator.Compare to bdd_imp.
- Parameters:
that- the BDD to 'implication' with- Returns:
- the logical 'implication' of two BDDs
-
impWith
public BDD impWith(BDD that)
Makes this BDD be the logical 'implication' of two BDDs. The "that" BDD is consumed, and can no longer be used. This is a shortcut for calling "applyWith" with the "imp" operator.Compare to bdd_imp and bdd_delref.
- Parameters:
that- the BDD to 'implication' with- Returns:
- the logical 'implication' of the two BDDs
-
biimp
public BDD biimp(BDD that)
Returns the logical 'bi-implication' of two BDDs. This is a shortcut for calling "apply" with the "biimp" operator.Compare to bdd_biimp.
- Parameters:
that- the BDD to 'bi-implication' with- Returns:
- the logical 'bi-implication' of two BDDs
-
biimpWith
public BDD biimpWith(BDD that)
Makes this BDD be the logical 'bi-implication' of two BDDs. The "that" BDD is consumed, and can no longer be used. This is a shortcut for calling "applyWith" with the "biimp" operator.Compare to bdd_biimp and bdd_delref.
- Parameters:
that- the BDD to 'bi-implication' with- Returns:
- the logical 'bi-implication' of two BDDs
-
ite
public abstract BDD ite(BDD thenBDD, BDD elseBDD)
if-then-else operator.Compare to bdd_ite.
- Parameters:
thenBDD- the 'then' BDDelseBDD- the 'else' BDD- Returns:
- the result of the if-then-else operator on the three BDDs
-
relprod
public BDD relprod(BDD that, BDDVarSet var)
Relational product. Calculates the relational product of the two BDDs as this AND that with the variables in var quantified out afterwards. Identical to applyEx(that, and, var).Compare to bdd_relprod.
- Parameters:
that- the BDD to 'and' withvar- the BDDVarSet to existentially quantify with- Returns:
- the result of the relational product
- See Also:
BDDDomain.set()
-
compose
public abstract BDD compose(BDD g, int var)
Functional composition. Substitutes the variable var with the BDD that in this BDD: result = f[g/var].Compare to bdd_compose.
- Parameters:
g- the function to use to replacevar- the variable number to replace- Returns:
- the result of the functional composition
-
veccompose
public abstract BDD veccompose(BDDPairing pair)
Simultaneous functional composition. Uses the pairs of variables and BDDs in pair to make the simultaneous substitution: f [g1/V1, ... gn/Vn]. In this way one or more BDDs may be substituted in one step. The BDDs in pair may depend on the variables they are substituting. BDD.compose() may be used instead of BDD.replace() but is not as efficient when gi is a single variable, the same applies to BDD.restrict(). Note that simultaneous substitution is not necessarily the same as repeated substitution.Compare to bdd_veccompose.
- Parameters:
pair- the pairing of variables to functions- Returns:
- BDD the result of the simultaneous functional composition
-
constrain
public abstract BDD constrain(BDD that)
Generalized cofactor. Computes the generalized cofactor of this BDD with respect to the given BDD.Compare to bdd_constrain.
- Parameters:
that- the BDD with which to compute the generalized cofactor- Returns:
- the result of the generalized cofactor
-
exist
public abstract BDD exist(BDDVarSet var)
Existential quantification of variables. Removes all occurrences of this BDD in variables in the set var by existential quantification.Compare to bdd_exist.
- Parameters:
var- BDDVarSet containing the variables to be existentially quantified- Returns:
- the result of the existential quantification
- See Also:
BDDDomain.set()
-
forAll
public abstract BDD forAll(BDDVarSet var)
Universal quantification of variables. Removes all occurrences of this BDD in variables in the set var by universal quantification.Compare to bdd_forall.
- Parameters:
var- BDDVarSet containing the variables to be universally quantified- Returns:
- the result of the universal quantification
- See Also:
BDDDomain.set()
-
unique
public abstract BDD unique(BDDVarSet var)
Unique quantification of variables. This type of quantification uses a XOR operator instead of an OR operator as in the existential quantification.Compare to bdd_unique.
- Parameters:
var- BDDVarSet containing the variables to be uniquely quantified- Returns:
- the result of the unique quantification
- See Also:
BDDDomain.set()
-
restrict
public abstract BDD restrict(BDD var)
Restrict a set of variables to constant values. Restricts the variables in this BDD to constant true if they are included in their positive form in var, and constant false if they are included in their negative form.Note that this is quite different than Coudert and Madre's restrict function.
Compare to bdd_restrict.
- Parameters:
var- BDD containing the variables to be restricted- Returns:
- the result of the restrict operation
- See Also:
simplify(BDD)
-
restrictWith
public abstract BDD restrictWith(BDD var)
Mutates this BDD to restrict a set of variables to constant values. Restricts the variables in this BDD to constant true if they are included in their positive form in var, and constant false if they are included in their negative form. The "that" BDD is consumed, and can no longer be used.Note that this is quite different than Coudert and Madre's restrict function.
Compare to bdd_restrict and bdd_delref.
- Parameters:
var- BDD containing the variables to be restricted- Returns:
- the result of the restrict operation
- See Also:
BDDDomain.set()
-
simplify
public abstract BDD simplify(BDD d)
Coudert and Madre's restrict function. Tries to simplify the BDD f by restricting it to the domain covered by d. No checks are done to see if the result is actually smaller than the input. This can be done by the user with a call to nodeCount().Compare to bdd_simplify.
- Parameters:
d- BDDVarSet containing the variables in the domain- Returns:
- the result of the simplify operation
-
support
public abstract BDDVarSet support()
Returns the variable support of this BDD. The support is all the variables that this BDD depends on.Compare to bdd_support.
- Returns:
- the variable support of this BDD
-
apply
public abstract BDD apply(BDD that, BDDFactory.BDDOp opr)
Returns the result of applying the binary operatoroprto the two BDDs.Compare to bdd_apply.
- Parameters:
that- the BDD to apply the operator onopr- the operator to apply- Returns:
- the result of applying the operator
-
applyWith
public abstract BDD applyWith(BDD that, BDDFactory.BDDOp opr)
Makes this BDD be the result of the binary operatoroprof two BDDs. The "that" BDD is consumed, and can no longer be used. Attempting to use the passed in BDD again will result in an exception being thrown.Compare to bdd_apply and bdd_delref.
- Parameters:
that- the BDD to apply the operator onopr- the operator to apply- Returns:
- the result of applying the operator
-
applyAll
public abstract BDD applyAll(BDD that, BDDFactory.BDDOp opr, BDDVarSet var)
Applies the binary operatoroprto two BDDs and then performs a universal quantification of the variables from the variable setvar.Compare to bdd_appall.
- Parameters:
that- the BDD to apply the operator onopr- the operator to applyvar- BDDVarSet containing the variables to quantify- Returns:
- the result
- See Also:
BDDDomain.set()
-
applyEx
public abstract BDD applyEx(BDD that, BDDFactory.BDDOp opr, BDDVarSet var)
Applies the binary operatoroprto two BDDs and then performs an existential quantification of the variables from the variable setvar.Compare to bdd_appex.
- Parameters:
that- the BDD to apply the operator onopr- the operator to applyvar- BDDVarSet containing the variables to quantify- Returns:
- the result
- See Also:
BDDDomain.set()
-
applyUni
public abstract BDD applyUni(BDD that, BDDFactory.BDDOp opr, BDDVarSet var)
Applies the binary operatoroprto two BDDs and then performs a unique quantification of the variables from the variable setvar.Compare to bdd_appuni.
- Parameters:
that- the BDD to apply the operator onopr- the operator to applyvar- BDDVarSet containing the variables to quantify- Returns:
- the result
- See Also:
BDDDomain.set()
-
satOne
public abstract BDD satOne()
Finds one satisfying variable assignment. Finds a BDD with at most one variable at each level. The new BDD implies this BDD and is not false unless this BDD is false.Compare to bdd_satone.
- Returns:
- one satisfying variable assignment
-
fullSatOne
public abstract BDD fullSatOne()
Finds one satisfying variable assignment. Finds a BDD with exactly one variable at all levels. The new BDD implies this BDD and is not false unless this BDD is false.Compare to bdd_fullsatone.
- Returns:
- one satisfying variable assignment
-
satOne
public abstract BDD satOne(BDDVarSet var, boolean pol)
Finds one satisfying variable assignment. Finds a minterm in this BDD. Thevarargument is a set of variables that must be mentioned in the result. The polarity of these variables in the result - in case they are undefined in this BDD - are defined by thepolparameter. Ifpolis false, then all variables will be in negative form. Otherwise they will be in positive form.Compare to bdd_satoneset.
- Parameters:
var- BDDVarSet containing the set of variables that must be mentioned in the resultpol- the polarity of the result- Returns:
- one satisfying variable assignment
- See Also:
BDDDomain.set()
-
allsat
public BDD.AllSatIterator allsat()
Finds all satisfying variable assignments.Compare to bdd_allsat.
- Returns:
- all satisfying variable assignments
-
scanVar
public BigInteger scanVar(BDDDomain d)
Finds one satisfying assignment of the domaindin this BDD and returns that value.Compare to fdd_scanvar.
- Parameters:
d- domain to scan- Returns:
- one satisfying assignment for that domain
-
scanAllVar
public BigInteger[] scanAllVar()
Finds one satisfying assignment in this BDD of all the defined BDDDomain's. Each value is stored in an array which is returned. The size of this array is exactly the number of BDDDomain's defined.Compare to fdd_scanallvar.
- Returns:
- array containing one satisfying assignment of all the defined domains
-
iterator
public BDD.BDDIterator iterator(BDDVarSet var)
Returns an iteration of the satisfying assignments of this BDD. Returns an iteration of minterms. Thevarargument is the set of variables that will be mentioned in the result.- Parameters:
var- set of variables to mention in result- Returns:
- an iteration of minterms
- See Also:
BDDDomain.set()
-
replace
public abstract BDD replace(BDDPairing pair)
Returns a BDD where all variables are replaced with the variables defined by pair. Each entry in pair consists of a old and a new variable. Whenever the old variable is found in this BDD then a new node with the new variable is inserted instead.Compare to bdd_replace.
- Parameters:
pair- pairing of variables to the BDDs that replace those variables- Returns:
- result of replace
-
replaceWith
public abstract BDD replaceWith(BDDPairing pair)
Replaces all variables in this BDD with the variables defined by pair. Each entry in pair consists of a old and a new variable. Whenever the old variable is found in this BDD then a new node with the new variable is inserted instead. Mutates the current BDD.Compare to bdd_replace and bdd_delref.
- Parameters:
pair- pairing of variables to the BDDs that replace those variables- Returns:
- result of replace
-
printSet
public void printSet()
Prints the set of truth assignments specified by this BDD.Compare to bdd_printset.
-
printSetWithDomains
public void printSetWithDomains()
Prints this BDD using a set notation as in printSet() but with the index of the finite domain blocks included instead of the BDD variables.Compare to fdd_printset.
-
printDot
public void printDot()
Prints this BDD in dot graph notation.Compare to bdd_printdot.
-
printdot_rec
protected int printdot_rec(PrintStream out, int current, boolean[] visited, HashMap<BDD,Integer> map)
-
nodeCount
public abstract int nodeCount()
Counts the number of distinct nodes used for this BDD.Compare to bdd_nodecount.
- Returns:
- the number of distinct nodes used for this BDD
-
pathCount
public abstract double pathCount()
Counts the number of paths leading to the true terminal.Compare to bdd_pathcount.
- Returns:
- the number of paths leading to the true terminal
-
satCount
public abstract double satCount()
Calculates the number of satisfying variable assignments.Compare to bdd_satcount.
- Returns:
- the number of satisfying variable assignments
-
satCount
public double satCount(BDDVarSet varset)
Calculates the number of satisfying variable assignments to the variables in the given varset. ASSUMES THAT THE BDD DOES NOT HAVE ANY ASSIGNMENTS TO VARIABLES THAT ARE NOT IN VARSET. You will need to quantify out the other variables first.Compare to bdd_satcountset.
- Parameters:
varset- the given varset- Returns:
- the number of satisfying variable assignments
-
logSatCount
public double logSatCount()
Calculates the logarithm of the number of satisfying variable assignments.Compare to bdd_satcount.
- Returns:
- the logarithm of the number of satisfying variable assignments
-
logSatCount
public double logSatCount(BDDVarSet varset)
Calculates the logarithm of the number of satisfying variable assignments to the variables in the given varset.Compare to bdd_satcountset.
- Parameters:
varset- the given varset- Returns:
- the logarithm of the number of satisfying variable assignments
-
varProfile
public abstract int[] varProfile()
Counts the number of times each variable occurs in this BDD. The result is stored and returned in an integer array where the i'th position stores the number of times the i'th printing variable occurred in the BDD.Compare to bdd_varprofile.
- Returns:
- the variable profile
-
equalsBDD
public abstract boolean equalsBDD(BDD that)
Returns true if this BDD equals that BDD, false otherwise.- Parameters:
that- the BDD to compare with- Returns:
- true iff the two BDDs are equal
-
toStringWithDomains
public String toStringWithDomains()
Returns a string representation of this BDD using the defined domains.- Returns:
- string representation of this BDD using the defined domains
-
toStringWithDomains
public String toStringWithDomains(BDD.BDDToString ts)
Returns a string representation of this BDD on the defined domains, using the given BDDToString converter.- Parameters:
ts- the given BDDToString converter- Returns:
- string representation of this BDD using the given BDDToString converter
- See Also:
BDD.BDDToString
-
free
public abstract void free()
Frees this BDD. Further use of this BDD will result in an exception being thrown.
-
-