-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssaz.cpp
More file actions
187 lines (169 loc) · 6.35 KB
/
ssaz.cpp
File metadata and controls
187 lines (169 loc) · 6.35 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "option.h"
#include "rwgraph.h"
#include <iostream>
#include <ctime>
#include <cmath>
#include <cstring>
#include "sampler.h"
#include "IMSampler.h"
using namespace std;
using namespace std::placeholders;
void init_seeds(Sampler &sample)
{
vector <uint64_t> s_init;
for (int i = 0; i < 16; ++i)
s_init.push_back(rand());
sample.init_seed(rand()%16,s_init);
}
int main(int argc, char ** argv)
{
srand(time(NULL));
OptionParser op(argc, argv);
if (!op.validCheck()){
printf("Parameters error, please check the readme.txt file for correct format!\n");
return -1;
}
char * inFile = op.getPara("-i");
if (inFile == NULL){
inFile = (char*)"network.bin";
}
char * outFile = op.getPara("-o");
if (outFile == NULL){
outFile = (char*)"network.seeds";
}
char * tmp = op.getPara("-epsilon");
double epsilon = 0.1;
if (tmp != NULL){
epsilon = atof(tmp);
}
double delta = 0;
tmp = op.getPara("-delta");
if (tmp != NULL){
delta = atof(tmp);
}
int k = 0;
tmp = op.getPara("-k");
if (tmp != NULL){
k = atoi(tmp);
}
int t = 1;
tmp = op.getPara("-t");
if (tmp != NULL){
t = atoi(tmp);
}
char * prob = op.getPara("-prob");
if (prob == NULL){
cout << "Select an algorithm and run again!" << endl;
return 1;
}
char * alg = op.getPara("-alg");
if (alg == NULL){
cout << "Select an algorithm and run again!" << endl;
return 1;
}
int eager_mode = 1;
char * emode = op.getPara("-emode");
if (emode != NULL){
if (strcmp(emode,"STRICT") == 0){
eager_mode = 1;
} else if (strcmp(emode,"EAGER") == 0){
eager_mode = 2;
} else if (strcmp(emode,"VEAGER") == 0){
eager_mode = 3;
} else {
cout << "Invalid eager mode ====> set to default 'strict' mode" << endl;
}
}
bool do_check = false;
char * checked = op.getPara("-check");
if (checked != NULL) do_check = true;
if (strcmp(prob, "IM") == 0){
char * model = op.getPara("-m");
if (model == NULL)
model = (char *) "LT";
if (strcmp(model, "LT") == 0){
Graph g;
g.readGraphLT(inFile);
int n = g.getSize();
HyperGraph hg(n,k,eager_mode,epsilon,delta,do_check);
IM_LTSampler sampler(g,do_check);
if (strcmp(alg, "SRA") == 0){
hg.runMaxCover_SRA(std::bind(&IM_LTSampler::polling, &sampler, _1, _2, _3), epsilon,delta,k,t,n*1.0,1);
} else if (strcmp(alg, "SSA_z") == 0){
hg.runMaxCover_SSAz(std::bind(&IM_LTSampler::polling, &sampler, _1, _2, _3), epsilon,delta,k,t,n*1.0,1);
} else if (strcmp(alg, "SSA_mul") == 0){
double z = hg.getZ();
for (int l = floor(log2(z))-2; l>= 0; l--){
if (hg.runMaxCover_SSAz(std::bind(&IM_LTSampler::polling, &sampler, _1, _2, _3), epsilon,delta,k,t,n*1.0,l)){
break;
}
hg = HyperGraph(n,k,eager_mode,epsilon,delta,do_check);
}
}
} else if (strcmp(model, "IC") == 0){
Graph g;
g.readGraphIC(inFile);
int n = g.getSize();
HyperGraph hg(n,k,eager_mode,epsilon,delta,do_check);
IM_ICSampler sampler(g,do_check);
if (strcmp(alg, "SRA") == 0){
hg.runMaxCover_SRA(std::bind(&IM_ICSampler::polling, &sampler, _1, _2, _3),epsilon,delta,k,t,n*1.0,1);
} else if (strcmp(alg, "SSA_z") == 0){
hg.runMaxCover_SSAz(std::bind(&IM_ICSampler::polling, &sampler, _1, _2, _3),epsilon,delta,k,t,n*1.0,1);
} else if (strcmp(alg, "SSA_mul") == 0){
double z = hg.getZ();
for (int l = floor(log2(z)); l>= 0; l--){
if (hg.runMaxCover_SSAz(std::bind(&IM_ICSampler::polling, &sampler, _1, _2, _3), epsilon,delta,k,t,n*1.0,l)){
break;
}
hg = HyperGraph(n,k,eager_mode,epsilon,delta,do_check);
}
}
} else {
printf("Incorrect model option!");
return -1;
}
} else if (strcmp(prob, "BCM") == 0) {
graph g;
g.read_graph(inFile,true);
Sampler sam(g);
init_seeds(sam);
int n = g.get_n_vertices();
HyperGraph hg(n,k,eager_mode,epsilon,delta,do_check);
if (strcmp(alg, "SRA") == 0){
hg.runMaxCover_SRA(std::bind(&Sampler::bc_polling, &sam, _1, _2, _3), epsilon,delta,k,t,n*1.0,1);
} else if (strcmp(alg, "SSA_z") == 0){
hg.runMaxCover_SSAz(std::bind(&Sampler::bc_polling, &sam, _1, _2, _3), epsilon,delta,k,t,n*1.0,1);
} else if (strcmp(alg, "SSA_mul") == 0){
double z = hg.getZ();
for (int l = floor(log2(z))-2; l>= 0; l--){
if (hg.runMaxCover_SSAz(std::bind(&Sampler::bc_polling, &sam, _1, _2, _3), epsilon,delta,k,t,n*1.0,l)){
break;
}
hg = HyperGraph(n,k,eager_mode,epsilon,delta,do_check);
}
}
} else if (strcmp(prob, "CCM") == 0) {
graph g;
g.read_graph(inFile,true);
Sampler sam(g);
init_seeds(sam);
int n = g.get_n_vertices();
HyperGraph hg(n,k,eager_mode,epsilon,delta,do_check);
if (strcmp(alg, "SRA") == 0){
hg.runMaxCover_SRA(std::bind(&Sampler::cc_polling, &sam, _1, _2, _3), epsilon,delta,k,t,n*1.0,1);
} else if (strcmp(alg, "SSA_z") == 0){
hg.runMaxCover_SSAz(std::bind(&Sampler::cc_polling, &sam, _1, _2, _3), epsilon,delta,k,t,n*1.0,1);
} else if (strcmp(alg, "SSA_mul") == 0){
double z = hg.getZ();
for (int l = floor(log2(z))-2; l>= 0; l--){
if (hg.runMaxCover_SSAz(std::bind(&Sampler::cc_polling, &sam, _1, _2, _3), epsilon,delta,k,t,n*1.0,l)){
break;
}
hg = HyperGraph(n,k,eager_mode,epsilon,delta,do_check);
}
}
} else {
cout << "Selected problem is invalid!" << endl;
}
}