-
Notifications
You must be signed in to change notification settings - Fork 2
/
Query.cpp
755 lines (704 loc) · 19.4 KB
/
Query.cpp
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
#include "Query.h"
//Query::Query() {
// initFlags();
//}
//Query::Query(const char* grafile) {
// initFlags();
// ifstream in(grafile);
// if (!in) {
// cout << "Error: Cannot open " << grafile << endl;
// return;
// }
// else
// cout << "reading " << grafile << endl;
// g = Graph(in);
// in.close();
// gsize = g.num_vertices();
// initQueue();
//}
//Query::Query(const char* filestem, const char* grafile, int _r, double _ps, bool mat) {
// initFlags();
// epsilon = _r;
// preselectratio = _ps;
// ismaterialized = mat;
// string filestr(filestem);
// filestemstr = filestr;
// // init graph
// ifstream in(grafile);
// if (!in) {
// cout << "Error: Cannot open " << grafile << endl;
// return;
// }
// else
// cout << "reading " << grafile << endl;
// g = Graph(in);
// in.close();
// gsize = g.num_vertices();
// vector<string> gfilenames = makeggfilename(filestem);
// // init gates
// initGates(gfilenames[0].c_str());
// // init gategraph
// initGateGraph(gfilenames[1].c_str());
// // init gate graph's reachability indices
// string indexfile = filestr+".index";
// initIndex(indexfile.c_str());
// initQueue();
//}
Query::Query(const char* filestem, Graph& ig, int _r, double _ps, bool mat) : g(ig) {
initFlags();
epsilon = _r;
preselectratio = _ps;
ismaterialized = mat;
string filestr(filestem);
filestemstr = filestr;
// init graph
gsize = g.num_vertices();
vector<string> gfilenames = makeggfilename(filestem);
// init gates
initGates(gfilenames[0].c_str());
// init gategraph
initGateGraph(gfilenames[1].c_str());
// init gate graph's reachability indices
string indexfile = filestr+".index";
initIndex(indexfile.c_str());
initQueue();
}
//Query::Query(const char* filestem, const char* grafile, int _r) {
// epsilon = _r;
// initFlags();
// string filestr(filestem);
// filestemstr = filestr;
// // init graph
// ifstream in(grafile);
// if (!in) {
// cout << "Error: Cannot open " << grafile << endl;
// return;
// }
// else
// cout << "reading " << grafile << endl;
// g = Graph(in);
// in.close();
// gsize = g.num_vertices();
// // init gates
// string gatefile = filestr+"."+to_string(epsilon)+"gates";
// initGates(gatefile.c_str());
// // init gategraph
// string ggfile = filestr+"."+to_string(epsilon)+"gg";
// initGateGraph(ggfile.c_str());
// // init gate graph's reachability indices
// string indexfile = filestr+".index";
// initIndex(indexfile.c_str());
// initQueue();
//}
//Query::Query(const char* gatefile, const char* ggfile,
// const char* indexfile, const char* grafile) {
// initFlags();
// // init graph
// ifstream in(grafile);
// if (!in) {
// cout << "Error: Cannot open " << grafile << endl;
// return;
// }
// else
// cout << "reading " << grafile << endl;
// g = Graph(in);
// in.close();
// gsize = g.num_vertices();
// initGates(gatefile);
// initGateGraph(ggfile);
//// initIndex(indexfile);
// cout << "Init auxiliary data structures..." << endl;
// initQueue();
//}
Query::~Query() {
if (method_name!="DFS")
delete gates;
// release memory
if (ismaterialized) {
for (int i = 0; i < gsize; i++) {
if (materialized->get(i))
delete inneigs[i];
}
}
delete materialized;
cout << "reachtime=" << reachtime << endl;
cout << "average reachtime=" << (reachtime*1.0)/(1.0*100000) << endl;
}
int Query::getGateSize() const {
return gatesize;
}
string Query::getFilestem() const {
return filestemstr;
}
void Query::setMethodName(string _method_name) {
method_name = _method_name;
}
string Query::getMethodName() const {
return method_name;
}
long Query::getIndexSize() const {
if (method_name=="DFS") return 0;
long size = 0;
for (int i = 0; i < gsize; i++) {
if (method_name!="GATEDFS" && method_name!="GRAIL") {
if (indextype==0||indextype==2)
size += lin[i].size();
if (indextype==1||indextype==2)
size += lout[i].size();
if (labeltype!=0)
size += labels[i].size();
}
}
// using gate materialization
long localgatesize = 0;
if (useLocalGates || usePartialLocalGates) {
for (int i = 0; i < gsize; i++) {
localgatesize += localgates[i].size();
}
}
long multilabels = 0;
if (useMultiLabels) {
multilabels = gatesize*graillabels[0].size();
}
size += localgatesize;
size += multilabels;
return size;
}
vector<long> Query::indexSize() const {
vector<long> index; // indexsize, grailsize, inoutgates size, totalsize, inneighbors, inneitotoalsize
long indexsize=0, graillabelsize=0, inoutgatesize=0, subtotalsize=0;
long inneigsize = 0, totalsize = 0;
if (method_name=="DFS") return vector<long>(5,0);
for (int i = 0; i < gsize; i++) {
if (method_name!="GATEDFS" && method_name!="GRAIL") {
if (indextype==0||indextype==2)
indexsize += lin[i].size();
if (indextype==1||indextype==2)
indexsize += lout[i].size();
if (labeltype!=0)
indexsize += labels[i].size();
}
if (ismaterialized) {
if (materialized->get(i))
inneigsize += inneigs[i]->num_ones();
inoutgatesize += inoutgates[i][0].size()+inoutgates[i][1].size();
}
}
if (useGlobalMultiLabels) graillabelsize = dim*gsize*2;
subtotalsize = indexsize+graillabelsize+inoutgatesize;
totalsize = subtotalsize+inneigsize;
index.push_back(indexsize); index.push_back(graillabelsize); index.push_back(inoutgatesize);
index.push_back(subtotalsize);
//index.push_back(inneigsize); index.push_back(totalsize);
index.push_back(reachtime);
return index;
}
void Query::initFlags() {
gsize = 0;
gatesize = 0;
useLocalGates = false;
usePartialLocalGates = false;
useMultiLabels = false;
useTopoOrder = false;
num_bits = 1;
visitnum = 0;
ref = 0;
QueryCnt = 0;
ismaterialized = false;
useGlobalMultiLabels = false;
dim = 5;
preselectratio = 0.05;
reachtime = 0;
method_name = "DFS";
}
// init queue and basic data structure "materialized" to maintain correctness
void Query::initQueue() {
dist = vector<int>(gsize,0);
que = vector<int>(gsize,0);
visited = vector<int>(gsize,0);
materialized = new bit_vector(gsize);
}
void Query::setRadius(int _r) {
epsilon = _r;
}
int Query::getGateEdgeSize() {
return gateedgesize;
// return gategraph.num_edges();
}
vector<string> Query::makeggfilename(const char* filestem) {
cout << "preselectratio=" << preselectratio << endl;
string filestr(filestem);
int ps = (int)(preselectratio*1000);
filestr += "." + to_string(epsilon) + to_string(ps);
string gatefilename = filestr+"gates";
// std::cout << "gates file name: " << gatefilename << std::endl;
string ggfilename = filestr+"gg";
// std::cout << "gg file name: " << ggfilename << std::endl;
vector<string> result;
result.push_back(gatefilename);
result.push_back(ggfilename);
return result;
}
void Query::initGateGraph(const char* ggfilename) {
ifstream infile(ggfilename);
if (!infile) {
cout << "Error: Cannot open " << ggfilename << endl;
exit(-1);
}
gategraph = Graph(infile);
infile.close();
gateedgesize = gategraph.num_edges();
cout << "#V(gate graph)=" << gategraph.num_vertices() << " #E(gate graph)=" << gategraph.num_edges() << endl;
}
void Query::initGates(const char* gatefile) {
gates = new bit_vector(gsize);
ifstream in(gatefile);
if (!in) {
cout << "initGates Error: Cannot open " << gatefile << endl;
exit(-1);
}
else
cout << "reading " << gatefile << endl;
// fist line: the number of gates
in >> gatesize >> radius;
// cout << "radius=" << radius << endl;
num_bits = (int)ceil(log(radius+1)/log(2));
int inputval;
for (int i = 0; i < gatesize; i++) {
in >> inputval;
gates->set_one(inputval);
gatemap[inputval] = i;
}
in.close();
// displayGates(cout);
}
void Query::initIndex(const char* indexfile) {
ifstream in(indexfile);
if (!in) {
cout << "Error: Cannot open " << indexfile << endl;
exit(-1);
}
else
cout << "reading " << indexfile << endl;
int numgates=-1, begin, end;
labeltype=-1, indextype=-1;
// first line: #gates #hasLabel #indextype
in >> numgates >> labeltype >> indextype;
cout << "numgates: " << numgates << endl;
cout << "gatesize: " << gatesize << endl;
assert(numgates==gatesize);
if (indextype==0) {
lin = vector<vector<int> >(gsize,vector<int>());
}
else if (indextype==1) {
lout = vector<vector<int> >(gsize,vector<int>());
}
else if (indextype==2) {
lin = vector<vector<int> >(gsize,vector<int>());
lout = vector<vector<int> >(gsize,vector<int>());
}
int idx, vid;
string buf, inbuf, sub;
vector<int> gateindex;
for (int i = 0; i < gsize; i++) {
if (gates->get(i))
gateindex.push_back(i);
}
// process lin and lout
if (indextype != 3) {
getline(in,buf);
for (int i = 0; i < gatesize; i++) {
getline(in,buf);
// parse inlabels
// cout << "lin" << endl;
begin = buf.find(":");
end = buf.find_first_of("#");
inbuf = buf.substr(begin+2,end-begin-2);
int sid = gateindex[i];
vector<string> neighbors = Graph::split(inbuf, ' ');
// for (int j = 0; j < neighbors.size(); j++) {
// if (neighbors[j]=="") continue;
// vid = atoi(neighbors[j].c_str());
// lin[sid].push_back(gateindex[vid]);
// }
/*
buf = buf.substr(buf.find_first_of(":")+2);
// parse lin
inbuf = buf.substr(0,buf.find_first_of("#"));
while (inbuf.find(" ")!=string::npos) {
sub = inbuf.substr(0,inbuf.find(" "));
istringstream(sub) >> vid;
lin[gateindex[i]].push_back(gateindex[vid]);
inbuf.erase(0,inbuf.find(" ")+1);
}
*/
// if (indextype==0 || indextype==2)
// sort(lin[sid].begin(),lin[sid].end());
// cout << "lout" << endl;
// parse lout
// begin = end+2;
// end = buf.find_last_of("#");
// if (end-begin<=0) continue;
// buf = buf.substr(begin,end-begin);
// neighbors.clear();
// neighbors = Graph::split(buf, ' ');
for (int j = 0; j < neighbors.size(); j++) {
if (neighbors[j]=="") continue;
vid = atoi(neighbors[j].c_str());
lout[sid].push_back(gateindex[vid]);
}
/*
buf.erase(0, buf.find_first_of("#")+2);
while (buf.find(" ")!=string::npos) {
sub = buf.substr(0,buf.find(" "));
istringstream(sub) >> vid;
lout[gateindex[i]].push_back(gateindex[vid]);
buf.erase(0,buf.find(" ")+1);
}
*/
// if (indextype==1 || indextype==2)
// sort(lout[sid].begin(),lout[sid].end());
}
}
if (labeltype==0) {
in.close();
return;
}
// process labels
labels = vector<vector<int> >(gsize,vector<int>());
getline(in,buf);
for (int i = 0; i < gatesize; i++) {
getline(in,buf);
buf = buf.substr(buf.find_first_of(":")+2);
while (buf.find(" ")!=string::npos) {
sub = buf.substr(0,buf.find(" "));
istringstream(sub) >> vid;
labels[gateindex[i]].push_back(vid);
buf.erase(0,buf.find(" ")+1);
}
}
in.close();
}
//void Query::outIndex(const char* out_index_file){
// ofstream outer(out_index_file);
// for
//}
void Query::computeLocalGates(bool ispartial) {
vector<int> nodes;
if (ispartial) {
usePartialLocalGates = true;
selectPartialNodes(nodes, (int)(gsize*0.1));
}
else {
useLocalGates = true;
selectPartialNodes(nodes, gsize);
}
localgates = vector<vector<vector<int> > >(gsize,vector<vector<int> >(2,vector<int>()));
for (int i = 0; i < nodes.size(); i++) {
GraphUtil::collectInLocalGates(g, gates, nodes[i], radius, localgates[nodes[i]][0]);
GraphUtil::collectOutLocalGates(g, gates, nodes[i], radius, localgates[nodes[i]][0]);
}
}
void Query::computeMultiLabelsQuickRej(int num_labels) {
mutipleLabeling(num_labels);
}
// default strategy: randomly select #num vertices
void Query::selectPartialNodes(vector<int>& nodes, int num) {
assert(num<=gsize);
nodes.clear();
if (num == gsize) {
for (int i = 0; i < gsize; i++)
nodes.push_back(i);
return;
}
srand(time(NULL));
set<int> tmp_nodes;
set<int>::iterator sit;
while (tmp_nodes.size()<num) {
int node = rand()%gsize;
tmp_nodes.insert(node);
}
for (sit = tmp_nodes.begin(); sit != tmp_nodes.end(); sit++)
nodes.push_back(*sit);
}
// default strategy: randomly generate #num_labels DFS labels
void Query::mutipleLabeling(int num_labels) {
int index = 0;
vector<pair<int,int> > dfslabels;
graillabels = vector<vector<pair<int,int> > >(gsize,vector<pair<int,int> >());
for (int i = 0; i < num_labels; i++) {
dfslabels.clear();
// GraphUtil::randomDFSLabeling(gategraph,dfslabels);
GraphUtil::grail_labeling(g,dfslabels);
index = 0;
for (int j = 0; j < gsize; j++) {
if (gates->get(j)) {
graillabels[j].push_back(dfslabels[index]);
index++;
}
}
}
useMultiLabels = true;
}
void Query::computeTopoOrder() {
useTopoOrder = true;
GraphUtil::topological_sort(g,topoid);
}
bool Query::reach(int src, int trg) {
return GraphUtil::DFSReachCnt(g, src, trg, visited, QueryCnt);
// return GraphUtil::DFSReachVisitedNum(g,src,trg,visitnum);
}
bool Query::reachWithoutMat(int src, int trg) {
return GraphUtil::DFSReachCnt(g, src, trg, visited, QueryCnt);
// return GraphUtil::DFSReachVisitedNum(g,src,trg,visitnum);
}
bool Query::test_reach(int src, int trg) {
bool r = reach(src, trg);
bool ans = GraphUtil::DFSReach(g, src, trg);
if (r!=ans) {
cout << "###Wrong: [" << src << "] to [" << trg << "] reach = " << r << endl;
cout << "----------------------------------------------------" << endl;
displayLabelsByNode(src,cout);
displayLabelsByNode(trg,cout);
cout << "----------------------------------------------------" << endl;
// exit(0);
}
return true;
}
bool Query::test_nomreach(int src, int trg) {
bool r = reachWithoutMat(src, trg);
bool ans = GraphUtil::DFSReach(g, src, trg);
if (r!=ans) {
cout << "###Wrong: [" << src << "] to [" << trg << "] reach = " << r << endl;
cout << "----------------------------------------------------" << endl;
displayLabelsByNode(src,cout);
displayLabelsByNode(trg,cout);
cout << "----------------------------------------------------" << endl;
exit(0);
}
return true;
}
void Query::initMaterialization() {
inoutgates = vector<vector<vector<int> > >(gsize,vector<vector<int> >(2,vector<int>()));
inneigs = vector<bit_vector*>(gsize,NULL);
int pnum = (int)(gsize*0.001);
pnum = max(pnum,100);
if (gatesize>1500000) pnum=min(pnum,10);
pnum = min(gsize,pnum);
cout << "Materialize local gates pnum=" << pnum << endl;
materialization(pnum);
ismaterialized = true;
}
void Query::materialization(int num) {
cout << "Materialize top 0.1% highest indegree vertices" << endl;
selectMaterialized(num);
// cout << "Precompute inneighbors" << endl;
for (int i = 0; i < gsize; i++) {
if (materialized->get(i))
materializeInNeighbors(i); // collect paritial inneighbors and ingates
}
cout << "Precompute incoming local gates" << endl;
for (int i = 0; i < gsize; i++) {
if (gates->get(i)) continue;
precomputeGates(i,false); // collect ingates
}
cout << "Precompute outgoing local gates" << endl;
for (int i = 0; i < gsize; i++) {
if (gates->get(i)) continue;
precomputeGates(i,true); // collect outgates
}
useLocalGates = true;
// for test
#ifdef PATHTREE_DEBUG
displayInfor(cout);
#endif
}
void Query::selectMaterialized(int num) {
num = min(gsize,num);
multimap<int,int> indegmap;
int indeg;
for (int i = 0; i < gsize; i++) {
indeg = g.in_degree(i);
indegmap.insert(make_pair(indeg,i));
}
multimap<int,int>::reverse_iterator mit = indegmap.rbegin();
for (int i = 0; i < num; i++) {
materialized->set_one(mit->second);
mit++;
}
}
void Query::materializeInNeighbors(int vid) {
inneigs[vid] = new bit_vector(gsize);
QueryCnt++;
int u, val, index=0, endindex=0, nid;
EdgeList el;
EdgeList::iterator eit;
ref += radius+1;
que[0]=vid;
dist[vid]=ref;
endindex=1;
index=0;
while (index<endindex) {
u = que[index];
index++;
val = dist[u];
el = g.in_edges(u);
for (eit = el.begin(); eit != el.end(); eit++) {
nid=(*eit);
if (dist[nid]<ref) {
dist[nid]=val+1;
inneigs[vid]->set_one(nid);
/*
if (!gates->get(vid)&&gates->get(nid))
inoutgates[vid][0].push_back(nid);
*/
if (val+1-ref<radius)
que[endindex++]=nid;
}
}
}
}
// note that: using scalable version of gate graph generation, outlocalgates contains all gates within epsilon steps while inlocalgates contains all gates within epsion+1 steps
void Query::precomputeGates(int vid, bool out) {
if (gates->get(vid)) {
return;
}
int u, val, index=0, endindex=0, nid;
EdgeList el;
EdgeList::iterator eit;
ref += radius+2;
que[0]=vid;
dist[vid]=ref;
endindex=1;
index=0;
while (index<endindex) {
u = que[index];
index++;
val = dist[u];
if (out) el = g.out_edges(u);
else el = g.in_edges(u);
for (eit = el.begin(); eit != el.end(); eit++) {
nid=(*eit);
if (dist[nid]<ref) {
dist[nid]=val+1;
if (gates->get(nid)) {
if (out) inoutgates[vid][1].push_back(nid);
else inoutgates[vid][0].push_back(nid);
continue;
}
if (out) {
if (val+1-ref<radius)
que[endindex++]=nid;
}
else {
// if (val+1-ref<radius+1)
if (val+1-ref<radius)
que[endindex++]=nid;
}
}
}
}
}
void Query::displayInfor(ostream& out) {
for (int i = 0; i < gsize; i++)
displayInfor(i,out);
}
void Query::displayInfor(int vid, ostream& out) {
if (materialized->get(vid)) {
if (inneigs[vid]==NULL) {
cout << "Error: " << vid << " is NULL" << endl;
return;
}
out << "Inneigs[" << vid << "]: ";
for (int i = 0; i < gsize; i++)
if (inneigs[vid]->get(i)) cout << i << " ";
out << endl;
}
out << "InOutGates[" << vid << "]: ";
vector<int>::iterator vit;
for (vit = inoutgates[vid][0].begin(); vit != inoutgates[vid][0].end(); vit++)
out << *vit << " ";
out << " | ";
for (vit = inoutgates[vid][1].begin(); vit != inoutgates[vid][1].end(); vit++)
out << *vit << " ";
out << "#" << endl;
}
void Query::displayIndex(ostream& out) {
if (indextype==3) return;
out << "Lin and Lout Index " << endl;
for (int i = 0; i < gsize; i++) {
out << i << ": ";
if (indextype!=1) {
for (int j = 0; j < lin[i].size(); j++)
out << lin[i][j] << " ";
}
out << "# ";
if (indextype!=0) {
for (int j = 0; j < lout[i].size(); j++)
out << lout[i][j] << " ";
}
out << "#" << endl;
}
}
void Query::displayLabelsByNode(int vid, ostream& out) {
if (method_name=="GATEDFS") {
displayLocalGatesByNode(vid,cout);
return;
}
out << vid << ": [";
for (int j = 0; j < labels[vid].size()-1; j++)
out << labels[vid][j] << " ";
out << labels[vid][labels[vid].size()-1] << "]" << endl;
}
void Query::displayLabels(ostream& out) {
if (gates->num_bits_set()==0) return;
out << "Node Labels (only for gate vertices)" << endl;
for (int i = 0; i < gsize; i++) {
if (gates->get(i)) {
displayLabelsByNode(i,out);
}
}
}
void Query::displayGates(ostream& out) {
out << "Gates: ";
for (int i = 0; i < gsize; i++) {
if (gates->get(i)) {
out << i << " ";
if (i%20==0) out << endl;
}
}
out << "#" << endl;
}
void Query::displayGrailLabels(ostream& out) {
if (!useMultiLabels) return;
out << "GRAIL Labels" << endl;
for (int i = 0; i < gsize; i++) {
if (gates->get(i)) {
out << i << ": ";
for (int j = 0; j < graillabels[i].size(); j++)
out << "[" << graillabels[i][j].first << "," << graillabels[i][j].second << "] ";
out << endl;
}
}
}
void Query::displayLocalGatesByNode(int vid, ostream& out) {
if (!useLocalGates && !usePartialLocalGates) return;
cout << vid << " ";
if (gates->get(vid)) cout << "is gate node" << endl;
else cout << "is not gate node" << endl;
out << "Local Gates[";
out << vid << "]: ";
for (int j = 0; j < inoutgates[vid][0].size(); j++)
out << inoutgates[vid][0][j] << " ";
out << "# ";
for (int j = 0; j < inoutgates[vid][1].size(); j++)
out << inoutgates[vid][1][j] << " ";
out << "#" << endl;
}
void Query::displayLocalGates(ostream& out) {
if (!useLocalGates && !usePartialLocalGates) return;
out << "Local Gates" << endl;
for (int i = 0; i < gsize; i++) {
displayLocalGatesByNode(i, out);
}
}