commonMain.it.unibo.tuprolog.solve.concurrent.fsm.StateGoalSelection.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solve-concurrent-jvm Show documentation
Show all versions of solve-concurrent-jvm Show documentation
Experimental, state-machine-based implementation of an OR-Concurrent, Prolog-like logic solver, based on Kotlin coroutines
package it.unibo.tuprolog.solve.concurrent.fsm
import it.unibo.tuprolog.solve.Solution
import it.unibo.tuprolog.solve.concurrent.ConcurrentExecutionContext
data class StateGoalSelection(override val context: ConcurrentExecutionContext) : State {
override fun next(): Iterable {
return listOf(
if (context.goals.isOver) {
if (context.isRoot) {
StateEnd(
Solution.yes(context.query, context.substitution),
context.copy(step = nextStep())
)
} else {
StateGoalSelection(
context.parent!!.let {
it.copy(
flags = context.flags,
dynamicKb = context.dynamicKb,
staticKb = context.staticKb,
substitution = context.substitution.filter(it.interestingVariables),
goals = it.goals.next, // go on with parent's goals
procedure = it.procedure,
step = nextStep(),
startTime = context.startTime,
operators = context.operators,
inputChannels = context.inputChannels,
outputChannels = context.outputChannels,
libraries = context.libraries,
customData = context.customData
)
}
)
}
} else {
val goalsWithSubstitution = context.goals.map { it[context.substitution] }
StatePrimitiveSelection(context.copy(goals = goalsWithSubstitution, step = nextStep()))
}
)
}
override fun clone(context: ConcurrentExecutionContext): StateGoalSelection = copy(context = context)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy