
    hW                     j    S r SSKrSSKJr  S/r\" S5      \R                  " SSS9S	S j5       5       rg)
z8Generate graphs with given degree and triangle sequence.    N)py_random_staterandom_clustered_graph   T)graphsreturns_graphc                 j   [        U 5      n [        U 5      n[        R                  " X1[        R                  S9nUR                  5       (       a  [        R                  " S5      e/ n/ nU HS  nX   n[        US   5       H  n	UR                  U5        M     [        US   5       H  n
UR                  U5        M     MU     [        U5      S-  S:w  d  [        U5      S-  S:w  a  [        R                  " S5      eUR                  U5        UR                  U5        U(       a7  UR                  UR                  5       UR                  5       5        U(       a  M7  U(       aP  UR                  5       nUR                  5       nUR                  5       nUR                  X4X4X4/5        U(       a  MP  U$ )a
  Generate a random graph with the given joint independent edge degree and
triangle degree sequence.

This uses a configuration model-like approach to generate a random graph
(with parallel edges and self-loops) by randomly assigning edges to match
the given joint degree sequence.

The joint degree sequence is a list of pairs of integers of the form
$[(d_{1,i}, d_{1,t}), \dotsc, (d_{n,i}, d_{n,t})]$. According to this list,
vertex $u$ is a member of $d_{u,t}$ triangles and has $d_{u, i}$ other
edges. The number $d_{u,t}$ is the *triangle degree* of $u$ and the number
$d_{u,i}$ is the *independent edge degree*.

Parameters
----------
joint_degree_sequence : list of integer pairs
    Each list entry corresponds to the independent edge degree and
    triangle degree of a node.
create_using : NetworkX graph constructor, optional (default MultiGraph)
   Graph type to create. If graph instance, then cleared before populated.
seed : integer, random_state, or None (default)
    Indicator of random number generation state.
    See :ref:`Randomness<randomness>`.

Returns
-------
G : MultiGraph
    A graph with the specified degree sequence. Nodes are labeled
    starting at 0 with an index corresponding to the position in
    deg_sequence.

Raises
------
NetworkXError
    If the independent edge degree sequence sum is not even
    or the triangle degree sequence sum is not divisible by 3.

Notes
-----
As described by Miller [1]_ (see also Newman [2]_ for an equivalent
description).

A non-graphical degree sequence (not realizable by some simple
graph) is allowed since this function returns graphs with self
loops and parallel edges.  An exception is raised if the
independent degree sequence does not have an even sum or the
triangle degree sequence sum is not divisible by 3.

This configuration model-like construction process can lead to
duplicate edges and loops.  You can remove the self-loops and
parallel edges (see below) which will likely result in a graph
that doesn't have the exact degree sequence specified.  This
"finite-size effect" decreases as the size of the graph increases.

References
----------
.. [1] Joel C. Miller. "Percolation and epidemics in random clustered
       networks". In: Physical review. E, Statistical, nonlinear, and soft
       matter physics 80 (2 Part 1 August 2009).
.. [2] M. E. J. Newman. "Random Graphs with Clustering".
       In: Physical Review Letters 103 (5 July 2009)

Examples
--------
>>> deg = [(1, 0), (1, 0), (1, 0), (2, 0), (1, 0), (2, 1), (0, 1), (0, 1)]
>>> G = nx.random_clustered_graph(deg)

To remove parallel edges:

>>> G = nx.Graph(G)

To remove self loops:

>>> G.remove_edges_from(nx.selfloop_edges(G))

)defaultzDirected Graph not supportedr      r      zInvalid degree sequence)listlennxempty_graph
MultiGraphis_directedNetworkXErrorrangeappendshuffleadd_edgepopadd_edges_from)joint_degree_sequencecreate_usingseedNGilisttlistndegreesicounttcountn1n2n3s                 V/var/www/html/env/lib/python3.13/site-packages/networkx/generators/random_clustered.pyr   r   	   sa   ` !!67!"A
q>A}}=>>EE'*GAJ'FLLO (GAJ'FLLO (	  5zA~c%j1n1899LLLL
	

599;		, %
YY[YY[YY[	2(RHrh78	 %
 H    )NN)__doc__networkxr   networkx.utilsr   __all___dispatchabler    r(   r'   <module>r/      sF    >  *#
$ T2j 3 jr(   