Revision ee0dd796 custompackages/graph-parser/src/centrality.cpp

View differences:

custompackages/graph-parser/src/centrality.cpp
24 24

  
25 25
    // Nov 20, 2015
26 26
    // http://stackoverflow.com/questions/15432104/how-to-create-a-propertymap-for-a-boost-graph-using-lists-as-vertex-container
27
    typedef std::map<Vertex, size_t> StdVertexIndexMap;
28
    StdVertexIndexMap idxMap;
29 27

  
30
    // This property map is an adaptor that converts any type that is a model of Unique Associative Container such as std::map into a mutable Lvalue Property Map.
31
    typedef boost::associative_property_map<StdVertexIndexMap> VertexIndexMap;
32
    VertexIndexMap v_index(idxMap);
28
    StdVertexIndexMap v_index_std_map;
29
    VertexIndexMap v_index_map(v_index_std_map);
33 30

  
34 31
    // Populate the indexMap
35
    Viter v_iter, v_iter_end;
32
    Viter vi, ve; // vertex_iterator, vertex_iterator_end
36 33
    size_t i = 0;
37
    for (boost::tie(v_iter, v_iter_end) = boost::vertices(g); v_iter != v_iter_end; ++v_iter) {
38
        boost::put(v_index, *v_iter, i);
34
    for (boost::tie(vi, ve) = boost::vertices(g); vi != ve; ++vi) {
35
        boost::put(v_index_map, *vi, i);
39 36
        ++i;
40 37
    }
41 38

  
......
43 40
    CentralityVec v_centrality_vec(boost::num_vertices(g), 0);
44 41

  
45 42
    typedef boost::iterator_property_map<CentralityVec::iterator, VertexIndexMap> CentralityMap;
46
    CentralityMap v_centrality_map(v_centrality_vec.begin(), v_index);
43
    CentralityMap v_centrality_map(v_centrality_vec.begin(), v_index_map);
47 44

  
48 45
    // Nov 26, try out the normal call to centrality().This version is not working.
49 46
//    brandes_betweenness_centrality( g, boost::centrality_map(v_centrality_map));
50 47

  
51 48
    // http://stackoverflow.com/questions/30263594/adding-a-vertex-index-to-lists-graph-on-the-fly-for-betweenness-centrality
52 49
    // Use named-parameter
53
    brandes_betweenness_centrality(g, boost::centrality_map(v_centrality_map).vertex_index_map(v_index));
50
    brandes_betweenness_centrality(g, boost::centrality_map(v_centrality_map).vertex_index_map(v_index_map));
54 51
    relative_betweenness_centrality(g, v_centrality_map);
55 52

  
56 53

  
57 54
    // Print result of v_centrality_map to console
58 55
    cout << "Vertex betweenness" << endl;
59 56
    i = 0;
60
    for (boost::tie(v_iter, v_iter_end) = boost::vertices(g); v_iter != v_iter_end; ++v_iter) {
61
        cout << g[*v_iter].id << "\t" << v_centrality_vec.at(i) << endl;
57
    for (boost::tie(vi, ve) = boost::vertices(g); vi != ve; ++vi) {
58
        cout << g[*vi].id << "\t" << v_centrality_vec.at(i) << endl;
62 59
        ++i;
63 60
    }
64 61

  
......
71 68
void writeBetweennessCentrality(const Graph &g, std::vector<double> v_centrality_vec, string fileSuffix) {
72 69
    cout << "XXX Writing to File";
73 70
    string filePath = "../output/boost_" + fileSuffix + ".csv";
74
    ofstream outFile(filePath);
71
    ofstream outFile(filePath.c_str());
75 72

  
76 73
    Viter vi, ve;
77 74
    size_t i = 0;
......
84 81
    outFile.close();
85 82

  
86 83
    cout << "XXX Writing to File 2";
87
}
84
}

Also available in: Unified diff