SolutionIterator

Drives the :solve-classic finite-state machine, one State.next step at a time, and turns every visited end-state (see it.unibo.tuprolog.solve.classic.fsm.EndState) into an emitted Solution.

This is the piece AbstractClassicSolver.solveImpl wraps into a lazy Sequence: hasNext answers whether the current state is (or can, via backtracking, resume being) an end-state, and next steps the machine forward until it reaches one, returning its it.unibo.tuprolog.solve.classic.fsm.EndState.solution. Because this is a genuine Iterator over an explicit state value rather than host-language recursion, resolution can be driven incrementally -- one solution, or even one FSM transition, at a time -- without unwinding a call stack, and onStateTransition gives a hook to observe (e.g. log, trace, or count) every step as it happens.

See also

for a variant that can additionally hijack which state comes next.

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val state: State

The state the machine is currently in (before the next call to next advances it).

Link copied to clipboard
abstract val step: Long

How many transitions the underlying state machine has performed so far.

Functions

Link copied to clipboard
abstract operator override fun hasNext(): Boolean
Link copied to clipboard
abstract operator override fun next(): Solution
Link copied to clipboard
abstract fun onStateTransition(source: State, destination: State, index: Long)

Invoked after every transition from source to destination (the index-th transition overall).