ó
|£*^c           @   sz   d  Z  d d l Z d d l m Z m Z d j d g ƒ Z d d d d	 g Z e	 d
 „ Z
 e	 d „ Z d „  Z d „  Z d S(   s„   
====================
Breadth-first search
====================

Basic algorithms for breadth-first searching the nodes of a graph.
iÿÿÿÿN(   t   defaultdictt   deques   
s%   Aric Hagberg <aric.hagberg@gmail.com>t	   bfs_edgest   bfs_treet   bfs_predecessorst   bfs_successorsc   	      c   sæ   | r$ t  |  t j ƒ r$ |  j } n	 |  j } t | g ƒ } t | | | ƒ f g ƒ } xˆ | rá | d \ } } yP t | ƒ } | | k r¿ | | f V| j | ƒ | j	 | | | ƒ f ƒ n  WqZ t
 k
 rÝ | j ƒ  qZ XqZ Wd S(   s¾  Produce edges in a breadth-first-search starting at source.

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

    source : node
       Specify starting node for breadth-first search and return edges in
       the component reachable from source.

    reverse : bool, optional
       If True traverse a directed graph in the reverse direction

    Returns
    -------
    edges: generator
       A generator of edges in the breadth-first-search.

    Examples
    --------
    >>> G = nx.Graph()
    >>> G.add_path([0,1,2])
    >>> print(list(nx.bfs_edges(G,0)))
    [(0, 1), (1, 2)]

    Notes
    -----
    Based on http://www.ics.uci.edu/~eppstein/PADS/BFS.py
    by D. Eppstein, July 2004.
    i    N(   t
   isinstancet   nxt   DiGrapht   predecessors_itert   neighbors_itert   setR   t   nextt   addt   appendt   StopIterationt   popleft(	   t   Gt   sourcet   reverset	   neighborst   visitedt   queuet   parentt   childrent   child(    (    s†   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/traversal/breadth_first_search.pyR      s    		 c         C   s9   t  j ƒ  } | j | ƒ | j t |  | d | ƒƒ | S(   s¿  Return an oriented tree constructed from of a breadth-first-search
    starting at source.

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

    source : node
       Specify starting node for breadth-first search and return edges in
       the component reachable from source.

    reverse : bool, optional
       If True traverse a directed graph in the reverse direction

    Returns
    -------
    T: NetworkX DiGraph
       An oriented tree

    Examples
    --------
    >>> G = nx.Graph()
    >>> G.add_path([0,1,2])
    >>> print(list(nx.bfs_edges(G,0)))
    [(0, 1), (1, 2)]

    Notes
    -----
    Based on http://www.ics.uci.edu/~eppstein/PADS/BFS.py
    by D. Eppstein, July 2004.
    R   (   R   R   t   add_nodet   add_edges_fromR   (   R   R   R   t   T(    (    s†   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/traversal/breadth_first_search.pyR   =   s     c         C   s   t  d „  t |  | ƒ Dƒ ƒ S(   so  Return dictionary of predecessors in breadth-first-search from source.

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

    source : node
       Specify starting node for breadth-first search and return edges in
       the component reachable from source.

    Returns
    -------
    pred: dict
       A dictionary with nodes as keys and predecessor nodes as values.

    Examples
    --------
    >>> G = nx.Graph()
    >>> G.add_path([0,1,2])
    >>> print(nx.bfs_predecessors(G,0))
    {1: 0, 2: 1}

    Notes
    -----
    Based on http://www.ics.uci.edu/~eppstein/PADS/BFS.py
    by D. Eppstein, July 2004.
    c         s   s!   |  ] \ } } | | f Vq d  S(   N(    (   t   .0t   st   t(    (    s†   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/traversal/breadth_first_search.pys	   <genexpr>~   s    (   t   dictR   (   R   R   (    (    s†   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/traversal/breadth_first_search.pyR   b   s    c         C   sG   t  t ƒ } x. t |  | ƒ D] \ } } | | j | ƒ q Wt | ƒ S(   su  Return dictionary of successors in breadth-first-search from source.

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

    source : node
       Specify starting node for breadth-first search and return edges in
       the component reachable from source.

    Returns
    -------
    succ: dict
       A dictionary with nodes as keys and list of succssors nodes as values.

    Examples
    --------
    >>> G = nx.Graph()
    >>> G.add_path([0,1,2])
    >>> print(nx.bfs_successors(G,0))
    {0: [1], 1: [2]}

    Notes
    -----
    Based on http://www.ics.uci.edu/~eppstein/PADS/BFS.py
    by D. Eppstein, July 2004.
    (   R    t   listR   R   R    (   R   R   t   dR   R   (    (    s†   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/traversal/breadth_first_search.pyR   €   s    (   t   __doc__t   networkxR   t   collectionsR    R   t   joint
   __author__t   __all__t   FalseR   R   R   R   (    (    (    s†   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/traversal/breadth_first_search.pyt   <module>   s   0%	