Ë
    D^(h’È  ã                   óì  — 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!„«       «       Z& ed«       ej&                  dd¬«      	 d&ddœd"„«       «       Z'y)(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_shell_graphÚrandom_powerlaw_treeÚrandom_powerlaw_tree_sequenceÚrandom_kernel_graphT)ÚgraphsÚreturns_graph©Ú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  rvt        j                  d|j                  «       z
  «      }
|	dz   t        |
|z  «      z   }	|	|k\  r|| k  r|	|z
  }	|dz   }|	|k\  r|| k  rŒ|| k  r|j                  |	|«       || k  rŒvd}d}	|| k  rvt        j                  d|j                  «       z
  «      }
|	dz   t        |
|z  «      z   }	|	|k\  r|| k  r|	|z
  }	|dz   }|	|k\  r|| k  rŒ|| k  r|j                  ||	«       || k  rŒv|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/skyplay_api_hub/venv/lib/python3.12/site-packages/networkx/generators/random_graphs.pyr   r   (   sž  € ñT %Œb�jŠj¬"¯(©(€GÜ%Ø˜x°EÀ7ô€Lð 	ˆA‚v��a’Ü×"Ñ"Øˆq�t h¸\ô
ð 	
ô 	�A LÔ1€Aä	�‰�#˜‘'Ó	€BáØˆØˆØ�!ŠeÜ—‘˜# §¡£Ñ-Ó.ˆBØ�A‘œ˜B ™G›Ñ$ˆAØ�q’&˜Q šUØ˜‘E�Ø˜‘E�ð �q’&˜Q ›Uð �1ŠuØ—
‘
˜1˜aÔ ð �!‹eð 	
€AØ
€AØ
ˆaŠ%Ü�X‰X�c˜DŸK™K›MÑ)Ó*ˆØ�‰E”C˜˜R™“LÑ ˆØ�1Šf˜˜QšØ�A‘ˆAØ�A‘ˆAð �1Šf˜˜Q›ð ˆqŠ5Ø�J‰J�q˜!Ôð ˆa‹%ð €Hó    c                ó€  — |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 ]%  }|j                  «       |k  sŒ |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Úranger0   r2   )	r3   r4   r)   r&   r#   r(   r5   ÚedgetoolÚes	            r:   r   r   y   s¬   € ñ\ %Œb�jŠj¬"¯(©(€GÜ%Ø˜x°EÀ7ô€Lð 	ˆA‚vÜ˜a¨lÔ;Ð;ä
�‰�q |Ô4€AØˆA‚vØˆá)1Œy×%Ò%´y×7MÑ7M€HÙ”e˜A“h Ó"ò ˆØ�;‰;‹=˜1ÓØˆA�J‰J˜ŠNðð €Hr;   c                ó2  — t        |dd¬«      }| | dz
  z  dz  }||k\  rt        | |«      S t        | |«      }| dk(  r|S d}d}d}d}		 |j                  ||z
  «      ||	z
  k  r|j	                  ||«       |	dz  }	|	|k(  r|S |dz  }|dz  }|| k(  r
|dz  }|dz   }ŒR)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	   Ú	randranger2   )
r3   Úmr)   r#   Úmmaxr5   Úur7   ÚtÚks
             r:   r   r   ¾   sÔ   € ôN & l¸UÈuÔU€LØ��A‘‰;˜!Ñ€DØˆD‚yÜ˜a Ó.Ð.Ü�A�|Ó$€AàˆA‚vØˆà	€AØ	€AØ	€AØ	€AØ
Ø�>‰>˜$ ™(Ó# a¨!¡eÒ+Ø�J‰J�q˜!ÔØ�‰FˆAØ�AŠvØ�Ø	ˆQ‰ˆØ	ˆQ‰ˆØ�Š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  rW|j                  |«      }
|j                  |«      }|
|k(  s|j                  |
|«      rŒ?|j                  |
|«       |	dz   }	|	|k  rŒW|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_edger2   )r3   rF   r)   r&   r#   r(   Ú	max_edgesr5   ÚnlistÚ
edge_countrH   r7   s               r:   r   r   ÿ   sô   € ñ@ %Œb�jŠj¬"¯(©(€GÜ%Ø˜x°EÀ7ô€Lð 	ˆA‚vÜ�~‰~˜a¨lÔ;Ð;Ù'��Q˜‘U’¨Q°!°a±%©[¸3Ñ->€IØˆI‚~Ü˜a¨lÔ;Ð;ä
�‰�q |Ô4€AÜ�‹G€EØ€JØ
�qŠ.à�K‰K˜ÓˆØ�K‰K˜ÓˆØ�Š6�Q—Z‘Z  1Ô%Øà�J‰J�q˜!ÔØ# a™ˆJð �q‹.ð €Hr;   é   c                óæ  — t        |dd¬«      }|| kD  rt        j                  d«      ‚|| k(  rt        j                  | |«      S t	        | |«      }t        |j                  «       «      }|}t        d|dz  dz   «      D ]>  }||d |d| z   }	t        t        |«      «      D ]  }
|j                  ||
   |	|
   «       Œ Œ@ t        |j                  «       «      }|D ]•  \  }}|j                  «       |k  sŒ|j                  |«      }||k(  s|j                  ||«      rB|j                  |«      }|j                  |«      | dz
  k\  rŒk||k(  rŒ/|j                  ||«      rŒB|j                  ||«       Œ— |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
    FrD   z"k>=n, choose smaller k or larger nr   r   Nr   )r   r+   ÚNetworkXErrorr   r	   rL   Únodesr@   Úlenr2   Úedgesr0   rM   rN   Údegree)r3   rJ   r4   r)   r#   r5   rP   ÚfromvÚjÚtovÚirB   rH   r7   r8   s                  r:   r   r   8  sr  € ôT & l¸UÈuÔU€LØˆ1‚uÜ×ÑÐCÓDÐDð 	ˆA‚vÜ× Ñ   LÓ1Ð1ä�A�|Ó$€AÜ�—‘“‹O€EØ€Eä�1�a˜1‘f˜q‘jÓ!ò )ˆØ�A�Bˆi˜%  !˜*Ñ$ˆÜ”s˜5“zÓ"ò 	)ˆAØ�J‰J�u˜Q‘x  Q¡Õ(ñ	)ð)ô 	ˆQ�W‰W‹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¬«      }|| kD  rt        j                  d«      ‚|| k(  rt        j                  | |«      }|S t        j                  | |¬«      }t        t        | «      «      }t        d|dz  dz   «      D ](  }||d |d| z   }|j                  t        ||«      «       Œ* t        d|dz  dz   «      D ]Ã  }||d |d| z   }t        ||«      D ]§  \  }	}
|j                  «       |k  sŒ|j                  |«      }||	k(  s|j                  |	|«      rB|j                  |«      }|j                  |	«      | dz
  k\  rŒk||	k(  rŒ/|j                  |	|«      rŒB|j                  |	|
«       |j                  |	|«       Œ© ŒÅ |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.
    FrD   z!k>n, choose smaller k or larger nr"   r   r   Nr   )r   r+   rT   r   r	   rL   r@   Úadd_edges_fromÚzipr0   rM   rN   rX   Úremove_edger2   )r3   rJ   r4   r)   r#   r5   rU   rZ   ÚtargetsrH   r7   r8   s               r:   r   r   ƒ  s’  € ôZ & l¸UÈuÔU€LØˆ1‚uÜ×ÑÐBÓCÐCð 	ˆA‚vÜ×Ñ˜a Ó.ˆØˆä
�‰�q |Ô4€AÜ”�q“‹N€Eä�1�a˜1‘f˜q‘jÓ!ò .ˆØ˜˜�)˜e A a˜jÑ(ˆØ	×Ñœ˜U GÓ,Õ-ð.ô �1�a˜1‘f˜q‘jÓ!ò %ˆØ˜˜�)˜e A a˜jÑ(ˆä˜˜wÓ'ò 
	%‰DˆAˆqØ�{‰{‹}˜qÓ Ø—K‘K Ó&�à˜1’f §
¡
¨1¨aÔ 0ØŸ™ EÓ*�AØ—x‘x “{ a¨!¡eÒ+Øð ˜1“f §
¡
¨1¨aÕ 0ð
 —M‘M ! QÔ'Ø—J‘J˜q !Õ$ñ
	%ð%ð €Hr;   é   c                óž   — t        |«      D ]+  }t        | ||||¬«      }t        j                  |«      sŒ)|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)r@   r   r+   Úis_connectedrT   )r3   rJ   r4   Útriesr)   r#   r\   r5   s           r:   r   r   Ó  sO   € ô` �5‹\ò ˆä   A q¨$¸\ÔJˆÜ�?‰?˜1ÕØŠHð	ô
 ×
