Class KShortestPaths<TWeight>
- Namespace
- AlgorithmsSW.EdgeWeightedDigraph
- Assembly
- AlgorithmsSW.dll
This is an implementation of (a modified) Dijkstra's algorithm that finds the k shortest paths between a source and a target.
[ExerciseReference(4, 4, 7)]
public class KShortestPaths<TWeight> : IKShortestPaths<TWeight> where TWeight : INumber<TWeight>
Type Parameters
TWeightThe type of the edge weights.
- Inheritance
-
KShortestPaths<TWeight>
- Implements
-
IKShortestPaths<TWeight>
- Inherited Members
- Extension Methods
Remarks
Constructors
KShortestPaths(IReadOnlyEdgeWeightedDigraph<TWeight>, int, int, int)
Initializes a new instance of the KShortestPaths<TWeight> class.
public KShortestPaths(IReadOnlyEdgeWeightedDigraph<TWeight> graph, int source, int target, int k)
Parameters
graphIReadOnlyEdgeWeightedDigraph<TWeight>The graph to find the shortest paths in.
sourceintThe source vertex.
targetintThe target vertex.
kintThe number of shortest paths to find.
Methods
GetDistance(int)
Gets the distance of the kth shortest path between the source and target.
public TWeight GetDistance(int k)
Parameters
kintThe rank of the path whose distance to get.
Returns
- TWeight
Exceptions
- InvalidOperationException
No path exists with the given rank.
GetPath(int)
Gets the kth shortest path between the source and target.
public DirectedPath<TWeight> GetPath(int rank)
Parameters
rankintThe rank of the path to get.
Returns
- DirectedPath<TWeight>
The kth shortest path.
Exceptions
- InvalidOperationException
No path exists with the given rank.
HasPath(int)
Gets whether there is a path with the given rank.
public bool HasPath(int k)
Parameters
kintThe rank of the path.