+
    �°³jÕ*  ã                   ó®   € R t ^ RIHt ^ RIHt ^ RIHt ^ RIt^ RI	H
t
 ^ RIHt ]
tR.t]! R4      ]P                  RR	 l4       4       tR
 tR tR tR tR# )z,
Moody and White algorithm for k-components
)Údefaultdict)Úcombinations)Ú
itemgetterN)Úedmonds_karp)Únot_implemented_forÚk_componentsÚdirectedc           	     ó¸  € \        \        4      pVf   \        p\        P                  ! V 4       F8  p\        V4      p\        V4      ^8”  g   K   V^,          P                  V4       K:  	  \        P                  ! V 4       Uu. uF  qPP                  V4      NK  	  ppV F8  p\        V4      p\        V4      ^8”  g   K   V^,          P                  V4       K:  	  V EFF  p	\        V	4      ^8:  d   K  \        P                  ! W‘R7      p
V
^8”  d!   W*,          P                  \        V	4      4       \        \        P                  ! WšVR7      4      pV
\        W›V
4      3.pV'       g   KŽ  VR,          w  rÞ \        V4      pV	P                  V4      p\        P                  ! VVR7      pVV8”  d)   V^8”  d"   VV,          P                  \        V4      4       \        \        P                  ! VVVR7      4      pV'       d!   VP                  V\        VVV4      34       KÃ  KÅ  	  \!        V4      # u upi   \         d    TP                  4         Kõ  i ; i)a•  Returns the k-component structure of a graph G.

A `k`-component is a maximal subgraph of a graph G that has, at least,
node connectivity `k`: we need to remove at least `k` nodes to break it
into more components. `k`-components have an inherent hierarchical
structure because they are nested in terms of connectivity: a connected
graph can contain several 2-components, each of which can contain
one or more 3-components, and so forth.

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

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

Returns
-------
k_components : dict
    Dictionary with all connectivity levels `k` in the input Graph as keys
    and a list of sets of nodes that form a k-component of level `k` as
    values.

Raises
------
NetworkXNotImplemented
    If the input graph is directed.

Examples
--------
>>> # Petersen graph has 10 nodes and it is triconnected, thus all
>>> # nodes are in a single component on all three connectivity levels
>>> G = nx.petersen_graph()
>>> k_components = nx.k_components(G)
>>> sorted(k_components)
[1, 2, 3]
>>> all(comps == [set(G)] for comps in k_components.values())
True

Notes
-----
Moody and White [1]_ (appendix A) provide an algorithm for identifying
k-components in a graph, which is based on Kanevsky's algorithm [2]_
for finding all minimum-size node cut-sets of a graph (implemented in
:meth:`all_node_cuts` function):

    1. Compute node connectivity, k, of the input graph G.

    2. Identify all k-cutsets at the current level of connectivity using
       Kanevsky's algorithm.

    3. Generate new graph components based on the removal of
       these cutsets. Nodes in a cutset belong to both sides
       of the induced cut.

    4. If the graph is neither complete nor trivial, return to 1;
       else end.

This implementation also uses some heuristics (see [3]_ for details)
to speed up the computation.

See also
--------
node_connectivity
all_node_cuts
biconnected_components : special case of this function when k=2
k_edge_components : similar to this function, but uses edge-connectivity
    instead of node-connectivity

References
----------
.. [1]  Moody, J. and D. White (2003). Social cohesion and embeddedness:
        A hierarchical conception of social groups.
        American Sociological Review 68(1), 103--28.
        http://www2.asanet.org/journals/ASRFeb03MoodyWhite.pdf

.. [2]  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

