SearchStrategy

interface SearchStrategy<T, W, S>

A pluggable graph-traversal algorithm, generic over the kind of state it threads through the traversal (e.g. the current depth, for BreadthFirst/DepthFirst). Rather than Graph baking in a fixed set of traversal orders, it delegates to a SearchStrategy via Graph.asSequence/Graph.asIterable, so new orders (e.g. a custom best-first search) can be added without touching Graph itself. See AbstractSearchStrategy for a base class handling the traversal's bookkeeping (the fringe of edges still to explore), leaving concrete strategies to only decide which edge to explore next.

Type Parameters

T

is the type of the payload carried by the graph's nodes

W

is the type of the graph's edge weights

S

is the type of the state this strategy threads through the traversal

Inheritors

Properties

Link copied to clipboard
abstract val initialState: S

The state associated with the very first node of any traversal performed by search.

Functions

Link copied to clipboard
abstract fun search(graph: Graph<T, W>, source: Node<T>): Sequence<Visit<T, S>>

Lazily traverses graph starting from source, according to this strategy, yielding a Visit for each node reached along the way (including source itself).