+
    �°³j4?  ã                   ó¨   € R t ^ RIHt ^ RIHt ^ RIt^RIHt ^RIH	t	H
t
HtHtHt R.tR t]P                   ! R]! R	4      /R
R
R7      RR l4       tR# )zA
Highest-label preflow-push algorithm for maximum flow problems.
)Údeque)ÚisliceN)Úarbitrary_element)ÚCurrentEdgeÚGlobalRelabelThresholdÚLevelÚbuild_residual_networkÚdetect_unboundednessÚpreflow_pushc                ó,	  aaaaaaaaaaaaaaa€ SV 9  d$   \         P                  ! R\        S4       R24      hSV 9  d$   \         P                  ! R\        S4       R24      hSS8X  d   \         P                  ! R4      hVf   ^ pV^ 8  d   \         P                  ! R4      hVf   \        W4      oMVo\	        SSS4       SP
                  oSP                  oSP                  oS F2  p^ SV,          R&   SV,          P                  4        F  p^ VR&   K
  	  K4  	  V3R loS! S4      oSS9  d   ^ SP                  R&   S# \        S4      o\        VV3R	 lS 4       4      oSSS&   \        SSP                  4       V4      oS FB  pVS9   d
   SV,          MS^,           SV,          R
&   \        SV,          4      SV,          R&   KD  	  VV3R loSS,          P                  4        F   w  ryV	R,          p
V
^ 8”  g   K  S! SWz4       K"  	  \!        ^S,          4       Uu. uF  p\#        4       NK  	  upoS Fy  pVS8w  g   K  VS8w  g   K  SSV,          R
,          ,          pSV,          R,          ^ 8”  d   VP$                  P'                  V4       K^  VP(                  P'                  V4       K{  	  VVVV3R loVVV3R loVVVVVV3R lpVVVV3R lpVVVVVVV3R lpSpV^ 8”  dÃ    SV,          pVP$                  '       g   V^,          pK.  TpTp\+        VP$                  4      pV! VR4      pSP-                  4       '       d   V! R4      pVoSP/                  4        K{  VP$                  '       g(   VP(                  '       g   V! V4       V^,
          pVoK´  \        SV4      oKÂ  V'       d    SS,          R,          SP                  R&   S# V! R4      pSP/                  4        VS8”  dx    SV,          pVP$                  '       g   V^,          pK.  \+        VP$                  4      pV! VR4      pSP-                  4       '       g   K]  V! R4      pSP/                  4        Kw  SS,          R,          SP                  R&   S# u upi )z;Implementation of the highest-label preflow-push algorithm.znode z not in graphz!source and sink are the same nodez(global_relabel_freq must be nonnegative.ÚexcessÚflowc                ó   <€ V ^ /p\        V ^ 3.4      pV'       ds   VP                  4       w  r4V^,          pSV,          P                  4        F:  w  rVWQ9  g   K  VR,          VR,          8  g   K$  WAV&   VP                  WT34       K<  	  Kz  V# )zIPerform a reverse breadth-first search from src in the residual
network.
r   Úcapacity)r   ÚpopleftÚitemsÚappend)ÚsrcÚheightsÚqÚuÚheightÚvÚattrÚR_preds   &      €Úe/home/luca/screen-checking/.venv/lib/python3.14/site-packages/networkx/algorithms/flow/preflowpush.pyÚreverse_bfsÚ&preflow_push_impl.<locals>.reverse_bfs5   s€   ø€ ð ˜�(ˆÜ�C˜�8�*ÓˆßØŸ	™	›‰IˆAØ�a�KˆFØ! !�9Ÿ?™?Ö,‘�ØÖ#¨¨V­°t¸JÕ7GÖ(GØ!'˜A‘JØ—H‘H˜a˜[Ö)ó -ð ˆó    Ú
flow_valuec              3   óF   <"  € T F  qS8w  g   K  SV,          x € K  	  R # 5i)N© )Ú.0r   r   Úss   & €€r   Ú	<genexpr>Ú$preflow_push_impl.<locals>.<genexpr>P   s   øé € Ð;© A¸±F”Z�W˜Q—Z’Z«ùs   ƒ!�!r   Ú	curr_edgec                ó  <€ SV ,          V,          R;;,          V,          uu&   SV,          V ,          R;;,          V,          uu&   SV ,          R;;,          V,          uu&   SV,          R;;,          V,          uu&   R# )z$Push flow units of flow from u to v.r   r   Nr!   )r   r   r   ÚR_nodesÚR_succs   &&&€€r   ÚpushÚpreflow_push_impl.<locals>.pushZ   s[   ø€ àˆq�	�!��V× Õ$ÓØˆq�	�!��V× Õ$ÓØ��
�8× Õ$ÓØ��
�8× Õ$Õr   r   c                óê   <€ V S8w  dk   V S8w  db   SSV ,          R,          ,          pWP                   9   d9   VP                   P                  V 4       VP                  P                  V 4       R# R# R# R# )zAMove a node from the inactive set to the active set of its level.r   N)ÚinactiveÚremoveÚactiveÚadd)r   Úlevelr(   Úlevelsr#   Úts   & €€€€r   ÚactivateÚ#preflow_push_impl.<locals>.activater   s]   ø€ à�Œ6�a˜1”fØ˜7 1�: hÕ/Õ0ˆEØ—N‘NÔ"Ø—‘×%Ñ% aÔ(Ø—‘× Ñ  Ö#ñ #ñ ‰6r   c                ó¨   <€ SP                  \        SV ,          4      4       \        V3R lSV ,          P                  4        4       4      ^,           # )z,Relabel a node to create an admissible edge.c              3   óv   <"  € T F.  w  rVR ,          VR,          8  g   K  SV,          R,          x € K0  	  R# 5i)r   r   r   Nr!   )r"   r   r   r(   s   &  €r   r$   Ú5preflow_push_impl.<locals>.relabel.<locals>.<genexpr>~   s9   øé € ð á0‘G�AØ˜•< $ zÕ"2Ñ2ô %�˜•
˜8×$Ò$Û0ùs   ƒ9¡9)Úadd_workÚlenÚminr   )r   r(   r)   Úgrts   &€€€r   ÚrelabelÚ"preflow_push_impl.<locals>.relabelz   sF   ø€ à�‰”S˜ �“^Ô$äô à% a�yŸ™Ô0óó ð
 õð	
