#NEWLINE# def minimum_cut( G , s , t , capacity = 'capacity' , flow_func = None , **kwargs ) : #NEWLINE# #INDENT# "Compute the value and the node partition of a minimum (s, t)-cut.\n\n    Use the max-flow min-cut theorem, i.e., the capacity of a minimum\n    capacity cut is equal to the flow value of a maximum flow.\n\n    Parameters\n    ----------\n    G : NetworkX graph\n        Edges of the graph are expected to have an attribute called\n        'capacity'. If this attribute is not present, the edge is\n        considered to have infinite capacity.\n\n    s : node\n        Source node for the flow.\n\n    t : node\n        Sink node for the flow.\n\n    capacity : string\n        Edges of the graph G are expected to have an attribute capacity\n        that indicates how much flow the edge can support. If this\n        attribute is not present, the edge is considered to have\n        infinite capacity. Default value: 'capacity'.\n\n    flow_func : function\n        A function for computing the maximum flow among a pair of nodes\n        in a capacitated graph. The function has to accept at least three\n        parameters: a Graph or Digraph, a source node, and a target node.\n        And return a residual network that follows NetworkX conventions\n        (see Notes). If flow_func is None, the default maximum\n        flow function (:meth:`preflow_push`) is used. See below for\n        alternative algorithms. The choice of the default function may change\n        from version to version and should not be relied on. Default value:\n        None.\n\n    kwargs : Any other keyword parameter is passed to the function that\n        computes the maximum flow.\n\n    Returns\n    -------\n    cut_value : integer, float\n        Value of the minimum cut.\n\n    partition : pair of node sets\n        A partitioning of the nodes that defines a minimum cut.\n\n    Raises\n    ------\n    NetworkXUnbounded\n        If the graph has a path of infinite capacity, all cuts have\n        infinite capacity and the function raises a NetworkXError.\n\n    See also\n    --------\n    :meth:`maximum_flow`\n    :meth:`maximum_flow_value`\n    :meth:`minimum_cut_value`\n    :meth:`edmonds_karp`\n    :meth:`preflow_push`\n    :meth:`shortest_augmenting_path`\n\n    Notes\n    -----\n    The function used in the flow_func paramter has to return a residual\n    network that follows NetworkX conventions:\n\n    The residual network :samp:`R` from an input graph :samp:`G` has the\n    same nodes as :samp:`G`. :samp:`R` is a DiGraph that contains a pair\n    of edges :samp:`(u, v)` and :samp:`(v, u)` iff :samp:`(u, v)` is not a\n    self-loop, and at least one of :samp:`(u, v)` and :samp:`(v, u)` exists\n    in :samp:`G`.\n\n    For each edge :samp:`(u, v)` in :samp:`R`, :samp:`R[u][v]['capacity']`\n    is equal to the capacity of :samp:`(u, v)` in :samp:`G` if it exists\n    in :samp:`G` or zero otherwise. If the capacity is infinite,\n    :samp:`R[u][v]['capacity']` will have a high arbitrary finite value\n    that does not affect the solution of the problem. This value is stored in\n    :samp:`R.graph['inf']`. For each edge :samp:`(u, v)` in :samp:`R`,\n    :samp:`R[u][v]['flow']` represents the flow function of :samp:`(u, v)` and\n    satisfies :samp:`R[u][v]['flow'] == -R[v][u]['flow']`.\n\n    The flow value, defined as the total flow into :samp:`t`, the sink, is\n    stored in :samp:`R.graph['flow_value']`. Reachability to :samp:`t` using\n    only edges :samp:`(u, v)` such that\n    :samp:`R[u][v]['flow'] < R[u][v]['capacity']` induces a minimum\n    :samp:`s`-:samp:`t` cut.\n\n    Specific algorithms may store extra data in :samp:`R`.\n\n    The function should supports an optional boolean parameter value_only. When\n    True, it can optionally terminate the algorithm as soon as the maximum flow\n    value and the minimum cut can be determined.\n\n    Examples\n    --------\n    >>> import networkx as nx\n    >>> G = nx.DiGraph()\n    >>> G.add_edge('x','a', capacity = 3.0)\n    >>> G.add_edge('x','b', capacity = 1.0)\n    >>> G.add_edge('a','c', capacity = 3.0)\n    >>> G.add_edge('b','c', capacity = 5.0)\n    >>> G.add_edge('b','d', capacity = 4.0)\n    >>> G.add_edge('d','e', capacity = 2.0)\n    >>> G.add_edge('c','y', capacity = 2.0)\n    >>> G.add_edge('e','y', capacity = 3.0)\n\n    minimum_cut computes both the value of the\n    minimum cut and the node partition:\n\n    >>> cut_value, partition = nx.minimum_cut(G, 'x', 'y')\n    >>> reachable, non_reachable = partition\n\n    'partition' here is a tuple with the two sets of nodes that define\n    the minimum cut. You can compute the cut set of edges that induce\n    the minimum cut as follows:\n\n    >>> cutset = set()\n    >>> for u, nbrs in ((n, G[n]) for n in reachable):\n    ...     cutset.update((u, v) for v in nbrs if v in non_reachable)\n    >>> print(sorted(cutset))\n    [('c', 'y'), ('x', 'b')]\n    >>> cut_value == sum(G.edge[u][v]['capacity'] for (u, v) in cutset)\n    True\n\n    You can also use alternative algorithms for computing the\n    minimum cut by using the flow_func parameter.\n\n    >>> from networkx.algorithms.flow import shortest_augmenting_path\n    >>> cut_value == nx.minimum_cut(G, 'x', 'y',\n    ...                             flow_func=shortest_augmenting_path)[0]\n    True\n\n    " #NEWLINE# if ( flow_func is None ) : #NEWLINE# #INDENT# if kwargs : #NEWLINE# #INDENT# raise nx . NetworkXError ( 'You have to explicitly set a flow_func if you need to pass parameters via kwargs.' ) #NEWLINE# #UNINDENT# flow_func = default_flow_func #NEWLINE# #UNINDENT# if ( not callable ( flow_func ) ) : #NEWLINE# #INDENT# raise nx . NetworkXError ( 'flow_func has to be callable.' ) #NEWLINE# #UNINDENT# if ( ( kwargs . get ( 'cutoff' ) is not None ) and ( t in flow_funcs ) ) : #NEWLINE# #INDENT# raise nx . NetworkXError ( 'cutoff should not be specified.' ) #NEWLINE# #UNINDENT# R = flow_func ( G , s , t , capacity = capacity , value_only = True , ** kwargs ) #NEWLINE# cutset = [ ( u , v , d ) for ( u , v , d ) in R . edges ( data = True ) if ( d [ 'flow' ] == d [ 'capacity' ] ) ] #NEWLINE# R . remove_edges_from ( cutset ) #NEWLINE# non_reachable = set ( dict ( nx . shortest_path_length ( R , target = t ) ) ) #NEWLINE# partition = ( ( set ( G ) - non_reachable ) , non_reachable ) #NEWLINE# if ( cutset is not None ) : #NEWLINE# #INDENT# R . add_edges_from ( cutset ) #NEWLINE# #UNINDENT# return ( R . graph [ 'flow_value' ] , partition )