Ñ
Ð=Ó
>Ð>r;   c                óH  ‡ ‡‡‡— t        |dd¬«      }‰‰ z  dz  dk7  rt        j                  d«      ‚d‰ cxk  r‰k  sn t        j                  d«      ‚t        j                  ‰|¬«      }‰ dk(  r|S d„ Šˆˆ ˆˆfd	„} |«       }|€
 |«       }|€Œ
|j	                  |«       |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
    FrD   r   r   zn * d must be evenz+the 0 <= d < n inequality must be satisfiedr"   c                 óX   — |sy|D ]"  }|D ]  }||k(  r Œ||kD  r||}}||f| vsŒ  y Œ$ y)NTF© )rW   Úpotential_edgesÚs1Ús2s       r:   Ú	_suitablez'random_regular_graph.<locals>._suitableH  sX   € ñ ØØ!ò 	 ˆBØ%ò 
 �ð ˜’8áØ˜’7Ø ˜�BØ˜�8 5Ò(Úñ
 ð	 ð r;   c                  óÚ  •— t        «       } t        t        ‰«      «      ‰
z  }|r¿t        d„ «      }‰j	                  |«       t        |«      }t        ||«      D ]G  \  }}||kD  r||}}||k7  r||f| vr| j                  ||f«       Œ.||xx   dz  cc<   ||xx   dz  cc<   ŒI  ‰	| |«      sy |j                  «       D ���cg c]  \  }}t        |«      D ]  }|‘Œ Œ }}}}|rŒ¿| S c c}}}w )Nc                   ó   — y)Nr   rh   rh   r;   r:   ú<lambda>z=random_regular_graph.<locals>._try_creation.<locals>.<lambda>b  s   � r;   r   )	ÚsetrL   r@   r   ÚshuffleÚiterr_   ÚaddÚitems)rW   Ústubsri   Ústubiterrj   rk   ÚnodeÚ	potentialÚ_rl   Údr3   r)   s            €€€€r:   Ú_try_creationz+random_regular_graph.<locals>._try_creation[  s  ø€ ô “ˆÜ”U˜1“X“ Ñ"ˆáÜ)©)Ó4ˆOØ�L‰L˜ÔÜ˜E“{ˆHÜ˜h¨Ó1ò -‘��BØ˜’7Ø ˜�BØ˜’8 " b °Ñ!6Ø—I‘I˜r 2˜hÕ'à# BÓ'¨1Ñ,Ó'Ø# BÓ'¨1Ñ,Ô'ð-ñ ˜U OÔ4Øð (7×'<Ñ'<Ó'>÷ð á#�D˜)Ü˜yÓ)òð ò ðØðˆEò ò! ð* ˆùôs   ÃC&)r   r+   rT   r	   r^   )rz   r3   r)   r#   r5   r{   rW   rl   s   ```    @r:   r   r     s©   û€ ôb & l¸UÈuÔU€LØ	ˆA‰��{�aÒÜ×ÑÐ3Ó4Ð4à�Œ:�AŒ:Ü×ÑÐLÓMÐMä
�‰�q |Ô4€AàˆA‚vØˆò÷&ñ@ ‹O€EØ
ˆ-Ù“ˆð ‰-à×Ñ�UÔà€Hr;   c                 ó˜   — t        «       }t        |«      |k  r1|j                  | «      }|j                  |«       t        |«      |k  rŒ1|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.
    )rp   rV   rM   rs   )ÚseqrF   Úrngra   Úxs        r:   Ú_random_subsetr€   ƒ  sD   € ô ‹e€GÜ
