
    wg                         d Z ddlZddlmZmZ ddlmZ dgZ ed       ej                  ddd	id
      dd              Z
y)zRFunctions for generating stochastic graphs from a given weighted directed
graph.

    N)DiGraphMultiDiGraph)not_implemented_forstochastic_graph
undirectedweightznot copy   T)
edge_attrsmutates_inputreturns_graphc                 >   |r&| j                         rt        |       n
t        |       } t        | j	                  |            }| j                  d      D ]/  \  }}}||   dk(  rd||<   |j                  |d      ||   z  ||<   1 t        j                  |        | S )a  Returns a right-stochastic representation of directed graph `G`.

    A right-stochastic graph is a weighted digraph in which for each
    node, the sum of the weights of all the out-edges of that node is
    1. If the graph is already weighted (for example, via a 'weight'
    edge attribute), the reweighting takes that into account.

    Parameters
    ----------
    G : directed graph
        A :class:`~networkx.DiGraph` or :class:`~networkx.MultiDiGraph`.

    copy : boolean, optional
        If this is True, then this function returns a new graph with
        the stochastic reweighting. Otherwise, the original graph is
        modified in-place (and also returned, for convenience).

    weight : edge attribute key (optional, default='weight')
        Edge attribute key used for reading the existing weight and
        setting the new weight.  If no attribute with this key is found
        for an edge, then the edge weight is assumed to be 1. If an edge
        has a weight, it must be a positive number.

    )r   T)datar   r	   )	is_multigraphr   r   dict
out_degreeedgesgetnx_clear_cache)Gcopyr   degreeuvds          c/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/networkx/generators/stochastic.pyr   r      s    :  0LOgaj !,,f,-.F777% 51a!9>AfIfa(6!94AfI	5
 OOAH    )Tr   )__doc__networkxr   networkx.classesr   r   networkx.utilsr   __all___dispatchabler    r   r   <module>r%      sV   
  2 .
 \"
Ad% #%r   