§
    bŠtjÕÉ  ã                   ó<  — d Z ddlZddlZddlmZ ddlZddlmZ ddl	m
Z
 ddlmZmZmZmZ dd	lmZ g d
¢Z ed¦  «         ej        dd¬¦  «        d&ddœd„¦   «         ¦   «         Z ed¦  «         ej        dd¬¦  «        d&ddœd„¦   «         ¦   «         ZeZeZ ed¦  «         ej        dd¬¦  «        d'ddœd„¦   «         ¦   «         Z ed¦  «         ej        dd¬¦  «        d&ddœd„¦   «         ¦   «         Z ed¦  «         ej        dd¬¦  «        d'ddœd„¦   «         ¦   «         Z ed¦  «         ej        dd¬¦  «        d'ddœd„¦   «         ¦   «         Z ed¦  «         ej        dd¬¦  «        d(ddœd„¦   «         ¦   «         Z ed¦  «         ej        dd¬¦  «        d'ddœd„¦   «         ¦   «         Zd„ Z ed¦  «         ej        dd¬¦  «        d)ddœd„¦   «         ¦   «         Z ed¦  «         ej        dd¬¦  «        	 d)ddœd„¦   «         ¦   «         Z  ed¦  «         ej        dd¬¦  «        d'ddœd„¦   «         ¦   «         Z! ed¦  «         ej        dd¬¦  «        d'ddœd„¦   «         ¦   «         Z" ed¦  «         ej        dd¬¦  «        d'ddœd„¦   «         ¦   «         Z# ed¦  «         ej        dd¬¦  «        d'ddœd „¦   «         ¦   «         Z$ ed¦  «         ej        dd¬¦  «        d'ddœd!„¦   «         ¦   «         Z% ed¦  «         ej        dd¬¦  «        d*ddœd"„¦   «         ¦   «         Z& ed¦  «         ej        d¬#¦  «        d*d$„¦   «         ¦   «         Z' ed¦  «         ej        dd¬¦  «        	 d)ddœd%„¦   «         ¦   «         Z(dS )+z 
Generators for random graphs.

é    N)Údefaultdict)Úpy_random_stateé   )Úcheck_create_usingé   )Úcomplete_graphÚempty_graphÚ
path_graphÚ
star_graph)Údegree_sequence_tree)Úfast_gnp_random_graphÚgnp_random_graphÚdense_gnm_random_graphÚgnm_random_graphÚerdos_renyi_graphÚbinomial_graphÚnewman_watts_strogatz_graphÚwatts_strogatz_graphÚconnected_watts_strogatz_graphÚrandom_regular_graphÚbarabasi_albert_graphÚdual_barabasi_albert_graphÚextended_barabasi_albert_graphÚpowerlaw_cluster_graphÚrandom_lobsterÚrandom_lobster_graphÚrandom_shell_graphÚrandom_powerlaw_treeÚrandom_powerlaw_tree_sequenceÚrandom_kernel_graphT)ÚgraphsÚreturns_graphF©Úcreate_usingc                ó:  — |rt           j        nt           j        }t          ||d|¬¦  «        }|dk    s|dk    rt          j        | ||||¬¦  «        S t          | |¬¦  «        }t          j        d|z
  ¦  «        }|r�d}d}	|| k     r…t          j        d|                     ¦   «         z
  ¦  «        }
|	dz   t          |
|z  ¦  «        z   }	|	|k    r|| k     r|	|z
  }	|dz   }|	|k    r|| k     °|| k     r| 
                    |	|¦  «         || k     °…d}d}	|| k     r…t          j        d|                     ¦   «         z
  ¦  «        }
|	dz   t          |
|z  ¦  «        z   }	|	|k    r|| k     r|	|z
  }	|dz   }|	|k    r|| k     °|| k     r| 
                    ||	¦  «         || k     °…|S )	u¹  Returns a $G_{n,p}$ random graph, also known as an ErdÅ‘s-RÃ©nyi graph or
    a binomial graph.

    Parameters
    ----------
    n : int
        The number of nodes.
    p : float
        Probability for edge creation.
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    directed : bool, optional (default=False)
        If True, this function returns a directed graph.
    create_using : Graph constructor, optional (default=nx.Graph or nx.DiGraph)
        Graph type to create. If graph instance, then cleared before populated.
        Multigraph types are not supported and raise a ``NetworkXError``.
        By default NetworkX Graph or DiGraph are used depending on `directed`.

    Notes
    -----
    The $G_{n,p}$ graph algorithm chooses each of the $[n (n - 1)] / 2$
    (undirected) or $n (n - 1)$ (directed) possible edges with probability $p$.

    This algorithm [1]_ runs in $O(n + m)$ time, where `m` is the expected number of
    edges, which equals $p n (n - 1) / 2$. This should be faster than
    :func:`gnp_random_graph` when $p$ is small and the expected number of edges
    is small (that is, the graph is sparse).

    See Also
    --------
    gnp_random_graph

    References
    ----------
    .. [1] Vladimir Batagelj and Ulrik Brandes,
       "Efficient generation of large random networks",
       Phys. Rev. E, 71, 036113, 2005.
    F©ÚdirectedÚ
multigraphÚdefaultr   r   )Úseedr'   r$   r#   g      ð?éÿÿÿÿ)ÚnxÚDiGraphÚGraphr   r   r	   ÚmathÚlogÚrandomÚintÚadd_edge)ÚnÚpr*   r'   r$   r)   ÚGÚlpÚvÚwÚlrs              ú_/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/networkx/generators/random_graphs.pyr   r   )   sò  € ðT %Ð2�bŒjˆj­"¬(€GÝ%Ø˜x°EÀ7ðñ ô €Lð 	ˆA‚v€v��a’�ÝÔ"Øˆq�t h¸\ð
ñ 
ô 
ð 	
õ 	�A LÐ1Ñ1Ô1€Aå	Œ�#˜‘'Ñ	Ô	€Bàð 
!ØˆØˆØ�!ŠeˆeÝ”˜# §¢¡¤Ñ-Ñ.Ô.ˆBØ�A‘�˜B ™G™œÑ$ˆAØ�q’&�&˜Q šU˜UØ˜‘E�Ø˜‘E�ð �q’&�&˜Q šU˜Uð �1ŠuˆuØ—
’
˜1˜aÑ Ô Ð ð �!Šeˆeð 	
€AØ
€AØ
ˆaŠ%ˆ%ÝŒX�c˜DŸKšK™MœMÑ)Ñ*Ô*ˆØ�‰E•C˜˜R™‘L”LÑ ˆØ�1Šfˆf˜˜Qš˜Ø�A‘ˆAØ�A‘ˆAð �1Šfˆf˜˜Qš˜ð ˆqŠ5ˆ5Ø�JŠJ�q˜!ÑÔÐð ˆaŠ%ˆ%ð €Hó    c                óz  — |rt           j        nt           j        }t          ||d|¬¦  «        }|dk    rt	          | |¬¦  «        S t          j        | |¬¦  «        }|dk    r|S |rt          j        nt          j        } |t          | ¦  «        d¦  «        D ]$}| 
                    ¦   «         |k     r
 |j        |Ž  Œ%|S )uì  Returns a $G_{n,p}$ random graph, also known as an ErdÅ‘s-RÃ©nyi graph
    or a binomial graph.

    The $G_{n,p}$ model chooses each of the possible edges with probability $p$.

    Parameters
    ----------
    n : int
        The number of nodes.
    p : float
        Probability for edge creation.
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    directed : bool, optional (default=False)
        If True, this function returns a directed graph.
    create_using : Graph constructor, optional (default=nx.Graph or nx.DiGraph)
        Graph type to create. If graph instance, then cleared before populated.
        Multigraph types are not supported and raise a ``NetworkXError``.
        By default NetworkX Graph or DiGraph are used depending on `directed`.

    See Also
    --------
    fast_gnp_random_graph

    Notes
    -----
    This algorithm [2]_ runs in $O(n^2)$ time.  For sparse graphs (that is, for
    small values of $p$), :func:`fast_gnp_random_graph` is a faster algorithm.

    :func:`binomial_graph` and :func:`erdos_renyi_graph` are
    aliases for :func:`gnp_random_graph`.

    >>> nx.binomial_graph is nx.gnp_random_graph
    True
    >>> nx.erdos_renyi_graph is nx.gnp_random_graph
    True

    References
    ----------
    .. [1] P. ErdÅ‘s and A. RÃ©nyi, On Random Graphs, Publ. Math. 6, 290 (1959).
    .. [2] E. N. Gilbert, Random Graphs, Ann. Math. Stat., 30, 1141 (1959).
    Fr&   r   r#   r   r   )r,   r-   r.   r   r   r	   Ú	itertoolsÚpermutationsÚcombinationsÚranger1   r3   )	r4   r5   r*   r'   r$   r)   r6   ÚedgetoolÚes	            r;   r   r   z   sÐ   € ð\ %Ð2�bŒjˆj­"¬(€GÝ%Ø˜x°EÀ7ðñ ô €Lð 	ˆA‚v€vÝ˜a¨lÐ;Ñ;Ô;Ð;å
