
    wg#                     P   d Z ddlZddlmZmZ ddlmZ ddlmZ ddl	Z
ddlmZ ddlmZmZ g d	Zd
dhZddddZ ed      Z ed      d.d       Zd Zd Z e
j0                  ddi      d/d       Z ed       e
j0                  ddid      d0d              Z e
j0                  dd      	 	 	 	 d1d       Z e
j0                  ddd      	 d1d        Z e
j0                  ddd      ddddd!d"       Z e
j0                  ddd      	 d1d#       Z e
j0                  ddd      	 d1d$       Zd%Z e d&z   Z!e jE                  d'd(      e_         e jE                  d)d(      d*z   e_         e!jE                  d'd+(      e_         e!jE                  d)d+(      e_          G d, d-      Z#y)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                     dj                  t        |       D cg c]!  }|j                  t        j                        # c}      S c c}w )N )joinrangechoicestringascii_letters)Lseedns      h/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/networkx/algorithms/tree/branchings.pyrandom_stringr$   >   s2    77uQxH!DKK 4 45HIIHs   &Ac                     |  S N weights    r#   _min_weightr*   C   s	    7N    c                     | S r&   r'   r(   s    r#   _max_weightr-   G   s    Mr+   attrdefault)
edge_attrsr)   c                 P    t        fd| j                  d      D              S )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   H   K   | ]  }|d    j                          yw)   N)get).0edger.   r/   s     r#   	<genexpr>z#branching_weight.<locals>.<genexpr>j   s      IdtAw{{4)Is   "Tdata)sumedges)Gr.   r/   s    ``r#   r   r   K   s!    > Iagg4g6HIIIr+      T)r0   returns_graphc                    |t         vrt        j                  d      |dk(  rd}nd}|t        |      }| j	                  d      D cg c]  \  }}}|||j                  ||      f }	}}}	 |	j                  t        ddd	      |
       t        j                         }
|
j                  |        t        j                  j                         }t        |	      D ]Y  \  }\  }}}||   ||   k(  r|
j                  |      d	k(  r+i }||||<    |
j                  ||fi | |j!                  ||       [ |
S c c}}}w # t        $ r |	j                  t        d      |
       Y w xY w)a7  
    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!   r8   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!   rA   uvr9   r;   Bufiws                 r#   r   r   m   st   F 5""#>??u}|$'ABdASTT!QaDHHT7+,TET7

z!Q*G
< 	

AQ 
			B!%( 9Aq!a5BqE>[[^q  DT
AJJq!$t$HHQN H? U
  7 	

z!}g
67s    D;1E %E*)E*)preserve_edge_attrsr>   Fc                 j    !"#$%&'()* d $d %d"d( }t        j                          d  _        i  t        |j	                  d            D ]t  \  }\  }}}	|	j                  |      i}
|	j                        |	j                        |
<   |r#|	j                         D ]  \  }}|k7  s||
|<     $  |||fi |
 v d}t        j                         i g &g !t               )t         j                  j                         *g #g ' fd}  !"#$%&'()*fd	}d
 }t        t         j                              }	 	 t        |      }|)v r)j'                  |       j)                  |        ||      \  }}||dkD  r|d   }*|   *|   k(  }|i}|d   j                        |d   j                        |<    $|||d   fi | d |   |   |d      "<   *j+                  ||       |r1 ||||       t        t         j                                     }|dz  }# t        $ r t               t              k(  sJ t              rt!              sJ &j#                   j%                          j%                         f       !j#                  j%                         j%                         f       #j#                  g        'j#                  d        Y nw xY w|j-                         }t        !|   d         }|dkD  r|dz  }(t/        |      z   }#|   } |&|dz      d   ||      \  }}|j1                  |       |r'|   }|t2        |j5                  |       nC&|   \     |   d   }|D ]  } |   \  }}}	||k(  s n t3        d      |j5                  |       |dkD  r|j7                  |       |D ]R  }&d   d   |   \  }}}
|
   i}|r$|
j                         D ]  \  }}|"fvs|||<     |j8                  ||fi | T |S )Nc                     ||v r"||   \  }}}||k7  s||k7  rt        d|d       | j                  |||fi | ||| j                  |   |   |   f||<   y)aS  
        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)	ExceptionrM   succ)	r<   
