§
    bŠtj³(  ã                   óª  — d Z ddlmZ ddlZg d¢Z ej        d¬¦  «        dd„¦   «         Z ej        d¬¦  «        dd„¦   «         Z ej        d¬¦  «        dd	„¦   «         Z	 ej        d¬¦  «        dd
„¦   «         Z
 ej        d¬¦  «        dd„¦   «         Z ej        d¬¦  «        dd„¦   «         Zej        d„ ¦   «         Zej        d„ ¦   «         ZdS )z5Functions for finding and evaluating cuts in a graph.é    )ÚchainN)Úboundary_expansionÚconductanceÚcut_sizeÚedge_expansionÚmixing_expansionÚnode_expansionÚnormalized_cut_sizeÚvolumeÚweight)Ú
edge_attrsc           
      óÜ   — t          j        | |||d¬¦  «        }|                      ¦   «         r't          |t          j        | |||d¬¦  «        ¦  «        }t	          d„ |D ¦   «         ¦  «        S )a‡  Returns the size of the cut between two sets of nodes.

    A *cut* is a partition of the nodes of a graph into two sets. The
    *cut size* is the sum of the weights of the edges "between" the two
    sets of nodes.

    Parameters
    ----------
    G : NetworkX graph

    S : collection
        A collection of nodes in `G`.

    T : collection
        A collection of nodes in `G`. If not specified, this is taken to
        be the set complement of `S`.

    weight : object
        Edge attribute key to use as weight. If not specified, edges
        have weight one.

    Returns
    -------
    number
        Total weight of all edges from nodes in set `S` to nodes in
        set `T` (and, in the case of directed graphs, all edges from
        nodes in `T` to nodes in `S`).

    Examples
    --------
    In the graph with two cliques joined by a single edges, the natural
    bipartition of the graph into two blocks, one for each clique,
    yields a cut of weight one:

    >>> G = nx.barbell_graph(3, 0)
    >>> S = {0, 1, 2}
    >>> T = {3, 4, 5}
    >>> nx.cut_size(G, S, T)
    1

    Each parallel edge in a multigraph is counted when determining the
    cut size:

    >>> G = nx.MultiGraph(["ab", "ab"])
    >>> S = {"a"}
    >>> T = {"b"}
    >>> nx.cut_size(G, S, T)
    2

    Notes
    -----
    In a multigraph, the cut size is the total weight of edges including
    multiplicity.

    é   )ÚdataÚdefaultc              3   ó"   K  — | ]
\  }}}|V — Œd S ©N© )Ú.0ÚuÚvr   s       úV/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/networkx/algorithms/cuts.pyú	<genexpr>zcut_size.<locals>.<genexpr>R   s(   è è € Ð0Ð0™,˜!˜Q ˆvÐ0Ð0Ð0Ð0Ð0Ð0ó    )ÚnxÚedge_boundaryÚis_directedr   Úsum)ÚGÚSÚTr   Úedgess        r   r   r      ss   € õr Ô˜Q  1¨6¸1Ð=Ñ=Ô=€EØ‡}‚}�„ð PÝ�e�RÔ-¨a°°A¸FÈAÐNÑNÔNÑOÔOˆÝÐ0Ð0¨%Ð0Ñ0Ô0Ñ0Ô0Ð0r   c                 óŽ   — |                       ¦   «         r| j        n| j        }t          d„  |||¬¦  «        D ¦   «         ¦  «        S )a|  Returns the volume of a set of nodes.

    The *volume* of a set *S* is the sum of the (out-)degrees of nodes
    in *S* (taking into account parallel edges in multigraphs). [1]

    Parameters
    ----------
    G : NetworkX graph

    S : collection
        A collection of nodes in `G`.

    weight : object
        Edge attribute key to use as weight. If not specified, edges
        have weight one.

    Returns
    -------
    number
        The volume of the set of nodes represented by `S` in the graph
        `G`.

    See also
    --------
    conductance
    cut_size
    edge_expansion
    edge_boundary
    normalized_cut_size

    References
    ----------
    .. [1] David Gleich.
           *Hierarchical Directed Spectral Graph Partitioning*.
           <https://www.cs.purdue.edu/homes/dgleich/publications/Gleich%202005%20-%20hierarchical%20directed%20spectral.pdf>

    c              3   ó    K  — | ]	\  }}|V — Œ
