Revision f9e3a1f0 custompackages/graph-parser/src/main.cpp

View differences:

custompackages/graph-parser/src/main.cpp
1
#include <cstdlib>
1 2
#include <iostream>
3
#include <string>
2 4
#include "parser.h"
3 5
#include "utility.h"
4 6
#include "centrality.h"
......
22 24
    gm.print();
23 25
}
24 26

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

  
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));
33
    GraphManager gm(is_weighted_graph);
37 34

  
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
        }
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
    }
53 44

  
54
        gm.print();
45
    gm.print();
55 46

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

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

  
64
        string filename;
65
        string ext;
66
        helper::get_file_name_and_extension(filepath, filename, ext);
55
    string filename;
56
    string ext;
57
    helper::get_file_name_and_extension(filepath, filename, ext);
67 58

  
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);
59
    string out_filepath = "../output/" + filename;
60
    if (is_weighted_graph) {
61
        out_filepath += "_weighted.out";
62
    }
63
    else {
64
        out_filepath += "_unweighted.out";
76 65
    }
66
    bcc.write_all_betweenness_centrality(out_filepath);
77 67
}
78 68

  
79 69
void old_main_code() {
......
86 76
int main(int argc, char * argv[]) {
87 77
    bool is_weighted_graph = true;
88 78
    bool targets_inclusion = true;
79
    string filepath;
80
    int input_type;
81
    string argument;
89 82

  
90
    if (argc >= 2) {
91
        string argument(argv[1]);
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]);
92 89
        if (argument.compare("false") == 0) {
93 90
            is_weighted_graph = false;
94 91
        }
95 92

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

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

  
106 103
    cout << "is weighted graph  = " << is_weighted_graph << endl;
107 104
    return 0;

Also available in: Unified diff