V
- the graph vertex typeE
- the graph edge typepublic final class BidirectionalDijkstraShortestPath<V,E> extends Object
See the Wikipedia article for details and references about bidirectional search. This technique does not change the worst-case behavior of the algorithm but reduces, in some cases, the number of visited vertices in practice. This implementation alternatively constructs forward and reverse paths from the source and target vertices respectively.
DijkstraShortestPath
ShortestPathAlgorithm.SingleSourcePaths<V,E>
Modifier and Type | Field and Description |
---|---|
protected Graph<V,E> |
graph
The underlying graph.
|
Constructor and Description |
---|
BidirectionalDijkstraShortestPath(Graph<V,E> graph)
Constructs a new instance for a specified graph.
|
BidirectionalDijkstraShortestPath(Graph<V,E> graph,
double radius)
Constructs a new instance for a specified graph.
|
Modifier and Type | Method and Description |
---|---|
protected GraphPath<V,E> |
createEmptyPath(V source,
V sink)
Create an empty path.
|
static <V,E> GraphPath<V,E> |
findPathBetween(Graph<V,E> graph,
V source,
V sink)
Find a path between two vertices.
|
GraphPath<V,E> |
getPath(V source,
V sink)
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.
|
protected final Graph<V,E> graph
public BidirectionalDijkstraShortestPath(Graph<V,E> graph)
graph
- the input graphpublic GraphPath<V,E> getPath(V source, V sink)
ShortestPathAlgorithm
source
- the source vertexsink
- the target vertexpublic static <V,E> GraphPath<V,E> findPathBetween(Graph<V,E> graph, V source, V sink)
V
- the graph vertex typeE
- the graph edge typegraph
- the graph to be searchedsource
- the vertex at which the path should startsink
- the vertex at which the path should endpublic ShortestPathAlgorithm.SingleSourcePaths<V,E> getPaths(V source)
getPaths
in interface ShortestPathAlgorithm<V,E>
source
- the source 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 existsprotected final GraphPath<V,E> createEmptyPath(V source, V sink)
source
- the source vertexsink
- the sink vertexCopyright © 2017. All rights reserved.