
    hC                     f    S r SSKrSSKJr  SSKJr  S/r\R                  " SSS9SS	 j5       r
S
 rg)z Percolation centrality measures.    N)"_single_source_dijkstra_path_basic)"_single_source_shortest_path_basicpercolation_centrality	attributeweight)
node_attrs
edge_attrsc           
      \   [         R                  U S5      nU nUc  [        R                  " XQSS9nSnUR	                  5        H  nXg-  nM	     U H2  nUc  [        X5      u  ppO[        XU5      u  pp[        XIXXU5      nM4     [        U 5      nU H  nXG==   SUS-
  -  -  ss'   M     U$ )u	  Compute the percolation centrality for nodes.

Percolation centrality of a node $v$, at a given time, is defined
as the proportion of ‘percolated paths’ that go through that node.

This measure quantifies relative impact of nodes based on their
topological connectivity, as well as their percolation states.

Percolation states of nodes are used to depict network percolation
scenarios (such as during infection transmission in a social network
of individuals, spreading of computer viruses on computer networks, or
transmission of disease over a network of towns) over time. In this
measure usually the percolation state is expressed as a decimal
between 0.0 and 1.0.

When all nodes are in the same percolated state this measure is
equivalent to betweenness centrality.

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

attribute : None or string, optional (default='percolation')
  Name of the node attribute to use for percolation state, used
  if `states` is None. If a node does not set the attribute the
  state of that node will be set to the default value of 1.
  If all nodes do not have the attribute all nodes will be set to
  1 and the centrality measure will be equivalent to betweenness centrality.

states : None or dict, optional (default=None)
  Specify percolation states for the nodes, nodes as keys states
  as values.

weight : None or string, optional (default=None)
  If None, all edge weights are considered equal.
  Otherwise holds the name of the edge attribute used as weight.
  The weight of an edge is treated as the length or distance between the two sides.


Returns
-------
nodes : dictionary
   Dictionary of nodes with percolation centrality as the value.

See Also
--------
betweenness_centrality

Notes
-----
The algorithm is from Mahendra Piraveenan, Mikhail Prokopenko, and
Liaquat Hossain [1]_
Pair dependencies are calculated and accumulated using [2]_

For weighted graphs the edge weights must be greater than zero.
Zero edge weights can produce an infinite number of equal length
paths between pairs of nodes.

References
----------
.. [1] Mahendra Piraveenan, Mikhail Prokopenko, Liaquat Hossain
   Percolation Centrality: Quantifying Graph-Theoretic Impact of Nodes
   during Percolation in Networks
   http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0053095
.. [2] Ulrik Brandes:
   A Faster Algorithm for Betweenness Centrality.
   Journal of Mathematical Sociology 25(2):163-177, 2001.
   https://doi.org/10.1080/0022250X.2001.9990249
g           )default   )	dictfromkeysnxget_node_attributesvaluesshortest_pathdijkstra_accumulate_percolationlen)Gr   statesr   percolationnodesp_sigma_x_tvsSPsigma_ns                 \/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/centrality/percolation.pyr   r      s    P --3'KE~''!D K]]_  >*10NA%%aF3NA%-Aa
  	AA!q1u+%      c                    [         R                  US5      nU(       ac  UR                  5       nSXx   -   X8   -  n	X(    H  n
Xz==   X:   U	-  -  ss'   M     X:w  a  XT   XeU   -
  -  nX==   Xx   U-  -  ss'   U(       a  Mc  U $ )Nr   r   )r   r   pop)r   r   r   r    r   r   r   deltawcoeffr   pw_s_ws               r#   r   r   u   s    MM!QE
EEGUX)AH5((H 6Y+q	"9:FNeh//N ! r$   )r   NN)__doc__networkxr   *networkx.algorithms.centrality.betweennessr   r   r   r   __all___dispatchabler   r    r$   r#   <module>r1      sH    &  $
$ [X>c ?cLr$   