ķ
 ,ĩ[c           @   s   d  Z  d d l Z d d l Z d d l m Z d d d d g Z e d  d	    Z e d  d
    Z	 e d  d    Z
 e d  e d   Z d S(   s   Attracting components.i˙˙˙˙N(   t   not_implemented_fort   number_attracting_componentst   attracting_componentst   is_attracting_componentt   attracting_component_subgraphst
   undirectedc         c   s]   t  t j |    } t j |  |  } x/ | D]' } | j |  d k r. | | Vq. q. Wd S(   sj  Generates the attracting components in `G`.

    An attracting component in a directed graph `G` is a strongly connected
    component with the property that a random walker on the graph will never
    leave the component, once it enters the component.

    The nodes in attracting components can also be thought of as recurrent
    nodes.  If a random walker enters the attractor containing the node, then
    the node will be visited infinitely often.

    Parameters
    ----------
    G : DiGraph, MultiDiGraph
        The graph to be analyzed.

    Returns
    -------
    attractors : generator of sets
        A generator of sets of nodes, one for each attracting component of G.

    Raises
    ------
    NetworkXNotImplemented :
        If the input graph is undirected.

    See Also
    --------
    number_attracting_components
    is_attracting_component

    i    N(   t   listt   nxt   strongly_connected_componentst   condensationt
   out_degree(   t   Gt   scct   cGt   n(    (    sH   lib/python2.7/site-packages/networkx/algorithms/components/attracting.pyR      s
    !c         C   s   t  d   t |   D  S(   s  Returns the number of attracting components in `G`.

    Parameters
    ----------
    G : DiGraph, MultiDiGraph
        The graph to be analyzed.

    Returns
    -------
    n : int
        The number of attracting components in G.

    Raises
    ------
    NetworkXNotImplemented :
        If the input graph is undirected.

    See Also
    --------
    attracting_components
    is_attracting_component

    c         s   s   |  ] } d  Vq d S(   i   N(    (   t   .0t   ac(    (    sH   lib/python2.7/site-packages/networkx/algorithms/components/attracting.pys	   <genexpr>W   s    (   t   sumR   (   R   (    (    sH   lib/python2.7/site-packages/networkx/algorithms/components/attracting.pyR   >   s    c         C   sB   t  t |    } t |  d k r> t | d  t |   k St S(   sĪ  Returns True if `G` consists of a single attracting component.

    Parameters
    ----------
    G : DiGraph, MultiDiGraph
        The graph to be analyzed.

    Returns
    -------
    attracting : bool
        True if `G` has a single attracting component. Otherwise, False.

    Raises
    ------
    NetworkXNotImplemented :
        If the input graph is undirected.

    See Also
    --------
    attracting_components
    number_attracting_components

    i   i    (   R   R   t   lent   False(   R   R   (    (    sH   lib/python2.7/site-packages/networkx/algorithms/components/attracting.pyR   Z   s    c         c   s\   d } t  j | t  x? t |   D]1 } | rF |  j |  j   Vq# |  j |  Vq# Wd S(   s   DEPRECATED: Use ``(G.subgraph(c) for c in attracting_components(G))``

           Or ``(G.subgraph(c).copy() for c in attracting_components(G))``
    s   attracting_component_subgraphs is deprecated and will be removedin 2.2. Use (G.subgraph(c).copy() for c in attracting_components(G))N(   t	   _warningst   warnt   DeprecationWarningR   t   subgrapht   copy(   R   R   t   msgt   c(    (    sH   lib/python2.7/site-packages/networkx/algorithms/components/attracting.pyR   y   s    (   t   __doc__t   warningsR   t   networkxR   t   networkx.utils.decoratorsR    t   __all__R   R   R   t   TrueR   (    (    (    sH   lib/python2.7/site-packages/networkx/algorithms/components/attracting.pyt   <module>
   s   	(	