ˆg‹,˜Ò
Ø�J‰J�s‹OˆØ�‰�AŒô ˆg‹,˜Ó
ð €Nr;   c                ój  — t        |dd¬«      }|dk  s|| k\  rt        j                  d|› d| › �«      ‚|€t        ||«      }nHt	        |«      |k  st	        |«      | kD  rt        j                  d|› d| › d�«      ‚|j                  «       }|j                  «       D � ��cg c]  \  } }t        |«      D ]  }| ‘Œ Œ }}} }t	        |«      }	|	 k  r]t        |||«      }
|j                  t        |	g|z  |
«      «       |j                  |
«       |j                  |	g|z  «       |	dz  }	|	| k  rŒ]|S c c}}} w )	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.
    FrD   r   u;   BarabÃ¡siâ€“Albert network must have m >= 1 and m < n, m = ú, n = u1   BarabÃ¡siâ€“Albert initial graph needs between m=z and n=ú nodes)r   r+   rT   r   rV   ÚcopyrX   r@   r€   r^   r_   Úextend)r3   rF   r)   Úinitial_graphr#   r5   rz   ry   Úrepeated_nodesÚsourcera   s              r:   r   r   ’  sV  € ôR & l¸UÈuÔU€LØˆ1‚u��Q’Ü×ÑØIÈ!ÈÈFÐSTÐRUÐVó
ð 	
ð Ðä�q˜,Ó'‰äˆ}Ó Ò!¤S¨Ó%7¸!Ò%;Ü×"Ñ"ØCÀAÀ3ÀgÈaÈSÐPVÐWóð ð ×ÑÓ ˆð %&§H¡H£J×AÐA™D˜A˜q¼¸a»ÒA°1’aÐA�aÐA€NÒAä�‹V€FØ
�1Š*ô ! °°DÓ9ˆà	×Ñœ˜f˜X¨™\¨7Ó3Ô4à×Ñ˜gÔ&à×Ñ˜v˜h¨™lÔ+à�!‰ˆð �1‹*ð €Hùô Bs   ÂD.c                óÊ  — 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kD  rt        j                  d|› �«      ‚|dk(  rt        | |||¬	«      S |dk(  rt        | |||¬	«      S |€t	        t        ||«      |«      }n\t        |«      t        ||«      k  st        |«      | kD  r&t        j                  d
t        ||«      › d| › d�«      ‚|j                  «       }t        |«      }|j                  «       D � �	�
cg c]  \  } }	t        |	«      D ]  }
| ‘Œ Œ }}	} }
t        |«      }| k  ru|j                  «       |k  r|}n|}t        |||«      }|j                  t        |g|z  |«      «       |j                  |«       |j                  |g|z  «       |dz  }|| k  rŒu|S c c}
}	} w )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.
    FrD   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"   uA   BarabÃ¡siâ€“Albert initial graph must have between max(m1, m2) = z	 and n = rƒ   )r   r+   rT   r   r   ÚmaxrV   r„   rL   rX   r@   r0   r€   r^   r_   r…   )r3   Úm1Úm2r4   r)   r†   r#   r5   ra   rz   ry   r‡   rˆ   rF   s                 r:   r   r   Þ  s  € ô` & l¸UÈuÔU€LØ	ˆA‚v��q’Ü×ÑØIÈ"ÈÈVÐTUÐSVÐWó
ð 	
ð 
ˆA‚v��q’Ü×ÑØIÈ"ÈÈVÐTUÐSVÐWó
ð 	
ð 	ˆ1‚u��A’Ü×ÑØIÈ!ÈÐMó
ð 	
ð
 	ˆA‚vÜ$ Q¨¨D¸|ÔLÐLØ	
ˆaŠÜ$ Q¨¨D¸|ÔLÐLàÐä”s˜2˜r“{ LÓ1‰äˆ}Ó¤ B¨£Ò+¬s°=Ó/AÀAÒ/EÜ×"Ñ"ð!Ü!$ R¨£ ¨Y°q°c¸ðAóð ð ×ÑÓ ˆô �1‹g€Gà$%§H¡H£J×AÐA™D˜A˜q¼¸a»ÒA°1’aÐA�aÐA€NÒAä�‹V€FØ
�1Š*à�;‰;‹=˜1ÒØ‰AàˆAô ! °°DÓ9ˆà	×Ñœ˜f˜X¨™\¨7Ó3Ô4à×Ñ˜gÔ&à×Ñ˜v˜h¨™lÔ+à�!‰ˆð! �1‹*ð" €Hùô) Bs   Ä7Gc                óü  — t        |dd¬«      }|dk  s|| k\  rd|› d| › �}t        j                  |«      ‚||z   dk\  rd|› d|› �}t        j                  |«      ‚t        ||«      }g }|j	                  t        |«      «       |}	|	| k  �r[|j                  «       }
t        |«      dz
  }t        |«      |z  dz  }|
