ó
 ,µ[c           @   s¤   d  Z  d d l m Z d d l m Z d d l Z d d l m Z d d l	 m
 Z
 d d	 d
 g Z e
 d  d    Z e
 d  d    Z e
 d  d    Z d S(   sD   Provides functions for computing the efficiency of nodes and graphs.i˙˙˙˙(   t   division(   t   permutationsN(   t   NetworkXNoPathi   (   t   not_implemented_fort
   efficiencyt   local_efficiencyt   global_efficiencyt   directedc         C   s;   y d t  j |  | |  } Wn t k
 r6 d } n X| S(   sı  Returns the efficiency of a pair of nodes in a graph.

    The *efficiency* of a pair of nodes is the multiplicative inverse of the
    shortest path distance between the nodes [1]_. Returns 0 if no path
    between nodes.

    Parameters
    ----------
    G : :class:`networkx.Graph`
        An undirected graph for which to compute the average local efficiency.
    u, v : node
        Nodes in the graph ``G``.

    Returns
    -------
    float
        Multiplicative inverse of the shortest path distance between the nodes.

    Notes
    -----
    Edge weights are ignored when computing the shortest path distances.

    See also
    --------
    local_efficiency
    global_efficiency

    References
    ----------
    .. [1] Latora, Vito, and Massimo Marchiori.
           "Efficient behavior of small-world networks."
           *Physical Review Letters* 87.19 (2001): 198701.
           <https://doi.org/10.1103/PhysRevLett.87.198701>

    i   i    (   t   nxt   shortest_path_lengthR   (   t   Gt   ut   vt   eff(    (    s=   lib/python2.7/site-packages/networkx/algorithms/efficiency.pyR      s
    %
c            s\   t     } | | d } | d k rR t   f d   t   d  D  | } n d } | S(   s  Returns the average global efficiency of the graph.

    The *efficiency* of a pair of nodes in a graph is the multiplicative
    inverse of the shortest path distance between the nodes. The *average
    global efficiency* of a graph is the average efficiency of all pairs of
    nodes [1]_.

    Parameters
    ----------
    G : :class:`networkx.Graph`
        An undirected graph for which to compute the average global efficiency.

    Returns
    -------
    float
        The average global efficiency of the graph.

    Notes
    -----
    Edge weights are ignored when computing the shortest path distances.

    See also
    --------
    local_efficiency

    References
    ----------
    .. [1] Latora, Vito, and Massimo Marchiori.
           "Efficient behavior of small-world networks."
           *Physical Review Letters* 87.19 (2001): 198701.
           <https://doi.org/10.1103/PhysRevLett.87.198701>

    i   i    c         3   s'   |  ] \ } } t    | |  Vq d  S(   N(   R   (   t   .0R   R   (   R
   (    s=   lib/python2.7/site-packages/networkx/algorithms/efficiency.pys	   <genexpr>g   s    i   (   t   lent   sumR   (   R
   t   nt   denomt   g_eff(    (   R
   s=   lib/python2.7/site-packages/networkx/algorithms/efficiency.pyR   A   s    #,c            s*     f d     D } t  |  t    S(   s  Returns the average local efficiency of the graph.

    The *efficiency* of a pair of nodes in a graph is the multiplicative
    inverse of the shortest path distance between the nodes. The *local
    efficiency* of a node in the graph is the average global efficiency of the
    subgraph induced by the neighbors of the node. The *average local
    efficiency* is the average of the local efficiencies of each node [1]_.

    Parameters
    ----------
    G : :class:`networkx.Graph`
        An undirected graph for which to compute the average local efficiency.

    Returns
    -------
    float
        The average local efficiency of the graph.

    Notes
    -----
    Edge weights are ignored when computing the shortest path distances.

    See also
    --------
    global_efficiency

    References
    ----------
    .. [1] Latora, Vito, and Massimo Marchiori.
           "Efficient behavior of small-world networks."
           *Physical Review Letters* 87.19 (2001): 198701.
           <https://doi.org/10.1103/PhysRevLett.87.198701>

    c         3   s(   |  ] } t    j   |   Vq d  S(   N(   R   t   subgraph(   R   R   (   R
   (    s=   lib/python2.7/site-packages/networkx/algorithms/efficiency.pys	   <genexpr>   s    (   R   R   (   R
   t   efficiency_list(    (   R
   s=   lib/python2.7/site-packages/networkx/algorithms/efficiency.pyR   q   s    %(   t   __doc__t
   __future__R    t	   itertoolsR   t   networkxR   t   networkx.exceptionR   t   utilsR   t   __all__R   R   R   (    (    (    s=   lib/python2.7/site-packages/networkx/algorithms/efficiency.pyt   <module>	   s   ,0