Weighting for bicycle routing


continuing another thread from the mailing list: The original question was basically how a bicycle routing could be influenced so that it avoids highways and prefers bicycle friendly ways (even if they are longer). The original suggestion was to implement a CustomWeighting.

Meanwhile, I’ve looked a bit into the code and found BikeCommonFlagEncoder.collect:

    if (way.hasTag("bicycle", "designated"))
        weightToPrioMap.put(100d, PREFER.getValue());

In my test case, there’s a way with exactly that tag more or less parallel to a secondary highway. As long as my start/end point is reasonable close to the bicycle designated way, the routing uses it. As soon as I the start or end point further away, the routing prefers the highway.

I tried to set BEST.getValue() - no difference. What’s the purpose of the first parameter for the map and couldn’t the routing also be influenced right there?


1 Like

Thanks for this good question!

The purpose of the first map parameter is to be overwritten by a subclass and also if you have many if clauses you sometimes want to improve the priority but not in some really ugly cases like for tunnels. And so the order of the if clauses is less relevant and makes overall usage a bit simpler.

But here I’m open to any better system.

In general tuning the priority can be tricky and problems can have several reasons. You’ll have to look into every edge if it gets the intended priority after import.

Also the aim of the next release will be to make it easier to create custom vehicles/weightings.

couldn’t that (i.e. AVOID_AT_ALL_COSTS) be exposed as a parameter? Alternatively, BikeCommonFlagEncoder already avoids motorways, so it could optionally avoid primary and secondary highways as well? What I don’t understand yet (for lack of time spent digging through the code) is how to influence this from the router at runtime and not the encoder, though (I suppose this is the purpose of the custom weighting?).

In short, what I’m thinking about is the ability to exclude user configurable way types during routing, just like commercial car routers do (e.g. avoid toll roads, ferries, etc.). This would delegate part of the routing approach responsibility to the user which is always a good idea in cases where an algorithm cannot guess what the user really wants… And IMHO this should be a generic feature and not a “to be hardcoded” custom weighting.

Does that make sense?

Yes, such a flexibility is something we plan (see the other created topic)

couldn’t that (i.e. AVOID_AT_ALL_COSTS) be exposed as a parameter?

Not sure what you mean here.

though (I suppose this is the purpose of the custom weighting?).

this is currently not directly possible. You would need to store the OSM attributes in the flags (what we will do soon and make it easy for developers) and then evaluate this in the custom Weighting

Ok, I’ll keep watching More flexibility in GraphHopper then