Repository navigation
Adds new fail-fast option to hand-crafted matrix client. - #1661
Conversation
# Conflicts: # client-hc/src/main/java/com/graphhopper/api/GHMatrixSyncRequester.java
# Conflicts: # client-hc/src/test/java/com/graphhopper/api/GraphHopperGeocodingIT.java
# Conflicts: # client-hc/src/main/java/com/graphhopper/api/GHMRequest.java
|
|
||
| JsonNode distancesFromArray = null; | ||
| int[] distances = null; | ||
| double[] distances = null; |
There was a problem hiding this comment.
this was cast to int for a moment and later its a double again so I changed this.
There was a problem hiding this comment.
But why would we need double here (8 byte) when storing distances in int meter is sufficient (0 to 10 000 000)?
There was a problem hiding this comment.
Yes, as we discussed before it would be best to store distances as ints in units of 0.1m. In this case precision should be sufficient also for indoor stuff and the maximum distance should be enough also for very long shortcut edges. Here I changed this to double because the numbers stored were retrieved as floating point numbers (from json) and also MatrixResponse#getDistance() returns a double. Whatever you like better I can change this back to int as well. In the long run we should switch all distances to ints in my opinion.
There was a problem hiding this comment.
Yeah, I would keep this as int[] here.
IMO we should differentiate between storage and API. The Java API should stay as double and only the storage should be int (or less), especially when we keep this in RAM for a bit longer. 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 ;) )
There was a problem hiding this comment.
Ok I changed back to int[]. Also opened #1663.
| private String debugInfo = ""; | ||
| private final List<Throwable> errors = new ArrayList<>(4); | ||
| private final List<PointPair> disconnectedPoints = new ArrayList<>(0); | ||
| // todonow: should we add hppc to classpath and use IntArrayList instead ? |
There was a problem hiding this comment.
Yeah those cases of small objects in a list are ultra memory waste but we should improve this later if this makes a problem for bigger matrices.
There was a problem hiding this comment.
we could even return an int[], but I do not think its so critical here.
|
|
|
|
||
| public static class PointPair { | ||
| private final int sourceIndex; | ||
| private final int targetIndex; |
There was a problem hiding this comment.
(public final would be also fine for those structs allowing as to avoid the getter stuff)
| throw new IllegalStateException("Cannot get 'to' " + to + " from distances with size " + distances[from].length); | ||
| } | ||
| return distances[from][to]; | ||
| return distances[from][to] == Integer.MAX_VALUE ? Double.MAX_VALUE : distances[from][to]; |
There was a problem hiding this comment.
oh, thx - this is a good catch 👍
There was a problem hiding this comment.
Shouldn't it better map to infinity instead of Double.MAX_VALUE?
There was a problem hiding this comment.
Or the other way around: disconnected is null (i.e. "infinity" gets serialized into null) and should be back in Java world infinity (?)
(Oh, but this should be only done for failFast==false?)
There was a problem hiding this comment.
Yes previously this case never occurred because there would have been an error if points were not connected. Now we have this case if failFast==false, yes. Hm not sure about infinity vs. max. For time we also return Long.MAX_VALUE.
There was a problem hiding this comment.
The 'impossible' weight is Double.MAX_VALUE on the server side as well (so far). The same for Path#weight:
graphhopper/core/src/main/java/com/graphhopper/routing/Path.java
Lines 72 to 74 in c43d03e
There was a problem hiding this comment.
Ugh yeah either way its in a way inconsistent :( Maybe the only good thing is that it is not so critical, because normally when hasProblems()==true we can use getDisconnectedPoints() to check which connections are missing (instead of checking getWeight(3, 5) == Double.MAX_VALUE`.
There was a problem hiding this comment.
Do you prefer one over the other, I do not have a strong opinion about this and either way is fine for me.
There was a problem hiding this comment.
because normally when hasProblems()==true we can use getDisconnectedPoints() to check which connections are missing (instead of checking getWeight(3, 5) == Double.MAX_VALUE`
This seems like the best solution to force or promote the usage of disconnected points in this cases (or have a convenience method like isConnected(from, to))
There was a problem hiding this comment.
Yes having isConnected(from, to) is a very good idea, if we have this there should not really be a reason to check something like getWeight(3,5)==Double.MAX_VALUE and we only do this internally making the concrete 'impossible value' even 'less important'. Will do.
|
What kind of response should we expect if |
Good question. On the one hand I would not expect something special but if everything fails it would be also fine (and I have a tiny preference here) if this counts as an error and we do not have to return a large matrix where all indices are included in the "failed" array. But maybe then this should be a special message and explicitly documented? |
yes, but probably this case is rather rare ?
What is a bit ugly I think is that one has to handle this special case on the client side and there is not much information that can be used to recognize this case other than the actual error message (unless we use a dedicated http status, but this also makes it more complicated). Also the reason why the connections were not found is not always clear. Something like So we should at least keep the lists of invalid points on the response. But checking the error message is still ugly ? Maybe it is more clear to just blindly return the matrix full of nulls and return the full list of invalid points and disconnected points (even when its the whole matrix) as usual ? UpdateWe went with the matrix full of nulls. |
|
Looks like the backend is supporting this now, the tests are green :) |
With this PR we can disable the 'fail fast' option for matrix requests which means that the matrix calculation is not cancelled as soon as some points cannot be found or some points are not connected.
Instead, the full matrix is returned and the matrix entries that involve points that were not found and those for which no connection could not be found will be set to
Double.MAX_VALUEfor weight and distance andLong.MAX_VALUEfor time. Additionally,MatrixResponsenow has two arrays of the indices of the from/to points that could not be found and another list of index pairs of the points for which no connection could be found.In code: