All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.it.unibo.tuprolog.bdd.BinaryDecisionDiagramBuilder.kt Maven / Gradle / Ivy

Go to download

Multi-platform library for representing and manipulating Binary Decision Diagrams

There is a newer version: 1.0.4
Show newest version
package it.unibo.tuprolog.bdd

import it.unibo.tuprolog.bdd.impl.builder.ReducedBinaryDecisionDiagramBuilder
import it.unibo.tuprolog.bdd.impl.builder.SimpleBinaryDecisionDiagramBuilder
import kotlin.js.JsName

/**
 * 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.
 *
 * Business logic related to diagram reduction, or node re-usage,
 * should be handled by this entity.
 *
 * @author Jason Dellaluce
 */
interface BinaryDecisionDiagramBuilder> {

    /**
     * Returns an instance of [BinaryDecisionDiagram.Variable] with
     * the provided input.
     * */
    @JsName("buildVariable")
    fun buildVariable(value: T, low: BinaryDecisionDiagram, high: BinaryDecisionDiagram): BinaryDecisionDiagram

    /**
     * Returns an instance of [BinaryDecisionDiagram.Terminal] with
     * the provided input.
     * */
    @JsName("buildTerminal")
    fun buildTerminal(truth: Boolean): BinaryDecisionDiagram

    companion object {
        /**
         * Returns a default [BinaryDecisionDiagramBuilder] instance. Different
         * platforms can return different types of instances, to apply
         * platform-specific optimizations. Note, no reduction optimization
         * must be applied by the returned instance.
         * */
        @JsName("defaultOf")
        fun > defaultOf(): BinaryDecisionDiagramBuilder {
            return createDefaultBinaryDecisionDiagramBuilder()
        }

        /**
         * Returns a simple [BinaryDecisionDiagramBuilder] instance that does
         * not apply platform-specific or reduction optimizations. This
         * provides basic means to build represent BDDs, and keeps the entire
         * data structure in memory in the form of a directed graph.
         * */
        @JsName("simpleOf")
        fun > simpleOf(): BinaryDecisionDiagramBuilder {
            return SimpleBinaryDecisionDiagramBuilder()
        }

        /**
         * Returns a [BinaryDecisionDiagramBuilder] instance that applies
         * reduction optimizations through the `reduce` algorithm, and
         * delegates the actual construction logic of each node to [delegate].
         * By default, [delegate] is set as [defaultOf]. The following
         * reductions are performed:
         * - Removal of duplicate variable nodes
         * - Removal of duplicate terminal nodes
         * - Removal of redundant variable nodes, which are
         * [BinaryDecisionDiagram.Variable] nodes where low and high point
         * to the same node
         * */
        @JsName("reducedOf")
        fun > reducedOf(
            delegate: BinaryDecisionDiagramBuilder = defaultOf()
        ): BinaryDecisionDiagramBuilder {
            return ReducedBinaryDecisionDiagramBuilder(delegate)
        }
    }
}

internal fun > createDefaultBinaryDecisionDiagramBuilder(): BinaryDecisionDiagramBuilder =
    BinaryDecisionDiagramBuilder.simpleOf()




© 2015 - 2025 Weber Informatics LLC | Privacy Policy