+
    �°³j´"  ã                   óz   € R t ^ RIt^ RIHt R.tR tR t]P                  ! R]	! R4      /RRR	7      RR
 l4       t
R# )z3
Edmonds-Karp algorithm for maximum flow problems.
N)Úbuild_residual_networkÚedmonds_karpc                ó¦  aaaaa€ V P                   pV P                  oV P                  oV P                  R,          oVV3R lpVVVV3R lp^ pWs8  d}   V! 4       w  r‰p
V	f    V# V.pTpVS8w  d   Wœ,          pVP	                  V4       K"  VP                  4        TpVS8w  d   W¬,          pVP	                  V4       K"  Wu! V4      ,          pK‚  V# )ú-Implementation of the Edmonds-Karp algorithm.Úinfc                óÄ  <€ Sp\        V 4      p\        V4      pV F5  pSV,          V,          p\        WR,          VR,          ,
          4      pTpK7  	  V^,          S8”  d   \        P                  ! R4      h\        V 4      p\        V4      pV FK  pSV,          V,          R;;,          V,          uu&   SV,          V,          R;;,          V,          uu&   TpKM  	  V# )z&Augment flow along a path from s to t.ÚcapacityÚflowz-Infinite capacity path, flow unbounded above.)ÚiterÚnextÚminÚnxÚNetworkXUnbounded)Úpathr	   ÚitÚuÚvÚattrÚR_succr   s   &     €€Úe/home/luca/screen-checking/.venv/lib/python3.14/site-packages/networkx/algorithms/flow/edmondskarp.pyÚaugmentÚ"edmonds_karp_core.<locals>.augment   sÇ   ø€ ð ˆÜ�$‹ZˆÜ�‹HˆÛˆAØ˜!•9˜Q•<ˆDÜ�t *Õ-°°VµÕ<Ó=ˆDØŠAñ ð �!�8�cŒ>Ü×&Ò&Ð'VÓWÐWä�$‹ZˆÜ�‹HˆÛˆAØ�1�I�a�L˜×  DÕ(Ó Ø�1�I�a�L˜×  DÕ(Ó ØŠAñ ð ˆó    c                 ó>  <€ S
R/p S
.pSR/pS.p . p\        V4      \        V4      8:  dz   V Fe  pS	V,          P                  4        FG  w  rgW`9  g   K  VR,          VR,          8  g   K$  WPV&   Wb9   d	   W`V3u u # VP                  V4       KI  	  Kg  	  V'       g   R# TpK•  V Fe  pSV,          P                  4        FG  w  rgWb9  g   K  VR,          VR,          8  g   K$  WRV&   W`9   d	   W`V3u u # VP                  V4       KI  	  Kg  	  V'       g   R# TpEK  )z:Bidirectional breadth-first search for an augmenting path.Nr	   r   )NNN)ÚlenÚitemsÚappend)ÚpredÚq_sÚsuccÚq_tÚqr   r   r   ÚR_predr   ÚsÚts           €€€€r   Úbidirectional_bfsÚ,edmonds_karp_core.<locals>.bidirectional_bfs(   s	  ø€ à�4ˆyˆØˆcˆØ�4ˆyˆØˆcˆØØˆAÜ�3‹xœ3˜s›8Ô#Û�AØ#)¨!¥9§?¡?Ö#4™˜Øž=¨T°&­\¸DÀÕ<LÖ-LØ&' ™GØ œyØ'(° }Ô 4ØŸH™H QžKó $5ñ ÷ Ø+Ð+Ø’ã�AØ#)¨!¥9§?¡?Ö#4™˜Øž=¨T°&­\¸DÀÕ<LÖ-LØ&' ™GØ œyØ'(° }Ô 4ØŸH™H QžKó $5ñ ÷ Ø+Ð+Ø“r   )Únodesr   r   Úgraphr   Úreverse)ÚRr#   r$   ÚcutoffÚR_nodesr   r%   Ú
flow_valuer   r   r   r   r   r"   r   r   s   &ff&         @@@r   Úedmonds_karp_corer.      sÆ   ü€ à�g‰g€GØ�V‰V€FØ�V‰V€Fà
�'‰'�%�.€Cö÷*ð ð@ €JØ
Ô
Ù)Ó+‰ˆ�ØŠ<Øð Ðð ˆsˆàˆØ�1ŒfØ•ˆAØ�K‰K˜ŽNØ�‰ŒàˆØ�1ŒfØ•ˆAØ�K‰K˜ŽNØ�g˜d“mÕ#Š
àÐr   c                óÐ  € W9  d$   \         P                  ! R\        V4       R24      hW 9  d$   \         P                  ! R\        V4       R24      hW8X  d   \         P                  ! R4      hVf   \        W4      pMTpVP                  P                  4        F  pVP                  4        F  p^ VR&   K
  	  K!  	  Vf   \        R4      p\        WaW%4      VP                  R&   V# )r   znode z not in graphz!source and sink are the same noder	   r   r-   )	r   ÚNetworkXErrorÚstrr   Ú_succÚvaluesÚfloatr.   r(   )	ÚGr#   r$   r   Úresidualr+   r*   ÚnbrsÚes	   &&&&&&   r   Úedmonds_karp_implr9   ^   sÎ   € à„zÜ×Ò ¤s¨1£v h¨mÐ<Ó=Ð=Ø„zÜ×Ò ¤s¨1£v h¨mÐ<Ó=Ð=Ø„vÜ×ÒÐBÓCÐCàÒÜ" 1Ó/‰àˆð —‘—‘Ö ˆØ—‘–ˆAØˆAˆf‹Ió ñ !ð ‚~Ü�u“ˆÜ-¨a°AÓ>€A‡G�GˆLÑà€Hr   r   r   T)Ú
