Alternative_route.max_weight_factor < 1?

Hi,
we try to find ways to calculate the real shortest (not fastest) path between points.

In the Routing API is the parameter “alternative_route.max_weight_factor” with its default Value of 1.4.
Is it possible to change this value to let’s say 0.8 so that “alternative_route” may only bring shorter (but slower?) result routes?

Are there other approaches?

A raw “shortest distance” cost function is typically not what you want. E.g. it would lead to shortcuts through the forest that no one would do and more strange things. Instead you could increase the cost for a detour with the distance_influence, i.e. consider distance additional to time: Documentation - GraphHopper Directions API

Is it possible to change this value to let’s say 0.8 so that “alternative_route” may only bring shorter (but slower?) result routes?

This factor is unrelated to the cost function of the route. E.g. by default we accept 40% “longer” routes for alternatives (and the unit of this can be thought of seconds). A value smaller than 1 does not make sense here as it is always compared to the “best” route.

We struggle from time to time with the fastest routes. Our customers really want the shortest routes in some cases. We use restricted ares in the route optimization api to prevent that the routes go through unwanted terrain and areas.

But thanks for mentioning distance_influence (we didn’t know that), it seems to be what we want. If I understand it correctly, then we can set it to, let’s say, 1000000000 so it really values distance over travel duration?

Here’s an example:
(where the fastest route actually goes through forest and a swamp, rather through urban areas as the shortest route does.)

Image 1: GH Result between both points (ignore red areas, they aren’t considered here)
See the blue route → 4,88 km

Image 2: Shortest route between both points (what we want), manually moved, almost 100m difference:
See the blue route → 4,79 km

We use restricted ares in the route optimization api to prevent that the routes go through unwanted terrain and areas.

You mean for the Routing API? Because the Route Optimization API won’t support this or only via the Profiles API.

then we can set it to, let’s say, 1000000000 so it really values distance over travel duration?

It is unlikely that a value of more than a few hundred make sense. See the documentation where an example is provided:

A value of 100 means that one extra kilometer of detour must save you 100s of travelling time or else you are not willing to take the detour. Or to put it another way, if a reference route takes 600s and is 10km long, distance_influence=100 means that you are willing to take an alternative route that is 11km long only if it takes no longer than 500s (saves 100s). Things get a bit more complicated when priority is not 1, but the effect stays the same: The larger distance_influence is, the more GraphHopper will focus on finding short routes.

And for:

(where the fastest route actually goes through forest and a swamp, rather through urban areas as the shortest route does.)

Do you have a GH Maps link for this? I’m unsure about what you mean here exactly.