Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (3.09 KB)

1
#include <iostream>
2
#include "parser.h"
3
#include "utility.h"
4
#include "centrality.h"
5
#include "bi_connected_components.h"
6
#include "graph_manager.h"
7

    
8
void testHeuristic(string filepath) {
9
    GraphManager gm;
10
    readEdgeFileGraphManager(filepath, gm);
11
    BiConnectedComponents bcc = BiConnectedComponents(gm);
12
    bcc.run();
13
    bcc.print();
14

    
15
    bcc.write_all_betweenness_centrality("../output/simple.edges");
16
    cout << "DONE" << endl;
17
}
18

    
19
void testGraphManager(string filepath) {
20
    GraphManager gm;
21
    readEdgeFileGraphManager(filepath, gm);
22
    gm.print();
23
}
24

    
25
void default_run(bool is_weighted_graph, bool targets_inclusion) {
26
    // input_files = [(filepath, input_type)]
27
    // input_type = 1 ==> edges file
28
    // input_type = 2 ==> simple json file
29
    // input_type = 3 ==> complex json file
30

    
31
    std::list< std::tuple<string, int> > input_files;
32
    input_files.push_back(std::make_tuple("../input/simple.edges", 1));
33
    input_files.push_back(std::make_tuple("../input/ninux_unweighted_connected.edges", 1));
34
    input_files.push_back(std::make_tuple("../input/ninux_30_1.edges", 1));
35
    input_files.push_back(std::make_tuple("../input/olsr-netjson.json", 2));
36
    input_files.push_back(std::make_tuple("../input/jsoninfo_topo.json", 3));
37

    
38
    for (auto input : input_files) {
39
        string filepath = std::get<0>(input);
40
        int input_type = std::get<1>(input);
41

    
42
        GraphManager gm(is_weighted_graph);
43

    
44
        if (input_type == 1) {
45
            readEdgeFileGraphManager(filepath, gm);
46
        }
47
        else if (input_type == 2) {
48
            readJsonGraphManager(filepath, gm);
49
        }
50
        else if (input_type == 3) {
51
            readComplexJsonGraphManager(filepath, gm);
52
        }
53

    
54
        gm.print();
55

    
56
        BiConnectedComponents bcc = BiConnectedComponents(gm);
57
        bcc.run();
58

    
59
        // Calculate Betweenness Centrality
60
        cout << "Calculate Betweenness Centrality\n";
61
        bcc.CalculateBetweennessCentrality(targets_inclusion);
62
        // bcc.print();
63

    
64
        string filename;
65
        string ext;
66
        helper::get_file_name_and_extension(filepath, filename, ext);
67

    
68
        string out_filepath = "../output/" + filename;
69
        if (is_weighted_graph) {
70
            out_filepath += "_weighted.out";
71
        }
72
        else {
73
            out_filepath += "_unweighted.out";
74
        }
75
        bcc.write_all_betweenness_centrality(out_filepath);
76
    }
77
}
78

    
79
void old_main_code() {
80
    string simpleGraphfilepath = "../input/simple.edges";
81
    testGraphManager(simpleGraphfilepath);
82

    
83
    testHeuristic(simpleGraphfilepath);
84
}
85

    
86
int main(int argc, char * argv[]) {
87
    bool is_weighted_graph = true;
88
    bool targets_inclusion = true;
89

    
90
    if (argc >= 2) {
91
        string argument(argv[1]);
92
        if (argument.compare("false") == 0) {
93
            is_weighted_graph = false;
94
        }
95

    
96
        if (argc > 2) {
97
           argument = string(argv[2]);
98
            if (argument.compare("false") == 0) {
99
                targets_inclusion = false;
100
            }
101
        }
102
    }
103

    
104
    default_run(is_weighted_graph, targets_inclusion);
105

    
106
    cout << "is weighted graph  = " << is_weighted_graph << endl;
107
    return 0;
108
}