
    h#                        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      U/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/tree/branchings.pyrandom_stringr$   >   s4    77uQxHx!KK 4 45xHIIHs   (Ac                     U * $ N weights    r#   _min_weightr*   C   s	    7N    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#     I6HdAw{{4))6Hs   !$Tdata)sumedges)Gr.   r/   s    ``r#   r   r   K   s!    > Iagg4g6H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  pgoXxR                  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  XU'   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   Nf = 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TAS!HHT+,ASET7

z!Q*G
< 	

AQ 
			B!%(9A!5BE>[[^q  DT
JJq$t$HHQN ) H? U
  7 	

z!}g
67s   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  pUT:w  d  M  XU'   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 "IBAQW$sg-@ 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vvay'')GKK  *vvay'')GKK  * 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_edge4maximum_branching.<locals>.edmonds_find_desired_edgeO  s     T
 zz!$TzBOA#xx	"b&6&6&?&??dJ xx	"b&6&6&?&??'
ct4 	 &'
ct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XU '   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                  XUU45        M9  X
;   a9  UT   nXX   -
  -  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""1a+;DWQR[;Q
;Q%!D7:r"'')*1-;Q 	 
 	|A' 	H%h/JA$T
A $%a xx	"b&6&6&?&??}	"   	 w'qvvx!2!2!4561668\%6%6%89: &E
2	

8	 wwDtw<OA#t%)  B$$h3%;<) T
A%6%999AB BtH$$a3%;< -  =0 D<6<6  	((W6(OA#tQaC@4@%( L!Dt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     :qe9-..A66!9Q<& '>) ( 
 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   4B: ;N6J
AA L&z'7'7T'7'BC\aD488D'*+88I*88I.AiL JJL$; cF ) 	L!9q9 D E 	ALFJUN				B H O(# JU U Un2 aggE
	UA* N" # 	1	

1,Ea,H)) #(;a(?QA er!unG+,BA""9-9 ,Q 3 3I >9QaLOJrJ7;AaDGLO$^4HHQN <7T!'')_-
q   	 q6SV###1vv#A&MM1668\%6%6%89:qvvx):):)<=>OOB""4(	@ 	A 
5!!$%E
!)
 )3u:55/!&"3A"6UKW%e,G LL! %UmOA|!'*1-F")'2
d; #
   MNNLL!Q !)T Z )A,w'aAdG_ggi
Ut^44#BsG ( 	


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     777%155'' &OOA!7IFA777%155'' &OOA777%155'' &OOA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77761>J>J	 7 777%1
 q.J$;<quuT?SS & OOA!7IFA 777%1q.J$;<quuT?SS &OOA777%1q.J$;<quuT?SS &OOA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77761>J>J	 7 777%1%%&3a7:;RS &OOA!7IFA777%1%%&3a7:;RS &OOA777%1%%&3a7:;RS &OOA1ll,,-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ll,,-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"SD"&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      -dff% *!!$"5"56[[FFKK((	 ! 

 $dkk$
" 	 	  NN"ll
 **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( KKFFKK((	 ( 
 		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    ^^Ay77<<>?^^Ay77<<>?'--A000')'7'7'@'@!!!$')'7'7'@'@!!!$%%b)![["&"4"4'+	 ) F %+KKt{{K$CM59\\M~BM((,,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    vv|||.GA!v111(1(@(@!(H$$%(*(8(8(=(=$$%	 /
 	ANN66??!$??a55++,0@0@0I0II"a'NUU4--."2B2B2K2KK"a'N	 @ "~9I9I!9Lq9P'P#vvadCGA!uuT//0B4D4D4M4MM020@0@0I0I,,-  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     wwDw)GA!!!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	 
 "+
 El J J fi01J 2JB fi0EL F L^ d$? 
g @gT d$dSAE T( d$dSAet< T<~ d$dSAE& T&R d$dSAE T" 6   066	+ 7   
 I[A   )?(E(E	1 )F )  % )?(E(E	1 )F )  %
]  ] r+   