o
    ßË·eH  ã                   @   sh   d Z ddlmZ g d¢Zdd„ ZG dd„ dejƒZG dd	„ d	ejƒZG d
d„ deƒZG dd„ deƒZ	dS )a5  
    Module to simplify the specification of user-defined equality functions for
    node and edge attributes during isomorphism checks.

    During the construction of an isomorphism, the algorithm considers two
    candidate nodes n1 in G1 and n2 in G2.  The graphs G1 and G2 are then
    compared with respect to properties involving n1 and n2, and if the outcome
    is good, then the candidate nodes are considered isomorphic. NetworkX
    provides a simple mechanism for users to extend the comparisons to include
    node and edge attributes.

    Node attributes are handled by the node_match keyword. When considering
    n1 and n2, the algorithm passes their node attribute dictionaries to
    node_match, and if it returns False, then n1 and n2 cannot be
    considered to be isomorphic.

    Edge attributes are handled by the edge_match keyword. When considering
    n1 and n2, the algorithm must verify that outgoing edges from n1 are
    commensurate with the outgoing edges for n2. If the graph is directed,
    then a similar check is also performed for incoming edges.

    Focusing only on outgoing edges, we consider pairs of nodes (n1, v1) from
    G1 and (n2, v2) from G2. For graphs and digraphs, there is only one edge
    between (n1, v1) and only one edge between (n2, v2). Those edge attribute
    dictionaries are passed to edge_match, and if it returns False, then
    n1 and n2 cannot be considered isomorphic. For multigraphs and
    multidigraphs, there can be multiple edges between (n1, v1) and also
    multiple edges between (n2, v2).  Now, there must exist an isomorphism
    from "all the edges between (n1, v1)" to "all the edges between (n2, v2)".
    So, all of the edge attribute dictionaries are passed to edge_match, and
    it must determine if there is an isomorphism between the two sets of edges.
é   )Úisomorphvf2)ÚGraphMatcherÚDiGraphMatcherÚMultiGraphMatcherÚMultiDiGraphMatcherc           
      C   sÀ   | j dur|   | jj| | jj| ¡}|sdS | jdur^| j| }| j| }| j}| j}|D ]/}||krE||v rD||| || ƒsD dS q.||v r]|| }	|	|v r]||| ||	 ƒs] dS q.dS )úDReturns True if mapping G1_node to G2_node is semantically feasible.NFT)Ú
node_matchÚG1ÚnodesÚG2Ú
edge_matchÚG1_adjÚG2_adjÚcore_1)
ÚselfÚG1_nodeÚG2_nodeÚnmÚG1nbrsÚG2nbrsr   r   ÚneighborÚG2_nbr© r   úb/var/www/ideatree/venv/lib/python3.10/site-packages/networkx/algorithms/isomorphism/vf2userfunc.pyÚ_semantic_feasibility'   s0   




ÿ€
ÿ€r   c                   @   s   e Zd ZdZddd„ZeZdS )r   z.VF2 isomorphism checker for undirected graphs.Nc                 C   ó4   t j | ||¡ || _|| _| jj| _| jj| _	dS )a”  Initialize graph matcher.

        Parameters
        ----------
        G1, G2: graph
            The graphs to be tested.

        node_match: callable
            A function that returns True iff node n1 in G1 and n2 in G2
            should be considered equal during the isomorphism test. The
            function will be called like::

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

            That is, the function will receive the node attribute dictionaries
            of the nodes under consideration. If None, then no attributes are
            considered when testing for an isomorphism.

        edge_match: callable
            A function that returns True iff 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. 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. If None, then no attributes are
            considered when testing for an isomorphism.

        N)
Úvf2r   Ú__init__r   r   r	   Úadjr   r   r   ©r   r	   r   r   r   r   r   r   r   M   ó
    
zGraphMatcher.__init__©NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úsemantic_feasibilityr   r   r   r   r   J   s    
)r   c                   @   s"   e Zd ZdZddd„Zdd„ ZdS )r   z,VF2 isomorphism checker for directed graphs.Nc                 C   r   )a—  Initialize graph matcher.

        Parameters
        ----------
        G1, G2 : graph
            The graphs to be tested.

        node_match : callable
            A function that returns True iff node n1 in G1 and n2 in G2
            should be considered equal during the isomorphism test. The
            function will be called like::

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

            That is, the function will receive the node attribute dictionaries
            of the nodes under consideration. If None, then no attributes are
            considered when testing for an isomorphism.

        edge_match : callable
            A function that returns True iff 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. 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. If None, then no attributes are
            considered when testing for an isomorphism.

        N)
r   r   r   r   r   r	   r   r   r   r   r   r   r   r   r   |   r    zDiGraphMatcher.__init__c                 C   sL   t | ||ƒ}|s
dS | jj| _| jj| _t | ||ƒ}| jj| _| jj| _|S )r   F)r   r	   Úpredr   r   r   r   )r   r   r   Úfeasibler   r   r   r&   ¥   s   



z#DiGraphMatcher.semantic_feasibilityr!   )r"   r#   r$   r%   r   r&   r   r   r   r   r   y   s    
)r   c                   @   ó   e Zd ZdZdS )r   z3VF2 isomorphism checker for undirected multigraphs.N©r"   r#   r$   r%   r   r   r   r   r   ¼   ó    r   c                   @   r)   )r   z1VF2 isomorphism checker for directed multigraphs.Nr*   r   r   r   r   r   Â   r+   r   N)
r%   Ú r   r   Ú__all__r   r   r   r   r   r   r   r   r   Ú<module>   s    !#/C