Package org.graph4j.route
Class CycleFinder
java.lang.Object
org.graph4j.GraphAlgorithm
org.graph4j.route.CycleFinder
Algorithms for finding cycles in a directed or undirected graph.
Multigraphs and pseudographs are supported.
- Author:
- Cristian Frăsinaru
-
Field Summary
Fields inherited from class org.graph4j.GraphAlgorithm
directed, graph -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanUses DFS in order to find a cycle.findAnyCycle(int target) An heuristic for finding a long cycle.Uses BFS in order to find a cycle.findShortestCycle(int target) Methods inherited from class org.graph4j.GraphAlgorithm
getGraph
-
Constructor Details
-
CycleFinder
- Parameters:
graph- the input graph.
-
-
Method Details
-
containsCycle
public boolean containsCycle()- Returns:
trueif the graph contains a cycle.
-
findAnyCycle
Uses DFS in order to find a cycle.- Returns:
- the first cycle found, or
nullif the graph is acyclic.
-
findAnyCycle
- Parameters:
target- a vertex number.- Returns:
- the first cycle found that passes through
target, ornullif none exists.
-
findShortestCycle
Uses BFS in order to find a cycle.- Returns:
- the shortest cycle in the graph, or
nullif the graph is acyclic.
-
findShortestCycle
- Parameters:
target- a vertex number.- Returns:
- the shortest cycle in the graph that passes through
target, ornullif none exists.
-
findOddCycle
- Returns:
- the first odd cycle found, or
nullif the graph contains no odd cycles.
-
findEvenCycle
- Returns:
- the first even cycle found, or
nullif the graph contains no even cycles.
-
findLongCycle
An heuristic for finding a long cycle. There is no guarantee that the cycle returned is the longest cycle in the graph.- Returns:
- a cycle that is supposed to be long.
-