|k  �r)|j                  «       ||z
  k  �r|j                  «       D ��cg c]  \  }}||k  sŒ|‘Œ }}}t        |«      D ]Ú  }|j                  |«      }t        ||   «      }|j                  |«       |j                  |D �cg c]	  }||vsŒ|‘Œ c}«      }|j                  ||«       |j                  |«       |j                  |«       |j                  |«      |k(  r|j                  |«       |j                  |«      |k(  sŒÅ||v sŒÊ|j                  |«       ŒÜ �nö||
cxk  r	||z   k  �r�n �n‰||j                  «       cxk  r|k  �ron �nk|j                  «       D ��cg c]  \  }}d	|cxk  r|k  sŒn n|‘Œ }}}t        |«      D �]*  }|j                  |«      }t        ||   «      }|j                  |«      }|j                  |«       |j                  |D �cg c]	  }||vsŒ|‘Œ c}«      }|j                  ||«       |j                  ||«       |j                  |«       |j                  |«       |j                  |«      d	k(  r||v r|j                  |«       ||v r(|j                  |«      |k(  sŒñ|j                  |«       �Œ|j                  |«      dk(  s�Œ|j                  |«       �Œ- nZt!        |||«      }|j#                  t%        |	g|z  |«      «       |j	                  |«       |j	                  |	g|dz   z  «       |	dz  }	|	| k  r�Œ[|S c c}}w c c}w c c}}w c c}w )
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.
    FrD   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   r   )r   r+   rT   r	   r…   r@   r0   rV   ÚsizerX   rM   rL   Úappendr2   Úremover`   r€   r^   r_   )r3   rF   r4   Úqr)   r#   Úmsgr5   Úattachment_preferenceÚnew_nodeÚa_probabilityÚclique_degreeÚclique_sizeÚndÚdegÚeligible_nodesr\   Úsrc_nodeÚprohibited_nodesÚ	dest_noderw   Ú	nbr_nodesra   s                          r:   r   r   G  sä  € ôl & l¸UÈuÔU€LØˆ1‚u��Q’ØGÈÀsÈ$ÈqÈcÐRˆÜ×Ñ˜sÓ#Ð#Øˆ1�u�‚zØEÀaÀSÈÈQÈCÐPˆÜ×Ñ˜sÓ#Ð#ô 	�A�|Ó$€Að ÐØ× Ñ ¤ q£Ô*ð €HØ
�Q‹,ØŸ™›ˆô ˜A› ™
ˆÜ˜1“v Ñ-°Ñ2ˆð ˜1Ó §¡£¨[¸1©_Ó!<à01·±³
×R¡W R¨¸cÀMÓ>QšbÐRˆNÑRÜ˜1“Xò 5�àŸ;™; ~Ó6�ô $(¨¨(©Ó#4Ð Ø ×'Ñ'¨Ô1à ŸK™KØ"7ÖV˜B¸2ÐEUÒ;U’RÒVó�	ð —
‘
˜8 YÔ/ð &×,Ñ,¨XÔ6Ø%×,Ñ,¨YÔ7ð —8‘8˜HÓ%¨Ò6Ø"×)Ñ)¨(Ô3Ø—8‘8˜IÓ&¨-Ó7¸IÈÒ<WØ"×)Ñ)¨)Õ4ò/5ð4 �-Ô) 1 q¡5×)¨a°1·6±6³8Ô.I¸k×.Ið 12·±³
×V¡W R¨¸aÀ#Ô>UÈÖ>UšbÐVˆNÑVÜ˜1“Xó !9�à—{‘{ >Ó2�ô !  4¡›M�	ð  Ÿ;™; yÓ1�ð × Ñ  Ô&Ø ŸK™KØ"7ÖO˜B¸2ÀYÒ;N’RÒOó�	ð —‘˜d HÔ-Ø—
‘
˜4 Ô+ð &×,Ñ,¨XÔ6Ø%×,Ñ,¨YÔ7ð —8‘8˜HÓ%¨Ò*¨x¸>Ñ/IØ"×)Ñ)¨(Ô3Ø Ñ.Ø—x‘x 	Ó*¨mÓ;Ø&×-Ñ-¨iÖ8à—x‘x 	Ó*¨aÔ/Ø&×-Ñ-¨iÖ8ñC!9ôL %Ð%:¸A¸tÓDˆGØ×ÑœS ( ¨a¡°Ó9Ô:ð "×(Ñ(¨Ô1à!×(Ñ(¨(¨°q¸1±uÑ)=Ô>Ø˜‰MˆHðo �QŒ,ðp €Hùó] Sùò Wùó( Wùò Ps0   Ã*O(Ã8O(Å	O.
ÅO.
È-O3ÉO3Ê*	O9
Ê4O9
c                óL  — t        |dd¬«      }|dk  s| |k  rt        j                  d|› d| › �«      ‚|dkD  s|dk  rt        j                  d|› �«      ‚t        ||«      }t	        |«      }|}|| k  �r*t        |||«      }|j                  «       }	|j                  ||	«       |j                  |	«       d}
|
|k  rÂ|j                  «       |k  rq|j                  |	«      D �cg c]  }|j                  ||«      s||k7  r|‘Œ }}|r:|j                  |«      }|j                  ||«       |j                  |«       |
dz   }
Œ‰|j                  «       }	|j                  ||	«       |j                  |	«       |
dz   }
|
|k  rŒÂ|j                  |g|z  «       |dz  }|| k  r�Œ*|S c c}w )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.
    FrD   r   z'NetworkXError must have m>1 and m<n, m=z,n=r   z$NetworkXError p must be in [0,1], p=)r   r+   rT   r	   rL   r€   Úpopr2   r�   r0   Ú	neighborsrN   rM   r…   )r3   rF   r4   r)   r#   r5   r‡   rˆ   Úpossible_targetsÚtargetÚcountÚnbrÚneighborhoods                r:   r   r   í  sÀ  € ôf & l¸UÈuÔU€LØˆ1‚u��A’Ü×ÑÐ!HÈÈÈ3ÈqÈcÐRÓSÐSàˆ1‚u��A’Ü×ÑÐ!EÀaÀSÐIÓJÐJä�A�|Ó$€AÜ˜!“W€Nà€FØ
�1‹*Ü)¨.¸!¸TÓBÐà!×%Ñ%Ó'ˆØ	�
‰
�6˜6Ô"Ø×Ñ˜fÔ%ØˆØ�aŠiØ�{‰{‹}˜qÒ ð  !Ÿ{™{¨6Ó2ö àØŸ:™: f¨cÔ2°s¸f²}ò ð �ð  ñ
  ØŸ+™+ lÓ3�CØ—J‘J˜v sÔ+Ø"×)Ñ)¨#Ô.Ø! A™I�EØà%×)Ñ)Ó+ˆFØ�J‰J�v˜vÔ&Ø×!Ñ! &Ô)Ø˜A‘IˆEð# �a‹ið& 	×Ñ˜v˜h¨™lÔ+Ø�!‰ˆð7 �1Œ*ð8 €Hùò' s   Ã" F!c                ó$  — t        |dd¬«      }t        |«      t        |«      }}t        d„ ||fD «       «      rt        j                  d«      ‚t        d|j                  «       z  | z  dz   «      }t        ||«      }|dz
  }t        |«      D ]�  } |j                  «       |k  sŒ|dz  }|j                  | |«       |}|j                  «       |k  r+|dz  }|j                  ||«       |j                  «       |k  rŒ+|j                  «       |k  rŒ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.Grap)
        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.
    FrD   c              3   ó&   K  — | ]	  }|d k\  –— Œ y­w)r   Nrh   )Ú.0r4   s     r:   ú	<genexpr>z!random_lobster.<locals>.<genexpr>n  s   è ø€ Ò
$�aˆ1��6Ñ
$ùs   ‚z6Probability values for `p1` and `p2` must both be < 1.r   g      à?r   )
r   ÚabsÚanyr+   rT   r1   r0   r
   r@   r2   )	r3   Úp1Úp2r)   r#   ÚllenÚLÚcurrent_nodeÚcat_nodes	            r:   r   r   J  s	  € ôD & l¸UÈuÔU€LÜ�‹W”c˜"“gˆ€BÜ
Ñ
$˜B ˜8Ô
$Ô$Ü×ÑÐWÓXÐXô ˆq�4—;‘;“=Ñ  1Ñ$ sÑ*Ó+€DÜ�4˜Ó&€Aà˜!‘8€LÜ�4‹[ò 3ˆØ�k‰k‹m˜bÓ Ø˜AÑˆLØ�J‰J�q˜,Ô'Ø#ˆHØ—+‘+“- "Ò$Ø Ñ!�Ø—
‘
˜8 \Ô2ð —+‘+“- "Ó$ð	 �k‰k‹m˜bÔ ð3ð €Hr;   c          	      ó¦  — t        |dd¬«      }t        d|«      }g }g }d}| D ]Œ  \  }}}	t        ||	z  «      }
|j                  ||
z
  «       t	        j
                  t        ||
||j                  ¬«      |¬«      }|j                  |«       ||z  }t        j                  j                  ||«      }ŒŽ t        t        |«      dz
  «      D ]…  }t        ||   «      }t        ||dz      «      }||   }d}||k  sŒ/|j                  |«      }|j                  |«      }||k(  s|j                  ||«      rŒ@|j                  ||«       |dz   }||k  rŒWŒ‡ |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)

    FrD   r   )r)   r#   )Úfirst_labelr   )r   r	   r1   r�   r+   Úconvert_node_labels_to_integersr   Ú	__class__Ú	operatorsÚunionr@   rV   rL   rM   rN   r2   )Úconstructorr)   r#   r5   ÚglistÚintra_edgesÚnnodesr3   rF   rz   Úinter_edgesÚgÚgiÚnlist1Únlist2Útotal_edgesrQ   rH   r7   s                      r:   r   r   �  s`  € ô8 & l¸UÈuÔU€LÜ�A�|Ó$€Aà€EØ€KØ€Fàò 	%‰ˆˆ1ˆaÜ˜!˜a™%“jˆØ×Ñ˜1˜{™?Ô+Ü×.Ñ.Ü˜Q °$ÀQÇ[Á[ÔQØô
ˆð 	�‰�QŒØ�!‰ˆÜ�L‰L×Ñ˜q !Ó$‰ð	%ô ”C˜“J ‘NÓ#ò ,ˆÜ�e˜B‘i“ˆÜ�e˜B ™F‘mÓ$ˆØ! "‘oˆØˆ
Ø˜;Ó&Ø—‘˜FÓ#ˆAØ—‘˜FÓ#ˆAØ�AŠv˜Ÿ™ A qÔ)Øà—
‘
˜1˜aÔ Ø'¨!™^�
ð ˜;Ô&ð,ð €Hr;   c                óX   — 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).

    FrD   )Úgammar)   re   )r   r   r   )r3   rÄ   r)   re   r#   r}   r5   s          r:   r   r   À  s4   € ôD & l¸UÈuÔU€Lä
'¨°¸TÈÔ
O€CÜ˜S ,Ó/€AØ€Hr;   )r    c                 ó  — t         j                  j                  | ||¬«      }|D �cg c]!  }t        | t	        t        |«      d«      «      ‘Œ# }}t         j                  j                  |||¬«      }|D �cg c]!  }t        | t	        t        |«      d«      «      ‘Œ# }}|D ]B  }d| z  t        |«      z
  dk(  r|c S |j                  d| dz
  «      }	|j                  «       ||	<   ŒD t        j                  d|› d�«      ‚c c}w c c}w )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)   r   r   r   zExceeded max (z%) attempts for a valid tree sequence.)
r+   ÚutilsÚpowerlaw_sequenceÚminrŠ   ÚroundÚsumÚrandintr    rT   )
r3   rÄ   r)   re   ÚzÚsÚzseqÚswapr™   Úindexs
             r:   r   r   é  s  € ô@ 	�‰×"Ñ" 1¨u¸4Ð"Ó@€Aà./Ö0¨ŒC�”3”u˜Q“x Ó#Õ$Ð0€DÐ0ô 	�‰×"Ñ" 5°5¸tÐ"ÓD€Aà./Ö0¨ŒC�”3”u˜Q“x Ó#Õ$Ð0€DÐ0àò 	!ˆð ˆq‰5”3�t“9Ñ Ò!ØŠKØ—‘˜Q  A¡Ó&ˆØ—h‘h“jˆˆUŠð	!ô ×
