Skip to content

Improve instructions - #955

Merged
boldtrn merged 24 commits into
graphhopper:masterfrom
boldtrn:improve_instructions
Mar 23, 2017
Merged

boldtrn merged 24 commits into
graphhopper:masterfrom
boldtrn:improve_instructions

Conversation

@boldtrn

@boldtrn boldtrn commented Feb 20, 2017 •

Copy link
Copy Markdown
Member

This PR intents to improve the current turn instructions. (#94)

Manly this PR tries to solve the following issues:

  • Reduce unnecessary instructions (continue and turns that are actually no turn, but just a street curve).
  • Missing instructions if there is no name change

I made a couple of assumptions and changes the way I would like to receive turn instructions. This is very subjective, some people like more, some people like less.

The basic function is:

  • Force an instruction if annotations are changing (do we want that?)
  • Ignore Continues, unless we are leaving the current street
  • If there is no other turn possible, ignore the turn instruction
  • If there are other turns, and the turn instruction is something else than a slight turn, show the instruction
  • If the instruction is a slight turn, only show it if the other turns contain a slight turn or continue. Otherwise it will be an obvious follow the street situation (this is probably an assumption that others have a different opinion on?)
  • In this case we further check if the ref/name changes or the flags changes

Currently, a lot of tests are failing. I can fix all the failing ITs once, we decided if we want the current behavior like that or not.

My personal opinion on the state of this PR:

It is better as the current approach in most situations. However, there are thousands of edge cases we need to consider¹. For example look at the TODOs, there are cases that just happens very infrequent, but they happen and with some I feel like there is no good solution, without making other cases worse. It mostly happens in dense cities with a lot of streets around. Bicycle and Non-City instructions are pretty good IMHO (haven't found bigger issues yet).

Feedback from others checking the turn instructions for their area would be highly appreciated.

TODO:

¹: Thousands of edge cases sounds like a good case for deep learning.

@boldtrn

boldtrn commented Feb 21, 2017

Copy link
Copy Markdown
Member Author

So the current state is not too bad, IMHO. I tested a lot of random bike routes and compared the generated instructions with the instructions I would have expected according to the map. I'd say that I agree with > 95%. Are there any examples that I should try? I have tested the examples provided #94, but most of them still behave the same, as they were not intended to be improved in this PR. We should definitely find a solution to the above mentioned NEW issue. Not sure if performance is an issue here? Haven't measured my solution, but it obviously needs more resources, than the old solution. It does not feel slower than before (...).

@boldtrn

boldtrn commented Feb 22, 2017

Copy link
Copy Markdown
Member Author

I updated this PR to show Continue instructions if the situation might not be clear. Sometimes they happen too frequent, but haven't found a better way to filter them.

@boldtrn boldtrn self-assigned this Feb 27, 2017
@boldtrn
boldtrn requested a review from karussell February 27, 2017 05:33
@karussell

Copy link
Copy Markdown
Member

I really like the debugging view where all turns have a marker - nice :) !

Also I think the improvement is indeed there and good and will now look into more examples.

@karussell

karussell commented Mar 9, 2017 •

Copy link
Copy Markdown
Member

I tried a bit within Bavaria, Germany.

necessary improvement for this PR

possible improvements

later

@boldtrn

boldtrn commented Mar 10, 2017

Copy link
Copy Markdown
Member Author

@karussell Thanks for the review.

I updated this PR. In order to fix your necessary improvements I had to introduce a new concept: "keep right|left". In theory this should recognize forks, and tell the user if (s)he should go left or right at the fork. This fixes most issues, especially for motorways. Until all clients support the new sign for keeps we could also change the keeps to slight_right|left.

However, this fails sometimes. To make it better I think that I would need the highway type. For example we still miss the right turn here: http://localhost:8989/?point=49.398826%2C11.197751&point=49.39789%2C11.197729&vehicle=car

at the end a right instruction is too much and in the beginning a bug is shown

This example is very interesting: http://localhost:8989/?point=49.912877%2C11.568802&point=49.911965%2C11.56899&vehicle=foot

Most importantly, why does it show turn right, instead of continue? I debugged a bit. The orientation is calculated for the following points with the following orientation:

Orientation:-1.4124066420807577
49.913634357906155,11.568623480989563
49.91265814556162,11.568865624864376

Orientation:0.0
49.91265814556162,11.568865624864376
49.91265814556162,11.568865811128894

Orientation:-1.41231436135386
49.91265814556162,11.568865811128894
49.91196980109481,11.569036649239916

The second orientation is calculated for two points that are almost identical. Not sure if GH creates a very small edge in this case? Due to this GH thinks that there is a right turn, with two possible turns, so the right turn is displayed.

here should be a left turn instruction but bike has this instruction!?

Probably the bike instruction was due to an annotation? Should be fixed with my new commit anyway.

foot is allowed in any direction around the roundabout and we have to tell this in the turn instruction explicitly if in opposite direction

Haven't touched roundabouts in this PR. Maybe we should create a new issue for this?

the right turn is ambiguous http://localhost:8989/?point=49.94869%2C11.514546&point=49.949504%2C11.513452&locale=de&vehicle=foot

That's true, but I am not sure if this would be fixable. You could also walk straight ahead, so you are shown the instruction to turn right onto this foot path. From a data perspective this turn instruction is correct. This might be misleading for a user though.

the left turn is ambiguous

How would you fix that? I think this is the typical example where people turn wrong. GPS is not exact enough, so you have to study the map closely.

if turns are <10m away should we consider merging them or how to properly guide a walking person?

Shouldn't this be the job of the navigation engine? I think we show the correct turns here. A navigation engine might check if instructions are close together and merge them like: "turn left and after 10 m turn right".

start direction should contain north/west/south/east, finish should contain an indication which side of the road the destination is

That's a good idea. Maybe put this into a different PR as well?

Comment thread web/src/main/webapp/js/instructions.js Outdated
// Debug Turn Instructions more easily
L.marker([lngLat[1], lngLat[0]], {
draggable: true
}).addTo(mapLayer.getRoutingLayer()).bindPopup(title);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we always enable turn instruction debugging via an URL parameter debug_instruction=true or something? Also printing a marker for every instruction is really helpful (but not for the normal public audience of course ;))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, added that feature.

