ChoicePointContext

sealed class ChoicePointContext

One node of the :solve-classic choice-point queue: a saved point in the proof search that it.unibo.tuprolog.solve.classic.fsm.StateBacktracking can resume from, chained to its parent to form the full lineage of choice points recorded since the query started (see pathToRoot).

Crucially, a choice point is not a single alternative goal to retry: alternatives is a lazy Cursor over all remaining alternatives (primitive responses, for Primitives; candidate clauses, for Rules) at that point, and only one is ever consumed per resolution step -- the rest stay in the cursor to be pulled later on backtracking. Every ChoicePointContext also captures the executionContext active when it was recorded, which is what makes it possible to resume an entirely different branch of the proof tree on backtrack: not just "try the next alternative", but "restore the whole saved execution-context lineage, then try the next alternative". Primitives and Rules are otherwise structurally identical, reflecting how both primitives and rules are modelled uniformly as producers of lazy streams of alternatives.

See also

Inheritors

Types

Link copied to clipboard
data class Primitives(val alternatives: Cursor<out Solve.Response>, val executionContext: ClassicExecutionContext?, val parent: ChoicePointContext?, val depth: Int) : ChoicePointContext

A choice point recording the remaining it.unibo.tuprolog.solve.primitive.Solve.Response alternatives of a primitive call.

Link copied to clipboard
data class Rules(val alternatives: Cursor<out Rule>, val executionContext: ClassicExecutionContext?, val parent: ChoicePointContext?, val depth: Int) : ChoicePointContext

A choice point recording the remaining candidate Rules of a clause resolution attempt.

Properties

Link copied to clipboard
open val alternatives: Cursor<out Any>
Link copied to clipboard
open val depth: Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Whether this choice point, or any of its ancestors along pathToRoot, still has an alternative to try.

Link copied to clipboard

Whether this is the first choice point of a resolution (i.e. it has no parent).

Link copied to clipboard
Link copied to clipboard

This choice point and all its ancestors, from here up to (and including) the root, in that order.

Functions

Link copied to clipboard

Chains a new ChoicePointContext.Primitives recording alternatives onto this (null meaning "the root").

Link copied to clipboard
fun ChoicePointContext?.appendRules(alternatives: Cursor<out Rule>, executionContext: ClassicExecutionContext? = null): ChoicePointContext

Chains a new ChoicePointContext.Rules recording alternatives onto this (null meaning "the root").

Link copied to clipboard

Resumes this choice point: restores its saved executionContext (carrying over context's current step counter, flags and knowledge bases), advances alternatives to the next one, and returns the resulting ClassicExecutionContext, ready to be handed to it.unibo.tuprolog.solve.classic.fsm.StatePrimitiveExecution or it.unibo.tuprolog.solve.classic.fsm.StateRuleExecution depending on the concrete subtype.

Link copied to clipboard

The ChoicePointContext.depth a new choice point chained onto this one (or null, for the root) would have.

Link copied to clipboard
open override fun toString(): String