
    h                         S SK r S SKrSS/r\R                  " SS9SS.S j5       r\R                  " SS9SS.S j5       rg)	    Nedge_betweenness_partition'edge_current_flow_betweenness_partitionweight)
edge_attrsr   c                B   US::  a  [         R                  " S5      eUS:X  a  [        U 5      /$ U[        U 5      :X  a  U  Vs/ s H  o31PM     sn$ U[        U 5      :  a  [         R                  " S5      eU R	                  5       n[        [         R                  " U5      5      n[        U5      U:  af  [         R                  " XBS9n[        XfR                  S9nUR                  " U6   [        [         R                  " U5      5      n[        U5      U:  a  Mf  U$ s  snf )an  Partition created by iteratively removing the highest edge betweenness edge.

This algorithm works by calculating the edge betweenness for all
edges and removing the edge with the highest value. It is then
determined whether the graph has been broken into at least
`number_of_sets` connected components.
If not the process is repeated.

Parameters
----------
G : NetworkX Graph, DiGraph or MultiGraph
  Graph to be partitioned

number_of_sets : int
  Number of sets in the desired partition of the graph

weight : key, optional, default=None
  The key to use if using weights for edge betweenness calculation

Returns
-------
C : list of sets
  Partition of the nodes of G

Raises
------
NetworkXError
  If number_of_sets is <= 0 or if number_of_sets > len(G)

Examples
--------
>>> G = nx.karate_club_graph()
>>> part = nx.community.edge_betweenness_partition(G, 2)
>>> {0, 1, 3, 4, 5, 6, 7, 10, 11, 12, 13, 16, 17, 19, 21} in part
True
>>> {
...     2,
...     8,
...     9,
...     14,
...     15,
...     18,
...     20,
...     22,
...     23,
...     24,
...     25,
...     26,
...     27,
...     28,
...     29,
...     30,
...     31,
...     32,
...     33,
... } in part
True

See Also
--------
edge_current_flow_betweenness_partition

Notes
-----
This algorithm is fairly slow, as both the calculation of connected
components and edge betweenness relies on all pairs shortest
path algorithms. They could potentially be combined to cut down
on overall computation time.

References
----------
.. [1] Santo Fortunato 'Community Detection in Graphs' Physical Reports
   Volume 486, Issue 3-5 p. 75-174
   http://arxiv.org/abs/0906.0612
r   number_of_sets must be >0    number_of_sets must be <= len(G)r   key)nxNetworkXErrorsetlencopylistconnected_componentsedge_betweenness_centralitymaxgetremove_edge)Gnumber_of_setsr   nH	partitionrankingedges           X/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/community/divisive.pyr   r      s    Z :;;AxQQQAABB	AR,,Q/0I
i.>
)00B7,	t0034		 i.>
)
   s   Dc                N   US::  a  [         R                  " S5      eUS:X  a  [        U 5      /$ U[        U 5      :X  a  U  Vs/ s H  o31PM     sn$ U[        U 5      :  a  [         R                  " S5      e[        R
                  " [         R                  SUS9nU R                  5       n[        [         R                  " U5      5      n[        U5      S:  a/  U Vs/ s H!  ouR                  U5      R                  5       PM#     nnOU/n0 n	U H  n
U	R                  U" U
5      5        M     [        U5      U:  Ga_  [        XR                  S9n[        Xh5       GH*  u  pzUS   U;   d  M  U
R                  " U6   X	 [        [         R                  " U
5      5      n[        U5      S:  a  [!        U[        S9nU
R                  U5      R                  5       nU" U5      nUR#                  5        H  u  nnUU	UU	;   a  UOUSSS	2   '   M     UR%                  U5        UR%                  U5        U
R'                  U5        UR)                  U5        U" U
5      nUR#                  5        H  u  nnUU	UU	;   a  UOUSSS	2   '   M       O   [        U5      U:  a  GM_  U$ s  snf s  snf )
ay  Partition created by removing the highest edge current flow betweenness edge.

This algorithm works by calculating the edge current flow
betweenness for all edges and removing the edge with the
highest value. It is then determined whether the graph has
been broken into at least `number_of_sets` connected
components. If not the process is repeated.

Parameters
----------
G : NetworkX Graph, DiGraph or MultiGraph
  Graph to be partitioned

number_of_sets : int
  Number of sets in the desired partition of the graph

weight : key, optional (default=None)
  The edge attribute key to use as weights for
  edge current flow betweenness calculations

Returns
-------
C : list of sets
  Partition of G

Raises
------
NetworkXError
  If number_of_sets is <= 0 or number_of_sets > len(G)

Examples
--------
>>> G = nx.karate_club_graph()
>>> part = nx.community.edge_current_flow_betweenness_partition(G, 2)
>>> {0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 16, 17, 19, 21} in part
True
>>> {8, 14, 15, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33} in part
True


See Also
--------
edge_betweenness_partition

Notes
-----
This algorithm is extremely slow, as the recalculation of the edge
current flow betweenness is extremely slow.

References
----------
.. [1] Santo Fortunato 'Community Detection in Graphs' Physical Reports
   Volume 486, Issue 3-5 p. 75-174
   http://arxiv.org/abs/0906.0612
r   r	   r
   r   F)
normalizedr   r   N)r   r   r   r   	functoolspartial(edge_current_flow_betweenness_centralityr   r   r   subgraphupdater   r   zipr   minitemsappendremove_nodes_fromdifference_update)r   r   r   r   rankr   r   ccHcc_subgraphsr   Hccr   splitcc_listcc_newHcc_newnewranksers                     r    r   r   k   sf   r :;;	1	Ax	3q6	!QQ	#a&	 ABB
33fD
 	
AR,,Q/0I
9~9BC2B,,.CGtCy!  i.>
)7,94GBAw"}&M#B$;$;C$@A|$q( 37F!ll62779G#G}H ( 01BCQ'\q2w? !1 $$V,!((1 ))&1((09$NN,DAq>?GgA1TrT7; -1 5 i.>
)6 _   Ds   J(J")r$   networkxr   __all___dispatchabler   r        r    <module>r>      sc      !- X&<@ \ '\~ X&IM l 'lr=   