label_largest_component#
- graph_tool.structure.label_largest_component(g, directed=None)[git][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:
- g
Graph Graph to be used.
- directedbool (optional, default:
None) Treat graph as directed or not, independently of its actual directionality.
- g
- Returns:
- comp
VertexPropertyMap Boolean vertex property map which labels the largest component.
- comp
See also
label_componentsConnected components
extract_largest_componentExtract the largest component
vertex_percolationSize of the largest component as vertices are removed
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 1 0 0 1 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 1 0 0 1 0 1 0 1 0 0 0 0 1 1 0 1 0 1 0 1 0 0 0 0 0 0 0 1 0 1 1 0 0 0 1 1 1 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 1 1 0 0 0] >>> u = gt.GraphView(g, vfilt=l) # extract the largest component as a graph >>> print(u.num_vertices()) 28
The largest component can be highlighted in a drawing of the graph:
>>> pos = gt.sfdp_layout(g) >>> vcolor = g.new_vp("string", vals=np.where(l.a, "#f28c8e", "#cccccc")) >>> gt.graph_draw(g, pos, vertex_fill_color=vcolor, edge_color="#999999", ... output="label_largest_component-random.pdf") <...>
Largest component (in red) of a sparse random graph.#