Revision 437fd680 custompackages/graph-parser/src/sub_component.cpp

View differences:

custompackages/graph-parser/src/sub_component.cpp
39 39
    return traffic_matrix_;
40 40
}
41 41

  
42
CentralityVec const& SubComponent::v_centrality_vec() const {
43
    return v_centrality_vec_;
44
}
45

  
42 46
/* CREATE SUB-COMPONENT */
43 47
void SubComponent::AddEdge(Router r1, Router r2, Link l) {
44 48
    gm_.AddEdge(r1, r2, l);
45 49
}
46 50

  
47 51
void SubComponent::FinalizeSubComponent(StringSet all_art_points_id) {
52
    // TODO: is there anyway to not have to call this function after the graph was created completely?
53
    gm_.ResetVerticesAndEdgesIndexMap();
54

  
48 55
    // Create set of vertices id
49 56
    graphext::id_of_all_vertices(gm_.g_, all_vertices_id_);
50 57

  
......
58 65
    // Create name -> index map
59 66
    int index = 0;
60 67
    for (string s : all_vertices_id_) {
61
        name_index_map_[s] = index;
68
        name_index_pmap_[s] = index;
62 69
        ++index;
63 70
    }
64 71
}
......
166 173
    cout << "Mark 1" << endl;
167 174

  
168 175
    boost::brandes_betweenness_centrality(gm_.g_,
169
        boost::centrality_map(v_centrality_map_).vertex_index_map(
170
            gm_.v_index_map())
176
        boost::centrality_map(v_centrality_pmap_).vertex_index_map(
177
            gm_.v_index_pmap())
171 178
    );
172 179

  
173 180
    cout << "Mark 2" << endl;
......
180 187

  
181 188
void SubComponent::initialize_betweenness_centrality() {
182 189
    v_centrality_vec_ = CentralityVec(num_of_vertices());
183
    v_centrality_map_ = CentralityMap(v_centrality_vec_.begin(), gm_.v_index_map());
190
    v_centrality_pmap_ = CentralityPMap(v_centrality_vec_.begin(), gm_.v_index_pmap());
191
}
192

  
193
double SubComponent::get_betweenness_centrality(string name) {
194
    // There are 2 ways to retrieve the BC score
195
    // 1st way - through v_centrality_vec_
196
    int index = gm_.get_index_from_id(name);
197
    cout << "    index = " << index << endl;
198
    return v_centrality_vec_.at(index);
199
}
200

  
201
double SubComponent::get_betweenness_centrality(Vertex v) {
202
    // 2nd way - uncomment to use v_centrality_pmap
203
    return boost::get(v_centrality_pmap_, v);
184 204
}
185 205

  
186 206
/* HELPERS */
......
190 210

  
191 211
int SubComponent::index_of_vertex_id(string vertex_id) {
192 212
    // TODO: might throw exception here
193
    return name_index_map_[vertex_id];
213
    return name_index_pmap_[vertex_id];
194 214
}
195 215

  
196 216
bool SubComponent::vertex_exists(string name) {
......
209 229
}
210 230

  
211 231
/* HELPERS FOR OUTPUTTING RESULT */
212
void SubComponent::print_traffic_matrix() {
232
void SubComponent::print() {
233
    cout << "Sub-component:" << endl;
234
    gm_.print();
235

  
236
    cout << "\nArticulation points ID:\n";
237
    outops::operator<<(cout, art_points_id());
238

  
239
    cout << "\nNormal Vertices ID:\n";
240
    outops::operator<<(cout, all_vertices_id());
213 241

  
242
    cout << "\nLink Weight:\n";
243
    outops::operator<< <int> (cout, weight_map());
244
    // printhelper::for_map<string, int>(sc.weight_map());
245

  
246
    cout << "\nTraffic Matrix:\n";
247
    outops::operator<<(cout, traffic_matrix());
248

  
249
    cout << "\nBetweenness Centrality:\n";
250
    outops::operator<< <double>(cout, v_centrality_vec());
214 251
}
215 252

  
216 253
std::ostream& operator<<(std::ostream& os, const SubComponent& sc) {
......
224 261
    outops::operator<<(cout, sc.all_vertices_id());
225 262

  
226 263
    cout << "\nLink Weight:\n";
227
    outops::operator<<(cout, sc.weight_map());
264
    outops::operator<< <int> (cout, sc.weight_map());
228 265
    // printhelper::for_map<string, int>(sc.weight_map());
229 266

  
230 267
    cout << "\nTraffic Matrix:\n";
231 268
    outops::operator<<(cout, sc.traffic_matrix());
232 269

  
270
    cout << "\nBetweenness Centrality:\n";
271
    outops::operator<< <double>(cout, sc.v_centrality_vec());
272

  
233 273
    return os;
234 274
}

Also available in: Unified diff