- java.lang.Object
-
- org.logicng.knowledgecompilation.bdds.BDD
-
public class BDD extends Object
The internal representation of a BDD.- Since:
- 1.4.0
- Version:
- 2.4.0
-
-
Field Summary
Fields Modifier and Type Field Description protected BDDConstructionconstructionprotected BDDKernelkernelprotected BDDOperationsoperations
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BDDand(BDD other)Returns a new BDD which is the conjunction of this BDD and the given other BDD.<T> Tapply(BDDFunction<T> function)Applies a given function on this BDD and returns the result.Formulacnf()Returns a CNF formula for this BDD.Formuladnf()Returns a DNF formula for this BDD.List<Assignment>enumerateAllModels()Enumerates all models of this BDD.List<Assignment>enumerateAllModels(Collection<Variable> variables)Enumerates all models of this BDD wrt.List<Assignment>enumerateAllModels(Variable... variables)Enumerates all models of this BDD wrt.booleanequals(Object other)BDDequivalence(BDD other)Returns a new BDD which is the equivalence of this BDD and the other given BDD.BDDexists(Collection<Variable> variables)Existential quantifier elimination for a given set of variables.BDDexists(Variable... variables)Existential quantifier elimination for a given set of variables.BDDforall(Collection<Variable> variables)Universal quantifier elimination for a given set of variables.BDDforall(Variable... variables)Universal quantifier elimination for a given set of variables.AssignmentfullModel()Returns a full model of this BDD ornullif there is none.BDDReorderinggetReordering()Returns the reordering object for the BDD kernel.List<Variable>getVariableOrder()Returns the variable order of this BDD.inthashCode()BDDimpliedBy(BDD other)Returns a new BDD which is the implication of the other given BDD to this BDD.BDDimplies(BDD other)Returns a new BDD which is the implication of this BDD to the given other BDD.intindex()Returns the index of this BDD.booleanisContradiction()Returnstrueif this BDD is a contradiction,falseotherwise.booleanisTautology()Returnstrueif this BDD is a tautology,falseotherwise.Assignmentmodel()Returns an arbitrary model of this BDD ornullif there is none.Assignmentmodel(boolean defaultValue, Collection<Variable> variables)Returns an arbitrary model of this BDD which contains at least the given variables ornullif there is none.Assignmentmodel(boolean defaultValue, Variable... variables)Returns an arbitrary model of this BDD which contains at least the given variables ornullif there is none.BigIntegermodelCount()Returns the model count of this BDD.BDDnegate()Returns a new BDD which is the negation of this BDD.intnodeCount()Returns the number of distinct nodes for this BDD.BigIntegernumberOfClausesCNF()Returns the number of clauses for the CNF formula of the BDD.BDDor(BDD other)Returns a new BDD which is the disjunction of this BDD and the given other BDD.BigIntegerpathCountOne()Returns the number of paths leading to the terminal 'one' node.BigIntegerpathCountZero()Returns the number of paths leading to the terminal 'zero' node.BDDrestrict(Collection<Literal> restriction)Restricts the BDD.BDDrestrict(Literal... restriction)Restricts the BDD.SortedSet<Variable>support()Returns all the variables this BDD depends on.voidswapVariables(Variable first, Variable second)Swaps two variables in a BDD.FormulatoFormula()Returns a formula representation of this BDD.FormulatoFormula(boolean followPathsToTrue)Returns a formula representation of this BDD.BDDNodetoLngBdd()Returns a LogicNG internal BDD data structure of this BDD.StringtoString()BDDKernelunderlyingKernel()Returns the BDD Kernel of this factory.SortedMap<Variable,Integer>variableProfile()Returns how often each variable occurs in this BDD.
-
-
-
Field Detail
-
kernel
protected final BDDKernel kernel
-
construction
protected final BDDConstruction construction
-
operations
protected final BDDOperations operations
-
-
Constructor Detail
-
BDD
public BDD(int index, BDDKernel kernel)Constructs a new BDD with a given index.- Parameters:
index- the indexkernel- the kernel of this BDD
-
-
Method Detail
-
index
public int index()
Returns the index of this BDD.The index marks the entry point of this BDD in the
underlying kernel.- Returns:
- the index of this BDD
-
underlyingKernel
public BDDKernel underlyingKernel()
Returns the BDD Kernel of this factory. The Kernel should only be accessed when you know, what you are doing.- Returns:
- the BDD Kernel
-
apply
public <T> T apply(BDDFunction<T> function)
Applies a given function on this BDD and returns the result.- Type Parameters:
T- the result type of the function- Parameters:
function- the function- Returns:
- the result of the function application
-
toFormula
public Formula toFormula()
Returns a formula representation of this BDD. This is done by using the Shannon expansion.- Returns:
- the formula for this BDD
-
toFormula
public Formula toFormula(boolean followPathsToTrue)
Returns a formula representation of this BDD. This is done by using the Shannon expansion. IffollowPathsToTrueis activated, the paths leading to thetrueterminal are followed to generate the formula. IffollowPathsToTrueis deactivated, the paths leading to thefalseterminal are followed to generate the formula and the resulting formula is negated. Depending on the formula and the number of satisfying assignments, the generated formula can be more compact using thetruepaths orfalsepaths, respectively.- Parameters:
followPathsToTrue- the extraction style- Returns:
- the formula for this BDD
-
negate
public BDD negate()
Returns a new BDD which is the negation of this BDD.- Returns:
- the negation of this BDD
-
implies
public BDD implies(BDD other)
Returns a new BDD which is the implication of this BDD to the given other BDD. Both BDDs must use the same kernel.- Parameters:
other- the other BDD- Returns:
- the implication from this BDD to the other BDD
- Throws:
IllegalArgumentException- if the two BDDs don't have the same kernel
-
impliedBy
public BDD impliedBy(BDD other)
Returns a new BDD which is the implication of the other given BDD to this BDD. Both BDDs must use the same kernel.- Parameters:
other- the other BDD- Returns:
- the implication from the other BDD to this BDD
- Throws:
IllegalArgumentException- if the two BDDs don't have the same kernel
-
equivalence
public BDD equivalence(BDD other)
Returns a new BDD which is the equivalence of this BDD and the other given BDD. Both BDDs must use the same kernel.- Parameters:
other- the other BDD- Returns:
- the equivalence of this and the other BDD
- Throws:
IllegalArgumentException- if the two BDDs don't have the same kernel
-
and
public BDD and(BDD other)
Returns a new BDD which is the conjunction of this BDD and the given other BDD. Both BDDs must use the same kernel.- Parameters:
other- the other BDD- Returns:
- the conjunction of the two BDDs
- Throws:
IllegalArgumentException- if the two BDDs don't have the same kernel
-
or
public BDD or(BDD other)
Returns a new BDD which is the disjunction of this BDD and the given other BDD. Both BDDs must use the same kernel.- Parameters:
other- the other BDD- Returns:
- the disjunction of the two BDDs
- Throws:
IllegalArgumentException- if the two BDDs don't have the same kernel
-
isTautology
public boolean isTautology()
Returnstrueif this BDD is a tautology,falseotherwise.- Returns:
trueif this BDD is a tautology,falseotherwise
-
isContradiction
public boolean isContradiction()
Returnstrueif this BDD is a contradiction,falseotherwise.- Returns:
trueif this BDD is a contradiction,falseotherwise
-
modelCount
public BigInteger modelCount()
Returns the model count of this BDD.- Returns:
- the model count
-
enumerateAllModels
public List<Assignment> enumerateAllModels()
Enumerates all models of this BDD.- Returns:
- the list of all models
-
enumerateAllModels
public List<Assignment> enumerateAllModels(Variable... variables)
Enumerates all models of this BDD wrt. a given set of variables.- Parameters:
variables- the variables- Returns:
- the list of all models
-
enumerateAllModels
public List<Assignment> enumerateAllModels(Collection<Variable> variables)
Enumerates all models of this BDD wrt. a given set of variables.- Parameters:
variables- the variables- Returns:
- the list of all models
-
cnf
public Formula cnf()
Returns a CNF formula for this BDD.- Returns:
- the CNF for the formula represented by this BDD
-
numberOfClausesCNF
public BigInteger numberOfClausesCNF()
Returns the number of clauses for the CNF formula of the BDD.- Returns:
- the number of clauses for the CNF formula of the BDD
-
dnf
public Formula dnf()
Returns a DNF formula for this BDD.- Returns:
- the DNF for the formula represented by this BDD
-
restrict
public BDD restrict(Collection<Literal> restriction)
Restricts the BDD.- Parameters:
restriction- the restriction- Returns:
- the restricted BDD
-
restrict
public BDD restrict(Literal... restriction)
Restricts the BDD.- Parameters:
restriction- the restriction- Returns:
- the restricted BDD
-
exists
public BDD exists(Collection<Variable> variables)
Existential quantifier elimination for a given set of variables.- Parameters:
variables- the variables to eliminate- Returns:
- the BDD with the eliminated variables
-
exists
public BDD exists(Variable... variables)
Existential quantifier elimination for a given set of variables.- Parameters:
variables- the variables to eliminate- Returns:
- the BDD with the eliminated variables
-
forall
public BDD forall(Collection<Variable> variables)
Universal quantifier elimination for a given set of variables.- Parameters:
variables- the variables to eliminate- Returns:
- the BDD with the eliminated variables
-
forall
public BDD forall(Variable... variables)
Universal quantifier elimination for a given set of variables.- Parameters:
variables- the variables to eliminate- Returns:
- the BDD with the eliminated variables
-
model
public Assignment model()
Returns an arbitrary model of this BDD ornullif there is none.- Returns:
- an arbitrary model of this BDD
-
model
public Assignment model(boolean defaultValue, Collection<Variable> variables)
Returns an arbitrary model of this BDD which contains at least the given variables ornullif there is none. If a variable is a don't care variable, it will be assigned with the given default value.- Parameters:
defaultValue- the default value for don't care variablesvariables- the set of variable which has to be contained in the model- Returns:
- an arbitrary model of this BDD
-
model
public Assignment model(boolean defaultValue, Variable... variables)
Returns an arbitrary model of this BDD which contains at least the given variables ornullif there is none. If a variable is a don't care variable, it will be assigned with the given default value.- Parameters:
defaultValue- the default value for don't care variablesvariables- the set of variable which has to be contained in the model- Returns:
- an arbitrary model of this BDD
-
fullModel
public Assignment fullModel()
Returns a full model of this BDD ornullif there is none.- Returns:
- a full model of this BDD
-
pathCountOne
public BigInteger pathCountOne()
Returns the number of paths leading to the terminal 'one' node.- Returns:
- the number of paths leading to the terminal 'one' node
-
pathCountZero
public BigInteger pathCountZero()
Returns the number of paths leading to the terminal 'zero' node.- Returns:
- the number of paths leading to the terminal 'zero' node
-
support
public SortedSet<Variable> support()
Returns all the variables this BDD depends on.- Returns:
- all the variables that this BDD depends on
-
nodeCount
public int nodeCount()
Returns the number of distinct nodes for this BDD.- Returns:
- the number of distinct nodes
-
variableProfile
public SortedMap<Variable,Integer> variableProfile()
Returns how often each variable occurs in this BDD.- Returns:
- how often each variable occurs in the BDD
-
getVariableOrder
public List<Variable> getVariableOrder()
Returns the variable order of this BDD.- Returns:
- the variable order
-
swapVariables
public void swapVariables(Variable first, Variable second)
Swaps two variables in a BDD. Beware that if theBDDKernelof this BDD was used for multiple BDDs, the variables are swapped in all of these BDDs.- Parameters:
first- the first variable to swapsecond- the second variable to swap
-
getReordering
public BDDReordering getReordering()
Returns the reordering object for the BDD kernel.- Returns:
- the reordering object
-
toLngBdd
public BDDNode toLngBdd()
Returns a LogicNG internal BDD data structure of this BDD.- Returns:
- the BDD as LogicNG data structure
-
-