ó
|£*^c           @   sL   d  Z  d d l Z d j d d g ƒ Z d d g Z d „  Z d d	 „ Z d S(
   s   
Eulerian circuits and graphs.
iÿÿÿÿNs   
s&   Nima Mohammadi (nima.irt[AT]gmail.com)s   Aric Hagberg <hagberg@lanl.gov>t   is_euleriant   eulerian_circuitc         C   s£   |  j  ƒ  r[ x6 |  j ƒ  D]( } |  j | ƒ |  j | ƒ k r t Sq Wt j |  ƒ sŸ t SnD x. |  j ƒ  D]  \ } } | d d k rh t Sqh Wt j |  ƒ sŸ t St	 S(   s  Return True if G is an Eulerian graph, False otherwise.

    An Eulerian graph is a graph with an Eulerian circuit.

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

    Examples
    --------
    >>> nx.is_eulerian(nx.DiGraph({0:[3], 1:[2], 2:[3], 3:[0, 1]}))
    True
    >>> nx.is_eulerian(nx.complete_graph(5))
    True
    >>> nx.is_eulerian(nx.petersen_graph())
    False

    Notes
    -----
    This implementation requires the graph to be connected
    (or strongly connected for directed graphs).
    i   i    (
   t   is_directedt
   nodes_itert	   in_degreet
   out_degreet   Falset   nxt   is_strongly_connectedt   degree_itert   is_connectedt   True(   t   Gt   nt   vt   d(    (    sm   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/euler.pyR       s    c         c   sJ  d d l  m } t |  ƒ s. t j d ƒ ‚ n  |  j |  ƒ } | d k r^ t | j ƒ  ƒ } n | } | j	 ƒ  r‘ | j
 } | j } | d ƒ } n | j } | j } | d ƒ } | g } d }	 x… | rE| d }
 | |
 ƒ d k r|	 d k	 rý |	 |
 f Vn  |
 }	 | j ƒ  qÁ t | |
 ƒ ƒ } | j | | ƒ ƒ | j | Œ  qÁ Wd S(   s³  Return the edges of an Eulerian circuit in G.

    An Eulerian circuit is a path that crosses every edge in G exactly once
    and finishes at the starting node.

    Parameters
    ----------
    G : NetworkX Graph or DiGraph
        A directed or undirected graph
    source : node, optional
       Starting node for circuit.

    Returns
    -------
    edges : generator
       A generator that produces edges in the Eulerian circuit.

    Raises
    ------
    NetworkXError
       If the graph is not Eulerian.

    See Also
    --------
    is_eulerian

    Notes
    -----
    Linear time algorithm, adapted from [1]_.
    General information about Euler tours [2]_.

    References
    ----------
    .. [1] J. Edmonds, E. L. Johnson.
       Matching, Euler tours and the Chinese postman.
       Mathematical programming, Volume 5, Issue 1 (1973), 111-114.
    .. [2] http://en.wikipedia.org/wiki/Eulerian_path

    Examples
    --------
    >>> G=nx.complete_graph(3)
    >>> list(nx.eulerian_circuit(G))
    [(0, 2), (2, 1), (1, 0)]
    >>> list(nx.eulerian_circuit(G,source=1))
    [(1, 2), (2, 0), (0, 1)]
    >>> [u for u,v in nx.eulerian_circuit(G)]  # nodes in circuit
    [0, 2, 1]
    iÿÿÿÿ(   t
   itemgetters   G is not Eulerian.i    i   N(   t   operatorR   R    R   t   NetworkXErrort	   __class__t   Nonet   nextR   R   R   t   in_edges_itert   degreet
   edges_itert   popt   appendt   remove_edge(   R   t   sourceR   t   gR   R   t   edgest
   get_vertext   vertex_stackt   last_vertext   current_vertext   random_edge(    (    sm   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/euler.pyR   =   s4    1						
(	   t   __doc__t   networkxR   t   joint
   __author__t   __all__R    R   R   (    (    (    sm   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/euler.pyt   <module>   s   		+