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
Using 0.1m as distance unit should be sufficiently precise also for indoor routing and the maximum distance would still be sufficiently large: 214748km so more than five times the circumference of the earth. IMO using integers is more comfortable and prevents rounding / comparison issues.
Yes changing the distance factor, but also I think distances should be stored as ints and any int/double conversion should happen somewhere in the top layer (osm import / user api), so internally all distances are ints.
Or in some places as karussell suggested in #1661:
For edge.getDistance it could be valuable to investigate if we can include it in IntsRef. (btw: there is an interesting difference to e.g. max_speed or road_class then: the distance needs to be splitted for the virtual edges in the QueryGraph. And that is also the reason I did not try this yet ;) )
Ah, now I understand it. Now I am not so sure if I think this is a good idea :). This change could require significant changes for everyone using GraphHopper as a dependency and would make using it feel a bit cumbersome.
For example many existing FlagEncoders oder custom weightings could break due to that.
What improvements do you expect from this change? Better memory efficiency of 4 vs 8 bytes and better performance by avoiding the conversion from int to double?
If that's the case, it might make sense to have an internal method like getIntDistance and the regular getDistance? So we could use the int on the low level where performance is of the essence and use the convenient version where performance is not that critical?
I think my vision would be to interpret the 4 bytes we are using for distance in EdgeAccess at the moment as integer number that tells us the distance as multiple of 0.1m. I think the main advantage of
using int over double/float is that floating point numbers are never exact, and we have to include error margins etc. when comparing them.
At the same time I fully agree that having EdgeIteratorState#getDistance() return the distance in multiples of 0.1m would be very ugly, because it would result in x10 errors in existing code without giving a compiler error or similar.
So maybe having an internal method int getIntDistancel() for the edge iterator as you suggest could be a good solution, yes.
Better memory efficiency of 4 vs 8 bytes
Yes, in a few cases this might make a difference, not with storage, because we are already using only 4 bytes, but sometimes we keep many distances in memory.
better performance by avoiding the conversion from int to double?
Hmm, I do not think the conversion is critical for performance, but haven't really tried either.
and would make using it feel a bit cumbersome.
Do you think dealing with int in general is more cumbersome than with double ? I do not see a reason why this would be the case (except one has to pay some attention with division). In most cases int will be auto-cast to double anyway ? Or do you mean dealing with 0.1m as unit is cumbersome ? This is of course very awkward and I agree that on the public API level there should be methods returning the distance in meters.
Hmm, I do not think the conversion is critical for performance, but haven't really tried either.
I haven't profiled it either. IIRC when calculating CH we would call the getDistance method quite often? If this method can avoid an unnecessary division, I guess there could be a minor performance boost. Probably not worth the effort though.
Or do you mean dealing with 0.1m as unit is cumbersome ?
So maybe having an internal method int getIntDistancel() for the edge iterator as you suggest could be a good solution, yes
If distance would be implemented also as an EncodedValue we would automatically get such a method:
edge.get(distance_enc) // returns meters as double using UnsignedDecimalEncodedValue
edge.get((IntEncodedValue)distance_enc) // returns multiples of 0.1 as int using UnsignedIntEncodedValue
But already without this, the change from 1000 to 10 is hard: several tests break :(
In some cases even a different route is returned.
Activity
boldtrn commentedon Jul 19, 2019
I think that's a good idea! If I understand this correct, this would mean changing the INT_DISTANCE_FACTOR in EdgeAccess to 10?
easbar commentedon Jul 19, 2019
Yes changing the distance factor, but also I think distances should be stored as ints and any int/double conversion should happen somewhere in the top layer (osm import / user api), so internally all distances are ints.
Or in some places as karussell suggested in #1661:
boldtrn commentedon Jul 19, 2019
Ah, now I understand it. Now I am not so sure if I think this is a good idea :). This change could require significant changes for everyone using GraphHopper as a dependency and would make using it feel a bit cumbersome.
For example many existing FlagEncoders oder custom weightings could break due to that.
What improvements do you expect from this change? Better memory efficiency of 4 vs 8 bytes and better performance by avoiding the conversion from int to double?
If that's the case, it might make sense to have an internal method like getIntDistance and the regular getDistance? So we could use the int on the low level where performance is of the essence and use the convenient version where performance is not that critical?
easbar commentedon Jul 19, 2019
I think my vision would be to interpret the 4 bytes we are using for distance in
EdgeAccessat the moment as integer number that tells us the distance as multiple of0.1m. I think the main advantage ofusing int over double/float is that floating point numbers are never exact, and we have to include error margins etc. when comparing them.
At the same time I fully agree that having
EdgeIteratorState#getDistance()return the distance in multiples of0.1mwould be very ugly, because it would result in x10 errors in existing code without giving a compiler error or similar.So maybe having an internal method
int getIntDistancel()for the edge iterator as you suggest could be a good solution, yes.Yes, in a few cases this might make a difference, not with storage, because we are already using only 4 bytes, but sometimes we keep many distances in memory.
Hmm, I do not think the conversion is critical for performance, but haven't really tried either.
Do you think dealing with int in general is more cumbersome than with double ? I do not see a reason why this would be the case (except one has to pay some attention with division). In most cases int will be auto-cast to double anyway ? Or do you mean dealing with
0.1mas unit is cumbersome ? This is of course very awkward and I agree that on the public API level there should be methods returning the distance in meters.boldtrn commentedon Jul 19, 2019
Thanks for the explanation!
I haven't profiled it either. IIRC when calculating CH we would call the getDistance method quite often? If this method can avoid an unnecessary division, I guess there could be a minor performance boost. Probably not worth the effort though.
Yes, that's what I mean with cumbersome.
karussell commentedon Aug 12, 2019
If distance would be implemented also as an EncodedValue we would automatically get such a method:
But already without this, the change from 1000 to 10 is hard: several tests break :(
In some cases even a different route is returned.