Class GraphShortestPathExtensions
- Namespace
- Graph1x.Algorithms
- Assembly
- Graph1x.dll
Convenience entry points for shortest-path queries. These default to Dijkstra; instantiate BellmanFordShortestPath<TVertex, TEdge, TWeight>, AStarShortestPath<TVertex, TEdge, TWeight>, or FloydWarshallAllShortestPaths<TVertex, TEdge, TWeight> directly when negative weights, a heuristic, or all-pairs results are needed.
public static class GraphShortestPathExtensions
- Inheritance
-
GraphShortestPathExtensions
- Inherited Members
Methods
ShortestPath<TVertex, TWeight>(IReadOnlyGraph<TVertex, WeightedEdge<TVertex, TWeight>>, TVertex, TVertex)
Finds the shortest path from source to
target using Dijkstra's algorithm and the weights
carried by the graph's WeightedEdge<TVertex, TWeight> edges.
public static ShortestPathResult<TVertex, TWeight> ShortestPath<TVertex, TWeight>(this IReadOnlyGraph<TVertex, WeightedEdge<TVertex, TWeight>> graph, TVertex source, TVertex target) where TVertex : notnull where TWeight : INumber<TWeight>
Parameters
graphIReadOnlyGraph<TVertex, WeightedEdge<TVertex, TWeight>>The graph to search.
sourceTVertexThe start vertex.
targetTVertexThe end vertex.
Returns
- ShortestPathResult<TVertex, TWeight>
The query result, unreachable when no path exists.
Type Parameters
TVertexThe vertex type.
TWeightThe numeric weight type.
Exceptions
- NegativeWeightException
A negative edge weight was encountered.
ShortestPath<TVertex, TEdge, TWeight>(IReadOnlyGraph<TVertex, TEdge>, TVertex, TVertex, Func<TEdge, TWeight>)
Finds the shortest path from source to
target using Dijkstra's algorithm and
weightSelector to read edge weights.
public static ShortestPathResult<TVertex, TWeight> ShortestPath<TVertex, TEdge, TWeight>(this IReadOnlyGraph<TVertex, TEdge> graph, TVertex source, TVertex target, Func<TEdge, TWeight> weightSelector) where TVertex : notnull where TEdge : IEdge<TVertex> where TWeight : INumber<TWeight>
Parameters
graphIReadOnlyGraph<TVertex, TEdge>The graph to search.
sourceTVertexThe start vertex.
targetTVertexThe end vertex.
weightSelectorFunc<TEdge, TWeight>Maps an edge to its weight.
Returns
- ShortestPathResult<TVertex, TWeight>
The query result, unreachable when no path exists.
Type Parameters
TVertexThe vertex type.
TEdgeThe edge type.
TWeightThe numeric weight type.
Exceptions
- NegativeWeightException
A negative edge weight was encountered.
ShortestPathsFrom<TVertex, TWeight>(IReadOnlyGraph<TVertex, WeightedEdge<TVertex, TWeight>>, TVertex)
Computes shortest paths from source to every
reachable vertex using Dijkstra's algorithm and the weights carried by
the graph's WeightedEdge<TVertex, TWeight> edges.
public static SingleSourceShortestPaths<TVertex, TWeight> ShortestPathsFrom<TVertex, TWeight>(this IReadOnlyGraph<TVertex, WeightedEdge<TVertex, TWeight>> graph, TVertex source) where TVertex : notnull where TWeight : INumber<TWeight>
Parameters
graphIReadOnlyGraph<TVertex, WeightedEdge<TVertex, TWeight>>The graph to search.
sourceTVertexThe start vertex.
Returns
- SingleSourceShortestPaths<TVertex, TWeight>
A queryable single-source result.
Type Parameters
TVertexThe vertex type.
TWeightThe numeric weight type.
Exceptions
- NegativeWeightException
A negative edge weight was encountered.
ShortestPathsFrom<TVertex, TEdge, TWeight>(IReadOnlyGraph<TVertex, TEdge>, TVertex, Func<TEdge, TWeight>)
Computes shortest paths from source to every
reachable vertex using Dijkstra's algorithm and
weightSelector to read edge weights.
public static SingleSourceShortestPaths<TVertex, TWeight> ShortestPathsFrom<TVertex, TEdge, TWeight>(this IReadOnlyGraph<TVertex, TEdge> graph, TVertex source, Func<TEdge, TWeight> weightSelector) where TVertex : notnull where TEdge : IEdge<TVertex> where TWeight : INumber<TWeight>
Parameters
graphIReadOnlyGraph<TVertex, TEdge>The graph to search.
sourceTVertexThe start vertex.
weightSelectorFunc<TEdge, TWeight>Maps an edge to its weight.
Returns
- SingleSourceShortestPaths<TVertex, TWeight>
A queryable single-source result.
Type Parameters
TVertexThe vertex type.
TEdgeThe edge type.
TWeightThe numeric weight type.
Exceptions
- NegativeWeightException
A negative edge weight was encountered.
ShortestPathsFrom<TVertex, TEdge, TWeight>(IReadOnlyGraph<TVertex, TEdge>, TVertex, Func<TEdge, TWeight>, CancellationToken)
Computes shortest paths from source to every
reachable vertex using Dijkstra's algorithm, observing
cancellationToken between vertex settlements.
public static SingleSourceShortestPaths<TVertex, TWeight> ShortestPathsFrom<TVertex, TEdge, TWeight>(this IReadOnlyGraph<TVertex, TEdge> graph, TVertex source, Func<TEdge, TWeight> weightSelector, CancellationToken cancellationToken) where TVertex : notnull where TEdge : IEdge<TVertex> where TWeight : INumber<TWeight>
Parameters
graphIReadOnlyGraph<TVertex, TEdge>The graph to search.
sourceTVertexThe start vertex.
weightSelectorFunc<TEdge, TWeight>Maps an edge to its weight.
cancellationTokenCancellationTokenCancels the computation cooperatively.
Returns
- SingleSourceShortestPaths<TVertex, TWeight>
A queryable single-source result.
Type Parameters
TVertexThe vertex type.
TEdgeThe edge type.
TWeightThe numeric weight type.
Exceptions
- NegativeWeightException
A negative edge weight was encountered.
- OperationCanceledException
The token was cancelled.