Revision 37200dce fiddle/boost-networkx-comparision/src/boost_graph.cpp

View differences:

fiddle/boost-networkx-comparision/src/boost_graph.cpp
129 129

  
130 130
    BOOST_FOREACH(const boost::property_tree::ptree::value_type &v, pt.get_child("links"))
131 131
    {
132
        cout << "X" << endl;
133
        cout << v.second.get_value<std::string>() << " ";
134 132
        string source = v.second.get_child("source").get_value<std::string>();
135 133
        string target = v.second.get_child("target").get_value<std::string>();
136 134
        double cost = v.second.get_child("cost").get_value<double>();
137 135

  
138

  
139 136
        addLinkToGraph(source, target, cost, g, routers);
140 137
    }
141 138
}
......
154 151

  
155 152
    BOOST_FOREACH(const boost::property_tree::ptree::value_type &v, pt.get_child("topology"))
156 153
    {
157
        cout << "X" << endl;
158
        cout << v.second.get_value<std::string>() << " ";
159 154
        string source = v.second.get_child("lastHopIP").get_value<std::string>();
160 155
        string target = v.second.get_child("destinationIP").get_value<std::string>();
161 156
        double cost = v.second.get_child("neighborLinkQuality").get_value<double>();
......
184 179
    int count = 0;
185 180
    for (i = contents.begin(); i != contents.end(); ++i) {
186 181
        unsigned long size = (*i).size();
187
//        cout << "size = " << size << endl;
188
//        cout << "&i = " << &i << endl;
189 182
        for (int j = 0; j < size; ++j) {
190 183
            cout << (*i)[j] << endl;
191 184
        }
......
236 229
        string s2 = (*iter)[1];
237 230
        float cost = std::stof((*iter)[2]);
238 231

  
239
        cout << s1 << " " << s2 << " " << cost << endl;
240

  
241 232
        boost::tie(pos, inserted) = routers.insert(std::make_pair(s1, Vertex()));
242 233
        if (inserted) {
243
//            cout << "Added vertex " << s1 << endl;
244 234
            v1 = boost::add_vertex(g);
245 235
            routers[s1] = v1;
246 236
            pos->second = v1;
......
249 239
            g[v1].id = s1;
250 240
            g[v1].name = s1;
251 241
        } else {
252
//            cout << "Found vertex " << s1 << endl;
253 242
            v1 = pos->second;
254 243
        }
255 244

  
256 245
        boost::tie(pos, inserted) = routers.insert(std::make_pair(s2, Vertex()));
257 246
        if (inserted) {
258
//            cout << "Added vertex " << s2 << endl;
259 247
            v2 = boost::add_vertex(g);
260 248
            routers[s2] = v2;
261 249
            pos->second = v2;
262 250
            g[v2].id = s2;
263 251
            g[v2].name = s2;
264 252
        } else {
265
//            cout << "Found vertex " << s2 << endl;
266 253
            v2 = pos->second;
267 254
        }
268 255

  
269 256
        // Add edge (aka. link) connecting 2 vertices
270 257
        boost::tie(e, inserted) = boost::add_edge(v1, v2, g);
271 258
        if (inserted) {
272
            cout << "Added edge with weight " << cost << endl;
273 259
            g[e].cost = cost;
274 260
        }
275 261
    }
......
299 285
}
300 286

  
301 287
void writeBetweennessCentrality(Graph &g, std::vector<double> v_centrality_vec, string fileSuffix) {
302
    cout << "XXX Writing to File";
303 288
    string filePath = "../output/boost_" + fileSuffix + ".csv";
289
    cout << "Writing to File " << filePath << endl;
304 290
    ofstream outFile(filePath);
305 291

  
306 292
    // Reading to vector<graphDataType>
......
313 299
        }
314 300
    }
315 301
    outFile.close();
316

  
317
    cout << "XXX Writing to File 2";
318 302
}
319 303

  
304
template<typename Graph, typename CentralityVec>
305
void printCentrality(Graph g, CentralityVec v_centrality_vec) {
306
    size_t i = 0;
307

  
308
    typename Graph::vertex_iterator v_iter, v_iter_end;
320 309

  
310
    for(boost::tie(v_iter,v_iter_end) = boost::vertices(g); v_iter != v_iter_end; ++v_iter){
311
        cout << g[*v_iter].id << "\t" << v_centrality_vec.at(i) << endl;
312
        ++i;
313
    }
314
}
321 315

  
322 316
void simpleBetweennessCentrality(Graph g, string fileSuffix) {
323 317
    // One way to create centrality_map
......
363 357
    // http://stackoverflow.com/questions/30263594/adding-a-vertex-index-to-lists-graph-on-the-fly-for-betweenness-centrality
364 358
    // Use named-parameter
365 359
    brandes_betweenness_centrality( g, boost::centrality_map(v_centrality_map).vertex_index_map(v_index));
366
    relative_betweenness_centrality( g, v_centrality_map);
367 360

  
368
    // Nov 26, try out the normal call to centrality()
369
//    brandes_betweenness_centrality( g, boost::centrality_map(v_centrality_map));
361
    // ATTENTION: calling the relative_betweenness_centrality in the normal way
362
    // DO NOT USE the named-parameter
363
    relative_betweenness_centrality( g, v_centrality_map);
370 364

  
371 365

  
372 366
    // Print result of v_centrality_map to console
373
    cout << "Vertex betweenness" << endl;
374
    i = 0;
375
    for(boost::tie(v_iter,v_iter_end) = boost::vertices(g); v_iter != v_iter_end; ++v_iter){
376
        cout << g[*v_iter].id << "\t" << v_centrality_vec.at(i) << endl;
377
        ++i;
378
    }
367
    // Uncomment to see the result in the console.
368
    // printCentrality(g, v_centrality_vec);
379 369

  
380 370
    // Write result of v_centrality_map to file.
381 371
    writeBetweennessCentrality(g, v_centrality_vec, fileSuffix);
382

  
383 372
}
384 373

  
385 374
void handleSimpleInput(string filePath) {
386 375
    // Read the input.edges
387 376
    vector<graphDataType> contents;
388 377
    contents = readFile2(filePath);
389
    printVector2(contents);
378
    // printVector2(contents);
390 379
    Graph g;
391 380
    createUndirectedGraph(contents, g);
392
    cout << "Finish creating graph" << endl;
393 381

  
394 382
    simpleBetweennessCentrality(g, "edge_list");
395 383
}
......
397 385
void handleJsonInput(string filePath) {
398 386
    Graph g;
399 387
    readJson(filePath, g);
400
    printGraph(g);
388
    // printGraph(g);
401 389

  
402 390
    // Applying the betweenness centrality
403 391
    simpleBetweennessCentrality(g, "json_olsr");
404

  
405
    cout << "Done with Betweenness Centrality" << endl;
406 392
}
407 393

  
408 394
void handleComplexJsonInput(string filePath) {
409 395
    Graph g;
410 396
    readComplexJson(filePath, g);
411
    printGraph(g);
397
    // printGraph(g);
412 398

  
413 399
    // Applying the betweenness centrality
414 400
    simpleBetweennessCentrality(g, "json_topology");
415

  
416
    cout << "Done with Betweenness Centrality" << endl;
417 401
}
418 402

  
419 403

  

Also available in: Unified diff