ó
ú£Õ\c           @   s^   d  Z  d d l Z d j d g ƒ Z d d d d g Z d	 „  Z d
 „  Z d „  Z d „  Z	 d S(   s   
Attracting components.
iÿÿÿÿNs   
s   Christopher Ellisont   number_attracting_componentst   attracting_componentst   is_attracting_componentt   attracting_component_subgraphsc         C   sm   t  j |  ƒ } t  j |  | ƒ } g  | D]% } | j | ƒ d k r( | | ^ q( } | j d t d t ƒ | S(   sW  Returns a list of 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 : list
        The list of attracting components, sorted from largest attracting
        component to smallest attracting component.

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

    i    t   keyt   reverse(   t   nxt   strongly_connected_componentst   condensationt
   out_degreet   sortt   lent   True(   t   Gt   scct   cGt   nt
   attractors(    (    sa   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/attracting.pyR      s
    2c         C   s   t  t |  ƒ ƒ } | S(   sc  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.

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

    (   R   R   (   R   R   (    (    sa   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/attracting.pyR    7   s    c         C   s;   t  |  ƒ } t | d ƒ t |  ƒ k r1 t } n t } | 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.

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

    i    (   R   R   R   t   False(   R   t   act
   attracting(    (    sa   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/attracting.pyR   O   s
    	c         C   s2   g  t  |  ƒ D] } |  j | ƒ j ƒ  ^ q } | S(   sè  Returns a list of attracting component subgraphs from `G`.

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

    Returns
    -------
    subgraphs : list
        A list of node-induced subgraphs of the attracting components of `G`.
    
    Notes
    -----
    Graph, node, and edge attributes are copied to the subgraphs.

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

    (   R   t   subgrapht   copy(   R   R   t	   subgraphs(    (    sa   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/attracting.pyR   k   s    .(
   t   __doc__t   networkxR   t   joint   __authors__t   __all__R   R    R   R   (    (    (    sa   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/attracting.pyt   <module>   s   		$		