skm_tools.cuts ============== .. py:module:: skm_tools.cuts .. autoapi-nested-parse:: Minimum cuts between sets of nodes. Attributes ---------- .. autoapisummary:: skm_tools.cuts.logger Functions --------- .. autoapisummary:: skm_tools.cuts.get_cutset Module Contents --------------- .. py:data:: logger .. py:function:: 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). :param g: Graph with a ``capacity`` edge 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, use :func:`skm_tools.pss.simplify_pss` first). :type g: networkx.DiGraph :param sources: Source nodes (nodes not in `g` are ignored, with a warning). :type sources: node or iterable of nodes :param targets: Target nodes (nodes not in `g` are ignored, with a warning; targets that are also sources are ignored). :type targets: node or iterable of nodes :param return_flow: Also return the maximum flow. :type return_flow: bool :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)``. :rtype: list of tuple :raises networkx.NetworkXUnbounded: If a path from a source to a target has only edges without a ``capacity``. .. rubric:: 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)