ó
    †~iÕÉ  ã                   ó  • S r SSKrSSKrSSKJr  SSKrSSKJr  SSK	J
r
  SSKJrJrJrJr  SS	KJr  / S
Qr\" S5      \R&                  " SSS9S$SS.S jj5       5       r\" S5      \R&                  " SSS9S$SS.S jj5       5       r\r\r\" S5      \R&                  " SSS9S%SS.S jj5       5       r\" S5      \R&                  " SSS9S$SS.S jj5       5       r\" S5      \R&                  " SSS9S%SS.S jj5       5       r\" S5      \R&                  " SSS9S%SS.S jj5       5       r\" S5      \R&                  " SSS9S&SS.S jj5       5       r\" S5      \R&                  " SSS9S%SS.S jj5       5       rS r\" S5      \R&                  " SSS9S'SS.S jj5       5       r\" S5      \R&                  " SSS9 S'SS.S jj5       5       r \" S5      \R&                  " SSS9S%SS.S jj5       5       r!\" S5      \R&                  " SSS9S%SS.S jj5       5       r"\" S5      \R&                  " SSS9S%SS.S jj5       5       r#\" S5      \R&                  " SSS9S%SS.S jj5       5       r$\" S5      \R&                  " SSS9S%SS.S jj5       5       r%\" S5      \R&                  " SSS9S(SS.S  jj5       5       r&\" S5      \R&                  " SS!9S(S" j5       5       r'\" S5      \R&                  " SSS9 S'SS.S# jj5       5       r(g))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_graph©Úcreate_usingc                óü  • U(       a  [         R                  O[         R                  n[        XCSUS9nUS::  d  US:¼  a  [         R                  " XX#US9$ [        XS9n[        R                  " SU-
  5      nU(       a  SnSn	X€:  av  [        R                  " SUR                  5       -
  5      n
U	S-   [        X§-  5      -   n	X˜:¼  a  X€:  a  X˜-
  n	US-   nX˜:¼  a  X€:  a  M  X€:  a  UR                  X˜5        X€:  a  Mv  SnSn	X€:  av  [        R                  " SUR                  5       -
  5      n
U	S-   [        X§-  5      -   n	X˜:¼  a  X€:  a  X˜-
  n	US-   nX˜:¼  a  X€:  a  M  X€:  a  UR                  X‰5        X€:  a  Mv  U$ )	u5  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              Ú^/home/mande/repo/quber/.venv/lib/python3.13/site-packages/networkx/generators/random_graphs.pyr   r   )   sn  € öT %Œb�jŠj¬"¯(©(€GÜ%Ø°EÀ7ñ€Lð 	ˆAƒv��a“Ü×"Ò"Ø�t¸\ñ
ð 	
ô 	�AÑ1€Aä	�Š�#˜‘'Ó	€BæØˆØˆØ‹eÜ—’˜# §¡£Ñ-Ó.ˆBØ�A‘œ˜B™G›Ñ$ˆAØ“&˜Q›UØ‘E�Ø˜‘E�ð “&˜Q�Uð ‹uØ—
‘
˜1Ô ð �eð 	
€AØ
€AØ
‹%Ü�XŠX�c˜DŸK™K›MÑ)Ó*ˆØ�‰E”C˜™“LÑ ˆØ‹f˜›Ø‘ˆAØ�A‘ˆAð ‹f˜�ð ‹5Ø�J‰J�qÔð �%ð €Hó    c                óŠ  • U(       a  [         R                  O[         R                  n[        XCSUS9nUS:¼  a	  [	        XS9$ [         R
                  " XS9nUS::  a  U$ U(       a  [        R                  O[        R                  nU" [        U 5      S5       H(  nUR                  5       U:  d  M  UR                  " U6   M*     U$ )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Ÿ   € ö\ %Œb�jŠj¬"¯(©(€GÜ%Ø°EÀ7ñ€Lð 	ˆAƒvÜ˜aÑ;Ð;ä
�Š�qÑ4€AØˆAƒvØˆæ)1Œy×%Ò%´y×7MÑ7M€HÙ”e˜A“h Ö"ˆØ�;‰;‹=˜1ÕØ�JŠJ˜‹Nñ #ð €Hr<   c                ó&  • [        USSS9nX S-
  -  S-  nX:¼  a  [        X5      $ [        X5      nU S:X  a  U$ SnSnSnSn	 UR                  XH-
  5      X-
  :  a  UR	                  Xg5        U	S-  n	X‘:X  a  U$ US-  nUS-  nXp:X  a
  US-  nUS-   nMQ  )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:`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€LØ�A‘‰;˜!Ñ€DØƒyÜ˜aÓ.Ð.Ü�AÓ$€AàˆAƒvØˆà	€AØ	€AØ	€AØ	€AØ
Ø�>‰>˜$™(Ó# a¡eÓ+Ø�J‰J�qÔØ�‰FˆAØ‹vØ�Ø	ˆQ‰ˆØ	ˆQ‰ˆØ‹6Ø�‰FˆAØ�A‘ˆAñ r<   c                óî  • U(       a  [         R                  O[         R                  n[        XCSUS9nU S:X  a  [         R                  " XS9$ U(       a  X S-
  -  O	X S-
  -  S-  nX:¼  a	  [        XS9$ [         R                  " XS9n[        U5      nSn	X‘:  a\  UR                  U5      n
UR                  U5      nX«:X  d  UR                  X«5      (       a  MD  UR                  X«5        U	S-   n	X‘:  a  M\  U$ )au  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ß   € ö@ %Œb�jŠj¬"¯(©(€GÜ%Ø°EÀ7ñ€Lð 	ˆAƒvÜ�~Š~˜aÑ;Ð;Þ'�˜‘U’¨Q°a±%©[¸3Ñ->€IØƒ~Ü˜aÑ;Ð;ä
�Š�qÑ4€AÜ�‹G€EØ€JØ
‹.à�K‰K˜ÓˆØ�K‰K˜ÓˆØ‹6�Q—Z‘Z ×%Ñ%Ùà�J‰J�qÔØ# a™ˆJð �.ð €Hr<   é   c                óþ  • [        USSS9nX:”  a  [        R                  " S5      eX:X  a  [        R                  " X5      $ [	        X5      n[        UR                  5       5      nUn[        SUS-  S-   5       H>  nXxS USU -   n	[        [        U5      5       H  n
UR                  Xz   Xš   5        M     M@     [        UR                  5       5      nU H¢  u  pÍUR                  5       U:  d  M  UR                  U5      nXì:X  d  UR                  XÎ5      (       aJ  UR                  U5      nUR                  U5      U S-
  :¼  a  Mr  Xì:X  a  M2  UR                  XÎ5      (       a  MJ  UR                  XÎ5        M¤     U$ )u9  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  sO  € ôT & l¸UÈuÑU€LØƒuÜ×ÒÐCÓDÐDð 	ƒvÜ× Ò  Ó1Ð1ä�AÓ$€AÜ�—‘“‹O€EØ€Eä�1�a˜1‘f˜q‘jÖ!ˆØ�Bˆi˜%  !˜*Ñ$ˆÜ”s˜5“zÖ"ˆAØ�J‰J�u‘x ¡Ö(ó #ñ "ô 	ˆQ�W‰W‹Y‹€AÛ‰ˆØ�;‰;‹=˜1ÕØ—‘˜EÓ"ˆAð “&˜AŸJ™J q×,Ñ,Ø—K‘K Ó&�Ø—8‘8˜A“; ! a¡%Ó'Ùð •&˜AŸJ™J q×,Ó,ð
 —
‘
˜1Ö ñ ð €Hr<   c                ó   • [        USSS9nX:”  a  [        R                  " S5      eX:X  a  [        R                  " X5      nU$ [        R                  " XS9n[        [        U 5      5      n[        SUS-  S-   5       H'  nXgS USU -   nUR                  [        Xh5      5        M)     [        SUS-  S-   5       HÏ  nXgS USU -   n[        Xh5       H³  u  pšUR                  5       U:  d  M  UR                  U5      nX¹:X  d  UR                  X›5      (       aJ  UR                  U5      nUR                  U	5      U S-
  :¼  a  Mr  X¹:X  a  M2  UR                  X›5      (       a  MJ  UR                  Xš5        UR                  X›5        Mµ     MÑ     U$ )	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   „  sk  € ôZ & l¸UÈuÑU€LØƒuÜ×ÒÐBÓCÐCð 	ƒvÜ×Ò˜aÓ.ˆØˆä
�Š�qÑ4€AÜ”�q“‹N€Eä�1�a˜1‘f˜q‘jÖ!ˆØ˜�)˜e A a˜jÑ(ˆØ	×Ñœ˜UÓ,Ö-ñ "ô �1�a˜1‘f˜q‘jÖ!ˆØ˜�)˜e A a˜jÑ(ˆä˜Ö'‰DˆAØ�{‰{‹}˜qÕ Ø—K‘K Ó&�à“f §
¡
¨1× 0Ñ 0ØŸ™ EÓ*�AØ—x‘x “{ a¨!¡eÓ+Ùð •f §
¡
¨1× 0Ó 0ð
 —M‘M !Ô'Ø—J‘J˜qÖ$ó (ñ "ð €Hr<   é   c          	      ó¦   • [        U5       H-  n[        XX$US9n[        R                  " U5      (       d  M+  Us  $    [        R                  " S5      e)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   Ô  sI   € ô` �5Ž\ˆä   q¸\ÑJˆÜ�?Š?˜1×ÓØŠHñ	 ô
 ×
Ò
Ð=Ó
>Ð>r<   c                óR  ^ ^^^• [        USSS9nTT -  S-  S:w  a  [        R                  " S5      eST s=::  a  T:  d  O  [        R                  " S5      e[        R                  " TUS9nT S:X  a  U$ S mUU UU4S	 jnU" 5       nUc  U" 5       nUc  M  UR	                  U5        U$ )
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                 ój   • U(       d  gU H%  nU H  nX#:X  a    M  X#:”  a  X2p2X#4U ;  d  M      g   M'     g)NTF© )rX   Úpotential_edgesÚs1Ús2s       r;   Ú	_suitableÚ'random_regular_graph.<locals>._suitableI  sD   € ö ØÛ!ˆBÛ%�ð “8âØ“7Ø˜Ø�8 5Õ(Úó &ñ "ð r<   c                  óü  >• [        5       n [        [        T5      5      T
-  nU(       aË  [        S 5      nTR	                  U5        [        U5      n[        X35       HD  u  pEXE:”  a  XTpTXE:w  a  XE4U ;  a  U R                  XE45        M,  X$==   S-  ss'   X%==   S-  ss'   MF     T	" X5      (       d  g UR                  5        VVVs/ s H  u  pg[        U5        H  nUPM     M     nnnnU(       a  MË  U $ s  snnnf )Nc                  ó   • g)Nr   ri   ri   r<   r;   Ú<lambda>Ú=random_regular_graph.<locals>._try_creation.<locals>.<lambda>c  s   € °!r<   r   )	ÚsetrM   rA   r   ÚshuffleÚiterr`   ÚaddÚitems)rX   Ústubsrj   Ústubiterrk   rl   ÚnodeÚ	potentialÚ_rm   Údr4   r*   s            €€€€r;   Ú_try_creationÚ+random_regular_graph.<locals>._try_creation\  sõ   ø€ ô “ˆÜ”U˜1“X“ Ñ"ˆæÜ)©)Ó4ˆOØ�L‰L˜ÔÜ˜E“{ˆHÜ˜hÖ1‘�Ø“7Ø˜Ø“8 " °Ó!6Ø—I‘I˜r˜hÖ'à#Ó'¨1Ñ,Ó'Ø#Ó'¨1Ñ,Õ'ñ 2ñ ˜U×4Ñ4Øð (7×'<Ñ'<Ô'>õâ'>‘O�DÜ˜y×)�Aó á)ñ Ù'>ð ò ÷! ˆeð* ˆùôs   Ã!C7)r   r,   rU   r	   r_   )r}   r4   r*   r$   r6   r~   rX   rm   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                 óž   • [        5       n[        U5      U:  a3  UR                  U 5      nUR                  U5        [        U5      U:  a  M3  U$ )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.
)rs   rW   rN   rv   )ÚseqrG   Úrngrb   Úxs        r;   Ú_random_subsetr„   „  sD   € ô ‹e€GÜ
ˆg‹,˜Ó
Ø�J‰J�s‹OˆØ�‰�AŒô ˆg‹,˜Õ
ð €Nr<   c                óx  • [        USSS9nUS:  d  X:¼  a  [        R                  " SU SU  35      eUc  [        X5      nOK[	        U5      U:  d  [	        U5      U :”  a  [        R                  " SU SU  S35      eUR                  5       nUR                  5        V VVs/ s H  u  p[        U5        H  opPM     M     nnn n[	        U5      n	U	W :  a]  [        X�U5      n
UR                  [        U	/U-  U
5      5        UR                  U
5        UR                  U	/U-  5        U	S-  n	X�:  a  M]  U$ s  snnn f )	uå  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 = u1   BarabÃ¡siâ€“Albert initial graph needs between m=z and n=ú nodes)r   r,   rU   r   rW   ÚcopyrY   rA   r„   r_   r`   Úextend)r4   rG   r*   Úinitial_graphr$   r6   r}   r|   Úrepeated_nodesÚsourcerb   s              r;   r   r   “  sF  € ôR & l¸UÈuÑU€LØˆ1ƒu�“Ü×ÒØIÈ!ÈÈFÐSTÐRUÐVó
ð 	
ð Ñä�qÓ'‰äˆ}Ó Ó!¤S¨Ó%7¸!Ó%;Ü×"Ò"ØCÀAÀ3ÀgÈaÈSÐPVÐWóð ð ×ÑÓ ˆð %&§H¡H¤JÕA¢J™D˜A¼¸a¿°1’a¹‘a¡J€NÒAä�‹V€FØ
�1‹*ô ! °DÓ9ˆà	×Ñœ˜f˜X¨™\¨7Ó3Ô4à×Ñ˜gÔ&à×Ñ˜v˜h¨™lÔ+à�!‰ˆð �*ð €Hùô Bs   Â! D5c                óÐ  • [        USSS9nUS:  d  X:¼  a  [        R                  " SU SU  35      eUS:  d  X :¼  a  [        R                  " SU SU  35      eUS:  d  US:”  a  [        R                  " SU 35      eUS:X  a
  [        XXFS	9$ US:X  a
  [        XXFS	9$ Uc  [	        [        X5      U5      nO][        U5      [        X5      :  d  [        U5      U :”  a&  [        R                  " S
[        X5       SU  S35      eUR                  5       n[        U5      nUR                  5        V V	V
s/ s H  u  p	[        U	5        H  o PM     M     nn	n n
[        U5      nUW :  av  UR                  5       U:  a  UnOUn[        X½U5      nUR                  [        U/U-  U5      5        UR                  U5        UR                  U/U-  5        US-  nXÀ:  a  Mv  U$ s  sn
n	n f )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#   uA   BarabÃ¡siâ€“Albert initial graph must have between max(m1, m2) = z	 and n = r‡   )r   r,   rU   r   r   ÚmaxrW   rˆ   rM   rY   rA   r1   r„   r_   r`   r‰   )r4   Úm1Úm2r5   r*   rŠ   r$   r6   rb   r}   r|   r‹   rŒ   rG   s                 r;   r   r   ß  s   € ô` & l¸UÈuÑU€LØ	ˆAƒv�“Ü×ÒØIÈ"ÈÈVÐTUÐSVÐWó
ð 	
ð 
ˆAƒv�“Ü×ÒØIÈ"ÈÈVÐTUÐSVÐWó
ð 	
ð 	ˆ1ƒu��A“Ü×ÒØIÈ!ÈÐMó
ð 	
ð
 	ˆAƒvÜ$ Q¨DÑLÐLØ	
ˆa‹Ü$ Q¨DÑLÐLàÑä”s˜2“{ LÓ1‰äˆ}Ó¤ B£Ó+¬s°=Ó/AÀAÓ/EÜ×"Ò"ð!Ü!$ R£ ¨Y°q°c¸ðAóð ð ×ÑÓ ˆô �1‹g€Gà$%§H¡H¤JÕA¢J™D˜A¼¸a¿°1’a¹‘a¡J€NÒAä�‹V€FØ
�1‹*à�;‰;‹=˜1ÓØ‰AàˆAô ! °DÓ9ˆà	×Ñœ˜f˜X¨™\¨7Ó3Ô4à×Ñ˜gÔ&à×Ñ˜v˜h¨™lÔ+à�!‰ˆð! �*ð" €Hùô) Bs   Ä4 G!c                óL  • [        USSS9nUS:  d  X:¼  a  SU SU  3n[        R                  " U5      eX#-   S:¼  a  SU SU 3n[        R                  " U5      e[        X5      n/ nUR	                  [        U5      5        Un	X�:  Ga„  UR                  5       n
[        U5      S-
  n[        U5      U-  S-  nX¢:  Ga9  UR                  5       XÁ-
  ::  Ga"  UR                  5        VVs/ s H  u  pÞXë:  d  M  UPM     nnn[        U5       Hæ  nUR                  U5      n[        UU   5      nUR                  U5        UR                  U Vs/ s H  oÝU;  d  M
  UPM     sn5      nUR                  UU5        UR                  U5        UR                  U5        UR                  U5      U:X  a  UR                  U5        UR                  U5      U:X  d  MÍ  UU;   d  MÕ  UR                  U5        Mè     GOX*s=::  a	  X#-   :  Ga¦  O  GO¢XR                  5       s=::  a  U:  Ga‡  O  GOƒUR                  5        VVs/ s H  u  pÞS	Us=:  a  U:  d  M  O  M  UPM     nnn[        U5       GH;  nUR                  U5      n[        UU   5      nUR                  U5      nUR                  U5        UR                  U Vs/ s H  oÝU;  d  M
  UPM     sn5      nUR                  UU5        UR                  UU5        UR                  U5        UR                  U5        UR                  U5      S	:X  a  UU;   a  UR                  U5        UU;   a,  UR                  U5      U:X  a  UR                  U5        GM  GM  UR                  U5      S:X  d  GM*  UR                  U5        GM>     OY[!        X�U5      nUR#                  [%        U	/U-  U5      5        UR	                  U5        UR	                  U	/US-   -  5        U	S-  n	X�:  a  GM„  U$ s  snnf s  snf s  snnf s  snf )
uÑ  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   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_degreeÚclique_sizeÚndÚdegÚeligible_nodesr]   Úsrc_nodeÚprohibited_nodesÚ	dest_noderz   Ú	nbr_nodesrb   s                          r;   r   r   H  sÚ  € ôl & l¸UÈuÑU€LØˆ1ƒu�“ØGÈÀsÈ$ÈqÈcÐRˆÜ×Ò˜sÓ#Ð#Ø�u�ƒzØEÀaÀSÈÈQÈCÐPˆÜ×Ò˜sÓ#Ð#ô 	�AÓ$€Að ÐØ× Ñ ¤ q£Ô*ð €HØ
Œ,ØŸ™›ˆô ˜A› ™
ˆÜ˜1“v Ñ-°Ñ2ˆð Ô §¡£¨[©_Ô!<à01·±´
ÔR²
¡W R¸cÑ>QŸb±
ˆNÑRÜ˜1–X�àŸ;™; ~Ó6�ô $(¨¨(©Ó#4Ð Ø ×'Ñ'¨Ô1à ŸK™KÙ"7ÓVÒ"7˜BÐEUÑ;U—RÑ"7ÑVó�	ð —
‘
˜8 YÔ/ð &×,Ñ,¨XÔ6Ø%×,Ñ,¨YÔ7ð —8‘8˜HÓ%¨Ó6Ø"×)Ñ)¨(Ô3Ø—8‘8˜IÓ&¨-Õ7¸IÈÕ<WØ"×)Ñ)¨)Ö4ó/ ð4 Õ) 1¡5×)Ð)¨a·6±6³8Õ.I¸k×.IÐ.Ið 12·±´
ÔV²
¡W R¸aÀ#Õ>UÈÑ>U›bÑ>U�b±
ˆNÑVÜ˜1—X�à—{‘{ >Ó2�ô !  4¡›M�	ð  Ÿ;™; yÓ1�ð × Ñ  Ô&Ø ŸK™KÙ"7ÓOÒ"7˜BÀYÑ;N—RÑ"7Ñ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 ôL %Ð%:¸tÓDˆGØ×ÑœS ( ¨a¡°Ó9Ô:ð "×(Ñ(¨Ô1à!×(Ñ(¨(¨°q¸1±uÑ)=Ô>Ø˜‰MˆHðo Ž,ðp €Hùó] Sùò Wùó( Wùò Ps6   Ã)PÃ8PÅ	P
ÅP
È=PÉPÉPË 	P!
ËP!
c                ón  • [        USSS9nUS:  d  X:  a  [        R                  " SU SU  35      eUS:”  d  US:  a  [        R                  " SU 35      e[        X5      n[	        U5      nUnXp:  Ga:  [        XaU5      nUR                  5       n	UR                  Xy5        UR                  U	5        Sn
X¡:  aÓ  UR                  5       U:  a�  UR                  U	5       Vs/ s H$  nUR                  X{5      (       a  M  X·:w  d  M"  UPM&     nnU(       a:  UR                  U5      nUR                  X{5        UR                  U5        U
S-   n
Mš  UR                  5       n	UR                  Xy5        UR                  U	5        U
S-   n
X¡:  a  MÓ  UR                  U/U-  5        US-  nXp:  a  GM:  U$ s  snf )ur  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=)r   r,   rU   r	   rM   r„   Úpopr3   r“   r1   Ú	neighborsrO   rN   r‰   )r4   rG   r5   r*   r$   r6   r‹   rŒ   Úpossible_targetsÚtargetÚcountÚnbrÚneighborhoods                r;   r   r   î  s±  € ôf & l¸UÈuÑU€LØˆ1ƒu�“Ü×ÒÐ!HÈÈÈ3ÈqÈcÐRÓSÐSàˆ1ƒu��A“Ü×ÒÐ!EÀaÀSÐIÓJÐJä�AÓ$€AÜ˜!“W€Nà€FØ
Œ*Ü)¨.¸TÓBÐà!×%Ñ%Ó'ˆØ	�
‰
�6Ô"Ø×Ñ˜fÔ%ØˆØ‹iØ�{‰{‹}˜qÓ ð  !Ÿ{™{¨6Ô2ó â2˜ØŸ:™: f×2ó à7:±}÷ Ù2ð ð  ö
  ØŸ+™+ lÓ3�CØ—J‘J˜vÔ+Ø"×)Ñ)¨#Ô.Ø! A™I�EÙà%×)Ñ)Ó+ˆFØ�J‰J�vÔ&Ø×!Ñ! &Ô)Ø˜A‘IˆEð# �ið& 	×Ñ˜v˜h¨™lÔ+Ø�!‰ˆð7 Ž*ð8 €Hùò' s   Ã"F2Ä F2ÄF2c                ó2  • [        USSS9n[        U5      [        U5      p![        S X4 5       5      (       a  [        R                  " S5      e[        SUR                  5       -  U -  S-   5      n[        XT5      nUS-
  n[        U5       H‡  n UR                  5       U:  d  M  US-  nUR                  X5        UnUR                  5       U:  a,  US-  nUR                  X‡5        UR                  5       U:  a  M,  UR                  5       U:  a  Mn  M‰     U$ )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   ó*   #   • U  H	  oS :¬  v •  M     g7f)r   Nri   )Ú.0r5   s     r;   Ú	<genexpr>Ú'random_lobster_graph.<locals>.<genexpr>o  s   é € Ð
$š8�a�Ž6š8ùs   ‚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  sý   € ôD & l¸UÈuÑU€LÜ�‹W”c˜"“gˆÜ
Ñ
$˜B™8Ó
$×$Ñ$Ü×ÒÐWÓXÐXô ˆq�4—;‘;“=Ñ  1Ñ$ sÑ*Ó+€DÜ�4Ó&€Aà˜!‘8€LÜ�4Ž[ˆØ�k‰k‹m˜bÕ Ø˜AÑˆLØ�J‰J�qÔ'Ø#ˆHØ—+‘+“- "Ó$Ø Ñ!�Ø—
‘
˜8Ô2ð —+‘+“- "Õ$ð	 �k‰k‹m˜b× ñ ð €Hr<   c                óJ   • SSK nUR                  S[        SS9  [        XX#US9$ )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   ‚  s2   € ó à‡M�MØMÜ#Øð ñ ô
    rÀ<ÑPÐPr<   c          
      ó   • [        USSS9n[        SU5      n/ n/ nSnU  H�  u  pxn	[        X‰-  5      n
UR                  XŠ-
  5        [        R
                  " [        XzXR                  S9US9nUR                  U5        Xg-  n[        R                  R                  X;5      nMƒ     [        [        U5      S-
  5       HŽ  n[        XL   5      n[        XLS-      5      nX\   nSnUU:  d  M.  UR                  U5      nUR                  U5      nUU:X  d  UR                  UU5      (       a  MI  UR                  UU5        US-   nUU:  a  M`  M�     U$ )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   •  sE  € ô8 & l¸UÈuÑU€LÜ�A�|Ó$€Aà€EØ€KØ€Fã‰ˆˆaÜ˜!™%“jˆØ×Ñ˜1™?Ô+Ü×.Ò.Ü˜Q°$Ç[Á[ÑQØñ
ˆð 	�‰�QŒØ‰ˆÜ�L‰L×Ñ˜qÓ$Šñ ô ”C˜“J ‘NÖ#ˆÜ�e‘i“ˆÜ�e ™F‘mÓ$ˆØ!‘oˆØˆ
Ø˜;Õ&Ø—‘˜FÓ#ˆAØ—‘˜FÓ#ˆAØ�A‹v˜Ÿ™ A q×)Ñ)Ùà—
‘
˜1˜aÔ Ø'¨!™^�
ð ˜;×&ñ $ð €Hr<   c                óF   • [        USSS9n[        XX#S9n[        XT5      nU$ )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*   rf   )r   r   r   )r4   rÐ   r*   rf   r$   r�   r6   s          r;   r   r   Ô  s.   € ôD & l¸UÈuÑU€Lä
'¨¸TÑ
O€CÜ˜SÓ/€AØ€Hr<   )r!   c                 ó6  • [         R                  R                  XUS9nU Vs/ s H"  n[        U [	        [        U5      S5      5      PM$     nn[         R                  R                  X1US9nU Vs/ s H"  n[        U [	        [        U5      S5      5      PM$     nnU HV  n[         R                  R                  U5      u  p˜U	(       a  Us  $ UR                  SU S-
  5      n
UR                  5       Xj'   MX     [         R                  " SU S35      es  snf s  snf )aï  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   zExceeded max (z%) attempts for a valid tree sequence.)
r,   ÚutilsÚpowerlaw_sequenceÚminrŽ   ÚroundÚis_valid_tree_degree_sequenceÚrandintr¤   rU   )r4   rÐ   r*   rf   ÚzÚsÚzseqÚswapr|   ÚvalidÚindexs              r;   r   r   ý  sú   € ô@ 	�‰×"Ñ" 1¸4Ð"Ð@€Aá./Ó0ªa¨ŒC�”3”u˜Q“x Ó#Ö$©a€DÐ0ô 	�‰×"Ñ" 5¸tÐ"ÐD€Aá./Ó0ªa¨ŒC�”3”u˜Q“x Ó#Ö$©a€DÐ0ãˆÜ—8‘8×9Ñ9¸$Ó?‰ˆÞØŠKØ—‘˜Q  A¡Ó&ˆØ—h‘h“jˆ‹ñ ô ×
Ò
Ø
˜˜ÐDÐEóð ùò 1ùò
 1s   £)DÁ0)Dc                ó¸  ^^	• [        USSS9nUc  SSKm	UU	4S jn[        R                  " US9nUR	                  [        U 5      5        Su  pgX`:  a‡  [        R                  " SUR                  5       -
  5      * nT" X`-  Xp-  S5      U::  a
  US-   US-   pvO<[        R                  " X" X`-  Xp-  U5      -  5      nUR                  US-
  US-
  5        X`:  a  M‡  U$ )	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                 óV   >^ ^^• UUUU 4S jnTR                   R                  UTS5      $ )Nc                 ó   >• T" TTU 5      T-
  $ ©Nri   )ÚbÚaÚkernel_integralÚrÚys    €€€€r;   Úmy_functionÚ=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_rootÚ(random_kernel_graph.<locals>.kernel_rootx  s(   û€ ÷4ð 4ð —;‘;×%Ñ% k°1°aÓ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  sÔ   ù€ ôD & l¸UÈuÑU€LØÑÛö	9ô �NŠN¨Ñ5€EØ	×Ñœ˜q›Ô"Ø�F€QØ
‹%Ü�XŠX�a˜$Ÿ+™+›-Ñ'Ó(Ð(ˆÙ˜1™5 !¡%¨Ó+¨qÓ0Ø�q‘5˜!˜a™%‰qä—	’	˜!˜k¨!©%°±¸Ó:Ñ:Ó;ˆAØ�N‰N˜1˜q™5 ! a¡%Ô(ð �%ð €Lr<   )NFrâ   )éd   N)NN)rS   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   r    ri   r<   r;   Ú<module>rý      s(  ðñó
 Û Ý #ã Ý *å +ß HÓ HÝ ,ò€ñ0 �ÓØ×Ò˜¨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¸tõ 2ó 3ó ð2ñj �ÓØ×Ò˜¨TÑ2ðQ¸õ Qó 3ó ðQñ" �ÓØ×Ò˜¨TÑ2ð:¸tõ :ó 3ó ð:ñz �ÓØ×Ò˜¨TÑ2ð$È4õ $ó 3ó ð$ñN �ÓØ×Ò˜Ñó0ó ó ð0ñf �ÓØ×Ò˜¨TÑ2à/3ðTØEIõTó 3ó ñTr<   