graph_tool.topology.label_largest_component#

graph_tool.topology.label_largest_component(g, directed=None)[source]#

Label the largest component in the graph. If the graph is directed, then the largest strongly connected component is labelled.

A property map with a boolean label is returned.

Parameters:
gGraph

Graph to be used.

directedbool (optional, default: None)

Treat graph as directed or not, independently of its actual directionality.

Returns:
compVertexPropertyMap

Boolean vertex property map which labels the largest component.

Notes

The algorithm runs in \(O(V + E)\) time.

Examples

>>> g = gt.random_graph(100, lambda: poisson(1), directed=False)
>>> l = gt.label_largest_component(g)
>>> print(l.a)
[0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0
 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
>>> u = gt.GraphView(g, vfilt=l)   # extract the largest component as a graph
>>> print(u.num_vertices())
10