Revision 20756421

View differences:

custompackages/graph-parser/src/bi_connected_components.cpp
50 50
    cout << "Calculate Traffic Matrix\n";
51 51
    CalculateTrafficMatrix();
52 52

  
53
    // Calculate Betweenness Centrality
54
    cout << "Calculate Betweenness Centrality\n";
55
    CalculateBetweennessCentrality();
56

  
53 57
    print();
54 58
}
55 59

  
......
98 102
    }
99 103
}
100 104

  
105
/* BETWEENNESS CENTRALITY */
106
void BiConnectedComponents::CalculateBetweennessCentrality() {
107
    for (int i = 0; i < num_of_bcc_; ++i) {
108
        BCCs[i].CalculateBetweennessCentrality();
109
    }
110
}
111

  
101 112
/* HELPERS */
102 113
int BiConnectedComponents::num_of_bcc() {
103 114
    if (num_of_bcc_ == -1) { // calculate it
custompackages/graph-parser/src/bi_connected_components.h
51 51
    // TRAFFIC MATRIX - calculation for all sub-components
52 52
    void CalculateTrafficMatrix();
53 53

  
54
    // BETWEENNESS CENTRALITY
55
    void CalculateBetweennessCentrality();
56

  
54 57
    // HELPERS
55 58
    int num_of_bcc();
56 59

  
custompackages/graph-parser/src/main.cpp
49 49
void handleJsonInput(string filePath) {
50 50
    Graph g;
51 51
    readJson(filePath, g);
52
    printGraph(g);
52
    outops::operator<<(cout, g);
53 53

  
54 54
    // Applying the betweenness centrality
55 55
    simpleBetweennessCentrality(g, "json_olsr");
......
60 60
void handleComplexJsonInput(string filePath) {
61 61
    Graph g;
62 62
    readComplexJson(filePath, g);
63
    printGraph(g);
63
    outops::operator<<(cout, g);
64 64

  
65 65
    // Applying the betweenness centrality
66 66
    simpleBetweennessCentrality(g, "json_topology");
custompackages/graph-parser/src/sub_component.cpp
154 154
void SubComponent::update_traffic_matrix(string name_1, string name_2, int value) {
155 155
    int i1 = index_of_vertex_id(name_1);
156 156
    int i2 = index_of_vertex_id(name_2);
157
    cout << i1 << " " << i2 << " = " << value << endl;
157
    // cout << i1 << " " << i2 << " = " << value << endl;
158 158
    traffic_matrix_[i1][i2] = value;
159 159
    traffic_matrix_[i2][i1] = value; // because Traffic Matrix is symmetric
160 160
}
161 161

  
162
/* BETWEENNESS CENTRALITY */
163
void SubComponent::CalculateBetweennessCentrality() {
164
    initialize_betweenness_centrality();
165

  
166
    cout << "Mark 1" << endl;
167

  
168
    boost::brandes_betweenness_centrality(gm_.g_,
169
        boost::centrality_map(v_centrality_map_).vertex_index_map(
170
            gm_.v_index_map())
171
    );
172

  
173
    cout << "Mark 2" << endl;
174

  
175
    cout << "Vertex betweenness\n" << endl;
176
    for (int i = 0; i < num_of_vertices(); ++i) {
177
        cout << v_centrality_vec_.at(i) << endl;
178
    }
179
}
180

  
181
void SubComponent::initialize_betweenness_centrality() {
182
    v_centrality_vec_ = CentralityVec(num_of_vertices());
183
    v_centrality_map_ = CentralityMap(v_centrality_vec_.begin(), gm_.v_index_map());
184
}
185

  
162 186
/* HELPERS */
163 187
int SubComponent::num_of_vertices() {
164 188
    return boost::num_vertices(gm_.g_);
custompackages/graph-parser/src/sub_component.h
16 16

  
17 17
class SubComponent {
18 18
public:
19
    typedef std::vector<double> CentralityVec;
20
    typedef boost::iterator_property_map<CentralityVec::iterator, VertexIndexMap> CentralityMap;
21

  
19 22
    SubComponent();
20 23

  
21 24
    // Getter & Setter
......
45 48
    int get_traffic_matrix(string name_1, string name_2);
46 49
    void update_traffic_matrix(string name_1, string name_2, int value);
47 50

  
51
    // BETWEENNESS CENTRALITY
52
    void CalculateBetweennessCentrality();
53
    void initialize_betweenness_centrality();
54

  
48 55
    // HELPERS
49 56
    int num_of_vertices();
50 57
    int index_of_vertex_id(string vertex_id);
......
60 67
    void printWeight();
61 68
    void _find_vertices_with_unknown_weight(VertexVec& unknown_weight_vertices);
62 69

  
63
    // Traffic Matrix
64
    void _computeTrafficMatrix();
65

  
66 70
    // Betweenness Centrality
67
    void _initializeBetweennessCentrality();
71

  
68 72
    void findBetweennessCentrality();
69 73
    void printBetweennessCentrality();
70 74

  
......
75 79
    StringSet all_vertices_id_;
76 80
    StringSet art_points_id_;
77 81
    StringSet non_art_points_id_; // vertices that are not articulation points
82
    NameToIntMap name_index_map_;
83

  
78 84

  
79 85
    NameToIntMap weight_map_;
80 86
    NameToIntMap weight_reversed_map_;
81 87

  
82
    NameToIntMap name_index_map_;
83 88
    vector<vector<int> > traffic_matrix_;
84 89

  
85
    // Traffic Matrix
90
    CentralityVec v_centrality_vec_;
91
    CentralityMap v_centrality_map_;
92

  
86 93

  
87
    // Betweenness Centrality
88 94
};
89 95

  
90 96

  
custompackages/graph-parser/src/utility.cpp
5 5
#include "utility.h"
6 6
using namespace boost;
7 7

  
8
void printGraph(Graph &g) {
9
    typename boost::graph_traits<Graph>::out_edge_iterator out_i, out_ie;
10
    Viter v_i, v_ie;
11

  
12
    Vertex v;
13
    Edge e;
14

  
15
    boost::tie(v_i, v_ie) = boost::vertices(g);
16
    for (v_i; v_i != v_ie; ++v_i) {
17
        v = *v_i;
18
        boost::tie(out_i, out_ie) = boost::out_edges(v, g);
19

  
20
        for (out_i; out_i != out_ie; ++out_i) {
21
            e = *out_i;
22
            Vertex src = boost::source(e, g);
23
            Vertex targ = boost::target(e, g);
24
            std::cout << "(" << g[src].id << ","
25
            << g[targ].id << ") ";
26
        }
27
        cout << endl;
28
    }
29
}
30

  
31 8
/* outops namespace */
32 9
namespace outops {
33
    std::ostream& operator<<(std::ostream& os, const Graph& g)
34
    {
10
    std::ostream& operator<<(std::ostream& os, const Graph& g) {
35 11
        os <<   "Graph has: \n"
36 12
                "---------- " << boost::num_vertices(g) << " vertices\n"
37 13
                "---------- " << boost::num_edges(g) << " edges\n";
......
86 62
        return os;
87 63
    }
88 64

  
89
    std::ostream& operator<<(std::ostream& os, const std::map<string, int>& m)
90
    {
65
    std::ostream& operator<<(std::ostream& os, const std::map<string, int>& m) {
91 66
        // similar to printhelper::for_map()
92 67
        os << "cout << std::map\n";
93 68
        std::map<string, int>::const_iterator iter;
custompackages/graph-parser/src/utility.h
13 13
#include <boost/graph/iteration_macros.hpp>
14 14
#include "common.h"
15 15

  
16

  
17

  
18
void printGraph(Graph &g);
19

  
20 16
namespace outops {
21 17
    std::ostream& operator<<(std::ostream& os, const Graph& g);
22 18

  

Also available in: Unified diff