I'm trying to calculate the shortest path on a graph with vertex weights and edge weights, but boost::dijkstra_shortest_paths doesn't calculate the weights passing through the vertices.
I tried customizing weight_map, but it always reported an error when running. The following is my code
auto custom_weight_map = [&g](const Graph::edge_descriptor& e) -> float {
float vertex_weight = g[target(e, g)].weight;
float edge_weight = get(boost::edge_weight, g, e);
return vertex_weight + edge_weight;
};
boost::dijkstra_shortest_paths(
g, source_vertex,
boost::predecessor_map(
boost::make_iterator_property_map(
predecessors.begin(), boost::get(boost::vertex_index, g)))
.distance_map(boost::make_iterator_property_map(
distances.begin(), boost::get(boost::vertex_index, g)))
.weight_map(custom_weight_map));

The custom weight map needs to be a property map: doc
The simplest way I think to do it is to use a function property map or perhaps transform property map:
Live On Coliru