
    wg                        d dl Zd dlmZmZ ddgZ ed       ed       ed       ej                  d	      dd
                            Zd Z ed       ed       ed       ej                  d	      dd                            Z	y)    N)not_implemented_forpy_random_staterandomized_partitioningone_exchangedirected
multigraph   weight)
edge_attrsc                     | j                         D ch c]  }|j                         |k  s| }}t        j                  j	                  | ||      }|| j                   |z
  f}||fS c c}w )a  Compute a random partitioning of the graph nodes and its cut value.

    A partitioning is calculated by observing each node
    and deciding to add it to the partition with probability `p`,
    returning a random cut and its corresponding value (the
    sum of weights of edges connecting different partitions).

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

    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.

    p : scalar
        Probability for each node to be part of the first partition.
        Should be in [0,1]

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

    Returns
    -------
    cut_size : scalar
        Value of the minimum cut.

    partition : pair of node sets
        A partitioning of the nodes that defines a minimum cut.

    Examples
    --------
    >>> G = nx.complete_graph(5)
    >>> cut_size, partition = nx.approximation.randomized_partitioning(G, seed=1)
    >>> cut_size
    6
    >>> partition
    ({0, 3, 4}, {1, 2})

    Raises
    ------
    NetworkXNotImplemented
        If the graph is directed or is a multigraph.
    r
   )nodesrandomnx
algorithmscut_size)Gseedpr
   nodecutr   	partitions           m/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/networkx/algorithms/approximation/maxcut.pyr   r      sh    d GGI
;D):4
;C
;}}%%aV%<Haggm$IY <s
   A)A)c                 :    || v r| |hz
  S | j                  |h      S )N)union)r   r   s     r   _swap_node_partitionr   ?   s$    3;3$<=CIItf,==       c                    
 |
t               }t        |      
t        j                  j                   
      }	 t	         j                               }|j                  |       t        | 
fdd      }t        
|      }t        j                  j                   |      }||kD  r|
|}nnw
 j
                  
z
  f}	||	fS )a+  Compute a partitioning of the graphs nodes and the corresponding cut value.

    Use a greedy one exchange strategy to find a locally maximal cut
    and its value, it works by finding the best node (one that gives
    the highest gain to the cut value) to add to the current cut
    and repeats this process until no improvement can be made.

    Parameters
    ----------
    G : networkx Graph
        Graph to find a maximum cut for.

    initial_cut : set
        Cut to use as a starting point. If not supplied the algorithm
        starts with an empty cut.

    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.

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

    Returns
    -------
    cut_value : scalar
        Value of the maximum cut.

    partition : pair of node sets
        A partitioning of the nodes that defines a maximum cut.

    Examples
    --------
    >>> G = nx.complete_graph(5)
    >>> curr_cut_size, partition = nx.approximation.one_exchange(G, seed=1)
    >>> curr_cut_size
    6
    >>> partition
    ({0, 2}, {1, 3, 4})

    Raises
    ------
    NetworkXNotImplemented
        If the graph is directed or is a multigraph.
    Nr   c                 \    t         j                  j                  t        |             S )Nr   )r   r   r   r   )vr   r   r
   s    r   <lambda>zone_exchange.<locals>.<lambda>   s*    "--00'Q/ 1  r   )keydefault)	setr   r   r   listr   shufflemaxr   )r   initial_cutr   r
   current_cut_sizer   best_node_to_swappotential_cutpotential_cut_sizer   r   s   `  `      @r   r   r   C   s    f e
k
C}}--aV-D
QWWYU 
 -S2CD]]33A}V3T 00C1% ( aggm$IY&&r   )Ng      ?N)NNN)
networkxr   networkx.utils.decoratorsr   r   __all___dispatchabler   r   r    r   r   <module>r3      s     J$n
5 Z \"X&1 '  # !1h> Z \"X&H' '  # !H'r   