Œ�q |Ð4Ñ4Ô4€AØˆA‚v€vØˆà)1ÐM�yÔ%Ð%µyÔ7M€HØˆX•e˜A‘h”h Ñ"Ô"ð ð ˆØ�;Š;‰=Œ=˜1ÒÐØˆAŒJ˜ˆNˆNøØ€Hr<   c                ód  — t          |dd¬¦  «        }| | dz
  z  dz  }||k    rt          | |¦  «        S t          | |¦  «        }| dk    r|S d}d}d}d}		 |                     ||z
  ¦  «        ||	z
  k     r#|                     ||¦  «         |	dz  }	|	|k    r|S |dz  }|dz  }|| k    r
|dz  }|dz   }Œ])ao  Returns a $G_{n,m}$ random graph.

    In the $G_{n,m}$ model, a graph is chosen uniformly at random from the set
    of all graphs with $n$ nodes and $m$ edges.

    This algorithm should be faster than :func:`gnm_random_graph` for dense
    graphs.

    Parameters
    ----------
    n : int
        The number of nodes.
    m : int
        The number of edges.
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    create_using : Graph constructor, optional (default=nx.Graph)
        Graph type to create. If graph instance, then cleared before populated.
        Multigraph and directed types are not supported and raise a ``NetworkXError``.

    See Also
    --------
    gnm_random_graph

    Notes
    -----
    Algorithm by Keith M. Briggs Mar 31, 2006.
    Inspired by Knuth's Algorithm S (Selection sampling technique),
    in section 3.4.2 of [1]_.

    References
    ----------
    .. [1] Donald E. Knuth, The Art of Computer Programming,
        Volume 2/Seminumerical algorithms, Third Edition, Addison-Wesley, 1997.
    F©r'   r(   r   r   r   )r   r   r	   Ú	randranger3   )
r4   Úmr*   r$   Úmmaxr6   Úur8   ÚtÚks
             r;   r   r   ¿   sö   € õN & l¸UÈuÐUÑUÔU€LØ��A‘‰;˜!Ñ€DØˆD‚y€yÝ˜a Ñ.Ô.Ð.Ý�A�|Ñ$Ô$€AàˆA‚v€vØˆà	€AØ	€AØ	€AØ	€Að
Ø�>Š>˜$ ™(Ñ#Ô# a¨!¡eÒ+Ð+Ø�JŠJ�q˜!ÑÔÐØ�‰FˆAØ�AŠvˆvØ�Ø	ˆQ‰ˆØ	ˆQ‰ˆØ�Š6ˆ6Ø�‰FˆAØ�A‘ˆAð
r<   c                ó  — |rt           j        nt           j        }t          ||d|¬¦  «        }| dk    rt          j        | |¬¦  «        S |r| | dz
  z  n
| | dz
  z  dz  }||k    rt          | |¬¦  «        S t          j        | |¬¦  «        }t          |¦  «        }d}	|	|k     rh|                     |¦  «        }
|                     |¦  «        }|
|k    s|                     |
|¦  «        rŒM| 	                    |
|¦  «         |	dz   }	|	|k     °h|S )aÑ  Returns a $G_{n,m}$ random graph.

    In the $G_{n,m}$ model, a graph is chosen uniformly at random from the set
    of all graphs with $n$ nodes and $m$ edges.

    This algorithm should be faster than :func:`dense_gnm_random_graph` for
    sparse graphs.

    Parameters
    ----------
    n : int
        The number of nodes.
    m : int
        The number of edges.
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    directed : bool, optional (default=False)
        If True return a directed graph
    create_using : Graph constructor, optional (default=nx.Graph or nx.DiGraph)
        Graph type to create. If graph instance, then cleared before populated.
        Multigraph types are not supported and raise a ``NetworkXError``.
        By default NetworkX Graph or DiGraph are used depending on `directed`.

    See also
    --------
    dense_gnm_random_graph

    Fr&   r   r#   g       @r   )
r,   r-   r.   r   r	   r   ÚlistÚchoiceÚhas_edger3   )r4   rG   r*   r'   r$   r)   Ú	max_edgesr6   ÚnlistÚ
edge_countrI   r8   s               r;   r   r      s/  € ð@ %Ð2�bŒjˆj­"¬(€GÝ%Ø˜x°EÀ7ðñ ô €Lð 	ˆA‚v€vÝŒ~˜a¨lÐ;Ñ;Ô;Ð;Ø'Ð>��Q˜‘U‘�¨Q°!°a±%©[¸3Ñ->€IØˆI‚~€~Ý˜a¨lÐ;Ñ;Ô;Ð;å
Œ�q |Ð4Ñ4Ô4€AÝ�‰GŒG€EØ€JØ
�qŠ.ˆ.à�KŠK˜ÑÔˆØ�KŠK˜ÑÔˆØ�Š6ˆ6�Q—Z’Z  1Ñ%Ô%ˆ6Øà�JŠJ�q˜!ÑÔÐØ# a™ˆJð �qŠ.ˆ.ð €Hr<   é   c                ó„  — t          |dd¬¦  «        }|| k    rt          j        d¦  «        ‚|| k    rt          j        | |¦  «        S t	          | |¦  «        }t          |                     ¦   «         ¦  «        }|}t          d|dz  dz   ¦  «        D ]X}||d…         |d|…         z   }	t          t          |¦  «        ¦  «        D ]$}
| 	                    ||
         |	|
         ¦  «         Œ%ŒYt          | 
                    ¦   «         ¦  «        }|D ]²\  }}|                     ¦   «         |k     r•|                     |¦  «        }||k    s|                     ||¦  «        rN|                     |¦  «        }|                     |¦  «        | dz
  k    rn2||k    °8|                     ||¦  «        °N| 	                    ||¦  «         Œ³|S )uÁ  Returns a Newmanâ€“Wattsâ€“Strogatz small-world graph.

    Parameters
    ----------
    n : int
        The number of nodes.
    k : int
        Each node is joined with its `k` nearest neighbors in a ring
        topology.
    p : float
        The probability of adding a new edge for each edge.
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    create_using : Graph constructor, optional (default=nx.Graph)
        Graph type to create. If graph instance, then cleared before populated.
        Multigraph and directed types are not supported and raise a ``NetworkXError``.

    Notes
    -----
    First create a ring over $n$ nodes [1]_.  Then each node in the ring is
    connected with its $k$ nearest neighbors (or $k - 1$ neighbors if $k$
    is odd).  Then shortcuts are created by adding new edges as follows: for
    each edge $(u, v)$ in the underlying "$n$-ring with $k$ nearest
    neighbors" with probability $p$ add a new edge $(u, w)$ with
    randomly-chosen existing node $w$.  In contrast with
    :func:`watts_strogatz_graph`, no edges are removed.

    See Also
    --------
    watts_strogatz_graph

    References
    ----------
    .. [1] M. E. J. Newman and D. J. Watts,
       Renormalization group analysis of the small-world network model,
       Physics Letters A, 263, 341, 1999.
       https://doi.org/10.1016/S0375-9601(99)00757-4
    FrE   z"k>=n, choose smaller k or larger nr   r   Nr   )r   r,   ÚNetworkXErrorr   r	   rM   ÚnodesrA   Úlenr3   Úedgesr1   rN   rO   Údegree)r4   rK   r5   r*   r$   r6   rQ   ÚfromvÚjÚtovÚirC   rI   r8   r9   s                  r;   r   r   9  sÄ  € õT & l¸UÈuÐUÑUÔU€LØˆ1‚u€uÝÔÐCÑDÔDÐDð 	ˆA‚v€vÝÔ   LÑ1Ô1Ð1å�A�|Ñ$Ô$€AÝ�—’‘”‰OŒO€EØ€Eå�1�a˜1‘f˜q‘jÑ!Ô!ð )ð )ˆØ�A�B�BŒi˜%  ! œ*Ñ$ˆÝ•s˜5‘z”zÑ"Ô"ð 	)ð 	)ˆAØ�JŠJ�u˜Q”x  Q¤Ñ(Ô(Ð(Ð(ð	)õ 	ˆQ�WŠW‰YŒY‰Œ€AØð 
!ð 
!‰ˆˆ1Ø�;Š;‰=Œ=˜1ÒÐØ—’˜EÑ"Ô"ˆAð �q’&�&˜AŸJšJ q¨!Ñ,Ô,�&Ø—K’K Ñ&Ô&�Ø—8’8˜A‘;”; ! a¡%Ò'Ð'Øð �q’&�&˜AŸJšJ q¨!Ñ,Ô,�&ð
 —
