Package org.graph4j.connectivity
Class ConnectivityAlgorithm
java.lang.Object
org.graph4j.SimpleGraphAlgorithm
org.graph4j.connectivity.ConnectivityAlgorithm
Determines the connected components of a graph. In case of directed graph,
the algorithm is executed on its support graph, analyzing the
weak-connectivity of the digraph.
- Author:
- Cristian Frăsinaru
-
Field Summary
Fields inherited from class org.graph4j.SimpleGraphAlgorithm
graph -
Constructor Summary
ConstructorsConstructorDescriptionConnectivityAlgorithm(Graph graph) Creates an algorithm for analyzing the connectivity of a graph. -
Method Summary
Modifier and TypeMethodDescriptionintDetermines the number of connected components, without creating the actual components.getConnectedComponent(int v) Returns the connected component the specified vertex belongs to.Returns the connected components of the graph.getConnectedSet(int v) Returns the vertex set of the connected component the specified vertex belongs to.Each connected component is represented by its vertices.booleanhasPath(int v, int u) Determines if there is a path from v to u in the graph.booleanA graph is connected if there is a path from any vertex to any other vertex in the graph.Methods inherited from class org.graph4j.SimpleGraphAlgorithm
getGraph
-
Constructor Details
-
ConnectivityAlgorithm
Creates an algorithm for analyzing the connectivity of a graph.- Parameters:
graph- the input graph.
-
-
Method Details
-
isConnected
public boolean isConnected()A graph is connected if there is a path from any vertex to any other vertex in the graph.- Returns:
trueif the graph is connected.
-
countConnectedComponents
public int countConnectedComponents()Determines the number of connected components, without creating the actual components.- Returns:
- the number of connected components.
-
hasPath
public boolean hasPath(int v, int u) Determines if there is a path from v to u in the graph.- Parameters:
v- a vertex number.u- a vertex number.- Returns:
trueif v and u are connected,falseotherwise.
-
getConnectedSets
Each connected component is represented by its vertices. In order to obtain the subgraph induced by the vertices of a connected component, you may useGraph.subgraph(VertexSet).Graph cc = graph.subgraph(set.vertices());
- Returns:
- the list of the connected sets.
-
getConnectedSet
Returns the vertex set of the connected component the specified vertex belongs to.- Parameters:
v- a vertex number.- Returns:
- the connected set containing v.
-
getConnectedComponents
Returns the connected components of the graph. If only the vertices of the connected components are needed, thegetConnectedSets()method should be used.- Returns:
- the connected components.
-
getConnectedComponent
Returns the connected component the specified vertex belongs to. If only the vertices of the connected component are needed, thegetConnectedSet(int)method should be used.- Parameters:
v- a vertex number.- Returns:
- the connected component containing v.
-