-
Notifications
You must be signed in to change notification settings - Fork 0
/
undirect.cpp
87 lines (73 loc) · 2.47 KB
/
undirect.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
// VOLT: Vertex Ordering to List Triangles
// Copyright (C) 2022 Fabrice Lécuyer ([email protected])
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 or later.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details: https://www.gnu.org/licenses/
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include "utils/tools.h"
using namespace std;
// inline ul max3(ul a, ul b, ul c) { return (a >= b and a >= c) ? a : ((b >= c) ? b : c); /}
int main(int argc, char** argv){
TimeBegin()
if(argc <= 2) { // secret arg added to allow for directed cleansing
cout << "./undirect INPUT OUTPUT" << endl;
cout << "with INPUT the initial edgelist, OUTPUT the file to output the trimmed edgelist" << endl;
cout << "returns a (sorted) list of non-loop non-redundant edges (if both `a b` and `b a` existed, only `a b` is kept)" << endl;
return 1;
}
cout << "Read file " << argv[1] << endl;
ifstream filein(argv[1]);
vector<pair<ul,ul>> edges;
edges.reserve(NLINKS);
ul n=0, u, v;
intEdge e = 0;
if(argc > 3) Info("Directed graph cleansing")
while(filein >> u >> v) {
e ++;
if(u == v) continue;
if(argc == 3 and u > v) swap(u, v);
edges.push_back(make_pair(u, v));
n = max3(n, u, v);
// cout << "read " << u << " " << v << endl;
}
n++;
TimeStep("Read")
cout << "Number of nodes: " << n << endl;
cout << "Number of edges: " << e << endl;
cout << "Number of loops: " << (e - edges.size()) << endl;
cout << endl;
cout << "Sorting " << edges.size() << " edges" << endl;
sort(edges.begin(), edges.end());
TimeStep("Sort")
cout << "Write file " << argv[2] << endl;
FILE *fileout = fopen(argv[2], "w");
u = v = n + 2;
intEdge e2 = 0;
for (auto &edge : edges) {
if(edge.second == v and edge.first == u) {
// Debug(u<<" " << v)
continue;
}
e2 ++;
u = edge.first;
v = edge.second;
fprintf(fileout, "%" ULPRINTF " %" ULPRINTF "\n", u, v);
// cout << "written " << u << " " << v << endl;
}
fclose(fileout);
cout << "Output " << e2 << " unique edges" << endl;
TimeStep("Out")
TimeTotal()
return 0;
}