’
˜1˜aÑ Ô Ð øØ€Hr<   c                ó¬  — t          |dd¬¦  «        }|| k    rt          j        d¦  «        ‚|| k    rt          j        | |¦  «        }|S t          j        | |¬¦  «        }t          t          | ¦  «        ¦  «        }t          d|dz  dz   ¦  «        D ]:}||d…         |d|…         z   }|                     t          ||¦  «        ¦  «         Œ;t          d|dz  dz   ¦  «        D ]ð}||d…         |d|…         z   }t          ||¦  «        D ]È\  }	}
| 	                    ¦   «         |k     r«| 
                    |¦  «        }||	k    s|                     |	|¦  «        rN| 
                    |¦  «        }|                     |	¦  «        | dz
  k    rnH||	k    °8|                     |	|¦  «        °N|                     |	|
¦  «         |                     |	|¦  «         ŒÉŒñ|S )	u:  Returns a Wattsâ€“Strogatz small-world graph.

    Parameters
    ----------
    n : int
        The number of nodes
    k : int
        Each node is joined with its `k` nearest neighbors in a ring
        topology.
    p : float
        The probability of rewiring each edge
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    create_using : Graph constructor, optional (default=nx.Graph)
        Graph type to create. If graph instance, then cleared before populated.
        Multigraph and directed types are not supported and raise a ``NetworkXError``.

    See Also
    --------
    newman_watts_strogatz_graph
    connected_watts_strogatz_graph

    Notes
    -----
    First create a ring over $n$ nodes [1]_.  Then each node in the ring is joined
    to its $k$ nearest neighbors (or $k - 1$ neighbors if $k$ is odd).
    Then shortcuts are created by replacing some edges as follows: for each
    edge $(u, v)$ in the underlying "$n$-ring with $k$ nearest neighbors"
    with probability $p$ replace it with a new edge $(u, w)$ with uniformly
    random choice of existing node $w$.

    In contrast with :func:`newman_watts_strogatz_graph`, the random rewiring
    does not increase the number of edges. The rewired graph is not guaranteed
    to be connected as in :func:`connected_watts_strogatz_graph`.

    References
    ----------
    .. [1] Duncan J. Watts and Steven H. Strogatz,
       Collective dynamics of small-world networks,
       Nature, 393, pp. 440--442, 1998.
    FrE   z!k>n, choose smaller k or larger nr#   r   r   Nr   )r   r,   rU   r   r	   rM   rA   Úadd_edges_fromÚzipr1   rN   rO   rY   Úremove_edger3   )r4   rK   r5   r*   r$   r6   rV   r[   ÚtargetsrI   r8   r9   s               r;   r   r   „  sñ  € õZ & l¸UÈuÐUÑUÔU€LØˆ1‚u€uÝÔÐBÑCÔCÐCð 	ˆA‚v€vÝÔ˜a Ñ.Ô.ˆØˆå
Œ�q |Ð4Ñ4Ô4€AÝ•�q‘”‰NŒN€Eå�1�a˜1‘f˜q‘jÑ!Ô!ð .ð .ˆØ˜˜˜”)˜e A a CœjÑ(ˆØ	×Ò�˜U GÑ,Ô,Ñ-Ô-Ð-Ð-õ �1�a˜1‘f˜q‘jÑ!Ô!ð %ð %ˆØ˜˜˜”)˜e A a CœjÑ(ˆå˜˜wÑ'Ô'ð 
	%ð 
	%‰DˆAˆqØ�{Š{‰}Œ}˜qÒ Ð Ø—K’K Ñ&Ô&�à˜1’f�f §
¢
¨1¨aÑ 0Ô 0�fØŸš EÑ*Ô*�AØ—x’x ‘{”{ a¨!¡eÒ+Ð+Øð ˜1’f�f §
¢
¨1¨aÑ 0Ô 0�fð
 —M’M ! QÑ'Ô'Ð'Ø—J’J˜q !Ñ$Ô$Ð$øð
	%ð €Hr<   é   éd   c                ó¦   — t          |¦  «        D ].}t          | ||||¬¦  «        }t          j        |¦  «        r|c S Œ/t          j        d¦  «        ‚)uŸ  Returns a connected Wattsâ€“Strogatz small-world graph.

    Attempts to generate a connected graph by repeated generation of
    Wattsâ€“Strogatz small-world graphs.  An exception is raised if the maximum
    number of tries is exceeded.

    Parameters
    ----------
    n : int
        The number of nodes
    k : int
        Each node is joined with its `k` nearest neighbors in a ring
        topology.
    p : float
        The probability of rewiring each edge
    tries : int
        Number of attempts to generate a connected graph.
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    create_using : Graph constructor, optional (default=nx.Graph)
        Graph type to create. If graph instance, then cleared before populated.
        Multigraph and directed types are not supported and raise a ``NetworkXError``.

    Notes
    -----
    First create a ring over $n$ nodes [1]_.  Then each node in the ring is joined
    to its $k$ nearest neighbors (or $k - 1$ neighbors if $k$ is odd).
    Then shortcuts are created by replacing some edges as follows: for each
    edge $(u, v)$ in the underlying "$n$-ring with $k$ nearest neighbors"
    with probability $p$ replace it with a new edge $(u, w)$ with uniformly
    random choice of existing node $w$.
    The entire process is repeated until a connected graph results.

    See Also
    --------
    newman_watts_strogatz_graph
    watts_strogatz_graph

    References
    ----------
    .. [1] Duncan J. Watts and Steven H. Strogatz,
       Collective dynamics of small-world networks,
       Nature, 393, pp. 440--442, 1998.
    r#   z Maximum number of tries exceeded)rA   r   r,   Úis_connectedrU   )r4   rK   r5   Útriesr*   r$   r]   r6   s           r;   r   r   Ô  sd   € õ` �5‰\Œ\ð ð ˆå   A q¨$¸\ÐJÑJÔJˆÝŒ?˜1ÑÔð 	ØˆHˆHˆHð	å
Ô
Ð=Ñ
>Ô
>Ð>r<   c                ód  ‡ ‡‡‡— t          |dd¬¦  «        }‰‰ z  dz  dk    rt          j        d¦  «        ‚d‰ cxk    r‰k     sn t          j        d¦  «        ‚t          j        ‰|¬¦  «        }‰ dk    r|S d„ Šˆˆ ˆˆfd	„} |¦   «         }|€ |¦   «         }|®|                     |¦  «         |S )
a)  Returns a random $d$-regular graph on $n$ nodes.

    A regular graph is a graph where each node has the same number of neighbors.

    The resulting graph has no self-loops or parallel edges.

    Parameters
    ----------
    d : int
      The degree of each node.
    n : integer
      The number of nodes. The value of $n \times d$ must be even.
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    create_using : Graph constructor, optional (default=nx.Graph)
        Graph type to create. If graph instance, then cleared before populated.
        Multigraph and directed types are not supported and raise a ``NetworkXError``.

    Notes
    -----
    The nodes are numbered from $0$ to $n - 1$.

    Kim and Vu's paper [2]_ shows that this algorithm samples in an
    asymptotically uniform way from the space of random graphs when
    $d = O(n^{1 / 3 - \epsilon})$.

    Raises
    ------

    NetworkXError
        If $n \times d$ is odd or $d$ is greater than or equal to $n$.

    References
    ----------
    .. [1] A. Steger and N. Wormald,
       Generating random regular graphs quickly,
       Probability and Computing 8 (1999), 377-396, 1999.
       https://doi.org/10.1017/S0963548399003867

    .. [2] Jeong Han Kim and Van H. Vu,
       Generating random regular graphs,
       Proceedings of the thirty-fifth ACM symposium on Theory of computing,
       San Diego, CA, USA, pp 213--222, 2003.
       http://portal.acm.org/citation.cfm?id=780542.780576
    FrE   r   r   zn * d must be evenz+the 0 <= d < n inequality must be satisfiedr#   c                 óZ   — |sdS |D ]#}|D ]}||k    r n||k    r||}}||f| vr  dS ŒŒ$dS )NTF© )rX   Úpotential_edgesÚs1Ús2s       r;   Ú	_suitablez'random_regular_graph.<locals>._suitableI  st   € ð ð 	Ø�4Ø!ð 	 ð 	 ˆBØ%ð 
 ð 
 �ð ˜’8�8à�EØ˜’7�7Ø ˜�BØ˜�8 5Ð(Ð(Ø˜4˜4˜4ð )øàˆur<   c                  óò  •— t          ¦   «         } t          t          ‰¦  «        ¦  «        ‰z  }|rÆt          d„ ¦  «        }‰	                     |¦  «         t          |¦  «        }t          ||¦  «        D ]S\  }}||k    r||}}||k    r||f| vr|                      ||f¦  «         Œ3||xx         dz  cc<   ||xx         dz  cc<   ŒT ‰| |¦  «        sd S d„ |                     ¦   «         D ¦   «         }|°Æ| S )Nc                  ó   — dS )Nr   rj   rj   r<   r;   ú<lambda>z=random_regular_graph.<locals>._try_creation.<locals>.<lambda>c  s   € °!€ r<   r   c                 ó<   — g | ]\  }}t          |¦  «        D ]}|‘ŒŒS rj   ©rA   )Ú.0ÚnodeÚ	potentialÚ_s       r;   ú
