net.sf.javabdd
Class BDD

java.lang.Object
  extended by net.sf.javabdd.BDD
Direct Known Subclasses:
BDDFactoryIntImpl.IntBDD, TypedBDDFactory.TypedBDD

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.

Version:
$Id: BDD.java 472 2006-12-03 10:32:26Z joewhaley $
Author:
John Whaley
See Also:
BDDFactory, BDDDomain.set()

Nested Class Summary
static class BDD.AllSatIterator
          Iterator that returns all satisfying assignments as byte arrays.
static class BDD.BDDIterator
          BDDIterator is used to iterate through the satisfying assignments of a BDD.
static class BDD.BDDToString
          BDDToString is used to specify the printing behavior of BDDs with domains.
 
Constructor Summary
protected BDD()
          Protected constructor.
 
Method Summary
 BDD.AllSatIterator allsat()
          Finds all satisfying variable assignments.
 BDD and(BDD that)
          Returns the logical 'and' of two BDDs.
 BDD andWith(BDD that)
          Makes this BDD be the logical 'and' of two BDDs.
abstract  BDD apply(BDD that, BDDFactory.BDDOp opr)
          Returns the result of applying the binary operator opr to the two BDDs.
abstract  BDD applyAll(BDD that, BDDFactory.BDDOp opr, BDDVarSet var)
          Applies the binary operator opr to two BDDs and then performs a universal quantification of the variables from the variable set var.
abstract  BDD applyEx(BDD that, BDDFactory.BDDOp opr, BDDVarSet var)
          Applies the binary operator opr to two BDDs and then performs an existential quantification of the variables from the variable set var.
abstract  BDD applyUni(BDD that, BDDFactory.BDDOp opr, BDDVarSet var)
          Applies the binary operator opr to two BDDs and then performs a unique quantification of the variables from the variable set var.
abstract  BDD applyWith(BDD that, BDDFactory.BDDOp opr)
          Makes this BDD be the result of the binary operator opr of two BDDs.
 BDD biimp(BDD that)
          Returns the logical 'bi-implication' of two BDDs.
 BDD biimpWith(BDD that)
          Makes this BDD be the logical 'bi-implication' of two BDDs.
abstract  BDD compose(BDD g, int var)
          Functional composition.
abstract  BDD constrain(BDD that)
          Generalized cofactor.
abstract  boolean equals(BDD that)
          Returns true if this BDD equals that BDD, false otherwise.
 boolean equals(Object o)
           
abstract  BDD exist(BDDVarSet var)
          Existential quantification of variables.
abstract  BDD forAll(BDDVarSet var)
          Universal quantification of variables.
abstract  void free()
          Frees this BDD.
abstract  BDD fullSatOne()
          Finds one satisfying variable assignment.
abstract  BDDFactory getFactory()
          Returns the factory that created this BDD.
abstract  int hashCode()
           
abstract  BDD high()
          Gets the true branch of this BDD.
abstract  BDD id()
          Identity function.
 BDD imp(BDD that)
          Returns the logical 'implication' of two BDDs.
 BDD impWith(BDD that)
          Makes this BDD be the logical 'implication' of two BDDs.
abstract  boolean isOne()
          Returns true if this BDD is the one (true) BDD.
 boolean isUniverse()
          Returns true if this BDD is the universe BDD.
abstract  boolean isZero()
          Returns true if this BDD is the zero (false) BDD.
abstract  BDD ite(BDD thenBDD, BDD elseBDD)
          if-then-else operator.
 BDD.BDDIterator iterator(BDDVarSet var)
          Returns an iteration of the satisfying assignments of this BDD.
 int level()
          Gets the level of this BDD.
 double logSatCount()
          Calculates the logarithm of the number of satisfying variable assignments.
 double logSatCount(BDDVarSet varset)
          Calculates the logarithm of the number of satisfying variable assignments to the variables in the given varset.
abstract  BDD low()
          Gets the false branch of this BDD.
abstract  int nodeCount()
          Counts the number of distinct nodes used for this BDD.
abstract  BDD not()
          Negates this BDD by exchanging all references to the zero-terminal with references to the one-terminal and vice-versa.
 BDD or(BDD that)
          Returns the logical 'or' of two BDDs.
 BDD orWith(BDD that)
          Makes this BDD be the logical 'or' of two BDDs.