r   c                óö  <€ SV ,          R,          pSV ,          R,          pTpS
V,          P                   P                  V 4        VP                  4       w  rVVSV,          R,          ^,           8X  dŽ   VR,          VR,          8  dy   \        SV ,          R,          VR,          VR,          ,
          4      pS! WV4       S	! V4       SV ,          R,          ^ 8X  d$   S
V,          P                  P                  V 4       M VP                  4        KÏ  VSV ,          R&   V#   \         dK    S! T 4      pT'       d4   TS^,
          8¼  d&   S
T,          P                   P                  T 4        K\  Tp EK1  i ; i)z«Discharge a node until it becomes inactive or, during phase 1 (see
below), its height reaches at least n. The node is known to have the
largest height among active nodes.
r   r&   r   r   r   )r/   r.   Úgetr;   r-   r0   Úmove_to_nextÚStopIteration)r   Ú	is_phase1r   r&   Únext_heightr   r   r   r(   r4   r2   Únr*   r=   s   &&      €€€€€€r   Ú	dischargeÚ$preflow_push_impl.<locals>.discharge†   sJ  ø€ ð
 ˜•˜HÕ%ˆØ˜A•J˜{Õ+ˆ	ð ˆØˆv�×Ñ×$Ñ$ QÔ'ØØ—m‘m“o‰GˆAØ˜ � HÕ-°Õ1Ô1°d¸6µlÀTÈ*ÕEUÔ6UÜ˜7 1�: hÕ/°°jÕ1AÀDÈÅLÕ1PÓQ�Ù�Q˜4Ô Ù˜”Ø˜1•:˜hÕ'¨1Ô,à˜6•N×+Ñ+×/Ñ/°Ô2Øð%Ø×&Ñ&Ö(ð   &ˆ��
�8ÑØÐøô! !ô %ñ ! ›�ß ¨1¨q­5¤ð ˜6•N×)Ñ)×-Ñ-¨aÔ0Úð
 %”ð%ús   ÄD# Ä#E8Ä>0E8Å1E8Å7E8c                ó  <€ \        SV ^,           S^,           4       Fé  pVP                   F  pS^,           SV,          R&   K  	  VP                   F  pS^,           SV,          R&   K  	  SS^,           ,          P                  P                  VP                  4       VP                  P	                  4        SS^,           ,          P                  P                  VP                  4       VP                  P	                  4        Kë  	  R# )zApply the gap heuristic.r   N)r   r/   r-   ÚupdateÚclear)r   r1   r   r(   r2   Ú
max_heightrE   s   &  €€€€r   Úgap_heuristicÚ(preflow_push_impl.<locals>.gap_heuristic¯   sÁ   ø€ ô ˜F F¨Q¥J°
¸QµÖ?ˆEØ—\”\�Ø'(¨1¥u�˜•
˜8Ó$ñ "à—^”^�Ø'(¨1¥u�˜•
˜8Ó$ñ $à�1�q•5�M× Ñ ×'Ñ'¨¯©Ô5Ø�L‰L×ÑÔ Ø�1�q•5�M×"Ñ"×)Ñ)¨%¯.©.Ô9Ø�N‰N× Ñ Ö"ó @r   c                óü  <€ V '       d   SMSpS! V4      pV '       g   VS \        VP                  4       4      pV '       d5   S F-  pWB9  g   K  SV,          R,          S
8  g   K"  S
^,           W$&   K/  	  M&V F  pW$;;,          S
,          uu&   K  	  VS
,          pW! VP                  4        FÊ  w  rESV,          R,          pWV8w  g   K  VS	V,          P                  9   dF   S	V,          P                  P	                  V4       S	V,          P                  P                  V4       MDS	V,          P                  P	                  V4       S	V,          P                  P                  V4       VSV,          R&   KÌ  	  V# )z&Apply the global relabeling heuristic.r   )ÚmaxÚvaluesr   r/   r.   r0   r-   )Ú	from_sinkr   r   rK   r   Ú
new_heightÚ
old_heightÚRr(   r2   rE   r   r#   r3   s   &      €€€€€€€r   Úglobal_relabelÚ)preflow_push_impl.<locals>.global_relabel¼   s9  ø€ ç‰a !ˆÙ˜cÓ"ˆßà˜�
Ü˜Ÿ™Ó)Ó*ˆ
ßó �ØÖ#¨°­
°8Õ(<¸qÖ(@Ø!" Q¥�G“Jò ó
 �Ø—
˜a••
ñ à˜!�OˆJØˆLØ$Ÿ]™]ž_‰MˆAØ  � HÕ-ˆJØÖ'Ø˜˜zÕ*×1Ñ1Ô1Ø˜:Õ&×-Ñ-×4Ñ4°QÔ7Ø˜:Õ&×-Ñ-×1Ñ1°!Õ4à˜:Õ&×/Ñ/×6Ñ6°qÔ9Ø˜:Õ&×/Ñ/×3Ñ3°AÔ6Ø'1�˜•
˜8Ó$ñ -ð Ðr   TF)ÚnxÚNetworkXErrorÚstrr   r	   ÚnodesÚpredÚsuccrP   Úgraphr:   rO   r   Úsizer   r   Úranger   r/   r0   r-   r   Ú
is_reachedÚ
clear_work) ÚGr#   r3   r   ÚresidualÚglobal_relabel_freqÚ
value_onlyr   Úer   r   Úir1   rF   rL   rU   r   rS   Ú	old_levelrT   r(   r   r)   r4   r<   r   r2   rK   rE   r*   r=   r   s    &ff&&&&            @@@@@@@@@@@@@r   Úpreflow_push_implri      s  ÿþ€ à�„zÜ×Ò ¤s¨1£v h¨mÐ<Ó=Ð=Ø�„zÜ×Ò ¤s¨1£v h¨mÐ<Ó=Ð=ØˆA„vÜ×ÒÐBÓCÐCàÒ"ØÐØ˜QÔÜ×ÒÐIÓJÐJàÒÜ" 1Ó/‰àˆä˜˜A˜qÔ!à�g‰g€GØ�V‰V€FØ�V‰V€Fó ˆØ ˆ��
�8ÑØ˜•×!Ñ!Ö#ˆAØˆAˆf‹Ió $ñ õ
ñ  ˜!‹n€Gà�Ôð !"ˆ�‰�ÑØˆäˆA‹€Aô Õ;©Ó;Ó;€JØ€GˆA�Jä
   A§F¡F£HÐ.AÓ