<listcomp>z?random_regular_graph.<locals>._try_creation.<locals>.<listcomp>r  sK   € ð ð ð á#�D˜)Ý˜yÑ)Ô)ðð ð ð ðð ð ð r<   )	ÚsetrM   rA   r   ÚshuffleÚiterr`   ÚaddÚitems)
rX   Ústubsrk   Ústubiterrl   rm   rn   Údr4   r*   s
         €€€€r;   Ú_try_creationz+random_regular_graph.<locals>._try_creation\  sF  ø€ õ ‘”ˆÝ•U˜1‘X”X‘” Ñ"ˆàð 	Ý)¨)¨)Ñ4Ô4ˆOØ�LŠL˜ÑÔÐÝ˜E‘{”{ˆHÝ˜h¨Ñ1Ô1ð -ð -‘��BØ˜’7�7Ø ˜�BØ˜’8�8 " b °Ð!6Ð!6Ø—I’I˜r 2˜hÑ'Ô'Ð'Ð'à# BÐ'Ð'Ô'¨1Ñ,Ð'Ð'Ñ'Ø# BÐ'Ð'Ô'¨1Ñ,Ð'Ð'Ñ'Ð'à�9˜U OÑ4Ô4ð Ø�tðð à'6×'<Ò'<Ñ'>Ô'>ðñ ô ˆEð! ð 	ð* ˆr<   )r   r,   rU   r	   r_   )r€   r4   r*   r$   r6   r�   rX   rn   s   ```    @r;   r   r     s  øøøø€ õb & l¸UÈuÐUÑUÔU€LØ	ˆA‰��{�aÒÐÝÔÐ3Ñ4Ô4Ð4à�ˆ:ˆ:Š:ˆ:�AŠ:ˆ:ˆ:ˆ:ÝÔÐLÑMÔMÐMå
Œ�q |Ð4Ñ4Ô4€AàˆA‚v€vØˆðð ð ð&ð ð ð ð ð ð ð ð@ ˆM‰OŒO€EØ
ˆ-Ø�‘”ˆð ˆ-à×Ò�UÑÔÐà€Hr<   c                 óÂ   — t          ¦   «         }t          |¦  «        |k     r=|                     | ¦  «        }|                     |¦  «         t          |¦  «        |k     °=|S )zÛReturn m unique elements from seq.

    This differs from random.sample which can return repeated
    elements if seq holds repeated elements.

    Note: rng is a random.Random or numpy.random.RandomState instance.
    )ry   rW   rN   r|   )ÚseqrG   Úrngrb   Úxs        r;   Ú_random_subsetr†   „  sV   € õ ‰eŒe€GÝ
