1 from logging import debug
2 import time
3 import sys
4
5
6
7 _maxsize=0
8 _solution=0
9 _notbound=0
10 _sizebound=0
11
36
37
38
39
40
42 global _maxsize,_solution,_notbound,_sizebound
43
44
45 lclique = len(clique)
46 lcandidates = len(candidates)
47 notmin = lcandidates
48 notfix = None
49
50 for n in notlist:
51 nnc = candidates - graph.neighbourIndexSet(index=n)
52 nc = len(nnc)
53 if nc < notmin:
54 notmin=nc
55 notfix=n
56 notfixneib = nnc
57
58 if lclique > _maxsize or not _solution % 1000 :
59 if start is not None:
60 top = time.time()
61 delta = top - start
62 speed = _solution / delta
63 start = top
64 else:
65 speed = 0
66 print >>sys.stderr,"\rCandidates : %-5d Maximum clique size : %-5d Solutions explored : %10d speed = %5.2f solutions/sec sizebound=%10d notbound=%10d " % (lcandidates,_maxsize,_solution,speed,_sizebound,_notbound),
67 sys.stderr.flush()
68 if lclique > _maxsize:
69 _maxsize=lclique
70
71
72
73 if not candidates and not notlist:
74 yield set(clique)
75 else:
76 while notmin and candidates and (lclique + len(candidates)) >= minsize:
77
78 _solution+=1
79
80 if notfix is None:
81 nextcandidate = candidates.pop()
82 else:
83 nextcandidate = notfixneib.pop()
84 candidates.remove(nextcandidate)
85
86 clique.add(nextcandidate)
87
88 neighbours = graph.neighbourIndexSet(index=nextcandidate)
89
90 nextcandidates = candidates & neighbours
91 nextnot = notlist & neighbours
92
93 nnc = candidates - neighbours
94 lnnc=len(nnc)
95
96 for c in _cliqueIterator(graph,
97 set(clique),
98 nextcandidates,
99 nextnot,
100 minsize,
101 start):
102 yield c
103
104
105 clique.remove(nextcandidate)
106
107 notmin-=1
108
109 if lnnc < notmin:
110 notmin = lnnc
111 notfix = nextcandidate
112 notfixneib = nnc
113
114 if notmin==0:
115 _notbound+=1
116
117 notlist.add(nextcandidate)
118 else:
119 if (lclique + len(candidates)) < minsize:
120 _sizebound+=1
121