commonMain.it.unibo.tuprolog.solve.stdlib.primitive.AbstractCollectingPrimitive.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solve-jvm Show documentation
Show all versions of solve-jvm Show documentation
Resolution-agnostic API for logic solvers
package it.unibo.tuprolog.solve.stdlib.primitive
import it.unibo.tuprolog.core.Struct
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.Solution
import it.unibo.tuprolog.solve.exception.TimeOutException
import it.unibo.tuprolog.solve.primitive.Solve
import it.unibo.tuprolog.solve.primitive.TernaryRelation
abstract class AbstractCollectingPrimitive(name: String) : TernaryRelation.WithoutSideEffects(name) {
protected fun Solve.Request.computeIntermediateSolutions(goal: Struct): List =
buildList {
for (solution in solve(goal, context.remainingTime)) {
when {
context.remainingTime <= 0 -> {
throw TimeOutException(
exceededDuration = context.maxDuration,
context = context,
)
}
solution.isHalt -> {
throw solution.exception!!.pushContext(context)
}
solution.isNo -> {
break
}
else -> {
add(solution.castToYes())
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy