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
TWeight
The 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
graph
IReadOnlyEdgeWeightedDigraph<TWeight>The graph to find the shortest paths in.
source
intThe source vertex.
target
intThe target vertex.
k
intThe 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
k
intThe 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
rank
intThe 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
k
intThe rank of the path.