ˆg‰,Œ,˜Ò
Ð
Ø�JŠJ�s‰OŒOˆØ�Š�A‰Œˆõ ˆg‰,Œ,˜Ò
Ð
ð €Nr<   c                óŽ  — t          |dd¬¦  «        }|dk     s|| k    rt          j        d|› d| › �¦  «        ‚|€t          ||¦  «        }nUt	          |¦  «        |k     st	          |¦  «        | k    rt          j        d|› d| › d	�¦  «        ‚|                     ¦   «         }d
„ |                     ¦   «         D ¦   «         }t	          |¦  «        }|| k     rqt          |||¦  «        }|                     t          |g|z  |¦  «        ¦  «         | 
                    |¦  «         | 
                    |g|z  ¦  «         |dz  }|| k     °q|S )ue  Returns a random graph using BarabÃ¡siâ€“Albert preferential attachment

    A graph of $n$ nodes is grown by attaching new nodes each with $m$
    edges that are preferentially attached to existing nodes with high degree.

    Parameters
    ----------
    n : int
        Number of nodes
    m : int
        Number of edges to attach from a new node to existing nodes
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    initial_graph : Graph or None (default)
        Initial network for BarabÃ¡siâ€“Albert algorithm.
        It should be a connected graph for most use cases.
        A copy of `initial_graph` is used.
        If None, starts from a star graph on (m+1) nodes.
    create_using : Graph constructor, optional (default=nx.Graph)
        Graph type to create. If graph instance, then cleared before populated.
        Multigraph and directed types are not supported and raise a ``NetworkXError``.

    Returns
    -------
    G : Graph

    Raises
    ------
    NetworkXError
        If `m` does not satisfy ``1 <= m < n``, or
        the initial graph number of nodes m0 does not satisfy ``m <= m0 <= n``.

    References
    ----------
    .. [1] A. L. BarabÃ¡si and R. Albert "Emergence of scaling in
       random networks", Science 286, pp 509-512, 1999.
    FrE   r   u;   BarabÃ¡siâ€“Albert network must have m >= 1 and m < n, m = ú, n = Nu1   BarabÃ¡siâ€“Albert initial graph needs between m=z and n=ú nodesc                 ó<   — g | ]\  }}t          |¦  «        D ]}|‘ŒŒS rj   rs   ©rt   r4   r€   rw   s       r;   rx   z)barabasi_albert_graph.<locals>.<listcomp>Í  ó/   € ÐAÐAÐA™D˜A˜q½¸a¹¼ÐAÐA°1�aÐAÐAÐAÐAr<   )r   r,   rU   r   rW   ÚcopyrY   r†   r_   r`   Úextend)	r4   rG   r*   Úinitial_graphr$   r6   Úrepeated_nodesÚsourcerb   s	            r;   r   r   “  s�  € õR & l¸UÈuÐUÑUÔU€LØˆ1‚u€u��Q’�ÝÔØVÈ!ÐVÐVÐSTÐVÐVñ
ô 
ð 	
ð Ðå�q˜,Ñ'Ô'ˆˆåˆ}ÑÔ Ò!Ð!¥S¨Ñ%7Ô%7¸!Ò%;Ð%;ÝÔ"ØWÀAÐWÐWÈaÐWÐWÐWñô ð ð ×ÒÑ Ô ˆð BÐA A§H¢H¡J¤JÐAÑAÔA€Nå�‰VŒV€FØ
�1Š*ˆ*õ ! °°DÑ9Ô9ˆà	×Ò�˜f˜X¨™\¨7Ñ3Ô3Ñ4Ô4Ð4à×Ò˜gÑ&Ô&Ð&à×Ò˜v˜h¨™lÑ+Ô+Ð+à�!‰ˆð �1Š*ˆ*ð €Hr<   c                ó0  — t          |dd¬¦  «        }|dk     s|| k    rt          j        d|› d| › �¦  «        ‚|dk     s|| k    rt          j        d|› d| › �¦  «        ‚|dk     s|dk    rt          j        d|› �¦  «        ‚|dk    rt          | |||¬	¦  «        S |dk    rt          | |||¬	¦  «        S |€t	          t          ||¦  «        |¦  «        }nqt          |¦  «        t          ||¦  «        k     st          |¦  «        | k    r)t          j        dt          ||¦  «        › d| › d�¦  «        ‚|                     ¦   «         }t          |¦  «        }d„ | 	                    ¦   «         D ¦   «         }	t          |¦  «        }
|
| k     rŽ| 
                    ¦   «         |k     r|}n|}t          |	||¦  «        }|                     t          |
g|z  |¦  «        ¦  «         |	                     |¦  «         |	                     |
g|z  ¦  «         |
dz  }
|
| k     °Ž|S )u˜  Returns a random graph using dual BarabÃ¡siâ€“Albert preferential attachment

    A graph of $n$ nodes is grown by attaching new nodes each with either $m_1$
    edges (with probability $p$) or $m_2$ edges (with probability $1-p$) that
    are preferentially attached to existing nodes with high degree.

    Parameters
    ----------
    n : int
        Number of nodes
    m1 : int
        Number of edges to link each new node to existing nodes with probability $p$
    m2 : int
        Number of edges to link each new node to existing nodes with probability $1-p$
    p : float
        The probability of attaching $m_1$ edges (as opposed to $m_2$ edges)
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    initial_graph : Graph or None (default)
        Initial network for BarabÃ¡siâ€“Albert algorithm.
        A copy of `initial_graph` is used.
        It should be connected for most use cases.
        If None, starts from an star graph on max(m1, m2) + 1 nodes.
    create_using : Graph constructor, optional (default=nx.Graph)
        Graph type to create. If graph instance, then cleared before populated.
        Multigraph and directed types are not supported and raise a ``NetworkXError``.

    Returns
    -------
    G : Graph

    Raises
    ------
    NetworkXError
        If `m1` and `m2` do not satisfy ``1 <= m1,m2 < n``, or
        `p` does not satisfy ``0 <= p <= 1``, or
        the initial graph number of nodes m0 does not satisfy m1, m2 <= m0 <= n.

    References
    ----------
    .. [1] N. Moshiri "The dual-Barabasi-Albert model", arXiv:1810.10538.
    FrE   r   u;   Dual BarabÃ¡siâ€“Albert must have m1 >= 1 and m1 < n, m1 = rˆ   u;   Dual BarabÃ¡siâ€“Albert must have m2 >= 1 and m2 < n, m2 = r   u;   Dual BarabÃ¡siâ€“Albert network must have 0 <= p <= 1, p = r#   NuA   BarabÃ¡siâ€“Albert initial graph must have between max(m1, m2) = z	 and n = r‰   c                 ó<   — g | ]\  }}t          |¦  «        D ]}|‘ŒŒS rj   rs   r‹   s       r;   rx   z.dual_barabasi_albert_graph.<locals>.<listcomp>1  rŒ   r<   )r   r,   rU   r   r   ÚmaxrW   r�   rM   rY   r1   r†   r_   r`   rŽ   )r4   Úm1Úm2r5   r*   r�   r$   r6   rb   r�   r‘   rG   s               r;   r   r   ß  s…  € õ` & l¸UÈuÐUÑUÔU€LØ	ˆA‚v€v��q’�ÝÔØWÈ"ÐWÐWÐTUÐWÐWñ
ô 
ð 	
ð 
ˆA‚v€v��q’�ÝÔØWÈ"ÐWÐWÐTUÐWÐWñ
ô 
ð 	
ð 	ˆ1‚u€u��A’�ÝÔØMÈ!ÐMÐMñ
ô 
ð 	
ð
 	ˆA‚v€vÝ$ Q¨¨D¸|ÐLÑLÔLÐLØ	
ˆaŠˆÝ$ Q¨¨D¸|ÐLÑLÔLÐLàÐå•s˜2˜r‘{”{ LÑ1Ô1ˆˆåˆ}ÑÔ¥ B¨¡¤Ò+Ð+­s°=Ñ/AÔ/AÀAÒ/EÐ/EÝÔ"ðAÝ!$ R¨¡¤ðAð AØ78ðAð Að Añô ð ð ×ÒÑ Ô ˆõ �1‰gŒg€GàAÐA A§H¢H¡J¤JÐAÑAÔA€Nå�‰VŒV€FØ
�1Š*ˆ*à�;Š;‰=Œ=˜1ÒÐØˆAˆAàˆAõ ! °°DÑ9Ô9ˆà	×Ò�˜f˜X¨™\¨7Ñ3Ô3Ñ4Ô4Ð4à×Ò˜gÑ&Ô&Ð&à×Ò˜v˜h¨™lÑ+Ô+Ð+à�!‰ˆð! �1Š*ˆ*ð" €Hr<   c                óð  ‡‡‡— t          |dd¬¦  «        }|dk     s|| k    rd|› d| › �}t          j        |¦  «        ‚||z   dk    rd|› d|› �}t          j        |¦  «        ‚t          ||¦  «        }g }|                     t          |¦  «        ¦  «         |}	|	| k     �rÖ|                     ¦   «         }
t          |¦  «        dz
  Št          |¦  «        ‰z  dz  }|
|k     �rR|                     ¦   «         ||z
  k    �r6ˆfd	„| 	                    ¦   «         D ¦   «         }t          |¦  «        D �]}| 
                    |¦  «        }t          ||         ¦  «        Š‰                     |¦  «         | 
                    ˆfd
„|D ¦   «         ¦  «        }|                     ||¦  «         |                     |¦  «         |                     |¦  «         | 	                    |¦  «        ‰k    r|                     |¦  «         | 	                    |¦  «        ‰k    r||v r|                     |¦  «         �Œ�n;||
cxk    r
||z   k     �r¼n �n¸||                     ¦   «         cxk    r|k     �r˜n �n”ˆfd„| 	                    ¦   «         D ¦   «         }t          |¦  «        D �]b}| 
                    |¦  «        }t          ||         ¦  «        Š| 
                    ‰¦  «        }‰                     |¦  «         | 
                    ˆfd„|D ¦   «         ¦  «        }|                     ||¦  «         |                     ||¦  «         |                     |¦  «         |                     |¦  «         | 	                    |¦  «        dk    r||v r|                     |¦  «         ||v r0| 	                    |¦  «        ‰k    r|                     |¦  «         �Œ4| 	                    |¦  «        dk    r|                     |¦  «         �Œdnnt!          |||¦  «        }|                     t%          |	g|z  |¦  «        ¦  «         |                     |¦  «         |                     |	g|dz   z  ¦  «         |	dz  }	|	| k     �°Ö|S )uu  Returns an extended BarabÃ¡siâ€“Albert model graph.

    An extended BarabÃ¡siâ€“Albert model graph is a random graph constructed
    using preferential attachment. The extended model allows new edges,
    rewired edges or new nodes. Based on the probabilities $p$ and $q$
    with $p + q < 1$, the growing behavior of the graph is determined as:

    1) With $p$ probability, $m$ new edges are added to the graph,
    starting from randomly chosen existing nodes and attached preferentially at the
    other end.

    2) With $q$ probability, $m$ existing edges are rewired
    by randomly choosing an edge and rewiring one end to a preferentially chosen node.

    3) With $(1 - p - q)$ probability, $m$ new nodes are added to the graph
    with edges attached preferentially.

    When $p = q = 0$, the model behaves just like the BarabÃ¡siâ€“Alber model.

    Parameters
    ----------
    n : int
        Number of nodes
    m : int
        Number of edges with which a new node attaches to existing nodes
    p : float
        Probability value for adding an edge between existing nodes. p + q < 1
    q : float
        Probability value of rewiring of existing edges. p + q < 1
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    create_using : Graph constructor, optional (default=nx.Graph)
        Graph type to create. If graph instance, then cleared before populated.
        Multigraph and directed types are not supported and raise a ``NetworkXError``.

    Returns
    -------
    G : Graph

    Raises
    ------
    NetworkXError
        If `m` does not satisfy ``1 <= m < n`` or ``1 >= p + q``

    References
    ----------
    .. [1] Albert, R., & BarabÃ¡si, A. L. (2000)
       Topology of evolving networks: local events and universality
       Physical review letters, 85(24), 5234.
    FrE   r   z7Extended Barabasi-Albert network needs m>=1 and m<n, m=z, n=z5Extended Barabasi-Albert network needs p + q <= 1, p=z, q=r   c                 ó&   •— g | ]\  }}|‰k     ¯|‘ŒS rj   rj   ©rt   ÚndÚdegÚclique_degrees      €r;   rx   z2extended_barabasi_albert_graph.<locals>.<listcomp>�  s'   ø€ ÐRÐRÐR¡W R¨¸cÀMÒ>QÐ>Q˜bÐ>QÐ>QÐ>Qr<   c                 ó   •— g | ]}|‰v¯|‘Œ	S rj   rj   )rt   rš   Úprohibited_nodess     €r;   rx   z2extended_barabasi_albert_graph.<locals>.<listcomp>¨  s$   ø€ ÐVÐVÐV˜B¸2ÐEUÐ;UÐ;U�RÐ;UÐ;UÐ;Ur<   c                 ó:   •— g | ]\  }}d |cxk     r‰k     ¯n n|‘ŒS ©r   rj   r™   s      €r;   rx   z2extended_barabasi_albert_graph.<locals>.<listcomp>¼  s>   ø€ ÐVÐVÐV¡W R¨¸aÀ#Ð>UÐ>UÒ>UÐ>UÈÒ>UÐ>UÐ>UÐ>UÐ>U˜bÐ>UÐ>UÐ>Ur<   c                 ó   •— g | ]}|‰v¯|‘Œ	S rj   rj   )rt   rš   Ú	nbr_nodess     €r;   rx   z2extended_barabasi_albert_graph.<locals>.<listcomp>Ë  s#   ø€ ÐOÐOÐO˜B¸2ÀYÐ;NÐ;N�RÐ;NÐ;NÐ;Nr<   r   )r   r,   rU   r	   rŽ   rA   r1   rW   ÚsizerY   rN   rM   Úappendr3   Úremovera   r†   r_   r`   )r4   rG   r5   Úqr*   r$   Úmsgr6   Úattachment_preferenceÚnew_nodeÚa_probabilityÚclique_sizeÚeligible_nodesr]   Úsrc_nodeÚ	dest_noderu   rb   rœ   r¢   rž   s                     @@@r;   r   r   H  sà  øøø€ õl & l¸UÈuÐUÑUÔU€LØˆ1‚u€u��Q’�ØRÈÐRÐRÈqÐRÐRˆÝÔ˜sÑ#Ô#Ð#Øˆ1�u�‚z€zØPÀaÐPÐPÈQÐPÐPˆÝÔ˜sÑ#Ô#Ð#õ 	�A�|Ñ$Ô$€Að ÐØ× Ò ¥ q¡¤Ñ*Ô*Ð*ð €HØ
