Skip to content

How to deal with encoded values that depend on others? #2470

Closed

Description

@easbar

Encoded values are often very simple. We take some OSM tags as input to a TagParser and set some bits to store some value like the RoadClass. However, there are also cases where encoded values depend on others. Take for example the priorityEnc in BikeCommonFlagEncoder. It depends on:

  • the result of getAccess(way) (if there is no access no value is set, the priority will be 0)
  • the bikeRouteEnc
  • the speed
  • the roundaboutEnc (via speed)
  • smoothness

So to remove BikeCommonFlagEncoder and write something like a BikePriorityTagParser we either have to share (or duplicate) the code that determines these values or create these other encoded values first so the BikePriorityTagParser will be able to use them. Another option might be not calculating the priority in a TagParser at all, but rather calculate the priority in CustomWeighting.

There are a few more examples for such 'higher-order' encoded values in AbstractFlagEncoder#applyWayTags where we update e.g. the speed based on elevation stuff (which at some point will also be stored as encoded values). Another one is curvatureEncoder that also depends on speed.

Activity

  1. otbutz commented on Nov 19, 2021

    @otbutz
    Contributor

    Expressing dependencies within the parsers better reflects the reality to be honest.

  2. easbar commented on Nov 19, 2021

    @easbar
    MemberAuthor

    Yes, maybe I should explain this better. The idea would be to store data directly extracted from OSM using encoded values just like we do in the TagParsers currently. But then express the derived speed/priority/access(?) values in custom language syntax. It should then be possible to re-use these derived speeds etc. in other custom models, i.e. by taking some of these expressions from a base profile. This should also allow to easily modify the rules that are used to determine speed&priority.

    Then again this could also be just part of it and it could still be useful to support higher-order encoded values, just like you said by using some kind of tag parsers that depend on others (or similar). Basically something that receives the current encoded values and writes another one.

  3. easbar commented on Nov 19, 2021

    @easbar
    MemberAuthor

    I wonder if we could just repeat handleWayTags twice. This way the 'first-order' EVs could be set based on OSM tags and others ('second-order') could be set based on the first-order ones. The TagParsers could access other EVs if they just had a reference to the EncodingManager.

  4. easbar commented on Dec 9, 2021

    @easbar
    MemberAuthor

    I wonder if we could just repeat handleWayTags twice.

    Ok, maybe not. It should be sufficient to just use the order of the TagParsers. The EV of a TagParser can then depend on EVs that were written by TagParsers that come before. The next thing we should do for #2463 is then probably giving the TagParsers access to the other EVs (probably simply using a reference to the EncodingManager).

  5. karussell commented on Dec 10, 2021

    @karussell
    Member

    What about injecting the dependent EVs via the TagParser constructor? (or using the smaller EncodedValueLookup interface)

  6. easbar commented on Dec 10, 2021

    @easbar
    MemberAuthor

    What about injecting the dependent EVs

    That could be really messy, at least as long as the TagParsers also create the EVs. It would mean that the earlier TagParsers had to create their EVs which would then be passed to the others. Otherwise, yes, this would be probably the cleanest thing to do as it minimizes dependencies and the dependencies are more visible. But maybe it is more practical to just pass the entire EncodedValueLookup?

    or using the smaller EncodedValueLookup interface

    Yes 👍. In my mind EncodingManager already is nothing but an EncodedValueLookup :)

  7. easbar commented on Dec 10, 2021

    @easbar
    MemberAuthor

    As @karussell pointed out, the TagParsers are already capable of obtaining a reference to EncodedValueLookup via their createEncodedValues method. Maybe not perfect, but good enough to make progress for #2463.

  8. otbutz commented on Jun 3, 2022

    @otbutz
    Contributor

    Just a rough sketch: #2595

    The idea would be to let TagParsers express which EncodedValue they require/provide and sort them accordingly. The next step would be to actually add requirements and let them obtain EncodedValues.

    Would that be a feasible approach?

  9. easbar commented on Jun 3, 2022

    @easbar
    MemberAuthor

    The last time I discussed this with karussell the idea was simply setting the order manually as I pointed out here: #2450 (comment)

    But not sure if this becomes too much manual work or is too error-prone in some cases. Another problem is that so far we do not really have an explicit (and complete) list of all tag parsers yet. Besides those activated via graph.encoded_values there are also some that are add in Java code:

    // this needs to be in sync with the default EVs added in EncodingManager.Builder#build. ideally I would like to remove
    // all these defaults and just use the config as the single source of truth
    if (!encodedValueStrings.contains(Roundabout.KEY))
    osmParsers.addWayTagParser(new OSMRoundaboutParser(encodingManager.getBooleanEncodedValue(Roundabout.KEY)));
    if (!encodedValueStrings.contains(RoadClass.KEY))
    osmParsers.addWayTagParser(new OSMRoadClassParser(encodingManager.getEnumEncodedValue(RoadClass.KEY, RoadClass.class)));
    if (!encodedValueStrings.contains(RoadClassLink.KEY))
    osmParsers.addWayTagParser(new OSMRoadClassLinkParser(encodingManager.getBooleanEncodedValue(RoadClassLink.KEY)));
    if (!encodedValueStrings.contains(RoadEnvironment.KEY))
    osmParsers.addWayTagParser(new OSMRoadEnvironmentParser(encodingManager.getEnumEncodedValue(RoadEnvironment.KEY, RoadEnvironment.class)));
    if (!encodedValueStrings.contains(MaxSpeed.KEY))
    osmParsers.addWayTagParser(new OSMMaxSpeedParser(encodingManager.getDecimalEncodedValue(MaxSpeed.KEY)));
    if (!encodedValueStrings.contains(RoadAccess.KEY))
    osmParsers.addWayTagParser(new OSMRoadAccessParser(encodingManager.getEnumEncodedValue(RoadAccess.KEY, RoadAccess.class), OSMRoadAccessParser.toOSMRestrictions(TransportationMode.CAR)));

    I'd like to get rid of this, see e.g. this discussion: #2561 (comment).

    Doing automatic dependency resolution would be another possibility, but certainly adds some complexity that I'm not sure we need? The tag parsers do not change that often. Looking at your usage scenario, would an explicit list of tag parsers in config.yml (probably replacing or next to graph.encoded_values) be sufficient?

  10. otbutz commented on Jun 3, 2022

    @otbutz
    Contributor

    // this needs to be in sync with the default EVs added in EncodingManager.Builder#build. ideally I would like to remove
    // all these defaults and just use the config as the single source of truth
    if (!encodedValueStrings.contains(Roundabout.KEY))
    osmParsers.addWayTagParser(new OSMRoundaboutParser(encodingManager.getBooleanEncodedValue(Roundabout.KEY)));
    if (!encodedValueStrings.contains(RoadClass.KEY))
    osmParsers.addWayTagParser(new OSMRoadClassParser(encodingManager.getEnumEncodedValue(RoadClass.KEY, RoadClass.class)));
    if (!encodedValueStrings.contains(RoadClassLink.KEY))
    osmParsers.addWayTagParser(new OSMRoadClassLinkParser(encodingManager.getBooleanEncodedValue(RoadClassLink.KEY)));
    if (!encodedValueStrings.contains(RoadEnvironment.KEY))
    osmParsers.addWayTagParser(new OSMRoadEnvironmentParser(encodingManager.getEnumEncodedValue(RoadEnvironment.KEY, RoadEnvironment.class)));
    if (!encodedValueStrings.contains(MaxSpeed.KEY))
    osmParsers.addWayTagParser(new OSMMaxSpeedParser(encodingManager.getDecimalEncodedValue(MaxSpeed.KEY)));
    if (!encodedValueStrings.contains(RoadAccess.KEY))
    osmParsers.addWayTagParser(new OSMRoadAccessParser(encodingManager.getEnumEncodedValue(RoadAccess.KEY, RoadAccess.class), OSMRoadAccessParser.toOSMRestrictions(TransportationMode.CAR)));

    With dependency resolution we would get rid of manually having to maintain things like this. I'd rather add the code for dependency resolution with proper unittests instead of having to curate the order.

    Ideally the user would specify extra EVs for path details and all other EVs would be resolved from the TagParsers required for the specified profiles.

  11. easbar commented on Jun 3, 2022

    @easbar
    MemberAuthor

    With dependency resolution we would get rid of manually having to maintain things like this. I'd rather add the code for dependency resolution with proper unittests instead of having to curate the order.

    This does not curate the order, but it adds default parsers. Like I stated above, in my opinion there should not be such a thing as default parsers, i.e. this code should just be removed. There should just be a list of parsers in config.yml and the order of this list should define the dependencies (later parsers can only expect valid values of encoded values written by earlier parsers).

    So the question is not whether we want to somehow curate the order or find it automatically, but rather whether this simple approach of an ordered list is sufficient or if we use automatic dependency resolution instead of relying on the order as you suggest.

    Ideally the user would specify extra EVs for path details and all other EVs would be resolved from the TagParsers required for the specified profiles.

    I want to get away from the idea that parsers define EVs. Is this what you mean with "EVs would be resolved from the TagParsers"? This is what we did previously btw: TagParsers had a 'createEncodedValues' method. I think 'creating EVs' should be different from 'writing EVs', because writing EVs is only done when importing map/OSM data, but not when loading an already imported graph. So I think there should be:

    • something that defines the 'memory layout' of the graph edges, i.e. which encoded values should exist for a graph
    • something that defines how the different way tags shall be interpreted and the encoded values shall be written (the tag parsers)

    When we import a new graph we need both, in this order. When we load an existing graph the graph layout should ultimately just be from the graph(meta)-data and the tag parsers are not needed at all. This is why tag parsers should not be the place where the encoded values are created or defined.

  12. easbar commented on Jun 3, 2022

    @easbar
    MemberAuthor

    The other reason why I want to separate this is that maybe someone does not use tag parsers at all. Imagine using the graph on a lower level: I want to be able to create a graph with certain encoded values and set their values just like this:

    graph.edge(0, 1).set(myEnc, 42);

    If encoded values were somehow defined in tag parsers this would mean that we need tag parsers to create encoded values, even when we don't want to parse any tags at all.

  13. karussell commented on May 15, 2024

    @karussell
    Member

    I think this is now solved with the ImportRegistry.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions