ó
    …~if  ã                   ó  • S r SSKJr  SSKr/ SQr " S S5      r " S S5      r " S	 S
5      r\R                  " S\
" S5      0SS9S 5       r\R                  " SSS\
" S5      00SS9S 5       r\R                  " SSS.SSS00S9S 5       rg)z<
Utility classes and functions for network flow algorithms.
é    )ÚdequeN)ÚCurrentEdgeÚLevelÚGlobalRelabelThresholdÚbuild_residual_networkÚdetect_unboundednessÚbuild_flow_dictc                   ó:   • \ rS rSrSrSrS rS rS rS r	S r
S	rg
)r   é   zŠMechanism for iterating over out-edges incident to a node in a circular
manner. StopIteration exception is raised when wraparound occurs.
)Ú_edgesÚ_itÚ_currc                 óT   • Xl         U R                   (       a  U R                  5         g g ©N)r   Ú_rewind)ÚselfÚedgess     Ú[/home/mande/repo/quber/.venv/lib/python3.13/site-packages/networkx/algorithms/flow/utils.pyÚ__init__ÚCurrentEdge.__init__   s   € ØŒØ�;�;Ø�L‰L�Nð ó    c                 ó   • U R                   $ r   )r   ©r   s    r   ÚgetÚCurrentEdge.get   s   € Ø�z‰zÐr   c                 óx   •  [        U R                  5      U l        g ! [         a    U R	                  5         e f = fr   )Únextr   r   ÚStopIterationr   r   s    r   Úmove_to_nextÚCurrentEdge.move_to_next"   s1   € ð	Ü˜dŸh™h›ˆD�JøÜó 	Ø�L‰LŒNØð	ús   ‚ �9c                 óˆ   • [        U R                  R                  5       5      U l        [	        U R                  5      U l        g r   )Úiterr   Úitemsr   r   r   r   s    r   r   ÚCurrentEdge._rewind)   s*   € Ü˜Ÿ™×)Ñ)Ó+Ó,ˆŒÜ˜$Ÿ(™(“^ˆ�
r   c                 óh   • [        U SS 5      U R                  4[        USS 5      UR                  4:H  $ )Nr   )Úgetattrr   )r   Úothers     r   Ú__eq__ÚCurrentEdge.__eq__-   s6   € Ü˜˜g tÓ,¨d¯k©kÐ:Ü�U˜G TÓ*¨E¯L©LÐ9ñ
ð 	
r   )r   r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú	__slots__r   r   r   r   r(   Ú__static_attributes__© r   r   r   r      s'   † ñð +€Iòò
òò$õ
r   r   c                   ó"   • \ rS rSrSrSrS rSrg)r   é3   z%Active and inactive nodes in a level.)ÚactiveÚinactivec                 ó@   • [        5       U l        [        5       U l        g r   )Úsetr4   r5   r   s    r   r   ÚLevel.__init__8   s   € Ü“eˆŒÜ›ˆ�r   N)r*   r+   r,   r-   r.   r/   r   r0   r1   r   r   r   r   3   s   † Ù/à&€Iõr   r   c                   ó0   • \ rS rSrSrS rS rS rS rSr	g)	r   é=   zNMeasurement of work before the global relabeling heuristic should be
applied.
c                 óN   • U(       a  X-   U-  O
[        S5      U l        SU l        g )NÚinfr   )ÚfloatÚ
_thresholdÚ_work)r   ÚnÚmÚfreqs       r   r   ÚGlobalRelabelThreshold.__init__B   s   € Þ,0˜1™5 Dš.´e¸E³lˆŒØˆ�
r   c                 ó.   • U =R                   U-  sl         g r   ©r?   )r   Úworks     r   Úadd_workÚGlobalRelabelThreshold.add_workF   s   € Ø�
Š
�dÑŽ
r   c                 ó4   • U R                   U R                  :¬  $ r   )r?   r>   r   s    r   Ú
is_reachedÚ!GlobalRelabelThreshold.is_reachedI   s   € Ø�z‰z˜TŸ_™_Ñ,Ð,r   c                 ó   • SU l         g )Nr   rE   r   s    r   Ú
clear_workÚ!GlobalRelabelThreshold.clear_workL   s	   € Øˆ�
r   )r>   r?   N)
r*   r+   r,   r-   r.   r   rG   rJ   rM   r0   r1   r   r   r   r   =   s   † ñòòò-õr   r   Úcapacityr<   T)Ú
edge_attrsÚreturns_graphc           	      ó^  ^^• U R                  5       (       a  [        R                  " S5      e[        R                  " 5       nSUl        UR                  U 5        [        S5      mU R                  SS9 VVVs/ s H)  u  p4nX4:w  d  M  UR                  TT5      S:”  d  M%  X4U4PM+     nnnnS[        UU4S jU 5       5      -  =(       d    S	mU R                  5       (       ak  U Hd  u  p4n[        UR                  TT5      T5      nUR                  X45      (       d"  UR                  X4US
9  UR                  XCSS
9  MZ  XrU   U   S'   Mf     OHU HB  u  p4n[        UR                  TT5      T5      nUR                  X4US
9  UR                  XCUS
9  MD     TUR                  S'   U$ s  snnnf )a­  Build a residual network and initialize a zero flow.

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.

z0MultiGraph and MultiDiGraph not supported (yet).Nr<   T)Údatar   é   c              3   óZ   >#   • U  H   u  pnTU;   d  M  UT   T:w  d  M  UT   v •  M"     g 7fr   r1   )Ú.0ÚuÚvÚattrrO   r<   s       €€r   Ú	<genexpr>Ú)build_residual_network.<locals>.<genexpr>„   s;   øé € ð 
â'‘
��dØ˜4Ñó à$(¨¡N°cÑ$9ó ˆD�ŽNÚ'ùs   ƒ+”+Ÿ+é   )rO   rO   )Úis_multigraphÚnxÚNetworkXErrorÚDiGraphÚ__networkx_cache__Úadd_nodes_fromr=   r   r   ÚsumÚis_directedÚminÚhas_edgeÚadd_edgeÚgraph)	ÚGrO   ÚRrW   rX   rY   Ú	edge_listÚrr<   s	    `      @r   r   r   P   s¦  ù€ ð4 	‡�×ÑÜ×ÒÐQÓRÐRä
�
Š
‹€AØ€AÔØ×Ñ�QÔä
�‹,€Cð Ÿ'™' t˜'Ñ,õâ,‰JˆA�$Ø‰6ó 	à—h‘h˜x¨Ó-°Ñ1ó 	ˆˆt‹Ù,ð ò ð  	
Ü
õ 
á'ó
ó 
ñ	
÷ 	ð ð ð 	‡}�}‡�Û#‰JˆA�$Ü�D—H‘H˜X sÓ+¨SÓ1ˆAØ—:‘:˜a×#Ñ#ð —
‘
˜1¨!�
Ñ,Ø—
‘
˜1¨!�
Ó,ð '(�!‘�Q‘˜
Ó#ò $ó $‰JˆA�$ä�D—H‘H˜X sÓ+¨SÓ1ˆAØ�J‰J�q aˆJÑ(Ø�J‰J�q aˆJÓ(ñ	 $ð €A‡G�GˆE�Nà€Hùô[s   Á9F(Â	F(Â!F(rj   )ÚgraphsÚpreserve_edge_attrsÚpreserve_graph_attrsc                 óV  • [        U/5      nU1nU R                  S   nU(       a„  UR                  5       nX   R                  5        HT  u  pxUS   U:X  d  M  Xt;  d  M  Xr:X  a  [        R
                  " S5      eUR                  U5        UR                  U5        MV     U(       a  Mƒ  gg)z*Detect an infinite-capacity s-t path in R.r<   rO   z-Infinite capacity path, flow unbounded above.N)r   rh   Úpopleftr#   r^   ÚNetworkXUnboundedÚaddÚappend)	rj   ÚsÚtÚqÚseenr<   rW   rX   rY   s	            r   r   r   £   s�   € ô 	ˆqˆc‹
€AØˆ3€DØ
�'‰'�%‰.€CÞ
Ø�I‰I‹KˆØ‘t—z‘z–|‰GˆAØ�JÑ 3Õ&¨1­=Ø“6Ü×.Ò.ØGóð ð —‘˜”Ø—‘˜–ñ $÷ Š!r   r\   )ri   rj   Úflow)rm   rn   c                 ó¨   • 0 nU  HD  nX    Vs0 s H  oDS_M     snX#'   X#   R                  S X   R                  5        5       5        MF     U$ s  snf )z0Build a flow dictionary from a residual network.r   c              3   óH   #   • U  H  u  pUS    S:”  d  M  XS    4v •  M     g7f)ry   r   Nr1   )rV   rX   rY   s      r   rZ   Ú"build_flow_dict.<locals>.<genexpr>¿   s*   é € ð 
Ú-9¡' !¸TÀ&¹\ÈAÑ=MÓˆQ�V‘Õª\ùs   ‚"•")Úupdater#   )ri   rj   Ú	flow_dictrW   rX   s        r   r	   r	   ¹   s_   € ð €IÛˆØ&'¢dÓ+¢d ˜1š¡dÑ+ˆ	‰Ø‰×Ññ 
Ø-.©T¯Z©Z¬\ó
ö 	
ñ ð
 Ðùò	 ,s   ŽA)r.   Úcollectionsr   Únetworkxr^   Ú__all__r   r   r   Ú_dispatchabler=   r   r   r	   r1   r   r   Ú<module>rƒ      sÌ   ðñõ ã ò€÷
ñ 
÷@ñ ÷ñ ð& ×Ò˜j©%°«,Ð7ÀtÑLñOó MðOðd ×ÒØØ˜z©5°«<Ð8Ð9Øññ
óð
ð" ×Ò˜q qÑ)ÀÀfÈdÀ^Ð?TÑUñó Vñr   