Ë
    D^(hÄ  ã                   ó0  — d Z ddlmZ ddlZg d¢Z G d„ d«      Z G d„ d«      Z G d	„ d
«      Z ej                  d e
d«      id¬«      d„ «       Z ej                  ddd e
d«      iid¬«      d„ «       Z ej                  dddœdddii¬«      d„ «       Zy)z<
Utility classes and functions for network flow algorithms.
é    )ÚdequeN)ÚCurrentEdgeÚLevelÚGlobalRelabelThresholdÚbuild_residual_networkÚdetect_unboundednessÚbuild_flow_dictc                   ó,   — e Zd ZdZdZd„ Zd„ Zd„ Zd„ Zy)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                 óL   — || _         | j                   r| j                  «        y y ©N)r   Ú_rewind)ÚselfÚedgess     ú\/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/networkx/algorithms/flow/utils.pyÚ__init__zCurrentEdge.__init__   s   € ØˆŒØ�;Š;Ø�L‰L�Nð ó    c                 ó   — | j                   S r   )r   ©r   s    r   ÚgetzCurrentEdge.get   s   € Ø�z‰zÐr   c                 óv   — 	 t        | j                  «      | _        y # t        $ r | j	                  «        ‚ w xY wr   )Únextr   r   ÚStopIterationr   r   s    r   Úmove_to_nextzCurrentEdge.move_to_next"   s1   € ð	Ü˜dŸh™h›ˆD�JøÜò 	Ø�L‰LŒNØð	ús   ‚ �8c                 óˆ   — t        | j                  j                  «       «      | _        t	        | j                  «      | _        y r   )Úiterr   Úitemsr   r   r   r   s    r   r   zCurrentEdge._rewind)   s*   € Ü˜Ÿ™×)Ñ)Ó+Ó,ˆŒÜ˜$Ÿ(™(“^ˆ�
r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r   r   © r   r   r   r      s"   „ ñð +€Iòò
òó$r   r   c                   ó   — e Zd ZdZdZd„ Zy)r   z%Active and inactive nodes in a level.)ÚactiveÚinactivec                 ó@   — t        «       | _        t        «       | _        y r   )Úsetr'   r(   r   s    r   r   zLevel.__init__3   s   € Ü“eˆŒÜ›ˆ�r   N)r    r!   r"   r#   r$   r   r%   r   r   r   r   .   s   „ Ù/à&€Iór   r   c                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)r   zVMeasurement of work before the global relabeling heuristic should be
    applied.
    c                 óF   — |r||z   |z  n
