Package org.jgrapht.alg
Class ConnectivityInspector<V,E>
- java.lang.Object
-
- org.jgrapht.alg.ConnectivityInspector<V,E>
-
- All Implemented Interfaces:
java.util.EventListener,GraphListener<V,E>,VertexSetListener<V>
public class ConnectivityInspector<V,E> extends java.lang.Object implements GraphListener<V,E>
Allows obtaining various connectivity aspects of a graph. The inspected graph is specified at construction time and cannot be modified. Currently, the inspector supports connected components for an undirected graph and weakly connected components for a directed graph. To find strongly connected components, useStrongConnectivityInspectorinstead.The inspector methods work in a lazy fashion: no computation is performed unless immediately necessary. Computation are done once and results and cached within this class for future need.
The inspector is also a
GraphListener. If added as a listener to the inspected graph, the inspector will amend internal cached results instead of recomputing them. It is efficient when a few modifications are applied to a large graph. If many modifications are expected it will not be efficient due to added overhead on graph update operations. If inspector is added as listener to a graph other than the one it inspects, results are undefined.- Since:
- Aug 6, 2003
- Author:
- Barak Naveh, John V. Sichi
-
-
Constructor Summary
Constructors Constructor Description ConnectivityInspector(DirectedGraph<V,E> g)Creates a connectivity inspector for the specified directed graph.ConnectivityInspector(UndirectedGraph<V,E> g)Creates a connectivity inspector for the specified undirected graph.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Set<V>connectedSetOf(V vertex)Returns a set of all vertices that are in the maximally connected component together with the specified vertex.java.util.List<java.util.Set<V>>connectedSets()Returns a list ofSets, where each set contains all vertices that are in the same maximally connected component.voidedgeAdded(GraphEdgeChangeEvent<V,E> e)Notifies that an edge has been added to the graph.voidedgeRemoved(GraphEdgeChangeEvent<V,E> e)Notifies that an edge has been removed from the graph.booleanisGraphConnected()Test if the inspected graph is connected.booleanpathExists(V sourceVertex, V targetVertex)Tests if there is a path from the specified source vertex to the specified target vertices.voidvertexAdded(GraphVertexChangeEvent<V> e)Notifies that a vertex has been added to the graph.voidvertexRemoved(GraphVertexChangeEvent<V> e)Notifies that a vertex has been removed from the graph.
-
-
-
Constructor Detail
-
ConnectivityInspector
public ConnectivityInspector(UndirectedGraph<V,E> g)
Creates a connectivity inspector for the specified undirected graph.- Parameters:
g- the graph for which a connectivity inspector to be created.
-
ConnectivityInspector
public ConnectivityInspector(DirectedGraph<V,E> g)
Creates a connectivity inspector for the specified directed graph.- Parameters:
g- the graph for which a connectivity inspector to be created.
-
-
Method Detail
-
isGraphConnected
public boolean isGraphConnected()
Test if the inspected graph is connected. An empty graph is not considered connected.- Returns:
trueif and only if inspected graph is connected.
-
connectedSetOf
public java.util.Set<V> connectedSetOf(V vertex)
Returns a set of all vertices that are in the maximally connected component together with the specified vertex. For more on maximally connected component, see http://www.nist.gov/dads/HTML/maximallyConnectedComponent.html.- Parameters:
vertex- the vertex for which the connected set to be returned.- Returns:
- a set of all vertices that are in the maximally connected component together with the specified vertex.
-
connectedSets
public java.util.List<java.util.Set<V>> connectedSets()
Returns a list ofSets, where each set contains all vertices that are in the same maximally connected component. All graph vertices occur in exactly one set. For more on maximally connected component, see http://www.nist.gov/dads/HTML/maximallyConnectedComponent.html.- Returns:
- Returns a list of
Sets, where each set contains all vertices that are in the same maximally connected component.
-
edgeAdded
public void edgeAdded(GraphEdgeChangeEvent<V,E> e)
Description copied from interface:GraphListenerNotifies that an edge has been added to the graph.- Specified by:
edgeAddedin interfaceGraphListener<V,E>- Parameters:
e- the edge event.- See Also:
GraphListener.edgeAdded(GraphEdgeChangeEvent)
-
edgeRemoved
public void edgeRemoved(GraphEdgeChangeEvent<V,E> e)
Description copied from interface:GraphListenerNotifies that an edge has been removed from the graph.- Specified by:
edgeRemovedin interfaceGraphListener<V,E>- Parameters:
e- the edge event.- See Also:
GraphListener.edgeRemoved(GraphEdgeChangeEvent)
-
pathExists
public boolean pathExists(V sourceVertex, V targetVertex)
Tests if there is a path from the specified source vertex to the specified target vertices. For a directed graph, direction is ignored for this interpretation of path.Note: Future versions of this method might not ignore edge directions for directed graphs.
- Parameters:
sourceVertex- one end of the path.targetVertex- another end of the path.- Returns:
trueif and only if there is a path from the source vertex to the target vertex.
-
vertexAdded
public void vertexAdded(GraphVertexChangeEvent<V> e)
Description copied from interface:VertexSetListenerNotifies that a vertex has been added to the graph.- Specified by:
vertexAddedin interfaceVertexSetListener<V>- Parameters:
e- the vertex event.- See Also:
VertexSetListener.vertexAdded(GraphVertexChangeEvent)
-
vertexRemoved
public void vertexRemoved(GraphVertexChangeEvent<V> e)
Description copied from interface:VertexSetListenerNotifies that a vertex has been removed from the graph.- Specified by:
vertexRemovedin interfaceVertexSetListener<V>- Parameters:
e- the vertex event.- See Also:
VertexSetListener.vertexRemoved(GraphVertexChangeEvent)
-
-