edge_attrsÚreturns_graphÚpreserve_edge_attrsc                ój   € \        WW#WF4      pRVP                  R&   \        P                  ! V4       V# )aß  Find a maximum single-commodity flow using the Edmonds-Karp algorithm.

This function returns the residual network resulting after computing
the maximum flow. See below for details about the conventions
NetworkX uses for defining residual networks.

This algorithm has a running time of $O(n m^2)$ for $n$ nodes and $m$
edges.


Parameters
----------
G : NetworkX graph
    Edges of the graph are expected to have an attribute called
    'capacity'. If this attribute is not present, the edge is
    considered to have infinite capacity.

s : node
    Source node for the flow.

t : node
    Sink node for the flow.

capacity : string or function (default= 'capacity')
    If this is a string, then edge capacity will be accessed via the
    edge attribute with this key (that is, the capacity of the edge
    joining `u` to `v` will be ``G.edges[u, v][capacity]``). If no
    such edge attribute exists, the capacity of the edge is assumed to
    be infinite.

    If this is a function, the capacity of an edge is the value
    returned by the function. The function must accept exactly three
    positional arguments: the two endpoints of an edge and the
    dictionary of edge attributes for that edge. The function must
    return a number or None to indicate a hidden edge.

residual : NetworkX graph
    Residual network on which the algorithm is to be executed. If None, a
    new residual network is created. Default value: None.

value_only : bool
    If True compute only the value of the maximum flow. This parameter
    will be ignored by this algorithm because it is not applicable.

cutoff : integer, float
    If specified, the algorithm will terminate when the flow value reaches
    or exceeds the cutoff. In this case, it may be unable to immediately
    determine a minimum cut. Default value: None.

Returns
-------
R : NetworkX DiGraph
    Residual network after computing the maximum flow.

Raises
------
NetworkXError
    The algorithm does not support MultiGraph and MultiDiGraph. If
    the input graph is an instance of one of these two classes, a
    NetworkXError is raised.

NetworkXUnbounded
    If the graph has a path of infinite capacity, the value of a
    feasible flow on the graph is unbounded above and the function
    raises a NetworkXUnbounded.

See also
--------
:meth:`maximum_flow`
:meth:`minimum_cut`
:meth:`preflow_push`
:meth:`shortest_augmenting_path`

Notes
-----
The residual network :samp:`R` from an input graph :samp:`G` has the
same nodes as :samp:`G`. :samp:`R` is a DiGraph that contains a pair
of edges :samp:`(u, v)` and :samp:`(v, u)` iff :samp:`(u, v)` is not a
self-loop, and at least one of :samp:`(u, v)` and :samp:`(v, u)` exists
in :samp:`G`.

For each edge :samp:`(u, v)` in :samp:`R`, :samp:`R[u][v]['capacity']`
is equal to the capacity of :samp:`(u, v)` in :samp:`G` if it exists
in :samp:`G` or zero otherwise. If the capacity is infinite,
:samp:`R[u][v]['capacity']` will have a high arbitrary finite value
that does not affect the solution of the problem. This value is stored in
:samp:`R.graph['inf']`. For each edge :samp:`(u, v)` in :samp:`R`,
:samp:`R[u][v]['flow']` represents the flow function of :samp:`(u, v)` and
satisfies :samp:`R[u][v]['flow'] == -R[v][u]['flow']`.

The flow value, defined as the total flow into :samp:`t`, the sink, is
stored in :samp:`R.graph['flow_value']`. If :samp:`cutoff` is not
specified, reachability to :samp:`t` using only edges :samp:`(u, v)` such
that :samp:`R[u][v]['flow'] < R[u][v]['capacity']` induces a minimum
:samp:`s`-:samp:`t` cut.

Examples
--------
>>> from networkx.algorithms.flow import edmonds_karp

The functions that implement flow algorithms and output a residual
network, such as this one, are not imported to the base NetworkX
namespace, so you have to explicitly import them from the flow package.

>>> G = nx.DiGraph()
>>> G.add_edge("x", "a", capacity=3.0)
>>> G.add_edge("x", "b", capacity=1.0)
>>> G.add_edge("a", "c", capacity=3.0)
>>> G.add_edge("b", "c", capacity=5.0)
>>> G.add_edge("b", "d", capacity=4.0)
>>> G.add_edge("d", "e", capacity=2.0)
>>> G.add_edge("c", "y", capacity=2.0)
>>> G.add_edge("e", "y", capacity=3.0)
>>> R = edmonds_karp(G, "x", "y")
>>> flow_value = nx.maximum_flow_value(G, "x", "y")
>>> flow_value
3.0
>>> flow_value == R.graph["flow_value"]
True

r   Ú	algorithm)r9   r(   r   Ú_clear_cache)r5   r#   r$   r   r6   Ú
value_onlyr+   r*   s   &&&&&&& r   r   r   }   s2   € ô~ 	˜! ¨XÓ>€AØ)€A‡G�GˆKÑÜ‡O‚O�AÔØ€Hr   )r   NFN)Ú__doc__Únetworkxr   Únetworkx.algorithms.flow.utilsr   Ú__all__r.   r9   Ú_dispatchabler4   r   © r   r   Ú<module>rG      sX   ðñó Ý AàÐ
€òPòfð> ×ÒØ™E %›LÐ)¸ÐSWôóóòr   