
    h                     F    S r SSKrS/r\R                  " SS9SS j5       rg)z
Flow Hierarchy.
    Nflow_hierarchyweight)
edge_attrsc                 @  ^ ^ [         R                  " T 5      (       a  [         R                  " S5      eT R                  5       (       d  [         R                  " S5      e[         R                  " T 5      nS[        U U4S jU 5       5      T R                  T5      -  -
  $ )aq  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 : string, optional (default=None)
   Attribute to use for edge weights. If None the weight defaults to 1.

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

Raises
------
NetworkXError
   If `G` is not a directed graph or if `G` has no edges.

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
z-flow_hierarchy not applicable to empty graphsz%G must be a digraph in flow_hierarchy   c              3   d   >#    U  H%  nTR                  U5      R                  T5      v   M'     g 7fN)subgraphsize).0cGr   s     O/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/hierarchy.py	<genexpr>!flow_hierarchy.<locals>.<genexpr>9   s'     ;s!1::a=%%f--ss   -0)nxis_emptyNetworkXErroris_directedstrongly_connected_componentssumr   )r   r   sccs   `` r   r   r   
   su    T 
{{1~~NOO==??FGG

*
*1
-Cs;s;;affVnLLL    r	   )__doc__networkxr   __all___dispatchabler    r   r   <module>r      s8    
 X&.M '.Mr   