
    wg/                     D    d dl mZ d dlZdgZej
                  dd       Zy)    )combinationsN
dispersionc                 v   fd}|g|3| D ci c]  }|i  }	}| D ]  }| |   D ]  } || ||      |	|   |<     |	S t         j                  | |   i       }	| |   D ]  } || ||      |	|<    |	S |2t         j                  | |   i       }	| |   D ]  } || ||      |	|<    |	S  || ||      }	|	S c c}w )a  Calculate dispersion between `u` and `v` in `G`.

    A link between two actors (`u` and `v`) has a high dispersion when their
    mutual ties (`s` and `t`) are not well connected with each other.

    Parameters
    ----------
    G : graph
        A NetworkX graph.
    u : node, optional
        The source for the dispersion score (e.g. ego node of the network).
    v : node, optional
        The target of the dispersion score if specified.
    normalized : bool
        If True (default) normalize by the embeddedness of the nodes (u and v).
    alpha, b, c : float
        Parameters for the normalization procedure. When `normalized` is True,
        the dispersion value is normalized by::

            result = ((dispersion + b) ** alpha) / (embeddedness + c)

        as long as the denominator is nonzero.

    Returns
    -------
    nodes : dictionary
        If u (v) is specified, returns a dictionary of nodes with dispersion
        score for all "target" ("source") nodes. If neither u nor v is
        specified, returns a dictionary of dictionaries for all nodes 'u' in the
        graph with a dispersion score for each node 'v'.

    Notes
    -----
    This implementation follows Lars Backstrom and Jon Kleinberg [1]_. Typical
    usage would be to run dispersion on the ego network $G_u$ if $u$ were
    specified.  Running :func:`dispersion` with neither $u$ nor $v$ specified
    can take some time to complete.

    References
    ----------
    .. [1] Romantic Partnerships and the Dispersion of Social Ties:
        A Network Analysis of Relationship Status on Facebook.
        Lars Backstrom, Jon Kleinberg.
        https://arxiv.org/pdf/1310.6753v1.pdf

    c                 N   t        | |         }| |   D ch c]	  }||v s| }}||h}t        |d      }d}|D ];  \  }	}
|j                  | |	         |z
  }|
|vs"|j                  | |
         s7|dz  }= t	        |      }|}r|z   z  }|z   dk7  r||z   z  }|S c c}w )z=dispersion for all nodes 'v' in a ego network G_u of node 'u'   r      )setr   intersection
isdisjointlen)G_uuvu_nbrsnSTset_uvpossibtotalstnbrs_sembeddednessdispersion_valalphabc
normalizeds                 n/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/networkx/algorithms/centrality/dispersion.py_dispersionzdispersion.<locals>._dispersion9   s    SVQ/A1;a//Qb!$ 	DAq((Q069F$$SV,QJE	 2w#aiE1Na1$,"22/ 0s
   	B"B")dictfromkeys)
Gr   r   r   r   r   r   r    r   resultss
      ````   r   r   r      s   b8 	y9&'(q"u(G( 91 9A$/1a$8GAJqM99$ N mmAaD"-GqT 2(Aq1
2 N 9mmAaD"-GqT 2(Aq1
2 N "!Q*GN' )s   
B6)NNTg      ?        r%   )	itertoolsr   networkxnx__all___dispatchabler        r   <module>r-      s.    " . b br,   