-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
97 lines (85 loc) · 2.49 KB
/
main.cpp
File metadata and controls
97 lines (85 loc) · 2.49 KB
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
87
88
89
90
91
92
93
94
95
96
97
#include "public.h"
#include "read_file.h"
#include "Vertices.h"
using namespace std;
static int num = 0;
static vector<int> maxclique;
static vector<int> tmpclique;
void expand(bool MCR, const bool * const * conn, Vertices &V);
int main(int argc, char *argv[]) {
assert(argc == 2);
cout << "args = " << argv[1] << endl;
bool **conn;
size_t size;
read_file(argv[1], conn, size);
clock_t start1 = time(NULL);
clock_t start2 = clock();
Vertices V, V_MCR;
cout<<"--------------------------normal sort-----------------------------------"<<endl;
V.init(size);
V.set_degrees(conn);
V.degree_sort();
V.colo_sort(conn, 1);
expand(false, conn, V);
/*
cout<<"maxclique: ";
for(vector<int>::iterator iter = maxclique.begin(); iter != maxclique.end(); ++iter) {
cout<<*iter + 1<<' ';
}
cout<<endl;
*/
cout<<"size: "<<maxclique.size()<<endl;
cout<<"common expand num:"<<num<<endl;
cout<<"Time = "<<difftime(time(NULL), start1) <<endl;
cout<<"Time (precise) = "<<((double) (clock() - start2)) / CLOCKS_PER_SEC <<endl;
num = 0;
maxclique.resize(0);
start1 = time(NULL);
start2 = clock();
cout<<"--------------------------MCR sort--------------------------------------"<<endl;
V_MCR.init(size);
V_MCR.set_degrees(conn);
V_MCR.MCR_sort(conn);
V_MCR.colo_sort(conn, 1);
expand(true, conn, V_MCR);
/*
cout<<"maxclique: ";
for(vector<int>::iterator iter = maxclique.begin(); iter != maxclique.end(); ++iter) {
cout<<*iter + 1<<' ';
}
cout<<endl;
*/
cout<<"size: "<<maxclique.size()<<endl;
cout<<"MCR expand num:"<<num<<endl;
cout<<"Time = "<<difftime(time(NULL), start1) <<endl;
cout<<"Time (precise) = "<<((double) (clock() - start2)) / CLOCKS_PER_SEC <<endl;
return 0;
}
void expand(bool MCR, const bool * const * conn, Vertices &V) {
int min_k;
Vertices temp;
size_t i;
while(!V.empty()) {
min_k = maxclique.size() > tmpclique.size() ? maxclique.size() - tmpclique.size() : -1;
if(V.get_color_num() > min_k) {
i = V.pop();
tmpclique.push_back(i);
temp.cut_vertex_from(conn, V, i);
if(!temp.empty()) {
// temp.set_degrees(conn);
// MCR ? temp.MCR_sort(conn) : temp.degree_sort();
// temp.colo_sort(conn, min_k);
num++;
expand(MCR, conn, temp);
}
else if (tmpclique.size() > maxclique.size()) {
std::cout<<"step = "<<num<<" current max size: "<<tmpclique.size()<<std::endl;
maxclique = tmpclique;
}
tmpclique.pop_back();
}
else {
return;
}
}
}