ó
    …~i#†  ã                   ó  • S r SSKrSSKJrJr  SSKJr  SSKJr  SSK	r
SSKJr  SSKJrJr  / S	QrS
S1rSSSS.r\" S5      r\" S5      S.S j5       rS rS r\
R0                  " SS0S9S/S j5       r\" S5      \
R0                  " SS0SS9S0S j5       5       r\
R0                  " SSS9    S1S j5       r\
R0                  " SSSS9 S1S  j5       r\
R0                  " SSSS9SSSSS!.S" j5       r\
R0                  " SSSS9 S1S# j5       r\
R0                  " SSSS9 S1S$ j5       rS%r \ S&-   r!\ RE                  S'SS(9\l         \ RE                  S)SS(9S*-   \l         \!RE                  S'S+S(9\l         \!RE                  S)S+S(9\l          " S, S-5      r#g)2uö   
Algorithms for finding optimum branchings and spanning arborescences.

This implementation is based on:

    J. Edmonds, Optimum branchings, J. Res. Natl. Bur. Standards 71B (1967),
    233â€“240. URL: http://archive.org/details/jresv71Bn4p233

é    N)Ú	dataclassÚfield)Ú
itemgetter)ÚPriorityQueue)Úpy_random_stateé   )Úis_arborescenceÚis_branching)Úbranching_weightÚgreedy_branchingÚmaximum_branchingÚminimum_branchingÚminimal_branchingÚmaximum_spanning_arborescenceÚminimum_spanning_arborescenceÚArborescenceIteratorÚmaxÚminÚ	branchingÚarborescence)r   r   úspanning arborescenceÚinfc                 óš   • SR                  [        U 5       Vs/ s H!  o!R                  [        R                  5      PM#     sn5      $ s  snf )NÚ )ÚjoinÚrangeÚchoiceÚstringÚascii_letters)ÚLÚseedÚns      Ú`/home/mande/repo/quber/.venv/lib/python3.13/site-packages/networkx/algorithms/tree/branchings.pyÚrandom_stringr$   >   s4   € à�7‰7¼uÀQ¼xÓHºx¸!—K‘K¤× 4Ñ 4Ö5¹xÑHÓIÐIùÒHs   ™(Ac                 ó   • U * $ ©N© ©Úweights    r#   Ú_min_weightr*   C   s	   € Øˆ7€Nó    c                 ó   • U $ r&   r'   r(   s    r#   Ú_max_weightr-   G   s   € Ø€Mr+   ÚattrÚdefault)Ú
edge_attrsr)   c                 óL   ^^• [        UU4S jU R                  SS9 5       5      $ )aœ  
Returns the total weight of a branching.

You must access this function through the networkx.algorithms.tree module.

Parameters
----------
G : DiGraph
    The directed graph.
attr : str
    The attribute to use as weights. If None, then each edge will be
    treated equally with a weight of 1.
default : float
    When `attr` is not None, then if an edge does not have that attribute,
    `default` specifies what value it should take.

Returns
-------
weight: int or float
    The total weight of the branching.

Examples
--------
>>> G = nx.DiGraph()
>>> G.add_weighted_edges_from([(0, 1, 2), (1, 2, 4), (2, 3, 3), (3, 4, 2)])
>>> nx.tree.branching_weight(G)
11

c              3   óL   >#   • U  H  oS    R                  TT5      v •  M     g7f)é   N)Úget)Ú.0Úedger.   r/   s     €€r#   Ú	<genexpr>Ú#branching_weight.<locals>.<genexpr>j   s#   øé € ÐIÒ6H¨d�A‰w�{‰{˜4 ×)Ð)Ò6Hùs   ƒ!$T©Údata)ÚsumÚedges)ÚGr.   r/   s    ``r#   r   r   K   s!   ù€ ô> ÕI°a·g±gÀ4°gÑ6HÓIÓIÐIr+   é   T)r0   Úreturns_graphc                 óÐ  • U[         ;  a  [        R                  " S5      eUS:X  a  SnOSnUc	  [        US9nU R	                  SS9 VVVs/ s H  u  pgo†XxR                  X5      4PM     n	nnn U	R                  [        SSS	5      US
9  [        R                  " 5       n
U
R                  U 5        [        R                  R                  5       n[        U	5       HY  u  nu  pgnX¶   X·   :X  a  M  U
R                  U5      S	:X  a  M,  0 nUb  XØU'   U
R                  " Xg40 UD6  UR!                  Xg5        M[     U
$ s  snnnf ! [         a    U	R                  [        S5      US
9   NÚf = f)aÏ  
Returns a branching obtained through a greedy algorithm.

This algorithm is wrong, and cannot give a proper optimal branching.
However, we include it for pedagogical reasons, as it can be helpful to
see what its outputs are.

The output is a branching, and possibly, a spanning arborescence. However,
it is not guaranteed to be optimal in either case.

Parameters
----------
G : DiGraph
    The directed graph to scan.
attr : str
    The attribute to use as weights. If None, then each edge will be
    treated equally with a weight of 1.
default : float
    When `attr` is not None, then if an edge does not have that attribute,
    `default` specifies what value it should take.
kind : str
    The type of optimum to search for: 'min' or 'max' greedy branching.
seed : integer, random_state, or None (default)
    Indicator of random number generation state.
    See :ref:`Randomness<randomness>`.

Returns
-------
B : directed graph
    The greedily obtained branching.

zUnknown value for `kind`.r   FT)r!   r9   r3   r   r   )ÚkeyÚreverse)ÚKINDSÚnxÚNetworkXExceptionr$   r<   r4   Úsortr   Ú	TypeErrorÚDiGraphÚadd_nodes_fromÚutilsÚ	UnionFindÚ	enumerateÚ	in_degreeÚadd_edgeÚunion)r=   r.   r/   Úkindr!   rB   ÚuÚvr:   r<   ÚBÚufÚiÚws                 r#   r   r   m   sY  € ðF ”5ÓÜ×"Ò"Ð#>Ó?Ð?àˆuƒ}Ø‰àˆà�|ä $Ñ'ˆàABÇÁÈdÀÑASÕTÒAS±°!¸�—H‘H˜TÓ+Ó,ÑAS€EÒTð7Ø�
‰
”z ! Q¨Ó*°Gˆ
Ñ<ô 	�
Š
‹€AØ×Ñ�QÔô 
�‰×	Ñ	Ó	€BÜ! %Ö(‰ˆ‰9ˆA�!Ø‰5�B‘E‹>áØ�[‰[˜‹^˜qÓ áð ˆDØÑØ�T‘
Ø�JŠJ�qÑ$˜tÒ$Ø�H‰H�QŽNñ )ð €Hùô? Uøô
 ó 7ð 	�
‰
”z !“}¨gˆ
Ó6ð7ús   ÁD8Á/D? Ä?#E%Å$E%)Úpreserve_edge_attrsr?   Fc                 óÔ  ^ ^^^^^ ^!^"^#^$^%^&^'^(^)^*• S m$S m%Sm"Sm(T n[         R                  " 5       m S T l        0 m [        UR	                  SS95       H{  u  nu  pxn	TU	R                  TU5      0n
U	R                  T5      b  U	R                  T5      U
T'   U(       a%  U	R                  5        H  u  p¼UT:w  d  M  XÊU'   M     T$" T T XxU40 U
D6  M}     Sn[         R                  " 5       m0 m/ m&/ m![        5       m)[         R                  R                  5       m*/ m#/ m'U UU4S jnUUU U UU!U"U#U$U%U&U'U(UU)U*4S	 jnS
 n[        [        T R                  5      5      n  [        U5      nUT);   a  M   T)R'                  U5        TR)                  U5        U" U5      u  nnUb¯  US:”  a©  US   nT*U   T*U   :H  nTU0nUS   R                  T5      b  US   R                  T5      UT'   T$" TTXxUS   40 UD6  ST U   U   US      T"'   T*R+                  Xx5        U(       a1  U" UUU5        [        [        T R                  5       5      5      nUS-  nMö  ! [         a¿    [        T 5      [        T5      :X  d   e[        T5      (       a  [!        T5      (       d   eT&R#                  T R%                  5       T R%                  5       45        T!R#                  TR%                  5       TR%                  5       45        T#R#                  / 5        T'R#                  S 5         Of = fUR-                  5       n[        T!U   S   5      nUS:”  a³  US-  nT([/        U5      -   nT#U   nU" T&US-      S   UU5      u  nnUR1                  U5        U(       a   T'U   nUc  [2        eUR5                  U5        OET&U   u  m m T U   S   nU H  nT U   u  pxn	UU:X  d  M    O   [3        S5      eUR5                  U5        US:”  a  M³  UR7                  U5        U H[  nT&S   S   U   u  pxn
TU
T   0nU(       a)  U
R                  5        H  u  nnUTT"4;  d  M  UUU'   M     UR8                  " Xx40 UD6  M]     U$ )Nc                 óª   • XA;   a!  X   u  pgnX&:w  d  X7:w  a  [        SU< S35      eU R                  " X#U40 UD6  X#U R                  U   U   U   4X'   g)a³  
Adds an edge to `G` while also updating the edge index.

This algorithm requires the use of an external dictionary to track
the edge keys since it is possible that the source or destination
node of an edge will be changed and the default key-handling
capabilities of the MultiDiGraph class do not account for this.

Parameters
----------
G : MultiDiGraph
    The graph to insert an edge into.
edge_index : dict
    A mapping from integers to the edges of the graph.
u : node
    The source node of the new edge.
v : node
    The destination node of the new edge.
key : int
    The key to use from `edge_index`.
d : keyword arguments, optional
    Other attributes to store on the new edge.
zKey z is already in use.N)Ú	ExceptionrN   Úsucc)	r=   Ú
edge_indexrQ   rR   rA   ÚdÚuuÚvvÚ_s	            r#   Úedmonds_add_edgeÚ+maximum_branching.<locals>.edmonds_add_edgeÊ   sc   € ð2 ÓØ"™‰IˆB�AØ“˜Q›WÜ $ s¡gÐ-@Ð AÓBÐBà	�
Š
�1˜Ñ" Ò"Ø §¡¨¡¨1¡¨cÑ!2Ð3ˆ
Šr+   c                 ó$  • [        5       nU R                  U   R                  5        H  nUR                  U5        M     U R                  U   R                  5        H  nUR                  U5        M     U H  nX	 M     U R                  U5        g)a  
Remove a node from the graph, updating the edge index to match.

