Class DijkstraBidirectional<TWeight>
- Namespace
- AlgorithmsSW.EdgeWeightedDigraph
- Assembly
- AlgorithmsSW.dll
A modified version of Dijkstra's algorithm that finds the shortest path from a source to a sink.
[ExerciseReference(4, 4, 23)]
public class DijkstraBidirectional<TWeight> where TWeight : INumber<TWeight>, IMinMaxValue<TWeight>
Type Parameters
TWeight
- Inheritance
-
DijkstraBidirectional<TWeight>
- Inherited Members
- Extension Methods
Remarks
This implementation can be faster than vanilla Dijkstra since we can stop early once we processed the sink.
Constructors
DijkstraBidirectional(IEdgeWeightedDigraph<TWeight>, int, int)
Initializes a new instance of the DijkstraBidirectional<TWeight> class.
public DijkstraBidirectional(IEdgeWeightedDigraph<TWeight> graph, int source, int sink)
Parameters
graph
IEdgeWeightedDigraph<TWeight>The graph to find the shortest path in.
source
intThe source vertex to find the shortest path from.
sink
intThe sink vertex to find the shortest path to.
Exceptions
- ArgumentException
graph
contains negative weights.
Properties
Distance
Gets the distance from the source to the sink.
public TWeight Distance { get; }
Property Value
- TWeight
Exceptions
Path
Gets the path from the source to the sink.
public IReadonlyRandomAccessList<DirectedEdge<TWeight>>? Path { get; }
Property Value
- IReadonlyRandomAccessList<DirectedEdge<TWeight>>
Exceptions
PathExists
Gets a value indicating whether a path exists from the source to the sink.
public bool PathExists { get; }