Ñ
Ø
˜˜ÐDÐEóð ùò% 1ùò
 1s   §&C=Á5&Dc                óÄ  ‡‡	— t        |dd¬«      }|€
ddlŠ	ˆˆ	fd„}t        j                  |¬«      }|j	                  t        | «      «       d\  }}|| k  r‰t        j                  d|j                  «       z
  «       } ‰|| z  || z  d«      |k  r|dz   |dz   }}n>t        j                  |  ||| z  || z  |«      z  «      }|j                  |dz
  |dz
  «       || k  rŒ‰|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
    FrD   Nr   c                 óT   •‡ ‡‡— ˆˆˆˆ fd„}‰j                   j                  |‰d«      S )Nc                 ó   •—  ‰‰‰| «      ‰z
  S ©Nrh   )ÚbÚaÚkernel_integralÚrÚys    €€€€r:   Úmy_functionz=random_kernel_graph.<locals>.kernel_root.<locals>.my_functioni  s   ø€ Ù& q¨!¨QÓ/°!Ñ3Ð3r;   r   )ÚoptimizeÚbrentq)rÚ   r×   rÙ   rÛ   rØ   Úsps   ``` €€r:   Úkernel_rootz(random_kernel_graph.<locals>.kernel_rooth  s#   û€ ÷4ð —;‘;×%Ñ% k°1°aÓ8Ð8r;   r"   )r   r   r   )r   Úscipyr+   r	   Úadd_nodes_fromr@   r.   r/   r0   Úceilr2   )
r3   rØ   rß   r)   r#   Úgraphr\   rZ   rÙ   rÞ   s
    `       @r:   r   r   "  sä   ù€ ôD & l¸UÈuÔU€LØÐÛõ	9ô �N‰N¨Ô5€EØ	×Ñœ˜q›Ô"Ø�F€QˆØ
ˆaŠ%Ü�X‰X�a˜$Ÿ+™+›-Ñ'Ó(Ð(ˆÙ˜1˜q™5 ! a¡%¨Ó+¨qÒ0Ø�q‘5˜!˜a™%ˆq‰Aä—	‘	˜!™k¨!¨a©%°°Q±¸Ó:Ñ:Ó;ˆAØ�N‰N˜1˜q™5 ! a¡%Ô(ð ˆa‹%ð €Lr;   )NFrÕ   )éd   N)NN)rR   Nrä   )(Ú__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   rh   r;   r:   ú<module>rî      s  ðñó
 Û Ý #ã Ý *å +ß HÓ HÝ ,ò€ñ. �ÓØ€×Ñ˜¨TÔ2ðLÈ4ó Ló 3ó ðLñ^ �ÓØ€×Ñ˜¨TÔ2ð;Àdó ;ó 3ó ð;ð~ "€Ø$Ð ñ �ÓØ€×Ñ˜¨TÔ2ð<¸Dó <ó 3ó ð<ñ~ �ÓØ€×Ñ˜¨TÔ2ð4Àdó 4ó 3ó ð4ñn �ÓØ€×Ñ˜¨TÔ2ðFÀDó Fó 3ó ðFñR �ÓØ€×Ñ˜¨TÔ2ðK¸Tó Kó 3ó ðKñ\ �ÓØ€×Ñ˜¨TÔ2ð3?ÐRVó 3?ó 3ó ð3?ñl �ÓØ€×Ñ˜¨TÔ2ðs¸$ó só 3ó ðsòlñ �ÓØ€×Ñ˜¨TÔ2ðGÈtó Gó 3ó ðGñT �ÓØ€×Ñ˜¨TÔ2à+/ðdØAEódó 3ó ðdñN �ÓØ€×Ñ˜¨TÔ2ðaÈ$ó aó 3ó ðañH �ÓØ€×Ñ˜¨TÔ2ðX¸tó Xó 3ó ðXñv �ÓØ€×Ñ˜¨TÔ2ð2¸ó 2ó 3ó ð2ñj �ÓØ€×Ñ˜¨TÔ2ð:¸tó :ó 3ó ð:ñz �ÓØ€×Ñ˜¨TÔ2ð$È4ó $ó 3ó ð$ñN �ÓØ€×Ñ˜Ôò4ó ó ð4ñn �ÓØ€×Ñ˜¨TÔ2à/3ðTØEIóTó 3ó ñTr;   