commonMain.it.unibo.tuprolog.bdd.impl.ExpansionVisitor.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bdd-jvm Show documentation
Show all versions of bdd-jvm Show documentation
Multi-platform library for representing and manipulating Binary Decision Diagrams
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