Repository navigation
Implements correct time calculation for edge-based CH. - #1611
Conversation
| protected void processEdgeBwd(int edgeId, int adjNode, int nextEdgeId) { | ||
| EdgeIteratorState edge = graph.getEdgeIteratorState(edgeId, adjNode); | ||
| distance += edge.getDistance(); | ||
| // special case for loop edges: since they do not have a meaningful direction we always need to read them |
There was a problem hiding this comment.
Here I wonder if we should do the loop-handling within calcMillis. But maybe in a separate PR along with u-turn cleanup.
| return; | ||
| } | ||
| if (weighting instanceof TurnWeighting) { | ||
| time += ((TurnWeighting) weighting).calcTurnWeight(inEdge, viaNode, outEdge) * 1000; |
There was a problem hiding this comment.
Casting here is ugly, I wonder if calcTurnWeight should be in the Weighting interface.
There was a problem hiding this comment.
btw: instanceof was really expensive, so having it here would be ugly as this is kind of a loop. But in recent JVMs (at least server-side) this shouldn't be a problem
| * Equivalent to java 8 String#join | ||
| */ | ||
| public static String join(String delimiter, List<String> strings) { | ||
| StringJoiner joiner = new StringJoiner(delimiter); |
There was a problem hiding this comment.
That would cause problem on Android compatibility, since StringJoiner being a Java 8 class, was added in API level 24 (Android 7 Nougat).
There was a problem hiding this comment.
Oh right! Thanks for pointing this out, will replace.
| expandEdge(sk2, !reverseOrder); | ||
| expandEdge(sk1, reverseOrder); | ||
| } | ||
| private void expandSkippedEdgesNodeBased(int skippedEdge1, int skippedEdge2, int base, int adj, boolean reverse) { |
There was a problem hiding this comment.
I changed this in the following way: Previously we got the CHEdgeIteratorState like this: base<-mid->adj and then passed on the reverse flags such that the base<-mid edge was read 'in reverse'/base->mid. Now I get the states like this: base->mid->adj from the beginning, which I think makes it a lot easier to understand.
| // since the first/last orig edge is not stateful (just like skipped1/2) we have to find out which one | ||
| // is attached to adjNode, similar as we do for skipped1/2. | ||
| // todo: it is wasteful to create a CHEdgeIteratorState object just to check which edge we have to use! | ||
| return graph.getEdgeIteratorState(edgeState.getOrigEdgeLast(), adjNode) == null |
There was a problem hiding this comment.
Maybe add a special method to CHGraph here to prevent creating the edge iterator state object ?
There was a problem hiding this comment.
done, by adding isAdjacentNode method to Graph.
| tmpEdge = currEdge.edge; | ||
| } | ||
|
|
||
| private void extractBwdPath() { |
There was a problem hiding this comment.
I changed the way the edges are traversed here to make sure we are always in the same situation as in the backward search: adj-->base-nextEdgeId. Otherwise the 'incEdge' of the prev/next SPTEntry would not be the one we need to calculate the turn cost.
| "never happen because edge-based CH does not use bidirectional shortcuts at the moment"; | ||
| CHEdgeIteratorState sk1 = getEdge(skippedEdge1, sk2.getBaseNode()); | ||
| if (base == adj && (sk1.getAdjNode() == sk1.getBaseNode() || sk2.getAdjNode() == sk2.getBaseNode())) { | ||
| throw new IllegalStateException(String.format(Locale.ROOT, |
There was a problem hiding this comment.
Does this never happen because we remove loops in the import? Or this is something else as we still have loop support elsewhere like in getShortcutUnpacker?
There was a problem hiding this comment.
I think a skipped edge that is a loop is impossible unless there is a bug in CH preparation. I think this check has been there more or less since the very beginning and I think I never saw this error :)
There was a problem hiding this comment.
I did not see this error before and after we excluded loops during import.
There was a problem hiding this comment.
Regarding loop support I think our algorithms can handle them in most cases but what is not possible is to decide in which direction a loop should be read (problematic when there is geometry or different fwd/bwd speeds etc.)
There was a problem hiding this comment.
Ok, thanks for the explanation!
(problematic when there is geometry or different fwd/bwd speeds etc.)
Should we create a separate issue for this? I think there is a solution (although not without problems) #1525 (comment)
There was a problem hiding this comment.
Yes! And another one for some turn-cost cleanup stuff, like u-turn in calcMillis and calcTurnCost in Weighting. Will do.
There was a problem hiding this comment.
Thanks, so from my perspective you can merge (have not fully understood everything but is also not required yet ;) )
There was a problem hiding this comment.
Ok thanks for the review! The changes in shortcutunpacker and pathbidirref are really not easy to understand without thinking about it in detail, sketching some examples etc. Was not so easy to get it right to be honest. I might post a little drawing to make it clear.
This PR adjusts the path unpacking such that turn cost times are included (previously they were ignored) for edge-based CH, see #1585.