�QŠ,‰,ØŸš™œˆõ ˜A™œ ™
ˆÝ˜1‘v”v Ñ-°Ñ2ˆð ˜1ÒÑ §¢¡¤¨[¸1©_Ò!<Ñ!<àRÐRÐRÐR°·²±
´
ÐRÑRÔRˆNÝ˜1‘X”Xð 5ñ 5�àŸ;š; ~Ñ6Ô6�õ $(¨¨(¬Ñ#4Ô#4Ð Ø ×'Ò'¨Ñ1Ô1Ð1à ŸKšKØVÐVÐVÐVÐ"7ÐVÑVÔVñô �	ð —
’
˜8 YÑ/Ô/Ð/ð &×,Ò,¨XÑ6Ô6Ð6Ø%×,Ò,¨YÑ7Ô7Ð7ð —8’8˜HÑ%Ô%¨Ò6Ð6Ø"×)Ò)¨(Ñ3Ô3Ð3Ø—8’8˜IÑ&Ô&¨-Ò7Ð7¸IÈÐ<WÐ<WØ"×)Ò)¨)Ñ4Ô4Ð4ùñ/5ð4 �-Ð)Ð)Ò)Ð) 1 q¡5Ò)Ñ)Ð)Ð)Ñ)¨a°1·6²6±8´8Ð.IÐ.IÒ.IÐ.I¸kÒ.IÑ.IÐ.IÐ.IÑ.Ið WÐVÐVÐV°·²±
´
ÐVÑVÔVˆNÝ˜1‘X”Xð !9ñ !9�à—{’{ >Ñ2Ô2�õ !  4¤™MœM�	ð  Ÿ;š; yÑ1Ô1�ð × Ò  Ñ&Ô&Ð&Ø ŸKšKØOÐOÐOÐOÐ"7ÐOÑOÔOñô �	ð —’˜d HÑ-Ô-Ð-Ø—
’
˜4 Ñ+Ô+Ð+ð &×,Ò,¨XÑ6Ô6Ð6Ø%×,Ò,¨YÑ7Ô7Ð7ð —8’8˜HÑ%Ô%¨Ò*Ð*¨x¸>Ð/IÐ/IØ"×)Ò)¨(Ñ3Ô3Ð3Ø Ð.Ð.Ø—x’x 	Ñ*Ô*¨mÒ;Ð;Ø&×-Ò-¨iÑ8Ô8Ð8ùà—x’x 	Ñ*Ô*¨aÒ/Ð/Ø&×-Ò-¨iÑ8Ô8Ð8ùðC!9õL %Ð%:¸A¸tÑDÔDˆGØ×Ò�S ( ¨a¡°Ñ9Ô9Ñ:Ô:Ð:ð "×(Ò(¨Ñ1Ô1Ð1à!×(Ò(¨(¨°q¸1±uÑ)=Ñ>Ô>Ð>Ø˜‰MˆHðo �QŠ,‰,ðp €Hr<   c                ó¢  ‡‡— t          |dd¬¦  «        }|dk     s| |k     rt          j        d|› d| › �¦  «        ‚|dk    s|dk     rt          j        d|› �¦  «        ‚t          ||¦  «        Št	          ‰¦  «        }|Š‰| k     �rIt          |||¦  «        }|                     ¦   «         }‰                     ‰|¦  «         |                     |¦  «         d}||k     rÌ| 	                    ¦   «         |k     rjˆˆfd„‰ 
                    |¦  «        D ¦   «         }	|	rF|                     |	¦  «        }
‰                     ‰|
¦  «         |                     |
¦  «         |dz   }Œˆ|                     ¦   «         }‰                     ‰|¦  «         |                     |¦  «         |dz   }||k     °Ì|                     ‰g|z  ¦  «         ‰dz  Š‰| k     �°I‰S )	u  Holme and Kim algorithm for growing graphs with powerlaw
    degree distribution and approximate average clustering.

    Parameters
    ----------
    n : int
        the number of nodes
    m : int
        the number of random edges to add for each new node
    p : float,
        Probability of adding a triangle after adding a random edge
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    create_using : Graph constructor, optional (default=nx.Graph)
        Graph type to create. If graph instance, then cleared before populated.
        Multigraph and directed types are not supported and raise a ``NetworkXError``.

    Notes
    -----
    The average clustering has a hard time getting above a certain
    cutoff that depends on `m`.  This cutoff is often quite low.  The
    transitivity (fraction of triangles to possible triangles) seems to
    decrease with network size.

    It is essentially the BarabÃ¡siâ€“Albert (BA) growth model with an
    extra step that each random edge is followed by a chance of
    making an edge to one of its neighbors too (and thus a triangle).

    This algorithm improves on BA in the sense that it enables a
    higher average clustering to be attained if desired.

    It seems possible to have a disconnected graph with this algorithm
    since the initial `m` nodes may not be all linked to a new node
    on the first iteration like the BA model.

    Raises
    ------
    NetworkXError
        If `m` does not satisfy ``1 <= m <= n`` or `p` does not
        satisfy ``0 <= p <= 1``.

    References
    ----------
    .. [1] P. Holme and B. J. Kim,
       "Growing scale-free networks with tunable clustering",
       Phys. Rev. E, 65, 026107, 2002.
    FrE   r   z'NetworkXError must have m>1 and m<n, m=z,n=r   z$NetworkXError p must be in [0,1], p=c                 óL   •— g | ] }‰                      ‰|¦  «        s|‰k    ¯|‘Œ!S rj   )rO   )rt   Únbrr6   r‘   s     €€r;   rx   z*powerlaw_cluster_graph.<locals>.<listcomp>5  sB   ø€ ð  ð  ð  àØŸ:š: f¨cÑ2Ô2ð ð 8;¸f²}°}ð à7D°}°}r<   )r   r,   rU   r	   rM   r†   Úpopr3   r¤   r1   Ú	neighborsrN   rŽ   )r4   rG   r5   r*   r$   r�   Úpossible_targetsÚtargetÚcountÚneighborhoodr±   r6   r‘   s              @@r;   r   r   î  s  øø€ õf & l¸UÈuÐUÑUÔU€LØˆ1‚u€u��A’�ÝÔÐRÈÐRÐRÈqÐRÐRÑSÔSÐSàˆ1‚u€u��A’�ÝÔÐIÀaÐIÐIÑJÔJÐJå�A�|Ñ$Ô$€AÝ˜!‘W”W€Nà€FØ
�1Š*‰*Ý)¨.¸!¸TÑBÔBÐà!×%Ò%Ñ'Ô'ˆØ	�
Š
�6˜6Ñ"Ô"Ð"Ø×Ò˜fÑ%Ô%Ð%ØˆØ�aŠiˆiØ�{Š{‰}Œ}˜qÒ Ð ð ð  ð  ð  ð  à Ÿ{š{¨6Ñ2Ô2ð ñ  ô  �ð
  ð ØŸ+š+ lÑ3Ô3�CØ—J’J˜v sÑ+Ô+Ð+Ø"×)Ò)¨#Ñ.Ô.Ð.Ø! A™I�EØà%×)Ò)Ñ+Ô+ˆFØ�JŠJ�v˜vÑ&Ô&Ð&Ø×!Ò! &Ñ)Ô)Ð)Ø˜A‘IˆEð# �aŠiˆið& 	×Ò˜v˜h¨™lÑ+Ô+Ð+Ø�!‰ˆð7 �1Š*‰*ð8 €Hr<   c                ó–  — t          |dd¬¦  «        }t          |¦  «        t          |¦  «        }}t          d„ ||fD ¦   «         ¦  «        rt          j        d¦  «        ‚t          d|                     ¦   «         z  | z  dz   ¦  «        }t          ||¦  «        }|dz
  }t          |¦  «        D ]š} |                     ¦   «         |k     r€|dz  }| 	                    | |¦  «         |}|                     ¦   «         |k     r3|dz  }| 	                    ||¦  «         |                     ¦   «         |k     °3|                     ¦   «         |k     °€Œ›|S )a  Returns a random lobster graph.

    A lobster is a tree that reduces to a caterpillar when pruning all
    leaf nodes. A caterpillar is a tree that reduces to a path graph
    when pruning all leaf nodes; setting `p2` to zero produces a caterpillar.

    This implementation iterates on the probabilities `p1` and `p2` to add
    edges at levels 1 and 2, respectively. Graphs are therefore constructed
    iteratively with uniform randomness at each level rather than being selected
    uniformly at random from the set of all possible lobsters.

    Parameters
    ----------
    n : int
        The expected number of nodes in the backbone
    p1 : float
        Probability of adding an edge to the backbone
    p2 : float
        Probability of adding an edge one level beyond backbone
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    create_using : Graph constructor, optional (default=nx.Graph)
        Graph type to create. If graph instance, then cleared before populated.
        Multigraph and directed types are not supported and raise a ``NetworkXError``.

    Raises
    ------
    NetworkXError
        If `p1` or `p2` parameters are >= 1 because the while loops would never finish.
    FrE   c              3   ó"   K  — | ]
}|d k    V — ŒdS )r   Nrj   )rt   r5   s     r;   ú	<genexpr>z'random_lobster_graph.<locals>.<genexpr>o  s&   è è € Ð
$Ð
$�aˆ1�Š6Ð
$Ð
$Ð
$Ð
$Ð
$Ð
$r<   z6Probability values for `p1` and `p2` must both be < 1.r   g      à?r   )
r   ÚabsÚanyr,   rU   r2   r1   r
   rA   r3   )	r4   Úp1Úp2r*   r$   ÚllenÚLÚcurrent_nodeÚcat_nodes	            r;   r   r   K  sP  € õD & l¸UÈuÐUÑUÔU€LÝ�‰WŒW•c˜"‘g”gˆ€BÝ
