§
    bŠtj'  ã                   óÂ   — d Z ddlZddlmZ ddlmZ ddgZ edd	¦  «        ej        dd
„¦   «         ¦   «         Zd„ Z	 edd	¦  «        ej        d„ ¦   «         ¦   «         Z
dS )z8Algorithms to calculate reciprocity in a directed graph.é    N)ÚNetworkXErroré   )Únot_implemented_forÚreciprocityÚoverall_reciprocityÚ
undirectedÚ
multigraphc                 óÒ   — |€t          | ¦  «        S || v r6t          t          | |¦  «        ¦  «        d         }|€t          d¦  «        ‚|S t	          t          | |¦  «        ¦  «        S )af  Compute the reciprocity in a directed graph.

    The reciprocity of a directed graph is defined as the ratio
    of the number of edges pointing in both directions to the total
    number of edges in the graph.
    Formally, $r = |{(u,v) \in G|(v,u) \in G}| / |{(u,v) \in G}|$.

    The reciprocity of a single node u is defined similarly,
    it is the ratio of the number of edges in both directions to
    the total number of edges attached to node u.

    Parameters
    ----------
    G : graph
       A networkx directed graph
    nodes : container of nodes, optional (default=whole graph)
       Compute reciprocity for nodes in this container.

    Returns
    -------
    out : dictionary
       Reciprocity keyed by node label.

    Notes
    -----
    The reciprocity is not defined for isolated nodes.
    In such cases this function will return None.

    Né   zNot defined for isolated nodes.)r   ÚnextÚ_reciprocity_iterr   Údict)ÚGÚnodesr   s      ú]/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/networkx/algorithms/reciprocity.pyr   r      sv   € ðB €}Ý" 1Ñ%Ô%Ð%ð �€z€zÝÕ,¨Q°Ñ6Ô6Ñ7Ô7¸Ô:ˆØÐÝÐ AÑBÔBÐBàÐõ Õ! ! UÑ+Ô+Ñ,Ô,Ð,ó    c              #   ó^  K  — |                       |¦  «        }|D ]’}t          |                      |¦  «        ¦  «        }t          |                      |¦  «        ¦  «        }||z  }t	          |¦  «        t	          |¦  «        z   }|dk    r|dfV — Œwdt	          |¦  «        z  |z  }||fV — Œ“dS )z*Return an iterator of (node, reciprocity).r   Nr   )Únbunch_iterÚsetÚpredecessorsÚ
successorsÚlen)	r   r   ÚnÚnodeÚpredÚsuccÚoverlapÚn_totalr   s	            r   r   r   =   sÈ   è è € à	�Š�eÑÔ€AØð &ð &ˆÝ�1—>’> $Ñ'Ô'Ñ(Ô(ˆÝ�1—<’< Ñ%Ô%Ñ&Ô&ˆØ˜‘+ˆÝ�d‘)”)�c $™iœiÑ'ˆð �aŠ<ˆ<Ø˜�,ÐÐÐÐà�c '™lœlÑ*¨WÑ4ˆKØ˜Ð%Ð%Ð%Ð%Ð%ð&ð &r   c                 ó¶   — |                       ¦   «         }||                      ¦   «                               ¦   «         z
  dz  }|dk    rt          d¦  «        ‚||z  S )z«Compute the reciprocity for the whole graph.

    See the doc of reciprocity for the definition.

    Parameters
    ----------
    G : graph
       A networkx graph

    r   r   zNot defined for empty graphs)Únumber_of_edgesÚto_undirectedr   )r   Ú
n_all_edgeÚn_overlap_edges      r   r   r   O   s]   € ð ×"Ò"Ñ$Ô$€JØ  1§?¢?Ñ#4Ô#4×#DÒ#DÑ#FÔ#FÑFÈ!ÑK€Nà�Q‚€ÝÐ:Ñ;Ô;Ð;à˜JÑ&Ð&r   )N)Ú__doc__ÚnetworkxÚnxr   Úutilsr   Ú__all__Ú_dispatchabler   r   r   © r   r   ú<module>r+      sÓ   ðØ >Ð >à Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "à 'Ð 'Ð 'Ð 'Ð 'Ð 'àÐ/Ð
0€ð Ð�\ <Ñ0Ô0ØÔð--ð --ð --ñ Ôñ 1Ô0ð--ð`&ð &ð &ð$ Ð�\ <Ñ0Ô0ØÔð'ð 'ñ Ôñ 1Ô0ð'ð 'ð 'r   