kl_connected_subgraph#
- graph_tool.structure.kl_connected_subgraph(g, k, l)[git][source]#
Return the largest locally \((k, l)\)-connected subgraph found by edge removal.
- Parameters:
- g
Graph Graph to be used.
- k
int Maximum length of the paths.
- l
int Number of edge-disjoint paths.
- g
- Returns:
- u
GraphView Subgraph with the remaining edges.
- ok
bool Trueif no edge was removed, i.e. if the graph is locally \((k, l)\)-connected.
- u
See also
is_kl_connectedTest for local (k, l)-connectivity
graph_tool.flow.label_k_edge_subgraphsK-edge-connected subgraphs
Notes
The edges that are not \((k, l)\)-connected (see
is_kl_connected(), which describes the greedy search for the paths) are removed repeatedly, with the paths searched in the remaining graph, until every remaining edge is \((k, l)\)-connected in it, as in the extraction of the local graph of Chung and Lu [chung-small-2004]. The time is \(O(lE^2(V + E))\) in the worst case.References
[chung-small-2004]Fan Chung and Linyuan Lu, “The small world phenomenon in hybrid power law graphs”, in Complex Networks, Lecture Notes in Physics 650, 89-104 (Springer, 2004), DOI: 10.1007/978-3-540-44485-5_4 [sci-hub, @tor]
Examples
>>> g = gt.collection.data["karate"] >>> u, ok = gt.kl_connected_subgraph(g, 2, 2) >>> print(u.num_edges(), ok) 67 False
The edges removed can be shown in a drawing of the network:
>>> kept = g.new_ep("bool") >>> kept.a[u.get_edges([u.edge_index])[:, 2]] = True >>> ecolor = g.new_ep("string", vals=np.where(kept.a, "#999999", ... "#e41a1c")) >>> ewidth = g.new_ep("double", vals=np.where(kept.a, 1, 2.5)) >>> gt.graph_draw(g, g.vp.pos, vertex_fill_color="#cccccc", ... edge_color=ecolor, edge_pen_width=ewidth, ... output="kl_connected_subgraph-karate.pdf") <...>
Locally \((2, 2)\)-connected subgraph of Zachary’s karate club network. The edges removed are shown in red, and the remaining edges in gray.#