0

Hello I am trying to find the max clique of a graph using the algorithm 1 from p.2 of that paper so far the algorithm returns just an empty set and I can't seem to find the mistake in my code. Any suggestions would be appreciated. Cheers!

my graph

import networkx as nx
graph_2 = nx.Graph()
graph_2.add_edges_from([('1','2'), ('1','3'), ('1','4'), 
                        ('2', '3'), ('2', '4'), ('3', '4'), ('4','5'), 
                        ('4', '6'), ('5', '6')])

algorithm 1

R, R_best = [], []
S = list(graph_2.nodes)

def bnb(S):
    global R 
    global R_best
    while len(S) != 0:
        if len(R) + len(S) <= len(R_best):
            return 0 
        v = S.pop(0)
        R.append(v)
        S_mark = list(set(S).intersection(set(graph_2.adj[v])))
        if len(S_mark) != 0:
            bnb(S_mark)
        elif len(R) > len(R_best):
            R_best = R
        try:    
            R.remove(v)
            S.remove(v)
        except:
            continue
    return R_best 


print(bnb(S))   # prints []
C96
  • 477
  • 8
  • 33

0 Answers0