Skip to content

beamSearch

beamSearch<TState>(initialState, traits, beamWidth, maxDepth): TState | undefined

Defined in: optimize/beam-search.ts:38

Performs a beam search over a state space.

Starting from initialState, each step expands every live state, then keeps only the top beamWidth candidates by score. The search stops on the first goal state in the beam, when no successors are produced, or at maxDepth.

Time complexity: O(maxDepth · beamWidth · b log(beamWidth · b)) for a branching factor b — the sort at each step dominates.

TState extends DefinedValue

TState

Seed state for the search.

BeamSearchTraits<TState>

How to expand, score and test a state.

number

Maximum number of states kept after each expansion step.

number

Maximum number of expansion steps before the search stops.

TState | undefined

The highest-scoring surviving state, or undefined if no states survive.