Creating a property map inside Dijkstra Visitor

Good afternoon, Inside a dijkstra visitor I would like to change the edge weights at some point, so in my visitor I'm trying to make a property map called weight :
template<class DynamicMap> class gds_visitor : public dijkstra_visitor<> { public:
gds_visitor(DynamicMap input):dynamic(input){}
....
template <class Edge, class Graph> void examine_edge (Edge e, Graph& g) { typename property_map<Graph, edge_weight_t>::type weight; weight=get(edge_weight, g);
std::cout << "An edge is being examined..." << "\n"; }
protected: DynamicMap dynamic; };
typedef adjacency_list<listS, vecS, directedS, no_property,
where Graph: property<edge_weight_t, int> > Graph; and Edge:
typedef std::pair<int, int> Edge;
But it is not compiling, mentioning a problem with weight 'soperator = . Thank you in advance, Jonas Gabriel

Jonas Gabriel wrote:
Good afternoon,
Inside a dijkstra visitor I would like to change the edge weights at some point, so in my visitor I'm trying to make a property map called weight :
template <class Edge, class Graph> void examine_edge (Edge e, Graph& g) { typename property_map<Graph, edge_weight_t>::type weight; weight=get(edge_weight, g);
The "Graph" you get will actually be a const Graph. So you should probably make the parameter to examine_edge a const Graph& and then either use the "const_type" of the property map: template <class Edge, class Graph> void examine_edge (Edge e, const Graph& g) { typename property_map<Graph, edge_weight_t>::const_type weight; weight=get(edge_weight, g); Or const_cast away the constness of the Graph, if you need to modify the weights: template <class Edge, class Graph> void examine_edge (Edge e, const Graph& cg) { Graph& g = const_cast<Graph&>(cg); typename property_map<Graph, edge_weight_t>::type weight; weight=get(edge_weight, g); - Doug
participants (2)
-
Douglas Gregor
-
Jonas Gabriel