
    he                        S r SSKJrJr  SSKJrJrJr  SSKr	SSK
Jr  / SQr\" S5      \	R                  S 5       5       r\" S5      \	R                  SS	 j5       5       r\	R                  SS
 j5       r\	R                  " SS9SS j5       r\	R                  " SS9SS j5       r\	R                  SS j5       rSS jr " S S5      r\" S5      \	R                  " SS9SS j5       5       rg)a@  Functions for finding and manipulating cliques.

Finding the largest clique in a graph is NP-complete problem, so most of
these algorithms have an exponential running time; for more information,
see the Wikipedia article on the clique problem [1]_.

.. [1] clique problem:: https://en.wikipedia.org/wiki/Clique_problem

    )defaultdictdeque)chaincombinationsisliceN)not_implemented_for)find_cliquesfind_cliques_recursivemake_max_clique_graphmake_clique_bipartitenode_clique_numbernumber_of_cliquesenumerate_all_cliquesmax_weight_cliquedirectedc              #     ^^#    0 m0 mU  H0  n[        T5      TU'   X    Vs1 s H  o"T;  d  M
  UiM     snTU'   M2     [        UU4S jU  5       5      nU(       a  [        [        UR	                  5       5      u  pEUv   [        U5       HF  u  paUR                  [        XA/5      [        TU   R                  [        XVS-   S5      5      45        MH     U(       a  M  ggs  snf 7f)a  Returns all cliques in an undirected graph.

This function returns an iterator over cliques, each of which is a
list of nodes. The iteration is ordered by cardinality of the
cliques: first all cliques of size one, then all cliques of size
two, etc.

Parameters
----------
G : NetworkX graph
    An undirected graph.

Returns
-------
iterator
    An iterator over cliques, each of which is a list of nodes in
    `G`. The cliques are ordered according to size.

Notes
-----
To obtain a list of all cliques, use
`list(enumerate_all_cliques(G))`. However, be aware that in the
worst-case, the length of this list can be exponential in the number
of nodes in the graph (for example, when the graph is the complete
graph). This function avoids storing all cliques in memory by only
keeping current candidate node lists in memory during its search.

The implementation is adapted from the algorithm by Zhang, et
al. (2005) [1]_ to output all cliques discovered.

This algorithm ignores self-loops and parallel edges, since cliques
are not conventionally defined with such edges.

References
----------
.. [1] Yun Zhang, Abu-Khzam, F.N., Baldwin, N.E., Chesler, E.J.,
       Langston, M.A., Samatova, N.F.,
       "Genome-Scale Computational Approaches to Memory-Intensive
       Applications in Systems Biology".
       *Supercomputing*, 2005. Proceedings of the ACM/IEEE SC 2005
       Conference, pp. 12, 12--18 Nov. 2005.
       <https://doi.org/10.1109/SC.2005.29>.

c              3   V   >#    U  H  o/[        TU   TR                  S 94v   M      g7f)keyN)sorted__getitem__).0uindexnbrss     L/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/clique.py	<genexpr>(enumerate_all_cliques.<locals>.<genexpr>S   s'     KA3tAwE,=,=>?s   &)   N)lenr   maplistpopleft	enumerateappendr   filter__contains__r   )	Gr   vqueuebasecnbrsir   r   s	          @@r   r   r      s     ^ EDu:ad5dun1d5Q 
 KKKE
 $0
