public final class GraphConnectivity extends Object
It also provides convenience methods for working with these components.
Modifier and Type | Method and Description |
---|---|
static EdgeList[] |
biconnectedComponents(Graph graph)
Calculates the biconnected components of a given undirected graph.
|
static int |
biconnectedComponents(Graph graph,
IEdgeMap compNum)
Calculates the biconnected components and the articulation points of a given undirected graph and returns the number of
biconnected components.
|
static int |
biconnectedComponents(Graph graph,
IEdgeMap compNum,
INodeMap aPoint)
Calculates the biconnected components and the articulation points of a given undirected graph and returns the number of
biconnected components.
|
static NodeList[] |
connectedComponents(Graph graph)
Calculates the connected components of a given graph.
|
static int |
connectedComponents(Graph graph,
INodeMap compNum)
Calculates the connected components of a given graph and returns their number.
|
static NodeList |
getNeighbors(Graph graph,
NodeList startNodes,
int maxDistance)
Determines the direct or indirect neighbors of a given set of nodes.
|
static NodeList |
getPredecessors(Graph graph,
NodeList startNodes,
int maxDistance)
Determines the direct or indirect predecessors of a given list of nodes.
|
static NodeList |
getSuccessors(Graph graph,
NodeList startNodes,
int maxDistance)
Determines the direct or indirect successors of a given list of nodes.
|
static boolean |
isBiconnected(Graph graph)
Checks whether or not the given undirected graph is biconnected.
|
static boolean |
isConnected(Graph graph)
Checks whether or not the given graph is connected.
|
static boolean |
isStronglyConnected(Graph graph)
Checks whether or not the given directed graph is strongly connected.
|
static EdgeList |
makeBiconnected(Graph graph)
Makes the given graph biconnected by inserting a minimum number of edges in the graph.
|
static EdgeList |
makeConnected(Graph graph)
Makes a graph connected by adding additional edges to the graph.
|
static void |
reachable(Graph graph,
Node start,
boolean directed,
boolean[] reached)
Determines the set of nodes that are reachable from a given node when a set of edges that cannot be traversed is
specified.
|
static void |
reachable(Graph graph,
Node start,
boolean directed,
boolean[] reached,
boolean[] forbidden)
Determines the set of nodes that are reachable from a given node when a set of edges that cannot be traversed is
specified.
|
static NodeList[] |
stronglyConnectedComponents(Graph graph)
Calculates the strongly connected components of a given graph.
|
static int |
stronglyConnectedComponents(Graph graph,
INodeMap compNum)
Calculates the strongly connected components of a given graph and returns their number.
|
static EdgeList[] |
toEdgeListArray(Graph graph,
IEdgeMap compNum,
int maxCompNum)
Transforms the return values of
biconnectedComponents(Graph, IEdgeMap, INodeMap) to an array of
EdgeList s, like it is returned by biconnectedComponents(Graph) . |
static NodeList[] |
toNodeListArray(Graph graph,
INodeMap compNum,
int maxCompNum)
Transforms the return values of method
connectedComponents(Graph, INodeMap) to an array of NodeList s,
like it is returned by connectedComponents(Graph) . |
public static final EdgeList[] biconnectedComponents(Graph graph)
The result is returned as an array of
EdgeList
s each containing all edges that belong to the same biconnected component.
EdgeList
s.connected
.O(graph.N() + graph.E())
graph
- the input graphEdgeList
s each containing all edges that belong to the same biconnected componentbiconnectedComponents(Graph, IEdgeMap, INodeMap)
public static final int biconnectedComponents(Graph graph, IEdgeMap compNum)
Articulation points are returned in the form of a INodeMap
that returns for each node a boolean value indicating
whether or not it is an articulation point.
-1
.connected
.compNum
should not be null
.aPoint
should not be null
.O(graph.N() + graph.E())
graph
- the input graphcompNum
- the IEdgeMap
that will be filled during the execution and returns the zero-based index of the biconnected
component to which each edge belongs or -1
for self-loopsbiconnectedComponents(Graph)
,
biconnectedComponents(Graph, IEdgeMap, INodeMap)
public static final int biconnectedComponents(Graph graph, IEdgeMap compNum, INodeMap aPoint)
Articulation points are returned in the form of a INodeMap
that returns for each node a boolean value indicating
whether or not it is an articulation point.
-1
.connected
.compNum
should not be null
.aPoint
should not be null
.O(graph.N() + graph.E())
graph
- the input graphcompNum
- the IEdgeMap
that will be filled during the execution and returns the zero-based index of the biconnected
component to which each edge belongs or -1
for self-loopsaPoint
- the INodeMap
that will be filled during the execution and returns a boolean value indicating whether or not a
given node is an articulation pointbiconnectedComponents(Graph)
,
biconnectedComponents(Graph, IEdgeMap, INodeMap)
public static final NodeList[] connectedComponents(Graph graph)
A graph G
is called connected if there exists an undirected path of edges between every pair of nodes.
The connected components of a graph are the maximal connected subgraphs of which the graph consists.
O(graph.N() + graph.E())
graph
- the input graphNodeList
s each of which contains the nodes that belong to the same connected componentpublic static final int connectedComponents(Graph graph, INodeMap compNum)
A graph G
is called connected if there exists an undirected path of edges between every pair of nodes.
The connected components of a graph are the maximal connected subgraphs of which the graph consists.
O(graph.N() + graph.E())
compNum
- the INodeMap
that will be filled during the execution and returns the zero-based index of the connected
component to which each node belongspublic static final NodeList getNeighbors(Graph graph, NodeList startNodes, int maxDistance)
The order of the returned nodes is determined by a breadth first search. No start node will be part of the resulting set.
To obtain the result, an integer value should be given as input that limits the distance between a start node and a returned node. For all returned nodes there must be a path to a start node that has a length equal to or smaller than this distance.
Setting the maximum distance to 1
will only yield the direct neighbors of all start nodes. On the other hand,
setting the maximum distance to graph.N()
or larger will yield all neighbors of all start nodes.
NodeList
that contains all direct and indirect neighbors of a nodepublic static final NodeList getPredecessors(Graph graph, NodeList startNodes, int maxDistance)
The order of the returned nodes is determined by a breadth first search. No start node will be part of the resulting set.
To obtain the result, an integer value should be given as input that limits the distance between a start node and a returned node. For all returned nodes there must be a path to a start node that has a length equal to or smaller than this distance.
Setting the maximum distance to 1
will only yield the direct predecessors of all start nodes. On the other hand,
setting the maximum distance to graph.N()
or larger will yield all predecessors of all start nodes.
public static final NodeList getSuccessors(Graph graph, NodeList startNodes, int maxDistance)
The order of the returned nodes is determined by a breadth first search. No start node will be part of the resulting set.
To obtain the result, an integer value should be given as input that limits the distance between a start node and a returned node. For all returned nodes there must be a path to a start node that has a length equal to or smaller than this distance.
Setting the maximum distance to 1
will only yield the direct successors of all start nodes. On the other hand,
setting the maximum distance to graph.N()
or larger will yield all successors of all start nodes.
public static final boolean isBiconnected(Graph graph)
A graph is called biconnected if it has no cut vertex or articulation point, i.e., no node whose removal disconnects the graph.
graph
- the given undirected graphtrue
if the graph is biconnected, false
otherwisepublic static final boolean isConnected(Graph graph)
A graph is called connected if there exists an undirected path of edges between every pair of nodes.
graph
- the given graphtrue
if the graph is connected, false
otherwisepublic static final boolean isStronglyConnected(Graph graph)
A graph is called strongly connected if there exists a directed path between each pair of nodes.
graph
- the given directed graphtrue
if the graph is strongly connected, false
, otherwisepublic static final EdgeList makeBiconnected(Graph graph)
The given graph is considered to be undirected.
public static final EdgeList makeConnected(Graph graph)
The number of edges that will be added equals the number of separate components of the original graph minus 1
.
O(graph.N() + graph.E())
graph
- the input graphEdgeList
containing the edges added to the graphpublic static final void reachable(Graph graph, Node start, boolean directed, boolean[] reached)
The result is based on a depth first search.
forbiddenEdges.length = graph.E()
graph
- the given graphstart
- the node from which the search startsdirected
- true
if the edges should be traversed from source to target, false
if edges can be traversed in both
directionsreached
- an array that will be filled during the execution and returns for each Node
a Boolean
value based on
whether the node can be reached during the DFS; if a node v
is reachable, then
reached[v.index()] = true
public static final void reachable(Graph graph, Node start, boolean directed, boolean[] reached, boolean[] forbidden)
The result is based on a depth first search.
forbiddenEdges.length = graph.E()
graph
- the given graphstart
- the node from which the search startsdirected
- true
if the edges should be traversed from source to target, false
if edges can be traversed in both
directionsforbidden
- an array that holds for each Edge
a Boolean
value indicating whether or not an edge can be traversed; an
edge e
is marked as forbidden if forbidden[e.index()] == true
reached
- an array that will be filled during the execution and returns for each Node
a Boolean
value based on
whether the node can be reached during the DFS; if a node v
is reachable, then
reached[v.index()] = true
public static final NodeList[] stronglyConnectedComponents(Graph graph)
A graph is called strongly connected if there exists a directed path between each pair of nodes.
The strongly connected components of a graph are the strongly connected subgraphs of which it consists.
O(graph.N() + graph.E())
graph
- the input graphNodeList
s each of which contains the nodes that belong to the same strongly connected componentstronglyConnectedComponents(Graph, INodeMap)
public static final int stronglyConnectedComponents(Graph graph, INodeMap compNum)
A graph is called strongly connected if there exists a directed path between each pair of nodes.
The strongly connected components of a graph are the strongly connected subgraphs of which it consists.
O(graph.N() + graph.E())
graph
- the input graphcompNum
- the INodeMap
that will be filled during the execution and returns the zero-based index of the connected
component to which each node belongsstronglyConnectedComponents(Graph)
public static final EdgeList[] toEdgeListArray(Graph graph, IEdgeMap compNum, int maxCompNum)
biconnectedComponents(Graph, IEdgeMap, INodeMap)
to an array of
EdgeList
s, like it is returned by biconnectedComponents(Graph)
.graph
- the input graphcompNum
- the IEdgeMap
that will be filled during the execution and returns the zero-based index of the connected
component to which each edge belongsmaxCompNum
- the maximum number of biconnected componentsEdgeList
s each containing all edges that belong to the same biconnected componentpublic static final NodeList[] toNodeListArray(Graph graph, INodeMap compNum, int maxCompNum)
connectedComponents(Graph, INodeMap)
to an array of NodeList
s,
like it is returned by connectedComponents(Graph)
.graph
- the input graphcompNum
- the INodeMap
that will be filled during the execution and returns the zero-based index of the connected
component to which each node belongsmaxCompNum
- the maximum number of connected componentsNodeList
s each of which contains the nodes that belong to the same connected component