K idZddlZddlmZmZddlmZdgZedejddd id d d Z y)zRFunctions for generating stochastic graphs from a given weighted directed graph. N)DiGraph MultiDiGraph)not_implemented_forstochastic_graph undirectedweightznot copyT) edge_attrs mutates_input returns_graphc>|r&|jr t|n t|}t|j |}|j dD]/\}}}||dk(rd||<|j |d||z ||<1tj||S)aReturns 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. )rT)datarr ) is_multigraphrrdict out_degreeedgesgetnx _clear_cache)Gcopyrdegreeuvds d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/networkx/generators/stochastic.pyrr s:  0LOgaj!,,f,- .F777%51a !9>AfIfa(6!94AfI 5 OOA H)Tr) __doc__networkxrnetworkx.classesrrnetworkx.utilsr__all__ _dispatchablerrrr%sV 2.  \" Ad% #% r