Ð
$Ð
$˜B ˜8Ð
$Ñ
$Ô
$Ñ$Ô$ð YÝÔÐWÑXÔXÐXõ ˆq�4—;’;‘=”=Ñ  1Ñ$ sÑ*Ñ+Ô+€DÝ�4˜Ñ&Ô&€Aà˜!‘8€LÝ�4‰[Œ[ð 3ð 3ˆØ�kŠk‰mŒm˜bÒ Ð Ø˜AÑˆLØ�JŠJ�q˜,Ñ'Ô'Ð'Ø#ˆHØ—+’+‘-”- "Ò$Ð$Ø Ñ!�Ø—
’
˜8 \Ñ2Ô2Ð2ð —+’+‘-”- "Ò$Ð$ð	 �kŠk‰mŒm˜bÒ Ð øð €Hr<   c                ól   — ddl }|                     dt          d¬¦  «         t          | ||||¬¦  «        S )z™
    .. deprecated:: 3.5
       `random_lobster` is a deprecated alias
       for `random_lobster_graph`.
       Use `random_lobster_graph` instead.
    r   NzC`random_lobster` is deprecated, use `random_lobster_graph` instead.r   )ÚcategoryÚ
stacklevel©r*   r$   )ÚwarningsÚwarnÚDeprecationWarningr   )r4   r½   r¾   r*   r$   rÇ   s         r;   r   r   ‚  sL   € ð €O€O€Oà‡M‚MØMÝ#Øð ñ ô ð õ
    2 r°À<ÐPÑPÔPÐPr<   c          	      ó  — t          |dd¬¦  «        }t          d|¦  «        }g }g }d}| D ]–\  }}}	t          ||	z  ¦  «        }
|                     ||
z
  ¦  «         t	          j        t          ||
||j        ¬¦  «        |¬¦  «        }|                     |¦  «         ||z  }t          j         	                    ||¦  «        }Œ—t          t          |¦  «        dz
  ¦  «        D ]§}t          ||         ¦  «        }t          ||dz            ¦  «        }||         }d}||k     rh|                     |¦  «        }|                     |¦  «        }||k    s|                     ||¦  «        rŒM|                     ||¦  «         |dz   }||k     °hŒ¨|S )a;  Returns a random shell graph for the constructor given.

    Parameters
    ----------
    constructor : list of three-tuples
        Represents the parameters for a shell, starting at the center
        shell.  Each element of the list must be of the form `(n, m,
        d)`, where `n` is the number of nodes in the shell, `m` is
        the number of edges in the shell, and `d` is the ratio of
        inter-shell (next) edges to intra-shell edges. If `d` is zero,
        there will be no intra-shell edges, and if `d` is one there
        will be all possible intra-shell edges.
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    create_using : Graph constructor, optional (default=nx.Graph)
        Graph type to create. Graph instances are not supported.
        Multigraph and directed types are not supported and raise a ``NetworkXError``.

    Examples
    --------
    >>> constructor = [(10, 20, 0.8), (20, 40, 0.8)]
    >>> G = nx.random_shell_graph(constructor)

    FrE   r   rÆ   )Úfirst_labelr   )r   r	   r2   r¤   r,   Úconvert_node_labels_to_integersr   Ú	__class__Ú	operatorsÚunionrA   rW   rM   rN   rO   r3   )Úconstructorr*   r$   r6   ÚglistÚintra_edgesÚnnodesr4   rG   r€   Úinter_edgesÚgÚgiÚnlist1Únlist2Útotal_edgesrR   rI   r8   s                      r;   r   r   •  s§  € õ8 & l¸UÈuÐUÑUÔU€LÝ�A�|Ñ$Ô$€Aà€EØ€KØ€Fàð 	%ð 	%‰ˆˆ1ˆaÝ˜!˜a™%‘j”jˆØ×Ò˜1˜{™?Ñ+Ô+Ð+ÝÔ.Ý˜Q °$ÀQÄ[ÐQÑQÔQØð
ñ 
ô 
ˆð 	�Š�Q‰ŒˆØ�!‰ˆÝŒL×Ò˜q !Ñ$Ô$ˆˆõ •C˜‘J”J ‘NÑ#Ô#ð ,ð ,ˆÝ�e˜B”i‘”ˆÝ�e˜B ™F”mÑ$Ô$ˆØ! "”oˆØˆ
Ø˜;Ò&Ð&Ø—’˜FÑ#Ô#ˆAØ—’˜FÑ#Ô#ˆAØ�AŠvˆv˜Ÿš A qÑ)Ô)ˆvØà—
’
˜1˜aÑ Ô Ð Ø'¨!™^�
ð ˜;Ò&Ð&øð €Hr<   c                óp   — t          |dd¬¦  «        }t          | |||¬¦  «        }t          ||¦  «        }|S )a#  Returns a tree with a power law degree distribution.

    Parameters
    ----------
    n : int
        The number of nodes.
    gamma : float
        Exponent of the power law.
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    tries : int
        Number of attempts to adjust the sequence to make it a tree.
    create_using : Graph constructor, optional (default=nx.Graph)
        Graph type to create. If graph instance, then cleared before populated.
        Multigraph and directed types are not supported and raise a ``NetworkXError``.

    Raises
    ------
    NetworkXError
        If no valid sequence is found within the maximum number of
        attempts.

    Notes
    -----
    A trial power law degree sequence is chosen and then elements are
    swapped with new elements from a powerlaw distribution until the
    sequence makes a tree (by checking, for example, that the number of
    edges is one smaller than the number of nodes).

    FrE   )Úgammar*   rg   )r   r   r   )r4   rÛ   r*   rg   r$   rƒ   r6   s          r;   r   r   Ô  sC   € õD & l¸UÈuÐUÑUÔU€Lå
'¨°¸TÈÐ
OÑ
OÔ
O€CÝ˜S ,Ñ/Ô/€AØ€Hr<   )r!   c                 ó®  ‡ — t           j                             ‰ ||¬¦  «        }ˆ fd„|D ¦   «         }t           j                             |||¬¦  «        }ˆ fd„|D ¦   «         }|D ]Z}t           j                             |¦  «        \  }}|r|c S |                     d‰ dz
  ¦  «        }	|                     ¦   «         ||	<   Œ[t          j        d|› d�¦  «        ‚)aK  Returns a degree sequence for a tree with a power law distribution.

    Parameters
    ----------
    n : int,
        The number of nodes.
    gamma : float
        Exponent of the power law.
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    tries : int
        Number of attempts to adjust the sequence to make it a tree.

    Raises
    ------
    NetworkXError
        If no valid sequence is found within the maximum number of
        attempts.

    Notes
    -----
    A trial power law degree sequence is chosen and then elements are
    swapped with new elements from a power law distribution until
    the sequence makes a tree (by checking, for example, that the number of
    edges is one smaller than the number of nodes).

    )Úexponentr*   c           
      óf   •— g | ]-}t          ‰t          t          |¦  «        d ¦  «        ¦  «        ‘Œ.S r    ©Úminr”   Úround©rt   Úsr4   s     €r;   rx   z1random_powerlaw_tree_sequence.<locals>.<listcomp>  ó3   ø€ Ð0Ð0Ð0¨�C�•3•u˜Q‘x”x Ñ#Ô#Ñ$Ô$Ð0Ð0Ð0r<   c           
      óf   •— g | ]-}t          ‰t          t          |¦  «        d ¦  «        ¦  «        ‘Œ.S r    rß   râ   s     €r;   rx   z1random_powerlaw_tree_sequence.<locals>.<listcomp>$  rä   r<   r   r   zExceeded max (z%) attempts for a valid tree sequence.)r,   ÚutilsÚpowerlaw_sequenceÚis_valid_tree_degree_sequenceÚrandintr²   rU   )
