Class DijkstraShortestPath<TVertex, TEdge, TWeight>
- Namespace
- Graph1x.Algorithms
- Assembly
- Graph1x.dll
Dijkstra's shortest-path algorithm over a PriorityQueue<TElement, TPriority>. Requires non-negative edge weights; throws NegativeWeightException otherwise.
public sealed class DijkstraShortestPath<TVertex, TEdge, TWeight> : IShortestPathAlgorithm<TVertex, TEdge, TWeight> where TVertex : notnull where TEdge : IEdge<TVertex> where TWeight : INumber<TWeight>
Type Parameters
TVertexThe vertex type.
TEdgeThe edge type.
TWeightThe numeric weight type.
- Inheritance
-
DijkstraShortestPath<TVertex, TEdge, TWeight>
- Implements
-
IShortestPathAlgorithm<TVertex, TEdge, TWeight>
- Inherited Members
Constructors
DijkstraShortestPath(Func<TEdge, TWeight>)
Initializes the algorithm with the function that reads an edge's weight.
public DijkstraShortestPath(Func<TEdge, TWeight> weightSelector)
Parameters
weightSelectorFunc<TEdge, TWeight>Maps an edge to its weight.
Exceptions
- ArgumentNullException
weightSelectoris null.
Methods
FindPath(IReadOnlyGraph<TVertex, TEdge>, TVertex, TVertex)
Finds the shortest path from source to target.
public ShortestPathResult<TVertex, TWeight> FindPath(IReadOnlyGraph<TVertex, TEdge> graph, TVertex source, TVertex target)
Parameters
graphIReadOnlyGraph<TVertex, TEdge>The graph to search.
sourceTVertexThe start vertex.
targetTVertexThe end vertex.
Returns
- ShortestPathResult<TVertex, TWeight>
The query result, unreachable when no path exists.
Exceptions
- ArgumentException
Either endpoint is not in the graph.
- NegativeWeightException
A negative edge weight was encountered.
FindPathsFrom(IReadOnlyGraph<TVertex, TEdge>, TVertex)
Computes shortest paths from source to every
reachable vertex in one run, for querying many targets without
re-running the algorithm.
public SingleSourceShortestPaths<TVertex, TWeight> FindPathsFrom(IReadOnlyGraph<TVertex, TEdge> graph, TVertex source)
Parameters
graphIReadOnlyGraph<TVertex, TEdge>The graph to search.
sourceTVertexThe start vertex.
Returns
- SingleSourceShortestPaths<TVertex, TWeight>
A queryable single-source result.
Exceptions
- ArgumentException
sourceis not in the graph.- NegativeWeightException
A negative edge weight was encountered.
FindPathsFrom(IReadOnlyGraph<TVertex, TEdge>, TVertex, CancellationToken)
Computes shortest paths from source to every
reachable vertex, observing cancellationToken
between vertex settlements.
public SingleSourceShortestPaths<TVertex, TWeight> FindPathsFrom(IReadOnlyGraph<TVertex, TEdge> graph, TVertex source, CancellationToken cancellationToken)
Parameters
graphIReadOnlyGraph<TVertex, TEdge>The graph to search.
sourceTVertexThe start vertex.
cancellationTokenCancellationTokenCancels the computation cooperatively.
Returns
- SingleSourceShortestPaths<TVertex, TWeight>
A queryable single-source result.
Exceptions
- ArgumentException
sourceis not in the graph.- NegativeWeightException
A negative edge weight was encountered.
- OperationCanceledException
The token was cancelled.