shortestPath method
Path<V, num> ?
shortestPath(
- V source,
- V target, {
- num edgeCost(
- V source,
- V target
- num costEstimate(
- V vertex
- 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;