Statistics
| Branch: | Revision:

root / custompackages / graph-parser / src / main.cpp @ f9e3a1f0

History | View | Annotate | Download (2.65 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 targets_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(targets_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
    bool is_weighted_graph = true;
78
    bool targets_inclusion = true;
79
    string filepath;
80
    int input_type;
81
    string argument;
82

    
83
    if (argc >= 3) {
84
        filepath = string(argv[1]);
85
        input_type = atoi(argv[2]);
86
    }
87
    if (argc >= 4) {
88
        argument = string(argv[3]);
89
        if (argument.compare("false") == 0) {
90
            is_weighted_graph = false;
91
        }
92

    
93
        if (argc > 4) {
94
           argument = string(argv[4]);
95
            if (argument.compare("false") == 0) {
96
                targets_inclusion = false;
97
            }
98
        }
99
    }
100

    
101
    default_run(filepath, input_type, is_weighted_graph, targets_inclusion);
102

    
103
    cout << "is weighted graph  = " << is_weighted_graph << endl;
104
    return 0;
105
}