Parameters
----------
G : MultiDiGraph
    The graph to remove an edge from.
edge_index : dict
    A mapping from integers to the edges of the graph.
n : node
    The node to remove from `G`.
N)ÚsetÚpredÚvaluesÚupdater[   Úremove_node)r=   r\   r"   ÚkeysÚkeydictrA   s         r#   Úedmonds_remove_nodeÚ.maximum_branching.<locals>.edmonds_remove_nodeë   sx   € ô ‹uˆØ—v‘v˜a‘y×'Ñ'Ö)ˆGØ�K‰K˜Ö ñ *à—v‘v˜a‘y×'Ñ'Ö)ˆGØ�K‰K˜Ö ñ *ó ˆCØ’ñ ð 	
�‰�aÕr+   z#edmonds' secret candidate attributezedmonds new node base name Tr9   r   c                 óF  >• Sn[         * nTR                  U SSS9 H€  u  p4pVUR                  T
5      [        R                  R
                  :X  a  M5  UT	   nUR                  T
5      [        R                  R                  :X  a  UnX0XWU4n  X4$ Xr:”  d  My  UnX0XWU4nM‚     X4$ )al  
Find the edge directed towards v with maximal weight.

If an edge partition exists in this graph, return the included
edge if it exists and never return any excluded edge.

Note: There can only be one included edge for each vertex otherwise
the edge partition is empty.

Parameters
----------
v : node
    The node to search for the maximal weight incoming edge.
NT©r:   ri   )ÚINFÚin_edgesr4   rD   ÚEdgePartitionÚEXCLUDEDÚINCLUDED)rR   r6   Ú
max_weightrQ   r`   rA   r:   Ú
new_weightr=   r.   Ú	partitions           €€€r#   Úedmonds_find_desired_edgeÚ4maximum_branching.<locals>.edmonds_find_desired_edgeO  sº   ø€ ð ˆÜ�Tˆ
Ø Ÿz™z¨!°$¸T˜zÓB‰OˆA�#à�x‰x˜	Ó"¤b×&6Ñ&6×&?Ñ&?Ó?Ùà˜d™ˆJð �x‰x˜	Ó"¤b×&6Ñ&6×&?Ñ&?Ó?Ø'�
Ø˜c¨tÐ4�Øð ÐÐð	 Õ&Ø'�
Ø˜c¨tÐ4’ñ!  Cð$ ÐÐr+   c           	      óþ  >• US   n[         R                  " TX5      n[        USS 5       VVs/ s H)  u  pV[        TXE      U   R	                  5       5      S   PM+     nnnUR                  US   5        [        nSn	0 n
U HN  nTU   u  p0nUT   nXÚU '   UR                  T 5      [         R                  R                  :X  a  MC  XØ:  d  MJ  UnUn	MP     TR                  U5        TR                  U	5        TR                  TR                  5       TR                  5       45        TR                  TR                  5       TR                  5       45        T[        U5      -   nTR                  U5        / nTR                  SSS9 Hw  u  p0nnX:;   a-  X
;   a  M  UR                  5       nUR                  XàUU45        M9  X
;   a9  UT   nXØX    -
  -  nUR                  5       nUUT'   UR                  X>UU45        Mw  My     U H  nT" TTU5        T" TTU5        M     T!R                  [        U5      5        U H;  u  p0nnT" TTX0U40 UD6  TU;   d  M  UT	 T" TTX0U40 UD6  T"R!                  X05        M=     gs  snnf )aœ  
Perform step I2 from Edmonds' paper

First, check if the last step I1 created a cycle. If it did not, do nothing.
If it did, store the cycle for later reference and contract it.

Parameters
----------
v : node
    The current node to consider
desired_edge : edge
    The minimum desired edge to remove from the cycle.
level : int
    The current level, i.e. the number of cycles that have already been removed.
r   r   Nr3   Trn   )rD   Úshortest_pathrL   Úlistri   Úappendro   r4   rq   rs   ÚcopyÚstrÚadd_noder<   Údifference_updaterd   rO   )#rR   Údesired_edgeÚlevelrQ   ÚQ_nodesrU   r_   ÚQ_edgesÚ	minweightÚminedgeÚQ_incoming_weightÚedge_keyr:   rV   Únew_nodeÚ	new_edgesrA   ÚddÚnoderS   ÚB_edge_indexr=   ÚG_edge_indexr.   Ú
branchingsÚcandidate_attrÚcircuitsra   rk   ÚgraphsÚminedge_circuitÚnew_node_base_namerv   Úselected_nodesrT   s#                      €€€€€€€€€€€€€€€€r#   Úedmonds_step_I2Ú*maximum_branching.<locals>.edmonds_step_I2t  s”  ø€ ð  ˜‰Oˆä×"Ò" 1 aÓ+ˆä;DÀWÈQÈRÀ[Ô;Qô
Ú;Q±%°!ŒD��7‘:‘˜rÑ"×'Ñ'Ó)Ó*¨1Ô-Ñ;Qð 	ñ 
ð 	�‰�| A‘Ô'ô ˆ	ØˆØÐÛˆHØ% hÑ/‰JˆA�$Ø�T‘
ˆAð $%˜aÑ Ø�x‰x˜	Ó"¤b×&6Ñ&6×&?Ñ&?Ó?ÙØ�}Ø�	Ø"’ñ  ð 	�‰˜Ô Ø×Ñ˜wÔ'Ø�‰�q—v‘v“x ×!2Ñ!2Ó!4Ð5Ô6Ø×Ñ˜1Ÿ6™6›8 \×%6Ñ%6Ó%8Ð9Ô:ð &¬¨E«
Ñ2ˆØ	�
‰
�8ÔØˆ	Ø Ÿw™w¨D°t˜wÓ<‰OˆA�#�tØÓ%ØÓ)ñ ð Ÿ™›�BØ×$Ñ$ h°3¸Ð%;Ö<àÓ)ð ˜T™
�AØÐ%6Ñ%9Ñ9Ñ9�AØŸ™›�BØ �B�t‘HØ×$Ñ$ a°3¸Ð%;Ö<ñ ñ-  =ó0 ˆDÙ  <°Ô6Ù  <°Ö6ñ ð 	×(Ñ(¬¨W«Ô6ã(‰OˆA�#�tÙ˜Q ¨a°CÑ@¸4Ò@Ø Õ%Ø˜Ð(Ù   L°!¸ÑD¸tÒDØ—‘˜–ò  )ùó{
s   ¯0I9c                 ó¤   • X;  a  [        U< S35      eU R                  U    H)  nU R                  U   U    H  nXB;   d  M
  SU4s  s  $    M+     g)a8  
Returns True if `u` is a root node in G.

Node `u` is a root node if its in-degree over the specified edges is zero.

Parameters
----------
G : Graph
    The current graph.
u : node
    The node in `G` to check if it is a root.
edgekeys : iterable of edges
    The edges for which to check if `u` is a root of.
z	 not in GF)TN)rZ   re   )r=   rQ   ÚedgekeysrR   Úedgekeys        r#   Úis_rootÚ"maximum_branching.<locals>.is_rootË  sX   € ð ‹:Ü˜q™e 9Ð-Ó.Ð.à—‘˜”ˆAØŸ6™6 !™9 Qœ<�ØÕ&Ø  '˜>Ô)ó (ñ ð
 r+   r>   r3   r   z+Couldn't find edge incoming to merged node.)rD   ÚMultiDiGraphÚ__networkx_cache__rL   r<   r4   Úitemsrd   rJ   rK   Úiterr{   ÚnodesÚnextÚStopIterationÚlenr
   r|   r}   Úaddr   rO   Ú	__class__r~   rg   rZ   ÚremoverI   rN   )+r=   r.   r/   Úpreserve_attrsrv   Ú
G_originalrA   rQ   rR   r:   r]   Úd_kÚd_vr‚   rw   r–   r›   r¡   r�   Údesired_edge_weightÚcircuitr‹   ÚHr<   Úmerged_nodeÚisrootrš   r†   ÚtargetÚvaluerS   r�   rŽ   r�   r�   r‘   ra   rk   r’   r“   r”   r•   rT   s+   ``  `                         @@@@@@@@@@@@@r#   r   r   ¾   sš  ÿÿ€ ò4òBð: ;€NØ6Ðà€JÜ
�ŠÓ€AØ€AÔð €Lä& z×'7Ñ'7¸TÐ'7Ð'BÖCÑˆ‰\ˆa�DØ�4—8‘8˜D 'Ó*Ð+ˆà�8‰8�IÓÑ*ØŸ8™8 IÓ.ˆAˆi‰LæØ ŸJ™JžL‘�Ø˜$•;Ø �c“Fñ )ñ 	˜˜L¨!°Ñ9°qÔ9ñ Dð €Eô 	�ŠÓ€AØ€LØ€FØ€JÜ“U€NÜ	�‰×	Ñ	Ó	€Bð €Hð €O÷(# ÷JU÷ Uô Uònô2 ”�a—g‘g“Ó€EØ
ð	Ü�U“ˆAð* �NÓ"Ùð #ð 	×Ñ˜1ÔØ	�
‰
�1ŒÙ,EÀaÓ,HÑ)ˆÐ)ð Ñ#Ð(;¸aÓ(?Ø˜Q‘ˆAð ˜‘e˜r !™u‘nˆGØÐ+Ð,ˆBØ˜A‰×"Ñ" 9Ó-Ñ9Ø ,¨Q¡× 3Ñ 3°IÓ >��9‘á˜Q ¨a°LÀ±OÑJÀrÒJØ7;ˆAˆa‰D�‰G�L ‘OÑ$ ^Ñ4Ø�H‰H�QŒNö Ù  <°Ô7ÜœT !§'¡'£)›_Ó-�Ø˜‘
�ñq øô ó 	ô �q“6œS ›VÓ#Ð#Ð#Ü�1�v‰vÜ# A—‘Ð&�à�M‰M˜1Ÿ6™6›8 \×%6Ñ%6Ó%8Ð9Ô:Ø×Ñ˜qŸv™v›x¨×):Ñ):Ó)<Ð=Ô>Ø�O‰O˜BÔØ×"Ñ" 4Ô(áð	úð@ 	×ÑÓ€Aô �
˜5Ñ! !Ñ$Ó%€EØ
�!‹)Ø�‰
ˆð )¬3¨u«:Ñ5ˆØ˜5‘/ˆÙ! &¨°©Ñ"3°AÑ"6¸ÀUÓK‰ˆ�Ø�‰�WÔæØ% eÑ,ˆGØ‰Ü�ð �L‰L˜Õ!ð % U™m‰OˆAˆ|Ø! 'Ñ*¨1Ñ-ˆFÛ"�Ø)¨'Ñ2‘
��dØ˜•;Ùñ #ô
  Ð MÓNÐNà�L‰L˜Ô!ðQ �!�)ðT ×Ñ�ZÔ ÛˆØ˜‘)˜A‘,˜wÑ'‰ˆˆaØ�A�d‘Gˆ_ˆæØŸg™gži‘