edge_indexrP   rQ   r@   duuvv_s	            r#   edmonds_add_edgez+maximum_branching.<locals>.edmonds_add_edge   su    2 *"3IBARQ"W$sg-@ ABB

1a""a1c!23
3r+   c                    t               }| j                  |   j                         D ]  }|j                  |        | j                  |   j                         D ]  }|j                  |        |D ]  }||=  | j                  |       y)aR  
        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updaterZ   remove_node)r<   r[   r"   keyskeydictr@   s         r#   edmonds_remove_nodez.maximum_branching.<locals>.edmonds_remove_node   s     uvvay'') 	!GKK 	!vvay'') 	!GKK 	!  	 C3	  	
ar+   z#edmonds' secret candidate attributezedmonds new node base name Tr8   r   c                 P   d}t          }j                  | dd      D ]  \  }}}}|j                  
      t        j                  j
                  k(  r5|	   }|j                  
      t        j                  j                  k(  r|}|| |||f} ||fS ||kD  sz|}|| |||f} ||fS )a  
        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r9   rg   )INFin_edgesr4   rC   EdgePartitionEXCLUDEDINCLUDED)rQ   r6   
max_weightrP   r_   r@   r9   
new_weightr<   r.   	partitions           r#   edmonds_find_desired_edgez4maximum_branching.<locals>.edmonds_find_desired_edgeO  s     T
 zz!$TzB 	5OAq#txx	"b&6&6&?&??dJ xx	"b&6&6&?&??'
1c:t4 Z	 J&'
1c:t4!	5$ Zr+   c           	         |d   }t        j                  | |      }t        |dd       D cg c]*  \  }}t        ||      |   j	                               d   , }}}|j                  |d          t        }d}	i }
|D ]L  }|   \  }} }|   }||
| <   |j                         t         j                  j                  k(  rC||k  sI|}|}	N j                  |       j                  |	       j                  j                         j                         f       j                  j                         j                         f       t        |      z   }j                  |       g }j                  dd      D ]u  \  }} }}||
v r+| |
v r|j                         }|j                  || ||f       7| |
v r;|   }|||
|    z
  z  }|j                         }||<   |j                  ||||f       vw |D ]  } |        |        !j                  t        |             |D ];  \  }} }} || |fi | |v s|=  || |fi | "j!                  ||        = yc c}}w )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   Trk   )rC   shortest_pathrK   listrg   appendrl   r4   rn   rp   copystradd_noder;   difference_updaterb   rN   )#rQ   desired_edgelevelrP   Q_nodesrT   r^   Q_edges	minweightminedgeQ_incoming_weightedge_keyr9   rU   new_node	new_edgesr@   ddnoderR   B_edge_indexr<   G_edge_indexr.   
