§
    bŠtjf  ã                   óV  — 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dS )z<
Utility classes and functions for network flow algorithms.
é    )ÚdequeN)ÚCurrentEdgeÚLevelÚGlobalRelabelThresholdÚbuild_residual_networkÚdetect_unboundednessÚbuild_flow_dictc                   ó4   — e Zd ZdZdZd„ Zd„ Zd„ Zd„ Zd„ Z	dS )	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                 óN   — || _         | j         r|                      ¦   «          d S d S ©N)r   Ú_rewind)ÚselfÚedgess     ú\/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/networkx/algorithms/flow/utils.pyÚ__init__zCurrentEdge.__init__   s.   € ØˆŒØŒ;ð 	Ø�LŠL‰NŒNˆNˆNˆNð	ð 	ó    c                 ó   — | j         S r   )r   ©r   s    r   ÚgetzCurrentEdge.get   s
   € ØŒzÐr   c                 ó€   — 	 t          | j        ¦  «        | _        d S # t          $ r |                      ¦   «          ‚ w xY wr   )Únextr   r   ÚStopIterationr   r   s    r   Úmove_to_nextzCurrentEdge.move_to_next"   sE   € ð	Ý˜dœh™œˆDŒJˆJˆJøÝð 	ð 	ð 	Ø�LŠL‰NŒNˆNØð	øøøs   ‚ � =c                 óŽ   — t          | j                             ¦   «         ¦  «        | _        t	          | j        ¦  «        | _        d S r   )Úiterr   Úitemsr   r   r   r   s    r   r   zCurrentEdge._rewind)   s2   € Ý˜œ×)Ò)Ñ+Ô+Ñ,Ô,ˆŒÝ˜$œ(‘^”^ˆŒ
ˆ
ˆ
r   c                 óf   — t          | dd ¦  «        | j        ft          |dd ¦  «        |j        fk    S )Nr   )Úgetattrr   )r   Úothers     r   Ú__eq__zCurrentEdge.__eq__-   s8   € Ý˜˜g tÑ,Ô,¨d¬kÐ:Ý�U˜G TÑ*Ô*¨E¬LÐ9ò
ð 	
r   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r   r   r#   © r   r   r   r      sp   € € € € € ðð ð +€Iðð ð ð
ð ð ðð ð ð$ð $ð $ð
ð 
ð 
ð 
ð 
r   r   c                   ó   — e Zd ZdZdZd„ ZdS )r   z%Active and inactive nodes in a level.)ÚactiveÚinactivec                 óR   — t          ¦   «         | _        t          ¦   «         | _        d S r   )Úsetr+   r,   r   s    r   r   zLevel.__init__8   s   € Ý‘e”eˆŒÝ™œˆŒˆˆr   N)r$   r%   r&   r'   r(   r   r)   r   r   r   r   3   s.   € € € € € Ø/Ð/à&€Iðð ð ð ð r   r   c                   ó*   — e Zd ZdZd„ Zd„ Zd„ Zd„ ZdS )r   zVMeasurement of work before the global relabeling heuristic should be
    applied.
    c                 óP   — |r||z   |z  nt          d¦  «        | _        d| _        d S )NÚinfr   )ÚfloatÚ
