ó
ś£Õ\c           @   sU   d  Z  d d l Z d d l Z d j d d d g  Z d g Z d d e d  Z	 d S(	   s!   
Closeness centrality measures.

i’’’’Ns   
s   Aric Hagberg (hagberg@lanl.gov)s   Pieter Swart (swart@lanl.gov)s#   Sasha Gutfraind (ag362@cornell.edu)t   closeness_centralityc         C   s7  | d k	 r< | t k r! d } n  t j t j d | } n	 t j } | d k r` |  j   } n	 | g } i  } x© | D]” } | |  |  } t | j	    }	 |	 d k rt
 |   d k rt
 |  d |	 | | <| rt
 |  d t
 |   d }
 | | c |
 9<qqv d | | <qv W| d k	 r/| | S| Sd S(   s	  Compute closeness centrality for nodes.

    Closeness centrality at a node is 1/average distance to all other nodes.

    Parameters
    ----------
    G : graph
      A networkx graph 
    v : node, optional
      Return only the value for node v
    distance : string key, optional (default=None)
      Use specified edge key as edge distance. 
      If True, use 'weight' as the edge key.
    normalized : bool, optional      
      If True (default) normalize by the graph size.

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

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

    Notes
    -----
    The closeness centrality is normalized to to n-1 / size(G)-1 where
    n is the number of nodes in the connected part of graph containing
    the node.  If the graph is not completely connected, this
    algorithm computes the closeness centrality for each connected
    part separately.
    t   weightg        i   g      š?N(   t   Nonet   Truet	   functoolst   partialt   nxt"   single_source_dijkstra_path_lengtht"   single_source_shortest_path_lengtht   nodest   sumt   valuest   len(   t   Gt   vt   distancet
   normalizedt   path_lengthR	   R    t   nt   spt   totspt   s(    (    s`   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/centrality/closeness.pyR       s,    # 			(
   t   __doc__R   t   networkxR   t   joint
   __author__t   __all__R   R   R    (    (    (    s`   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/centrality/closeness.pyt   <module>   s   		