Skip to content

Consolidate concepts of spatial rules, custom models and custom areas #2246

Closed

Description

@easbar

We have an ongoing discussion about different concepts that are all about area-dependent data (often not originating from OSM) that is used in different parts of GraphHopper. We have spatial rules and now also custom models and in #2201 there is a proposal for custom areas. The discussion about how these concepts relate to each other is spread over multiple issues and PRs.

Can we clarify first what we are trying to achieve so we can derive a (hopefully) consistent approach how such functionality should be dealt with in the future? I'll start with a small list of things we'd like to have, but please feel free to modify and extend it.

  1. Modify edge weights for route calculations based on the location of the edge per request / from the client side. Currently we can do this by specifying areas in the custom model and use the area in the speed or priority section.

  2. Modify edge weights for route calculations depending on whether or not the edges are located in areas that are defined on the server side.

  3. Choose values of encoded values depending on the location of edges (e.g. max_speed depends on the country)

Related: #1280, #1808, #2201, #1799, #2164 (and probably many more?!)

Activity

  1. otbutz commented on Mar 5, 2021

    @otbutz
    Contributor

    Also related: #1799, #2164

    spatial rules, custom models and custom areas

    I'd go with @karussell naming proposal: custom models, custom areas and custom rules

    1. Choose values of encoded values depending on the location of edges (e.g. max_speed depends on the country)

    We should differentiate a bit more here:

    • override
    • cap
    • fallback

    I'd really appreciate if we could finally come up with a concept that everyone agrees with. I've been pushing this since November 2019 and fatigue is setting in to be honest. Yes it's complex and i don't expect to be spoon fed or get reviews within the minute. But getting zero feedback for multiple weeks is a real mood killer. I'm aware that reviews of code written by some thirdparty take up quite some time and even more so if it's in a part of the codebase you haven't touched recently. Again, i understand that.

    Drafting a PR already takes requires some effort but it gets even worse if i don't get any feedback for a longer period of time. Reacting to change requests after over 2 weeks adds additional workload because i have to start from scratch. Any knowledge of that changes or the code it touches is gone at this point.

    Unanswered questions like "how do you want to handle X" also adds to this latency. Yes, i can draft a workable solution but i might end up putting a lot of work into something which doesn't fit into the concept of the project maintainers and gets therefore rejected.

    Sorry if this is off topic but i needed to vent.

  2. karussell commented on Mar 5, 2021

    @karussell
    Member

    doesn't fit into the concept of the project maintainers and gets therefore rejected

    Of course this is always the risk for every contributor including the core team too :) ! I have so many unfinished branches that I lost count but from most of them I get an improvement at least due to better understanding the matter.

    From our side every PR (regardless of the contributor) is also a risk regarding maintenance. In the past I made sometimes the mistake that I accepted pull requests that could be well done also outside of the project and so they got stale, broken or even a maintenance burden - this is not what the project needs :)

    Let me be clear with custom areas: we need this and we will work on this. This is really important for the project: for better ETAs for better max_speed values and more. We will even try hard to contribute from our currently closed source solution for improved ETAs (using yet another code base). But we do not know when exactly we have the bandwidth to do that. Hopefully the next months but could be also later this year or even next year.

  3. otbutz commented on Mar 5, 2021

    @otbutz
    Contributor

    Of course this is always the risk for every contributor including the core team too

    From our side every PR (regardless of the contributor) is also a risk regarding maintenance.

    My point is not about receiving objections or having a PR rejected. It's the high delay between trying to contribute something and getting feedback that irks me. I don't expect a full fledged analysis of my code but something along the lines of "This class looks a bit too complicated" or "Moving this here seems ok to me" would help a lot.

    e.g i've currently stopped working on #2201 until it is clear how to properly persist the encountered values: #2243
    Is it ok to store them as part of the encoded value representation? Do i need to come up with a different solution? If yes, how would that solution look like so that it fits upcoming changes?

    These are question i cannot answer myself. I can and will work on this when I know what an acceptable solution could look like in your eyes.

    But we do not know when exactly we have the bandwidth to do that.

    Which is perfectly understandable. But please invest a few minutes now and then so that external contributors are not completely in the dark.

  4. easbar commented on Mar 15, 2021

    @easbar
    MemberAuthor

    @otbutz Thanks for providing your feedback. It is certainly not ideal (and definitely the opposite of what we desire) when contributors like you get tired or even frustrated by the PR process and I can see how providing PRs and not getting a timely response has been a bad experience for you. At the same time I do not see a clear way how we can improve the process. Taking a few minutes to look at a PR and leaving some comments like "This class looks a bit too complicated" is not helpful at all in my opinion. Starting a discussion about details makes it seem like the PR is close to being merged when maybe there are some fundamental questions that need to be answered first or library is currently just not in a good state to accept the changes in the PR. Taking a deep look and figuring out what kind of fundamental issues there might be takes a lot more time and even then asking questions or starting to discuss some of the issues might only lead to more questions and discussion that in the process will take even more time. We cannot always adjust our own agenda according to public contributions and it certainly can happen that the development goes a different direction for quite some time. There might be cases where a contribution just fits into the current development and gets merged a lot faster, but also the opposite can be true. I think every PR needs to be written with this in mind. If there are details or meta-knowledge that is needed to understand the PR and it is not possible to reflect this in the code this should be included in the PR description. Either way the PR description should make it as easy as possible to see what the intention was and maybe even provide some guideline how it can be reviewed efficiently. You said you might forget about some things after two weeks, but if this is so how are reviewers supposed to understand the intention of the PR (now, in the future, or even after it was merged)?

    At the same time I totally understand that getting no answer at all is not helpful for the contributor either. Probably we should try to write a comment that gives a rough idea about the PR and when there might be time to consider it. But then again we cannot make any promises when and how this will happen, so this is not as easy either. Is it better to claim it will be reviewed within the next two months even when this might not be true?

    One thing I am sure of is that PRs are a lot more likely to be merged the more they focus on exactly one issue (and nothing else). I am not saying this is an easy thing to do or even possible in all cases, but a small and focused PR is the ideal that we normally should aim for. If this is not possible maybe it is better to have a discussion upfront to figure out how likely it is that a certain contribution might get accepted and if there even will be time to consider and review it in detail.

    Please note this is just general advice and maybe not even applicable to your work. I am just trying to explain my general point of view on the issue you pointed to.

  5. easbar commented on Mar 15, 2021

    @easbar
    MemberAuthor

    Also related: #1799, #2164

    Thanks, I added these to the list.

    We should differentiate a bit more here:

    Can you explain this in a bit more in detail? I just meant when during import we set the encoded values' 'values' we want to do this depending on the position of an edge. Whether we later use these encoded values as fallback values or maximum limits etc. or not seems like another question?

  6. easbar commented on Mar 15, 2021

    @easbar
    MemberAuthor

    I also wonder what the areas in custom models are supposed to mean. On the client side this seems clear, because they allow a client to specify an area 'on-the-fly' so it can be used for a single request. But using areas on the server side seems to be the same as using 'area-dependent encoded values', e.g. an area can just be represented by an encoded value that is true for every edge within that area. Is this the same and do we need the concept of areas within (server-side) custom models?

    Update: Yes, we need this. One important difference is that custom model areas can be used without compiling from source again.

  7. otbutz commented on Mar 16, 2021

    @otbutz
    Contributor

    We should differentiate a bit more here:

    Can you explain this in a bit more in detail? I just meant when during import we set the encoded values' 'values' we want to do this depending on the position of an edge. Whether we later use these encoded values as fallback values or maximum limits etc. or not seems like another question?

    To cite your initial statement:

    1. Choose values of encoded values depending on the location of edges (e.g. max_speed depends on the country)

    If i understood this correctly, you want to set the final value for e.g the maxspeed EV during import like we do it currently in the OSMMaxSpeedParser?

    But their are multiple ways how a (missing) max speed value in the dataset could be treated:

    • override: e.g set maxspeed for all living streets in Germany to 7km/h
    • cap: maxspeed for primary roads in Germany is 100km/h but might be lower in urban areas. We can still cap all values to 100km/h if they are higher.
    • fallback: no value tagged, so use a fallback which at least fits to the road type

    Or do you want to store the "raw" value and do this kind of logic at runtime?

  8. easbar commented on Mar 16, 2021

    @easbar
    MemberAuthor

    No I meant just generally we want to set encoded values depending on the position of edges (during import). So we could have all kinds of logic, like the override/cap/fallback you mentioned and this results in some value (for maxspeed in your example) and the logic includes the position of the edge. After the import is done there is a value for each edge kept in the storage and the logic does not need to be run again.

  9. easbar commented on Jun 28, 2021

    @easbar
    MemberAuthor

    Today I had a long discussion with @karussell about this. We think we have somewhat of a 'plan' how to deal with custom areas and encoded values now, but like to invite everyone to this discussion so we can hopefully cover all use cases to some extent. I want to write down what currently can be done, how it is done and what should be possible in the future. I am probably at risk of repeating some things that were already discussed elsewhere like in #2201, but since the discussion is spread over so many issues I think repeating some basics here will help to make sure we are talking about the same things. It is also very likely we forgot to consider some important details or entire use cases, and this is exactly why I am writing this, so please feel free to correct or add the aspects you are missing, especially @otbutz and @boldtrn. Also @karussell I am writing this as a result of our discussion, but in case you think otherwise or I might have gotten you wrong somewhere please also feel free to correct me.

    So what kind of area-related concepts do we support so far? I think there are only spatial rules and areas in custom_model currently. So what do they do, how are they different and why are they not sufficient yet?

    Spatial rules are used to modify the access and max_speed encoded values depending on the geographical location of an edge (OSMRoadAccessParser and OSMMaxSpeedParser). Currently there are only spatial rules for Germany and Austria. Adding more such spatial rules is simple, but requires modifying and re-compiling the Java sources. The areas corresponding to a spatial rule are specified via external geojson files. Since there is code that basically allows checking whether or not a coordinate (lat,lon) matches an area defined in an external file that that corresponds to a spatial rule they are somewhat 'misused' for LM preparation as well.

    The areas section in custom_model also allows defining areas (currently only directly in config.yml), but these areas are not used to modify encoded values and instead they can be directly used to change the speed or priority of the custom weighting. Their evaluation requires some kind of in_polygon lookup, which can be more costly than simply reading an encoded value. The custom model language allows very flexible use of these custom areas (if/else logic in custom models) without compiling the source code again. On the other hand using these areas is also somewhat limited, because the custom model language does not allow arbitrary programming, nested if/else clauses, loops etc. Even mapping the current Spatial Rules for Germany and Austria to custom model areas is not entirely trivial and requires writing ugly, long and repetitive boolean conditions.

    In short we have one 'config-like' approach (custom model areas) and one approach that is based on modifying the Java source code. @karussell and I already decided (based on our current understanding) that it is not possible (or non-sensical) to try to cover all use cases by one of them and we want to keep supporting both (but in a different form).

    Let's take a look at some of the use-cases we were able to come up with:

    1. Modify the weighting in some user-specific area. This is a perfect use case for custom model areas, at least as long the 'edge-in-polygon' lookup does not become too costly, like when using very many custom areas. Not having to compile a different jar is a huge plus of this approach.

    2. Modify the weighting depending on the country an edge is located in. In theory this also works with custom model areas, but there are some drawbacks. First of all copying the country borders to the custom model file seems very cumbersome. This can be improved by externalizing the custom model areas to separate files (Allow specifying areas for custom weighting in a separate file #2037), but we think that things like max speed rules for different countries are such a common thing they should rather be included in GraphHopper directly. This also gives more flexibility in how to modify e.g. max speed because as I mentioned above the max speed rules we use for Germany/Austria are already a bit hard to represent by custom models. We think there should be a country encoded value which could then of course also be used in custom models.

    3. Obtain the current country in path details. We like to keep the correspondence between path details and encoded values so this is another very good reason to have a country encoded value. We also think that the countries.geojson should be included right in the distribution so the country encoded value can be included by default.

    4. Modify any encoded value depending on the country an edge is located at. This is a more general version of what is currently possible using Spatial Rules. We would like to basically turn Spatial Rules into something similar to TagParsers that are aware of the country of an edge. So basically we can modify every encoded value any way we want in these TagParsers and also based on their location. We are only planning to allow this (only) via the Java API, so modifying these TagParsers will be a matter of editing the source code and re-compiling. Maybe we can extend this (or parts of it) to some kind of 'configurable' approach, but for the time being we have no intention to do this. At the very least we would like to built the Java version of this first and only later think about externalizing this to config files. The reason is simply that we want maximum flexibility (basically any use-case that involves modifying encoded values based on the edge's location should be covered) without taking the burden of doing this in some kind of restricted config environment.

    5. Doing the same for arbitrary areas. 2), 3) and 4) should just as well be possible for arbitrary areas. The only difference should be that the custom areas are defined in some external geojson files (instead of the built-in countries.geojson). Using such custom areas will then be a matter of a) specifying the areas in the geojson files and b) adding (or modifying) TagParsers to add or adjust encoded values.

    So with our current understanding we would like to adjust the import process to something like the following:

    a) read geojson files and build an index that allows obtaining the IDs of the different areas (instead of obtaining SpatialRules)
    b) read OSM and call the TagParsers for every way/edge. handleWayTags will receive a list of area IDs the edge belongs to. We can apply any logic we like by adding or modifying TagParsers. So we can basically do arbitrary modifications of any encoded value. If for some reason the behavior of one of the TagParsers should be configurable without re-compilation this can of course be implemented in some custom TagParser, but currently we do not intend to include this in this repository.

    To give an example, the countries are included by default and OSMMaxSpeedParser will include the logic of modifying the max speed depending on the country just like the Germany and Austria spatial rules currently do. Or another example: some kind of CountryTagParser will simply attach the country information to every edge (Country encoded value).

    Please keep in mind that here I was just trying to identify and write down the way we'd like to handle these things in the future. Once we come to an agreement here of course we should also consider what has currently already been done (like #2201 etc.) and what else needs to be done.

  10. boldtrn commented on Jun 29, 2021

    @boldtrn
    Member

    Thanks a lot for working on the concept 👍 . I really like the idea of being able to use SpatialRules in the TagParsers.

    handleWayTags will receive a list of area IDs the edge belongs to.

    Especially for access handling it might be helpful to have this information available when determining access already.

  11. easbar commented on Jun 29, 2021

    @easbar
    MemberAuthor

    I did a little proof of concept here: #2353

  12. easbar commented on Jun 29, 2021

    @easbar
    MemberAuthor

    Especially for access handling it might be helpful to have this information available when determining access already.

    You mean for access flags in flag encoders? Yes this should be possible, but I think all we need to do is pass the custom areas not only to tag parsers, but also to flag encoders like I did here:

    encoder.handleWayTags(edgeFlags, way, acceptWay.get(encoder.toString()), customAreas);

    ?

  13. boldtrn commented on Jun 29, 2021

    @boldtrn
    Member

    I actually meant in the accept way method here:

    acceptWay.put(encoder.toString(), encoder.getAccess(way));

    Otherwise we might accept a large amount of roads and block them again later, depending on the setting.

  14. easbar commented on Jun 29, 2021

    @easbar
    MemberAuthor

    Ah ok interesting, so this would be a performance optimization? Do we do something similar with spatial rules currently (to me it looks like we don't?!).

  15. boldtrn commented on Jun 29, 2021

    @boldtrn
    Member

    so this would be a performance optimization?

    Haven't measured the impact, but yes, at least a graph space optimisation :)

    Do we do something similar with spatial rules currently (to me it looks like we don't?!).

    I think we don't do this right now. I thought there was an issue for this - but couldn't find it after a quick search :).

  16. karussell commented on Jul 5, 2021

    @karussell
    Member

    I did a little proof of concept here: #2353

    Thanks, I like this approach and now features would be even possible like excluding a country via a custom model or showing this in path details.

    When this approach is production ready I think the PRs like #2201 and #1808 would be put on hold for now (as we for now would say that everyone could built its custom EnumEncodedValue to integrate its own custom areas). But the PRs #1799 & #2164 and issue #1427 would be easy to do.

  17. otbutz commented on Jul 12, 2021

    @otbutz
    Contributor

    We should also use the country information when parsing OSM tags like e.g maxspeed=RU:urban
    It would be nice if we could get rid of these hardcoded defaults:

    if (str.endsWith(":rural") || str.endsWith(":trunk"))
    return 80;
    if (str.endsWith(":urban"))
    return 50;

  18. easbar commented on Jul 12, 2021

    @easbar
    MemberAuthor

    We should also use the country information when parsing OSM tags like e.g maxspeed=RU:urban
    It would be nice if we could get rid of these hardcoded defaults:

    Ok, yes. I think I would prefer moving this logic out of OSMValueExtractor and into OSMMaxSpeedParser, rather than passing the country information or country rule into OSMValueExtractor though. And also not sure if we should do this right away or as a follow up, since there are probably many details to be discussed already.

  19. otbutz commented on Jul 12, 2021

    @otbutz
    Contributor

    A followup PR is probably cleaner.

  20. IldarKhayrutdinov commented on Oct 14, 2021

    @IldarKhayrutdinov
    Contributor

    We should also use the country information when parsing OSM tags like e.g maxspeed=RU:urban It would be nice if we could get rid of these hardcoded defaults:

    if (str.endsWith(":rural") || str.endsWith(":trunk"))
    return 80;

    yeah, these hardcoded defaults are different for each country

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