-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_pch.cpp
More file actions
133 lines (131 loc) · 4.12 KB
/
Copy pathbuild_pch.cpp
File metadata and controls
133 lines (131 loc) · 4.12 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
#include "build_pch.hpp"
#include "dijkstra.hpp"
#include "query.hpp"
int main(int argc, char *argv[]) {
if (argc < 3) {
fprintf(stderr,
"WeightedGraph only\n"
"Usage: %s [-i input_graph]\n"
"Options:\n"
"\t-o,\toutput_ch_graph\n"
"\t-p,\tmax_pop_count\n"
"\t-s,\tselect fraction\n"
"\t-t,\ts-t query verify numn"
"\t-q,\tsssp query verify num\n"
"\t-b,\tdegree bound\n"
"\t-d,\tprint per round detail\n",
argv[0]);
return 0;
}
char c;
int max_pop_count = 500;
int bidirect_verify_num = 0;
int sssp_verify_num = 0;
int degree_bound = 0;
bool degree_bounded = false, print_detail = false, write_ch = false;
double sample_bound = 1;
while ((c = getopt(argc, argv, "i:o:p:s:t:q:b:d")) != -1) {
switch (c) {
case 'i':
INPUT_FILEPATH = optarg;
break;
case 'o':
write_ch= true;
OUTPUT_FILEPATH = optarg;
break;
case 'p':
max_pop_count = atol(optarg);
if (max_pop_count < 0) {
fprintf(stderr, "Error: max_pop_count must be non negative\n");
exit(EXIT_FAILURE);
}
break;
case 's':
sample_bound = atof(optarg);
if (sample_bound <= 0 || sample_bound >1) {
fprintf(stderr, "Error: selection_fraction must be larger than 0 and smaller than or equal to 1\n");
exit(EXIT_FAILURE);
}
break;
case 't':
bidirect_verify_num = atol(optarg);
if (bidirect_verify_num < 0) {
fprintf(stderr, "Error: bidirect_verify_num must be non negative\n");
exit(EXIT_FAILURE);
}
break;
case 'q':
sssp_verify_num = atol(optarg);
if (sssp_verify_num < 0) {
fprintf(stderr, "Error: sssp_verify_num must be non negative\n");
exit(EXIT_FAILURE);
}
break;
case 'b':
degree_bounded = true;
degree_bound = atol(optarg);
if (degree_bound < 0) {
fprintf(stderr, "Error: degree_bound must be non negative\n");
exit(EXIT_FAILURE);
}
break;
case 'd':
print_detail = true;
break;
default:
fprintf(stderr, "Error: Unknown option %c\n", optopt);
exit(EXIT_FAILURE);
}
}
Graph origin_graph = read_graph(INPUT_FILEPATH);
PCH *solver =
new PCH(origin_graph, max_pop_count, degree_bounded, degree_bound, sample_bound, print_detail);
PchGraph contracted_graph = solver->createContractionHierarchy();
delete (solver);
PchQuery query(contracted_graph, origin_graph);
ofstream ofs("pch.tsv", ios::app);
ofs << fixed << setprecision(6);
printf("Start query\n");
query.make_inverse();
for (int i = 0; i < bidirect_verify_num; i++) {
NodeId s = hash32(i) % origin_graph.n;
NodeId t = hash32(i + s) % origin_graph.n;
internal::timer tm;
auto [d, itr] = query.stQuery(s, t);
tm.stop();
internal::timer tm2;
auto [exp_dist, itr2] = query.stVerifier(s, t);
tm2.stop();
if (exp_dist != d) {
printf("Error: s: %u, t: %u, output_dist: %u, exp_dist: %u\n", s, t, d,
exp_dist);
abort();
}
printf("s: %u, t: %u, itr: %u, d: %u\n", s, t, itr, d);
ofs << s << '\t' << t << '\t' << itr << '\t' << itr2 << '\t' << d << '\t'
<< tm.total_time() << '\t' << tm2.total_time() << '\n';
}
for (int i = 0; i < sssp_verify_num; i++) {
NodeId s = hash32(i) % origin_graph.n;
internal::timer tm;
auto dist = query.ssspQuery(s);
tm.stop();
printf("%d SSSP query: s: %u\n", i, s);
internal::timer tm2;
auto exp_dist = query.ssspVerifier(s);
tm2.stop();
if (exp_dist != dist) {
for (size_t i = 0; i < dist.size(); i++) {
if (dist[i] != exp_dist[i]) {
printf("output_dist[%zu]: %u, exp_dist[%zu]: %u\n", i, dist[i], i,
exp_dist[i]);
}
}
abort();
}
ofs << s << '\t' << tm.total_time() << '\t' << tm2.total_time() << '\n';
}
ofs.close();
if(write_ch)write_pbbs_format(contracted_graph, OUTPUT_FILEPATH);
return 0;
}