ó
ú£Õ\c           @   sŒ   d  Z  d d l Z d d l m Z d j d d d g ƒ Z d d	 d
 d g Z d „  Z e Z	 d „  Z
 e
 Z d „  Z e Z d d d „ Z d S(   s   
Graph isomorphism functions.
iÿÿÿÿN(   t   NetworkXErrors   
s   Aric Hagberg (hagberg@lanl.gov)s   Pieter Swart (swart@lanl.gov)s-   Christopher Ellison cellison@cse.ucdavis.edu)t   could_be_isomorphict   fast_could_be_isomorphict   faster_could_be_isomorphict   is_isomorphicc         C   sô   |  j  ƒ  | j  ƒ  k r t S|  j ƒ  } t j |  ƒ } t j |  ƒ } g  | D]! } | | | | | | g ^ qM } | j ƒ  | j ƒ  } t j | ƒ } t j | ƒ }	 g  | D]! } | | | | |	 | g ^ q¯ }
 |
 j ƒ  | |
 k rð t St S(   s.  Returns False if graphs are definitely not isomorphic.
    True does NOT guarantee isomorphism.

    Parameters
    ----------
    G1, G2 : graphs
       The two graphs G1 and G2 must be the same type.

    Notes
    -----
    Checks for matching degree, triangle, and number of cliques sequences.
    (   t   ordert   Falset   degreet   nxt	   trianglest   number_of_cliquest   sortt   True(   t   G1t   G2t   d1t   t1t   c1t   vt   props1t   d2t   t2t   c2t   props2(    (    s`   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/isomorphism/isomorph.pyR      s     .
.
c   	      C   sÈ   |  j  ƒ  | j  ƒ  k r t S|  j ƒ  } t j |  ƒ } g  | D] } | | | | g ^ q> } | j ƒ  | j ƒ  } t j | ƒ } g  | D] } | | | | g ^ qŠ } | j ƒ  | | k rÄ t St S(   s  Returns False if graphs are definitely not isomorphic.

    True does NOT guarantee isomorphism.

    Parameters
    ----------
    G1, G2 : graphs
       The two graphs G1 and G2 must be the same type.

    Notes
    -----
    Checks for matching degree and triangle sequences.
    (   R   R   R   R   R	   R   R   (	   R   R   R   R   R   R   R   R   R   (    (    s`   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/isomorphism/isomorph.pyR   :   s     '
'
 c         C   st   |  j  ƒ  | j  ƒ  k r t St |  j ƒ  j ƒ  ƒ } | j ƒ  t | j ƒ  j ƒ  ƒ } | j ƒ  | | k rp t St S(   s  Returns False if graphs are definitely not isomorphic.

    True does NOT guarantee isomorphism.

    Parameters
    ----------
    G1, G2 : graphs
       The two graphs G1 and G2 must be the same type.

    Notes
    -----
    Checks for matching degree sequences.
    (   R   R   t   listR   t   valuesR   R   (   R   R   R   R   (    (    s`   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/isomorphism/isomorph.pyR   ]   s     

 c         C   s‡   |  j  ƒ  r* | j  ƒ  r* t j j j } n8 |  j  ƒ  rV | j  ƒ  rV t j j j } n t d ƒ ‚ | |  | d | d | ƒ} | j ƒ  S(   sÓ  Returns True if the graphs G1 and G2 are isomorphic and False otherwise.

    Parameters
    ----------
    G1, G2: graphs
        The two graphs G1 and G2 must be the same type.

    node_match : callable
        A function that returns True if node n1 in G1 and n2 in G2 should
        be considered equal during the isomorphism test.
        If node_match is not specified then node attributes are not considered.

        The function will be called like

           node_match(G1.node[n1], G2.node[n2]).

        That is, the function will receive the node attribute dictionaries
        for n1 and n2 as inputs.

    edge_match : callable
        A function that returns True if the edge attribute dictionary
        for the pair of nodes (u1, v1) in G1 and (u2, v2) in G2 should
        be considered equal during the isomorphism test.  If edge_match is
        not specified then edge attributes are not considered.

        The function will be called like

           edge_match(G1[u1][v1], G2[u2][v2]).

        That is, the function will receive the edge attribute dictionaries
        of the edges under consideration.

    Notes
    -----
    Uses the vf2 algorithm [1]_.

    Examples
    --------
    >>> import networkx.algorithms.isomorphism as iso

    For digraphs G1 and G2, using 'weight' edge attribute (default: 1)

    >>> G1 = nx.DiGraph()
    >>> G2 = nx.DiGraph()
    >>> G1.add_path([1,2,3,4],weight=1)
    >>> G2.add_path([10,20,30,40],weight=2)
    >>> em = iso.numerical_edge_match('weight', 1)
    >>> nx.is_isomorphic(G1, G2)  # no weights considered
    True
    >>> nx.is_isomorphic(G1, G2, edge_match=em) # match weights
    False

    For multidigraphs G1 and G2, using 'fill' node attribute (default: '')

    >>> G1 = nx.MultiDiGraph()
    >>> G2 = nx.MultiDiGraph()
    >>> G1.add_nodes_from([1,2,3],fill='red')
    >>> G2.add_nodes_from([10,20,30,40],fill='red')
    >>> G1.add_path([1,2,3,4],weight=3, linewidth=2.5)
    >>> G2.add_path([10,20,30,40],weight=3)
    >>> nm = iso.categorical_node_match('fill', 'red')
    >>> nx.is_isomorphic(G1, G2, node_match=nm)
    True

    For multidigraphs G1 and G2, using 'weight' edge attribute (default: 7)

    >>> G1.add_edge(1,2, weight=7)
    >>> G2.add_edge(10,20)
    >>> em = iso.numerical_multiedge_match('weight', 7, rtol=1e-6)
    >>> nx.is_isomorphic(G1, G2, edge_match=em)
    True

    For multigraphs G1 and G2, using 'weight' and 'linewidth' edge attributes
    with default values 7 and 2.5. Also using 'fill' node attribute with
    default value 'red'.

    >>> em = iso.numerical_multiedge_match(['weight', 'linewidth'], [7, 2.5])
    >>> nm = iso.categorical_node_match('fill', 'red')
    >>> nx.is_isomorphic(G1, G2, edge_match=em, node_match=nm)
    True

    See Also
    --------
    numerical_node_match, numerical_edge_match, numerical_multiedge_match
    categorical_node_match, categorical_edge_match, categorical_multiedge_match

    References
    ----------
    .. [1]  L. P. Cordella, P. Foggia, C. Sansone, M. Vento,
       "An Improved Algorithm for Matching Large Graphs",
       3rd IAPR-TC15 Workshop  on Graph-based Representations in
       Pattern Recognition, Cuen, pp. 149-159, 2001.
       http://amalfi.dis.unina.it/graph/db/papers/vf-algorithm.pdf
    s*   Graphs G1 and G2 are not of the same type.t
   node_matcht
   edge_match(   t   is_directedR   t
   algorithmst   isomorphismt   DiGraphMatchert   GraphMatcherR    R   (   R   R   R   R   t   GMt   gm(    (    s`   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/isomorphism/isomorph.pyR   {   s    _(   t   __doc__t   networkxR   t   networkx.exceptionR    t   joint
   __author__t   __all__R   t   graph_could_be_isomorphicR   t   fast_graph_could_be_isomorphicR   t    faster_graph_could_be_isomorphict   NoneR   (    (    (    s`   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/isomorphism/isomorph.pyt   <module>   s    			$	!	