ó
ú£Õ\c           @   sj   d  Z  d j d g ƒ Z d d d d g Z d d l Z d	 „  Z d
 „  Z d „  Z d „  Z	 d d „ Z d S(   s   
Weakly connected components.
s   
s2   Aric Hagberg (hagberg@lanl.gov)Christopher Ellisont"   number_weakly_connected_componentst   weakly_connected_componentst$   weakly_connected_component_subgraphst   is_weakly_connectediÿÿÿÿNc         C   s™   |  j  ƒ  s t j d ƒ ‚ n  i  } g  } xR |  D]J } | | k r1 t |  | ƒ } | j t | j ƒ  ƒ ƒ | j | ƒ q1 q1 W| j d t	 d t
 ƒ | S(   s-   Return weakly connected components of G.
    sN   Not allowed for undirected graph G. 
              Use connected_components() t   keyt   reverse(   t   is_directedt   nxt   NetworkXErrort&   _single_source_shortest_unipath_lengtht   appendt   listt   keyst   updatet   sortt   lent   True(   t   Gt   seent
   componentst   vt   c(    (    sg   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/weakly_connected.pyR      s    c         C   s   t  t |  ƒ ƒ S(   sS   Return the number of connected components in G.
    For directed graphs only. 
    (   R   R   (   R   (    (    sg   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/weakly_connected.pyR    '   s    c         C   sC   t  |  ƒ } g  } x* | D]" } | j |  j | ƒ j ƒ  ƒ q W| S(   sx   Return weakly connected components as subgraphs.

    Graph, node, and edge attributes are copied to the subgraphs.
    (   R   R
   t   subgrapht   copy(   R   t   wcct
   graph_listR   (    (    sg   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/weakly_connected.pyR   -   s
     c         C   sb   |  j  ƒ  s t j d ƒ ‚ n  t |  ƒ d k rB t j d ƒ ‚ n  t t |  ƒ d ƒ t |  ƒ k S(   s[  Test directed graph for weak connectivity.

    Parameters
    ----------
    G : NetworkX Graph
       A directed graph.

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

    See Also
    --------
    strongly_connected_components

    Notes
    -----
    For directed graphs only. 
    s[   Not allowed for undirected graph G.
              See is_connected() for connectivity test.i    s-   Connectivity is undefined for the null graph.(   R   R   R   R   t   NetworkXPointlessConceptR   (   R   (    (    sg   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/weakly_connected.pyR   8   s    c   
      C   s¿   |  j  } |  j } i  } d } t | g ƒ } x‹ | rº | } t ƒ  } xI | D]A }	 |	 | k rL | | |	 <| j | |	 ƒ | j | |	 ƒ qL qL W| d k	 r­ | | k r­ Pn  | d } q0 W| S(   së  Compute the shortest path lengths from source to all reachable nodes.

    The direction of the edge between nodes is ignored.
    
    For directed graphs only.

    Parameters
    ----------
    G : NetworkX graph

    source : node
       Starting node for path

    cutoff : integer, optional
        Depth to stop the search. Only paths of length <= cutoff are returned.

    Returns
    -------
    lengths : dictionary
        Dictionary of shortest path lengths keyed by target.
    i    i   N(   t   succt   predt   setR   t   None(
   R   t   sourcet   cutofft   Gsucct   GpredR   t   levelt	   nextlevelt	   thislevelR   (    (    sg   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/weakly_connected.pyR	   W   s"    				
 (   t   __doc__t   joint   __authors__t   __all__t   networkxR   R   R    R   R   R   R	   (    (    (    sg   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/components/weakly_connected.pyt   <module>   s   						