
    h                        S SK rS SKJrJr  SS/r\" S5      \" S5      \" S5      \R                  " SS	9SS
 j5       5       5       5       rS r\" S5      \" S5      \" S5      \R                  " SS	9SS j5       5       5       5       r	g)    N)not_implemented_forpy_random_staterandomized_partitioningone_exchangedirected
multigraph   weight)
edge_attrsc                     U R                  5        Vs1 s H  oAR                  5       U:  d  M  UiM     nn[        R                  R	                  XUS9nXPR                   U-
  4nXg4$ s  snf )aI  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           Z/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/approximation/maxcut.pyr   r      sa    d GGI
;ID):4IC
;}}%%aV%<Hggm$I <s
   A'A'c                 :    X;   a  X1-
  $ U R                  U15      $ )N)union)r   r   s     r   _swap_node_partitionr   ?   s     ;3<=CIItf,==       c                   ^ ^^
 Uc
  [        5       n[        U5      m
[        R                  R                  T T
TS9n [	        T R                  5       5      nUR                  U5        [        UU U
U4S jSS9n[        T
U5      n[        R                  R                  T UTS9nX:  a  Um
UnOOMs  T
T R
                  T
-
  4n	XI4$ )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                 V   > [         R                  R                  T[        TU 5      TS9$ )Nr   )r   r   r   r   )vr   r   r
   s    r   <lambda>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C1% ( aggm$I&&r   )Ng      ?N)NNN)
networkxr   networkx.utils.decoratorsr   r   __all___dispatchabler   r   r    r   r   <module>r4      s     J$n
5 Z \"X&1 '  # !1h> Z \"X&H' '  # !H'r   