-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
133 lines (105 loc) · 3.3 KB
/
main.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
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include "Graph.hpp"
#include "io.hpp"
#include "algorithms.hpp"
#include "splicing.hpp"
using namespace std;
int main (int argc, char * argv[]) {
// --- Default parameters ---
string nodesFilename = "nodes.csv";
string edgesFilename = "edges.csv";
string basename = "";
int nodeFilter = 0;
int edgeFilter = 0;
int seed = time(0);
bool optimizeComponents = false;
// --- Arguments parsing ---
for (int idx=1 ; idx<argc ; idx++) {
if (argv[idx][0] == '-') {
switch (argv[idx][1]) {
case 'n':
nodesFilename = string(argv[++idx]);
break;
case 'e':
edgesFilename = string(argv[++idx]);
break;
case 'b':
basename = string(argv[++idx]);
break;
case 'N':
nodeFilter = atoi(argv[++idx]);
break;
case 'E':
edgeFilter = atoi(argv[++idx]);
break;
case 'o':
optimizeComponents = true;
break;
case 'r':
seed = atoi(argv[++idx]);
break;
default:
break;
}
}
}
// Init random generator
srand(seed);
// --- Loading ---
cout << endl << "--- Loading ---" << endl;
ifstream nodesFile (nodesFilename.c_str());
if (!nodesFile) {
cerr << "The file " << nodesFilename << " seems to be missing." << endl;
return 1;
}
ifstream edgesFile (edgesFilename.c_str());
if (!edgesFile) {
cerr << "The file " << edgesFilename << " seems to be missing." << endl;
return 1;
}
Graph<Node> graph = load_graph(nodesFile, edgesFile);
cout << graph.nodes.size() << " nodes loaded " << endl;
// --- Algorithms ---
cout << endl << "--- Run algorithms ---" << endl;
cout << "-> BFS..." << endl;
vector<int> bfs = BFS (graph);
cout << "-> Contraction..." << endl;
Graph<MetaNode> contracted = contract (graph, bfs);
cout << contracted.nodes.size() << " nodes in the contracted graph" << endl;
cout << contracted.getEdgesNb() << " edges in the contracted graph" << endl;
cout << "-> Absorb fingers..." << endl;
contracted = absorbFingers (contracted);
cout << contracted.nodes.size() << " nodes in the contracted graph" << endl;
cout << contracted.getEdgesNb() << " edges in the contracted graph" << endl;
cout << endl << "--- Filtering ---" << endl;
cout << "-> Filtering nodes..." << endl;
Graph<MetaNode> filtered = filterNodes (contracted, nodeFilter);
cout << filtered.nodes.size() << " nodes in the filtered graph" << endl;
cout << "-> Filtering edges..." << endl;
filtered = filterEdges (filtered, nodeFilter, graph.nodes.size());
cout << filtered.getEdgesNb() << " edges in the filtered graph" << endl;
// --- Splicing ---
cout << endl << "--- Splicing ---" << endl;
Graph<MetaNode> spliced = splice (filtered, false);
// --- Output ---
cout << endl << "--- Saving results ---" << endl;
cout << "-> Saving components" << endl;
stringstream ss;
ss << basename << ".components.csv";
ofstream outStream (ss.str());
ifstream inStream (nodesFilename);
save_componants (spliced, graph, inStream, outStream);
cout << "-> Saving meta graph" << endl;
stringstream nodes;
stringstream edges;
nodes << basename << ".metaNodes.csv";
edges << basename << ".metaEdges.csv";
ofstream nodesStream (nodes.str());
ofstream edgesStream (edges.str());
save_metagraph (spliced, nodesStream, edgesStream);
cout << endl << "--- Program ended ---" << endl << endl;
return 0;
}