B€Có ˆØ-.°'¬\˜w qžz¸qÀ1½uˆ��
�8ÑÜ"-¨f°Q­iÓ"8ˆ��
�;Óñ ö%ð ˜!•9—?‘?Ö$‰ˆØ�JÕˆØ�!Ž8Ù��AÖñ %ô  % Q¨¥Uœ|Ó,™|˜!ŒeŽg™|Ñ,€FÛˆØ�Ž6�a˜1–fØ˜7 1�: hÕ/Õ0ˆEØ�q�z˜(Õ# aÔ'Ø—‘× Ñ  Ö#à—‘×"Ñ" 1Ö%ñ ÷$ð $÷

÷'ò '÷R#ð #÷ó ðF €FØ
�1Œ*àØ˜6•NˆEØ—<—<�<ð ˜!•�ÙàˆJØˆIÜ! %§,¡,Ó/ˆAÙ˜q $Ó'ˆFØ�~‰~×Òñ (¨Ó-�Ø#�
Ø—‘Ö Ø×%×%Ð%¨i×.@×.@Ð.@ñ
 ˜jÔ)Ø# a��Ø#’
ô ! ¨VÓ4’
÷ Ø '¨¥
¨8Õ 4ˆ�‰�ÑØˆñ ˜EÓ"€FØ‡N�NÔð �1Œ*àØ˜6•NˆEØ—<—<�<ð ˜!•�ÙÜ! %§,¡,Ó/ˆAÙ˜q %Ó(ˆFØ�~‰~×Ôá'¨Ó.�Ø—‘Ö à# A�J xÕ0€A‡G�GˆLÑØ€Hùòo -s   È$Rr   ÚinfT)Ú
edge_attrsÚreturns_graphÚpreserve_edge_attrsc           	     ól   € \        WW#WEV4      pRVP                  R&   \        P                  ! V4       V# )aÂ  Find a maximum single-commodity flow using the highest-label
preflow-push 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^2 \sqrt{m})$ 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.

