Skip to content

LMApproximator does not yield (approximately) feasible heuristic on QueryGraph #2584

Open

Description

@easbar

The A* heuristic (h) must fulfill two properties so we can use it the way we use it:

  1. The heuristic must be 'admissible', i.e. it must never overestimate the distance to the target
  2. 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.

Very likely this is related to #1971.

Activity

  1. michaz commented on May 29, 2022

    @michaz
    Member

    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.

  2. michaz commented on May 29, 2022

    @michaz
    Member

    It's still infeasible though.

  3. easbar commented on Jun 1, 2022

    @easbar
    MemberAuthor

    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.

  4. reopened this on Jun 1, 2022
  5. changed the title [-]LMApproximator does not yield feasible heuristic[/-] [+]LMApproximator does not yield (approximately) feasible heuristic on QueryGraph[/+] on Jun 1, 2022
  6. easbar commented on Jun 2, 2022

    @easbar
    MemberAuthor

    Let u be any node, t the target node and LM a landmark node. Then according to the triangle inequality we have for the distances between these nodes:

    d(u, t) + d(t, LM) >= d(u, LM)
    

    and it follows that

    d(u, t) >= d(u, LM) - d(t, LM) =: h(u)
    

    The heuristic h(u) is feasible as:

    d(u1, u2) + h(u2) = d(u1, u2) + d(u2, LM) - d(t, LM) >= d(u1, LM) - d(t, LM) = h(u1)
    

    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:

    d(v, LM) = min(d(v, A)+d(A, LM), d(v, B)+d(B, LM))
    

    so we can define the heuristic of the virtual node as:

    h(v) := min(d(v, A)+d(A, LM), d(v, B)+d(B, LM)) - d(t, LM)
    

    for which we have:

    d(v,t) >= h(v)
    

    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.

  7. easbar commented on Jun 2, 2022

    @easbar
    MemberAuthor

    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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions