root / custompackages / graph-parser / src / main.cpp @ 33e5ad95
History | View | Annotate | Download (2.71 KB)
1 |
#include <cstdlib> |
---|---|
2 |
#include <iostream> |
3 |
#include <string> |
4 |
#include "parser.h" |
5 |
#include "utility.h" |
6 |
#include "centrality.h" |
7 |
#include "bi_connected_components.h" |
8 |
#include "graph_manager.h" |
9 |
|
10 |
void testHeuristic(string filepath) { |
11 |
GraphManager gm; |
12 |
readEdgeFileGraphManager(filepath, gm); |
13 |
BiConnectedComponents bcc = BiConnectedComponents(gm); |
14 |
bcc.run(); |
15 |
bcc.print(); |
16 |
|
17 |
bcc.write_all_betweenness_centrality("../output/simple.edges");
|
18 |
cout << "DONE" << endl;
|
19 |
} |
20 |
|
21 |
void testGraphManager(string filepath) { |
22 |
GraphManager gm; |
23 |
readEdgeFileGraphManager(filepath, gm); |
24 |
gm.print(); |
25 |
} |
26 |
|
27 |
void default_run(string filepath, int input_type, bool is_weighted_graph, bool endpoints_inclusion) { |
28 |
// input_files = [(filepath, input_type)]
|
29 |
// input_type = 1 ==> edges file
|
30 |
// input_type = 2 ==> simple json file
|
31 |
// input_type = 3 ==> complex json file
|
32 |
|
33 |
GraphManager gm(is_weighted_graph); |
34 |
|
35 |
if (input_type == 1) { |
36 |
readEdgeFileGraphManager(filepath, gm); |
37 |
} |
38 |
else if (input_type == 2) { |
39 |
readJsonGraphManager(filepath, gm); |
40 |
} |
41 |
else if (input_type == 3) { |
42 |
readComplexJsonGraphManager(filepath, gm); |
43 |
} |
44 |
|
45 |
gm.print(); |
46 |
|
47 |
BiConnectedComponents bcc = BiConnectedComponents(gm); |
48 |
bcc.run(); |
49 |
|
50 |
// Calculate Betweenness Centrality
|
51 |
cout << "Calculate Betweenness Centrality\n";
|
52 |
bcc.CalculateBetweennessCentrality(endpoints_inclusion); |
53 |
// bcc.print();
|
54 |
|
55 |
string filename;
|
56 |
string ext;
|
57 |
helper::get_file_name_and_extension(filepath, filename, ext); |
58 |
|
59 |
string out_filepath = "../output/" + filename; |
60 |
if (is_weighted_graph) {
|
61 |
out_filepath += "_weighted.out";
|
62 |
} |
63 |
else {
|
64 |
out_filepath += "_unweighted.out";
|
65 |
} |
66 |
bcc.write_all_betweenness_centrality(out_filepath); |
67 |
} |
68 |
|
69 |
void old_main_code() {
|
70 |
string simpleGraphfilepath = "../input/simple.edges"; |
71 |
testGraphManager(simpleGraphfilepath); |
72 |
|
73 |
testHeuristic(simpleGraphfilepath); |
74 |
} |
75 |
|
76 |
int main(int argc, char * argv[]) { |
77 |
// Example: ./main simple.edges 1 true true
|
78 |
|
79 |
bool is_weighted_graph = true; |
80 |
bool endpoints_inclusion = true; |
81 |
string filepath;
|
82 |
int input_type;
|
83 |
string argument;
|
84 |
|
85 |
if (argc >= 3) { |
86 |
filepath = string(argv[1]); |
87 |
input_type = atoi(argv[2]);
|
88 |
} |
89 |
if (argc >= 4) { |
90 |
argument = string(argv[3]); |
91 |
if (argument.compare("false") == 0) { |
92 |
is_weighted_graph = false;
|
93 |
} |
94 |
|
95 |
if (argc > 4) { |
96 |
argument = string(argv[4]); |
97 |
if (argument.compare("false") == 0) { |
98 |
endpoints_inclusion = false;
|
99 |
} |
100 |
} |
101 |
} |
102 |
|
103 |
default_run(filepath, input_type, is_weighted_graph, endpoints_inclusion); |
104 |
|
105 |
cout << "is weighted graph = " << is_weighted_graph << endl;
|
106 |
return 0; |
107 |
} |