31 #pragma warning(push, 0) // no warnings from includes 47 void set_i(
const int ii) { i = ii; }
48 int get_i()
const {
return i; }
49 void set_degree(
int dd) { d = dd; }
50 int get_degree()
const {
return d; }
54 static bool desc_degree(
const Vertex vi,
const Vertex vj) {
return (vi.get_degree() > vj.get_degree()); }
57 void dbg_v(
const string msg=
"")
const {
58 std::cout << msg <<
" Vertices: [";
59 for (
int i=0; i < sz; i++)
60 std::cout <<
"(" << v[i].get_i() <<
"," << v[i].get_degree() <<
") ";
61 std::cout <<
"]" << std::endl;
64 Vertices(
int size) : sz(0) { v =
new Vertex[size]; }
66 void dispose() {
if (v)
delete [] v; }
67 void sort() { std::sort(v, v+sz, desc_degree); }
70 int size()
const {
return sz; }
71 void push(
const int ii) { v[sz++].set_i(ii); };
73 Vertex& at(
const int ii)
const {
return v[ii]; };
74 Vertex& end()
const {
return v[sz - 1]; };
81 void dbg_i(
const string msg=
"")
const {
82 std::cout << msg <<
" Class: [";
83 for (
int ii=0; ii < sz; ii++)
84 std::cout << i[ii] <<
" ";
85 std::cout <<
"]" << std::endl;
88 ColorClass() : sz(0), i(0) {}
89 ColorClass(
const int sz) : sz(sz), i(0) { init(sz); }
90 ~ColorClass() {
if (i)
delete [] i;
92 void init(
const int sz2) { i =
new int[sz2]; rewind(); }
93 void push(
const int ii) { i[sz++] = ii; };
95 void rewind() { sz = 0; };
96 int size()
const {
return sz; }
97 int& at(
const int ii)
const {
return i[ii]; }
98 ColorClass& operator=(
const ColorClass& dh) {
99 for (
int j = 0; j < dh.sz; j++) i[j] = dh.i[j];
105 ColorClass *C, QMAX, Q;
109 StepCount() : i1(0), i2(0) {}
110 void set_i1(
const int ii) { i1 = ii; }
111 int get_i1()
const {
return i1; }
112 void set_i2(
const int ii) { i2 = ii; }
113 int get_i2()
const {
return i2; }
114 void inc_i1() { i1++; }
117 bool connection(
const int i,
const int j)
const {
return e[i][j]; }
118 bool cut1(
const int,
const ColorClass&);
119 void cut2(
const Vertices&, Vertices&);
120 void color_sort(Vertices&);
121 void expand(Vertices);
122 void expand_dyn(Vertices);
123 void _mcq(
int*&,
int&,
bool);
124 void degree_sort(Vertices &R) { R.set_degrees(*
this); R.sort(); }
128 for (
int i=0; i < V.size(); i++) {
129 std::cout <<
"C["<< i <<
"] : ";
133 void dbg_conn()
const {
134 for (
int i=0; i < V.size(); i++) {
135 for (
int j=0; j < V.size(); j++) {
138 std::cout<< std::endl;
142 Maxclique(
const bool*
const*,
const int,
const float=0.025);
144 void mcq(
int* &maxclique,
int &sz) { _mcq(maxclique, sz,
false); }
145 void mcqdyn(
int* &maxclique,
int &sz) { _mcq(maxclique, sz,
true); }
154 assert(conn!=0 && sz>0);
155 for (
int i=0; i < sz; i++) V.push(i);
157 C =
new ColorClass[sz + 1];
158 for (
int i=0; i < sz + 1; i++) C[i].init(sz + 1);
159 S =
new StepCount[sz + 1];
162 void Maxclique::_mcq(
int* &maxclique,
int &sz,
bool dyn) {
163 V.set_degrees(*
this);
167 for (
int i=0; i < V.size() + 1; i++) {
175 maxclique =
new int[QMAX.size()];
176 for (
int i=0; i<QMAX.size(); i++) {
177 maxclique[i] = QMAX.at(i);
182 void Maxclique::Vertices::init_colors() {
183 const int max_degree = v[0].get_degree();
184 for (
int i = 0; i < max_degree; i++)
185 v[i].set_degree(i + 1);
186 for (
int i = max_degree; i < sz; i++)
187 v[i].set_degree(max_degree + 1);
190 void Maxclique::Vertices::set_degrees(
Maxclique &m) {
191 for (
int i=0; i < sz; i++) {
193 for (
int j=0; j < sz; j++)
194 if (m.connection(v[i].get_i(), v[j].get_i())) d++;
199 bool Maxclique::cut1(
const int pi,
const ColorClass &A) {
200 for (
int i = 0; i < A.size(); i++)
201 if (connection(pi, A.at(i)))
206 void Maxclique::cut2(
const Vertices &A, Vertices &B) {
207 for (
int i = 0; i < A.size() - 1; i++) {
208 if (connection(A.end().get_i(), A.at(i).get_i()))
209 B.push(A.at(i).get_i());
213 void Maxclique::color_sort(Vertices &R) {
216 int min_k = QMAX.size() - Q.size() + 1;
220 for (
int i=0; i < R.size(); i++) {
221 int pi = R.at(i).get_i();
223 while (cut1(pi, C[k]))
227 C[maxno + 1].rewind();
234 if (j > 0) R.at(j-1).set_degree(0);
235 if (min_k <= 0) min_k = 1;
236 for (k = min_k; k <= maxno; k++)
237 for (
int i = 0; i < C[k].size(); i++) {
238 R.at(j).set_i(C[k].at(i));
239 R.at(j++).set_degree(k);
243 void Maxclique::expand(Vertices R) {
245 if (Q.size() + R.end().get_degree() > QMAX.size()) {
246 Q.push(R.end().get_i());
247 Vertices Rp(R.size());
254 else if (Q.size() > QMAX.size()) {
255 qDebug() <<
"step = " << pk <<
" current max. clique size = " << Q.size();
268 void Maxclique::expand_dyn(Vertices R) {
269 S[level].set_i1(S[level].get_i1() + S[level - 1].get_i1() - S[level].get_i2());
270 S[level].set_i2(S[level - 1].get_i1());
272 if (Q.size() + R.end().get_degree() > QMAX.size()) {
273 Q.push(R.end().get_i());
274 Vertices Rp(R.size());
277 if ((
float)S[level].get_i1()/++pk < Tlimit) {
286 else if (Q.size() > QMAX.size()) {
287 std::cout <<
"step = " << pk <<
" current max. clique size = " << Q.size() << std::endl;
~Maxclique()
Definition: mcqd.h:146
level
Definition: DependencyCollector.py:25
Maxclique(const bool *const *, const int, const float=0.025)
Definition: mcqd.h:153
int steps() const
Definition: mcqd.h:143
void mcq(int *&maxclique, int &sz)
Definition: mcqd.h:144
void mcqdyn(int *&maxclique, int &sz)
Definition: mcqd.h:145