-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathto_static.cpp
More file actions
56 lines (46 loc) · 1.53 KB
/
to_static.cpp
File metadata and controls
56 lines (46 loc) · 1.53 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
#include "binary_file_stream.h"
#include <cassert>
#include <fstream>
#include <iostream>
#include <vector>
/*
* Converts a binary graph stream to a static ascii edge list
*/
int main(int argc, char **argv) {
if (argc != 3) {
std::cout << "Incorrect number of arguments. Expected two but got " << argc - 1 << std::endl;
std::cout << "Arguments are: input_stream, output_file" << std::endl;
exit(EXIT_FAILURE);
}
std::string input = argv[1];
std::string output = argv[2];
assert(input != output);
BinaryFileStream stream(input);
std::ofstream out_file(output);
node_id_t num_nodes = stream.vertices();
long m = stream.edges();
std::vector<std::vector<bool>> adj_mat(num_nodes);
for (node_id_t i = 0; i < num_nodes; i++) adj_mat[i] = std::vector<bool>(num_nodes - i);
while (m--) {
GraphStreamUpdate upd;
stream.get_update_buffer(&upd, 1);
node_id_t src = upd.edge.src;
node_id_t dst = upd.edge.dst;
if (src > dst) std::swap(src, dst);
dst = dst - src;
adj_mat[src][dst] = !adj_mat[src][dst];
}
std::cout << "Updating adjacency matrix done. Writing static graph to file." << std::endl;
uint64_t edges = 0;
for (node_id_t i = 0; i < num_nodes; i++) {
for (node_id_t j = 0; j < num_nodes - i; j++) {
if (adj_mat[i][j]) edges++;
}
}
out_file << num_nodes << " " << edges << std::endl;
for (node_id_t i = 0; i < num_nodes; i++) {
for (node_id_t j = 0; j < num_nodes - i; j++) {
if (adj_mat[i][j]) out_file << i << "\t" << j + i << std::endl;
}
}
}