I would like to obtain two sets of shortest paths (one-to-all) derived from one graph, defined as adjacency_list
with internal properties (as opposed to bundles)
In theory I could run dijkstra_shortest_paths
on two reference nodes, n1
and n2
. If I create two property_maps
and pass them in sequence to dijkstra_...
I get what looks like two views of the same map. Both point to the result of the last run of dijkstra_shortest_paths
, so that the older result is gone. What should I do to achieve the desired result?
// Define some property maps
property_map<ugraph_t,edge_weight_t>::type Weight=get(edge_weight,G);
property_map<ugraph_t,vertex_distance_t>::type Dist1=get(vertex_distance,G);
// One line later, I expect this to be mapped to the SPs w.r.t n1
// Run SP on the first node
dijkstra_shortest_paths(G,n1,predecessor_map(Prev1).distance_map(Dist1).weight_map(Weight));
// New property maps
property_map<ugraph_t,vertex_distance_t>::type Dist2(Dist1); // And now to the second set
property_map<ugraph_t,vertex_predecessor_t>::type Prev2(Prev1); // But no two sets will result...
// Run SP on the second node
// This will run fine, but I will lose the first SP set (with or without a copy constructor above)
dijkstra_shortest_paths(G,n2,predecessor_map(Prev2).distance_map(Dist2).weight_map(Weight));
CONCLUSION: If I am not mistaken, a property_map
can be thought of as an interface with an iterator so that copying property_map
s makes no sense. The solution is to pass a custom container, constructed on the fly. That solution is detailed in the answer by @sehe below for which my many thanks!
NOTE: This only works if the vertex container type is vecS
. With listS
one has to "manually" copy vertex-by-vertex.