Search code examples
c++boostgraphdijkstraboost-graph

How do I define a custom distance in Boost Dijkstra?


I'm currently looking at the documentation of Boost Dijkstra - http://www.boost.org/doc/libs/1_52_0/libs/graph/doc/dijkstra_shortest_paths.html; my objective is to modify the distance combining to get a "max" instead of a "plus" when computing my distances. The doc says this:

IN: distance_combine(CombineFunction cmb)
This function is used to combine distances to compute the distance of a path. The
CombineFunction type must be a model of Binary Function. The first argument typ
of the binary function must match the value type of the DistanceMap property map
and the second argument type must match the value type of the WeightMap property
map. The result type must be the same type as the distance value type.
Default: closed_plus<D> with D=typename property_traits<DistanceMap>::value_type

What's the syntax to define such a Combine function? I've tried fumbling around with std::max, but my compiler doesn't seem to be happy with it.


Solution

  • Probably having its arguments be templates is might make things a bit difficult...

    Try (where T is the type of your distances)

    T comb(T& a, T& b) { return std::max(a, b); }
    

    and pass comb.