1

I'm trying to design an algorithm with BGL. I am given different weight maps and I need to compute the MST of the graph with respect to each weight map.

I was wondering, by the way, if it was possible to use different weight maps and just change the reference in the graph.

I've tried the following code, but it seems that if I modify an entry of one map I modify the same entry of all the maps I have declared. Here is the code:

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
boost::no_property, boost::property<boost::edge_weight_t, long> >      weighted_graph;
typedef boost::property_map<weighted_graph, boost::edge_weight_t>::type weight_map;
typedef boost::graph_traits<weighted_graph>::edge_descriptor            edge_desc;
typedef boost::graph_traits<weighted_graph>::vertex_descriptor          vertex_desc;

weighted_graph G(50);
weight_map weights[5];

...
// build the graph
...
weights[0][edge1] = 121;
...
weights[3][edge1] = 34;
...
// weights[0][edge1] == 34

how is that possible?

NoImaginationGuy
  • 1,795
  • 14
  • 24
  • See also the answers linked to in the duplicate, or this https://stackoverflow.com/questions/33103659/weight-map-as-function-in-boost-graph-dijkstra-algorithm/33104513#33104513 – sehe Oct 11 '19 at 15:51

0 Answers0