Package-level declarations

Types

Link copied to clipboard

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.

Link copied to clipboard

This interfaces hides the strategy with which instances of BinaryDecisionDiagram are created. Platform-specific optimized representations of BDDs can be introduced by providing new implementations of this interface.

Link copied to clipboard

Implements the Visitor pattern over a BinaryDecisionDiagram to its hierarchy, which only includes instances of BinaryDecisionDiagram.Terminal and BinaryDecisionDiagram.Variable. This abstraction is the method of choice to explore the internal structure of a BDD, dispatched through BinaryDecisionDiagram.accept rather than by checking BinaryDecisionDiagram.isTerminal/BinaryDecisionDiagram.isVariable and casting manually. All BDD operators and utilities in this module (e.g. expansion, apply, any, map) are themselves implemented as internal visitors.

Functions

Link copied to clipboard

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.

Link copied to clipboard
fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.andThenExpansion(that: BinaryDecisionDiagram<T>, expansionFalseTerminal: E, expansionTrueTerminal: E, expansionOperator: (node: T, low: E, high: E) -> E): Pair<BinaryDecisionDiagram<T>, E>

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.

Link copied to clipboard

Returns true if the BinaryDecisionDiagram has at least one variable element, i.e. it is not just a Terminal.

fun <T : Comparable<T>> BinaryDecisionDiagram<T>.any(predicate: (T) -> Boolean): Boolean

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.

Link copied to clipboard

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

Link copied to clipboard
fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.applyThenExpansion(unaryOp: (Boolean) -> Boolean, expansionFalseTerminal: E, expansionTrueTerminal: E, expansionOperator: (node: T, low: E, high: E) -> E): Pair<BinaryDecisionDiagram<T>, E>

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.

fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.applyThenExpansion(that: BinaryDecisionDiagram<T>, binaryOp: (Boolean, Boolean) -> Boolean, expansionFalseTerminal: E, expansionTrueTerminal: E, expansionOperator: (node: T, low: E, high: E) -> E): Pair<BinaryDecisionDiagram<T>, E>

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.

Link copied to clipboard

Shortcut for the BinaryDecisionDiagram.variableOf method, creating a single-Variable diagram out of value. This is the usual entry point for building up a BDD-encoded formula, e.g. in it.unibo.tuprolog.solve.problog.lib.knowledge.ProbExplanation.of, where a probabilistic Prolog term is turned into its single-variable explanation with bddOf(term), ready to be combined with and/or/not.

Link copied to clipboard

Shortcut for the BinaryDecisionDiagram.terminalOf method, creating a Terminal diagram representing the constant value. Used e.g. in it.unibo.tuprolog.solve.problog.lib.knowledge.ProbExplanation to represent the constant TRUE/FALSE explanations with bddTerminalOf(true) / bddTerminalOf(false).

Link copied to clipboard

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.

Link copied to clipboard
fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.expansion(falseTerminal: E, trueTerminal: E, operator: (node: T, low: E, high: E) -> E): E

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.

Link copied to clipboard

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

Link copied to clipboard

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.

Link copied to clipboard
fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.notThenExpansion(expansionFalseTerminal: E, expansionTrueTerminal: E, expansionOperator: (node: T, low: E, high: E) -> E): Pair<BinaryDecisionDiagram<T>, E>

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.

Link copied to clipboard

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.

Link copied to clipboard
fun <T : Comparable<T>, E> BinaryDecisionDiagram<T>.orThenExpansion(that: BinaryDecisionDiagram<T>, expansionFalseTerminal: E, expansionTrueTerminal: E, expansionOperator: (node: T, low: E, high: E) -> E): Pair<BinaryDecisionDiagram<T>, E>

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.

Link copied to clipboard

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.