Repository navigation
Conversation
| } | ||
|
|
||
| @Test | ||
| public void withPriority() { |
There was a problem hiding this comment.
This test shows how the weight changes when changing the priority for a few edges with different speeds
| // todonow: the polygon used here is a bit weird and we really have to use a low priority to force the | ||
| // large detour | ||
| " area_custom1: 0.05\n" + |
There was a problem hiding this comment.
Here it looks like you were trying to enforce the green route instead of the red one using the area shown as grey box:
But this seems a bit strange to me because both routes are crossing the area. With the new formula I was not able to enforce this route and instead it yields a route that really avoids the grey box (goes around it and therefore the distance is much longer):
There was a problem hiding this comment.
Maybe this is exactly because the priority contribution depends on the speed (with the old formula): The green route (in the first screenshot) is probably faster and therefore decreasing the priority does not increase the weight as much as on the red route.
There was a problem hiding this comment.
Hmmh, ugly. I'll have a look why I chose this area and then accepted that the path was still going through (might be the intention but I'm no longer 100% sure)
There was a problem hiding this comment.
This seems like a key example to me: We set the priority to some low value in this area and with the old formula this means we add a bigger penalty to the slower road and a smaller penalty to the faster road. Therefore we have this situation where one of the roads crossing the area is surpressed, but the other is not. With the new formula we apply the same penalty to both roads (per meter) and therefore they are both neglected. What is better? I don't know :) I guess that depends on what you want to achieve.
There was a problem hiding this comment.
The old formula also needs a 0.05 priority to force the long detour, but yes, for all values until 0.05 the old formula prefers the longer way where the new prefers the shorter. So here the new formula makes more sense as inside the avoided area it influences the original path the least.
And yes, we should remove assertBetween and replace with assertEquals and a bigger delta.
# Conflicts: # docs/core/profiles.md
|
|
||
| @Override | ||
| public double calcEdgeWeight(EdgeIteratorState edgeState, boolean reverse) { | ||
| double distance = edgeState.getDistance(); |
There was a problem hiding this comment.
BTW: the reason I "cached" the distance here is that it gave a minor speed up. (not sure if this is still true)
There was a problem hiding this comment.
ok I added a todo and lets check this when we have decided on the formula again
|
Thanks a lot for this! The new formula has a nice property it seems. Also thanks for making it so clear and easy as I would have a hard time in understanding the effects of it just from the formula. What I also like is that there was no need to change the yaml it seems (except for the area thing which could also be a faulty test).
"regardless of the speed", but still "dependent on the distance"? I.e. has meaning of
Can you expand on this a bit? I think, this was also the motivation for you for this new formula (?)
Ok. Tough problem :) I'm currently slightly preferring the old formula because of its simple explanation: use But I'm likely just more used to the old formula and I might as well oversimplify the situation, which you probably have better studied. We could even name these two different priorities in a different way and expose them in the yaml, but especially at the beginning of this CustomWeighting adventure I would probably try to avoid this and pick one meaning (name it "priority") and in the worst case switch to the other meaning/formula. But which one :D ? |
Yes there is no difference. The priority is a number between 0 and 1 and the only question is how exactly this should enter the formula.
For both formulas the 'priority costs' are proportional to the distance. Nothing has changed about this. The difference is just that in one case the penalty is proportional to the speed and in the other it is not.
Yes this was my original motivation, but I think when I started I did not fully realize that with custom weighting we are not setting any kind of costs explicitly, but rather apply some factors to change the default behavior. The question is simply what is meant when somebody sets something like
Ok but this has not changed with the new formula. Setting the priority to something < 1 still means avoiding certain kinds of roads and it does not change the ETA. This simple message still applies. What is slightly more simple with the old formula is the 'size' of the priority costs.
Yes for sure I would not introduce another parameter in the configuration either and this is also nice, it should be easy to change the formula any time if there is need to do this.
I am still not sure :D. |
|
Do you have a common use case for priority? |
|
Here I plotted the weight calculated using the two formulas for We can see that with the old formula the priority affects the weight of slower roads more than faster ones and around But honestly this kind of qualitative analysis has not helped me much in deciding which one we should prefer. We probably need some real-life examples to make a better decision and as far as I am concerned we can keep the old formula until we feel like we need to change something. |
|
Interesting. And the avoid area example could be indeed like a key example and it is indeed unexpected that roads inside the area get a different penalty.
:)
There are many examples like avoiding motorways for car, or avoid sand for bike, or avoiding ferries, or tolls or smaller roads for trucks, or avoiding destination-only roads ... or the opposite like preferring official bike routes means avoiding everything else. In general we expect that the weight increases and do not care about how exactly. But it sounds bad to put a bigger penalty on the roads with slower speed. I can imagine that for big speed differences that occur e.g. for walking (5kmh) when they use a ferry (30kmh) this somehow could become more obvious?
👍
At least I'm now also undecided and not in favor of the old anymore ;) |
# Conflicts: # core/src/main/java/com/graphhopper/routing/weighting/custom/CustomWeighting.java # core/src/test/java/com/graphhopper/routing/weighting/CustomWeightingTest.java # docs/core/profiles.md # web/src/test/java/com/graphhopper/http/resources/CustomWeightingRouteResourceTest.java
|
Right now we do not seem to come to a clear decision which formula is the best, so let's stick with the old one for now. Just for future reference: Another possibility would be: or simply These formulas allow scaling the priority costs using the distance_influence factor, which also makes sense, because applying priorities < 1 always induces distance costs. Setting f=0 does not allow any priority effects, but this just expresses that when we include priorities we can no longer have a pure fastest weighting. |



Here I changed the formula for custom weighting from
to
where
w=weight,d=distance,v=speed,p=priority,f=distance_influence,s=priority_sensitivity.p=1means that there are no priority costs andp=0means that the weight is infinite (just like with the previous formula). For0<p<1we get additional priority costs that are proportional to the distance andsis just a factor that determines how 'sensitive' these costs are to changes ofp. For example ifsis large, something likep=0.9already means large priority costs and ifsis smallp=0.9does not change the weight much.sshould therefore be roughly equal to some common speed so the priority costs are of the same order as the speed costs.The key difference here is that
sis a constant and does not depend on the speed of the edge. In fact if we sets=1/v(instead of it being a constant) the two formulas are identical. And this brings me to the key question here: Should the priority costs depend on the speed of an edge or not? Let's look at an example of an edge that is1000mlong and the speed is50km/h. The speed costs on this edge are:72s. If we setp=0.5this value doubles with the old formula (144s). With the new formula this depends on our choice ofs, but let's say we sets=1/(50/3.6), then we also get144s.But now let's assume the speed is not
50km/h, but25km/h. In this case the old formula yields288swhile the new formula yields:144s+72s=218s, because settingp=0.5still means the priority costs are72snot144s. So for the old formula changingpmeans that we 'add' priority costs that are proportional to the speed costs while with the new formula choosing a value ofpmeans we get certain priority costs regardless of the speed.WDYT? Honestly right now I am not sure what is better here. Generally I think the stress costs should be independent from the speed costs, but here we are using the
priorityfactor to 'modify' an existing weighting and its not entirely clear what the meaning ofpriorityis supposed to be.