��UØ˜t ^Ð4Õ4Ø#�B�s“Gñ (ð 	
�
Š
�1Ñ˜2Ôñ ð €Hs   ÅI ÉCLÌL)rW   Úmutates_inputr?   c                 ó²  • U R                  SS9 H  u    pVUR                  X5      * Xa'   M     [        R                  " U 5        [	        XX#U5      nU R                  SS9 H  u    pVUR                  X5      * Xa'   M     [        R                  " U 5        UR                  SS9 H  u    pVUR                  X5      * Xa'   M     [        R                  " U5        U$ )NTr9   )r<   r4   rD   Ú_clear_cacher   )r=   r.   r/   r¨   rv   r`   r]   rS   s           r#   r   r   i  s¿   € ð —7‘7 �7Ó%‰ˆˆ1Ø—5‘5˜Ó'Ð'ˆ‹ñ &ä‡O‚O�AÔä˜! 7¸IÓF€Aà—7‘7 �7Ó%‰ˆˆ1Ø—5‘5˜Ó'Ð'ˆ‹ñ &ä‡O‚O�AÔà—7‘7 �7Ó%‰ˆˆ1Ø—5‘5˜Ó'Ð'ˆ‹ñ &ä‡O‚O�AÔà€Hr+   ©r.   r/   r¨   rv   c               óZ  • [         * n[         nU R                  XS9 H  u    pxX…:”  a  UnX†:  d  M  UnM     U R                  SS9 H$  u    pyUS-   XV-
  -   U	R                  X5      -
  X‘'   M&     [        R                  " U 5        [        XX#U5      n
U R                  SS9 H$  u    pyUS-   XV-
  -   U	R                  X5      -
  X‘'   M&     [        R                  " U 5        U
R                  SS9 H$  u    pyUS-   XV-
  -   U	R                  X5      -
  X‘'   M&     [        R                  " U
5        U
$ )aŸ  
Returns a minimal branching from `G`.

A minimal branching is a branching similar to a minimal arborescence but
without the requirement that the result is actually a spanning arborescence.
This allows minimal branchinges to be computed over graphs which may not
have arborescence (such as multiple components).

Parameters
----------
G : (multi)digraph-like
    The graph to be searched.
attr : str
    The edge attribute used in determining optimality.
default : float
    The value of the edge attribute used if an edge does not have
    the attribute `attr`.
preserve_attrs : bool
    If True, preserve the other attributes of the original graph (that are not
    passed to `attr`)
partition : str
    The key for the edge attribute containing the partition
    data on the graph. Edges can be included, excluded or open using the
    `EdgePartition` enum.

Returns
-------
B : (multi)digraph-like
    A minimal branching.
©r:   r/   Tr9   r   )ro   r<   r4   rD   rµ   r   )r=   r.   r/   r¨   rv   rt   Ú
min_weightr`   rV   r]   rS   s              r#   r   r   ~  s+  € ôD �€JÜ€JØ—7‘7 �7Ó6‰ˆˆ1Ø‹>ØˆJØ�>ØŠJñ	 7ð —7‘7 �7Ó%‰ˆˆ1ð
 ˜q‘. JÑ$;Ñ<¸q¿u¹uÀTÓ?SÑSˆ‹ñ &ô ‡O‚O�AÔä˜! 7¸IÓF€Að —7‘7 �7Ó%‰ˆˆ1Ø˜q‘. JÑ$;Ñ<¸q¿u¹uÀTÓ?SÑSˆ‹ñ &ä‡O‚O�AÔà—7‘7 �7Ó%‰ˆˆ1Ø˜q‘. JÑ$;Ñ<¸q¿u¹uÀTÓ?SÑSˆ‹ñ &ä‡O‚O�AÔà€Hr+   c                 ó¸  • [         n[         * nU R                  XS9 H  u    pxX…:  a  UnX†:”  d  M  UnM     U R                  SS9 H$  u    pyU	R                  X5      U-
  S-   XV-
  -
  X‘'   M&     [        R                  " U 5        [        XX#U5      n
U R                  SS9 H$  u    pyU	R                  X5      U-   S-
  XV-
  -   X‘'   M&     [        R                  " U 5        U
R                  SS9 H$  u    pyU	R                  X5      U-   S-
  XV-
  -   X‘'   M&     [        R                  " U
5        [        U
5      (       d  [        R                  R                  S5      eU
$ )Nr¸   Tr9   r   z&No maximum spanning arborescence in G.)	ro   r<   r4   rD   rµ   r   r	   Ú	exceptionrE   )r=   r.   r/   r¨   rv   r¹   rt   r`   rV   r]   rS   s              r#   r   r   ¾  sH  € ô €JÜ�€JØ—7‘7 �7Ó6‰ˆˆ1Ø‹>ØˆJØ�>ØŠJñ	 7ð —7‘7 �7Ó%‰ˆˆ1Ø—%‘%˜Ó&¨Ñ3°aÑ7¸:Ñ;RÑSˆ‹ñ &ä‡O‚O�AÔä˜! 7¸IÓF€Aà—7‘7 �7Ó%‰ˆˆ1Ø—%‘%˜Ó&¨Ñ3°aÑ7¸:Ñ;RÑSˆ‹ñ &ä‡O‚O�AÔà—7‘7 �7Ó%‰ˆˆ1Ø—%‘%˜Ó&¨Ñ3°aÑ7¸:Ñ;RÑSˆ‹ñ &ä‡O‚O�AÔä˜1×ÑÜ�l‰l×,Ñ,Ð-UÓVÐVà€Hr+   c                 ó~   • [        U UUUUS9n[        U5      (       d  [        R                  R	                  S5      eU$ )Nr¶   z&No minimum spanning arborescence in G.)r   r	   rD   r»   rE   )r=   r.   r/   r¨   rv   rS   s         r#   r   r   è  sE   € ô 	Ø	ØØØ%Øñ	€Aô ˜1×ÑÜ�l‰l×,Ñ,Ð-UÓVÐVà€Hr+   a‰  
Returns a {kind} {style} from G.

Parameters
----------
G : (multi)digraph-like
    The graph to be searched.
attr : str
    The edge attribute used to in determining optimality.
default : float
    The value of the edge attribute used if an edge does not have
    the attribute `attr`.
preserve_attrs : bool
    If True, preserve the other attributes of the original graph (that are not
    passed to `attr`)
partition : str
    The key for the edge attribute containing the partition
    data on the graph. Edges can be included, excluded or open using the
    `EdgePartition` enum.

Returns
-------
B : (multi)digraph-like
    A {kind} {style}.
zV
Raises
------
NetworkXException
    If the graph does not contain a {kind} {style}.

Úmaximum)rP   ÚstyleÚminimumz)
See Also
--------
    minimal_branching
r   c                   óf   • \ rS rSrSr\" SS9 " S S5      5       rSS jrS	 rS
 r	S r
S rS rSrg)r   i5  uš  
Iterate over all spanning arborescences of a graph in either increasing or
decreasing cost.

Notes
-----
This iterator uses the partition scheme from [1]_ (included edges,
excluded edges and open edges). It generates minimum spanning
arborescences using a modified Edmonds' Algorithm which respects the
partition of edges. For arborescences with the same weight, ties are
broken arbitrarily.

References
----------
.. [1] G.K. Janssens, K. SÃ¶rensen, An algorithm to generate all spanning
       trees in order of increasing cost, Pesquisa Operacional, 2005-08,
       Vol. 25 (2), p. 219-229,
       https://www.scielo.br/j/pope/a/XHswBwRwJyrfL88dmMwYNWp/?lang=en
T)Úorderc                   ó@   • \ rS rSr% Sr\\S'   \" SS9r\	\S'   S r
Srg	)
ÚArborescenceIterator.PartitioniJ  z—
This dataclass represents a partition and stores a dict with the edge
data and the weight of the minimum spanning arborescence of the
partition dict.
Ú
mst_weightF)ÚcompareÚpartition_dictc                 ór   • [         R                  U R                  U R                  R	                  5       5      $ r&   )r   Ú	PartitionrÄ   rÆ   r}   )Úselfs    r#   Ú__copy__Ú'ArborescenceIterator.Partition.__copy__U  s-   € Ü'×1Ñ1Ø—‘ ×!4Ñ!4×!9Ñ!9Ó!;óð r+   r'   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚfloatÚ__annotations__r   rÆ   ÚdictrÊ   Ú__static_attributes__r'   r+   r#   rÈ   rÃ   J  s#   ‡ ñ	ð ÓÙ$¨UÑ3ˆ˜Ó3õ	r+   rÈ   Nc                 ót  • UR                  5       U l        X l        X0l        U(       a  [        O[
        U l        SU l        Ubn  0 nUS    H  n[        R                  R                  XV'   M!     US    H  n[        R                  R                  XV'   M!     [        R                  SU5      U l        gSU l        g)a~  
Initialize the iterator

Parameters
----------
G : nx.DiGraph
    The directed graph which we need to iterate trees over

weight : String, default = "weight"
    The edge attribute used to store the weight of the edge

minimum : bool, default = True
    Return the trees in increasing order while true and decreasing order
    while false.

init_partition : tuple, default = None
    In the case that certain edges have to be included or excluded from
    the arborescences, `init_partition` should be in the form
    `(included_edges, excluded_edges)` where each edges is a
    `(u, v)`-tuple inside an iterable such as a list or set.

z;ArborescenceIterators super secret partition attribute nameNr   r   )r}   r=   r)   r¿   r   r   ÚmethodÚpartition_keyrD   rq   rs   rr   r   rÈ   Úinit_partition)rÉ   r=   r)   r¿   rØ   rÆ   Úes          r#   Ú__init__ÚArborescenceIterator.__init__Z  s©   € ð. —‘“ˆŒØŒØŒæ-4Õ)Ô:Wð 	Œð
 Jð 	Ôð Ñ%ØˆNØ# AÔ&�Ü$&×$4Ñ$4×$=Ñ$=�Ó!ñ 'à# AÔ&�Ü$&×$4Ñ$4×$=Ñ$=�Ó!ñ 'ä"6×"@Ñ"@ÀÀNÓ"SˆDÕà"&ˆDÕr+   c                 óü  • [        5       U l        U R                  U R                  5        U R                  b  U R                  U R                  5        U R                  U R                  U R                  U R                  SS9R                  U R                  S9nU R                  R                  U R                  U R                  (       a  UOU* U R                  c  0 OU R                  R                  5      5        U $ )zM
Returns
-------
ArborescenceIterator
    The iterator object for this graph
T©rv   r¨   r(   )r   Úpartition_queueÚ_clear_partitionr=   rØ   Ú_write_partitionrÖ   r)   r×   ÚsizeÚputrÈ   r¿   rÆ   )rÉ   rÄ   s     r#   Ú__iter__ÚArborescenceIterator.__iter__…  sÜ   € ô  -›ˆÔØ×Ñ˜dŸf™fÔ%ð ×ÑÑ*Ø×!Ñ! $×"5Ñ"5Ô6à—[‘[Ø�F‰FØ�K‰KØ×(Ñ(Øð	 !ð 
÷
 ‰$�d—k‘kˆ$Ð
"ð 	ð 	×Ñ× Ñ Ø�N‰NØ"ŸlŸl‘
°°ð ×*Ñ*Ñ2ñ à×,Ñ,×;Ñ;óô		
ð ˆr+   c                 óR  • U R                   R                  5       (       a
  U ?U ? [        eU R                   R	                  5       nU R                  U5        U R                  U R                  U R                  U R                  SS9nU R                  X5        U R                  U5        U$ )zp
Returns
-------
(multi)Graph
    The spanning tree of next greatest weight, which ties broken
    arbitrarily.
TrÝ   )rÞ   Úemptyr=   r£   r4   rà   rÖ   r)   r×   Ú
_partitionrß   )rÉ   rv   Únext_arborescences      r#   Ú__next__ÚArborescenceIterator.__next__§  sœ   € ð ×Ñ×%Ñ%×'Ñ'Ø�˜Ð,ÜÐà×(Ñ(×,Ñ,Ó.ˆ	Ø×Ñ˜iÔ(Ø ŸK™KØ�F‰FØ�K‰KØ×(Ñ(Øð	 (ð 
Ðð 	�‰˜	Ô5à×ÑÐ/Ô0Ø Ð r+   c                 óD  • U R                  SUR                  R                  5       5      nU R                  SUR                  R                  5       5      nUR                   GH!  nXQR                  ;  d  M  [        R
                  R                  UR                  U'   [        R
                  R                  UR                  U'   U R                  U5         U R                  U R                  U R                  U R                  SS9nUR                  U R                  S9nU R                  (       a  UOU* Ul        U R                   R#                  UR%                  5       5        UR                  R                  5       Ul        GM$     g! [        R&                   a     N;f = f)a<  
Create new partitions based of the minimum spanning tree of the
current minimum partition.

Parameters
----------
partition : Partition
    The Partition instance used to generate the current minimum spanning
    tree.
partition_arborescence : nx.Graph
    The minimum spanning arborescence of the input partition.
r   TrÝ   r(   N)rÈ   rÆ   r}   r<   rD   rq   rr   rs   rà   rÖ   r=   r)   r×   rá   r¿   rÄ   rÞ   râ   rÊ   rE   )rÉ   rv   Úpartition_arborescenceÚp1Úp2rÙ   Úp1_mstÚp1_mst_weights           r#   rç   ÚArborescenceIterator._partitionÀ  sJ  € ð �^‰^˜A˜y×7Ñ7×<Ñ<Ó>Ó?ˆØ�^‰^˜A˜y×7Ñ7×<Ñ<Ó>Ó?ˆØ'×-Õ-ˆAà×0Ñ0Õ0ä')×'7Ñ'7×'@Ñ'@�×!Ñ! !Ñ$Ü')×'7Ñ'7×'@Ñ'@�×!Ñ! !Ñ$à×%Ñ% bÔ)ðØ!Ÿ[™[ØŸ™ØŸ™Ø"&×"4Ñ"4Ø'+ð	 )ð �Fð %+§K¡K°t·{±{ KÐ$C�MØ59·\·\¡MÈÀ~�B”MØ×(Ñ(×,Ñ,¨R¯[©[«]Ô;ð %'×$5Ñ$5×$:Ñ$:Ó$<�×!ò- .øô& ×+Ñ+ó Ùðús   ÃBFÆFÆFc                 ó  • U R                   R                  SS9 H[  u  p#nX#4UR                  ;   a  UR                  X#4   X@R                  '   M5  [        R
                  R                  X@R                  '   M]     [        R                  " U R                   5        U R                    GHV  nSnSnU R                   R                  USS9 H‚  u  p#nUR                  U R                  5      [        R
                  R                  :X  a  US-  nMD  UR                  U R                  5      [        R
                  R                  :X  d  M}  US-  nM„     US:X  d  M°  XpR                   R                  U5      S-
  :w  d  MÓ  U R                   R                  USS9 He  u  p#nUR                  U R                  5      [        R
                  R                  :w  d  M?  [        R
                  R                  X@R                  '   Mg     GMY     g)a�  
Writes the desired partition into the graph to calculate the minimum
spanning tree. Also, if one incoming edge is included, mark all others
as excluded so that if that vertex is merged during Edmonds' algorithm
we cannot still pick another of that vertex's included edges.

Parameters
----------
partition : Partition
    A Partition dataclass describing a partition on the edges of the
    graph.
Tr9   r   )Únbunchr:   r   N)r=   r<   rÆ   r×   rD   rq   ÚOPENrµ   rp   r4   rs   rr   rM   )rÉ   rv   rQ   rR   r]   r"   Úincluded_countÚexcluded_counts           r#   rà   Ú%ArborescenceIterator._write_partitionè  sŠ  € ð —v‘v—|‘|¨�|Ó.‰GˆA�!Øˆv˜×1Ñ1Ó1Ø(1×(@Ñ(@À!ÀÑ(H�×$Ñ$Ó%ä(*×(8Ñ(8×(=Ñ(=�×$Ñ$Ó%ñ	 /ô
 	�Š˜Ÿ™Ôà—•ˆAØˆNØˆNØŸ6™6Ÿ?™?°!¸$˜?Ó?‘��aØ—5‘5˜×+Ñ+Ó,´×0@Ñ0@×0IÑ0IÓIØ" aÑ'’NØ—U‘U˜4×-Ñ-Ó.´"×2BÑ2B×2KÑ2KÕKØ" aÑ'’Nñ	 @ð  Õ" ~¿¹×9IÑ9IÈ!Ó9LÈqÑ9PÕ'PØ#Ÿv™vŸ™°a¸d˜ÓC‘G�A˜!Ø—u‘u˜T×/Ñ/Ó0´B×4DÑ4D×4MÑ4MÕMÜ02×0@Ñ0@×0IÑ0I˜×,Ñ,Ó-ô  Dò r+   c                 ó²   • UR                  SS9 H$  u  p#nU R                  U;   d  M  X@R                  	 M&     [        R                  " U R                  5        g)z'
Removes partition data from the graph
Tr9   N)r<   r×   rD   rµ   r=   )rÉ   r=   rQ   rR   r]   s        r#   rß   Ú%ArborescenceIterator._clear_partition  sI   € ð —w‘w D�wÓ)‰GˆA�!Ø×!Ñ! QÕ&Ø×(Ñ(Ò)ñ *ô 	�Š˜Ÿ™Õr+   )r=   rØ   rÖ   r¿   r×   rÞ   r)   )r)   TN)rÌ   rÍ   rÎ   rÏ   rÐ   r   rÈ   rÚ   rã   ré   rç   rà   rß   rÔ   r'   r+   r#   r   r   5  sH   † ññ( �TÑ÷ð ó ðô)'òV òD!ò2&=òP!JõF r+   r   )é   N)r)   r   )r)   r   r   N)r)   r   FN)$rÐ   r   Údataclassesr   r   Úoperatorr   Úqueuer   ÚnetworkxrD   Únetworkx.utilsr   Úrecognitionr	   r
   Ú__all__rC   ÚSTYLESrÑ   ro   r$   r*   r-   Ú_dispatchabler   r   r   r   r   r   r   Údocstring_branchingÚdocstring_arborescenceÚformatr   r'   r+   r#   Ú<module>r     s]  ðñó: ß (Ý Ý ã Ý *ç 6ò	€ð 
�ˆ€ð Ø"Ø+ñ
€ñ ˆEƒl€ñ �ÓóJó ðJòòð ×Ò˜f iÐ0Ñ1óJó 2ðJñB �ÓØ×Ò˜f iÐ0ÀÑEóLó Fó ðLð^ ×Ò d¸$Ñ?ð 
ØØØógó @ðgðT ×Ò d¸$ÈdÑSàAEóó Tðð( ×Ò d¸$ÈdÑSà A°eÀtô<ó Tð<ð~ ×Ò d¸$ÈdÑSàAEó&ó Tð&ðR ×Ò d¸$ÈdÑSàAEóó Tðð"Ð ð6 ðñð ð 0×6Ñ6Ø	˜+ð 7ð Ð Ô ð
 ×Ñ I°[ÐÐAðñð Ô ð )?×(EÑ(EØ	Ð1ð )Fð )Ð Ô %ð )?×(EÑ(EØ	Ð1ð )Fð )Ð Ô %÷
] ò ] r+   