You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to deal with encoded values that depend on others? #2470
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.
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.
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.
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).
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 :)
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.
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.
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:
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?
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.
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.
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.
Activity
otbutz commentedon Nov 19, 2021
Expressing dependencies within the parsers better reflects the reality to be honest.
easbar commentedon Nov 19, 2021
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
TagParserscurrently. 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.
easbar commentedon Nov 19, 2021
I wonder if we could just repeat
handleWayTagstwice. 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. TheTagParserscould access other EVs if they just had a reference to the EncodingManager.easbar commentedon Dec 9, 2021
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).
karussell commentedon Dec 10, 2021
What about injecting the dependent EVs via the TagParser constructor? (or using the smaller EncodedValueLookup interface)
easbar commentedon Dec 10, 2021
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?Yes 👍. In my mind
EncodingManageralready is nothing but anEncodedValueLookup:)easbar commentedon Dec 10, 2021
As @karussell pointed out, the
TagParsers are already capable of obtaining a reference toEncodedValueLookupvia theircreateEncodedValuesmethod. Maybe not perfect, but good enough to make progress for #2463.otbutz commentedon Jun 3, 2022
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?
easbar commentedon Jun 3, 2022
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_valuesthere are also some that are add in Java code:graphhopper/core/src/main/java/com/graphhopper/GraphHopper.java
Lines 578 to 591 in 4da856b
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?otbutz commentedon Jun 3, 2022
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.
easbar commentedon Jun 3, 2022
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.ymland 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.
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:
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.
easbar commentedon Jun 3, 2022
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:
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.
karussell commentedon May 15, 2024
I think this is now solved with the ImportRegistry.