Statistics
| Branch: | Revision:

root / custompackages / graph-parser / src / main.cpp @ 4ca27bae

History | View | Annotate | Download (2.7 KB)

1 f9e3a1f0 Quynh PX Nguyen
#include <cstdlib>
2 af008982 Quynh PX Nguyen
#include <iostream>
3 f9e3a1f0 Quynh PX Nguyen
#include <string>
4 04a9ef10 Quynh PX Nguyen
#include "parser.h"
5 6a12e353 Quynh PX Nguyen
#include "utility.h"
6 c6961065 Quynh PX Nguyen
#include "centrality.h"
7 ee0dd796 Quynh PX Nguyen
#include "bi_connected_components.h"
8 cb770240 Quynh PX Nguyen
#include "graph_manager.h"
9 04a9ef10 Quynh PX Nguyen
10 162e1bda Quynh PX Nguyen
void testHeuristic(string filepath) {
11 cb770240 Quynh PX Nguyen
    GraphManager gm;
12 162e1bda Quynh PX Nguyen
    readEdgeFileGraphManager(filepath, gm);
13 437fd680 Quynh PX Nguyen
    BiConnectedComponents bcc = BiConnectedComponents(gm);
14 162e1bda Quynh PX Nguyen
    bcc.run();
15
    bcc.print();
16
17
    bcc.write_all_betweenness_centrality("../output/simple.edges");
18 ee0dd796 Quynh PX Nguyen
    cout << "DONE" << endl;
19 cb770240 Quynh PX Nguyen
}
20 ee0dd796 Quynh PX Nguyen
21 162e1bda Quynh PX Nguyen
void testGraphManager(string filepath) {
22 cb770240 Quynh PX Nguyen
    GraphManager gm;
23 162e1bda Quynh PX Nguyen
    readEdgeFileGraphManager(filepath, gm);
24 437fd680 Quynh PX Nguyen
    gm.print();
25 ee0dd796 Quynh PX Nguyen
}
26 af008982 Quynh PX Nguyen
27 f9e3a1f0 Quynh PX Nguyen
void default_run(string filepath, int input_type, bool is_weighted_graph, bool targets_inclusion) {
28 162e1bda Quynh PX Nguyen
    // 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 f9e3a1f0 Quynh PX Nguyen
    GraphManager gm(is_weighted_graph);
34 162e1bda Quynh PX Nguyen
35 f9e3a1f0 Quynh PX Nguyen
    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 162e1bda Quynh PX Nguyen
45 f9e3a1f0 Quynh PX Nguyen
    gm.print();
46 162e1bda Quynh PX Nguyen
47 f9e3a1f0 Quynh PX Nguyen
    BiConnectedComponents bcc = BiConnectedComponents(gm);
48
    bcc.run();
49 d5b7a27f Quynh PX Nguyen
50 f9e3a1f0 Quynh PX Nguyen
    // Calculate Betweenness Centrality
51
    cout << "Calculate Betweenness Centrality\n";
52
    bcc.CalculateBetweennessCentrality(targets_inclusion);
53
    // bcc.print();
54 d5b7a27f Quynh PX Nguyen
55 f9e3a1f0 Quynh PX Nguyen
    string filename;
56
    string ext;
57
    helper::get_file_name_and_extension(filepath, filename, ext);
58 d5b7a27f Quynh PX Nguyen
59 f9e3a1f0 Quynh PX Nguyen
    string out_filepath = "../output/" + filename;
60
    if (is_weighted_graph) {
61
        out_filepath += "_weighted.out";
62
    }
63
    else {
64
        out_filepath += "_unweighted.out";
65 162e1bda Quynh PX Nguyen
    }
66 f9e3a1f0 Quynh PX Nguyen
    bcc.write_all_betweenness_centrality(out_filepath);
67 162e1bda Quynh PX Nguyen
}
68 04a9ef10 Quynh PX Nguyen
69 162e1bda Quynh PX Nguyen
void old_main_code() {
70
    string simpleGraphfilepath = "../input/simple.edges";
71
    testGraphManager(simpleGraphfilepath);
72 04a9ef10 Quynh PX Nguyen
73 162e1bda Quynh PX Nguyen
    testHeuristic(simpleGraphfilepath);
74
}
75
76 d5b7a27f Quynh PX Nguyen
int main(int argc, char * argv[]) {
77 4ca27bae Quynh PX Nguyen
    // Example: ./main simple.edges 1 true true
78
79 d5b7a27f Quynh PX Nguyen
    bool is_weighted_graph = true;
80
    bool targets_inclusion = true;
81 f9e3a1f0 Quynh PX Nguyen
    string filepath;
82
    int input_type;
83
    string argument;
84 d5b7a27f Quynh PX Nguyen
85 f9e3a1f0 Quynh PX Nguyen
    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 d5b7a27f Quynh PX Nguyen
        if (argument.compare("false") == 0) {
92
            is_weighted_graph = false;
93
        }
94
95 f9e3a1f0 Quynh PX Nguyen
        if (argc > 4) {
96
           argument = string(argv[4]);
97 d5b7a27f Quynh PX Nguyen
            if (argument.compare("false") == 0) {
98
                targets_inclusion = false;
99
            }
100
        }
101
    }
102
103 f9e3a1f0 Quynh PX Nguyen
    default_run(filepath, input_type, is_weighted_graph, targets_inclusion);
104 cb770240 Quynh PX Nguyen
105 d5b7a27f Quynh PX Nguyen
    cout << "is weighted graph  = " << is_weighted_graph << endl;
106 af008982 Quynh PX Nguyen
    return 0;
107
}