Skip to content

Make EdgeAccess#INT_DIST_FACTOR configurable #1688

Open

Description

@boldtrn

Currently, the max distance of an edge is roughly 1000km. There are cases where this is not enough, especially when using a different datasource than OSM.

Would it make sense to make the INT_DIST_FACTOR configurable?

Related to #1663.

Activity

  1. easbar commented on Aug 18, 2019

    @easbar
    Member

    Would it not suffice to set INT_DIST_FACTOR to 10 ? In this case the minimum distance that is not considered to be zero would be increased from 0.5mm to 5cm (should not be relevant ?) and the maximum distance would be increased from about 2147km to 214748km. The problem with changing the value lies mostly in adjusting the failing tests (I guess 99% rounding issues and/or hard coded expected distances that need to be adjusted), but this would be rather annoying if the conversion factor would not be fixed.

  2. boldtrn commented on Aug 18, 2019

    @boldtrn
    MemberAuthor

    This would fix at least my scenario perfectly @easbar 👍

  3. boldtrn commented on Aug 18, 2019

    @boldtrn
    MemberAuthor

    Should I provide a PR? Could there be other downsides? Probably there was a reason why the factor is so big?

  4. changed the title [-]Make EdgeAccess#INT_DIST_FACTOR confirgurabel[/-] [+]Make EdgeAccess#INT_DIST_FACTOR configurable[/+] on Aug 19, 2019
  5. easbar commented on Aug 20, 2019

    @easbar
    Member

    The problem with changing the value lies mostly in adjusting the failing tests

    Now I thought about this again I am not sure anymore...

    Could there be other downsides?

    Likely there will be some more rounding issues, and we probably have to identify the places where the (rounded) distances are compared to the precise ones ? For example for AStar we might be comparing the (rounded) edge-distance with the precise result of calcDist(lat, lon). For CH we are storing the sum of several (rounded) edge-distances as (rounded) distance of the shortcut. For QueryGraph there can be a mismatch between the edge distance and the sum of the distances of the virtual edges. These issues already exist, but might get worse for a lower distance precision ? I am not sure to be honest. Maybe we need to try fixing the tests and see what complications arise.

    Ultimately the best solution might be to use 0.1m as distance unit and integer values all across GH (already during data import, calcDist(lat,lon) etc.) and only convert it to meters where the result is shown to the user (?). I guess it is the 'do not use floating point numbers where exact answers are required' type of problem.

  6. karussell commented on Aug 20, 2019

    @karussell
    Member

    Ultimately the best solution might be to use 0.1m as distance unit and integer values all across GH

    This one I do not understand as rounding issues can sum up even with integers (?)

  7. boldtrn commented on Aug 20, 2019

    @boldtrn
    MemberAuthor

    For example for AStar we might be comparing the (rounded) edge-distance with the precise result of calcDist(lat, lon)

    Could we round the results from calcDist? So that we are comparing two rounded distances?

  8. easbar commented on Aug 20, 2019

    @easbar
    Member

    This one I do not understand as rounding issues can sum up even with integers (?)

    At least with integers we have no rounding issues for summation (like in CH shortcuts), no ? For cases where we compare distances that were calculated with calcDist(lat, lon) it is indeed more complicated than just switching to int. For example when we split an edge during QueryGraph#lookup we might be able to first calculate the distances of the virtual edges states and then adjust them such that the sum is the same as the distance of the edge we split. For AStar distance comparisons we could use an offset, because it is ok to overestimate the distance (just not underestimate it), etc. It definitely depends on the situation, but with integers at least we get a chance to use the 'right' value whereas with floating point numbers there is always some uncertainty involved.

  9. easbar commented on Aug 20, 2019

    @easbar
    Member

    Could we round the results from calcDist? So that we are comparing two rounded distances?

    Yes, but the question is sometimes how often we do the rounding. Lets say the real distance of an edge (according to calcDist) is 3.68m. Then we round it to 3.7m or 37 in units of 0.1m. When we split this edge in QueryGraph maybe the two virtual edges have (according to calcDist) distance 3.038m and 0.642m. When we apply the rounding this will be 3.0m and 0.6m so the sum would be 3.6m instead of 3.7m...

  10. boldtrn commented on Aug 20, 2019

    @boldtrn
    MemberAuthor

    When we apply the rounding this will be 3.0m and 0.6m so the sum would be 3.6m instead of 3.7m...

    Do you think that there will be serious issues because of that? If I understand this correctly, for every waypoint the distance can be off by ~ .1m.

  11. karussell commented on Aug 20, 2019

    @karussell
    Member

    but with integers at least we get a chance to use the 'right' value whereas with floating point numbers there is always some uncertainty involved.

    Can you explain what you mean here? Let us assume a simple graph where the task is to calc route from A to C:

    A-B-C and A-D-C. Now if edge AB is 0.24, BC is 0.14, AD is 0.15 and DC is 0.15 the sum of rounded distance is always 0.3 i.e. it picks the first and longer result ABC. How will integers with 0.1m unit help to make something better (prefer ADC) than a double value that is rounded to 0.1?

    When thinking about all this I'm now more hesitating if we really want to make rounding issues more likely only to tweak this internal factor. Instead maybe we should think about storing the distance in more than 31 bits? A simple fix would be to allow 32 bits. And the second step could be to introduce distance dependent EncodedValues (if perf is ok) that could be then configurable.

    Do you think that there will be serious issues because of that? If I understand this correctly, for every waypoint the distance can be off by ~ .1m.

    I think so, yes. Gets more problematic for longer routes, yes.

  12. easbar commented on Aug 20, 2019

    @easbar
    Member

    A-B-C and A-D-C. Now if edge AB is 0.24, BC is 0.14, AD is 0.15 and DC is 0.15 the sum of rounded distance is always 0.3 i.e. it picks the first and longer result ABC. How will integers with 0.1m unit help to make something better (prefer ADC) than a double value that is rounded to 0.1?

    Maybe you have a typo here ? I am not sure what you mean

    round(0.24)+round(0.14)=0.2+0.1=0.3
    round(0.15)+round(0.15)=0.2+0.2=0.4
    

    or

    round(0.24+0.14)=round(0.38)=0.4
    round(0.15+0.15)=round(0.30)=0.3
    

    In both cases it is not the sum of rounded distance is always 0.3 ?

  13. easbar commented on Aug 20, 2019

    @easbar
    Member

    A simple fix would be to allow 32 bits.

    @boldtrn Would this suffice ? Can you explain in which situation the edges become longer than 2000km btw ?

    And the second step could be to introduce distance dependent EncodedValues (if perf is ok) that could be then configurable.

    Configurable sounds good, but as long as the correctness of the route calculations depends (in some ways) on the precision this is also a bit dangerous ?

    When thinking about all this I'm now more hesitating if we really want to make rounding issues more likely only to tweak this internal factor.

    I think I agree, but the real solution would be to properly deal with the situations where the rounding can be harmful (needs some analysis to find out which ones these are).

  14. karussell commented on Aug 20, 2019

    @karussell
    Member

    ABC: round(0.24)+round(0.14)=0.2+0.1=0.3
    ADC: round(0.15)+round(0.15)=0.2+0.2=0.4

    Ups. I meant 0.05 instead of 0.15 for DC. But this example is even better:
    the algo will choose ABC (0.3 < 0.4) as best path although ADC is shorter when using full precision for the single edge distances (0.38 > 0.30).

    Would 0.1m units help in this case?

  15. easbar commented on Aug 20, 2019

    @easbar
    Member

    Ok, no, units of 0.1m do not help to find the 'better' path ADC, but in this model ABC simply is the shortest path. If we store distances in units of 0.1m there is no way to distinguish between e.g. 0.15m and 0.20m anymore. As we see here, which path is 'better' depends on how we distribute the real distance over the single edges. For example another path AEFC = round(0.14) + round(0.02) + round(0.14) = 0.2 would have the same length as ADC in the real world, but come out as the shortest path in our model (with a 'wrong' distance of 0.2 instead of 0.3).

    In any case, the conversion from real-world distances to our discrete model causes an error and whether or not this is acceptable depends on the precision we need. For example the distance of a path with 1000 edges can be off by 1000*0.05m=50m compared to its real-world counterpart (in the (unlikely) worst case). This error can only be controlled by the precision we use to represent distances in our model (and it does not play a role whether we use integers or doubles (that later get converted to 4byte numbers)).

    However, in my opinion using integer distances internally is still advantageous, because at least after the initial conversion from the real-world distances to the internal units the calculations are (or at least can be made) exact. Right now we not only introduce an error when converting real-world distances to internal distances (in EdgeAccess#distToInt during import), but also when we do things like taking some distances from storage, 'casting' them to double, adding them and writing them back to storage (again using distToInt), like in CH shortcuts. When we stay in the internal int representation my hope would be that we can make all internal computations exact. For example if we split an edge into two virtual edges (see my example above) we can adjust the distances of the two virtual edges such that their sum exactly matches the distance of the original edge whereas with double values we can still never be sure that dist(virtualEdge1)+dist(virtualEdge2)==dist(edge), especially after writing the results back to storage (calling distToInt again).

  16. easbar commented on Aug 20, 2019

    @easbar
    Member

    Do you think that there will be serious issues because of that?

    I am not sure tbh.

  17. boldtrn commented on Aug 20, 2019

    @boldtrn
    MemberAuthor

    @boldtrn Would this suffice ? Can you explain in which situation the edges become longer than 2000km btw ?

    There are scenarios, other than regular OSM road routing that require longer edges. For example flights, ship routes, etc.

    For example for flights we should be able to create edges that are ~20,000km (half the equator) long.

    I think so, yes. Gets more problematic for longer routes, yes.

    For example the distance of a path with 1000 edges can be off by 1000*0.05m=50m

    Ah I see, thanks for the explanation. This would indeed be a bit unfortunate.

    So maybe we could consider making the factor configurable? Maybe not even in the config.yml, but at least in a way that allows a 3rd party to change this when using GraphHopper as a lib. Right now, I think it wouldn't be possible to change this factor without forking?

  18. easbar commented on Aug 20, 2019

    @easbar
    Member

    There are scenarios, other than regular OSM road routing that require longer edges. For example flights, ship routes, etc.

    Can you not split these edges into smaller pieces #435 ?

  19. boldtrn commented on Aug 20, 2019

    @boldtrn
    MemberAuthor

    That would be my least preferred option to be honest. For long straight routes, the curvature of the earth plays a major role (geodetic line). I am not 100% sure what happens if you split these lines. But usually, this results in multiple arcs, which would probably result in an incorrect result.

  20. easbar commented on Aug 20, 2019

    @easbar
    Member

    For long straight routes, the curvature of the earth plays a major role (geodetic line).

    Ok, I see. It should def. be possible to do this correctly somehow, but sure this takes some effort as well.

    Maybe we should really use some more bytes for distance and in turn remove distance from CH shortcuts. But also we should clarify what the problematic cases are when we use a higher/lower precision.

  21. karussell commented on Aug 20, 2019

    @karussell
    Member

    For long straight routes, the curvature of the earth plays a major role (geodetic line).

    I think that earth(distA)+earth(distB) == earth(distAB). We already consider this "round earth stuff" in OSMReader via DistanceCalcEarth. So there should not a problem with splitting edges. Do you have examples where this fails @boldtrn?

  22. boldtrn commented on Aug 20, 2019

    @boldtrn
    MemberAuthor

    So there should not a problem with splitting edges. Do you have examples where this fails @boldtrn?

    I just checked, the splitting could work, if you calculate the coordinates on the arc precisely. I was mostly concerned about the visualization part when splitting edges, but that works as well.

    At least for my case, this would make things complicated though. Most of the edges are > 1000km. So splitting would significantly raise the number of edges and nodes. Probably also slow down the route calculation, since there would be more edges.

  23. easbar commented on Sep 10, 2019

    @easbar
    Member

    CH shortcut distances are gone so no need to worry about them here anymore, #1719

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions