ó
|£*^c           @   sL   d  Z  d d l Z d j d d g ƒ Z d g Z d d „ Z d d „ Z d S(	   s   
Vitality measures.
iÿÿÿÿNs   
s   Aric Hagberg (hagberg@lanl.gov)s   Renato Fabbrit   closeness_vitalityc         C   s‘   d } | d  k rN xx |  D]. } t j |  | ƒ } | t | j ƒ  ƒ 7} q Wn? x< |  D]4 } t j |  | d | ƒ} | t | j ƒ  ƒ 7} qU W| S(   Ng        t   weight(   t   Nonet   nxt"   single_source_shortest_path_lengtht   sumt   valuest"   single_source_dijkstra_path_length(   t   GR   t   weinert   nt   path_length(    (    sp   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/vitality.pyt   weiner_index   s    	c         C   sö   |  j  ƒ  } t |  | ƒ } i  } xÎ |  D]Æ } | r€ |  j | d t d t ƒ} |  j ƒ  r½ | |  j | d t d t ƒ7} q½ n= |  j | d t ƒ} |  j ƒ  r½ | |  j | d t ƒ7} n  |  j | ƒ | t |  | ƒ | | <|  j | ƒ q( W| S(   sE  Compute closeness vitality for nodes.

    Closeness vitality of a node is the change in the sum of distances
    between all node pairs when excluding that node.

    Parameters
    ----------
    G : graph

    weight : None or string (optional)
       The name of the edge attribute used as weight. If None the edge
       weights are ignored.

    Returns
    -------
    nodes : dictionary
       Dictionary with nodes as keys and closeness vitality as the value.

    Examples
    --------
    >>> G=nx.cycle_graph(3)
    >>> nx.closeness_vitality(G)
    {0: 4.0, 1: 4.0, 2: 4.0}

    See Also
    --------
    closeness_centrality()

    References
    ----------
    .. [1] Ulrik Brandes, Sec. 3.6.2 in
       Network Analysis: Methodological Foundations, Springer, 2005.
       http://books.google.com/books?id=TTNhSm7HYrIC
    t   datat   keys(   t   is_multigraphR   t   edgest   Truet   is_directedt   in_edgest   remove_edges_fromt   add_edges_from(   R   R   t
   multigrapht   wigR    R
   R   (    (    sp   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/vitality.pyR       s    #%(	   t   __doc__t   networkxR   t   joint
   __author__t   __all__R   R   R    (    (    (    sp   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/vitality.pyt   <module>   s   		