t        d«      | _        d| _        y )NÚinfr   )ÚfloatÚ
_thresholdÚ_work)r   ÚnÚmÚfreqs       r   r   zGlobalRelabelThreshold.__init__=   s    € Ù,0˜1˜q™5 Dš.´e¸E³lˆŒØˆ�
r   c                 ó.   — | xj                   |z  c_         y r   ©r0   )r   Úworks     r   Úadd_workzGlobalRelabelThreshold.add_workA   s   € Ø�
Š
�dÑŽ
r   c                 ó4   — | j                   | j                  k\  S r   )r0   r/   r   s    r   Ú
is_reachedz!GlobalRelabelThreshold.is_reachedD   s   € Ø�z‰z˜TŸ_™_Ñ,Ð,r   c                 ó   — d| _         y )Nr   r5   r   s    r   Ú
clear_workz!GlobalRelabelThreshold.clear_workG   s	   € Øˆ�
r   N)r    r!   r"   r#   r   r7   r9   r;   r%   r   r   r   r   8   s   „ ñòòò-ór   r   Úcapacityr-   T)Ú
edge_attrsÚreturns_graphc           	      óH  ‡‡— | j                  «       rt        j                  d«      ‚t        j                  «       }d|_        |j                  | «       t        d«      Š| j                  d¬«      D ���cg c]%  \  }}}||k7  r|j                  ‰‰«      dkD  r|||f‘Œ' }}}}dt        ˆˆfd„|D «       «      z  xs d	Š| j                  «       rn|D ]h  \  }}}t        |j                  ‰‰«      ‰«      }|j                  ||«      s)|j                  |||¬
«       |j                  ||d¬
«       Œ^|||   |   d<   Œj nO|D ]J  \  }}}t        |j                  ‰‰«      ‰«      }|j                  |||¬
«       |j                  |||¬
«       ŒL ‰|j                  d<   |S c c}}}w )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   óH   •K  — | ]  \  }}}‰|v r|‰   ‰k7  r|‰   –— Œ y ­wr   r%   )Ú.0ÚuÚvÚattrr<   r-   s       €€r   ú	<genexpr>z)build_residual_network.<locals>.<genexpr>   s6   øè ø€ ò 
á��1�dØ˜4Ñ D¨¡N°cÒ$9ð ��Nñ
ùs   ƒ"é   )r<   r<   )Úis_multigraphÚnxÚNetworkXErrorÚDiGraphÚ__networkx_cache__Úadd_nodes_fromr.   r   r   ÚsumÚis_directedÚminÚhas_edgeÚadd_edgeÚgraph)	ÚGr<   ÚRrD   rE   rF   Ú	edge_listÚrr-   s	    `      @r   r   r   K   s¸  ù€ ð4 	‡�ÔÜ×ÑÐQÓRÐRä
�
‰
‹€AØ€AÔØ×Ñ�QÔä
�‹,€Cð Ÿ'™' t˜'Ó,÷ð áˆAˆq�$Ø�Š6�d—h‘h˜x¨Ó-°Ò1ð 
ˆAˆtŠð€Iò ð  	
Ü
ô 
à'ô
ó 
ñ	
ò 	ð ð ð 	‡}�}„Ø#ò 		(‰JˆAˆq�$Ü�D—H‘H˜X sÓ+¨SÓ1ˆAØ—:‘:˜a Ô#ð —
‘
˜1˜a¨!�
Ô,Ø—
‘
˜1˜a¨!�
Õ,ð '(��!‘�Q‘˜
Ò#ñ		(ð $ò 	)‰JˆAˆq�$ä�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   Á5*FrV   )ÚgraphsÚpreserve_edge_attrsÚpreserve_graph_attrsc                 ó6  — t        |g«      }|h}| j                  d   }|ry|j                  «       }| |   j                  «       D ]O  \  }}|d   |k(  sŒ||vsŒ||k(  rt	        j
                  d«      ‚|j                  |«       |j                  |«       ŒQ |rŒxyy)z*Detect an infinite-capacity s-t path in R.r-   r<   z-Infinite capacity path, flow unbounded above.N)r   rT   Úpopleftr   rJ   ÚNetworkXUnboundedÚaddÚappend)	rV   ÚsÚtÚqÚseenr-   rD   rE   rF   s	            r   r   r   ž   s›   € ô 	ˆqˆc‹
€AØˆ3€DØ
�'‰'�%‰.€CÙ
Ø�I‰I‹KˆØ˜‘t—z‘z“|ò 	‰GˆAˆtØ�JÑ 3Ó&¨1°Dª=Ø˜’6Ü×.Ñ.ØGóð ð —‘˜”Ø—‘˜•ð	ô r   rH   )rU   rV   Úflow)rY   rZ   c                 ó¨   — i }| D ]E  }| |   D �ci c]  }|d“Œ c}||<   ||   j                  d„ ||   j                  «       D «       «       ŒG |S c c}w )z0Build a flow dictionary from a residual network.r   c              3   óB   K  — | ]  \  }}|d    dkD  sŒ||d    f–— Œ y­w)re   r   Nr%   )rC   rE   rF   s      r   rG   z"build_flow_dict.<locals>.<genexpr>º   s-   è ø€ ò 
Ù") ! T¸TÀ&¹\ÈAÓ=MˆQ��V‘Ôñ
ùs   ‚“)Úupdater   )rU   rV   Ú	flow_dictrD   rE   s        r   r	   r	   ´   sj   € ð €IØò 
ˆØ&'¨¡dÖ+ ˜˜1™Ò+ˆ	�!‰Ø�!‰×Ññ 
Ø-.¨q©T¯Z©Z«\ô
õ 	
ð
ð
 Ðùò	 ,s   �
A)r#   Úcollectionsr   ÚnetworkxrJ   Ú__all__r   r   r   Ú_dispatchabler.   r   r   r	   r%   r   r   ú<module>rn      sÑ   ðñõ ã ò€÷$ñ $÷6ñ ÷ñ ð& €×Ñ˜j©%°«,Ð7ÀtÔLñOó MðOðd €×ÑØØ˜z©5°«<Ð8Ð9Øôñ
óð
ð" €×Ñ˜q qÑ)ÀÀfÈdÀ^Ð?TÔUñó Vñr   