-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrb-validate.cpp
More file actions
executable file
·266 lines (239 loc) · 10.3 KB
/
rb-validate.cpp
File metadata and controls
executable file
·266 lines (239 loc) · 10.3 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <libgen.h> // basename
#include "tclap/CmdLine.h"
#include <sdsl/bit_vectors.hpp>
#include <sdsl/wavelet_trees.hpp>
#include "io.hpp"
#include "debruijn_graph_shifted.hpp"
#include "algorithm.hpp"
#include "rb-query.hpp"
#include <sys/timeb.h>
#include <random>
#include "cereal/archives/json.hpp"
struct parameters_t {
std::string input_filename = "";
std::string color_filename = "";
std::string res_dir = "";
std::string bvs_type = "";
std::string validation_type = "";
};
int getMilliCount(){
timeb tb;
ftime(&tb);
int nCount = tb.millitm + (tb.time & 0xfffff) * 1000;
return nCount;
}
int getMilliSpan(int nTimeStart){
int nSpan = getMilliCount() - nTimeStart;
if(nSpan < 0)
nSpan += 0x100000 * 1000;
return nSpan;
}
void parse_arguments(int argc, char **argv, parameters_t & params)
{
TCLAP::CmdLine cmd("Rainbowfish validate", ' ', "0.1.0");
TCLAP::UnlabeledValueArg<std::string> input_filename_arg("input", ".dbg file.", true, "", "graph_file", cmd);
TCLAP::UnlabeledValueArg<std::string> color_filename_arg("color", ".rrr file.", true, "", "color_file", cmd);
TCLAP::UnlabeledValueArg<std::string> res_dir_arg("dir", "Result directory. Should have created the directory first.", true, "", "res_dir", cmd);
//TCLAP::UnlabeledValueArg<std::string> bitvectors_type_arg("bv_type","format is like ccc, uuu, ucc, .. c=compressed, u=uncompressed. order = label, rank, eqTable", true, "", "bv_type", cmd);
TCLAP::UnlabeledValueArg<std::string> validation_type_arg("validation_type","Validation Type: Accepted values:compare, query, random-query, cosmo-query", true, "", "validation_type", cmd);
cmd.parse( argc, argv );
params.input_filename = input_filename_arg.getValue();
params.color_filename = color_filename_arg.getValue();
params.res_dir = res_dir_arg.getValue();
//params.bvs_type = bitvectors_type_arg.getValue();
params.validation_type = validation_type_arg.getValue();
std::string l,s,eq;
std::string jsonFileName = params.res_dir + "/info.json";
std::ifstream jsonFile(jsonFileName);
{
cereal::JSONInputArchive archive(jsonFile);
archive(cereal::make_nvp("label_type", l));
archive(cereal::make_nvp("select_type", s));
archive(cereal::make_nvp("eqtable_type", eq));
}
jsonFile.close();
params.bvs_type = "";
if (l == "compressed") params.bvs_type += "c";
else params.bvs_type += "u";
if (s == "compressed") params.bvs_type += "c";
else params.bvs_type += "u";
if (eq == "compressed") params.bvs_type += "c";
else params.bvs_type += "u";
std::cerr << "bvs type: " << params.bvs_type << "\n";
}
void deserialize_info(uint64_t& num_colors, uint64_t& num_edges, std::string res_dir, bool& isDynamicLblLength, uint64_t& lblFixedLength ) {
std::string jsonFileName = res_dir + "/info.json";
std::ifstream jsonFile(jsonFileName);
{
cereal::JSONInputArchive archive(jsonFile);
archive(cereal::make_nvp("num_colors", num_colors));
archive(cereal::make_nvp("num_edges", num_edges));
archive(cereal::make_nvp("is_label_dynamic", isDynamicLblLength));
archive(cereal::make_nvp("label_fixed_length", lblFixedLength));
}
jsonFile.close();
}
class MainBase {
public:
MainBase(){}
virtual void run(parameters_t& p){ std::cout<<p.bvs_type<<"\n";}
};
template <class T1, class T2, class T3>
class MainTemplatized : public MainBase {
public:
MainTemplatized(){}
void run(parameters_t& p) {
cerr << typeid(T1).name() << " " << typeid(T2).name() << " " << typeid(T3).name() << endl;
cerr << "pack-color compiled with supported colors=" << NUM_COLS << std::endl;
//ifstream input(p.input_filename, ios::in|ios::binary|ios::ate);
//Can add this to save a couple seconds off traversal - not really worth it.
cerr << "loading dbg" << std::endl;
debruijn_graph_shifted<> dbg;
load_from_file(dbg, p.input_filename);
//input.close();
cerr << "loading colors" << std::endl;
sd_vector<> colors;
load_from_file(colors, p.color_filename);
uint64_t num_colors = 0;
uint64_t num_edges = 0;
bool isDynamicLblLength = true;
uint64_t lblFixedLength = 0;
deserialize_info(num_colors, num_edges, p.res_dir, isDynamicLblLength, lblFixedLength);
cerr << "k : " << dbg.k << endl;
cerr << "num_nodes() : " << dbg.num_nodes() << endl;
cerr << "num_edges() : " << dbg.num_edges() << " or " << num_edges << endl;
cerr << "colors : " << colors.size() / dbg.size() << " or " << num_colors << endl;
cerr << "Total size : " << size_in_mega_bytes(dbg) << " MB" << endl;
cerr << "Bits per edge : " << bits_per_element(dbg) << " Bits" << endl;
cerr << "Is Label Length Dynamic? : " << isDynamicLblLength << endl;
cerr << "Label Fixed Length : " << lblFixedLength << endl;
std::string res_dir = p.res_dir;
ColorDetector<T1, T2, T3> cd(res_dir, num_colors, isDynamicLblLength, lblFixedLength);
uint64_t checkPointTime = getMilliCount();
if (p.validation_type == "compare") {
uint64_t startTime = getMilliCount();
uint64_t rbsum = 0;
uint64_t cosmosum = 0;
bool allTheSame = true;
for (uint64_t edge = 0; edge < num_edges; edge++) {
bool first = true;
for (size_t c = 0; c < num_colors; c++) {
short rb = cd.contains(c, edge);
short cosmo = colors[edge*num_colors+c];
rbsum += rb;
cosmosum += cosmo;
if (rb != cosmo) {
allTheSame = false;
if (first) {
std::cout << "rbVSvari e" <<edge << "--> ";
first = false;
}
std::cout << "c"<<c << ":" << cd.contains(c, edge) << "," << colors[edge*num_colors+c] << " ";
}
}
if (!first) std::cout << "\n";
if (edge % 10000000 == 0) {
std::cerr << getMilliSpan(checkPointTime) << " ms : " << edge << " out of " << num_edges << " edges were compared.\n";
checkPointTime = getMilliCount();
}
}
std::cerr << "rbsum: " << rbsum << " cosmosum: "<<cosmosum;
std::cerr << "\n\n" << getMilliSpan(startTime) << " ms : Time for total of " << num_edges * num_colors << " comparisons.\n";
if (allTheSame) std::cerr<<" HURRAAAAY! Validation Test Passed.\n";
else std::cerr<<"NOT GOOD! Validation Test Failed.\n";
}
if (p.validation_type == "query" || p.validation_type == "random-query") {
bool temp;
uint64_t totalsetbit = 0;
uint64_t rainbow_st = getMilliCount();
checkPointTime = getMilliCount();
if (p.validation_type == "random-query") {
std::random_device rd;
std::mt19937_64 gen(rd());
std::uniform_int_distribution<unsigned long long> dis;
uint64_t *edgeIdx = new uint64_t[num_edges];
uint64_t *colorIdx = new uint64_t[num_colors];
for (uint64_t edge = 0; edge < num_edges; edge++) {
edgeIdx[edge] = dis(gen)%num_edges;
}
for (size_t c = 0; c < num_colors; c++) {
colorIdx[c] = rand() % num_colors;
}
for (uint64_t edge = 0; edge < num_edges; edge++) {
for (size_t c = 0; c < num_colors; c++) {
temp = cd.contains(colorIdx[c], edgeIdx[edge]);
totalsetbit += temp;
}
if (edge % 10000000 == 0) {
std::cerr << "rb " << getMilliSpan(checkPointTime)/1000 << " s : " << edge << " of " << num_edges << "\n";
checkPointTime = getMilliCount();
}
// std::cerr << "rb " << getMilliSpan(checkPointTime)/1000 << " s : " << num_edges << " for color " <<c< "\n";
// checkPointTime = getMilliCount();
// }
}
}
for (uint64_t edge = 0; edge < num_edges; edge++) {
for (size_t c = 0; c < num_colors; c++) {
temp = cd.contains(c, edge);
totalsetbit += temp;
}
if (edge % 10000000 == 0) {
std::cerr << "rb " << getMilliSpan(checkPointTime)/1000 << " s : " << edge << " of " << num_edges << "\n";
//cd.printStatistics();
checkPointTime = getMilliCount();
}
}
std::cerr<<"\n\n\n";
rainbow_st = getMilliSpan(rainbow_st);
std::cerr << "\n\n Total of " << num_edges * num_colors << " comparisons with "<<totalsetbit<<" set bits:\n";
std::cerr << " " << rainbow_st << " ms : RAINBOWFISH\n";
cd.printStatistics();
}
if (p.validation_type == "cosmo-query") {
uint64_t vari_st = getMilliCount();
uint64_t totalsetbit = 0;
bool temp;
checkPointTime = getMilliCount();
for (uint64_t edge = 0; edge < dbg.num_edges(); edge++) {
for (size_t c = 0; c < 1000; c++) {
temp = colors[edge*num_colors+c];
totalsetbit += temp;
}
// if (edge % 100000 == 0) {
// std::cerr << "v " << getMilliSpan(checkPointTime)/1000 << " s : "<< edge << " of " << num_edges <<"\n";
// checkPointTime = getMilliCount();
// }
}
std::cerr<<"\n\n\n";
vari_st = getMilliSpan(vari_st);
std::cerr << "\n\n Total of " << num_edges * num_colors << " comparisons with "<<totalsetbit<<" set bits:\n";
//std::cerr << " " << rainbow_st << " ms : RAINBOWFISH\n";
std::cerr << " " << vari_st << " ms : VARI\n";
}
}
};
template class MainTemplatized<RBVec, RBVec, RBVec>;
template class MainTemplatized<RBVecCompressed, RBVecCompressed, RBVecCompressed>;
template class MainTemplatized<RBVec, RBVecCompressed, RBVecCompressed>;
template class MainTemplatized<RBVec, RBVec, RBVecCompressed>;
int main(int argc, char* argv[]) {
parameters_t p;
parse_arguments(argc, argv, p);
MainBase* m{nullptr};
if (p.bvs_type == "ccc")
m = new MainTemplatized<RBVecCompressed, RBVecCompressed, RBVecCompressed>();
else if (p.bvs_type == "uuu")
m = new MainTemplatized<RBVec, RBVec, RBVec>();
else if (p.bvs_type == "ucc")
m = new MainTemplatized<RBVec, RBVecCompressed, RBVecCompressed>();
else if (p.bvs_type == "uuc")
m = new MainTemplatized<RBVec, RBVec, RBVecCompressed>();
if (m)
m->run(p);
else std::cout<<"Initialization failed.\n";
}