Class Dijkstra<TWeight>
- Namespace
- AlgorithmsSW.EdgeWeightedDigraph
- Assembly
- AlgorithmsSW.dll
Algorithm to find the shortest path from a source vertex to all other vertices in a edge weighted digraph.
[AlgorithmReference(4, 9)]
public class Dijkstra<TWeight> : IShortestPath<TWeight> where TWeight : INumber<TWeight>, IMinMaxValue<TWeight>
Type Parameters
TWeightThe type of the edge weights.
- Inheritance
-
Dijkstra<TWeight>
- Implements
-
IShortestPath<TWeight>
- Inherited Members
- Extension Methods
Constructors
Dijkstra(IReadOnlyEdgeWeightedDigraph<TWeight>, int)
Initializes a new instance of the Dijkstra<TWeight> class.
public Dijkstra(IReadOnlyEdgeWeightedDigraph<TWeight> graph, int source)
Parameters
graphIReadOnlyEdgeWeightedDigraph<TWeight>The graph to find the shortest paths in.
sourceintThe source vertex to find the shortest paths from.
Methods
GetDistanceTo(int)
Gets the distance from the source vertex to the given vertex.
public TWeight GetDistanceTo(int vertex)
Parameters
vertexintThe vertex to find the distance to.
Returns
- TWeight
The distance from the source vertex to the given vertex.
GetEdgesOfPathTo(int)
Gets the path from the source vertex to the given vertex.
public IEnumerable<DirectedEdge<TWeight>> GetEdgesOfPathTo(int target)
Parameters
targetintThe vertex to find the path to.
Returns
- IEnumerable<DirectedEdge<TWeight>>
An enumerable of edges representing the path from the source vertex to the given vertex.
Exceptions
- InvalidOperationException
+there is no path from the source vertex to the given vertex.
GetPathTo(int)
public DirectedPath<TWeight> GetPathTo(int target)
Parameters
targetint
Returns
- DirectedPath<TWeight>
HasPathTo(int)
Whether there is a path from the source vertex to the given vertex.
public bool HasPathTo(int vertex)
Parameters
vertexintThe vertex to check if there is a path to.