@boldtrn

boldtrn commented Mar 16, 2017

Copy link
Copy Markdown
Member Author

I've just realized that the improved instructions fail for the DataFlagEncoder. The improved instructions use the getSpeed method, which is not implemented for the DataFlagEncoder. What should we do about that?

@boldtrn

boldtrn commented Mar 16, 2017 •

Copy link
Copy Markdown
Member Author

I updated this PR to show the instructions nodes only when passing debug_instructions=true. Also also used a smaller icon to make it more usable.

@karussell

Copy link
Copy Markdown
Member

What should we do about that?

Probably it is time to refactor something else before this change. Because getSpeed is not something the FlagEncoder can know and only a configured Weighting does. Hmmh.

@boldtrn

boldtrn commented Mar 16, 2017

Copy link
Copy Markdown
Member Author

Probably it is time to refactor something else before this change. Because getSpeed is not something the FlagEncoder can know and only a configured Weighting does. Hmmh.

I think we need a different sort of logic for the DataFlagEncoder anyways, as it contains the HighwayType and so on. So I could try and see if I can create some special code block for the DataFlagEncoder?

Not very nice but probably the best choice right now?

@boldtrn

boldtrn commented Mar 18, 2017

Copy link
Copy Markdown
Member Author

I updated this PR. I added a fix for the DataFlagEncoder. We might have slightly more instructions for the DataFlagEncoder compared to the other Encoders. We might show instructions where they are not necessary, but we don't ignore any instructions. The speed is currently only used to omit instructions that seem to be not relevant.

In a future PR, we should improve the instructions for the DataFlagEncoder using also the highway tag and maybe even calculate the actual speed for every edge. I will open a separate issue for this.

The good thing is we don't have to defer this PR and can use the improved instructions.

while (edgeIter.next()) {
tmpSpeed = encoder.getSpeed(edgeIter.getFlags());
if (encoder instanceof DataFlagEncoder) {
tmpSpeed = ((DataFlagEncoder) encoder).getMaxspeed(edgeIter, 0, false);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we have the weighting in the Path class available, would it be somehow possible to use it here instead? E.g. edgeIter.getDistance/calcMillis?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be, yes. I am a bit afraid of rounding issues, as I am comparing these values, but sure, I can try that. OTOH I think we need a different logic for the DataFlagEncoder. We need to consider the highway tag and speed becomes rather unimportant (maybe we only need to check speed with a low priority, whereas for the other encoders speed is important for the instruction generation.

@boldtrn

boldtrn commented Mar 22, 2017

Copy link
Copy Markdown
Member Author

Currently problematic remains this Route:

http://localhost:8989/?point=49.398826%2C11.197751&point=49.39789%2C11.197729&vehicle=car

But the current version of GH has the same issue, so this is no regression:

https://graphhopper.com/maps/?point=49.398826%2C11.197751&point=49.39789%2C11.197729&vehicle=car

I think we should be aware of these things and try to improve them, but from a data point of view this is hard to solve. With highway tags this would be easy to solve. However, this need a different logic, so I think we should do this separately for the DataFlagEncoder. After some consideration I think we should do the DataFlagEncoder Optimization in a completely different branch. The DataFlagEncoder instructions are improved by this PR, but not as much as the other encoders.

Things I've seen during testing:

Something I have changed is to return Continues instead of Keeps, if we are going pretty straight and the other road is at least slightly bend. This removes keeps, that could be misunderstood, if there is a turn close by.

When we merge this, we should also get images for the keeps in the front-end.

@karussell

Copy link
Copy Markdown
Member

To avoid breaking the existing clients can we also use keep_left=slight_left just until we have released the more tolerant js&java clients for ~3 months?

@karussell karussell left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good to merge when:

  • use KEEP_LEFT=TURN_SLIGHT_LEFT (same for right) until we fixed the clients and have released them for a long enough period of time
  • Plus the fixes regarding the failing tests :)

@boldtrn

boldtrn commented Mar 23, 2017

Copy link
Copy Markdown
Member Author

To avoid breaking the existing clients can we also use keep_left=slight_left just until we have released the more tolerant js&java clients for ~3 months?

Yes sure, not a problem.

@boldtrn

boldtrn commented Mar 23, 2017

Copy link
Copy Markdown
Member Author

I just changed the code a bit. If there was an annotation, we would not have used the improved instructions, but just showed the old instructions.

Here is one example: http://localhost:8989/?point=49.037889%2C13.118073&point=49.034949%2C13.119403&vehicle=bike

With the old code, this would have generated the following instruction "Continue, small way, unpaved", now we generate this: "Turn slight right, small way, unpaved", which is more accurate.

@boldtrn
boldtrn merged commit f0804c2 into graphhopper:master Mar 23, 2017
@boldtrn
boldtrn deleted the improve_instructions branch March 23, 2017 08:22
@devemux86

Copy link
Copy Markdown
Contributor

👍
@boldtrn nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants