+
    �°³j'Ù  ã                   óz  € R t ^ RIt^ RIt^ RIHt ^ RIt^ RIHt ^RI	H
t
 ^RIHtHtHtHt ^RIHt . ROt]! ^4      ]P&                  ! RRR7      R R	R/R
 ll4       4       t]! ^4      ]P&                  ! RRR7      R R	R/R ll4       4       t]t]t]! ^4      ]P&                  ! RRR7      R!R	R/R ll4       4       t]! ^4      ]P&                  ! RRR7      R R	R/R ll4       4       t]! ^4      ]P&                  ! RRR7      R!R	R/R ll4       4       t]! ^4      ]P&                  ! RRR7      R!R	R/R ll4       4       t]! ^4      ]P&                  ! RRR7      R"R	R/R ll4       4       t]! ^4      ]P&                  ! RRR7      R!R	R/R ll4       4       tR t]! ^4      ]P&                  ! RRR7      R#R	R/R ll4       4       t]! ^4      ]P&                  ! RRR7      R#R	R/R ll4       4       t ]! ^4      ]P&                  ! RRR7      R!R	R/R ll4       4       t!]! ^4      ]P&                  ! RRR7      R!R	R/R ll4       4       t"]! ^4      ]P&                  ! RRR7      R!R	R/R ll4       4       t#]! ^4      ]P&                  ! RRR7      R!R	R/R ll4       4       t$]! ^4      ]P&                  ! RRR7      R$R	R/R ll4       4       t%]! ^4      ]P&                  ! RR7      R$R l4       4       t&]! ^4      ]P&                  ! RRR7      R#R	R/R ll4       4       t']! R4      ]P&                  ! RRR7      R!R l4       4       t(R# )%z 
Generators for random graphs.

N)Údefaultdict)Úpy_random_state)Úcheck_create_using)Úcomplete_graphÚempty_graphÚ
path_graphÚ
star_graph)Údegree_sequence_treeT)ÚgraphsÚreturns_graphÚcreate_usingc               óZ  € V'       d   \         P                  M\         P                  p\        WCRVR7      pV^ 8:  g   V^8¼  d   \         P                  ! WW#VR7      # \        WR7      p\        P                  ! RV,
          4      pV'       d�   ^pRp	W€8  d…   \        P                  ! RVP                  4       ,
          4      p
V	^,           \        W§,          4      ,           p	W˜8¼  d   W€8  d   W˜,
          p	V^,           pK  W€8  g   Kw  VP                  W˜4       KŠ  ^pRp	W€8  d…   \        P                  ! RVP                  4       ,
          4      p
V	^,           \        W§,          4      ,           p	W˜8¼  d   W€8  d   W˜,
          p	V^,           pK  W€8  g   Kw  VP                  W‰4       KŠ  V# )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Údefault)Úseedr   r   ©r   g      ð?éÿÿÿÿ)ÚnxÚDiGraphÚGraphr   Úgnp_random_graphr   ÚmathÚlogÚrandomÚintÚadd_edge)ÚnÚpr   r   r   r   ÚGÚlpÚvÚwÚlrs   &&&&$      Úb/home/luca/screen-checking/.venv/lib/python3.14/site-packages/networkx/generators/random_graphs.pyÚfast_gnp_random_graphr&   )   sD  € ÷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’ØŽuØ—
‘
˜1Ö ð 	
€AØ
€AØ
Œ%Ü�XŠX�c˜DŸK™K›MÕ)Ó*ˆØ��E”C˜�“LÕ ˆØŒf˜œØ•ˆAØ�A•ŠAØŽ5Ø�J‰J�qÖØ€Hó    c               ó¨  € V'       d   \         P                  M\         P                  p\        WCRVR7      pV^8¼  d   \	        WR7      # \         P
                  ! WR7      pV^ 8:  d   V# V'       d   \        P                  M\        P                  pV! \        V 4      ^4       F*  pVP                  4       V8  g   K  VP                  ! V!   K,  	  V# )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   Ú	itertoolsÚpermutationsÚcombinationsÚranger   r   )	r   r   r   r   r   r   r    Ú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               óŠ  € \        VRRR7      pW ^,
          ,          ^,          pW8¼  d   \        W4      # \        W4      pV ^8X  d   V# ^ p^p^ p^ p	 VP                  WH,
          4      W,
          8  d#   VP	                  Wg4       V	^,          p	W‘8X  d   V# V^,          pV^,          pWp8X  g   K_  V^,          pV^,           pKs  )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   Ú	randranger   )
r   Úmr   r   Úmmaxr    Úur"   ÚtÚks
   &&&$      r%   Údense_gnm_random_graphr7   ¿   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•ŠAr'   c               ó:  € V'       d   \         P                  M\         P                  p\        WCRVR7      pV ^8X  d   \         P                  ! WR7      # V'       d   W ^,
          ,          MW ^,
          ,          R,          pW8¼  d   \        WR7      # \         P                  ! WR7      p\        V4      p^ p	W‘8  d^   VP                  V4      p
VP                  V4      pW«8X  g   VP                  W«4      '       d   KG  VP                  W«4       V	^,           p	Kc  V# )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   g       @)
r   r   r   r   r   r   ÚlistÚchoiceÚhas_edger   )r   r2   r   r   r   r   Ú	max_edgesr    ÚnlistÚ
edge_countr4   r"   s   &&&&$       r%   Úgnm_random_graphr?      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               ó  € \        VRRR7      pW8”  d   \        P                  ! R4      hW8X  d   \        P                  ! W4      # \	        W4      p\        VP                  4       4      pTp\        ^V^,          ^,           4       FJ  pWxR V^ V ,           p	\        \        V4      4       F!  p
VP                  Wz,          Wš,          4       K#  	  KL  	  \        VP                  4       4      pV F�  w  rÍVP                  4       V8  g   K  VP                  V4      pWì8X  g   VP                  WÎ4      '       d3   VP                  V4      pVP                  V4      V ^,
          8¼  g   KM  K|  VP                  WÎ4       K�  	  V# )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
Fr0   z"k>=n, choose smaller k or larger nN)r   r   ÚNetworkXErrorr   r   r9   Únodesr,   Úlenr   Úedgesr   r:   r;   Údegree)r   r6   r   r   r   r    r=   ÚfromvÚjÚtovÚir.   r4   r"   r#   s   &&&&$          r%   Únewman_watts_strogatz_graphrJ   9  s8  € ô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¥%Ö'Ùà—
‘
˜1Ö ñ ð €Hr'   c               ó6  € \        VRRR7      pW8”  d   \        P                  ! R4      hW8X  d   \        P                  ! W4      pV# \        P                  ! WR7      p\        \        V 4      4      p\        ^V^,          ^,           4       F+  pWgR V^ V ,           pVP                  \        Wh4      4       K-  	  \        ^V^,          ^,           4       F¾  pWgR V^ V ,           p\        Wh4       Fž  w  ršVP                  4       V8  g   K  VP                  V4      pW¹8X  g   VP                  W›4      '       d3   VP                  V4      pVP                  V	4      V ^,
          8¼  g   KM  K|  VP                  Wš4       VP                  W›4       K   	  KÀ  	  V# )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.
Fr0   z!k>n, choose smaller k or larger nr   N)r   r   rA   r   r   r9   r,   Úadd_edges_fromÚzipr   r:   r;   rE   Úremove_edger   )r   r6   r   r   r   r    rB   rG   Útargetsr4   r"   r#   s   &&&&$       r%   Úwatts_strogatz_graphrP   „  sT  € ô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Ö+Ùà—M‘M !Ô'Ø—J‘J˜qÖ$ó (ñ "ð €Hr'   c          	     ó®   € \        V4       F1  p\        WW$VR7      p\        P                  ! V4      '       g   K/  Vu # 	  \        P                  ! R4      h)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,   rP   r   Úis_connectedrA   )r   r6   r   Útriesr   r   rI   r    s   &&&&&$  r%   Úconnected_watts_strogatz_graphrT   Ô  sI   € ô` �5Ž\ˆä   q¸\ÔJˆÜ�?Š?˜1×ÔØŠHñ	 ô
 ×
Ò
Ð=Ó
>Ð>r'   c               ór  a aaa€ \        VRRR7      pSS ,          ^,          ^ 8w  d   \        P                  ! R4      h^ S u;8:  d   S8  g   M \        P                  ! R4      h\        P                  ! SVR7      pS ^ 8X  d   V# R oVV VV3R lpV! 4       pVf
   V! 4       pK  VP	                  V4       V# )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
