-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis_clique_k.py
90 lines (60 loc) · 2.17 KB
/
is_clique_k.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
80
81
82
83
84
85
86
#! usr/bin/python
# This porgram tells whether the given graph has a clique of size k or not
import deg_check as dc
from numpy import *
import xlrd as xlrd
r = raw_input('Pls enter the name of sheet in which adjcent matrix is being stored \n ')
wb = xlrd.open_workbook(r)#To get workbook
sh = wb.sheet_by_index(0)#To get first sheet
Adj_mat = []#Initialisation
V = []
for rn in range(sh.nrows):# creating Adj_mat and V
Adj_mat = Adj_mat + [sh.row_values(rn)]
V.append(rn+1)
k = input('Enter the size of clique we are looking for ')
k=k-1
flag =0
D = [0 for i in range(0,len(Adj_mat))]
while flag==0:
for i in range(0,len(Adj_mat)):
D[i]=sum(Adj_mat[i])
Adj_mat,D = dc.min_deg_check(Adj_mat,D,k)
if len(Adj_mat)==0:
print '1.No clique exists'
break
d_max_i = D.index(max(D))
if max(D) < k:
print '2.No clique exist'
break
temp = Adj_mat[d_max_i]
temp1 = [0 for i in range(0,len(Adj_mat))]
temp2 = [0 for i in range(0,len(Adj_mat))]
q=1# to measure the size of clique
Covered = [d_max_i]
print Covered
while sum(temp)!= 0:
k1=0
for i in range(0,len(Adj_mat)):
if i in Covered != True:
print i
print sum(temp1)
for i1 in range(0,len(Adj_mat)):
temp1[i1] = temp[i1]*Adj_mat[i][i1]
print 'sum(temp1) is ',sum(temp1)
print 'k1 is ',k1
a = input('Script check ')
if k1 < sum(temp1):
k1 = sum(temp1)
temp2 =temp1
i_sto = i
temp = temp2
Covered = Covered + [i_sto]
q=q+1
if q < k:
for j in range(0,len(Adj_mat)):
del Adj_mat[j][d_max_i]
del Adj_mat[d_max_i]
del D[d_max_i]
else:
print 'Clique of given size exist'
break