d S r   r   )r   r   Úds      r   r   zvolume.<locals>.<genexpr>}   s&   è è € Ð6Ð6‘T�Q˜ˆqÐ6Ð6Ð6Ð6Ð6Ð6r   ©r   )r   Ú
out_degreeÚdegreer   )r   r    r   r(   s       r   r   r   U   sK   € ðN Ÿ]š]™_œ_Ð:ˆQŒ\ˆ\°!´(€FÝÐ6Ð6˜V˜V A¨fÐ5Ñ5Ô5Ð6Ñ6Ô6Ñ6Ô6Ð6r   c                 óÎ   — |€t          | ¦  «        t          |¦  «        z
  }t          | |||¬¦  «        }t          | ||¬¦  «        }t          | ||¬¦  «        }|d|z  d|z  z   z  S )a  Returns the normalized size of the cut between two sets of nodes.

    The *normalized cut size* is the cut size times the sum of the
    reciprocal sizes of the volumes of the two sets. [1]

    Parameters
    ----------
    G : NetworkX graph

    S : collection
        A collection of nodes in `G`.

    T : collection
        A collection of nodes in `G`.

    weight : object
        Edge attribute key to use as weight. If not specified, edges
        have weight one.

    Returns
    -------
    number
        The normalized cut size between the two sets `S` and `T`.

    Notes
    -----
    In a multigraph, the cut size is the total weight of edges including
    multiplicity.

    See also
    --------
    conductance
    cut_size
    edge_expansion
    volume

    References
    ----------
    .. [1] David Gleich.
           *Hierarchical Directed Spectral Graph Partitioning*.
           <https://www.cs.purdue.edu/homes/dgleich/publications/Gleich%202005%20-%20hierarchical%20directed%20spectral.pdf>

    N©r!   r   r&   r   )Úsetr   r   ©r   r    r!   r   Únum_cut_edgesÚvolume_SÚvolume_Ts          r   r
   r
   €   su   € ðZ 	€yÝ�‰FŒF•S˜‘V”V‰OˆÝ˜Q  Q¨vÐ6Ñ6Ô6€MÝ�a˜ 6Ð*Ñ*Ô*€HÝ�a˜ 6Ð*Ñ*Ô*€HØ˜Q ™\¨a°(©lÑ;Ñ<Ð<r   c                 óØ   — |€t          | ¦  «        t          |¦  «        z
  }t          | |||¬¦  «        }t          | ||¬¦  «        }t          | ||¬¦  «        }|t          ||¦  «        z  S )ap  Returns the conductance of two sets of nodes.

    The *conductance* is the quotient of the cut size and the smaller of
    the volumes of the two sets. [1]

    Parameters
    ----------
    G : NetworkX graph

    S : collection
        A collection of nodes in `G`.

    T : collection
        A collection of nodes in `G`.

    weight : object
        Edge attribute key to use as weight. If not specified, edges
        have weight one.

    Returns
    -------
    number
        The conductance between the two sets `S` and `T`.

    See also
    --------
    cut_size
    edge_expansion
    normalized_cut_size
    volume

    References
    ----------
    .. [1] David Gleich.
           *Hierarchical Directed Spectral Graph Partitioning*.
           <https://www.cs.purdue.edu/homes/dgleich/publications/Gleich%202005%20-%20hierarchical%20directed%20spectral.pdf>

    Nr&   )r+   r   r   Úminr,   s          r   r   r   µ   sr   € ðP 	€yÝ�‰FŒF•S˜‘V”V‰OˆÝ˜Q  1¨VÐ4Ñ4Ô4€MÝ�a˜ 6Ð*Ñ*Ô*€HÝ�a˜ 6Ð*Ñ*Ô*€HØ�3˜x¨Ñ2Ô2Ñ2Ð2r   c                 óÄ   — |€t          | ¦  «        t          |¦  «        z
  }t          | |||¬¦  «        }|t          t          |¦  «        t          |¦  «        ¦  «        z  S )a©  Returns the edge expansion between two node sets.

    The *edge expansion* is the quotient of the cut size and the smaller
    of the cardinalities of the two sets. [1]

    Parameters
    ----------
    G : NetworkX graph

    S : collection
        A collection of nodes in `G`.

    T : collection
        A collection of nodes in `G`.

    weight : object
        Edge attribute key to use as weight. If not specified, edges
        have weight one.

    Returns
    -------
    number
        The edge expansion between the two sets `S` and `T`.

    See also
    --------
    boundary_expansion
    mixing_expansion
    node_expansion

    References
    ----------
    .. [1] Fan Chung.
           *Spectral Graph Theory*.
           (CBMS Regional Conference Series in Mathematics, No. 92),
           American Mathematical Society, 1997, ISBN 0-8218-0315-8
           <http://www.math.ucsd.edu/~fan/research/revised.html>

    Nr*   )r+   r   r1   Úlen)r   r    r!   r   r-   s        r   r   r   å   sV   € ðR 	€yÝ�‰FŒF•S˜‘V”V‰OˆÝ˜Q  Q¨vÐ6Ñ6Ô6€MØ�3�s 1™vœv¥s¨1¡v¤vÑ.Ô.Ñ.Ð.r   c                 ó`   — t          | |||¬¦  «        }|                      ¦   «         }|d|z  z  S )us  Returns the mixing expansion between two node sets.

    The *mixing expansion* is the quotient of the cut size and twice the
    number of edges in the graph. [1]

    Parameters
    ----------
    G : NetworkX graph

    S : collection
        A collection of nodes in `G`.

    T : collection
        A collection of nodes in `G`.

    weight : object
        Edge attribute key to use as weight. If not specified, edges
        have weight one.

    Returns
    -------
    number
        The mixing expansion between the two sets `S` and `T`.

    See also
    --------
    boundary_expansion
    edge_expansion
    node_expansion

    References
    ----------
    .. [1] Vadhan, Salil P.
           "Pseudorandomness."
           *Foundations and Trends
           in Theoretical Computer Science* 7.1â€“3 (2011): 1â€“336.
           <https://doi.org/10.1561/0400000010>

    r*   é   )r   Únumber_of_edges)r   r    r!   r   r-   Únum_total_edgess         r   r   r     s<   € õR ˜Q  Q¨vÐ6Ñ6Ô6€MØ×'Ò'Ñ)Ô)€OØ˜A Ñ/Ñ0Ð0r   c                 óœ   ‡ — t          t          j        ˆ fd„|D ¦   «         ¦  «        ¦  «        }t          |¦  «        t          |¦  «        z  S )u±  Returns the node expansion of the set `S`.

    The *node expansion* is the quotient of the size of the node
    boundary of *S* and the cardinality of *S*. [1]

    Parameters
    ----------
    G : NetworkX graph

    S : collection
        A collection of nodes in `G`.

    Returns
    -------
    number
        The node expansion of the set `S`.

    See also
    --------
    boundary_expansion
    edge_expansion
    mixing_expansion

    References
    ----------
    .. [1] Vadhan, Salil P.
           "Pseudorandomness."
           *Foundations and Trends
           in Theoretical Computer Science* 7.1â€“3 (2011): 1â€“336.
           <https://doi.org/10.1561/0400000010>

    c              3   óB   •K  — | ]}‰                      |¦  «        V — Œd S r   )Ú	neighbors)r   r   r   s     €r   r   z!node_expansion.<locals>.<genexpr>f  s-   øè è € Ð*EÐ*E¸a¨1¯;ª;°q©>¬>Ð*EÐ*EÐ*EÐ*EÐ*EÐ*Er   )r+   r   Úfrom_iterabler3   )r   r    Úneighborhoods   `  r   r	   r	   D  sL   ø€ õD •uÔ*Ð*EÐ*EÐ*EÐ*EÀ1Ð*EÑ*EÔ*EÑEÔEÑFÔF€LÝˆ|ÑÔ�s 1™vœvÑ%Ð%r   c                 óf   — t          t          j        | |¦  «        ¦  «        t          |¦  «        z  S )uû  Returns the boundary expansion of the set `S`.

    The *boundary expansion* of a set `S` is the ratio between the size of its
    node boundary and the cardinality of the set itself [1]_ .

    Parameters
    ----------
    G : NetworkX graph
        The input graph.

    S : collection
        A collection of nodes in `G`.

    Returns
    -------
    number
        The boundary expansion ratio: size of node boundary / size of `S`.

    Examples
    --------
    The node boundary is {2, 3} (size 2), divided by ``|S|=2``:

    >>> G = nx.cycle_graph(4)
    >>> S = {0, 1}
    >>> nx.boundary_expansion(G, S)
    1.0

    For disconnected sets, e.g. here where the node boundary is ``{1, 3, 5}``:

    >>> G = nx.cycle_graph(6)
    >>> S = {0, 2, 4}
    >>> nx.boundary_expansion(G, S)
    1.0

    See also
    --------
    :func:`~networkx.algorithms.boundary.node_boundary`
    edge_expansion
    mixing_expansion
    node_expansion

    Notes
    -----
    The node boundary is defined as all nodes not in `S` that are adjacent to
    nodes in `S`.

    References
    ----------
    .. [1] Vadhan, Salil P.
       "Pseudorandomness." *Foundations and Trends in Theoretical Computer Science*
       7.1â€“3 (2011): 1â€“336. <https://doi.org/10.1561/0400000010>
    )r3   r   Únode_boundary)r   r    s     r   r   r   j  s+   € õl �rÔ  1Ñ%Ô%Ñ&Ô&­¨Q©¬Ñ/Ð/r   )NNr   )Ú__doc__Ú	itertoolsr   Únetworkxr   Ú__all__Ú_dispatchabler   r   r
   r   r   r   r	   r   r   r   r   ú<module>rD      s¯  ðØ ;Ð ;à Ð Ð Ð Ð Ð à Ð Ð Ð ð	ð 	ð 	€ð €Ô˜XÐ&Ñ&Ô&ð;1ð ;1ð ;1ñ 'Ô&ð;1ð| €Ô˜XÐ&Ñ&Ô&ð'7ð '7ð '7ñ 'Ô&ð'7ðT €Ô˜XÐ&Ñ&Ô&ð1=ð 1=ð 1=ñ 'Ô&ð1=ðh €Ô˜XÐ&Ñ&Ô&ð,3ð ,3ð ,3ñ 'Ô&ð,3ð^ €Ô˜XÐ&Ñ&Ô&ð+/ð +/ð +/ñ 'Ô&ð+/ð\ €Ô˜XÐ&Ñ&Ô&ð*1ð *1ð *1ñ 'Ô&ð*1ð^ Ôð"&ð "&ñ Ôð"&ðJ Ôð50ð 50ñ Ôð50ð 50ð 50r   