ó
 ,µ[c           @   s=   d  Z  d d l Z d j d g ƒ Z d g Z d d „ Z d S(   s   
Flow Hierarchy.
iÿÿÿÿNs   
s!   Ben Edwards (bedwards@cs.unm.edu)t   flow_hierarchyc            sa   ˆ  j  ƒ  s t j d ƒ ‚ n  t j ˆ  ƒ } d t ‡  ‡ f d †  | Dƒ ƒ t ˆ  j ˆ ƒ ƒ S(   s‚  Returns the flow hierarchy of a directed network.

    Flow hierarchy is defined as the fraction of edges not participating
    in cycles in a directed graph [1]_.

    Parameters
    ----------
    G : DiGraph or MultiDiGraph
       A directed graph

    weight : key,optional (default=None)
       Attribute to use for node weights. If None the weight defaults to 1.

    Returns
    -------
    h : float
       Flow hierarchy value

    Notes
    -----
    The algorithm described in [1]_ computes the flow hierarchy through
    exponentiation of the adjacency matrix.  This function implements an
    alternative approach that finds strongly connected components.
    An edge is in a cycle if and only if it is in a strongly connected
    component, which can be found in $O(m)$ time using Tarjan's algorithm.

    References
    ----------
    .. [1] Luo, J.; Magee, C.L. (2011),
       Detecting evolving patterns of self-organizing networks by flow
       hierarchy measurement, Complexity, Volume 16 Issue 6 53-61.
       DOI: 10.1002/cplx.20368
       http://web.mit.edu/~cmagee/www/documents/28-DetectingEvolvingPatterns_FlowHierarchy.pdf
    s%   G must be a digraph in flow_heirarchyg      ð?c         3   s'   |  ] } ˆ  j  | ƒ j ˆ ƒ Vq d  S(   N(   t   subgrapht   size(   t   .0t   c(   t   Gt   weight(    s<   lib/python2.7/site-packages/networkx/algorithms/hierarchy.pys	   <genexpr>6   s    (   t   is_directedt   nxt   NetworkXErrort   strongly_connected_componentst   sumt   floatR   (   R   R   t   scc(    (   R   R   s<   lib/python2.7/site-packages/networkx/algorithms/hierarchy.pyR       s    #(   t   __doc__t   networkxR   t   joint   __authors__t   __all__t   NoneR    (    (    (    s<   lib/python2.7/site-packages/networkx/algorithms/hierarchy.pyt   <module>   s   	