ó
ú£Õ\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(    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/euler.pyR       s    c         c   s'  t  |  ƒ s t j d ƒ ‚ n  |  j |  ƒ } | d k rN t | j ƒ  ƒ } n | } xÌ | j ƒ  d k r"| } t g  | j	 | ƒ D] \ } } | ^ q‚ ƒ } xN | D]F } | j
 | | ƒ t j | j ƒ  ƒ } | ré | j | | ƒ q¤ Pq¤ W| r| j
 | | ƒ | j | ƒ n  | | f VqW Wd S(   s9  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 : graph
       A NetworkX 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
    -----
    Uses Fleury's algorithm [1]_,[2]_  

    References
    ----------
    .. [1] Fleury, "Deux problemes de geometrie de situation", 
       Journal de mathematiques elementaires (1883), 257-261.
    .. [2] http://en.wikipedia.org/wiki/Eulerian_path

    Examples
    --------
    >>> G=nx.complete_graph(3)
    >>> list(nx.eulerian_circuit(G))
    [(0, 1), (1, 2), (2, 0)]
    >>> list(nx.eulerian_circuit(G,source=1)) 
    [(1, 0), (0, 2), (2, 1)]
    >>> [u for u,v in nx.eulerian_circuit(G)]  # nodes in circuit
    [0, 1, 2]
    s   G is not Eulerian.i    N(   R    R   t   NetworkXErrort	   __class__t   Nonet   nextR   t   sizet   sortedt   edgest   remove_edgeR
   t   to_undirectedt   add_edget   remove_node(   R   t   sourcet   gR   R   t   ut   nbrst   bridge(    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/euler.pyR   =   s&    /.(	   t   __doc__t   networkxR   t   joint
   __author__t   __all__R    R   R   (    (    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/euler.pyt   <module>   s   		+