I am doing my first steps with Boost::Graph and encountered some (to me) unexpected behavior.
What I want is to have a series of edge_weight
properties (the number is only known at runtime), and use the minimum of all weights that satisfy certain constraints. First, the typedef
declarations:
typedef adjacency_list<vecS, vecS, undirectedS, property<vertex_distance_t, int>, property<edge_weight_t, int> > Graph;
typedef graph_traits<Graph>::edge_descriptor Edge;
typedef property_map<Graph, edge_weight_t>::type WeightMap;
typedef property_map<Graph, vertex_distance_t>::type DistanceMap;
I initialize the graph as follows:
void testcase() {
int t, e, s, a, b;
cin >> t >> e >> s >> a >> b;
Graph g(t);
WeightMap fastestLinkWeight = get(edge_weight, g);
vector<WeightMap> weightMaps(s);
for (int i=0;i<e;i++) {
int u, v;
cin >> u >> v;
Edge edge; bool worked;
tie(edge, worked) = add_edge(u, v, g);
for (int j=0;j<s;j++) {
cin >> weightMaps[j][edge];
}
fastestLinkWeight[edge] = INT_MAX;
cout << weightMaps[0][edge] << "\n";
}
}
And it outputs INT_MAX
over and over. It seems like the (external) weightMaps[j]
are all the same and equal to the internal property fastestLinkWeight
. But why? How can I ensure that I use separate maps?