skm_tools.cuts
Minimum cuts between sets of nodes.
Attributes
Functions
|
Minimum edge cut separating sources from targets (max-flow / min-cut). |
Module Contents
- skm_tools.cuts.logger
- skm_tools.cuts.get_cutset(g, sources, targets, return_flow=False)
Minimum edge cut separating sources from targets (max-flow / min-cut).
The sources are joined to a super-source and the targets to a super-sink with unlimited capacity, and the minimum cut between them is computed with Edmonds-Karp. The maximum flow (the total capacity of the cut edges) is logged (INFO).
- Parameters:
g (networkx.DiGraph) – Graph with a
capacityedge attribute. Edges without it have infinite capacity in networkx, so set it on every edge (e.g.nx.set_edge_attributes(g, 1, "capacity")to count edges). g is not changed. Multigraphs are not supported (for PSS, useskm_tools.pss.simplify_pss()first).sources (node or iterable of nodes) – Source nodes (nodes not in g are ignored, with a warning).
targets (node or iterable of nodes) – Target nodes (nodes not in g are ignored, with a warning; targets that are also sources are ignored).
return_flow (bool) – Also return the maximum flow.
- Returns:
The cut edges (u, v), sorted. Empty if no target can be reached from the sources. With return_flow, a tuple
(cut edges, max flow).- Return type:
- Raises:
networkx.NetworkXUnbounded – If a path from a source to a target has only edges without a
capacity.
Examples
>>> import networkx as nx >>> g = nx.DiGraph([("A", "B"), ("A", "C"), ("B", "D"), ("C", "D"), ("D", "E")]) >>> nx.set_edge_attributes(g, 1, "capacity") >>> get_cutset(g, ["A"], ["E"]) [('D', 'E')] >>> get_cutset(g, ["A"], ["D"], return_flow=True) ([('B', 'D'), ('C', 'D')], 2)