Repository navigation
Conversation
|
The trick here was again the +1 for via points. The issue is described in #1139. Since our merge method corrected most issues at via points by merging the last and first PathDetail of adjacent Paths, if they have the same value. Therefore, this issue only pops up if the last PathDetail of one Path has a different value than the first PathDetail of the next Path. The test has a via point that is placed exactly between two edges, with different speed values. |
| if (!pathDetails.isEmpty() && !otherDetails.isEmpty()) { | ||
| PathDetail lastDetail = pathDetails.get(pathDetails.size() - 1); | ||
| // Add +1 for the via point | ||
| lastDetail.setLast(lastDetail.getLast()+1); |
There was a problem hiding this comment.
Hmmh, this feels wrong and we should probably skip adding the via points opposed to my recent comment in #1139?
| if (pathIndex + 1 < paths.size()) { | ||
| ViaInstruction newInstr = new ViaInstruction(fullInstructions.get(fullInstructions.size() - 1)); | ||
| newInstr.setViaCount(pathIndex + 1); | ||
| // Similar to the FinishInstruction, ViaInstructions have lenght=0 |
There was a problem hiding this comment.
We could also enforce this during the Finish Instruction creation here
There was a problem hiding this comment.
I do not fully understand it. The ViaInstruction and FinishInstruction both should have one point, why is setting to an empty list necessary? And why do we still need this viaPosition/viaCount workaround?
There was a problem hiding this comment.
As I understood it, they should have no points. If they have no points, we create intervals like [9,9]. If there is one point, we create an interval [9,10]. If we leave the point, we have to create a workaround for the simplification as well as for the serialization.
There was a problem hiding this comment.
I just updated the PR to show an alternative approach. Now the Instructions contain one point, but we ignore these points during the simplification and serialization. I think it looks a bit cleaner like this.
There was a problem hiding this comment.
If there is one point, we create an interval [9,10]
But that is two points?
If we leave the point, we have to create a workaround for the simplification as well as for the serialization.
Why? Simplification should be disabled for <3 points.
There was a problem hiding this comment.
But that is two points?
No. The second point ref of the interval is equal to the first point of the next interval. Intervals are generated by [ START_REF, START_REF + POIN_COUNT ] for all Instructions,
expect the FinshInstruction where we artificially set the point count to 0 in the SimpleRouteSerializer. This PR enforces this behavior for all ViaInstructions and FinishInstructions.
Due to that they don't have their own point in the points array. That's why we have to create the workaround with lenght=0 in the PathSimplification.
There was a problem hiding this comment.
Hmmh. Let me summarize how it should be: every instruction has a first point and a last one, obviously the last point is the first point of the next instruction and the json would be interval:[first_ref,last_ref] and length=last_ref-first_ref. For Finish and ViaInstruction the result is length=0 (due to first==last) and pointlist.size==1 which makes still sense to me.
Everything which contradicts to this should be fixed e.g. the current ViaInstruction interval etc. and/or make the Instructions like the JSON output (and also PathDetails).
| this.add(points, 0, points.size()); | ||
| } | ||
|
|
||
| public void add(PointList points, int from, int to) { |
There was a problem hiding this comment.
I added this method to have a better performance compared to first copy the PointList and then add it.
There was a problem hiding this comment.
Looks good. Another idea would be removeLast via size--
There was a problem hiding this comment.
You are right, might be the better solution. I did it like this, because at first I wanted to remove the first point of the PointList, which turned out to be the worse approach :). Once it was implemented doing the other war around worked easy. Should we switch to the removeLast approach?
There was a problem hiding this comment.
I'm fine with the current state
|
I updated this PR to remove the duplicated point in the PointList |
| this.add(points, 0, points.size()); | ||
| } | ||
|
|
||
| public void add(PointList points, int from, int to) { |
There was a problem hiding this comment.
Looks good. Another idea would be removeLast via size--
| if (pathIndex + 1 < paths.size()) { | ||
| ViaInstruction newInstr = new ViaInstruction(fullInstructions.get(fullInstructions.size() - 1)); | ||
| newInstr.setViaCount(pathIndex + 1); | ||
| // Similar to the FinishInstruction, ViaInstructions have lenght=0 |
There was a problem hiding this comment.
I do not fully understand it. The ViaInstruction and FinishInstruction both should have one point, why is setting to an empty list necessary? And why do we still need this viaPosition/viaCount workaround?
| if(instruction instanceof ViaInstruction) | ||
| size = 0; | ||
| else | ||
| size = instruction.getPoints().size(); |
There was a problem hiding this comment.
Here I would expect 'getPoints.size-1' for both cases
There was a problem hiding this comment.
For the ViaInstruction it shouldn't matter as it should be only one point anyway. For the other case it should be the size IMHO. Could you explain why it should be size-1?
There was a problem hiding this comment.
Consistency. All path details currently work this way: you specify first and last and the length is last-first. Now imagine an instruction 0-1-2-3-4, where e.g. at 3 there is the via point, then the first instruction includes point 3, i.e. it is interval:[0,3] and therefor the length is 3-0=3, although the pointlist.size is 4.
| @@ -99,8 +99,6 @@ public void doWork(PathWrapper altRsp, List<Path> paths, Translation tr) { | |||
| if (pathIndex + 1 < paths.size()) { | |||
| ViaInstruction newInstr = new ViaInstruction(fullInstructions.get(fullInstructions.size() - 1)); | |||
| newInstr.setViaCount(pathIndex + 1); | |||
There was a problem hiding this comment.
can we remove setViaCount as getViaCount is unused?
There was a problem hiding this comment.
can we remove setViaCount as getViaCount is unused?
The viaCount is used in the getTurnDescription mehtod of the ViaInstruction.
There was a problem hiding this comment.
Ah, ok. Makes sense. Is it possible to move this to the constructor and remove the getViaCount getter?
|
I just updated this PR. The latest push is only WIP, and it's not even building. I just commited to show you the current approach I am taking. Essentially I tried to remove everything point related and move it up to the InstructionList, so the InstructionList contains the whole PointList for a Path and can get Points for a single Instruction. The Instruction only stores references. This breaks the current API, but I think it's a nice improvement :). Let me know what you think or if we should follow a different Path. |
karussell
left a comment
There was a problem hiding this comment.
Yes, I think this is more consistent in a few places and already align with the JSON API - thanks!
| public FinishInstruction(PointAccess pointAccess, int node) { | ||
| this(pointAccess.getLatitude(node), pointAccess.getLongitude(node), | ||
| pointAccess.is3D() ? pointAccess.getElevation(node) : Double.NaN); | ||
| public FinishInstruction(int pointRef) { |
There was a problem hiding this comment.
Is pointRef == last == first for the FinishInstruction?
| this.name = name; | ||
| this.points = pl; | ||
| this.annotation = ia; | ||
| this.first = first; |
There was a problem hiding this comment.
No, as we change the first reference during the simplification. I would have liked that as well.
| return AC.calcAzimuth(lat, lon, nextLat, nextLon); | ||
| public int getLast() { | ||
| if (last < first) | ||
| throw new IllegalStateException("last cannot be smaller than first"); |
There was a problem hiding this comment.
checkOne can be used or is unused?
| this.points = points; | ||
| } | ||
|
|
||
| public PointList getPoints(Instruction instruction) { |
There was a problem hiding this comment.
Maybe a different name or some javadocs are important to see the difference between this method and getPoints()?
There was a problem hiding this comment.
Yes certainly, it's still pretty raw and I am trying to get everything working, as it might involve bigger changes at some points in the code (not 100% sure yet).
| fullWeight += path.getWeight(); | ||
| if (enableInstructions) { | ||
| InstructionList il = path.calcInstructions(tr); | ||
| InstructionList il = path.calcInstructions(tr, origPoints); |
There was a problem hiding this comment.
A better name now for origPoints might be origPointCount (?) as I initially thought it is the full PointList that must be injected into every InstructionList ...
| if (o instanceof Instruction) { | ||
| first = ((Instruction) o).getFirst(); | ||
| last = ((Instruction) o).getLast(); | ||
| } |
There was a problem hiding this comment.
here an if&else if might make sense with and else that throws an IllegalStateException as the list is of an unknown type.
There was a problem hiding this comment.
I actually want the Instruction and PathDetail implement the same interface, that all provide getLast, getFirst, getLength, etc. so we could solve most of this without any instanceof.
There was a problem hiding this comment.
For now I would have no problem with instanceof.
| return viaPosition; | ||
| } | ||
|
|
||
| public void setViaCount(int count) { |
There was a problem hiding this comment.
We still need the viaPosition, the getter is just not used.
There was a problem hiding this comment.
Ups, I see :) ... we still could pass it via the constructor and make it final (?)
| if (instruction.getLength() == 0) | ||
| // Copy does not include the last point | ||
| return this.points.copy(instruction.getFirst(), instruction.getLast() + 1); | ||
| return this.points.copy(instruction.getFirst(), instruction.getLast()); |
There was a problem hiding this comment.
We should always include the last point, even if we break backward compatibility.
| } | ||
|
|
||
| /** | ||
| * Appends the insturctionList to this InstructionList, from instruction index 0 to toIndex |
| foundInstruction = instructionIndex; | ||
| break; | ||
| } | ||
| } |
There was a problem hiding this comment.
Is this logic change of introducing two for-loops necessary or to make it easier?
Thanks for the feedback, I updated the PR. I got everything working except for the gtfs and web module so far. The web module depends on the gtfs module, so I couldn't build it without fixing the gtfs module. @michaz, maybe you can give me a hint on how to fix the issues in the Why is there a special handling for the last leg here? Because of the FinishInstruction? Why do we use What happens here with the replace? Are the points of the |
Yes.
Yes.
No. When we are "inSameVehicleAsPrevious", the previous trip already gave an arrival instruction, but we don't want it, so we overwrite it. We only really arrive now. Those are two trips which, according to the schedule, are technically two trips with two trip numbers, but the user does not know this and doesn't care, so we patch the instructions so that they look like one trip. |
|
Thanks @michaz.
Why is the station instruction needed then? Is this working with the current code? Right now the serialization and deserialization (and probably a lot more code as well) assumes that instructions follow each other and are not mixed.
Would this be the same example as the train switches it's name example as above? |
The test is: GraphHopperGtfsIT.testBlockTrips, and last time I checked, it looked fine in the JS GUI. (No automatic tests for that, though.) Maybe have a look? What is currently supposed to happen in the isSameVehicleAsPrevious-case is just this: For these Legs: create not these instructions but these ... with those instructions covering all the points of the ride. In the normal order. What you see in the code in the loop is (if I remember correctly) processing Leg 1 the normal way (without looking ahead), and when Leg 2 comes, change things to the expected result. Missing luxury feature (please go for it if you have time!): Insert a "Stay in vehicle -- vehicle changes its headsign to C" instruction, located at B. |
| edges(path).map(edgeLabel -> edgeLabel.edgeIteratorState).collect(Collectors.toList()), | ||
| lineStringFromEdges(path), | ||
| edges(path).mapToDouble(edgeLabel -> edgeLabel.distance).sum(), | ||
| instructions.stream().collect(Collectors.toCollection(() -> new InstructionList(tr))), |
There was a problem hiding this comment.
Was there a reason for this, couldn't understand why we are not passing the instructions as created @michaz?
There was a problem hiding this comment.
You're right, that was left over from something. I'm merging this line (for a start :-) ) to master, thanks.
|
Thanks for the clarification @michaz, I understood it slightly different.
This should be fine, and thanks for pointing me towards the test. I finally got the GTFS tests to succeed. Can you live with the changes @michaz? Unfortunately, I wasn't able to do this with a lower impact, as I needed to change more than I would have expected, but maybe there would be a better way to do this? The PR is still WIP BTW :). |
Looks good to me. I mean, yes, it's more code, but on the other hand, The super-cleanest thing of all would probably to have a builder which allows creating instructions with something like the previous syntax, but the new result. But not necessary, from my point. |
|
This PR has been stale for quite a while now. The biggest problem when converting Instructions to contain only indices in contrast to a PointList, it becomes more expensive to work with the points of an instruction. The code became more complicated and there was a measurable slowdown. This might be improvable with updating the InstructionList code, but for now it's probably not worth the effort. In the future it would be still nice to see this feature merged into master. |
|
Hmm, I thought it was ready to merge, wasn't it? I don't even remember, it was so long ago. But look at how much writing and thinking was put in by all of us. I don't even remember what the problem was which it was solving, but if it was solving something substantial, like allowing a corner case which was previously not working in some surprising way, please re-consider merging it. |
Yes parts of this PR (the bug part) has been merged in a separate PR #1240. The new feature part of this PR was to remove the PointList from the Instructions and only store start and end indexes, similar to the PathDetails. In the long term this could allow to remove the difference between PathDetails and Instructions and to declare instructions just a PathDetail. Overall I was also hoping to remove some of the overhead generated by splitting the geometry into the instructions and afterwards merging them again. The problem with this is that it didn't feel good in the code, it made many things more complicated, for which I created some helper methods to hide the more complicated parts. Overall it is harder to work with indexes than with PointLists as you need to update the global PointList. The PR was "working" in a sense that the response looked correct. It was a bit slower than our current approach. Because the InstructionList used many rather "expensive" calls that required us to extract a part of the global PointList. I think this could have been improved and it might become even a bit faster than our current approach. IMHO there was still some work to do to get this to a mergeable state and I am not sure if the required work justifies the benefit? If you want to I can reopen this PR, update it to the current master and do some more tests? |
|
Ohhhhkay, thanks for explaining. That seems fine then. I was only looking at the headline, and that looked worrying to me. Like, when I use a seemingly-general data structure in a certain totally-allowed-looking way, it won't work. Because I'm notoriously the person who wants to use it in exactly that way. ;-) |
|
(Or do we still have that?) |
Do you mean if we still see issues with PathDetails? AFAIK they work fine and I am not aware of any bugs related to them that would prevent anyone from using them or implementing own PathDetails. |
|
Okay cool, thanks! |
I found the issue here. If we place a waypoint at exactly the position where the PathDetails change, the PathDetails are not merged. The index we passed to the PathDetail generation was too big by 1 index. So this was not necessarily a Roundtrip Issue.