e$DALL$$47//1ud1KL % % 6s   C%	C C B'C%C%c           
   #   <  ^^#    [        U 5      S:X  a  gU  VVs0 s H  o"X    Vs1 s H  o3U:w  d  M
  UiM     sn_M!     snnmUb  USS O/ n[        U 5      mU H   nUT;  a  [        SU S35      eTTU   -  mM"     T(       d  USS v   gTR                  5       n/ nUR	                  S5        [        UUU4S jS9nTTU   -
  n  U(       a  UR                  5       n	TR                  U	5        XS'   TU	   n
Xj-  nU(       d  USS v   OqTU
-  nU(       a@  UR	                  UTU45        UR	                  S5        UnUm[        UUU4S jS9nTTU   -
  nO$UR                  5         UR                  5       u  nmnM  s  snf s  snnf ! [         a     gf = f7f)	a4  Returns all maximal cliques in an undirected graph.

For each node *n*, a *maximal clique for n* is a largest complete
subgraph containing *n*. The largest maximal clique is sometimes
called the *maximum clique*.

This function returns an iterator over cliques, each of which is a
list of nodes. It is an iterative implementation, so should not
suffer from recursion depth issues.

This function accepts a list of `nodes` and only the maximal cliques
containing all of these `nodes` are returned. It can considerably speed up
the running time if some specific cliques are desired.

Parameters
----------
G : NetworkX graph
    An undirected graph.

nodes : list, optional (default=None)
    If provided, only yield *maximal cliques* containing all nodes in `nodes`.
    If `nodes` isn't a clique itself, a ValueError is raised.

Returns
-------
iterator
    An iterator over maximal cliques, each of which is a list of
    nodes in `G`. If `nodes` is provided, only the maximal cliques
    containing all the nodes in `nodes` are returned. The order of
    cliques is arbitrary.

Raises
------
ValueError
    If `nodes` is not a clique.

Examples
--------
>>> from pprint import pprint  # For nice dict formatting
>>> G = nx.karate_club_graph()
>>> sum(1 for c in nx.find_cliques(G))  # The number of maximal cliques in G
36
>>> max(nx.find_cliques(G), key=len)  # The largest maximal clique in G
[0, 1, 2, 3, 13]

The size of the largest maximal clique is known as the *clique number* of
the graph, which can be found directly with:

>>> max(len(c) for c in nx.find_cliques(G))
5

One can also compute the number of maximal cliques in `G` that contain a given
node. The following produces a dictionary keyed by node whose
values are the number of maximal cliques in `G` that contain the node:

>>> pprint({n: sum(1 for c in nx.find_cliques(G) if n in c) for n in G})
{0: 13,
 1: 6,
 2: 7,
 3: 3,
 4: 2,
 5: 3,
 6: 3,
 7: 1,
 8: 3,
 9: 2,
 10: 2,
 11: 1,
 12: 1,
 13: 2,
 14: 1,
 15: 1,
 16: 1,
 17: 1,
 18: 1,
 19: 2,
 20: 1,
 21: 1,
 22: 1,
 23: 3,
 24: 2,
 25: 2,
 26: 1,
 27: 3,
 28: 2,
 29: 2,
 30: 2,
 31: 4,
 32: 9,
 33: 14}

Or, similarly, the maximal cliques in `G` that contain a given node.
For example, the 4 maximal cliques that contain node 31:

>>> [c for c in nx.find_cliques(G) if 31 in c]
[[0, 31], [33, 32, 31], [33, 28, 31], [24, 25, 31]]

See Also
--------
find_cliques_recursive
    A recursive version of the same algorithm.

Notes
-----
To obtain a list of all maximal cliques, use
`list(find_cliques(G))`. However, be aware that in the worst-case,
the length of this list can be exponential in the number of nodes in
the graph. This function avoids storing all cliques in memory by
only keeping current candidate node lists in memory during its search.

This implementation is based on the algorithm published by Bron and
Kerbosch (1973) [1]_, as adapted by Tomita, Tanaka and Takahashi
(2006) [2]_ and discussed in Cazals and Karande (2008) [3]_. It
essentially unrolls the recursion used in the references to avoid
issues of recursion stack depth (for a recursive implementation, see
:func:`find_cliques_recursive`).

This algorithm ignores self-loops and parallel edges, since cliques
are not conventionally defined with such edges.

References
----------
.. [1] Bron, C. and Kerbosch, J.
   "Algorithm 457: finding all cliques of an undirected graph".
   *Communications of the ACM* 16, 9 (Sep. 1973), 575--577.
   <http://portal.acm.org/citation.cfm?doid=362342.362367>

.. [2] Etsuji Tomita, Akira Tanaka, Haruhisa Takahashi,
   "The worst-case time complexity for generating all maximal
   cliques and computational experiments",
   *Theoretical Computer Science*, Volume 363, Issue 1,
   Computing and Combinatorics,
   10th Annual International Conference on
   Computing and Combinatorics (COCOON 2004), 25 October 2006, Pages 28--42
   <https://doi.org/10.1016/j.tcs.2006.06.015>

.. [3] F. Cazals, C. Karande,
   "A note on the problem of reporting maximal cliques",
   *Theoretical Computer Science*,
   Volume 407, Issues 1--3, 6 November 2008, Pages 564--568,
   <https://doi.org/10.1016/j.tcs.2008.05.010>

r   NThe given `nodes`  do not form a cliquec                 &   > [        TTU    -  5      $ Nr    r   adjcands    r   <lambda>find_cliques.<locals>.<lambda>  s    D3q6M 2    r   c                 &   > [        TTU    -  5      $ r2   r3   r4   s    r   r7   r8      s    Cs1v4Fr9   )	r    set
ValueErrorcopyr%   maxpopremove
IndexError)r(   nodesr   r)   Qnodesubgstackext_uqadj_qsubg_qcand_qr5   r6   s                @@r   r	   r	   e   s    d 1v{34
51a!$)$Qq&q$))1
5C %a2Aq6Dt1%8MNOOD	 
 d
99;DEHHTND23A3q6MEIIKA"AA$J!E\FdD%%89%%*FG $s1v$)IIK!dE) - *
5V  sK   FF	FFF BF	B8F FF
FFFFc           
        ^^^	 [        U 5      S:X  a  [        / 5      $ U  VVs0 s H  o"X    Vs1 s H  o3U:w  d  M
  UiM     sn_M!     snnmUb  USS O/ m[        U 5      nT H  nXT;  a  [        SU S35      eUTU   -  nM!     U(       d  [        T/5      $ UR	                  5       nUUU	4S jm	T	" Xd5      $ s  snf s  snnf )aW  Returns all maximal cliques in a graph.

For each node *v*, a *maximal clique for v* is a largest complete
subgraph containing *v*. The largest maximal clique is sometimes
called the *maximum clique*.

This function returns an iterator over cliques, each of which is a
list of nodes. It is a recursive implementation, so may suffer from
recursion depth issues, but is included for pedagogical reasons.
For a non-recursive implementation, see :func:`find_cliques`.

This function accepts a list of `nodes` and only the maximal cliques
containing all of these `nodes` are returned. It can considerably speed up
the running time if some specific cliques are desired.

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

nodes : list, optional (default=None)
    If provided, only yield *maximal cliques* containing all nodes in `nodes`.
    If `nodes` isn't a clique itself, a ValueError is raised.

Returns
-------
iterator
    An iterator over maximal cliques, each of which is a list of
    nodes in `G`. If `nodes` is provided, only the maximal cliques
    containing all the nodes in `nodes` are yielded. The order of
    cliques is arbitrary.

Raises
------
ValueError
    If `nodes` is not a clique.

See Also
--------
find_cliques
    An iterative version of the same algorithm. See docstring for examples.

Notes
-----
To obtain a list of all maximal cliques, use
`list(find_cliques_recursive(G))`. However, be aware that in the
worst-case, the length of this list can be exponential in the number
of nodes in the graph. This function avoids storing all cliques in memory
by only keeping current candidate node lists in memory during its search.

This implementation is based on the algorithm published by Bron and
Kerbosch (1973) [1]_, as adapted by Tomita, Tanaka and Takahashi
(2006) [2]_ and discussed in Cazals and Karande (2008) [3]_. For a
non-recursive implementation, see :func:`find_cliques`.

This algorithm ignores self-loops and parallel edges, since cliques
are not conventionally defined with such edges.

References
----------
.. [1] Bron, C. and Kerbosch, J.
   "Algorithm 457: finding all cliques of an undirected graph".
   *Communications of the ACM* 16, 9 (Sep. 1973), 575--577.
   <http://portal.acm.org/citation.cfm?doid=362342.362367>

.. [2] Etsuji Tomita, Akira Tanaka, Haruhisa Takahashi,
   "The worst-case time complexity for generating all maximal
   cliques and computational experiments",
   *Theoretical Computer Science*, Volume 363, Issue 1,
   Computing and Combinatorics,
   10th Annual International Conference on
   Computing and Combinatorics (COCOON 2004), 25 October 2006, Pages 28--42
   <https://doi.org/10.1016/j.tcs.2006.06.015>

.. [3] F. Cazals, C. Karande,
   "A note on the problem of reporting maximal cliques",
   *Theoretical Computer Science*,
   Volume 407, Issues 1--3, 6 November 2008, Pages 564--568,
   <https://doi.org/10.1016/j.tcs.2008.05.010>

r   Nr/   r0   c              3     >^#    [        U UU4S jS9nTTU   -
   Hi  nTR                  U5        TR                  U5        TU   nX-  nU(       d  TS S  v   OTU-  nU(       a  T	" XV5       S h  vN   TR                  5         Mk     g  N7f)Nc                 &   > [        TTU    -  5      $ r2   r3   r4   s    r   r7   8find_cliques_recursive.<locals>.expand.<locals>.<lambda>  s    Cs1v$6r9   r   )r?   rA   r%   r@   )
rF   r6   r   rI   rJ   rK   rL   rD   r5   expands
    `     r   rQ   &find_cliques_recursive.<locals>.expand  s     67AAKKNHHQKFE\Fd
%f555EEG  6s   A,B0B
1B)r    iterr<   r=   r>   )
r(   rC   r   r)   	cand_initrE   	subg_initrD   r5   rQ   s
          @@@r   r
   r
   *  s    d 1v{Bx34
51a!$)$Qq&q$))1
5C %a2AAI 1%8MNOOSY	 
 QCy I )''= *
5s   B?	B:B:B?:B?T)returns_graphc                    Uc  U R                  5       nO[        R                  " SU5      n[        [	        S [        U 5       5       5      5      nUR                  S U 5       5        [        US5      nUR                  S U 5       5        U$ )au  Returns the maximal clique graph of the given graph.

The nodes of the maximal clique graph of `G` are the cliques of
`G` and an edge joins two cliques if the cliques are not disjoint.

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

create_using : NetworkX graph constructor, optional (default=nx.Graph)
   Graph type to create. If graph instance, then cleared before populated.

Returns
-------
NetworkX graph
    A graph whose nodes are the cliques of `G` and whose edges
    join two cliques if they are not disjoint.

Notes
-----
This function behaves like the following code::

    import networkx as nx

    G = nx.make_clique_bipartite(G)
    cliques = [v for v in G.nodes() if G.nodes[v]["bipartite"] == 0]
    G = nx.bipartite.projected_graph(G, cliques)
    G = nx.relabel_nodes(G, {-v: v - 1 for v in G})

It should be faster, though, since it skips all the intermediate
steps.

r   c              3   8   #    U  H  n[        U5      v   M     g 7fr2   )r<   r   cs     r   r   (make_max_clique_graph.<locals>.<genexpr>  s     =_SVV_   c              3   *   #    U  H	  u  pUv   M     g 7fr2    )r   r-   rZ   s      r   r   r[     s     +741Q7s      c              3   L   #    U  H  u  u  pu  p4X$-  (       d  M  X4v   M     g 7fr2   r^   )r   r-   c1jc2s        r   r   r[     s!     LL 0!BGVaVLs   $
$)		__class__nxempty_graphr"   r$   r	   add_nodes_fromr   add_edges_from)r(   create_usingBcliquesclique_pairss        r   r   r     sx    F KKMNN1l+9=\!_==>G+7+++LLLLLHr9   c                   ^ [         R                  " SU5      nUR                  5         UR                  U SS9  [	        [        U 5      5       H6  u  pVU* S-
  mUR                  TSS9  UR                  U4S jU 5       5        M8     U$ )ae  Returns the bipartite clique graph corresponding to `G`.

In the returned bipartite graph, the "bottom" nodes are the nodes of
`G` and the "top" nodes represent the maximal cliques of `G`.
There is an edge from node *v* to clique *C* in the returned graph
if and only if *v* is an element of *C*.

Parameters
----------
G : NetworkX graph
    An undirected graph.

fpos : bool
    If True or not None, the returned graph will have an
    additional attribute, `pos`, a dictionary mapping node to
    position in the Euclidean plane.

create_using : NetworkX graph constructor, optional (default=nx.Graph)
   Graph type to create. If graph instance, then cleared before populated.

Returns
-------
NetworkX graph
    A bipartite graph whose "bottom" set is the nodes of the graph
    `G`, whose "top" set is the cliques of `G`, and whose edges
    join nodes of `G` to the cliques that contain them.

    The nodes of the graph `G` have the node attribute
    'bipartite' set to 1 and the nodes representing cliques
    have the node attribute 'bipartite' set to 0, as is the
    convention for bipartite graphs in NetworkX.

r   r   )	bipartitec              3   *   >#    U  H  oT4v   M
     g 7fr2   r^   )r   r)   names     r   r   (make_clique_bipartite.<locals>.<genexpr>  s     /BqTBs   )re   rf   clearrg   r$   r	   add_noderh   )r(   fposri   rp   rj   r-   cls      `   r   r   r     s    F 	q,'AGGI Q!$<?+ rAv	

41
%	/B// , Hr9   c                   ^ Uc  Tbv  TU ;   a0  [        S [        [        R                  " U T5      5       5       5      $ T Vs0 s H2  oD[        S [        [        R                  " X5      5       5       5      _M4     sn$ [	        [        U 5      5      nTU ;   a  [        U4S jU 5       5      $ [        [        5      nU H%  n[        U5      nU H  nXT   U:  d  M  XuU'   M     M'     Tc  U$ T Vs0 s H  oDXT   _M	     sn$ s  snf s  snf )a  Returns the size of the largest maximal clique containing each given node.

Returns a single or list depending on input nodes.
An optional list of cliques can be input if already computed.

Parameters
----------
G : NetworkX graph
    An undirected graph.

cliques : list, optional (default=None)
    A list of cliques, each of which is itself a list of nodes.
    If not specified, the list of all cliques will be computed
    using :func:`find_cliques`.

Returns
-------
int or dict
    If `nodes` is a single node, returns the size of the
    largest maximal clique in `G` containing that node.
    Otherwise return a dict keyed by node to the size
    of the largest maximal clique containing that node.

See Also
--------
find_cliques
    find_cliques yields the maximal cliques of G.
    It accepts a `nodes` argument which restricts consideration to
    maximal cliques containing all the given `nodes`.
    The search for the cliques is optimized for `nodes`.
c              3   8   #    U  H  n[        U5      v   M     g 7fr2   r3   rY   s     r   r   %node_clique_number.<locals>.<genexpr>'  s     P+Oa3q66+Or\   c              3   8   #    U  H  n[        U5      v   M     g 7fr2   r3   rY   s     r   r   rx   *  s     H'G!s1vv'Gr\   c              3   J   >#    U  H  nTU;   d  M  [        U5      v   M     g 7fr2   r3   )r   rZ   rC   s     r   r   rx   2  s     97aeqj63q667s   
##)r?   r	   re   	ego_graphr"   r   intr    )r(   rC   rk   separate_nodesn
size_for_nrZ   	size_of_cs    `      r   r   r     s   B  zP<Q8N+OPPP SXRWQ3H|BLL4F'GHHHRW 
 |A' z97999 S!JF	A}y( )1  
 }&+,ez}e,,+* -s   9D0Dc                 X   Uc  [        [        U 5      5      nUc  [        U R                  5       5      n[        U[         5      (       d'  Un[	        U Vs/ s H  oCU;   d  M
  SPM     sn5      nU$ 0 nU H(  n[	        U Vs/ s H  oCU;   d  M
  SPM     sn5      XS'   M*     U$ s  snf s  snf )zReturns the number of maximal cliques for each node.

Returns a single or list depending on input nodes.
Optional list of cliques can be input if already computed.
r   )r"   r	   rC   
isinstancer    )r(   rC   rk   r)   rZ   numcliqs         r   r   r   A  s     |A'}QWWYeT""'4'Q!Vq'45
 N A;AFa;<GJ N 5 <s   	B"!B" 	B'
B'
c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)MaxWeightCliqueiX  a  A class for the maximum weight clique algorithm.

This class is a helper for the `max_weight_clique` function.  The class
should not normally be used directly.

Parameters
----------
G : NetworkX graph
    The undirected graph for which a maximum weight clique is sought
weight : string or None, optional (default='weight')
    The node attribute that holds the integer value used as a weight.
    If None, then each node has weight 1.

Attributes
----------
G : NetworkX graph
    The undirected graph for which a maximum weight clique is sought
node_weights: dict
    The weight of each node
incumbent_nodes : list
    The nodes of the incumbent clique (the best clique found so far)
incumbent_weight: int
    The weight of the incumbent clique
c                    Xl         / U l        SU l        Uc'  UR                  5        Vs0 s H  o3S_M     snU l        g UR                  5        Hb  nX!R                  U   ;  a  SU< S3n[        U5      e[        UR                  U   U   [        5      (       a  MN  SU< SU< S3n[        U5      e   UR                  5        Vs0 s H  o3UR                  U   U   _M     snU l        g s  snf s  snf )Nr   r   zNode z* does not have the requested weight field.zThe z field of node z is not an integer.)	r(   incumbent_nodesincumbent_weightrC   node_weightsKeyErrorr   r|   r=   )selfr(   weightr)   errmsgs        r   __init__MaxWeightClique.__init__r  s    ! !>/0wwy 9y!Ay 9DWWY+$QE)STF"6**!!''!*V"4c::#F:_QEATUF$V,,  AB	 J	1AGGAJv$6!6	 JD !: !Ks   C,C1c                 D    X R                   :  a  USS U l        X l         gg)zYUpdate the incumbent if the node set C has greater weight.

C is assumed to be a clique.
N)r   r   )r   CC_weights      r   update_incumbent_if_improved,MaxWeightClique.update_incumbent_if_improved  s'    
 +++#$Q4D $,! ,r9   c                     / nUSS nU(       aZ  US   nUR                  U5        U Vs/ s H.  oCU:w  d  M
  U R                  R                  X45      (       a  M,  UPM0     nnU(       a  MZ  U$ s  snf )z@Greedily find an independent set of nodes from a set of
nodes P.Nr   )r%   r(   has_edge)r   Pindependent_setr)   ws        r   greedily_find_independent_set-MaxWeightClique.greedily_find_independent_set  sj     aD!A""1%FAqa0EAAF a  Gs   	A+A+A+c                 T  ^ U Vs0 s H  o3U R                   U   _M     snmSnUSS nU(       an  U R                  U5      n[        U4S jU 5       5      nXF-  nXB:  a   U$ U H  nTU==   U-  ss'   M     U Vs/ s H  nTU   S:w  d  M  UPM     nnU(       a  Mn  U$ s  snf s  snf )z!Find a set of nodes to branch on.r   Nc              3   .   >#    U  H
  nTU   v   M     g 7fr2   r^   )r   r)   residual_wts     r   r   7MaxWeightClique.find_branching_nodes.<locals>.<genexpr>  s     !J/Q+a./s   )r   r   min)r   r   targetr)   total_wtr   min_wt_in_classr   s          @r   find_branching_nodes$MaxWeightClique.find_branching_nodes  s    89:1$++A..:aD"@@CO!!J/!JJO'H   %A/1 %5AqQ1!4AA5 a  ; 6s   B <B%B%c                    U R                  X5        U R                  X0R                  U-
  5      nU(       a  UR                  5       nUR	                  U5        X/-   nX R
                  U   -   nU Vs/ s H&  oR                  R                  XX5      (       d  M$  UPM(     n	nU R                  XgU	5        U(       a  M  ggs  snf )zLook for the best clique that contains all the nodes in C and zero or
more of the nodes in P, backtracking if it can be shown that no such
clique has greater weight than the incumbent.
N)	r   r   r   r@   rA   r   r(   r   rQ   )
r   r   r   r   branching_nodesr)   new_Cnew_C_weightr   new_Ps
             r   rQ   MaxWeightClique.expand  s    
 	))!633A7L7Lx7WX##%AHHQKGE#&7&7&::L !;1VV__Q%:QE;KKU3 o
 <s   2#B>B>c                    ^  [        T R                  R                  5       U 4S jSS9nU Vs/ s H  nT R                  U   S:  d  M  UPM     nnT R	                  / SU5        gs  snf )zFind a maximum weight clique.c                 :   > TR                   R                  U 5      $ r2   )r(   degree)r)   r   s    r   r7   8MaxWeightClique.find_max_weight_clique.<locals>.<lambda>  s    TVV]]15Er9   T)r   reverser   N)r   r(   rC   r   rQ   )r   rC   r)   s   `  r   find_max_weight_clique&MaxWeightClique.find_max_weight_clique  sY     tvv||~+EtT!>EqT%6%6q%9A%=E>B5! ?s   A$A$)r(   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   r   r   rQ   r   __static_attributes__r^   r9   r   r   r   X  s&    2K"-	 4"r9   r   r   )
node_attrsc                 h    [        X5      nUR                  5         UR                  UR                  4$ )u  Find a maximum weight clique in G.

A *clique* in a graph is a set of nodes such that every two distinct nodes
are adjacent.  The *weight* of a clique is the sum of the weights of its
nodes.  A *maximum weight clique* of graph G is a clique C in G such that
no clique in G has weight greater than the weight of C.

Parameters
----------
G : NetworkX graph
    Undirected graph
weight : string or None, optional (default='weight')
    The node attribute that holds the integer value used as a weight.
    If None, then each node has weight 1.

Returns
-------
clique : list
    the nodes of a maximum weight clique
weight : int
    the weight of a maximum weight clique

Notes
-----
The implementation is recursive, and therefore it may run into recursion
depth issues if G contains a clique whose number of nodes is close to the
recursion depth limit.

At each search node, the algorithm greedily constructs a weighted
independent set cover of part of the graph in order to find a small set of
nodes on which to branch.  The algorithm is very similar to the algorithm
of Tavares et al. [1]_, other than the fact that the NetworkX version does
not use bitsets.  This style of algorithm for maximum weight clique (and
maximum weight independent set, which is the same problem but on the
complement graph) has a decades-long history.  See Algorithm B of Warren
and Hicks [2]_ and the references in that paper.

References
----------
.. [1] Tavares, W.A., Neto, M.B.C., Rodrigues, C.D., Michelon, P.: Um
       algoritmo de branch and bound para o problema da clique máxima
       ponderada.  Proceedings of XLVII SBPO 1 (2015).

.. [2] Warren, Jeffrey S, Hicks, Illya V.: Combinatorial Branch-and-Bound
       for the Maximum Weight Independent Set Problem.  Technical Report,
       Texas A&M University (2016).
)r   r   r   r   )r(   r   mwcs      r   r   r     s2    f !
$C  4 444r9   r2   )NNN)NNF)NN)r   )r   collectionsr   r   	itertoolsr   r   r   networkxre   networkx.utilsr   __all___dispatchabler   r	   r
   r   r   r   r   r   r   r^   r9   r   <module>r      s,   + 1 1  .	 Z C  !CL Z   !F r( r(j %, &,^ %- &-` <- <-~.c" c"L Z X&35 ' !35r9   