branchingscandidate_attrcircuitsr`   ri   graphsminedge_circuitnew_node_base_namers   selected_nodesrS   s#                      r#   edmonds_step_I2z*maximum_branching.<locals>.edmonds_step_I2t  s     O""1a+;DWQR[;Q
27!RD71:r"'')*1-
 
 	|A' 	 
	#H%h/JAq$T
A $%a xx	"b&6&6&?&??9}	"
	# 	 w'qvvx!2!2!4561668\%6%6%89: &E
2	

8	 wwDtw< 	OAq#t%%))  B$$h3%;<)) T
A%6q%999AB BtH$$a3%;< -	0  	7D<6<6	7 	((W6( 	OAq#tQaC@4@%( L!QDtDA	{
s   /I2c                     || vrt        |d      | j                  |   D ]%  }| j                  |   |   D ]  }||v sd|fc c S  ' y)a  
        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)rY   rc   )r<   rP   edgekeysrQ   edgekeys        r#   is_rootz"maximum_branching.<locals>.is_root  sf     A:qe9-.. 	A66!9Q< *h& '>)*	
 r+   r=   r3   r   z+Couldn't find edge incoming to merged node.)rC   MultiDiGraph__networkx_cache__rK   r;   r4   itemsrb   rI   rJ   iterrw   nodesnextStopIterationlenr
   rx   ry   addr{   rN   	__class__rz   re   rY   removerH   rM   )+r<   r.   r/   preserve_attrsrs   
G_originalr@   rP   rQ   r9   r\   d_kd_vr~   rt   r   r   r   r}   desired_edge_weightcircuitr   Hr;   merged_nodeisrootr   r   targetvaluerR   r   r   r   r   r   r`   ri   r   r   r   r   rS   s+   ``  `                         @@@@@@@@@@@@@r#   r   r      s   4B: ;N6J
AA L&z'7'7T'7'BC :\aD488D'*+88I*88I.AiL JJL !S$; AcF! 	L!Q9q9: 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aLOJrJ7;AaDGLO$^4HHQN <7T!'')_-
q   	 q6SV###1v#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" O)'2
1d;O
   MNNLL!Q !)T Z  	)A,w'1aAdG_ggi $
Ut^44#BsG$ 	

1a2	 Hs   H< <B:K98K9)rV   mutates_inputr>   c                    | j                  d      D ]  \  }}}|j                  ||       ||<    t        j                  |        t	        | ||||      }| j                  d      D ]  \  }}}|j                  ||       ||<    t        j                  |        |j                  d      D ]  \  }}}|j                  ||       ||<    t        j                  |       |S )NTr8   )r;   r4   rC   _clear_cacher   )r<   r.   r/   r   rs   r_   r\   rR   s           r#   r   r   i  s     777% (1a55w''$(OOA!T7NIFA777% (1a55w''$(OOA777% (1a55w''$(OOAHr+   r.   r/   r   rs   c               z   t          }t         }| j                  ||      D ]  \  }}}||kD  r|}||k  s|} | j                  d      D ]'  \  }}}	|dz   ||z
  z   |	j                  ||      z
  |	|<   ) t        j                  |        t        | ||||      }
| j                  d      D ]'  \  }}}	|dz   ||z
  z   |	j                  ||      z
  |	|<   ) t        j                  |        |
j                  d      D ]'  \  }}}	|dz   ||z
  z   |	j                  ||      z
  |	|<   ) t        j                  |
       |
S )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.
    r9   r/   Tr8   r   )rl   r;   r4   rC   r   r   )r<   r.   r/   r   rs   rq   
min_weightr_   rU   r\   rR   s              r#   r   r   ~  si   D JJ77g76 1az>Jz>J	 777% T1a
 q.J$;<quuT7?SS$T OOA!T7NIFA 777% T1aq.J$;<quuT7?SS$TOOA777% T1aq.J$;<quuT7?SS$TOOAHr+   c                    t         }t          }| j                  ||      D ]  \  }}}||k  r|}||kD  s|} | j                  d      D ]'  \  }}}	|	j                  ||      |z
  dz   ||z
  z
  |	|<   ) t        j                  |        t        | ||||      }
| j                  d      D ]'  \  }}}	|	j                  ||      |z   dz
  ||z
  z   |	|<   ) t        j                  |        |
j                  d      D ]'  \  }}}	|	j                  ||      |z   dz
  ||z
  z   |	|<   ) t        j                  |
       t        |
      st        j                  j                  d      |
S )Nr   Tr8   r   z&No maximum spanning arborescence in G.)	rl   r;   r4   rC   r   r   r	   	exceptionrD   )r<   r.   r/   r   rs   r   rq   r_   rU   r\   rR   s              r#   r   r     s    JJ77g76 1az>Jz>J	 777% T1a%%g&3a7:
;RS$TOOA!T7NIFA777% T1a%%g&3a7:
;RS$TOOA777% T1a%%g&3a7:
;RS$TOOA1ll,,-UVVHr+   c                 z    t        | ||||      }t        |      st        j                  j	                  d      |S )Nr   z&No minimum spanning arborescence in G.)r   r	   rC   r   rD   )r<   r.   r/   r   rs   rR   s         r#   r   r     sB     		%	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)rO   styleminimumz)
See Also
--------
    minimal_branching
r   c                   b    e Zd ZdZ ed       G d d             ZddZd Zd	 Zd
 Z	d Z
d Zy)r   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                   >    e Zd ZU dZeed<    ed      Zeed<   d Z	y)ArborescenceIterator.Partitionz
        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    t         j                  | j                  | j                  j	                               S r&   )r   	Partitionr   r   ry   )selfs    r#   __copy__z'ArborescenceIterator.Partition.__copy__U  s-    '11!4!4!9!9!; r+   N)
__name__
__module____qualname____doc__float__annotations__r   r   dictr   r'   r+   r#   r   r   J  s#    	 $U33	r+   r   Nc                 h   |j                         | _        || _        || _        |rt        nt
        | _        d| _        |li }|d   D ]  }t        j                  j                  ||<   ! |d   D ]  }t        j                  j                  ||<   ! t        j                  d|      | _        yd| _        y)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   )ry   r<   r)   r   r   r   methodpartition_keyrC   rn   rp   ro   r   r   init_partition)r   r<   r)   r   r   r   es          r#   __init__zArborescenceIterator.__init__Z  s    . -4):W 	
 J 	 %N#A& >$&$4$4$=$=q!>#A& >$&$4$4$=$=q!>"6"@"@N"SD"&Dr+   c                    t               | _        | j                  | j                         | j                  | j                  | j                         | j                  | j                  | j                  | j                  d      j                  | j                        }| j                  j                  | j                  | j                  r|n| | j                  i n| j                  j                               | S )zu
        Returns
        -------
        ArborescenceIterator
            The iterator object for this graph
        Trs   r   r(   )r   partition_queue_clear_partitionr<   r   _write_partitionr   r)   r   sizeputr   r   r   )r   r   s     r#   __iter__zArborescenceIterator.__iter__  s      -dff% *!!$"5"56[[FFKK((	 ! 

 $dkk$
" 	 	  NN"ll
 **2 ,,;;		
 r+   c                 P   | j                   j                         r
| `| ` t        | j                   j	                         }| j                  |       | j                  | j                  | j                  | j                  d      }| j                  ||       | j                  |       |S )z
        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   rs   next_arborescences      r#   __next__zArborescenceIterator.__next__  s     %%',((,,.	i( KKFFKK((	 ( 
 		#45/0  r+   c                 <   | j                  d|j                  j                               }| j                  d|j                  j                               }|j                  D ]  }||j                  vst        j
                  j                  |j                  |<   t        j
                  j                  |j                  |<   | j                  |       	 | j                  | j                  | j                  | j                  d      }|j                  | j                        }| j                  r|n| |_        | j                   j#                  |j%                                |j                  j                         |_        " y# t        j&                  $ r Y 8w xY w)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   ry   r;   rC   rn   ro   rp   r   r   r<   r)   r   r   r   r   r   r   r   rD   )r   rs   partition_arborescencep1p2r   p1_mstp1_mst_weights           r#   r   zArborescenceIterator._partition  sQ    ^^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                    | j                   j                  d      D ]\  \  }}}||f|j                  v r|j                  ||f   || j                  <   6t        j
                  j                  || j                  <   ^ t	        j                  | j                          | j                   D ]Q  }d}d}| j                   j                  |d      D ]~  \  }}}|j                  | j                        t        j
                  j                  k(  r|dz  }C|j                  | j                        t        j
                  j                  k(  sz|dz  } |dk(  s|| j                   j                  |      dz
  k7  s| j                   j                  |d      D ]d  \  }}}|j                  | j                        t        j
                  j                  k7  s>t        j
                  j                  || j                  <   f T y)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.
        Tr8   r   )nbunchr9   r   N)r<   r;   r   r   rC   rn   OPENr   rm   r4   rp   ro   rL   )r   rs   rP   rQ   r\   r"   included_countexcluded_counts           r#   r   z%ArborescenceIterator._write_partition  s    vv|||. 	>GAq!1v111(1(@(@!Q(H$$$%(*(8(8(=(=$$$%		>
 	 	JANN66??!$?? (1a55++,0@0@0I0II"a'NUU4--."2B2B2K2KK"a'N	( "~9I9I!9Lq9P'P#vvadC JGAq!uuT//0B4D4D4M4MM020@0@0I0I$,,-J	Jr+   c                     |j                  d      D ]"  \  }}}| j                  |v s|| j                  = $ t        j                  | j                         y)z7
        Removes partition data from the graph
        Tr8   N)r;   r   rC   r   r<   )r   r<   rP   rQ   r\   s        r#   r   z%ArborescenceIterator._clear_partition  sR     wwDw) 	*GAq!!!Q&d(()	* 	r+   )r)   TN)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   networkxrC   networkx.utilsr   recognitionr	   r
   __all__rB   STYLESr   rl   r$   r*   r-   _dispatchabler   r   r   r   r   r   r   docstring_branchingdocstring_arborescenceformatr   r'   r+   r#   <module>r      sk  :  (    * 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+   