Package org.graph4j.route
Class PathFinder
java.lang.Object
org.graph4j.GraphAlgorithm
org.graph4j.route.PathFinder
Algorithms for finding paths in unweighted directed or undirected graph.
- Author:
- Cristian Frăsinaru
-
Field Summary
Fields inherited from class org.graph4j.GraphAlgorithm
directed, graph -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfindShortestPath(Graph graph, int v, int u, int[] forbiddenVertices) Finds the path with the fewest edges connecting two vertices.booleanhasPath(int v, int u) Determines if there is a path connecting two vertices.Methods inherited from class org.graph4j.GraphAlgorithm
getGraph
-
Constructor Details
-
PathFinder
-
-
Method Details
-
findShortestPath
Finds the path with the fewest edges connecting two vertices. If the input graph is directed, the path takes into account the edge orientations. The path is found using a BFS iterator, therefore it is an induced path. The weights of the edges (if the graph is edge-weighted) are not taken in consideration. For determining a shortest path in an edge-weighted graph (seeorg.graph4j.shortestpathpackage).- Parameters:
graph- the input graph.v- a vertex number.u- a vertex number.forbiddenVertices- vertices that are not allowed in the path; can benullif there are no forbidden vertices.- Returns:
- a path connecting v and u or
nullif no such path exists. - Throws:
InvalidVertexException- if any of the specified vertices is not in the graph.- See Also:
-
hasPath
public boolean hasPath(int v, int u) Determines if there is a path connecting two vertices. If the input graph is directed, the path takes into account the edge orientations.- Parameters:
v- a vertex number.u- a vertex number.- Returns:
trueif there is a path connecting v and u,falseotherwise.
-