label_out_component#
- graph_tool.structure.label_out_component(g, root, label=None)[git][source]#
Label the out-component (or simply the component for undirected graphs) of a root vertex.
- Parameters:
- g
Graph Graph to be used.
- root
Vertex The root vertex.
- label
VertexPropertyMap(optional, default:None) If provided, this must be an initialized Boolean vertex property map where the out-component will be labeled.
- g
- Returns:
- label
VertexPropertyMap Boolean vertex property map which labels the out-component.
- label
See also
label_componentsConnected components
count_reachableNumber of vertices reachable from every vertex
ego_graphSubgraph within a given distance of a vertex
shortest_distanceDistances from a source vertex
Notes
The algorithm runs in \(O(V + E)\) time.
Examples
>>> g = gt.random_graph(100, lambda: poisson(2.2), directed=False) >>> l = gt.label_out_component(g, g.vertex(2)) >>> print(l.a) [1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 0 0 1 0 1 0 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 0]
The in-component can be obtained by reversing the graph.
>>> l = gt.label_out_component(gt.GraphView(g, reversed=True, directed=True), ... g.vertex(1)) >>> print(l.a) [0 1 1 0 0 1 0 0 0 1 1 0 1 0 0 0 0 1 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 1 0 1 1 0 0 0 1 1 1 1 0 1 1 1 1 1 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 1 0 0 1 0 1 1 1 1 0 1 0 0 0 1 0 0 1 0 0 0]
In a directed graph, the out-component contains the vertices reachable from the given one, as shown for a Price network, whose edges point from newer to older vertices:
>>> g = gt.price_network(60, m=2) >>> l = gt.label_out_component(g, g.vertex(59)) >>> pos = gt.sfdp_layout(g) >>> vcolor = g.new_vp("string", vals=np.where(l.a, "#f28c8e", "#cccccc")) >>> vcolor[59] = "#9bbedc" >>> gt.graph_draw(g, pos, vertex_fill_color=vcolor, edge_color="#999999", ... output="label_out_component-price.pdf") <...>
Out-component (in red) of the vertex shown in blue in a Price network of 60 vertices.#