Fr0   zn * d must be evenz+the 0 <= d < n inequality must be satisfiedr   c                 óx   € V'       g   R # V F)  pV F   pW#8X  d    K  W#8”  d   Y2r2W#3V 9  g   K    R # 	  K+  	  R# )TF© )rD   Úpotential_edgesÚs1Ús2s   &&  r%   Ú	_suitableÚ'random_regular_graph.<locals>._suitableI  sD   € ÷ ÙÛ!ˆBÛ%�ð ”8âØ”7Ø˜Ø�8 5Ö(Ûó &ñ "ñ r'   c                  ó  <€ \        4       p \        \        S4      4      S
,          pV'       dØ   \        R  4      pSP	                  V4       \        V4      p\        W34       FW  w  rEWE8”  d   YTrTWE8w  d   WE3V 9  d   V P                  WE34       K/  W$;;,          ^,          uu&   W%;;,          ^,          uu&   KY  	  S	! W4      '       g   R# VP                  4        UUUu. uF  w  rg\        V4       F  pVNK  	  K  	  ppppKß  V # u upppi )c                  ó   € ^ # )é    rW   rW   r'   r%   Ú<lambda>Ú=random_regular_graph.<locals>._try_creation.<locals>.<lambda>c  s   € ±!r'   N)	Úsetr9   r,   r   ÚshuffleÚiterrM   ÚaddÚitems)rD   ÚstubsrX   ÚstubiterrY   rZ   ÚnodeÚ	potentialÚ_r[   Údr   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   Ã!D)r   r   rA   r   rL   )rl   r   r   r   r    rm   rD   r[   s   fff$   @r%   Úrandom_regular_graphro     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                ó‚   € \        4       p\        V4      V8  d%   VP                  V 4      pVP                  V4       K4  V# )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.
)rb   rC   r:   re   )Úseqr2   ÚrngrO   Úxs   &&&  r%   Ú_random_subsetrt   „  s4   € ô ‹e€GÜ
ˆg‹,˜Ô
Ø�J‰J�s‹OˆØ�‰�AŽØ€Nr'   c               ó”  € \        VRRR7      pV^8  g   W8¼  d   \        P                  ! RV RV  24      hVf   \        W4      pMM\	        V4      V8  g   \	        V4      V 8”  d   \        P                  ! RV RV  R24      hVP                  4       pVP                  4        U UUu. uF  w  r\        V4       F  qpNK  	  K  	  ppp p\	        V4      p	V	X 8  de   \        W�V4      p
VP                  \        V	.V,          V
4      4       VP                  V
4       VP                  V	.V,          4       V	^,          p	Kk  V# u uppp i )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.
Fr0   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   rA   r   rC   ÚcopyrE   r,   rt   rL   rM   Úextend)r   r2   r   Úinitial_graphr   r    rl   rk   Úrepeated_nodesÚsourcerO   s   &&&&$      r%   Úbarabasi_albert_graphr}   “  s=  € ô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   Â)Ec               ó  € \        VRRR7      pV^8  g   W8¼  d   \        P                  ! RV RV  24      hV^8  g   W 8¼  d   \        P                  ! RV RV  24      hV^ 8  g   V^8”  d   \        P                  ! RV 24      hV^8X  d   \        WWFR7      # V^ 8X  d   \        WWFR7      # Vf   \	        \        W4      V4      pM_\        V4      \        W4      8  g   \        V4      V 8”  d'   \        P                  ! R\        W4       R	V  R
24      hVP                  4       p\        V4      pVP                  4        U U	U
u. uF  w  r	\        V	4       F  q NK  	  K  	  pp	p p
\        V4      pVX 8  d   VP                  4       V8  d   TpMTp\        W½V4      pVP                  \        V.V,          V4      4       VP                  V4       VP                  V.V,          4       V^,          pK…  V# u up
p	p i )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 a 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.
Fr0   u;   Dual BarabÃ¡siâ€“Albert must have m1 >= 1 and m1 < n, m1 = rv   u;   Dual BarabÃ¡siâ€“Albert must have m2 >= 1 and m2 < n, m2 = 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 = rw   )r   r   rA   r}   r   ÚmaxrC   rx   r9   rE   r,   r   rt   rL   rM   ry   )r   Úm1Úm2r   r   rz   r   r    rO   rl   rk   r{   r|   r2   s   &&&&&&$       r%   Údual_barabasi_albert_graphr‚   ß  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   ÅG<c               óÔ  € \        VRRR7      pV^8  g   W8¼  d   RV RV  2p\        P                  ! V4      hW#,           ^8¼  d   RV RV 2p\        P                  ! V4      h\        W4      p. pVP	                  \        V4      4       Tp	W�8  Ed¾   VP                  4       p
\        V4      ^,
          p\        V4      V,          ^,          pW¢8  EdG   VP                  4       WÁ,
          8:  Ed+   VP                  4        UUu. uF  w  rÞWë8  g   K  VNK  	  ppp\        V4       Fí  pVP                  V4      p\        VV,          4      pVP                  V4       TP                  V Uu. uF  qÝV9  g   K  VNK  	  up4      pVP                  VV4       VP                  V4       VP                  V4       VP                  V4      V8X  d   VP                  V4       VP                  V4      V8X  g   KÓ  VV9   g   KÜ  VP                  V4       Kï  	  EK�  Y*u;8:  d   W#,           8  Edµ   M EM°WP                  4       u;8:  d	   V8  Ed”   M EM�VP                  4        UUu. uF  w  rÞ^ Tu;8  d
   V8  g   K  M K  VNK  	  ppp\        V4       EFD  pVP                  V4      p\        VV,          4      pVP                  V4      pVP                  V4       TP                  V Uu. uF  qÝV9  g   K  VNK  	  up4      pVP                  VV4       VP                  VV4       VP                  V4       VP                  V4       VP                  V4      ^ 8X  d   VV9   d   VP                  V4       VV9   d.   VP                  V4      V8X  d   VP                  V4       EK  EK  VP                  V4      ^8X  g   EK3  VP                  V4       EKG  	  EKX  \!        W�V4      pVP#                  \%        V	.V,          V4      4       VP	                  V4       VP	                  V	.V^,           ,          4       V	^,          p	EKÄ  V# u uppi u upi u uppi u upi )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.
Fr0   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   rA   r   ry   r,   r   rC   ÚsizerE   r:   r9   Úappendr   ÚremoverN   rt   rL   rM   )r   r2   r   Úqr   r   Úmsgr    Úattachment_preferenceÚnew_nodeÚa_probabilityÚclique_degreeÚclique_sizeÚndÚdegÚeligible_nodesrI   Úsrc_nodeÚprohibited_nodesÚ	dest_noderi   Ú	nbr_nodesrO   s   &&&&&$                 r%   Úextended_barabasi_albert_graphr•   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˜b±
ˆNÑRÜ˜1–X�àŸ;™; ~Ó6�ô $(¨¨(­Ó#4Ð Ø ×'Ñ'¨Ô1à ŸK™KÙ"7ÓVÑ"7˜BÐEUÑ;U—R�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�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Ø€Hùó] Sùò Wùó( Wùò Ps6   Ä
QÄQÅ/Q
Å<Q
É*QÊQÊQË2Q%
Ë?Q%
c               ó’  € \        VRRR7      pV^8  g   W8  d   \        P                  ! RV RV  24      hV^8”  g   V^ 8  d   \        P                  ! RV 24      h\        W4      p\	        V4      pTpWp8  EdE   \        WaV4      pVP                  4       p	VP                  Wy4       VP                  V	4       ^p
W¡8  dÚ   VP                  4       V8  dˆ   VP                  V	4       Uu. uF&  pVP                  W{4      '       d   K  W·8w  g   K$  VNK(  	  ppV'       d?   VP                  V4      pVP                  W{4       VP                  V4       V
^,           p
K¢  VP                  4       p	VP                  Wy4       VP                  V	4       V
^,           p
Kß  VP                  V.V,          4       V^,          pEKK  V# u upi )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.
Fr0   z'NetworkXError must have m>1 and m<n, m=z,n=z$NetworkXError p must be in [0,1], p=)r   r   rA   r   r9   rt   Úpopr   r…   r   Ú	neighborsr;   r:   ry   )r   r2   r   r   r   r    r{   r|   Úpossible_targetsÚtargetÚcountÚnbrÚneighborhoods   &&&&$        r%   Úpowerlaw_cluster_graphrž   î  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:±}÷ �CÙ2ð ð  ÷
  ØŸ+™+ lÓ3�CØ—J‘J˜vÔ+Ø"×)Ñ)¨#Ô.Ø! A�I�EÙà%×)Ñ)Ó+ˆFØ�J‰J�vÔ&Ø×!Ñ! &Ô)Ø˜A•IŠEà×Ñ˜v˜h¨�lÔ+Ø�!�‹Ø€Hùò' s   Ã,GÄ
GÄGc               ó`  € \        VRRR7      p\        V4      \        V4      r!\        ;QJ d    R W3 4       F  '       g   K   RM	  RM! R W3 4       4      '       d   \        P                  ! R4      h\        ^VP                  4       ,          V ,          R,           4      p\        WT4      pV^,
          p\        V4       Fg  p VP                  4       V8  g   K  V^,          pVP                  W4       TpVP                  4       V8  g   KJ  V^,          pVP                  W‡4       K3  	  V# )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.
Fr0   c              3   ó*   "  € T F	  q^8¬  x € K  	  R# 5i)é   NrW   )Ú.0r   s   & r%   Ú	<genexpr>Ú'random_lobster_graph.<locals>.<genexpr>o  s   é € Ð
$™8�a�Ž6›8ùs   ‚Tz6Probability values for `p1` and `p2` must both be < 1.g      à?)
r   ÚabsÚanyr   rA   r   r   r   r,   r   )	r   Úp1Úp2r   r   ÚllenÚLÚcurrent_nodeÚcat_nodes	   &&&&$    r%   Úrandom_lobster_graphr­   K  sï   € ôD & l¸UÈuÔU€LÜ�‹W”c˜"“gˆß
ƒsÑ
$˜B™8Ó
$‡s‡s‚sÑ
$˜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ñ ð €Hr'   c          
     óð  € \        VRRR7      p\        ^ V4      p. p. p^ pV  F“  w  rxp	\        W‰,          4      p
VP                  WŠ,
          4       \        P
                  ! \        WzWP                  R7      VR7      pVP                  V4       Wg,          p\        P                  P                  W;4      pK•  	  \        \        V4      ^,
          4       F�  p\        WL,          4      p\        WL^,           ,          4      pW\,          p^ pVV8  g   K?  VP                  V4      pVP                  V4      pVV8X  g   VP                  VV4      '       d   KL  VP                  VV4       V^,           pKi  	  V# )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)

Fr0   )r   r   )Úfirst_label)r   r   r   r…   r   Úconvert_node_labels_to_integersr?   Ú	__class__Ú	operatorsÚunionr,   rC   r9   r:   r;   r   )Úconstructorr   r   r    ÚglistÚintra_edgesÚnnodesr   r2   rl   Úinter_edgesÚgÚgiÚnlist1Únlist2Útotal_edgesr>   r4   r"   s   &&$                r%   Úrandom_shell_graphr¾   ‚  s;  € ô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               óR   € \        VRRR7      p\        WW#R7      p\        WT4      pV# )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).

Fr0   )Úgammar   rS   )r   Úrandom_powerlaw_tree_sequencer	   )r   rÀ   r   rS   r   rq   r    s   &&&&$  r%   Úrandom_powerlaw_treerÂ   Á  s.   € ôD & l¸UÈuÔU€Lä
'¨¸TÔ
O€CÜ˜SÓ/€AØ€Hr'   )r
   c                óH  € \         P                  P                  WVR7      pV Uu. uF"  p\        V \	        \        V4      ^ 4      4      NK$  	  pp\         P                  P                  W1VR7      pV Uu. uF"  p\        V \	        \        V4      ^ 4      4      NK$  	  ppV F[  p\         P                  P                  V4      w  r˜V	'       d   Vu # VP                  ^ V ^,
          4      p
VP                  4       Wj&   K]  	  \         P                  ! RV R24      hu upi u upi )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   zExceeded max (z%) attempts for a valid tree sequence.)
r   ÚutilsÚpowerlaw_sequenceÚminr   ÚroundÚis_valid_tree_degree_sequenceÚrandintr—   rA   )r   rÀ   r   rS   ÚzÚsÚzseqÚswaprk   Ú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Á5(Dc               ó  aa	€ \        VRRR7      pVf   ^ RIo	VV	3R lp\        P                  ! VR7      pVP	                  \        V 4      4       ^^rvW`8  d­   \        P                  ! ^VP                  4       ,
          4      ) pS! W`,          Wp,          ^4      V8:  d   V^,           V^,           rvK`  \        P                  ! W! W`,          Wp,          V4      ,          4      pVP                  V^,
          V^,
          4       K²  V# )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
Fr0   Nc                 óV   <a aa€ VVVV 3R  lpSP                   P                  VS^4      # )c                 ó&   <€ S! SSV 4      S,
          # ©NrW   )ÚbÚaÚkernel_integralÚrÚys   &€€€€r%   Úmy_functionÚ=random_kernel_graph.<locals>.kernel_root.<locals>.my_functionf  s   ø€ Ù& q¨!¨QÓ/°!Õ3Ð3r'   )ÚoptimizeÚbrentq)rÙ   rÖ   rØ   rÚ   r×   Úsps   fff €€r%   Úkernel_rootÚ(random_kernel_graph.<locals>.kernel_roote  s(   û€ ÷4ð 4ð —;‘;×%Ñ% k°1°aÓ8Ð8r'   r   )r   Úscipyr   r   Úadd_nodes_fromr,   r   r   r   Úceilr   )
r   r×   rß   r   r   ÚgraphrI   rG   rØ   rÞ   s
   &f&&$    @r%   Úrandom_kernel_graphrå     sË   ù€ ôD & l¸UÈuÔU€LØÒÛö	9ô �NŠN¨Ô5€EØ	×Ñœ˜q›Ô"Ø�ˆØ
Œ%Ü�XŠX�a˜$Ÿ+™+›-Õ'Ó(Ð(ˆÙ˜1�5 !¥%¨Ó+¨qÔ0Ø�q•5˜!˜a�%Šqä—	’	˜!˜k¨!­%°µ¸Ó:Õ:Ó;ˆAØ�N‰N˜1˜q�5 ! a¥%Ö(Ø€Lr'   r   c                óh  aaaa€ V P                  4       pVP                  V3R lV P                   4       4       . p\        \	        S4      4      oV P                  4        F=  w  ooVP                  S4       VP                  VVV3R l\	        S4       4       4       K?  	  VP                  V4       V# )ux  Return a `k`-lift of a graph using random permutations.

The resulting graph ``H`` has `k` copies of each node from `G`.
For each edge ``(u, v)`` in `G`, a random permutation is used to connect the ``i``-th copy of ``u``
to the permuted ``i``-th copy of ``v`` in ``H``.

Parameters
----------
G : Graph, DiGraph, MultiGraph, or MultiDiGraph
    The base graph to lift. Any standard NetworkX graph type is supported.
k : int
    The lift parameter. Each node in `G` is expanded to `k` copies.
seed : int, RandomState, or None (default: None)
    Seed for the random number generator (used for permutation generation).
    This ensures reproducibility.
    See :ref:`Randomness<randomness>`.

Returns
-------
H : Graph, DiGraph, MultiGraph, or MultiDiGraph
    The resulting `k`-lifted graph. The returned type matches the input graph type.

Notes
-----
Given a base graph `G` and a lift parameter `k`, this function performs a `k`-lift as follows:

- For each node ``v`` in `G`, it creates `k` copies: ``(v, 0), ..., (v, k - 1)``.
- For each edge ``(u, v)`` in `G`, a random permutation ``Ïƒ`` is applied to determine new edges:
  if ``Ïƒ(i) = j``, then ``((u, i), (v, j))`` is added to ``H``.
  The permutation is simulated by creating a shuffled list ``permutation`` of values 0 to ``k - 1``.
  Each ``i``-th copy of ``u`` is then connected to the ``permutation[i]``-th copy of ``v``.

This operation is often used in the construction of expander graphs [1]_.
If the base graph is a decent expander (i.e., has a good spectral gap-the
difference between the two largest eigenvalues (in absolute value) of its adjacency matrix),
then its `k`-lifts are also expanders, with the spectral gap preserved
(or slightly reduced and stabilizing for larger `k` [3]_) with high probability,
while producing a larger graph of the same degree.

For arbitrary input graphs, the lifted graph may be disconnected.
Disconnected lifts occur more often when the base graph is a poor expander.
Since enforcing connectivity in such cases is unlikely to
produce a good expander, this implementation returns the lift directly,
even if it is disconnected. Users who require connected results may wrap
this function with retries until a connected lift is found.

This implementation supports all standard NetworkX graph types.
While expander graphs are most commonly studied as degree-regular undirected simple graphs/multigraphs,
the `k`-lift operation itself is well-defined and can also be beneficial for directed [4]_
and non-regular [5]_ graphs.

References
----------
.. [1] Y. Bilu and N. Linial, "Lifts, Discrepancy and Nearly Optimal Spectral Gap."
   *Combinatorica*, 26(5), pp. 495â€“519, 2006,
   https://www.cs.huji.ac.il/~nati/PAPERS/raman_lift.pdf
.. [2] A. Valadarsky, G. Shahaf, M. Dinitz and M. Schapira,
   "Xpander: Towards Optimal-Performance Datacenters.",
   In *Proceedings of the 12th International Conference on
   Emerging Networking Experiments and Technologies (CoNEXT)*, 2016,
   https://dl.acm.org/doi/pdf/10.1145/2999572.2999580
.. [3] N. Agarwal, K. Chandrasekaran, A. Kolla and V. Madan,
   "On the Expansion of Group-Based Lifts.", arXiv preprint arXiv:1311.3268v2, 2016,
   http://arxiv.org/abs/1311.3268v2
.. [4] P. Chebolu and A. Frieze,
   "Hamilton Cycles in Random Lifts of Directed Graphs.",
   Department of Mathematics, Carnegie Mellon University, 2007,
   https://www.math.cmu.edu/~af1p/Texfiles/LiftHamDir.pdf
.. [5] S. Hoory,
   "On the Girth of Graph Lifts." arXiv:2401.01238v1, 2024,
   https://arxiv.org/pdf/2401.01238

Examples
--------
>>> G = nx.complete_graph(4)  # 3-regular, connected graph
>>> H = nx.random_k_lift(G, 4, seed=42)  # 4-lift of G
>>> H.number_of_nodes()
16
c              3   óN   <"  € T F  p\        S4       F  q!V3x € K
  	  K  	  R # 5irÔ   )r,   )r¢   r"   rI   r6   s   &  €r%   r£   Ú random_k_lift.<locals>.<genexpr>Í  s   øé € Ð?¡W ´e¸A¶h°˜•V±h‘V£Wùs   ƒ"%c              3   óB   <"  € T F  pSV3SSV,          33x € K  	  R # 5irÔ   rW   )r¢   rI   Úpermutationr4   r"   s   & €€€r%   r£   rè   Ô  s#   øé € ÐE¹H°q�q˜!�f˜q +¨a¥.Ð1Õ2»Hùs   ƒ)	r±   râ   rB   r9   r,   rD   rc   ry   rL   )r    r6   r   ÚHrD   rê   r4   r"   s   &f&  @@@r%   Úrandom_k_liftrì   x  sŠ   û€ ðd 	
�‰‹€Að ×ÑÔ? Q§W¢WÓ?Ô?ð €EÜ”u˜Q“x“.€KØ—‘–	‰ˆˆ1Ø�‰�[Ô!Ø�‰ÖE¼EÀ!¼HÓEÖEñ ð ×Ñ�UÔà€Hr'   )r&   r   r7   r?   Úerdos_renyi_graphÚbinomial_graphrJ   rP   rT   ro   r}   r‚   r•   rž   r­   r¾   rÂ   rÁ   rå   rì   )NFrÔ   )éd   N)NN)é   Nrï   ))Ú__doc__r)   r   Úcollectionsr   Únetworkxr   Únetworkx.utilsr   Ú
utils.miscr   Úclassicr   r   r   r   Ú
degree_seqr	   Ú__all__Ú_dispatchabler&   r   rî   rí   r7   r?   rJ   rP   rT   ro   rt   r}   r‚   r•   rž   r­   r¾   rÂ   rÁ   rå   rì   rW   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ñ:¸tô :ó 3ó ð:ñz �ÓØ×Ò˜¨TÔ2ñ$È4ô $ó 3ó ð$ñN �ÓØ×Ò˜Ôó0ó ó ð0ñf �ÓØ×Ò˜¨TÔ2ñTØEIôTó 3ó ðTñn �ÓØ×Ò˜¨TÔ2ó]ó 3ó ò]r'   