V
- the graph vertex typeE
- the graph edge typepublic class FloydWarshallShortestPaths<V,E> extends Object
The Floyd-Warshall algorithm finds all shortest paths (all $n^2$ of them) in $O(n^3)$ time. Note that during construction time, no computations are performed! All computations are performed the first time one of the member methods of this class is invoked. The results are stored, so all subsequent calls to the same method are computationally efficient.
ShortestPathAlgorithm.SingleSourcePaths<V,E>
Modifier and Type | Field and Description |
---|---|
protected Graph<V,E> |
graph
The underlying graph.
|
Constructor and Description |
---|
FloydWarshallShortestPaths(Graph<V,E> graph)
Create a new instance of the Floyd-Warshall all-pairs shortest path algorithm.
|
Modifier and Type | Method and Description |
---|---|
protected GraphPath<V,E> |
createEmptyPath(V source,
V sink)
Create an empty path.
|
V |
getFirstHop(V a,
V b)
Returns the first hop, i.e., the second node on the shortest path from $a$ to $b$.
|
V |
getLastHop(V a,
V b)
Returns the last hop, i.e., the second to last node on the shortest path from $a$ to $b$.
|
GraphPath<V,E> |
getPath(V a,
V b)
Get a shortest path from a source vertex to a sink vertex.
|
ShortestPathAlgorithm.SingleSourcePaths<V,E> |
getPaths(V source)
Compute all shortest paths starting from a single source vertex.
|
double |
getPathWeight(V source,
V sink)
Get the weight of the shortest path from a source vertex to a sink vertex.
|
int |
getShortestPathsCount()
Get the total number of shortest paths.
|
protected final Graph<V,E> graph
public int getShortestPathsCount()
public GraphPath<V,E> getPath(V a, V b)
a
- the source vertexb
- the target vertexpublic double getPathWeight(V source, V sink)
Double.POSITIVE_INFINITY
if no path exists.getPathWeight
in interface ShortestPathAlgorithm<V,E>
source
- the source vertexsink
- the sink vertexDouble.POSITIVE_INFINITY
if no path existspublic ShortestPathAlgorithm.SingleSourcePaths<V,E> getPaths(V source)
getPaths
in interface ShortestPathAlgorithm<V,E>
source
- the source vertexpublic V getFirstHop(V a, V b)
getPath(Object, Object)
and then reading the first vertex.a
- source vertexb
- target vertexpublic V getLastHop(V a, V b)
getPath(Object, Object)
and then reading the vertex. The first invocation of this
method populates a last hop matrix.a
- source vertexb
- target vertexprotected final GraphPath<V,E> createEmptyPath(V source, V sink)
source
- the source vertexsink
- the sink vertexCopyright © 2018. All rights reserved.