State

interface State

One location of the :solve-concurrent finite-state machine: an explicit, inspectable representation of "where resolution currently is" along one branch of the search tree, carrying the ConcurrentExecutionContext it operates on. Mirrors :solve-classic's own State (see that module's "state-machine" explanation for the formal model this is based on: StateGoalSelection, StatePrimitiveSelection, StatePrimitiveExecution, StateRuleSelection, StateRuleExecution, StateException, StateEnd and StateHalt).

The key difference from :solve-classic is next's return type: there, a state has exactly one successor, and backtracking across the other matching clauses/solutions is driven explicitly by a choice-point stack; here, next returns every alternative successor state at once (e.g. one StateRuleExecution per matching clause, or one StatePrimitiveExecution per solution a backtracking primitive can produce). It is it.unibo.tuprolog.solve.concurrent.ConcurrentSolverImpl that turns this into actual parallelism: it launches one coroutine per element of next's result, so every alternative is explored concurrently rather than sequentially -- this is the whole of :solve-concurrent's "concurrent" behaviour, applied recursively at every choice point down the tree.

See also

Inheritors

Properties

Link copied to clipboard

The execution context this state operates on.

Link copied to clipboard

Whether this state is a terminal one for the current branch, i.e. an EndState.

Functions

Link copied to clipboard
open fun asEndState(): EndState?

This state as an EndState, or null if isEndState is false.

Link copied to clipboard

This state as an EndState.

Link copied to clipboard
abstract fun clone(context: ConcurrentExecutionContext = this.context): State

Returns a copy of this state, replacing context with the given one (defaulting to the current context).

Link copied to clipboard
abstract fun next(): Iterable<State>

Computes every state this branch may transition into from here, one per alternative (matching clause, disjunct, primitive solution, ...) available at this point; empty only for EndStates. Each element is meant to be explored independently (and, in :solve-concurrent's solver, concurrently) of the others.