Revision 162e1bda custompackages/graph-parser/src/main.cpp

View differences:

custompackages/graph-parser/src/main.cpp
5 5
#include "bi_connected_components.h"
6 6
#include "graph_manager.h"
7 7

  
8

  
9
void handleSimpleGraph() {
10
    /* I don't understand the output. Why there are 8 vertices?
11
        Simple graph
12
        0
13
        1
14
        2
15
        3
16
        4
17
        5
18
        6
19
        7
20
        8
21
    */
22
    typedef boost::adjacency_list<> G;
23
    G a;
24
    {
25
        boost::graph_traits<G>::vertex_descriptor v, u, t;
26
        u = vertex(1, a);
27
        v = vertex(8, a);
28
        // t = vertex(5, a);
29
        add_edge(u, v, a);
30
        // add_edge(u, t, a);
31
    }
32

  
33
    std::set<typename boost::graph_traits<G>::vertex_descriptor> av;
34
    cout << "Simple graph" << endl;
35
    BGL_FORALL_VERTICES_T(v, a, G) {
36
        cout << v << endl;
37
    }
38
}
39
void handleSimpleInput(string filePath) {
40
    // Read the input.edges
41
    Graph g;
42
    readEdgeFile(filePath, g);
43

  
44
    cout << "Finish creating graph" << endl;
45

  
46
    simpleBetweennessCentrality(g, "edge_list");
47
}
48

  
49
void handleJsonInput(string filePath) {
50
    Graph g;
51
    readJson(filePath, g);
52
    outops::operator<<(cout, g);
53

  
54
    // Applying the betweenness centrality
55
    simpleBetweennessCentrality(g, "json_olsr");
56

  
57
    cout << "Done with Betweenness Centrality" << endl;
58
}
59

  
60
void handleComplexJsonInput(string filePath) {
61
    Graph g;
62
    readComplexJson(filePath, g);
63
    outops::operator<<(cout, g);
64

  
65
    // Applying the betweenness centrality
66
    simpleBetweennessCentrality(g, "json_topology");
67

  
68
    cout << "Done with Betweenness Centrality" << endl;
69
}
70

  
71
void testHeuristic(string filePath) {
8
void testHeuristic(string filepath) {
72 9
    GraphManager gm;
73
    readEdgeFileGraphManager(filePath, gm);
74
    gm.print();
10
    readEdgeFileGraphManager(filepath, gm);
75 11
    BiConnectedComponents bcc = BiConnectedComponents(gm);
76
    cout << bcc;
12
    bcc.run();
13
    bcc.print();
14

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

  
80
void testGraphManager(string filePath) {
19
void testGraphManager(string filepath) {
81 20
    GraphManager gm;
82
    readEdgeFileGraphManager(filePath, gm);
21
    readEdgeFileGraphManager(filepath, gm);
83 22
    gm.print();
84 23
}
85 24

  
86
int main(int, char *[]) {
87
//    string edgeFilePath = "../input/ninux_30_1.edges";
88
//    testHeuristic(edgeFilePath);
89
//    handleSimpleInput(edgeFilePath);
90
//
91
//    string jsonFilePath = "../input/olsr-netjson.json";
92
//    handleJsonInput(jsonFilePath);
93
//
94
//    string complexJsonFilePath = "../input/jsoninfo_topo.json";
95
//    handleComplexJsonInput(complexJsonFilePath);
25
void default_run() {
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/ninux_unweighted_connected.edges", 1));
33
    // input_files.push_back(std::make_tuple("../input/simple.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
        GraphManager gm;
42
        if (input_type == 1) {
43
            readEdgeFileGraphManager(filepath, gm);
44
        }
45
        else if (input_type == 2) {
46
            readJsonGraphManager(filepath, gm);
47
        }
48
        else if (input_type == 3) {
49
            readComplexJsonGraphManager(filepath, gm);
50
        }
51

  
52
        cout << gm;
53

  
54
        BiConnectedComponents bcc = BiConnectedComponents(gm);
55
        bcc.run();
56
        // bcc.print();
57
        string filename = helper::get_file_name(filepath);
58
        string out_filepath = "../output/" + filename + ".out";;
59
        bcc.write_all_betweenness_centrality(out_filepath);
60
    }
61
}
96 62

  
97
    // string simpleGraphFilePath = "../input/simple.edges";
98
    // testGraphManager(simpleGraphFilePath);
63
void old_main_code() {
64
    string simpleGraphfilepath = "../input/simple.edges";
65
    testGraphManager(simpleGraphfilepath);
99 66

  
100
    string simpleGraphFilePath = "../input/simple.edges";
101
    testHeuristic(simpleGraphFilePath);
67
    testHeuristic(simpleGraphfilepath);
68
}
69

  
70
int main(int, char *[]) {
71
    default_run();
102 72

  
103 73
    return 0;
104 74
}

Also available in: Unified diff