On Fri, 18 Dec 2009, Maxime van Noppen wrote:
Hi,
I can't find how to do this pretty basic thing : having a function instead of a field to compute the cost of edges for various path finding algorithms. I couldn't find the answer in the documentation and Google was of no help. Did I miss something obvious ?
Example :
------------------- #include
#include #include struct my_edge { double cost() const { return cost_ * 2; } double cost_; };
struct my_node { };
int main() { typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS, my_node, my_edge > graph_t; typedef boost::graph_traits
::vertex_descriptor vertex_t; graph_t graph;
vertex_t v /*= ... */;
using boost::weight_map;
// Works : boost::dijkstra_shortest_paths(graph, v, weight_map(boost::get(&my_edge::cost_, graph)));
// Doesn't compile : //boost::dijkstra_shortest_paths(graph, v, // weight_map(boost::get(&my_edge::cost, graph))); } -------------------
Thanks !
It looks like there is no property map that does what you want, although
there should be. Try something like this (not tested); it assumes that
your functors are lightweight to copy, have a const operator()(), and do
not have any internal state:
#include