-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrandom.cpp
More file actions
134 lines (113 loc) · 3.44 KB
/
random.cpp
File metadata and controls
134 lines (113 loc) · 3.44 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 <algorithm>
#include <cassert>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <unordered_map>
#include <unistd.h>
using namespace std;
//#define DEBUG
const int maxlen = 1000;
char in_filename[maxlen];
// Define standard values for parameters
bool approx_reconstr_err = false; // If true, use approximation when computing the reconstruction error
bool do_queries = true; // If true, run queries.
int param_k = 18; // Number of supernodes at the end
#include "grass.h"
#include "graph.h"
/*
* Print usage on stderr
*
*/
void usage(char *binary_name) {
fprintf(stderr, "Usage: %s [-a] [-h] [-k INT] [EDGE_FILE]\n", binary_name);
fprintf(stderr, " -a : use approximation when computing the reconstruction error.\n");
fprintf(stderr, " -h : print usage and exit.\n");
fprintf(stderr, " -k INT: number of supernodes of the final summary. Must be positive.\n");
fprintf(stderr, " -q: don't run queries (optional).\n");
}
/*
* Parse command line arguments
*
* -a : use approximation when computing the reconstruction error.
* -h : print usage and exit.
* -k INT: number of supernodes of the final summary.
*
*/
void parse_cmd_args(int argc, char* argv[]) {
int opt;
extern char *optarg;
extern int optind;
while ((opt = getopt(argc, argv, "ahk:")) != -1) {
switch (opt) {
case 'a':
approx_reconstr_err = true;
break;
case 'h':
usage(argv[0]);
exit(0);
break;
case 'k':
param_k = atoi(optarg);
if (param_k <= 0) {
fprintf(stderr, "Number of supernodes must be positive\n");
usage(argv[0]);
exit(1);
}
break;
case 'q':
do_queries = false;
break;
default:
fprintf(stderr, "Wrong option.\n");
usage(argv[0]);
exit(1);
}
}
if (optind < argc) {
strcpy(in_filename, argv[optind]);
printf("Input file = %s\n", in_filename);
} else {
printf("Input file = stdin\n");
}
printf("param_k = %i, approx_reconstr_err= %i\n", param_k, approx_reconstr_err);
}
/*
* Main function
*/
int main(int argc, char* argv[]) {
setbuf(stdout, NULL);
// Parse command line arguments
parse_cmd_args(argc, argv);
// Initialize random generator
srand(time(NULL));
// Read input graph
read_graph();
// Save start time. The steady clock is guaranteed to be monotonic
auto start = std::chrono::steady_clock::now();
// Run the actual algorithm to build the summary
random_summary(param_k);
// Save end time
auto end = std::chrono::steady_clock::now();
// Compute elapsed time
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
printf("Elapsed time: %lf\n", elapsed.count() / 1000.0);
// Analyze the summary and collect the statistics (also print some)
vector<double> stats = analyze_summary(approx_reconstr_err, do_queries);
// Print on stderr info and stats about the graph and the summary in a CSV format
fprintf(stderr, "random, %s, %d, %d, %lf, %lf, %lld, %d, %d", in_filename, n, num_edges,
avg_deg, avg_dens, triangles, param_k, approx_reconstr_err);
for (double stat : stats) {
fprintf(stderr, ", %lf", stat);
}
fprintf(stderr, ", %lf", elapsed.count() / 1000.0);
fprintf(stderr, "\n");
printf("\nDone\n");
return 0;
}