Package org.graph4j.shortestpath
Class BidirectionalDijkstra
java.lang.Object
org.graph4j.GraphAlgorithm
org.graph4j.shortestpath.BidirectionalDijkstra
- All Implemented Interfaces:
SinglePairShortestPath
Determines the shortest path between two vertices. Performs a forward search
starting from a source vertex and a reverse (backward) search on the
transpose graph starting from the target vertex.
- Author:
- Cristian Frăsinaru
-
Field Summary
Fields inherited from class org.graph4j.GraphAlgorithm
directed, graph -
Constructor Summary
ConstructorsConstructorDescriptionBidirectionalDijkstra(Graph graph, int source, int target) Creates an algorithm to find the shortest path between source and target. -
Method Summary
Modifier and TypeMethodDescriptionfindPath()Returns the shortest path between source and target.doubleReturns the weight of the shortest path from the source to the target, orDouble.POSITIVE_INFINITYif no path exists.intReturns the source vertex number.intReturns the target vertex number.Methods inherited from class org.graph4j.GraphAlgorithm
getGraphMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.graph4j.shortestpath.SinglePairShortestPath
getGraph
-
Constructor Details
-
BidirectionalDijkstra
Creates an algorithm to find the shortest path between source and target.- Parameters:
graph- the input graph.source- the source vertex number.target- the target vertex number.
-
-
Method Details
-
getSource
public int getSource()Description copied from interface:SinglePairShortestPathReturns the source vertex number.- Specified by:
getSourcein interfaceSinglePairShortestPath- Returns:
- the source vertex number.
-
getTarget
public int getTarget()Description copied from interface:SinglePairShortestPathReturns the target vertex number.- Specified by:
getTargetin interfaceSinglePairShortestPath- Returns:
- the target vertex number.
-
findPath
Description copied from interface:SinglePairShortestPathReturns the shortest path between source and target.- Specified by:
findPathin interfaceSinglePairShortestPath- Returns:
- the shortest path from the source to the target, or null if no path exists
-
getPathWeight
public double getPathWeight()Description copied from interface:SinglePairShortestPathReturns the weight of the shortest path from the source to the target, orDouble.POSITIVE_INFINITYif no path exists.- Specified by:
getPathWeightin interfaceSinglePairShortestPath- Returns:
- the weight of the shortest path from the source to the target, or
Double.POSITIVE_INFINITYif no path exists.
-