ó
ú£Õ\c           @   sm   d  Z  d j d d g ƒ Z d d d d d g Z d	 d
 l Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d
 S(   s   
Connected components.
s   
s
   Eben Kenahs2   Aric Hagberg (hagberg@lanl.gov)Christopher Ellisont   number_connected_componentst   connected_componentst   connected_component_subgraphst   is_connectedt   node_connected_componentiÿÿÿÿNc         C   sœ   |  j  ƒ  r t j d ƒ ‚ n  i  } g  } xU |  D]M } | | k r1 t j |  | ƒ } | j t | j ƒ  ƒ ƒ | j | ƒ q1 q1 W| j d t	 d t
 ƒ | S(   s§  Return nodes in connected components of graph.

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

    Returns
    -------
    comp : list of lists
       A list of nodes for each component of G.

    See Also       
    --------
    strongly_connected_components

    Notes
    -----
    The list is ordered from largest connected component to smallest.
    For undirected graphs only. 
    sg   Not allowed for directed graph G.
              Use UG=G.to_undirected() to create an undirected graph.t   keyt   reverse(   t   is_directedt   nxt   NetworkXErrort"   single_source_shortest_path_lengtht   appendt   listt   keyst   updatet   sortt   lent   True(   t   Gt   seent
   componentst   vt   c(    (    s`   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/connected.pyR      s    c         C   s   t  t |  ƒ ƒ S(   sF  Return number of connected components in graph.

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

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

    See Also       
    --------
    connected_components

    Notes
    -----
    For undirected graphs only. 
    (   R   R   (   R   (    (    s`   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/connected.pyR    <   s    c         C   sp   |  j  ƒ  r t j d ƒ ‚ n  t |  ƒ d k rB t j d ƒ ‚ n  t t j |  t |  j ƒ  ƒ ƒ ƒ t |  ƒ k S(   sŸ  Test graph connectivity.

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

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

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

    See Also
    --------
    connected_components

    Notes
    -----
    For undirected graphs only. 
    sY   Not allowed for directed graph G.
Use UG=G.to_undirected() to create an undirected graph.i    s-   Connectivity is undefined for the null graph.(   R   R   R	   R   t   NetworkXPointlessConceptR
   t   nextt
   nodes_iter(   R   (    (    s`   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/connected.pyR   T   s    c         C   sC   t  |  ƒ } g  } x* | D]" } | j |  j | ƒ j ƒ  ƒ q W| S(   sŒ  Return connected components as subgraphs.

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

    Returns
    -------
    glist : list
      A list of graphs, one for each connected component of G.

    Examples
    --------
    Get largest connected component as subgraph

    >>> G=nx.path_graph(4)
    >>> G.add_edge(5,6)
    >>> H=nx.connected_component_subgraphs(G)[0]

    See Also
    --------
    connected_components

    Notes
    -----
    The list is ordered from largest connected component to smallest.
    For undirected graphs only. 

    Graph, node, and edge attributes are copied to the subgraphs.
    (   R   R   t   subgrapht   copy(   R   t   cct
   graph_listR   (    (    s`   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/connected.pyR   |   s
      c         C   s:   |  j  ƒ  r t j d ƒ ‚ n  t t j |  | ƒ j ƒ  ƒ S(   sœ  Return nodes in connected components of graph containing node n.

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

    n : node label       
       A node in G

    Returns
    -------
    comp : lists
       A list of nodes in component of G containing node n.

    See Also       
    --------
    connected_components

    Notes
    -----
    For undirected graphs only. 
    sg   Not allowed for directed graph G.
              Use UG=G.to_undirected() to create an undirected graph.(   R   R   R	   R   R
   R   (   R   t   n(    (    s`   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/connected.pyR   £   s    (   t   __doc__t   joint   __authors__t   __all__t   networkxR   R   R    R   R   R   (    (    (    s`   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/connected.pyt   <module>   s   				$		(	'