r4   rÛ   r*   rg   ÚzÚzseqÚswaprw   ÚvalidÚindexs
   `         r;   r   r   ý  sø   ø€ õ@ 	Œ×"Ò" 1¨u¸4Ð"Ñ@Ô@€Aà0Ð0Ð0Ð0¨aÐ0Ñ0Ô0€Dõ 	Œ×"Ò" 5°5¸tÐ"ÑDÔD€Aà0Ð0Ð0Ð0¨aÐ0Ñ0Ô0€Dàð !ð !ˆÝ”8×9Ò9¸$Ñ?Ô?‰ˆˆqØð 	ØˆKˆKˆKØ—’˜Q  A¡Ñ&Ô&ˆØ—h’h‘j”jˆˆU‰ˆå
Ô
ØE˜ÐEÐEÐEñô ð r<   c                óö  ‡‡	— t          |dd¬¦  «        }|€
ddlŠ	ˆˆ	fd„}t          j        |¬¦  «        }|                     t          | ¦  «        ¦  «         d\  }}|| k     r–t          j        d|                     ¦   «         z
  ¦  «         } ‰|| z  || z  d¦  «        |k    r|dz   |dz   }}nDt          j	        |  ||| z  || z  |¦  «        z  ¦  «        }| 
                    |dz
  |dz
  ¦  «         || k     °–|S )	uÚ  Returns an random graph based on the specified kernel.

    The algorithm chooses each of the $[n(n-1)]/2$ possible edges with
    probability specified by a kernel $\kappa(x,y)$ [1]_.  The kernel
    $\kappa(x,y)$ must be a symmetric (in $x,y$), non-negative,
    bounded function.

    Parameters
    ----------
    n : int
        The number of nodes
    kernel_integral : function
        Function that returns the definite integral of the kernel $\kappa(x,y)$,
        $F(y,a,b) := \int_a^b \kappa(x,y)dx$
    kernel_root: function (optional)
        Function that returns the root $b$ of the equation $F(y,a,b) = r$.
        If None, the root is found using :func:`scipy.optimize.brentq`
        (this requires SciPy).
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.
    create_using : Graph constructor, optional (default=nx.Graph)
        Graph type to create. If graph instance, then cleared before populated.
        Multigraph and directed types are not supported and raise a ``NetworkXError``.

    Notes
    -----
    The kernel is specified through its definite integral which must be
    provided as one of the arguments. If the integral and root of the
    kernel integral can be found in $O(1)$ time then this algorithm runs in
    time $O(n+m)$ where m is the expected number of edges [2]_.

    The nodes are set to integers from $0$ to $n-1$.

    Examples
    --------
    Generate an ErdÅ‘sâ€“RÃ©nyi random graph $G(n,c/n)$, with kernel
    $\kappa(x,y)=c$ where $c$ is the mean expected degree.

    >>> def integral(u, w, z):
    ...     return c * (z - w)
    >>> def root(u, w, r):
    ...     return r / c + w
    >>> c = 1
    >>> graph = nx.random_kernel_graph(1000, integral, root)

    See Also
    --------
    gnp_random_graph
    expected_degree_graph

    References
    ----------
    .. [1] BollobÃ¡s, BÃ©la,  Janson, S. and Riordan, O.
       "The phase transition in inhomogeneous random graphs",
       *Random Structures Algorithms*, 31, 3--122, 2007.

    .. [2] Hagberg A, Lemons N (2015),
       "Fast Generation of Sparse Random Kernel Graphs".
       PLoS ONE 10(9): e0135177, 2015. doi:10.1371/journal.pone.0135177
    FrE   Nr   c                 óR   •‡ ‡‡— ˆˆˆˆ fd„}‰j                              |‰d¦  «        S )Nc                 ó$   •—  ‰‰‰| ¦  «        ‰z
  S ©Nrj   )ÚbÚaÚkernel_integralÚrÚys    €€€€r;   Úmy_functionz=random_kernel_graph.<locals>.kernel_root.<locals>.my_functiony  s   ø€ Ø&� q¨!¨QÑ/Ô/°!Ñ3Ð3r<   r   )ÚoptimizeÚbrentq)r÷   rô   rö   rø   rõ   Úsps   ``` €€r;   Úkernel_rootz(random_kernel_graph.<locals>.kernel_rootx  sJ   øøøø€ ð4ð 4ð 4ð 4ð 4ð 4ð 4ð 4ð ”;×%Ò% k°1°aÑ8Ô8Ð8r<   r#   )r   r   r   )r   Úscipyr,   r	   Úadd_nodes_fromrA   r/   r0   r1   Úceilr3   )
r4   rõ   rü   r*   r$   Úgraphr]   r[   rö   rû   s
    `       @r;   r    r    2  s6  øø€ õD & l¸UÈuÐUÑUÔU€LØÐØÐÐÐð	9ð 	9ð 	9ð 	9ð 	9ð 	9õ ŒN¨Ð5Ñ5Ô5€EØ	×Ò�˜q™œÑ"Ô"Ð"Ø�F€QˆØ
ˆaŠ%ˆ%ÝŒX�a˜$Ÿ+š+™-œ-Ñ'Ñ(Ô(Ð(ˆØˆ?˜1˜q™5 ! a¡%¨Ñ+Ô+¨qÒ0Ð0Ø�q‘5˜!˜a™%ˆqˆAˆAå”	˜!˜k˜k¨!¨a©%°°Q±¸Ñ:Ô:Ñ:Ñ;Ô;ˆAØ�NŠN˜1˜q™5 ! a¡%Ñ(Ô(Ð(ð ˆaŠ%ˆ%ð €Lr<   )NFrò   )rd   N)NN)rS   Nrd   ))Ú__doc__r>   r/   Úcollectionsr   Únetworkxr,   Únetworkx.utilsr   Ú
utils.miscr   Úclassicr   r	   r
   r   Ú
degree_seqr   Ú__all__Ú_dispatchabler   r   r   r   r   r   r   r   r   r   r†   r   r   r   r   r   r   r   r   r   r    rj   r<   r;   ú<module>r
     s  ððð ð
 Ð Ð Ð Ø €€€Ø #Ð #Ð #Ð #Ð #Ð #à Ð Ð Ð Ø *Ð *Ð *Ð *Ð *Ð *à +Ð +Ð +Ð +Ð +Ð +Ø HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HØ ,Ð ,Ð ,Ð ,Ð ,Ð ,ðð ð €ð0 €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2ðLÈ4ð Lð Lð Lð Lñ 3Ô2ñ ÔðLð^ €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2ð;Àdð ;ð ;ð ;ð ;ñ 3Ô2ñ Ôð;ð~ "€Ø$Ð ð €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2ð<¸Dð <ð <ð <ð <ñ 3Ô2ñ Ôð<ð~ €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2ð4Àdð 4ð 4ð 4ð 4ñ 3Ô2ñ Ôð4ðn €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2ðFÀDð Fð Fð Fð Fñ 3Ô2ñ ÔðFðR €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2ðK¸Tð Kð Kð Kð Kñ 3Ô2ñ ÔðKð\ €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2ð3?ÐRVð 3?ð 3?ð 3?ð 3?ñ 3Ô2ñ Ôð3?ðl €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2ðs¸$ð sð sð sð sñ 3Ô2ñ Ôðsðlð ð ð €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2ðGÈtð Gð Gð Gð Gñ 3Ô2ñ ÔðGðT €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2à+/ðdØAEðdð dð dð dñ 3Ô2ñ ÔðdðN €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2ðaÈ$ð að að að añ 3Ô2ñ ÔðaðH €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2ðX¸tð Xð Xð Xð Xñ 3Ô2ñ ÔðXðv €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2ð2¸tð 2ð 2ð 2ð 2ñ 3Ô2ñ Ôð2ðj €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2ðQ¸ð Qð Qð Qð Qñ 3Ô2ñ ÔðQð" €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2ð:¸tð :ð :ð :ð :ñ 3Ô2ñ Ôð:ðz €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2ð$È4ð $ð $ð $ð $ñ 3Ô2ñ Ôð$ðN €�ÑÔØ€Ô˜ÐÑÔð0ð 0ð 0ñ Ôñ Ôð0ðf €�ÑÔØ€Ô˜¨TÐ2Ñ2Ô2à/3ðTØEIðTð Tð Tð Tñ 3Ô2ñ ÔðTð Tð Tr<   