I need to get the bundled property map with a key_type of the
vertex_descriptor and a value_type of the bundled vertex property type from
a compressed_sparse_row_graph by get(vertex_bundle, g), but it failed. It
works when the graph is an adjacency_list.
1 #include <iostream>
2 #include <string>
3 #include
4 #ifndef CSR
5 #include
6 #else
7 #include
8 #endif
9 using namespace boost;
10 using namespace std;
11 struct City {
12 string name;
13 int population;
14 int zipcode;
15 explicit City(string const &n = "", int pop = 0, int zip = 0) :
name(n), population(pop), zipcode(zip){}
16 };
17 struct Highway {
18 string name;
19 double miles;
20 int speed_limit;
21 explicit Highway(string const &n = "", double m = 0, int s = 0)
: name(n), miles(m), speed_limit(s){}
22 };
23 #ifndef CSR
24 typedef adjacency_list
Graph;
25 #else
26 typedef compressed_sparse_row_graph Graph;
27 #endif
28 int main(int argc, char* argv[])
29 {
30 City ct[3] = { City("Beijing", 20, 100000), City("Tianjin", 10,
200000), City("Shanghai", 18, 300000) };
31 Highway hway[2] = { Highway("JJWay", 200, 100), Highway("JHWay",
1300, 120) };
32 graph_traits<Graph>::vertex_iterator vi, vi_end;
33 #ifndef CSR
34 Graph map;
35 Graph::vertex_descriptor v[3];
36 v[0] = add_vertex(ct[0], map);
37 v[1] = add_vertex(ct[1], map);
38 v[2] = add_vertex(ct[2], map);
39 add_edge(v[0], v[1], hway[0], map);
40 add_edge(v[0], v[2], hway[1], map);
41 #else
42 typedef pair Edge;
43 Edge edges[2] = { Edge(0, 1), Edge(0,2) };
44 Graph map(edges_are_unsorted, edges, edges + 2, hway, 3);
45 int i = 0;
46 for (tie(vi, vi_end) = vertices(map); vi != vi_end; ++vi)
47 map[*vi] = ct[i++];
48 #endif
49 property_map::type index =
get(vertex_bundle, map);
50 for (tie(vi, vi_end) = vertices(map); vi != vi_end; ++vi)
51 cout<::type Names =
get(&City::name, map);
53 for (tie(vi, vi_end) = vertices(map); vi != vi_end; ++vi)
54 cout<