+
    )i                         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                  ! WR7      p
V
^8  d!   W*,          P                  \        V	4      4       \        \        P                  ! WVR7      4      pV
\        WV
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)

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   &&                j/var/www/html/photoedit/myenv/lib/python3.14/site-packages/networkx/algorithms/connectivity/kcomponents.pyr   r      s   t t$L%	,,Q/	9~t9q=O""4(	 0
 ,.+D+DQ+GH+GaJJqM+GLH#[!v;?O""6*	 $
 q6Q;  8q5O""3q6*B$$QyAB(!456e$)"I!X
YJJu%--a9EH$! (//A7B,,Q&INOLL&*=av*N!OP % < %\22I 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      141SqE!H9L5MQR5R1s   )<<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/	iiI6Iq%((I677 06s   BB6B1
$B6c           
   #   6  "   R  p. pV UUu0 uF  qU F  qfkK  	  K  	  pppV P                  4        UUu0 uF  w  rhW8  g   K  VkK  	  uppV,
          p	V P                  V	4      p
\        \        \        P
                  ! V
4      4       F\  pY Uu0 uF  qc! WV4      '       g   K  VkK  	  up,          p\        V4      V P                  4       8  g   KK  VP                  V4       K^  	  \        WB^,           4       Rj  xL
  R# u uppi u uppi u upi  L5i)c                    a \         ;QJ d%    V3R  lW,           4       F  '       g   K   R# 	  R# ! V3R  lW,           4       4      # )c              3   ,   <"   T F	  qS9   x  K  	  R # 5ir/    )r0   r<   r(   s   & r,   r3   E_generate_partition.<locals>.has_nbrs_in_partition.<locals>.<genexpr>   s     37a	>7   TF)any)r   noder(   s   &&fr,   has_nbrs_in_partition2_generate_partition.<locals>.has_nbrs_in_partition   s0    s3173ss3s3s317333    N)
degreer   mapr   r   r   r   orderr   r=   )r   r%   r   rF   
componentscutr<   	n_in_cutsdr)   Hccr   s   &&&          r,   r   r      s     4 J"0dsCqCdI088:/:41QQ:/);E	

5A#r..q12YRY2Gb2Q!!YRR	y>AGGI%i( 3 JA... 1/ S /sE   DDD
DD
ADD&D,$D*D?D Dc                   a / pV '       d   \        V 4      M^ p\        V^ R4       EF  pW28X  d    \        \        W,          V4      4      W&   K)  W09  d'   \        \        W^,           ,          V4      4      W&   KU  \        P
                  ! W,          !  oW^,           ,           Uu. uFG  p\        ;QJ d    V3R lV 4       F  '       g   K   RM	  RM! V3R lV 4       4      '       g   KE  VNKI  	  ppV'       d'   \        \        W,          V,           V4      4      W&   K  \        \        W,          V4      4      W&   EK  	  V# u upi )    c              3   ,   <"   T F	  qS9  x  K  	  R # 5ir/   rA   )r0   r<   
nodes_at_ks   & r,   r3   ,_reconstruct_k_components.<locals>.<genexpr>   s     5USTaz6ISTrC   TFr   )maxranger   r=   r   r:   rD   )k_compsresultmax_kr   r    to_addrU   s   &     @r,   r   r      s    F#CLE5!R :\'*a89FI\&Q-;<FIGJ/J!'AVA##5UST5U###5UST5U2UaaFV gj6.A1!EF	 gj!!<=	 ! M Ws   &E6EE-E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 )rS   )key)sorteditemsr   )kcompsr   compsr   rE   s   &    r,   build_k_number_dictrc      sZ     v||~:a=AAHADD 	  	 	A  s   A
r/   )__doc__collectionsr   	itertoolsr   operatorr   networkxr   networkx.algorithms.flowr   networkx.utilsr   r   __all___dispatchabler   r=   r   r   rc   rA   rH   r,   <module>rm      sl    $ "   2 .  
 Z F3  !F3R8,/$rH   