ó
    †~iÇ  ã                   óÜ   • S r SSKrSSKJr  SSKJr  SSKJr  S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g)zøFunctions for generating graphs based on the "duplication" method.

These graph generators start with a small initial graph then duplicate
nodes and (partially) duplicate their edges. These functions are
generally inspired by biological networks.

é    N)ÚNetworkXError)Úpy_random_state)Úcheck_create_usingÚpartial_duplication_graphÚduplication_divergence_graphé   T)ÚgraphsÚreturns_graph©Úcreate_usingc                ó
  • [        USSS9nUS:  d  US:”  d  US:  d  US:”  a  Sn[        U5      eX:”  a  [        S5      e[        R                  " X5      n[	        X5       H�  nUR                  SUS-
  5      n	UR                  U5        [        [        R                  " Xy5      5       H*  n
UR                  5       U:  d  M  UR                  XŠ5        M,     UR                  5       U:  d  MŒ  UR                  X‰5        MŸ     U$ )a!  Returns a random graph using the partial duplication model.

Parameters
----------
N : int
    The total number of nodes in the final graph.

n : int
    The number of nodes in the initial clique.

p : float
    The probability of joining each neighbor of a node to the
    duplicate node. Must be a number in the between zero and one,
    inclusive.

q : float
    The probability of joining the source node to the duplicate
    node. Must be a number in the between zero and one, inclusive.

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
-----
A graph of nodes is grown by creating a fully connected graph
of size `n`. The following procedure is then repeated until
a total of `N` nodes have been reached.

1. A random node, *u*, is picked and a new node, *v*, is created.
2. For each neighbor of *u* an edge from the neighbor to *v* is created
   with probability `p`.
3. An edge from *u* to *v* is created with probability `q`.

This algorithm appears in [1].

This implementation allows the possibility of generating
disconnected graphs.

References
----------
.. [1] Knudsen Michael, and Carsten Wiuf. "A Markov chain approach to
       randomly grown graphs." Journal of Applied Mathematics 2008.
       <https://doi.org/10.1155/2008/190836>

F©ÚdirectedÚ
multigraphr   é   z3partial duplication graph must have 0 <= p, q <= 1.z+partial duplication graph must have n <= N.)r   r   ÚnxÚcomplete_graphÚrangeÚrandintÚadd_nodeÚlistÚall_neighborsÚrandomÚadd_edge)ÚNÚnÚpÚqÚseedr   ÚmsgÚGÚnew_nodeÚsrc_nodeÚnbr_nodes              Ú\/home/mande/repo/quber/.venv/lib/python3.13/site-packages/networkx/generators/duplication.pyr   r      sæ   € ôj & l¸UÈuÑU€LØˆ1ƒu��A“˜˜Q› ! a£%ØCˆÜ˜CÓ Ð ØƒuÜÐIÓJÐJä
×Ò˜!Ó*€AÜ˜!–Kˆà—<‘<  8¨a¡<Ó0ˆð 	
�
‰
�8Ôô œR×-Ò-¨aÓ:Ö;ˆHà�{‰{‹}˜qÕ Ø—
‘
˜8Ö.ñ <ð �;‰;‹=˜1ÕØ�J‰J�xÖ*ñ  ð  €Hó    é   c                ó(  • US:”  d  US:  a  SU S3n[         R                  " U5      eU S:  a  Sn[         R                  " U5      e[        USSS9n[         R                  " US	9nUR	                  SS5        SnX`:  a“  UR                  [        U5      5      nUR                  U5        SnUR                  U5       H,  n	UR                  5       U:  d  M  UR	                  Xi5        S
nM.     U(       d  UR                  U5        OUS-  nX`:  a  M“  U$ )a€  Returns an undirected graph using the duplication-divergence model.

A graph of `n` nodes is created by duplicating the initial nodes
and retaining edges incident to the original nodes with a retention
probability `p`.

Parameters
----------
n : int
    The desired number of nodes in the graph.
p : float
    The probability for retaining the edge of the replicated node.
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 `p` is not a valid probability.
    If `n` is less than 2.

Notes
-----
This algorithm appears in [1].

This implementation disallows the possibility of generating
disconnected graphs.

References
----------
.. [1] I. Ispolatov, P. L. Krapivsky, A. Yuryev,
   "Duplication-divergence model of protein interaction network",
   Phys. Rev. E, 71, 061911, 2005.

r   r   zNetworkXError p=z is not in [0,1].r'   z$n must be greater than or equal to 2Fr   r   T)r   r   r   Úempty_graphr   Úchoicer   r   Ú	neighborsr   Úremove_node)
r   r   r   r   r    r!   ÚiÚrandom_nodeÚflagÚnbrs
             r%   r   r   a   s  € ð\ 	ˆ1ƒu��A“Ø   Ð#4Ð5ˆÜ×Ò˜sÓ#Ð#Øˆ1ƒuØ4ˆÜ×Ò˜sÓ#Ð#ä% l¸UÈuÑU€LÜ
�Š LÑ1€Að ‡J�Jˆq�!ÔØ	€AØ
‹%à—k‘k¤$ q£'Ó*ˆà	�
‰
�1ŒàˆØ—;‘;˜{Ö+ˆCØ�{‰{‹}˜qÕ à—
‘
˜1Ô"Ø’ñ	 ,ö
 à�M‰M˜!Õð �‰FˆAð# �%ð$ €Hr&   )N)Ú__doc__Únetworkxr   Únetworkx.exceptionr   Únetworkx.utilsr   Únetworkx.utils.miscr   Ú__all__Ú_dispatchabler   r   © r&   r%   Ú<module>r9      s”   ðñó Ý ,Ý *Ý 2à&Ð(FÐ
G€ñ �ÓØ×Ò˜¨TÑ2ðKÀTõ Kó 3ó ðKñ\ �ÓØ×Ò˜¨TÑ2ðKÀ$õ Kó 3ó ñKr&   