ó
    …~i›$  ã                   ó”   • S r SSKrSSKJr  SSKJr  SSKJr  SSKr	SSK
JrJrJr  SSKJr  \rS	/r\	R$                  SS
 j5       rS rg)z0
Kanevsky all minimum node k cutsets algorithm.
é    N)Údefaultdict)Úcombinations)Ú
itemgetter)Úbuild_residual_networkÚedmonds_karpÚshortest_augmenting_pathé   )Ú!build_auxiliary_node_connectivityÚall_node_cutsc           
   #   ó:
  ^^"^##   • [         R                  " U 5      (       d  [         R                  " S5      e[         R                  " U 5      S:X  a  S Sh  v•N   g/ n[	        U 5      nUR
                  m"UR                  S   n[        R                  " UR                  5      n[        US5      nSUS.nUc  [        nU[        L a  SUS	'   Uc  [         R                  " XS
9n[        U R                  5       [        S5      SS9SU  V	V
s1 s H  u  pšU	iM	     nn	n
[!        X5      (       a  UR#                  U5        Uv •  U GHª  n[%        U 5      U1-
  [%        X   5      -
  nU GH‚  nU" XEU    S3X^    S340 UD6nUR                  S   nXñ:X  d  M/  UR'                  SS9 VVV
s/ s H  u  nnoªS   S:w  d  M  UU4PM     sn
nn=nnU VV	s1 s H  nU  H  o™iM     M     sn	n=nnUR'                  SS9 VVV
s/ s H#  u  nnn
U
S   U
S   :X  d  U
S   S:X  d  M  UUU
4PM%     nnnn
UR)                  U5        [         R*                  " U5      n[         R,                  " U5      nUR                  S   n[/        [0        5      nUR3                  5        H  u  n	nUU   R#                  U	5        M     U V	s1 s H  n	UU	   iM
     nn	[         R4                  " U5       GHP  n[%        U5      R7                  U5      (       d  M%  [%        5       m#U H  nT#R9                  UU   5        M     [%        5       nT# H!  n	UR9                  UR                  U	   5        M#     T#R9                  U5        X\    S3T#;  d  X^    S3T#;   a  M¦  [%        5       nT# H"  mUR9                  U#U4S jUT    5       5        M$     [;        U"4S jU 5       5      (       a  Mô  U VV s1 s H  u  nn T"U   S   iM     n!nn [=        U!5      U:X  d  GM#  UU!;   d  UU!;   a  GM2  U!U;  d  GM;  U!v •  UR#                  U!5        GMS     UR?                  X\    S3X^    S3SS9  UR?                  X^    S3X\    S3SS9  UR?                  X\    S3X^    S3SS9  UR?                  X^    S3X\    S3SS9  UR?                  X^    S3X\    S3SS9  UR?                  X\    S3X^    S3SS9  URA                  U5        GM…     GM­     g GN�s  sn
n	f s  sn
nnf s  sn	nf s  sn
nnf s  sn	f s  sn nf 7f)a  Returns all minimum k cutsets of an undirected graph G.

This implementation is based on Kanevsky's algorithm [1]_ for finding all
minimum-size node cut-sets of an undirected graph G; ie the set (or sets)
of nodes of cardinality equal to the node connectivity of G. Thus if
removed, would break G into two or more connected components.

Parameters
----------
G : NetworkX graph
    Undirected graph

k : Integer
    Node connectivity of the input graph. If k is None, then it is
    computed. Default value: None.

flow_func : function
    Function to perform the underlying flow computations. Default value is
    :func:`~networkx.algorithms.flow.edmonds_karp`. This function performs
    better in sparse graphs with right tailed degree distributions.
    :func:`~networkx.algorithms.flow.shortest_augmenting_path` will
    perform better in denser graphs.


Returns
-------
cuts : a generator of node cutsets
    Each node cutset has cardinality equal to the node connectivity of
    the input graph.

Examples
--------
>>> # A two-dimensional grid graph has 4 cutsets of cardinality 2
>>> G = nx.grid_2d_graph(5, 5)
>>> cutsets = list(nx.all_node_cuts(G))
>>> len(cutsets)
4
>>> all(2 == len(cutset) for cutset in cutsets)
True
>>> nx.node_connectivity(G)
2

Notes
-----
This implementation is based on the sequential algorithm for finding all
minimum-size separating vertex sets in a graph [1]_. The main idea is to
compute minimum cuts using local maximum flow computations among a set
of nodes of highest degree and all other non-adjacent nodes in the Graph.
Once we find a minimum cut, we add an edge between the high degree
node and the target node of the local maximum flow computation to make
sure that we will not find that minimum cut again.

See also
--------
node_connectivity
edmonds_karp
shortest_augmenting_path

References
----------
.. [1]  Kanevsky, A. (1993). Finding all minimum-size separating vertex
        sets in a graph. Networks 23(6), 533--541.
        http://onlinelibrary.wiley.com/doi/10.1002/net.3230230604/abstract

zInput graph is disconnected.r	   © NÚmappingÚcapacity)r   ÚresidualTÚ	two_phase)Ú	flow_func)ÚkeyÚreverseÚBÚAÚ
flow_value)ÚdataÚflowr   c              3   ó:   >#   • U  H  oT;  d  M
  TU4v •  M     g 7f)Nr   )Ú.0ÚwÚSÚus     €€Úf/home/mande/repo/quber/.venv/lib/python3.13/site-packages/networkx/algorithms/connectivity/kcutsets.pyÚ	<genexpr>Ú all_node_cuts.<locals>.<genexpr>À   s   øé € Ð%WÒ6H°ÐUVÉJ£f q¨!¥fÒ6Hùs   ƒ	�c              3   óJ   >#   • U  H  u  pTU   S    TU   S    :g  v •  M     g7f)ÚidNr   )r   r   r   ÚH_nodess      €r   r    r!   Ã   s*   øé € ÐSÊFÁDÀA˜7 1™: dÑ+¨w°q©z¸$Ñ/?Ö?ÊFùs   ƒ #r#   )r   )!ÚnxÚis_connectedÚNetworkXErrorÚdensityr
   ÚnodesÚgraphÚcopyÚ_predr   Údefault_flow_funcr   Únode_connectivityÚsortedÚdegreer   Ú_is_separating_setÚappendÚsetÚedgesÚremove_edges_fromÚtransitive_closureÚcondensationr   ÚlistÚitemsÚ
antichainsÚissubsetÚupdateÚanyÚlenÚadd_edgeÚadd_edges_from)$ÚGÚkr   ÚseenÚHr   Úoriginal_H_predÚRÚkwargsÚnÚdÚXÚxÚnon_adjacentÚvr   r   r   ÚE1Úflowed_edgesÚedgeÚVE1Úincident_nodesÚsaturated_edgesÚ	R_closureÚLÚcmapÚinv_cmapÚsccÚ	antichainÚS_ancestorsÚcutsetÚ_Únode_cutr$   r   s$                   `                 @@r   r   r      s  úé € ôF �?Š?˜1×ÑÜ×ÒÐ=Ó>Ð>ô
 
‡z‚z�!ƒ}˜ÓØ�ˆØð €Dô 	*¨!Ó,€AØ�g‰g€GØ�g‰g�iÑ €Gô —i’i §¡Ó(€OÜ˜q *Ó-€AØ$°!Ñ4€FàÑÜ%ˆ	ØÔ,Ò,Ø"ˆˆ{Ñð 	�yÜ× Ò  Ñ8ˆô ˜aŸh™h›j¬j¸«mÀTÑJÈ2ÈAÑNÔOÒN‰tˆq‹ÑN€AÑOä˜!×ÑØ�‰�AŒØŠäˆô ˜1“v  ‘|¤c¨!©$£iÑ/ˆÜˆAñ ˜!¨¡
˜|¨1Ð-°'±*°¸QÐ/?ÑJÀ6ÑJˆAØŸ™ Ñ.ˆJà�ð -.¯G©G¸¨GÑ,>õ%Ú,>™y  1 aÀFÁ)ÈqÁ.“F�Q˜“FÑ,>ó%ð ��\ñ 79Ô'G²b¨dÄ$¸QªÁ$©±bÒ'GÐG��nð &'§W¡W°$ WÑ%7õ#â%7™	˜˜A˜qØ˜‘}¨¨&©	Ó1°Q°z±]ÀaÑ5Gó �Q˜˜1“IÙ%7ð  ò #ð
 ×#Ñ# OÔ4Ü×1Ò1°!Ó4�	ô —O’O AÓ&�Ø—w‘w˜yÑ)�Ü&¤tÓ,�Ø"Ÿj™jžl‘F�A�sØ˜S‘M×(Ñ(¨Ö+ñ +ñ ),Ó,ª 1�t˜A”w©�Ð,ô "$§¢¨q×!1�Iô ˜y›>×2Ñ2°3×7Ñ7Ù ô ›�AÛ(˜ØŸ™ ¨#¡Ö/ñ  )ä"%£%�KÛ˜Ø#×*Ñ*¨9¯?©?¸1Ñ+=Ö>ñ à—H‘H˜[Ô)Ø!™*˜ QÐ'¨qÓ0°w±z°lÀ!Ð4DÈÓ4IÙ ä ›U�FÛ˜ØŸ™Õ%W°oÀaÒ6HÓ%WÖWñ ô ÔSÉFÓS×SÑSÙ Ù=CÔDºV±T°Q¸ ¨¡
¨4Ô 0¹V�HÑDä˜8“}¨Ö)ð  ›=¨A°«MÚ$Ø#¨4Ö/Ø"*šNØ ŸK™K¨×1ñI "2ðZ —
‘
˜g™j˜\¨Ð+°±
¨|¸1Ð-=È�
ÑJØ—
‘
˜g™j˜\¨Ð+°±
¨|¸1Ð-=È�
ÑJà—
‘
˜g™j˜\¨Ð+°±
¨|¸1Ð-=È�
ÑJØ—
‘
˜g™j˜\¨Ð+°±
¨|¸1Ð-=È�
ÑJØ—
‘
˜g™j˜\¨Ð+°±
¨|¸1Ð-=È�
ÑJØ—
‘
˜g™j˜\¨Ð+°±
¨|¸1Ð-=È�
ÑJð × Ñ  ×1ôq ò	 òC 	ùó6 	Pùô$%ùó (Hùô#ùò -ùó>  Eùsƒ   …ATÁS3ÁB4TÄS6ÄA8TÆTÆ(S<Æ<S<ÇTÇT
Ç%TÇ>T	È	T	È(BTÊ9TËDTÏTÏ.TÐTÐCTÓ6%Tc                 ó¢   • [        U5      [        U 5      S-
  :X  a  g[        R                  " X/ 5      n[        R                  " U5      (       a  gg)z)Assumes that the input graph is connectedr	   TF)r>   r%   Úrestricted_viewr&   )rA   ÚcutrD   s      r   r1   r1   ã   s@   € ä
ˆ3ƒx”3�q“6˜A‘:ÓØä
×Ò˜1 2Ó&€AÜ	‡‚�q×ÑØØó    )NN)Ú__doc__r+   Úcollectionsr   Ú	itertoolsr   Úoperatorr   Únetworkxr%   Únetworkx.algorithms.flowr   r   r   Úutilsr
   r-   Ú__all__Ú_dispatchabler   r1   r   ra   r   Ú<module>rk      s\   ðñó Ý #Ý "Ý ã ÷ñ õ 5à Ð ð Ð
€ð ×ÑóF2ó ðF2óRra   