global_relabel_freq : integer, float
    Relative frequency of applying the global relabeling heuristic to speed
    up the algorithm. If it is None, the heuristic is disabled. Default
    value: 1.

value_only : bool
    If False, compute a maximum flow; otherwise, compute a maximum preflow
    which is enough for computing the maximum flow value. Default value:
    False.

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:`edmonds_karp`
: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 node :samp:`u` in :samp:`R`,
:samp:`R.nodes[u]['excess']` represents the difference between flow into
:samp:`u` and flow out of :samp:`u`.

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']`. 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 preflow_push

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 = preflow_push(G, "x", "y")
>>> flow_value = nx.maximum_flow_value(G, "x", "y")
>>> flow_value == R.graph["flow_value"]
True
>>> # preflow_push also stores the maximum flow value
>>> # in the excess attribute of the sink node t
>>> flow_value == R.nodes["y"]["excess"]
True
>>> # For some problems, you might only want to compute a
>>> # maximum preflow.
>>> R = preflow_push(G, "x", "y", value_only=True)
>>> flow_value == R.graph["flow_value"]
True
>>> flow_value == R.nodes["y"]["excess"]
True

r
   Ú	algorithm)ri   r]   rW   Ú_clear_cache)rb   r#   r3   r   rc   rd   re   rT   s   &&&&&&& r   r
   r
   #  s4   € ôX 	˜! ¨XÈJÓW€AØ)€A‡G�GˆKÑÜ‡O‚O�AÔØ€Hr   )r   Né   F)Ú__doc__Úcollectionsr   Ú	itertoolsr   ÚnetworkxrW   Úutilsr   r   r   r   r   r	   Ú__all__ri   Ú_dispatchableÚfloatr
   r!   r   r   Ú<module>rz      se   ðñõ Ý ã å &÷õ ð Ð
€òJðZ ×ÒØ™E %›LÐ)¸ÐSWôóLóòLr   