approx_maximum_cut#
- graph_tool.structure.approx_maximum_cut(g, weight=None, part=None)[git][source]#
Return an approximate maximum cut.
- Parameters:
- g
Graph Graph to be used (the edge directions are ignored).
- weight
EdgePropertyMap(optional, default:None) Nonnegative edge weights. If not given, every edge has unit weight.
- part
VertexPropertyMap(optional, default:None) If provided, the side of every vertex will be stored in this property map.
- g
- Returns:
- cut
float The total weight of the edges between the two sides.
- part
VertexPropertyMap Boolean vertex property map with the side of every vertex.
- cut
See also
cut_sizeSize of a given cut
graph_tool.flow.minimum_cutMinimum cut
graph_tool.spectral.spectral_clusteringPartition based on the spectrum
Notes
A cut is a partition of the vertices into two sides \(S\) and \(\bar S = V\setminus S\), and its weight is
\[c(S) = \sum_{\{u,v\}\in E,\, u\in S,\, v\in\bar S} w_{uv},\]the total weight of the edges with an endpoint on each side, ignoring the edge directions (self-loops are never cut). A maximum cut maximizes \(c(S)\). Finding it is NP-hard, and a local search is used instead: starting from a random partition, vertices are moved to the other side as long as this increases the weight of the cut. The result is a local optimum, in which the cut edges incident on every vertex weigh at least as much as the uncut ones (other than self-loops); summing over the vertices, its weight is at least half of the total weight of the edges that are not self-loops, and hence at least half of the maximum. Moving a vertex \(v\) takes time \(O(k_v)\), where \(k_v\) is its degree, and every move increases the weight of the cut, so that with unit weights there are at most \(E\) moves.
Examples
>>> g = gt.collection.data["karate"] >>> cut, part = gt.approx_maximum_cut(g) >>> print(cut, g.num_edges()) 55.0 78
The two sides and the edges of the cut can be shown in a drawing of the network:
>>> vcolor = g.new_vp("string", vals=np.where(part.a, "#f28c8e", ... "#9bbedc")) >>> s = gt.edge_endpoint_property(g, part, "source") >>> t = gt.edge_endpoint_property(g, part, "target") >>> ecolor = g.new_ep("string", vals=np.where(s.a != t.a, "#e41a1c", ... "#999999")) >>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=vcolor, ... edge_color=ecolor, output="approx_maximum_cut-karate.pdf") <...>
Approximate maximum cut of Zachary’s karate club network. The two sides are shown in red and blue, and the edges of the cut in red.#