Class DijkstraShortestPathsAlgorithm<V,E extends GEdge<V>>
- Type Parameters:
V
- the type of verticesE
- the type of edges
This implementation computes the shortest paths between two vertices using Dijkstra's single-source shortest path finding algorithm. Any time a new source is given, it explores all destinations in the graph up to a maximum distance from the source. Thus, this implementation is best applied when many queries are anticipated from relatively few sources.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
A class representing all optimal paths from a given source to every other (reachable) vertex in the graph -
Field Summary
Modifier and TypeFieldDescriptionprotected final GImplicitDirectedGraph
<V, E> protected final double
protected final GEdgeWeightMetric
<E> protected final Map
<V, DijkstraShortestPathsAlgorithm<V, E>.OneSourceToAll> -
Constructor Summary
ConstructorDescriptionUse Dijkstra's algorithm on the given graphDijkstraShortestPathsAlgorithm
(GImplicitDirectedGraph<V, E> graph, double maxDistance) Use Dijkstra's algorithm on the given graph with the given maximum distanceDijkstraShortestPathsAlgorithm
(GImplicitDirectedGraph<V, E> graph, double maxDistance, GEdgeWeightMetric<E> metric) Use Dijstra's algorithm on the given graph with the given maximum distance and a custom edge weight metricDijkstraShortestPathsAlgorithm
(GImplicitDirectedGraph<V, E> graph, GEdgeWeightMetric<E> metric) Use Dijstra's algorithm on the given graph with a custom edge weight metric -
Method Summary
Modifier and TypeMethodDescriptionCollection
<Deque<E>> computeOptimalPaths
(V src, V dst) Compute the shortest paths from the given source to the given destinationCompute the shortest distance to all reachable vertices from the given source
-
Field Details
-
sources
-
graph
-
maxDistance
protected final double maxDistance -
metric
-
-
Constructor Details
-
DijkstraShortestPathsAlgorithm
Use Dijkstra's algorithm on the given graphThis constructor assumes the graph's edges are
GWeightedEdge
s. If not, you will likely encounter aClassCastException
.- Parameters:
graph
- the graph
-
DijkstraShortestPathsAlgorithm
Use Dijkstra's algorithm on the given graph with the given maximum distanceThis constructor assumes the graph's edges are
GWeightedEdge
s. If not, you will likely encounter aClassCastException
.- Parameters:
graph
- the graphmaxDistance
- the maximum distance, or null for no maximum
-
DijkstraShortestPathsAlgorithm
public DijkstraShortestPathsAlgorithm(GImplicitDirectedGraph<V, E> graph, GEdgeWeightMetric<E> metric) Use Dijstra's algorithm on the given graph with a custom edge weight metric- Parameters:
graph
- the graphmetric
- the function to compute the weight of an edge
-
DijkstraShortestPathsAlgorithm
public DijkstraShortestPathsAlgorithm(GImplicitDirectedGraph<V, E> graph, double maxDistance, GEdgeWeightMetric<E> metric) Use Dijstra's algorithm on the given graph with the given maximum distance and a custom edge weight metric- Parameters:
graph
- the graphmaxDistance
- the maximum distance, or null for no maximummetric
- the function to compute the weight of an edge
-
-
Method Details
-
getDistancesFromSource
Compute the shortest distance to all reachable vertices from the given source- Parameters:
v
- the source vertex- Returns:
- a map of destinations to distances from the given source
-
computeOptimalPaths
Compute the shortest paths from the given source to the given destinationThis implementation differs from typical implementations in that paths tied for the shortest distance are all returned. Others tend to choose one arbitrarily.
- Parameters:
src
- the sourcedst
- the destination- Returns:
- a collection of paths of shortest distance from source to destination
-