ó
ú£Õ\c           @   sV   d  Z  d Z d d g Z d d l Z d d l Te d e d d	 „ Z e Z	 d
 „  Z
 d S(   s.   
Current-flow closeness centrality measures.

s%   Aric Hagberg <aric.hagberg@gmail.com>t!   current_flow_closeness_centralityt   information_centralityiÿÿÿÿN(   t   *t   weightt   luc      
      sa  d d l  m } y d d l } Wn  t k
 rB t d d ƒ ‚ n Xy d d l } Wn  t k
 ru t d d ƒ ‚ n X|  j ƒ  r— t j d d ƒ ‚ n  |  j ƒ  rµ t j d	 ƒ ‚ n  t j |  ƒ sÖ t j d
 ƒ ‚ n  i t	 d 6t
 d 6t d 6} |  j ƒ  }	 t | |  ƒ ƒ ‰  t j |  t t ˆ  t |	 ƒ ƒ ƒ ƒ }
 t j |
 d ƒ } |  j ƒ  }	 t |
 d t |	 ƒ d | d | d d ƒ} | | | d d d | ƒ} xb |
 D]Z } | j | ƒ } xB |
 D]: } | | c | | d | | 7<| | c | | 7<q½Wq¡W| rt | ƒ d } n d } x  |
 D] } | | | | | <q%Wt ‡  f d †  | j ƒ  Dƒ ƒ S(   sS  Compute current-flow closeness centrality for nodes.

    A variant of closeness centrality based on effective
    resistance between nodes in a network.  This metric
    is also known as information centrality.

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

    normalized : bool, optional
      If True the values are normalized by 1/(n-1) where n is the 
      number of nodes in G.

    dtype: data type (float)
      Default data type for internal matrices.
      Set to np.float32 for lower memory consumption.

    solver: string (default='lu')
       Type of linear solver to use for computing the flow matrix.
       Options are "full" (uses most memory), "lu" (recommended), and 
       "cg" (uses least memory).

    Returns
    -------
    nodes : dictionary
       Dictionary of nodes with current flow closeness centrality as the value.
        
    See Also
    --------
    closeness_centrality

    Notes
    -----
    The algorithm is from Brandes [1]_.

    See also [2]_ for the original definition of information centrality.

    References
    ----------
    .. [1] Ulrik Brandes and Daniel Fleischer,
       Centrality Measures Based on Current Flow. 
       Proc. 22nd Symp. Theoretical Aspects of Computer Science (STACS '05). 
       LNCS 3404, pp. 533-544. Springer-Verlag, 2005. 
       http://www.inf.uni-konstanz.de/algo/publications/bf-cmbcf-05.pdf

    .. [2] Stephenson, K. and Zelen, M.
       Rethinking centrality: Methods and examples.
       Social Networks. Volume 11, Issue 1, March 1989, pp. 1-37
       http://dx.doi.org/10.1016/0378-8733(89)90016-6
    iÿÿÿÿ(   t   reverse_cuthill_mckee_orderingNs1   current_flow_closeness_centrality requires NumPy s   http://scipy.org/s1   current_flow_closeness_centrality requires SciPy s"   current_flow_closeness_centrality s   not defined for digraphs.s=   current_flow_closeness_centrality() not defined for digraphs.s   Graph not connected.t   fullR   t   cgg        t   nodelistR   t   dtypet   formatt   csct   widthi   i   g      ð?c         3   s+   |  ]! \ } } ˆ  | t  | ƒ f Vq d  S(   N(   t   float(   t   .0t   kt   v(   t   ordering(    sm   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/centrality/current_flow_closeness.pys	   <genexpr>u   s    (   t   networkx.utilsR   t   numpyt   ImportErrort   scipyt   is_directedt   nxt   NetworkXErrort   is_connectedt   FullInverseLaplaciant   SuperLUInverseLaplaciant   CGInverseLaplaciant   number_of_nodest   listt   relabel_nodest   dictt   zipt   ranget   fromkeyst   laplacian_sparse_matrixt   get_rowt   lent   items(   t   Gt
   normalizedR   R	   t   solverR   t   npR   t
   solvernamet   nt   Ht   betweennesst   Lt   C2R   t   colt   wt   nb(    (   R   sm   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/centrality/current_flow_closeness.pyR       sR    6	

' c         C   s:   d d l  m } y d d  l } Wn | d ƒ ‚ n Xd  S(   Niÿÿÿÿ(   t   SkipTests   NumPy not available(   t   noseR5   R   (   t   moduleR5   R   (    (    sm   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/centrality/current_flow_closeness.pyt   setup_modulez   s
    (   t   __doc__t
   __author__t   __all__t   networkxR   t*   networkx.algorithms.centrality.flow_matrixt   TrueR   R    R   R8   (    (    (    sm   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/centrality/current_flow_closeness.pyt   <module>   s   
c