
    h5                         S r SS/rSSKr\R                  " SSS9SS j5       r\R                  " SS9S	 5       rSS
 jrS rS r	S r
S rg)a  
Implementation of the Wright, Richmond, Odlyzko and McKay (WROM)
algorithm for the enumeration of all non-isomorphic free trees of a
given order.  Rooted trees are represented by level sequences, i.e.,
lists in which the i-th element specifies the distance of vertex i to
the root.

nonisomorphic_treesnumber_of_nonisomorphic_trees    NT)graphsreturns_graphc              #   T  #    U S:  a  [         e[        [        U S-  S-   5      5      [        [        SU S-   S-  5      5      -   nUb_  [        U5      nUbK  US:X  a  [	        U5      v   O,US:X  a&  SSKnUR                  S[        SS9  [        U5      v   [        U5      nUb  M^  gg7f)	a  Generates lists of nonisomorphic trees

Parameters
----------
order : int
   order of the desired tree(s)

create : one of {"graph", "matrix"} (default="graph")
   If ``"graph"`` is selected a list of ``Graph`` instances will be returned,
   if matrix is selected a list of adjacency matrices will be returned.

   .. deprecated:: 3.3

      The `create` argument is deprecated and will be removed in NetworkX
      version 3.5. In the future, `nonisomorphic_trees` will yield graph
      instances by default. To generate adjacency matrices, call
      ``nx.to_numpy_array`` on the output, e.g.::

         [nx.to_numpy_array(G) for G in nx.nonisomorphic_trees(N)]

Yields
------
list
   A list of nonisomorphic trees, in one of two formats depending on the
   value of the `create` parameter:
   - ``create="graph"``: yields a list of `networkx.Graph` instances
   - ``create="matrix"``: yields a list of list-of-lists representing adjacency matrices
      Ngraphmatrixr   z

The 'create=matrix' argument of nonisomorphic_trees
is deprecated and will be removed in version 3.5.
Use ``nx.to_numpy_array`` to convert graphs to adjacency matrices, e.g.::

   [nx.to_numpy_array(G) for G in nx.nonisomorphic_trees(N)])category
stacklevel)

ValueErrorlistrange
_next_tree_layout_to_graphwarningswarnDeprecationWarning_layout_to_matrix_next_rooted_tree)ordercreatelayoutr   s       Y/var/www/html/env/lib/python3.13/site-packages/networkx/generators/nonisomorphic_trees.pyr   r      s     > qy%
Q'(4a%!)9I0J+KKF

F# &v..8#W 0   
 (//&v.F+ 
s   B"B(&B()r   c                 8    [        S [        U 5       5       5      $ )zReturns the number of nonisomorphic trees

Parameters
----------
order : int
  order of the desired tree(s)

Returns
-------
length : Number of nonisomorphic graphs for the given order

References
----------

c              3   &   #    U  H  nS v   M	     g7f)r	   N ).0_s     r   	<genexpr>0number_of_nonisomorphic_trees.<locals>.<genexpr>\   s     54Qq4s   )sumr   )r   s    r   r   r   K   s    " 5-e4555    c                    Uc%  [        U 5      S-
  nX   S:X  a  US-  nX   S:X  a  M  US:X  a  gUS-
  nX   X   S-
  :w  a  US-  nX   X   S-
  :w  a  M  [        U 5      n[        U[        U5      5       H  nX4U-
  U-      X4'   M     U$ )z0One iteration of the Beyer-Hedetniemi algorithm.Nr	   r   )lenr   r   )predecessorpqresultis        r   r   r   _   s     	yq n!FA n!Av	AA
.KNQ.
.	Q .KNQ.
.+F1c&k"q519%	 #Mr$   c                    [        U 5      u  p[        U5      n[        U5      nXC:  nU(       a?  XC:X  a:  [        U5      [        U5      :  a  SnO[        U5      [        U5      :X  a  X:  a  SnU(       a  U $ [        U5      n[        X5      nX   S:  a5  [        U5      u  p[        U5      n
[	        SU
S-   5      nX[        U5      * S& U$ )zCOne iteration of the Wright, Richmond, Odlyzko and McKay
algorithm.Fr   r	   N)_split_treemaxr&   r   r   )	candidateleftrestleft_heightrest_heightvalidr(   new_candidatenew_leftnew_restnew_left_heightsuffixs               r   r   r   r   s     Y'JD d)Kd)K&E+ t9s4y E Y#d)#E I))7<!!,]!;H!(mO1o12F,23v;,.)r$   c                 >   SnSn[        [        U 5      5       H  nX   S:X  d  M  U(       a  Un  OSnM     Uc  [        U 5      n[        SU5       Vs/ s H
  o0U   S-
  PM     nnS/[        U[        U 5      5       Vs/ s H  o0U   PM	     sn-   nXE4$ s  snf s  snf )zReturns a tuple of two layouts, one containing the left
subtree of the root vertex, and one containing the original tree
with the left subtree removed.FNr	   Tr   )r   r&   )r   	one_foundmr+   r0   r1   s         r   r-   r-      s    
 IA3v;9> 	   	yK#(A;/;a1IM;D/3U1c&k%:;%:)%:;;D< 0;s   B?Bc                 \   [        [        U 5      5       Vs/ s H  nS/[        U 5      -  PM     nn/ n[        [        U 5      5       H[  nX   nU(       a<  US   nX   nXd:  a   UR                  5         US   nX   nXd:  a  M   S=X!   U'   X%   U'   UR                  U5        M]     U$ s  snf )zXCreate the adjacency matrix for the tree specified by the
given layout (level sequence).r   r	   )r   r&   popappend)r   r+   r*   stacki_leveljj_levels          r   r   r      s     */s6{);<);AqcCK);F<E3v;)b	AiG$		"I ) $ +,+FIaL69Q<Q   M =s   B)c                     [         R                  " 5       n/ n[        [        U 5      5       H^  nX   nU(       a?  US   nX   nXd:  a   UR	                  5         US   nX   nXd:  a  M   UR                  X55        UR                  U5        M`     U$ )zRCreate a NetworkX Graph for the tree specified by the
given layout(level sequence)r>   )nxGraphr   r&   r?   add_edger@   )r   GrA   r+   rB   rC   rD   s          r   r   r      s     	
AE3v;)b	AiG$		"I ) $ JJqQ   Hr$   )r
   )N)__doc____all__networkxrF   _dispatchabler   r   r   r   r-   r   r   r   r$   r   <module>rN      su    !"A
B  T28/ 38/v 6 6&&$N.(r$   