BinaryDecisionDiagram
A Binary Decision Diagram (BDD) is a rooted, directed, acyclic graph, which consists of several decision nodes and terminal nodes and uses the concept of Shannon Expansion to represent and encode complex Boolean Formulas.
Each node of the diagram represents a single boolean entry with variable value and part of a Boolean function. T is the type with which a variable is represented. In the context of a formula, variables for which the compareTo method (from the Comparable bound on T) returns 0 indicate the same Boolean variable.
Each BDD node has a directed edge to two sub-BDDs: the "high" BDD that leads to a true Terminal, and the "low" BDD that leads to a false Terminal.
In 2P-Kt, this data structure backs probabilistic logic programming (:solve-plp, :solve-problog): a probabilistic query's explanation is modeled as a Boolean formula over probabilistic clauses/facts (the BDD variables), combined with and, or and not. Since a BDD is a canonical, compressed encoding of that formula, expansion can then be used to compute the query's probability via Weighted Model Counting, bottom-up over the diagram, without re-evaluating the original formula. See it.unibo.tuprolog.solve.problog.lib.knowledge.impl.BinaryDecisionDiagramExplanation for the concrete usage of this API to implement such an explanation.
Basic usage:
val burglary = bddOf(ComparablePair(0, "burglary", 0.7))
val earthquake = bddOf(ComparablePair(1, "earthquake", 0.2))
val solution = (bddOf(alarm) and burglary and earthquake) or (bddOf(otherAlarm) and burglary)
val probability = solution.expansion(0.0, 1.0) { node, low, high ->
node.probabilityValue * high + (1.0 - node.probabilityValue) * low
}Author
Jason Dellaluce
Inheritors
Types
Properties
Functions
Accepts an instance of BinaryDecisionDiagramVisitor as for the visitor pattern. This is the method of preference for exploring the inner structure of the diagram, since it distinguishes between Terminal and Variable nodes without runtime type checks by the caller.
Performs the "And" binary boolean operation over two BinaryDecisionDiagrams. The result is a Reduced Ordered Binary Decision Diagram (ROBDD) representing the logical conjunction of the Boolean formulas encoded by the two diagrams.
Performs the "And" binary boolean operation over two BinaryDecisionDiagrams and computes a value using the Shannon Expansion over the result. The result is an instance of Pair of which Pair.first is the Reduced Ordered Binary Decision Diagram (ROBDD) produced by the operation, and Pair.second is the value of type E computed with the Shannon Expansion.
Returns true if the BinaryDecisionDiagram has at least one variable element, i.e. it is not just a Terminal.
Returns true if the BinaryDecisionDiagram has at least one Variable element matching the given predicate. Used e.g. by it.unibo.tuprolog.solve.problog.lib.knowledge.impl.BinaryDecisionDiagramExplanation.containsAnyNotGroundTerm as diagram.any { !it.isGround }, to detect explanations that still contain unbound Prolog terms.
Applies the "Apply" construction algorithm over BinaryDecisionDiagrams using a given unary boolean operator. The result is a Reduced Ordered Binary Decision Diagram (ROBDD).
Applies the "Apply" construction algorithm over two BinaryDecisionDiagrams using a given binary boolean operator. The result is a Reduced Ordered Binary Decision Diagram (ROBDD).
Applies the "Apply" construction algorithm over BinaryDecisionDiagrams using a given unary boolean operator, and computes a value using the Shannon Expansion over the result. The result is an instance of Pair of which Pair.first is the Reduced Ordered Binary Decision Diagram (ROBDD) produced by the operation, and Pair.second is the value of type E computed with the Shannon Expansion.
Applies the "Apply" construction algorithm over two BinaryDecisionDiagrams using a given binary boolean operator, and computes a value using the Shannon Expansion over the result. The result is an instance of Pair of which Pair.first is the Reduced Ordered Binary Decision Diagram (ROBDD) produced by the operation, and Pair.second is the value of type E computed with the Shannon Expansion.
Returns the number of Variable nodes contained in a BinaryDecisionDiagram. Note that, since a node can be shared by multiple parents (e.g. in a reduced diagram built by BinaryDecisionDiagramBuilder.reducedOf), a shared node is counted once for every path that reaches it, not once overall.
Applies a given operation over a BinaryDecisionDiagram using the Shannon Expansion. The result is a reduction of a given diagram, determined by applying an operation recursively over a BDD with bottom-up order: each Terminal is mapped to falseTerminal/trueTerminal, and each Variable is folded with operator, receiving the already-computed E values of its low/high sub-diagrams.
Returns a BinaryDecisionDiagram containing nodes of applying the given transform function to each element in the original BinaryDecisionDiagram. The internal structure of the diagram is maintained. Used e.g. by it.unibo.tuprolog.solve.problog.lib.knowledge.impl.BinaryDecisionDiagramExplanation.apply to rewrite the Prolog terms held by every variable of an explanation (e.g. after applying a substitution), as diagram.map { transformation(it) }.
Performs the "Not" unary boolean operation over a BinaryDecisionDiagram. The result is a Reduced Ordered Binary Decision Diagram (ROBDD) representing the logical negation of the Boolean formula encoded by this diagram.
Performs the "Not" unary boolean operation over a BinaryDecisionDiagram and computes a value using the Shannon Expansion over the result. The result is an instance of Pair of which Pair.first is the Reduced Ordered Binary Decision Diagram (ROBDD) produced by the operation, and Pair.second is the value of type E computed with the Shannon Expansion.
Performs the "Or" binary boolean operation over two BinaryDecisionDiagrams. The result is a Reduced Ordered Binary Decision Diagram (ROBDD) representing the logical disjunction of the Boolean formulas encoded by the two diagrams.
Performs the "Or" binary boolean operation over two BinaryDecisionDiagrams and computes a value using the Shannon Expansion over the result. The result is an instance of Pair of which Pair.first is the Reduced Ordered Binary Decision Diagram (ROBDD) produced by the operation, and Pair.second is the value of type E computed with the Shannon Expansion.
Formats a BinaryDecisionDiagram using Graphviz DOT notation (https://graphviz.org/). This provides a fast and widely supported solution to visualize the contents of a BDD.