abstract  double pathCount()
          Counts the number of paths leading to the true terminal.
protected  int printdot_rec(PrintStream out, int current, boolean[] visited, HashMap map)
           
 void printDot()
          Prints this BDD in dot graph notation.
 void printSet()
          Prints the set of truth assignments specified by this BDD.
 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.
 BDD relprod(BDD that, BDDVarSet var)
          Relational product.
abstract  BDD replace(BDDPairing pair)
          Returns a BDD where all variables are replaced with the variables defined by pair.
abstract  BDD replaceWith(BDDPairing pair)
          Replaces all variables in this BDD with the variables defined by pair.
abstract  BDD restrict(BDD var)
          Restrict a set of variables to constant values.
abstract  BDD restrictWith(BDD var)
          Mutates this BDD to restrict a set of variables to constant values.
abstract  double satCount()
          Calculates the number of satisfying variable assignments.
 double satCount(BDDVarSet varset)
          Calculates the number of satisfying variable assignments to the variables in the given varset.
abstract  BDD satOne()
          Finds one satisfying variable assignment.
abstract  BDD satOne(BDDVarSet var, boolean pol)
          Finds one satisfying variable assignment.
 BigInteger[] scanAllVar()
          Finds one satisfying assignment in this BDD of all the defined BDDDomain's.
 BigInteger scanVar(BDDDomain d)
          Finds one satisfying assignment of the domain d in this BDD and returns that value.
abstract  BDD simplify(BDDVarSet d)
          Coudert and Madre's restrict function.
abstract  BDDVarSet support()
          Returns the variable support of this BDD.
 String toString()
           
 String toStringWithDomains()
          Returns a string representation of this BDD using the defined domains.
 String toStringWithDomains(BDD.BDDToString ts)
          Returns a string representation of this BDD on the defined domains, using the given BDDToString converter.
 BDDVarSet toVarSet()
          Converts this BDD to a new BDDVarSet.
abstract  BDD unique(BDDVarSet var)
          Unique quantification of variables.
abstract  int var()
          Gets the variable labeling the BDD.
abstract  int[] varProfile()
          Counts the number of times each variable occurs in this BDD.
abstract  BDD veccompose(BDDPairing pair)
          Simultaneous functional composition.
 BDD xor(BDD that)
          Returns the logical 'xor' of two BDDs.
 BDD xorWith(BDD that)
          Makes this BDD be the logical 'xor' of two BDDs.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BDD

protected BDD()

Protected constructor.

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

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

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

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

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

ite

public abstract BDD ite(BDD thenBDD,
                        BDD elseBDD)

if-then-else operator.

Compare to bdd_ite.

Parameters:
thenBDD - the 'then' BDD
elseBDD - 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' with
var - 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 replace
var - 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:
net.sf.javabdd.BDD#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
See Also:
BDDDomain.set()

simplify

public abstract BDD simplify(BDDVarSet 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 operator opr to the two BDDs.

Compare to bdd_apply.

Parameters:
that - the BDD to apply the operator on
opr - 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 operator opr of 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 on
opr - the operator to apply

applyAll

public abstract BDD applyAll(BDD that,
                             BDDFactory.BDDOp opr,
                             BDDVarSet var)

Applies the binary operator opr to two BDDs and then performs a universal quantification of the variables from the variable set var.

Compare to bdd_appall.

Parameters:
that - the BDD to apply the operator on
opr - the operator to apply
var - 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 operator opr to two BDDs and then performs an existential quantification of the variables from the variable set var.

Compare to bdd_appex.

Parameters:
that - the BDD to apply the operator on
opr - the operator to apply
var - 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 operator opr to two BDDs and then performs a unique quantification of the variables from the variable set var.

Compare to bdd_appuni.

Parameters:
that - the BDD to apply the operator on
opr - the operator to apply
var - 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. The var argument 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 the pol parameter. If pol is 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 result
pol - 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 domain d in 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. The var argument 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

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 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.

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.

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.


equals

public abstract boolean equals(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

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public abstract int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

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.

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.



Copyright © 2003-2007 John Whaley. All Rights Reserved.