shortestPath method

Path<V, num>? shortestPath(
  1. V source,
  2. V target, {
  3. num edgeCost(
    1. V source,
    2. V target
    )?,
  4. num costEstimate(
    1. V vertex
    )?,
  5. StorageStrategy<V>? vertexStrategy,
})

Performs a search for the shortest path between source and target.

  • edgeCost is a function that returns the cost to traverse an edge between two vertices. If no function is provided, the numeric edge value or a constant weight of 1 is used.

  • costEstimate is a function that returns the remaining cost from the provided vertex. If an estimate is provided a faster A*-Search is performed, otherwise a Dijkstra Search.

Implementation

Path<V, num>? shortestPath(
  V source,
  V target, {
  num Function(V source, V target)? edgeCost,
  num Function(V vertex)? costEstimate,
  StorageStrategy<V>? vertexStrategy,
}) =>
    shortestPathAll(
      source,
      (vertex) => target == vertex,
      edgeCost: edgeCost ?? _getDefaultEdgeValueOr(1),
      costEstimate: costEstimate,
      vertexStrategy: vertexStrategy ?? this.vertexStrategy,
    ).firstOrNull;