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

commonMain.it.unibo.tuprolog.bdd.impl.ExpansionVisitor.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.impl

import it.unibo.tuprolog.bdd.BinaryDecisionDiagram
import it.unibo.tuprolog.bdd.BinaryDecisionDiagramVisitor

/**
 * 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.
 *
 * @author Jason Dellaluce
 */
internal class ExpansionVisitor, E>(
    private val varOp: (node: T, low: E, high: E) -> E,
    private val falseTerminal: E,
    private val trueTerminal: E
) : BinaryDecisionDiagramVisitor {

    override fun visit(node: BinaryDecisionDiagram.Terminal): E {
        return if (node.truth) trueTerminal else falseTerminal
    }

    override fun visit(node: BinaryDecisionDiagram.Variable): E {
        val lowValue = node.low.accept(this)
        val highValue = node.high.accept(this)
        return varOp(node.value, lowValue, highValue)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy