+
    �°³j³  ã                   óž   € R t ^ RIHt ^ RIHt ^ RIHt ^ RIt^ RI	H
t
 R.tRtRtRt^tR	tR
tR t]P&                  ! RRR7      RR l4       tR# )z=Lukes Algorithm for exact optimal weighted tree partitioning.)Údeepcopy)Ú	lru_cache)ÚchoiceN)Únot_implemented_forÚlukes_partitioningÚweightg      ð?Ú
partitionsi   c              #   óh   "  € W8¼  g   Q h\        W^,           4       F  pW V,
          3x € K  	  R# 5i)é   N)Úrange)ÚnÚmin_size_of_first_partÚp1s   && Úd/home/luca/screen-checking/.venv/lib/python3.14/site-packages/networkx/algorithms/community/lukes.pyÚ_split_n_fromr      s3   é € ð Ô&Ð&Ð&ÜÐ*°­EÖ2ˆØ�b•&ˆjÔó 3ùs   ‚02Únode_weightÚedge_weight)Ú
node_attrsÚ
edge_attrsc           
     ój
  aaa!a"a#a$a%a&€ \         P                  ! V 4      '       g   \         P                  ! R4      h\         P                  ! V 4      '       dT   V P	                  4        UUu. uF  w  rEV^ 8X  g   K  VNK  	  ppp\        V4      ^8X  g   Q hV^ ,          p\        V 4      pM4\        \        V P                  4      4      p\         P                  ! W4      pSe   Sfa   \        V 4      o&Sf'   \         P                  ! S&\        \        4       \        oSf'   \         P                  ! S&\        \         4       \         oMV o&\         P"                  ! S&S4      P%                  4       pV F(  p	\'        V	\(        4      '       d   K  \+        RS R24      h	  \-        R4      R 4       o!\-        R4      V!3R l4       p
\/        \0        4      VV&3R l4       o#V#3R	 lo$\/        \0        4      VV&3R
 l4       o%R o"V"V$V%3R lp\3        S!! V4      4      pV F}  p/ VP                  V,          \4        &   S&P                  V,          S,          pV0.VP                  V,          \4        ,          V&   V0.VP                  V,          \4        ,          ^ &   K  	  VP                   U	u. uF  q™V9  g   K  V	NK  	  up	 FZ  p/ VP                  V,          \4        &   S&P                  V,          S,          pV0.VP                  V,          \4        ,          V&   K\  	  \         P6                  ! V4        V
! V4      pS&P                  V,          S,          p^ pRp/ p\         P8                  ! VV4      pV EFS  p\;        VV^,           4       Fê  p\=        VV4       F×  w  ppVVP                  V,          \4        ,          9  g$   VVP                  V,          \4        ,          9  d   KN  VP                  V,          \4        ,          V,          pVP                  V,          \4        ,          V,          pV! VVVVV4      w  ppVV9  g   VV,          ^,          V8  d   VV3VV&   VV8:  g   KÓ  TpTpKÙ  	  Kì  	  VP?                  4        F*  w  pw  pp VVP                  V,          \4        ,          V&   K,  	  VPA                  4        EKV  	  VVP                  V,          \4        ,          ^ &   VPC                  V4       VV8X  g   EKÖ  VP                  V,          \4        ,          ^ ,          # u uppi u up	i )u�  Optimal partitioning of a weighted tree using the Lukes algorithm.

This algorithm partitions a connected, acyclic graph featuring integer
node weights and float edge weights. The resulting clusters are such
that the total weight of the nodes in each cluster does not exceed
max_size and that the weight of the edges that are cut by the partition
is minimum. The algorithm is based on [1]_.

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

max_size : int
    Maximum weight a partition can have in terms of sum of
    node_weight for all nodes in the partition

edge_weight : key
    Edge data key to use as weight. If None, the weights are all
    set to one.

node_weight : key
    Node data key to use as weight. If None, the weights are all
    set to one. The data must be int.

Returns
-------
partition : list
    A list of sets of nodes representing the clusters of the
    partition.

Raises
------
NotATree
    If G is not a tree.
TypeError
    If any of the values of node_weight is not int.

References
----------
.. [1] Lukes, J. A. (1974).
   "Efficient Algorithm for the Partitioning of Trees."
   IBM Journal of Research and Development, 18(3), 217â€“224.

z&lukes_partitioning works only on treesNz9lukes_partitioning needs integer values for node_weight (Ú)Ú
undirectedc              3   óx   "  € V P                    F%  p\        P                  ! W4      '       d   K!  Vx € K'  	  R # 5i©N)ÚnodesÚnxÚdescendants)ÚgrÚxs   & r   Ú_leavesÚ#lukes_partitioning.<locals>._leavesv   s)   é € ð —”ˆAÜ—>’> "×(Ô(Ø”ó ùs   ‚):°
:c                 óJ  <a€ \        S! V 4      4      o\        V P                  4      S,
           Fo  p\        ;QJ d3    V3R  l\        P                  ! W4       4       F  '       d   K   RM(	  RM$! V3R  l\        P                  ! W4       4       4      '       g   Km  Vu # 	  R# )c              3   ó,   <"  € T F	  qS9   x € K  	  R # 5ir   © )Ú.0r   Útleavess   & €r   Ú	<genexpr>ÚGlukes_partitioning.<locals>._a_parent_of_leaves_only.<locals>.<genexpr>�   s   øé € Ð?Ñ)> A˜–<Ó)>ùs   ƒFTN)Úsetr   Úallr   r   )r   r   r%   r   s   & @€r   Ú_a_parent_of_leaves_onlyÚ4lukes_partitioning.<locals>._a_parent_of_leaves_only}   sc   ù€ ä‘g˜b“kÓ"ˆÜ�R—X‘X“ ×(Ð(ˆAß‹sÔ?¬¯ª¸Ô)>Ó?�s�sŠsÔ?¬¯ª¸Ô)>Ó?×?Ô?Ø’ó )ó    c                 ó®   <€ SP                    Uu. uF$  q^ ,          V 9   g   K  V^,          V 9   g   K"  VNK&  	  pp\        VV3R lV 4       4      # u upi )é    c              3   óX   <"  € T F  pSP                   V,          S,          x € K!  	  R # 5ir   )Úedges)r$   Úer   Úsafe_Gs   & €€r   r&   Ú@lukes_partitioning.<locals>._value_of_cluster.<locals>.<genexpr>‡   s!   øé € ÐE¹°A�6—<‘< •? ;×/Ò/»ùó   ƒ'*)r0   Úsum)Úclusterr1   Úvalid_edgesr   r2   s   &  €€r   Ú_value_of_clusterÚ-lukes_partitioning.<locals>._value_of_cluster„   sH   ø€ à"(§,¢,ÓV¡,˜Q°Aµ$¸'±/”qÀaÈÅdÈgÁo—q�q¡,ˆÐVÜÕE¹ÓEÓEÐEùò Ws   �A¤A´Ac                 ó.   <€ \        V3R  lV  4       4      # )c              3   óF   <"  € T F  pS! \        V4      4      x € K  	  R # 5ir   )Ú	frozenset)r$   Úcr8   s   & €r   r&   ÚBlukes_partitioning.<locals>._value_of_partition.<locals>.<genexpr>Š   s   øé € ÐF¹I°qÑ$¤Y¨q£\×2Ð2»Iùs   ƒ!©r5   )Ú	partitionr8   s   &€r   Ú_value_of_partitionÚ/lukes_partitioning.<locals>._value_of_partition‰   s   ø€ ÜÔF¹IÓFÓFÐFr,   c                 ó0   <€ \        VV3R  lV  4       4      # )c              3   óX   <"  € T F  pSP                   V,          S,          x € K!  	  R # 5ir   )r   )r$   r   r   r2   s   & €€r   r&   ÚAlukes_partitioning.<locals>._weight_of_cluster.<locals>.<genexpr>Ž   s!   øé € ÐA¹°A�6—<‘< •? ;×/Ò/»ùr4   r?   )r6   r   r2   s   &€€r   Ú_weight_of_clusterÚ.lukes_partitioning.<locals>._weight_of_clusterŒ   s   ø€ äÕA¹ÓAÓAÐAr,   c                 ót   € V  Uu. uF  q!V9   g   K  VNK  	  pp\        V4      ^8X  g   Q hV^ ,          # u upi )r
   )Úlen)r@   Únoder=   Úccxs   &&  r   Ú_pivotÚ"lukes_partitioning.<locals>._pivot�   s:   € Ù#Ó1™)�Q¨q¡y�qˆq™)ˆÐ1Ü�3‹x˜1Œ}Ðˆ}Ø�1�vˆùò 2s   …5’5c                 ó4  <a
