networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersRaisesReturnsBackRef
stoer_wagner(G, weight='weight', heap=<class 'networkx.utils.heaps.BinaryHeap'>)

Determine the minimum edge cut of a connected graph using the Stoer-Wagner algorithm. In weighted cases, all weights must be nonnegative.

The running time of the algorithm depends on the type of heaps used:

============== ============================================= Type of heap Running time ============== ============================================= Binary heap $O(n (m + n) \log n)$ Fibonacci heap $O(nm + n^2 \log n)$ Pairing heap $O(2^{2 \sqrt{\log \log n}} nm + n^2 \log n)$ ============== =============================================

Parameters

G : NetworkX graph

Edges of the graph are expected to have an attribute named by the weight parameter below. If this attribute is not present, the edge is considered to have unit weight.

weight : string

Name of the weight attribute of the edges. If the attribute is not present, unit weight is assumed. Default value: 'weight'.

heap : class

Type of heap to be used in the algorithm. It should be a subclass of MinHeap or implement a compatible interface.

If a stock heap implementation is to be used, BinaryHeap is recommended over PairingHeap for Python implementations without optimized attribute accesses (e.g., CPython) despite a slower asymptotic running time. For Python implementations with optimized attribute accesses (e.g., PyPy), PairingHeap provides better performance. Default value: BinaryHeap .

Raises

NetworkXNotImplemented

If the graph is directed or a multigraph.

NetworkXError

If the graph has less than two nodes, is not connected or has a negative-weighted edge.

Returns

cut_value : integer or float

The sum of weights of edges in a minimum cut.

partition : pair of node lists

A partitioning of the nodes that defines a minimum cut.

Returns the weighted minimum edge cut using the Stoer-Wagner algorithm.

Examples

>>> G = nx.Graph()
... G.add_edge("x", "a", weight=3)
... G.add_edge("x", "b", weight=1)
... G.add_edge("a", "c", weight=3)
... G.add_edge("b", "c", weight=5)
... G.add_edge("b", "d", weight=4)
... G.add_edge("d", "e", weight=2)
... G.add_edge("c", "y", weight=2)
... G.add_edge("e", "y", weight=3)
... cut_value, partition = nx.stoer_wagner(G)
... cut_value 4
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.connectivity.cuts.minimum_node_cut networkx.algorithms.connectivity.cuts.minimum_edge_cut networkx.algorithms.connectivity.cuts.minimum_st_edge_cut networkx.algorithms.connectivity.cuts.minimum_st_node_cut networkx.algorithms.connectivity.stoerwagner.stoer_wagner

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/connectivity/stoerwagner.py#14
type: <class 'function'>
Commit: