ķ
|Ŗ*^c           @   sĒ   d  Z  d d l Z d d l m Z d j d g  Z d d d d	 g Z e d
  d    Z e d
  d    Z	 e d
  e
 d   Z e d
  d    Z d   Z d S(   s   Weakly connected components.
i˙˙˙˙N(   t   not_implemented_fors   
s2   Aric Hagberg (hagberg@lanl.gov)Christopher Ellisont"   number_weakly_connected_componentst   weakly_connected_componentst$   weakly_connected_component_subgraphst   is_weakly_connectedt
   undirectedc         c   sT   t    } xD |  D]< } | | k r t  t |  |   } | V| j |  q q Wd S(   sm  Generate weakly connected components of G.

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

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

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

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

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

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

    See Also
    --------
    strongly_connected_components

    Notes
    -----
    For directed graphs only.

    N(   t   sett
   _plain_bfst   update(   t   Gt   seent   vt   c(    (    s   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/components/weakly_connected.pyR      s    '	c         C   s   t  t t |     S(   sJ  Return the number of weakly connected components in G.

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

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

    See Also
    --------
    connected_components

    Notes
    -----
    For directed graphs only.

    (   t   lent   listR   (   R	   (    (    s   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/components/weakly_connected.pyR   H   s    c         c   sF   x? t  |   D]1 } | r0 |  j |  j   Vq |  j |  Vq Wd S(   s"  Generate weakly connected components as subgraphs.

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

    copy: bool (default=True)
        If True make a copy of the graph attributes

    Returns
    -------
    comp : generator
        A generator of graphs, one for each weakly connected component of G.

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

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

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

    >>> Gc = max(nx.weakly_connected_component_subgraphs(G), key=len)

    See Also
    --------
    strongly_connected_components
    connected_components

    Notes
    -----
    For directed graphs only.
    Graph, node, and edge attributes are copied to the subgraphs by default.

    N(   R   t   subgrapht   copy(   R	   R   t   comp(    (    s   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/components/weakly_connected.pyR   b   s    +c         C   sJ   t  |   d k r$ t j d   n  t  t t |    d  t  |   k S(   s  Test directed graph for weak connectivity.

    A directed graph is weakly connected if, and only if, the graph
    is connected when the direction of the edge between nodes is ignored.

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

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

    See Also
    --------
    is_strongly_connected
    is_semiconnected
    is_connected

    Notes
    -----
    For directed graphs only.

    i    s-   Connectivity is undefined for the null graph.(   R   t   nxt   NetworkXPointlessConceptR   R   (   R	   (    (    s   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/components/weakly_connected.pyR      s    c         c   s   |  j  } |  j } t   } | h } xm | r | } t   } xQ | D]I } | | k rC | V| j |  | j | |  | j | |  qC qC Wq' Wd S(   sw   A fast BFS node generator

    The direction of the edge between nodes is ignored.

    For directed graphs only.

    N(   t   succt   predR   t   addR   (   R	   t   sourcet   Gsucct   GpredR
   t	   nextlevelt	   thislevelR   (    (    s   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/components/weakly_connected.pyR   ˇ   s    						(   t   __doc__t   networkxR   t   networkx.utils.decoratorsR    t   joint   __authors__t   __all__R   R   t   TrueR   R   R   (    (    (    s   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/components/weakly_connected.pyt   <module>   s   	/	1#