
    wg                     <    d Z ddlZdgZej                  dd       Zy)z@Algorithm to select influential nodes in a graph using VoteRank.    Nvoterankc                    g }i t        |       dk(  r|S ||t        |       kD  rt        |       }| j                         r-t        d | j                         D              t        |       z  }n,t        d | j	                         D              t        |       z  }| j                         D ]	  }ddg|<    t        |      D ]	  }| j                         D ]
  }d|   d<    | j                         D ]B  \  }}|   dxx   |   d   z  cc<   | j                         r-|   dxx   |   d   z  cc<   D |D ]
  }d|   d<    t        | j
                  fd      }|   d   dk(  r|c S |j                  |       ddg|<   | j                  |      D ]0  \  }}|   dxx   d|z  z  cc<   t        |   d   d      |   d<   2  |S )a  Select a list of influential nodes in a graph using VoteRank algorithm

    VoteRank [1]_ computes a ranking of the nodes in a graph G based on a
    voting scheme. With VoteRank, all nodes vote for each of its in-neighbors
    and the node with the highest votes is elected iteratively. The voting
    ability of out-neighbors of elected nodes is decreased in subsequent turns.

    Parameters
    ----------
    G : graph
        A NetworkX graph.

    number_of_nodes : integer, optional
        Number of ranked nodes to extract (default all nodes).

    Returns
    -------
    voterank : list
        Ordered list of computed seeds.
        Only nodes with positive number of votes are returned.

    Examples
    --------
    >>> G = nx.Graph([(0, 1), (0, 2), (0, 3), (1, 4)])
    >>> nx.voterank(G)
    [0, 1]

    The algorithm can be used both for undirected and directed graphs.
    However, the directed version is different in two ways:
    (i) nodes only vote for their in-neighbors and
    (ii) only the voting ability of elected node and its out-neighbors are updated:

    >>> G = nx.DiGraph([(0, 1), (2, 1), (2, 3), (3, 4)])
    >>> nx.voterank(G)
    [2, 3]

    Notes
    -----
    Each edge is treated independently in case of multigraphs.

    References
    ----------
    .. [1] Zhang, J.-X. et al. (2016).
        Identifying a set of influential spreaders in complex networks.
        Sci. Rep. 6, 27823; doi: 10.1038/srep27823.
    r   c              3   &   K   | ]	  \  }}|  y wN .0_degs      p/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/networkx/algorithms/centrality/voterank_alg.py	<genexpr>zvoterank.<locals>.<genexpr>@   s     939   c              3   &   K   | ]	  \  }}|  y wr   r   r   s      r   r   zvoterank.<locals>.<genexpr>C   s     535r      c                     |    d   S )Nr   r   )x	vote_ranks    r   <lambda>zvoterank.<locals>.<lambda>U   s    y|A     )key)
lenis_directedsum
out_degreedegreenodesrangeedgesmaxappend)Gnumber_of_nodesinfluential_nodes	avgDegreenr
   nbrr   s          @r   r   r      s   ` I
1v{  /CF":a&}}9!,,.99CFB	 5!((*55A>	WWY 1v	! ?# : 	 AIaLO	  ggi 	5FAsaLOy~a00O==?#q!Yq\!_4!		5
 # 	 AIaLO	  67Q<?a$$  #1v	!ggaj 	:FAscN1Y. #IcN1$5q 9IcN1	:):. r   r   )__doc__networkxnx__all___dispatchabler   r   r   r   <module>r,      s.    F , V Vr   