ó
|£*^c           @   sY   d  Z  d d l m Z d d l Z d d l Z d j d g ƒ Z d g Z d d „ Z
 d S(   s   
Harmonic centrality measure.
iÿÿÿÿ(   t   divisionNs   
s6   Alessandro Luongo (alessandro.luongo@studenti.unimi.itt   harmonic_centralityc   	      C   sï   | d k	 r' t j t j d | ƒ} n	 t j } |  j ƒ  } i  } t |  ƒ d k rs x | D] } d | | <q[ W| S| |  j ƒ  rŽ |  j	 ƒ  n |  ƒ } xQ | D]I } t
 g  | | j ƒ  D]" } | d k rÔ d | n d ^ q¸ ƒ | | <qž W| S(   sõ  Compute harmonic centrality for nodes.

    Harmonic centrality [1]_ of a node `u` is the sum of the reciprocal
    of the shortest path distances from all other nodes to `u`

    .. math::

        C(u) = \sum_{v \neq u} \frac{1}{d(v, u)}

    where `d(v, u)` is the shortest-path distance between `v` and `u`.

    Notice that higher values indicate higher centrality.

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

    distance : edge attribute key, optional (default=None)
      Use the specified edge attribute as the edge distance in shortest
      path calculations.  If `None`, then each edge will have distance equal to 1.

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

    See Also
    --------
    betweenness_centrality, load_centrality, eigenvector_centrality,
    degree_centrality, closeness_centrality

    Notes
    -----
    If the 'distance' keyword is set to an edge attribute key then the
    shortest-path length will be computed using Dijkstra's algorithm with
    that edge attribute as the edge weight.

    References
    ----------
    .. [1] Boldi, Paolo, and Sebastiano Vigna. "Axioms for centrality." Internet Mathematics 10.3-4 (2014): 222-262.
    t   weighti   g        i    N(   t   Nonet	   functoolst   partialt   nxt   all_pairs_dijkstra_path_lengtht   all_pairs_shortest_path_lengtht   nodest   lent   is_directedt   reverset   sumt   values(	   t   Gt   distancet   path_lengthR	   R   t	   singletont   spt   nt   i(    (    s{   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/centrality/harmonic.pyR      s    ,	$G(   t   __doc__t
   __future__R    R   t   networkxR   t   joint
   __author__t   __all__R   R   (    (    (    s{   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/centrality/harmonic.pyt   <module>   s   	