Question

I have a custom edge property (MyWeight) in a boost graph and want to apply a Dijkstra shortest path search.

My weight type is, with the help of boost::operators, addable, subtractable, less-than comparable and equality comparable.

Because I know that search has to start with something, I need the equivalent of a zero, and to find out if a node is reachable, something very big.

MyWeight weight_zero(...), weight_inf(...);

// now, weight_zero is less than all other weights, weight_inf greater than all other weights.

boost::dijkstra_shortest_paths( G, target_idx, boost::predecessor_map(&predecessors[0])
    .distance_map(&distances[0])
    .distance_inf(weight_inf)
    .distance_zero(weight_zero)
            );

This is the principle I use my custom weight. It compiles (and seems to work correctly) with gcc 4.8.1, but with gcc 4.7.3 I get the following error (a little bit shortened):

/usr/include/c++/4.7/limits:-1: In instantiation of 'static constexpr _Tp std::numeric_limits<_Tp>::max() [with _Tp = MyWeight<2, MyEvaluator>]':
/usr/include/c++/4.7/limits:313: error: no matching function for call to 'MyWeight<2, MyEvaluator>::MyWeight(int)'

(MyWeight is actually a template)

I interpret this message as "there is no std::numeric_limit for your type", on the other hand, I tell BGL which extrema to use and don't understand why it tries to call numeric limits. I think the best thing to try here was to make numeric_limits recognize my custom data type.

Can someone point me on how to accomplish that?

I found a first hint here, but the example uses members like digits and digits10 and I'd like to know where they stem from.

EDIT

This is an example like mine. Can't compile it, for errors see above.

Was it helpful?

Solution

That appears to be a bug (or deficiency; I am not sure whether it is fixable) in the named parameters wrapper which expands the default values even if they are not used. If you use the positional arguments overload and fill in all the arguments in manually, numeric_limits are not needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top