You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LMApproximator does not yield (approximately) feasible heuristic on QueryGraph #2584
The A* heuristic (h) must fulfill two properties so we can use it the way we use it:
The heuristic must be 'admissible', i.e. it must never overestimate the distance to the target
The heuristic must be 'feasible' (or 'consistent' or 'monotone'), i.e. the triangle inequality must be fulfilled: For every edge u->v it must hold that w(u,v) + h(v) >= h(u). This is because running A* with modified tentative weights, where we add the heuristic to the weight of each entry in the priority queue, is equivalent to running Dijkstra with a modified weighting w_red(u,v) := w(u,v) - h(u) + h(v). And since Dijkstra requires the weighting to be positive we have w_red >= 0.
The first property follows from the second, but not the other way around! I added a test that shows that 1) seems to be OK, but the LMApproximator violates 2) in some cases, see here
This is most likely due to the rounding of the LM weights and we need to make sure that 2) still holds true after the rounding.
Writing down what we already discussed on Slack:
It's true that LMApproximator as implemented by itself is not 'feasible'. But my impression when I was working on this was that it's just not possible to make it 'feasible' without exact arithmetic.
With limited-precision numbers (especially extra-limited by our custom number store), I think the code that calls LMApproximator must account for its precision, and give all those inequalities some slack. (Like you would do in a JUnit test with double numbers.)
LMApproximatorTest does this, and the part in our A* routing where that inequality is used does it, too.
Yes, I came to the same conclusion: The LMApproximator cannot be made feasible in the sense that when we apply our numerical inconsistencies (storing double landmark weights with a restricted number of bits < 64, let alone the inherent inaccuracy of floating point numbers) the feasibility condition is not always strictly fulfilled. @michaz wrote this already here: #1749 (comment)
However, we can still ask for a weaker condition, i.e. enforce the feasibility condition up to some accuracy: Instead of strictly enforcing w(u,v) + h(v) >= h(u) we require w(u,v) + delta + h(v) >= h(u), delta>0, so the new condition is that the adjusted reduced weight w_red(u, v) = w(u, v) + h(v) - h(u) + delta is never negative. If our approximator does this we can shift the stopping condition by the accuracy delta as well and the algorithm should behave as if the approximator was feasible in the first place. We do this for some time already by adding the getSlack() term in the stopping condition.
The thing is: The LM approximator is 'approximately feasible' by this definition, as we are already testing in LMApproximatorTest , but it is not feasible when used together with QueryGraph.
I took a close look at LMApproximatorTest, cleaned up a bit and started using it on QueryGraph, and in fact it shows that the feasibility condition is strongly violated when there are virtual nodes: 6d05d52
Next, I tried the new fix of LMApproximator from here: c87ddf1, here: b51b1a9 and it looks like there are less (but still not none) violations of the feasibility criterion, but now there are cases where the other condition is violated: LMApproximator overestimates the remaining weight.
changed the title [-]LMApproximator does not yield feasible heuristic[/-][+]LMApproximator does not yield (approximately) feasible heuristic on QueryGraph[/+]on Jun 1, 2022
Now let v be a virtual node on an edge A-B. Again according to the triangle inequality:
d(v, t) + d(t, LM) >= d(v, LM)
Ignoring turn costs between the virtual edges and the real network at A and B, we can split the distance d(v, LM) into a short distance from the virtual node to A or B and the shortest path distance from A/B to the landmark:
The heuristic for v is also feasible. Assume the first term is minimal for node A (if it wasn't we could just do the same for B):
h(v) = d(v, A) + d(A, LM) - d(t, LM) = d(v, A) + h(A)
So for virtual nodes we need to first find the neighbor real node for which d(v, .) + d(., LM) is minimal and then subtract d(t, LM) from this.
Note that if LM == t we have:
h(v) = min(d(v, A) + d(A, t), d(v, B) + d(B, t))
h(A) = d(A, t)
h(B) = d(B, t)
==> h(v) = min(d(v, A) + h(A), d(v, B) + h(B))
i.e. the heuristic of the virtual node would be just the minimum sum of the distance from the virtual node to the neighbor real node and the heuristic of the neighbor real node. But in general (t != LM) this is wrong and we have to determine the heuristic of the virtual node according to the above definition.
Btw, I think the old implementation is wrong because it sets h(v)=0 which means it is not feasible as d(A, v) + h(v) = d(A, v) and d(A, v) >= h(A) is certainly not always fulfilled, e.g. when d(A, v) is a short virtual edge and h(A) is rather large (far away from the target).
The fix in 6d05d52 is sometimes right as it takes the closer of the two nodes A and B (say it is A) and sets h(v) = d(v, A) + h(A). This is right when d(v, A) + d(A, LM) < d(v, B) + d(B, LM) and wrong otherwise, i.e. it is right 50% of the time which matches our empirical finding that the change seems to fix about half of the failing routing test cases :)
Activity
michaz commentedon May 29, 2022
Writing down what we already discussed on Slack:
It's true that LMApproximator as implemented by itself is not 'feasible'. But my impression when I was working on this was that it's just not possible to make it 'feasible' without exact arithmetic.
With limited-precision numbers (especially extra-limited by our custom number store), I think the code that calls LMApproximator must account for its precision, and give all those inequalities some slack. (Like you would do in a JUnit test with
doublenumbers.)LMApproximatorTestdoes this, and the part in our A* routing where that inequality is used does it, too.michaz commentedon May 29, 2022
It's still infeasible though.
easbar commentedon Jun 1, 2022
Yes, I came to the same conclusion: The LMApproximator cannot be made feasible in the sense that when we apply our numerical inconsistencies (storing double landmark weights with a restricted number of bits < 64, let alone the inherent inaccuracy of floating point numbers) the feasibility condition is not always strictly fulfilled. @michaz wrote this already here:
#1749 (comment)
However, we can still ask for a weaker condition, i.e. enforce the feasibility condition up to some accuracy: Instead of strictly enforcing
w(u,v) + h(v) >= h(u)we requirew(u,v) + delta + h(v) >= h(u), delta>0, so the new condition is that the adjusted reduced weightw_red(u, v) = w(u, v) + h(v) - h(u) + deltais never negative. If our approximator does this we can shift the stopping condition by the accuracy delta as well and the algorithm should behave as if the approximator was feasible in the first place. We do this for some time already by adding thegetSlack()term in the stopping condition.The thing is: The LM approximator is 'approximately feasible' by this definition, as we are already testing in LMApproximatorTest , but it is not feasible when used together with QueryGraph.
I took a close look at
LMApproximatorTest, cleaned up a bit and started using it on QueryGraph, and in fact it shows that the feasibility condition is strongly violated when there are virtual nodes: 6d05d52Next, I tried the new fix of LMApproximator from here: c87ddf1, here: b51b1a9 and it looks like there are less (but still not none) violations of the feasibility criterion, but now there are cases where the other condition is violated: LMApproximator overestimates the remaining weight.
[-]LMApproximator does not yield feasible heuristic[/-][+]LMApproximator does not yield (approximately) feasible heuristic on QueryGraph[/+]easbar commentedon Jun 2, 2022
Let
ube any node,tthe target node andLMa landmark node. Then according to the triangle inequality we have for the distances between these nodes:and it follows that
The heuristic
h(u)is feasible as:Now let
vbe a virtual node on an edgeA-B. Again according to the triangle inequality:Ignoring turn costs between the virtual edges and the real network at
AandB, we can split the distanced(v, LM)into a short distance from the virtual node toAorBand the shortest path distance fromA/Bto the landmark:so we can define the heuristic of the virtual node as:
for which we have:
The heuristic for
vis also feasible. Assume the first term is minimal for node A (if it wasn't we could just do the same for B):So for virtual nodes we need to first find the neighbor real node for which
d(v, .) + d(., LM)is minimal and then subtractd(t, LM)from this.Note that if
LM == twe have:i.e. the heuristic of the virtual node would be just the minimum sum of the distance from the virtual node to the neighbor real node and the heuristic of the neighbor real node. But in general (
t != LM) this is wrong and we have to determine the heuristic of the virtual node according to the above definition.easbar commentedon Jun 2, 2022
Btw, I think the old implementation is wrong because it sets
h(v)=0which means it is not feasible asd(A, v) + h(v) = d(A, v)andd(A, v) >= h(A)is certainly not always fulfilled, e.g. whend(A, v)is a short virtual edge andh(A)is rather large (far away from the target).The fix in 6d05d52 is sometimes right as it takes the closer of the two nodes A and B (say it is A) and sets
h(v) = d(v, A) + h(A). This is right whend(v, A) + d(A, LM) < d(v, B) + d(B, LM)and wrong otherwise, i.e. it is right 50% of the time which matches our empirical finding that the change seems to fix about half of the failing routing test cases :)