_thresholdÚ_work)r   ÚnÚmÚfreqs       r   r   zGlobalRelabelThreshold.__init__B   s+   € Ø,0ÐB˜1˜q™5 D™.˜.µe¸E±l´lˆŒØˆŒ
ˆ
ˆ
r   c                 ó&   — | xj         |z  c_         d S r   ©r4   )r   Úworks     r   Úadd_workzGlobalRelabelThreshold.add_workF   s   € Øˆ
Œ
�dÑˆ
Œ
ˆ
ˆ
r   c                 ó"   — | j         | j        k    S r   )r4   r3   r   s    r   Ú
is_reachedz!GlobalRelabelThreshold.is_reachedI   s   € ØŒz˜Tœ_Ò,Ð,r   c                 ó   — d| _         d S )Nr   r9   r   s    r   Ú
clear_workz!GlobalRelabelThreshold.clear_workL   s   € ØˆŒ
ˆ
ˆ
r   N)r$   r%   r&   r'   r   r;   r=   r?   r)   r   r   r   r   =   sZ   € € € € € ðð ðð ð ðð ð ð-ð -ð -ðð ð ð ð r   r   Úcapacityr1   T)Ú
edge_attrsÚreturns_graphc                 ó`  ‡‡— |                       ¦   «         rt          j        d¦  «        ‚t          j        ¦   «         }d|_        |                     | ¦  «         t          d¦  «        Šˆˆfd„|                      d¬¦  «        D ¦   «         }dt          ˆˆfd„|D ¦   «         ¦  «        z  pd	Š|  	                    ¦   «         r†|D ]‚\  }}}t          |                     ‰‰¦  «        ‰¦  «        }|                     ||¦  «        s1|                     |||¬
¦  «         |                     ||d¬
¦  «         Œq|||         |         d<   Œƒn]|D ]Z\  }}}t          |                     ‰‰¦  «        ‰¦  «        }|                     |||¬
¦  «         |                     |||¬
¦  «         Œ[‰|j        d<   |S )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).Nr1   c                 ób   •— g | ]+\  }}}||k    ¯|                      ‰‰¦  «        d k    ¯&|||f‘Œ,S ©r   )r   ©Ú.0ÚuÚvÚattrr@   r1   s       €€r   ú
<listcomp>z*build_residual_network.<locals>.<listcomp>s   sP   ø€ ð ð ð áˆAˆq�$Ø�Š6ˆ6�d—h’h˜x¨Ñ-Ô-°Ò1Ð1ð 
ˆAˆtˆà1Ð1Ð1r   T)Údataé   c              3   óP   •K  — | ] \  }}}‰|v ¯
|‰         ‰k    ¯|‰         V — Œ!d S r   r)   rF   s       €€r   ú	<genexpr>z)build_residual_network.<locals>.<genexpr>„   sR   øè è € ð 
ð 
á��1�dØ˜4ÐÐ D¨¤N°cÒ$9Ð$9ð �ŒNà$9Ð$9Ð$9Ð$9ð
ð 
r   é   )r@   r   r@   )Úis_multigraphÚnxÚNetworkXErrorÚDiGraphÚ__networkx_cache__Úadd_nodes_fromr2   r   ÚsumÚis_directedÚminr   Úhas_edgeÚadd_edgeÚgraph)	ÚGr@   ÚRÚ	edge_listrH   rI   rJ   Úrr1   s	    `      @r   r   r   P   s  øø€ ð4 	‡‚ÑÔð SÝÔÐQÑRÔRÐRå
Œ
‰Œ€AØ€AÔØ×Ò�QÑÔÐå
�‰,Œ,€Cðð ð ð ð àŸ'š' t˜'Ñ,Ô,ðñ ô €Ið  	
Ý
ð 
ð 
ð 
ð 
ð 
à'ð
ñ 
ô 
ñ 
ô 
ñ	
ð 	ð ð ð 	‡}‚}�„ð )Ø#ð 		(ð 		(‰JˆAˆq�$Ý�D—H’H˜X sÑ+Ô+¨SÑ1Ô1ˆAØ—:’:˜a Ñ#Ô#ð (ð —
’
˜1˜a¨!�
Ñ,Ô,Ð,Ø—
’
˜1˜a¨!�
Ñ,Ô,Ð,Ð,ð '(��!”�Q”˜
Ñ#Ð#ð		(ð $ð 	)ð 	)‰JˆAˆq�$å�D—H’H˜X sÑ+Ô+¨SÑ1Ô1ˆAØ�JŠJ�q˜! aˆJÑ(Ô(Ð(Ø�JŠJ�q˜! aˆJÑ(Ô(Ð(Ð(ð €A„GˆE�Nà€Hr   r^   )ÚgraphsÚpreserve_edge_attrsÚpreserve_graph_attrsc                 ób  — t          |g¦  «        }|h}| j        d         }|rŒ|                     ¦   «         }| |                              ¦   «         D ]Y\  }}|d         |k    rH||vrD||k    rt	          j        d¦  «        ‚|                     |¦  «         |                     |¦  «         ŒZ|°ŠdS dS )z*Detect an infinite-capacity s-t path in R.r1   r@   z-Infinite capacity path, flow unbounded above.N)r   r\   Úpopleftr   rR   ÚNetworkXUnboundedÚaddÚappend)	r^   ÚsÚtÚqÚseenr1   rH   rI   rJ   s	            r   r   r   £   sÏ   € õ 	ˆqˆc‰
Œ
€AØˆ3€DØ
Œ'�%Œ.€CØ
ð 	Ø�IŠI‰KŒKˆØ˜”t—z’z‘|”|ð 	ð 	‰GˆAˆtØ�JÔ 3Ò&Ð&¨1°D¨=¨=Ø˜’6�6ÝÔ.ØGñô ð ð —’˜‘”�Ø—’˜‘”�øð ð 	ð 	ð 	ð 	ð 	r   rP   )r]   r^   Úflow)ra   rb   c                 ó¸   — i }| D ]T}d„ | |         D ¦   «         ||<   ||                               d„ ||                              ¦   «         D ¦   «         ¦  «         ŒU|S )z0Build a flow dictionary from a residual network.c                 ó   — i | ]}|d “ŒS rE   r)   )rG   rI   s     r   ú
<dictcomp>z#build_flow_dict.<locals>.<dictcomp>¾   s   € Ð+Ð+Ð+ ˜˜1Ð+Ð+Ð+r   c              3   óH   K  — | ]\  }}|d          dk    ¯||d          fV — ŒdS )rm   r   Nr)   )rG   rI   rJ   s      r   rO   z"build_flow_dict.<locals>.<genexpr>¿   sF   è è € ð 
ð 
Ù") ! T¸TÀ&¼\ÈAÒ=MÐ=MˆQ��V”ÐÐ=MÐ=MÐ=MÐ=Mð
ð 
r   )Úupdater   )r]   r^   Ú	flow_dictrH   s       r   r	   r	   ¹   s„   € ð €IØð 
ð 
ˆØ+Ð+ a¨¤dÐ+Ñ+Ô+ˆ	�!‰Ø�!Œ×Òð 
ð 
Ø-.¨q¬T¯ZªZ©\¬\ð
ñ 
ô 
ñ 	
ô 	
ð 	
ð 	
ð Ðr   )r'   Úcollectionsr   ÚnetworkxrR   Ú__all__r   r   r   Ú_dispatchabler2   r   r   r	   r)   r   r   ú<module>rx      s�  ððð ð Ð Ð Ð Ð Ð à Ð Ð Ð ðð ð €ð
ð 
ð 
ð 
ð 
ñ 
ô 
ð 
ð@ð ð ð ð ñ ô ð ðð ð ð ð ñ ô ð ð& €Ô˜j¨%¨%°©,¬,Ð7ÀtÐLÑLÔLðOð Oñ MÔLðOðd €ÔØØ˜z¨5¨5°©<¬<Ð8Ð9Øðñ ô ð
ð ñô ð
ð" €Ô˜q qÐ)Ð)ÀÀfÈdÀ^Ð?TÐUÑUÔUðð ñ VÔUðð ð r   