Skip to content

Improve Bicycle Routing #330

Closed
Closed

Description

@ximex

I tested around with the new routing implementation at osm (openstreetmap/openstreetmap-website@250bb47)

I found this strange routing:
This first routing is much longer as the second one. I place the destination only some meters west in the second routing. The osm data looks correct.
graphhopper
graphhopper2

Activity

  1. karussell commented on Feb 16, 2015

    @karussell
    Member

    GraphHopper bike routing is not about the shortest path, it is about the fastest but also including priorities like avoiding ugly surface, prefering a medium increase etc. Have a look at the time. They are similar:
    https://graphhopper.com/maps/?point=47.8947%2C16.1056&point=47.900074%2C16.106408&vehicle=bike&elevation=true&layer=TF%20Cycle

    So what do you think is the problem with the longer path, except that is longer in the distance :) ?

  2. ximex commented on Feb 16, 2015

    @ximex
    Author

    first it is much longer. yes the time is nearly the same. from my experience in realworld this couldn't be right.
    it's correct that the longer path has a smaller incline and a smother surface. But for me the distance should have more weight.
    And if you look: the length of the route on highway=track is approx. as long as by the other route.

  3. karussell commented on Feb 16, 2015

    @karussell
    Member

    But for me the distance should have more weight.

    Well, that is true for you but probably not for others and that is the reason bike routing is not easy :)

    Maybe you could tweak the routing a bit and avoid such a big penalty directly in the code for that area? You'll need to tweak the BikeCommonFlagEncoder. Installation of GraphHopper is trivially once you have java installed. Let me know and I'll see if that is okay for other areas too.

    We will make this more flexible from outside in a later version, but this personalization won't be accessible for OSM.org I fear ...

  4. ximex commented on Feb 16, 2015

    @ximex
    Author

    i checked the data again in detail:
    Short route: residential and track (grade1, grade2, "no grade")
    Long route: tertiary, residential and track ( only "no grade")

    Track Setting: https://github.com/graphhopper/graphhopper/blob/master/core/src/main/java/com/graphhopper/routing/util/BikeCommonFlagEncoder.java#L156
    Grade Settings: https://github.com/graphhopper/graphhopper/blob/master/core/src/main/java/com/graphhopper/routing/util/BikeCommonFlagEncoder.java#L116

    Speed for: tertiary, residential and track-grade1 is the same -> 18
    Speed for: track-grade2 and track-nograde is the same -> 12

    Only from this, the short route should win.

    I don't know the turn penaltis, ...
    The only reason i could think is the incline. If you look at the first route: why did he took the route over the street "Kreithgasse" and not over the "Hochstraße" -> Hochstraße has a much greater incline that Kreithgasse.

  5. sanderd17 commented on Feb 17, 2015

    @sanderd17

    I agree bicycle routing isn't easy. There are many types of bicycles, and even more types of cyclists. But since Graphhopper is now on the main OSM site, I guess you (devs) might get a lot of related questions to it. So maybe it's not a bad idea to explain some used routing principles (that way, people can adapt tagging to get better routing, or suggest improvements for the engine).

    F.e., I have problems with this cycle route: http://www.openstreetmap.org/directions?engine=graphhopper_bicycle&route=50.9399%2C3.0792%3B50.9388%2C3.0662#map=16/50.9409/3.0727

    Instead of following the quiet unclassified road (even if there's no cycle lane, there's also almost no traffic on unclassified roads, so it's an enjoyable ride), it says I have to cross a tertiary road twice, and drive on a noisy cycleway next to that rather busy tertiary road. Elevation doesn't matter (even if you have that info), both routes are perfectly flat.

    I know that tagging a cycleway next to a busy road is a bit contra-productive (when not tagged, I'm quite sure the router would prefer the quiet road), however, it's done quite often by now.

    For this problem, I see two solutions:

    • Make the preference difference between cycleways and unclassified roads smaller, on average they're both equally pleasant to drive on IMO, so the shortest one should probably be taken.
    • Implement the class:bicycle tag to allow mappers to show how pleasant it actually is to drive on a road.

    Thanks for the work on it

  6. karussell commented on Feb 17, 2015

    @karussell
    Member

    Thanks for pointing to class:bicycle, didn't know about it. Also yes, the unclassified road could get a boost.

    What does class:bicycle=-1 mean?

    explain some used routing principles

    I would avoid to suggest mappers to map for routing engines. Just map the reality and we try to guess the best possible. In this light class:bicycle is indeed not about mapping

    I know that tagging a cycleway next to a busy road is a bit contra-productive

    Why is that contra-productive when it is there? Can we somehow extract that it is along the tertiary highway?

  7. changed the title [-]Strange Routing (Cycle)[/-] [+]Improve Bicycle Routing[/+] on Feb 17, 2015
  8. karussell commented on Feb 17, 2015

    @karussell
    Member

    Related to #280

  9. sanderd17 commented on Feb 17, 2015

    @sanderd17

    The class:bicycle tag is indeed highly subjective. And thus also has many opponents within the OSM community. If you have other ways to improve tagging, that's also welcome.

    I would avoid to suggest mappers to map for routing engines. Just map the reality and we try to guess the best possible. In this light class:bicycle is indeed not about mapping

    Similar as tagging for the renderer. Everybody says not to do it, but it happens all the time. Tagging for the renderer also has some positive results. F.e. it creates a certain standardisation in the tags. It becomes bad when you tag false facts to influence a particular renderer. In this light, a clear description on matters like "what tags are taken into account", "for what sort of cyclists the routes are meant", ... would be very positive I guess.

    That way, people can see what part of the reality is missing in their tagging, and add it.

    Why is that contra-productive when it is there? Can we somehow extract that it is along the tertiary highway?

    Well, by adding a track next to it, instead of tagging the existence of a cycleway on the main road, you lose the obvious connection between the two. So routers can't see some of the finer details (f.e. the name of the road, some of the crossings might be strange due to missing links, ...). Extracting the environment is possible of course, but I don't think there's any router implementing this currently due to the difficulty.

    Other tags can be added, like the distance between the cycleway and the road, the type of separation (grass, hedges, trees, ...), the classification of the closest road, the name of the closest road, ... However, this might add tag duplication that's not really wanted.

  10. ratrun commented on Feb 17, 2015

    @ratrun
    Contributor

    The finding in the example above is mostly triggered by the way 161774102, which is currently mapped as "track" without any other tags (tracktype, surface). In this case we assume pretty bad cycling conditions (if you look closely it instructs you that you might need to get off) and as this segment is rather long, the longer paved de-tour is preferred.
    See

    https://github.com/graphhopper/graphhopper/blob/master/core/src/main/java/com/graphhopper/routing/util/BikeFlagEncoder.java#L66

    I was well aware about the class:bicycle existence during the bicycle routing tweaking. Parts of the ideas made it into the graphhopper code. I didn't include the tag "class:bicycle" support, because I believe that first place the common highway tags should influence the decisions, the class:bicycle tagging is pretty controversial and not often used.
    It is a pity that only the default bicycle routing is online. Graphhopper also supports MTB and racebike, but the online instance does not activate it. In the example above, choosing MTB would result in the tour you expected.

  11. ratrun commented on Feb 17, 2015

    @ratrun
    Contributor

    Regarding the example from sanderd17, which was

    http://www.openstreetmap.org/directions?engine=graphhopper_bicycle&route=50.9399%2C3.0792%3B50.9388%2C3.0662#map=16/50.9409/3.0727

    The proposed first solution was : "Make the preference difference between cycleways and unclassified roads smaller, on average they're both equally pleasant to drive on IMO, so the shortest one should probably be taken."

    Of course this would be easily possible. But tweaking the bicylce routing that way, I also wanted to cover the case of riding with kids in the default touring bike like profile. That's probably the main reason for your example. It is very hard to find a common balance between cylceways and lower classified roads which fits everybody.

    Regarding sanderd17's second solution: with support for class:bicycle: Go ahead, this implementation will be rather easy as everthing is prepared. As far as I understood, this is now the target of this #330. From my perspective it will not help a lot, see the comment above.

    But sanderd17 mentioned two other things, which I would try to solve with higher priority. The first one is related to #75. For the bicycle routing, costs for crossing high priority roads (primary, secondary) should be added. As far as I know graphhopper currently does not provide a framework for that feature.

    The other thing sanderd17 mentioned looks to be in the same or higher area of difficulty: Let's assume a separated highway=cycleway running in parallel to a main road / (e.g) primary. This should change down the priority e.g. to UNCHANGED. I do not think that this has already been adressed in one of the issues before.

  12. ratrun commented on Oct 5, 2015

    @ratrun
    Contributor

    Now that multiple bicycle types are available on graphhopper.com/maps I re-started the investigation for the observation from user ximexs at the initial report for this issue. This is the route:
    https://graphhopper.com/maps/?point=47.8947%2C16.1056&point=47.900074%2C16.106408&locale=de-DE&vehicle=bike&weighting=fastest&elevation=true&layer=TF%20Cycle

    The strange thing is that the racingbike profile solution is taking the expected shorter solution.

    For the check, I downloaded the respective OSM data, configured graph.elevation.provider=cgiar and compared bike2 and bike. Only bike2 is showing the surprisingly long de-tour. In my test bike takes a similar route compated to racingbike and 'mtb'. So the problem with bike2 is definitely related with elevation wighting. One can see that also easily by comparing the solution with this shorter solution via "Hochstraße": https://graphhopper.com/maps/?point=47.8947%2C16.1056&point=47.90065%2C16.118257&point=47.900074%2C16.106408&locale=de-DE&vehicle=bike&weighting=fastest&elevation=true&layer=TF%20Cycle
    This solution is longer and the total ascend even higher compared to the observed solution. @karussell : Can you please take a look and give hints how this issue can be further debugged?

  13. karussell commented on Oct 6, 2015

    @karussell
    Member

    Sorry, I won't have time for this in the next days. You'll need to debug into the elevation data and how this converts to the speed for up and down hill in bike2. It could be that the elevation is not smooth enough here, once again :(, and bike2 puts a penalty if the increase or decrease is too strong.

  14. ratrun commented on Oct 6, 2015

    @ratrun
    Contributor

    No problem. This issue is open for quite long now, one week more dosn't hurt.
    This is what I tought. But shouldn't we see elevation spikes also in the elevation graph then?
    An idea came into my mind for debugging: I could delete all the other not used way segments via JOSM and set breakpoints to the calculation of of the elevation weighting.

  15. karussell commented on Oct 6, 2015

    @karussell
    Member

    But shouldn't we see elevation spikes also in the elevation graph then?

    If edges are short only a few meter 'spikes' would matter a lot.

    set breakpoints to the calculation of of the elevation weighting.

    You can also set a breakpoint via OSM-way-id, they are still there in the import :)

  16. ratrun commented on Oct 7, 2015

    @ratrun
    Contributor

    The elevation aware speed calculation results in speed values PUSHING_SECTION_SPEED / 2 ( =2 km/h) for the two ways in the west. So the algorithm assumes that it is not possible to ride there any longer. The incline there according to the DEM data is about 10%. I didn't notice any spikes. As the bike2 profile is not designed for strong mountainbikers, but rather for weak cummute riders, I believe that we can keep it as it is. I did see people pushing their bikes at lower and shorter ascends, and once you are pushing a bike upwards, you are slower than 4km/h. And when you ride with kids, these will need to get off the bike there.
    Anyhow, it would be great to have explicit well commented test cases about incline values and the resulting expected calculated decreased speed values in Bike2WeightFlagEncoderTest. This is currently not the case. Maybe I'll create a few around Christmas.

  17. karussell commented on Oct 7, 2015

    @karussell
    Member

    Ok, thanks for the investigation, also maybe the real elevation is not that big @ximex ?

    Still it is strange to me why the algo chooses Kreithgasse instead of Hochstraße...

  18. ratrun commented on Oct 8, 2015

    @ratrun
    Contributor

    Well, Kreithgasse instead of Hochstraße is also related to the pretty aggressive slow down of the speed adoption algorithm for incline sections. For the 200 meters long Hochstraße with 10% incline the calculated speed is only 3.2 km/h. Kreithgasse is 30 meters longer and has about 6 % incline, but here the computed speed is significantly faster with 13km/h.

  19. karussell commented on Oct 8, 2015

    @karussell
    Member

    Thanks again! I don't think this is unreasonable as 10% is heavy, no? But still this could need fine tuning AND maybe the elevation needs a bit smoothing (?)
    Also it goes down on Kreithgasse which makes speed eventually too fast?
    @ratrun I suggest that you check if e.g. ele values of 10%, 5%, 0%, -5%, -10% and speeds like 5, 10, 15, 20, 25 should be checked and the decrease and increase compared to real world. I'm was not a good guesser in this subject probably :(

    Furthermore the current increase and decrease delta is based on tower nodes (double eleDelta = pl.getElevation(pl.size() - 1) - prevEle;) which is far from optimal but due to elevation spikes this gave better results when compared with the currently commented pillar node delta calculation (for (int i = 1; i < pl.size(); i++)).

  20. karussell commented on Jul 9, 2022

    @karussell
    Member

    When using the bike profile without elevation then I get either this route:

    image

    or this via a path:

    image

    So the problem is regarding the elevation spikes ( /smoothing ) like #2028 and I will close here.

  21. added a commit that references this issue on Jan 7, 2025
    1bb2760
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions