Ë
    D^(h'  ã                   ó°   — 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
y)z8Algorithms to calculate reciprocity in a directed graph.é    N)ÚNetworkXErroré   )Únot_implemented_forÚreciprocityÚoverall_reciprocityÚ
undirectedÚ
multigraphc                 óœ   — |€t        | «      S || v r't        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.

    é   zNot defined for isolated nodes.)r   ÚnextÚ_reciprocity_iterr   Údict)ÚGÚnodesr   s      ú]/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/networkx/algorithms/reciprocity.pyr   r      sb   € ðB €}Ü" 1Ó%Ð%ð ��zÜÔ,¨Q°Ó6Ó7¸Ñ:ˆØÐÜÐ AÓBÐBàÐô Ô! ! UÓ+Ó,Ð,ó    c              #   ó"  K  — | j                  |«      }|D ]u  }t        | j                  |«      «      }t        | j                  |«      «      }||z  }t	        |«      t	        |«      z   }|dk(  r|df–— Œ_dt	        |«      z  |z  }||f–— Œw y­w)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Ñ'ˆð �aŠ<Ø˜�,Óàœc '›lÑ*¨WÑ4ˆKØ˜Ð%Ó%ñ&ùs   ‚BBc                 ó”   — | j                  «       }|| j                  «       j                  «       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   sO   € ð ×"Ñ"Ó$€JØ  1§?¡?Ó#4×#DÑ#DÓ#FÑFÈ!ÑK€Nà�Q‚ÜÐ:Ó;Ð;à˜JÑ&Ð&r   )N)Ú__doc__ÚnetworkxÚnxr   Úutilsr   Ú__all__Ú_dispatchabler   r   r   © r   r   ú<module>r+      st   ðÙ >ã Ý "å 'àÐ/Ð
0€ñ �\ <Ó0Ø×Ñò--ó ó 1ð--ò`&ñ$ �\ <Ó0Ø×Ññ'ó ó 1ñ'r   