-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclique.py
92 lines (55 loc) · 1.22 KB
/
clique.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import csv
import sys
import numpy as np
from random import shuffle
from numpy import genfromtxt
from cvxopt import matrix, solvers
import cvxopt as cvx
import cvxopt.lapack
from cvxopt import matrix, spmatrix, sparse
from scipy.sparse import csgraph
import picos as pic
from scipy.sparse import *
from scipy import *
from numpy import linalg as LA
from scipy.linalg import fractional_matrix_power
import math
import itertools
import networkx as nx
#Reading the adjacency matrix
graph = genfromtxt('Graph_2.csv', delimiter=',')
N = graph.shape[1]
#to find diagonal
D = graph.dot(graph)
diag = diag(D)
#eigen value:
w, v = LA.eig(graph)
#changing to lost
w = w.tolist()
e = sorted(w)[-1]
ub = e +1
print("upper bound:", ub)
print("max diag +1:", max(diag)+1)
G=nx.from_numpy_matrix(graph)
cl = nx.find_cliques(G)
ans = list(cl)
print(ans)
length = 0
pos = 0
for i in range(len(ans)):
if len(ans[i])>length:
length = len(ans[i])
pos = i
clique_final = ans[pos]
print("brute force answer:", len(clique_final))
x = np.zeros(N)
for i in clique_final:
x[i] = 1
final_x = list(map(int, x))
#print(final_x)
'''
#Output
with open('6_clique_sol', 'w') as myfile:
wr = csv.writer(myfile)
wr.writerow(final_x)
'''