U
    9vfa
  ã                   @   sV   d Z ddlZddlmZ dddgZedƒdd„ ƒZedƒd	d„ ƒZedƒd
d„ ƒZdS )zAttracting components.é    N)Únot_implemented_forÚnumber_attracting_componentsÚattracting_componentsÚis_attracting_componentZ
undirectedc                 c   s@   t t | ¡ƒ}t | |¡}|D ]}| |¡dkr|| V  qdS )aá  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.

    To obtain induced subgraphs on each component use:
    ``(G.subgraph(c).copy() for c in attracting_components(G))``

    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

    r   N)ÚlistÚnxZstrongly_connected_componentsZcondensationZ
out_degree)ÚGZsccZcGÚn© r
   úM/tmp/pip-unpacked-wheel-_lngutwb/networkx/algorithms/components/attracting.pyr      s
    $c                 C   s   t dd„ t| ƒD ƒƒS )aœ  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 )é   Nr
   )Ú.0Úacr
   r
   r   Ú	<genexpr>P   s     z/number_attracting_components.<locals>.<genexpr>)Úsumr   )r   r
   r
   r   r   7   s    c                 C   s0   t t| ƒƒ}t|ƒdkr,t|d ƒt| ƒkS dS )aÍ  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

    r   r   F)r   r   Úlen)r   r   r
   r
   r   r   S   s    )	Ú__doc__Znetworkxr   Znetworkx.utils.decoratorsr   Ú__all__r   r   r   r
   r
   r
   r   Ú<module>   s   ý
*
