gomory_hu_tree#
- graph_tool.flow.gomory_hu_tree(g, weight=None)[git][source]#
Return the Gomory-Hu tree of an undirected graph.
- Parameters:
- g
Graph Graph to be used. If it is directed, it is treated as undirected.
- weight
EdgePropertyMap(optional, default:None) Non-negative edge capacities. If not supplied, every edge has unit capacity.
- g
- Returns:
- tree
Graph The Gomory-Hu tree, an undirected graph with the same vertex indices as
g.- tree_weight
EdgePropertyMap Edge property map of
treewith the values of the minimum cuts.
- tree
See also
minimum_st_cutMinimum s-t cut
minimum_cutMinimum cut of an undirected graph
edge_connectivityEdge connectivity
Notes
The Gomory-Hu tree [gomory-multi-1961] is a weighted tree on the vertices of the graph such that, for any two vertices \(s\) and \(t\), the smallest weight along the tree path between them is the value of the minimum \(s\)-\(t\) cut of the graph, and removing that tree edge separates the vertices into the two sides of such a cut. It encodes all \(V(V-1)/2\) minimum cuts with only \(V-1\) maximum flow computations.
The tree is obtained with Gusfield’s algorithm [gusfield-very-1990], which computes the flows in the original graph, with the Boykov-Kolmogorov algorithm (see
boykov_kolmogorov_max_flow()). Vertices in different components are joined by tree edges of zero weight.References
[gomory-multi-1961]Ralph E. Gomory and T. C. Hu, “Multi-terminal network flows”, Journal of the Society for Industrial and Applied Mathematics 9, 551-570 (1961), DOI: 10.1137/0109047 [sci-hub, @tor]
[gusfield-very-1990]Dan Gusfield, “Very simple methods for all pairs network flow analysis”, SIAM Journal on Computing 19, 143-155 (1990), DOI: 10.1137/0219009 [sci-hub, @tor]
Examples
>>> g = gt.collection.data["football"] >>> t, w = gt.gomory_hu_tree(g) >>> print(t.num_edges(), w.fa.min(), w.fa.max()) 114 7 12
For Zachary’s karate club network, the tree can be drawn with the values of the cuts as edge labels and edge widths:
>>> g = gt.collection.data["karate"] >>> t, w = gt.gomory_hu_tree(g) >>> gt.graph_draw(t, gt.sfdp_layout(t), vertex_fill_color="#cccccc", ... edge_text=w, edge_color="#377eb8", ... edge_pen_width=gt.prop_to_size(w, mi=1, ma=5, power=1), ... output="gomory_hu_tree-karate.pdf") <...>
Gomory-Hu tree of Zachary’s karate club network, with the values of the minimum cuts as edge labels. The edge widths increase with these values.#