findPath<T extends E> method

Path<T> findPath<T extends E>(
  1. WalkableBase<T> graph,
  2. T start,
  3. Goal<T> goal, {
  4. Tracer<T>? tracer,
})

Returns a path in graph from start to a node that satisfies goal.

If no path can be found, Path.notFound is returned.

A node will never be included in the path more than once, as determined by Object.== on the node, unless the source node is also a successor of itself, in which case it will be included twice (once at the beginning and once at the end), otherwise it will only be included at the start.

Tracing

May provide a tracer to capture finer-detail events during the traversal.

If omitted, no tracing is performed.

Example

final graph = Walkable.linear([1, 2, 3]);

final path = depthFirst.findPath(graph, 1, Goal.node(3));
print(path); // Path([1, 2, 3])

Implementation

Path<T> findPath<T extends E>(
  WalkableBase<T> graph,
  T start,
  Goal<T> goal, {
  Tracer<T>? tracer,
}) {
  if (goal.success(start)) {
    return Path([start]);
  }
  return findPathExclusive(graph, start, goal, tracer: tracer);
}