ó
|£*^c           @   s7   d  Z  d Z d Z d g Z d „  Z d d d „ Z d S(   s“   
===========================
Depth First Search on Edges
===========================

Algorithms for a depth-first traversal of edges in a graph.

t   forwardt   reverset   edge_dfsc            sÁ   ˆ  j  ƒ  o | d k ‰ ˆ  j  ƒ  o- | d k ‰ ˆ rH ‡  f d †  } n! ˆ r` ‡  f d †  } n	 ˆ  j } ˆ su ˆ r� d „  } n! ˆ  j  ƒ  r™ d „  } n	 d „  } ‡ ‡ f d †  } | | | f S(	   s“   
    These are various G-specific functions that help us implement the algorithm
    for all graph types: graph, multigraph, directed or not.

    t   ignoreR   c         ;   sV   x& ˆ  j  |  | � D] } | t f Vq Wx& ˆ  j |  | � D] } | t f Vq< Wd  S(   N(   t	   out_edgest   FORWARDt   in_edgest   REVERSE(   t   ut   kwdst   edge(   t   G(    sy   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/traversal/edgedfs.pyR      s    c         ;   s-   x& ˆ  j  |  | � D] } | t f Vq Wd  S(   N(   R   R   (   R   R	   R
   (   R   (    sy   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/traversal/edgedfs.pyR   !   s    c         S   s   |  d  S(   Niÿÿÿÿ(    (   R
   (    (    sy   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/traversal/edgedfs.pyt   key/   s    c         S   s   |  S(   N(    (   R
   (    (    sy   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/traversal/edgedfs.pyR   4   s    c         S   s   t  |  d  ƒ f |  d } | S(   Ni   (   t	   frozenset(   R
   t   new_edge(    (    sy   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/traversal/edgedfs.pyR   8   s    c            sS   ˆ  s ˆ r4 |  d t  k r4 |  d |  d } } n |  d |  d } } | | f S(   sÐ   
        Returns the tail and head of an edge, as it was traversed.

        So in general, this is different from the true tail and head.
        (Also, undirected edges have no true tail or head.)

        iÿÿÿÿi   i    (   R   (   R
   t   tailt   head(   t   ignore_orientationt   reverse_orientation(    sy   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/traversal/edgedfs.pyt   traversed_tailhead<   s    (   t   is_directedt
   edges_iter(   R   t   orientationR   R   R   (    (   R   R   R   sy   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/traversal/edgedfs.pyt   helper_funcs   s    		t   originalc         c   sT  t  |  j | ƒ ƒ } | s$ t ‚ n  i t d 6} |  j ƒ  rJ t | d <n  t |  | ƒ \ } } } t ƒ  } t ƒ  }	 i  }
 xÓ | D]Ë } | g } x¹ | rK| d } | |	 k rÒ | | | � |
 | <|	 j | ƒ n  y t	 |
 | ƒ } Wn t k
 r| j
 ƒ  q“ X| | ƒ } | | k r“ | j | ƒ | j | | ƒ d ƒ | Vq“ q“ Wq� Wd S(   sN  
    A directed, depth-first traversal of edges in ``G``, beginning at ``source``.

    Parameters
    ----------
    G : graph
        A directed/undirected graph/multigraph.

    source : node, list of nodes
        The node from which the traversal begins. If ``None``, then a source
        is chosen arbitrarily and repeatedly until all edges from each node in
        the graph are searched.

    orientation : 'original' | 'reverse' | 'ignore'
        For directed graphs and directed multigraphs, edge traversals need not
        respect the original orientation of the edges. When set to 'reverse',
        then every edge will be traversed in the reverse direction. When set to
        'ignore', then each directed edge is treated as a single undirected
        edge that can be traversed in either direction. For undirected graphs
        and undirected multigraphs, this parameter is meaningless and is not
        consulted by the algorithm.

    Yields
    ------
    edge : directed edge
        A directed edge indicating the path taken by the depth-first traversal.
        For graphs, ``edge`` is of the form ``(u, v)`` where ``u`` and ``v``
        are the tail and head of the edge as determined by the traversal. For
        multigraphs, ``edge`` is of the form ``(u, v, key)``, where `key` is
        the key of the edge. When the graph is directed, then ``u`` and ``v``
        are always in the order of the actual directed edge. If orientation is
        'reverse' or 'ignore', then ``edge`` takes the form
        ``(u, v, key, direction)`` where direction is a string, 'forward' or
        'reverse', that indicates if the edge was traversed in the forward
        (tail to head) or reverse (head to tail) direction, respectively.

    Examples
    --------
    >>> import networkx as nx
    >>> nodes = [0, 1, 2, 3]
    >>> edges = [(0, 1), (1, 0), (1, 0), (2, 1), (3, 1)]

    >>> list(nx.edge_dfs(nx.Graph(edges), nodes))
    [(0, 1), (1, 2), (1, 3)]

    >>> list(nx.edge_dfs(nx.DiGraph(edges), nodes))
    [(0, 1), (1, 0), (2, 1), (3, 1)]

    >>> list(nx.edge_dfs(nx.MultiGraph(edges), nodes))
    [(0, 1, 0), (1, 0, 1), (0, 1, 2), (1, 2, 0), (1, 3, 0)]

    >>> list(nx.edge_dfs(nx.MultiDiGraph(edges), nodes))
    [(0, 1, 0), (1, 0, 0), (1, 0, 1), (2, 1, 0), (3, 1, 0)]

    >>> list(nx.edge_dfs(nx.DiGraph(edges), nodes, orientation='ignore'))
    [(0, 1, 'forward'), (1, 0, 'forward'), (2, 1, 'reverse'), (3, 1, 'reverse')]

    >>> list(nx.edge_dfs(nx.MultiDiGraph(edges), nodes, orientation='ignore'))
    [(0, 1, 0, 'forward'), (1, 0, 0, 'forward'), (1, 0, 1, 'reverse'), (2, 1, 0, 'reverse'), (3, 1, 0, 'reverse')]

    Notes
    -----
    The goal of this function is to visit edges. It differs from the more
    familiar depth-first traversal of nodes, as provided by
    :func:`networkx.algorithms.traversal.depth_first_search.dfs_edges`, in
    that it does not stop once every node has been visited. In a directed graph
    with edges [(0, 1), (1, 2), (2, 1)], the edge (2, 1) would not be visited
    if not for the functionality provided by this function.

    See Also
    --------
    dfs_edges

    t   datat   keysiÿÿÿÿi   N(   t   listt   nbunch_itert   StopIterationt   Falset   is_multigrapht   TrueR   t   sett   addt   nextt   popt   append(   R   t   sourceR   t   nodesR	   R   R   t   tailheadt   visited_edgest   visited_nodest   edgest
   start_nodet   stackt   current_nodeR
   t   edge_key(    (    sy   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/traversal/edgedfs.pyR   L   s4    K					
N(   t   __doc__R   R   t   __all__R   t   NoneR   (    (    (    sy   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/traversal/edgedfs.pyt   <module>   s
   		=