ó
 ,µ[c           @   sĄ   d  Z  d d l Z d d l Z d d l m Z d d l m Z d d d d	 d
 g Z	 e d  d    Z
 e d  e d   Z d   Z e d  d    Z e d  d    Z d   Z d S(   s   Connected components.i’’’’N(   t   not_implemented_fori   (   t   arbitrary_elementt   number_connected_componentst   connected_componentst   connected_component_subgraphst   is_connectedt   node_connected_componentt   directedc         c   sT   t    } xD |  D]< } | | k r t  t |  |   } | V| j |  q q Wd S(   sv  Generate connected components.

    Parameters
    ----------
    G : NetworkX graph
       An undirected graph

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

    Raises
    ------
    NetworkXNotImplemented:
        If G is directed.

    Examples
    --------
    Generate a sorted list of connected components, largest first.

    >>> G = nx.path_graph(4)
    >>> nx.add_path(G, [10, 11, 12])
    >>> [len(c) for c in sorted(nx.connected_components(G), key=len, reverse=True)]
    [4, 3]

    If you only want the largest connected component, it's more
    efficient to use max instead of sort.

    >>> largest_cc = max(nx.connected_components(G), key=len)

    See Also
    --------
    strongly_connected_components
    weakly_connected_components

    Notes
    -----
    For undirected graphs only.

    N(   t   sett
   _plain_bfst   update(   t   Gt   seent   vt   c(    (    sG   lib/python2.7/site-packages/networkx/algorithms/components/connected.pyR      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 connected_components(G))``

           Or ``(G.subgraph(c).copy() for c in connected_components(G))``
    s   connected_component_subgraphs is deprecated and will be removedin 2.2. Use (G.subgraph(c).copy() for c in connected_components(G))N(   t	   _warningst   warnt   DeprecationWarningR   t   subgrapht   copy(   R   R   t   msgR   (    (    sG   lib/python2.7/site-packages/networkx/algorithms/components/connected.pyR   N   s    c         C   s   t  d   t |   D  S(   s  Return the number of connected components.

    Parameters
    ----------
    G : NetworkX graph
       An undirected graph.

    Returns
    -------
    n : integer
       Number of connected components

    See Also
    --------
    connected_components
    number_weakly_connected_components
    number_strongly_connected_components

    Notes
    -----
    For undirected graphs only.

    c         s   s   |  ] } d  Vq d S(   i   N(    (   t   .0t   cc(    (    sG   lib/python2.7/site-packages/networkx/algorithms/components/connected.pys	   <genexpr>v   s    (   t   sumR   (   R   (    (    sG   lib/python2.7/site-packages/networkx/algorithms/components/connected.pyR   ^   s    c         C   sV   t  |   d k r' t j d d   n  t d   t |  t |    D  t  |   k S(   sg  Return True if the graph is connected, False otherwise.

    Parameters
    ----------
    G : NetworkX Graph
       An undirected graph.

    Returns
    -------
    connected : bool
      True if the graph is connected, false otherwise.

    Raises
    ------
    NetworkXNotImplemented:
        If G is directed.

    Examples
    --------
    >>> G = nx.path_graph(4)
    >>> print(nx.is_connected(G))
    True

    See Also
    --------
    is_strongly_connected
    is_weakly_connected
    is_semiconnected
    is_biconnected
    connected_components

    Notes
    -----
    For undirected graphs only.

    i    s   Connectivity is undefined s   for the null graph.c         s   s   |  ] } d  Vq d S(   i   N(    (   R   t   node(    (    sG   lib/python2.7/site-packages/networkx/algorithms/components/connected.pys	   <genexpr>¢   s    (   t   lent   nxt   NetworkXPointlessConceptR   R	   R   (   R   (    (    sG   lib/python2.7/site-packages/networkx/algorithms/components/connected.pyR   y   s    &	c         C   s   t  t |  |   S(   są  Return the set of nodes in the component of graph containing node n.

    Parameters
    ----------
    G : NetworkX Graph
       An undirected graph.

    n : node label
       A node in G

    Returns
    -------
    comp : set
       A set of nodes in the component of G containing node n.

    Raises
    ------
    NetworkXNotImplemented:
        If G is directed.

    See Also
    --------
    connected_components

    Notes
    -----
    For undirected graphs only.

    (   R   R	   (   R   t   n(    (    sG   lib/python2.7/site-packages/networkx/algorithms/components/connected.pyR   „   s    c         c   s~   |  j  } t   } | h } x\ | ry | } t   } x@ | D]8 } | | k r: | V| j |  | j | |  q: q: Wq Wd S(   s   A fast BFS node generatorN(   t   adjR   t   addR
   (   R   t   sourcet   G_adjR   t	   nextlevelt	   thislevelR   (    (    sG   lib/python2.7/site-packages/networkx/algorithms/components/connected.pyR	   Ē   s    					(   t   __doc__t   warningsR   t   networkxR   t   networkx.utils.decoratorsR    t   utilsR   t   __all__R   t   TrueR   R   R   R   R	   (    (    (    sG   lib/python2.7/site-packages/networkx/algorithms/components/connected.pyt   <module>   s    	3		,"