a€ S! W4      oS! W4      o
SP                  S
4      pS! \        V4      4      V8:  dN   \        \        V3R  lV 4      4      p\        \        V
3R lV4      4      pV.V,           V,           pVS! V4      3# W,           p	V	S! V	4      3# )c                 ó   <€ V S8g  # r   r#   )r   rK   s   &€r   Ú<lambda>ÚClukes_partitioning.<locals>._concatenate_or_merge.<locals>.<lambda>�   ó	   ø€ ¨¨Sªr,   c                 ó   <€ V S8g  # r   r#   )r   Úccis   &€r   rP   rQ   ž   rR   r,   )Úunionr<   ÚlistÚfilter)Úpartition_1Úpartition_2r   ÚiÚ
ref_weightÚ	merged_xiÚcp1Úcp2Úoption_2Úoption_1rT   rK   rL   rA   rF   s   &&&&&     @@€€€r   Ú_concatenate_or_mergeÚ1lukes_partitioning.<locals>._concatenate_or_merge•   s—   ú€ Ù�[Ó$ˆÙ�[Ó$ˆØ—I‘I˜c“Nˆ	ñ œi¨	Ó2Ó3°zÔAÜ”vÔ0°+Ó>Ó?ˆCÜ”vÔ0°+Ó>Ó?ˆCà!�{ SÕ(¨3Õ.ˆHØÑ0°Ó:Ð:Ð:à"Õ0ˆHØÑ0°Ó:Ð:Ð:r,   )"r   Úis_treeÚNotATreeÚis_directedÚ	in_degreerI   r   r   rV   r   Údfs_treeÚset_edge_attributesÚD_EDGE_VALUEÚD_EDGE_WÚset_node_attributesÚD_NODE_VALUEÚD_NODE_WÚget_node_attributesÚvaluesÚ
isinstanceÚintÚ	TypeErrorr   r   ÚCLUSTER_EVAL_CACHE_SIZEr(   ÚPKEYÚ_clear_cacher   r   r   ÚitemsÚclearÚremove_nodes_from)'ÚGÚmax_sizer   r   r   ÚdÚrootÚt_GÚ
all_n_attrr   r*   ra   ÚleavesÚlvÚslotÚinnerÚx_nodeÚweight_of_xÚ
best_valueÚbest_partitionÚ	bp_bufferÚx_descendantsÚi_nodeÚjÚaÚbÚpart1Úpart2ÚpartÚvalueÚwÚbest_part_for_vlÚvlr   rL   r8   rA   rF   r2   s'   &&ff                             @@@@@@r   r   r      s_  ÿ€ ô^ �:Š:�a�=Š=Ü�kŠkÐBÓCÐCä�>Š>˜!×ÒØ"#§+¡+¤-Ô:¡-™$˜!°1¸±6—A�A¡-ˆDÑ:Ü�t“9 ”>Ð!�>Ø˜•7ˆDÜ˜1“+‰Cäœ$˜qŸw™w›-Ó(ˆDä—+’+˜aÓ&ˆCð Ò˜kÒ1Ü˜!“ˆØÒÜ×"Ò" 6¬<¼ÔBÜ"ˆKØÒÜ×"Ò" 6¬<¼ÔBÜ"ˆKøàˆô ×'Ò'¨°Ó<×CÑCÓE€JÛˆÜ˜!œS×!Ô!Üð+Ø+6¨-°qð:óð ñ ô ˜Ó&ñó 'ðô
 ˜Ó&ôó 'ðô Ô&Ó'õFó (ðFõGô Ô&Ó'õBó (ðBò÷
;ô$ ‘˜“Ó€FÛˆØ ˆ�	‰	�"�”dÑØ�|‰|˜BÕ Õ,ˆØ&( T Fˆ�	‰	�"�”dÕ˜DÑ!Ø#% $ ˆ�	‰	�"�”dÕ˜AÓñ	 ð !ŸYšYÓ:™Y˜°6©/—!�!™YÔ:ˆØ!#ˆ�	‰	�%ÕœÑØ�|‰|˜EÕ" ;Õ/ˆØ).¨ yˆ�	‰	�%ÕœÕ˜tÓ$ñ ;ô ‡O‚O�CÔð Ù)¨#Ó.ˆØ—l‘l 6Õ*¨;Õ7ˆØˆ
ØˆØˆ	ÜŸš s¨FÓ3ˆÜ#ˆFÜ˜;¨°1­Ö5�Ü)¨!¨[Ö9‘D�A�qà §¡¨6Õ!2´4Õ!8Ô8Ø C§I¡I¨fÕ$5´dÕ$;Ô;ñ !àŸI™I fÕ-¬dÕ3°AÕ6�EØŸI™I fÕ-¬dÕ3°AÕ6�EÙ"7¸¸uÀfÈfÐVWÓ"X‘K�D˜%à 	Ô)¨Y°q­\¸!­_¸uÔ-Dà'+¨U {˜	 !™ð " UÖ*Ø%*˜
Ø)-šó' :ñ 6ð4 .7¯_©_Ö->Ñ)�Ñ)Ð$ bØ-=�—	‘	˜&Õ!¤$Õ'¨Ó*ñ .?à�O‰O×ñ; $ðB &4ˆ�	‰	�&Õœ$Õ Ñ"Ø×Ñ˜mÔ,à�T�>ð —9‘9˜T•?¤4Õ(¨Õ+Ð+ùói ;ùò~ ;s   Á*T*Á:T*Ê%T0Ê2T0)NN)Ú__doc__Úcopyr   Ú	functoolsr   Úrandomr   Únetworkxr   Únetworkx.utilsr   Ú__all__rj   ri   rm   rl   rt   rs   r   Ú_dispatchabler   r#   r,   r   Ú<module>rœ      sg   ðÙ Cå Ý Ý ã Ý .àÐ
 €à€Ø€Ø€Ø€Ø€ØÐ òð ×Ò˜]°}ÔEóF,ó FòF,r,   