.. [3]  Torrents, J. and F. Ferraro (2015). Structural Cohesion:
        Visualization and Heuristics for Fast Computation.
        https://arxiv.org/pdf/1503.04476v1

)Ú	flow_func)Úkr
   éÿÿÿÿ)r   ÚlistÚdefault_flow_funcÚnxÚconnected_componentsÚsetÚlenÚappendÚbiconnected_componentsÚsubgraphÚnode_connectivityÚall_node_cutsÚ_generate_partitionÚnextÚStopIterationÚpopÚ_reconstruct_k_components)ÚGr
   r   Ú	componentÚcompÚcÚbicomponentsÚbicomponentÚbicompÚBr   ÚcutsÚstackÚparent_kÚ	partitionÚnodesÚCÚthis_ks   &&                Úm/home/luca/screen-checking/.venv/lib/python3.14/site-packages/networkx/algorithms/connectivity/kcomponents.pyr   r      sî  € ô| œtÓ$€LàÒÜ%ˆ	ä×,Ò,¨QÖ/ˆ	ä�9‹~ˆÜˆt‹9�qŽ=Ø˜�O×"Ñ" 4Ö(ñ	 0ô
 ,.×+DÒ+DÀQÔ+GÓHÑ+G a—J‘J˜q–MÑ+G€LÐHÛ#ˆÜ�[Ó!ˆäˆv‹;˜Ž?Ø˜�O×"Ñ" 6Ö*ñ	 $ô
 ˆÜˆq‹6�QŒ;ÙÜ× Ò  Ô8ˆØˆqŒ5Ø�O×"Ñ"¤3 q£6Ô*ä”B×$Ò$ Q°yÔAÓBˆØÔ(¨°!Ó4Ð5Ð6ˆß‰eØ$)¨"¥IÑ!ˆXð
Ü˜Y›�Ø—J‘J˜uÓ%�Ü×-Ò-¨a¸9ÔE�Ø˜HÔ$¨°!¬Ø  Õ(×/Ñ/´°A³Ô7ÜœB×,Ò,¨Q°&ÀIÔNÓO�ßØ—L‘L &Ô*=¸aÀÀvÓ*NÐ!OÖPñ ñ% ô< % \Ó2Ð2ùòI Iøô4 !ô Ø—	‘	—ðús   ÂH5Å9B+H:È:IÉIc              #  óp  aa"  € \         P                  ! 4       p\        \        V 4      4      oVP	                  S4       VP                  VV3R l\        S^4       4       4       \         P                  ! V4       F0  p\        P                  ! V Uu. uF  pSV,          NK  	  up!  x € K2  	  R# u upi 5i)aW  Merge sets that share k or more elements.

See: http://rosettacode.org/wiki/Set_consolidation

The iterative python implementation posted there is
faster than this because of the overhead of building a
Graph and calling nx.connected_components, but it's not
clear for us if we can use it in NetworkX because there
is no licence for the code.

c              3   ó|   <"  € T F1  w  r\        SV,          SV,          ,          4      S8¼  g   K,  W3x € K3  	  R # 5i©N©r   )Ú.0ÚuÚvr   r)   s   &  €€r,   Ú	<genexpr>Ú_consolidate.<locals>.<genexpr>²   s5   øé € ð Ù1‘4�1´S¸¸q½ÀEÈ!ÅHÕ9LÓ5MÐQRÑ5RŒˆ�Ó1ùs   ƒ)<±<N)
r   ÚGraphÚdictÚ	enumerateÚadd_nodes_fromÚadd_edges_fromr   r   r   Úunion)Úsetsr   r   r   Únr)   s   &f   @r,   Ú_consolidater>   £   s�   ùé € ô 	�Š‹
€AÜ”˜4“Ó!€EØ×Ñ�UÔØ×Ñõ Ü'¨¨qÔ1óô ô ×,Ò,¨QÖ/ˆ	Ü�iŠi©IÓ6©I q˜% Ÿ(˜(©IÑ6Ñ7Ô7ó 0ùÚ6ùs   „BB6ÂB1
Â$B6c              #  ó  aa"  € V P                  4       oV Uu. uF  p\        V4      NK  	  pp. p\        4       p\        V 4      .pV'       Ed=   VP                  4       pV Fÿ  pW78  g   K  \        \        P
                  ! V P                  Ws,
          4      4      4      p\        V4      ^8”  g   KQ  V F¦  o\        SV U	u0 uFS  p	\        ;QJ d%    V3R lW	,           4       F  '       g   K   RM	  RM! V3R lW	,           4       4      '       g   KQ  V	kKU  	  up	,          4      p
W¥9  g   K{  VP                  V
4       VP                  \        V
4      4       K¨  	   EK  	  \        V4      S8  g   EK1  VP                  V4       EKE  \        \        WB^,           4      4      p\        ;QJ d    V3R lV 4       F  '       g   K   RM	  RM! V3R lV 4       4      '       d   T Rj  x€L
  R# T Rj  x€L
  R# u upi u up	i  L L5i)a£  Generate parts of G induced by its minimum-size node cutsets.

Following Moody and White (appendix A, step 3), cutsets are applied
one at a time: removing a cutset splits the current set of nodes into
two or more connected components, and each component plus the cutset
that induced it becomes a new candidate part. Every j-component of
``G`` with ``j > k`` is preserved intact in at least one generated
part, because removing ``k < j`` nodes cannot disconnect it.

Applying cutsets one at a time is necessary for correctness: removing
the union of all cutsets in a single pass can drop cutset nodes whose
neighbors all belong to other cutsets, silently losing k-components.
c              3   ó,   <"  € T F	  qS9   x € K  	  R # 5ir/   © )r1   r3   r   s   & €r,   r4   Ú&_generate_partition.<locals>.<genexpr>Û   s   øé € Ð0NÉÀA°i¶Ëùs   ƒTFc              3   ó@   <"  € T F  p\        V4      S8H  x € K  	  R # 5ir/   r0   )r1   ÚpartÚorders   & €r,   r4   rB   ì   s   øé € Ð
7©, $Œ3ˆt‹9˜Ö«,ùs   ƒN)rE   r   r   r   r   r   r   r   Ú	frozensetÚanyÚaddr   r>   )r   r%   r   ÚcutÚpartsÚseenr&   r)   Ú
componentsr=   ÚchildÚconsolidatedr   rE   s   &&&         @@r,   r   r   ¹   s‚  ùé € ð �G‰G‹I€EÙ $Ó%¡˜ŒC�ŽH¡€DÐ%Ø€EÜ‹5€DÜ�‹VˆH€Eß
ˆ%Ø—	‘	“ˆÛˆCØ”;ÙÜœb×5Ò5°a·j±jÀÅÓ6MÓNÓOˆJÜ�:‹ Ö"Û!+�Iô &Ø!Ù&)ÓO¡c ¯S«SÔ0NÈÎÓ0N¯S¯SªSÔ0NÈÎÓ0N×-NŸ1˜1¡cÑOõPó�Eð Ö(ØŸ™ œØŸ™¤S¨£ZÖ0ñ ",ó ñ% ô* �5‹z˜E×!Ø—‘˜U×#ô œ U°­EÓ2Ó3€Lß
ƒsÔ
7©,Ó
7‡s‡s‚sÔ
7©,Ó
7×7Ò7Ø×Òà×ÒùòO &ùò& Pñ$ 	áùsr   „H™G?­"HÁAHÂ3HÃHÃHÃ/!HÄHÄHÄ0AHÅ8AHÇ	HÇ'HÇ,H	Ç-HÇ8HÇ9HÈHc           	      ó   a€ / pV '       d   \        V 4      M^ p\        V^ R4       EFY  pW28X  d   \        \        W,          V4      4      pMÜW09  d$   \        \        W^,           ,          V4      4      pM³W^,           ,           Uau. uFS  o\        ;QJ d%    V3R lW,           4       F  '       g   K   RM	  RM! V3R lW,           4       4      '       d   KQ  SNKU  	  ppV'       d$   \        \        W,          V,           V4      4      pM\        \        W,          V4      4      pV Uau. uFG  o\        ;QJ d    V3R lV 4       F  '       g   K   RM	  RM! V3R lV 4       4      '       d   KE  SNKI  	  upW&   EK\  	  V# u upi u upi )é    c              3   ó.   <"  € T F
  pSV8*  x € K  	  R # 5ir/   rA   )r1   r   r    s   & €r,   r4   Ú,_reconstruct_k_components.<locals>.<genexpr>  s   øé € Ð3UÉ*À$°A¸¶IË*ùó   ƒTFc              3   ó.   <"  € T F
  pSV8  x € K  	  R # 5ir/   rA   )r1   Údr    s   & €r,   r4   rR     s   øé € Ð0FÁ¸1°°Q¶ÃùrS   r   )ÚmaxÚranger   r>   rG   )Úk_compsÚresultÚmax_kr   Úcompsr    Úto_adds   &    ` r,   r   r   ò   s  ø€ Ø€Fß#ŒC�ŒL¨€EÜ�5˜!˜R× ˆØŒ:Üœ g¥j°!Ó4Ó5‰EØÔÜœ f°­U¥m°QÓ7Ó8‰Eð " a¥%ž=ôÙ(�a·³Ô3UÈ'Î*Ó3U··²Ô3UÈ'Î*Ó3U×0U—�™=ð ð ÷ Üœ\¨'­*°vÕ*=¸qÓAÓB‘äœ\¨'­*°aÓ8Ó9�ñ
 !&ÔG¡˜1¯S«SÔ0FÁÓ0F¯S¯SªSÔ0FÁÓ0F×-F—Q�Q¡ÑGˆŒ	ñ/ !ð0 €Mùòùò Hs0   ÂFÂFÂ4!FÃFÄ-FÄ=FÅFÅ4Fc           
      ó®   € \        V P                  4       \        ^ 4      R7       UUUUu/ uF  w  rV F  pV F  pWAbK  	  K  	  K  	  upppp# u uppppi )rP   )Úkey)ÚsortedÚitemsr   )Úkcompsr   r[   r   Únodes   &    r,   Úbuild_k_number_dictrc     sZ   € ô ˜vŸ|™|›~´:¸a³=ÕAöáA‰HˆAÛˆDÛˆDð 	Šñ ñ 	áñ 	ÙAôð ùõ s   ªA
r/   )Ú__doc__Úcollectionsr   Ú	itertoolsr   Úoperatorr   Únetworkxr   Únetworkx.algorithms.flowr   Únetworkx.utilsr   r   Ú__all__Ú_dispatchabler   r>   r   r   rc   rA   ó    r,   Ú<module>rn      sm   ðñõ $Ý "Ý ã õ 2Ý .à Ð àÐ
€ñ �ZÓ Ø×ÑóJ3ó ó !ðJ3òZ8ò,6 òrô<rm   