Skip to content

move relation and turn relation parsing out of FlagEncoder - #1775

Merged
karussell merged 42 commits into
masterfrom
move_tc_out_of_flag_encoder
Nov 25, 2019
Merged

karussell merged 42 commits into
masterfrom
move_tc_out_of_flag_encoder

Conversation

@karussell

@karussell karussell commented Nov 1, 2019 •

Copy link
Copy Markdown
Member

This pull request removes several methods of FlagEncoders and TurnCostEncoder.java and is one of the many tasks to remove this class like #1625. Especially in FlagEncoders that do not use turn costs like FootFlagEncoder you see the effects of this change. Also OSMReader.TurnCostTableEntry is no longer part of the public API.

Initially I wanted to create two PRs, one for the 'pure' relation and one for the turn restriction part, but I think this belongs together.

So this PR is based on the branch: https://github.com/graphhopper/graphhopper/commits/move_rel_out_of_flag_encoder where the first two commits move the relation handling out of FlagEncoder into a new RelationTagParser (plus some clean up commits). It also fixes a bug here that calling the super method here has no side effects: https://github.com/graphhopper/graphhopper/blob/master/core/src/main/java/com/graphhopper/routing/util/MountainBikeFlagEncoder.java#L150 Additionally there was code reduction possible in some FlagEncoders.

From commit 22b1483 it cleans up the turn relation parsing and moves it into OSMTurnRelationParser. The OSMReader shows its age here and needs some later rewrite maybe using mapdb or similar so that several workarounds can be avoided (this is tricky as it needs to be very fast). At the moment there are 2 phases: preprocessing and processing that both have 3 subprocedures:

  • 1.1. preprocess nodes, 1.2. preprocess way, 1.3. preprocess relations
  • 2.1. handle nodes, 2.2. handle way, 2.3. handle relations

The RelationTagParser fetches the ReaderRelation tags in step 1.3 and compacts them into relationFlags (IntsRef) to convert them in step 2.2 into edgeFlags: see the new EncodedValues for RouteNetwork (bike.network and foot.network). These EncodedValues can be used in other TagParsers.

The TurnCostParser is more involved and different to the RelationTagParser as it needs a traversable Graph and e.g. for car.turn_cost it requires a ready-to-use car.access. So this work is done at step 2.3. Also the method TurnCostParser.handleTurnRelationTags requires several parameters like the graph and an interface to convert between OSM and internal GraphHopper IDs.

TODOs:

  • cache EdgeExplorer creation in OSMTurnRelationParser like it was before?
  • Should we use one parser instead of the two OSMFootNetworkTagParser and OSMBikeNetworkTagParser that have only tiny differences? -> keep it separate
  • Make turn cost handling easier via Remove the GraphExtension interface #1772 (comment) and remove TurnCostAccess
  • rename TurnCostExtension to TurnCostStorage?
  • remove TODO NOWs

karussell and others added 4 commits November 9, 2019 23:14
# Conflicts:
#	core/src/main/java/com/graphhopper/routing/util/AbstractFlagEncoder.java
#	core/src/main/java/com/graphhopper/routing/util/BikeCommonFlagEncoder.java
#	core/src/main/java/com/graphhopper/routing/util/MotorcycleFlagEncoder.java
#	core/src/main/java/com/graphhopper/routing/util/MountainBikeFlagEncoder.java
#	core/src/main/java/com/graphhopper/routing/util/parsers/OSMMaxAxleLoadParser.java
#	core/src/main/java/com/graphhopper/routing/util/parsers/OSMMaxLengthParser.java
#	core/src/main/java/com/graphhopper/routing/util/parsers/OSMTollParser.java
#	core/src/main/java/com/graphhopper/routing/util/parsers/OSMTrackTypeParser.java
#	core/src/test/java/com/graphhopper/reader/dem/BridgeElevationInterpolatorTest.java
#	core/src/test/java/com/graphhopper/reader/dem/EdgeElevationInterpolatorTest.java
#	core/src/test/java/com/graphhopper/routing/PathTest.java
#	core/src/test/java/com/graphhopper/routing/util/AbstractBikeFlagEncoderTester.java
#	core/src/test/java/com/graphhopper/routing/util/BikeFlagEncoderTest.java
#	core/src/test/java/com/graphhopper/routing/util/CarFlagEncoderTest.java
#	core/src/test/java/com/graphhopper/routing/util/DataFlagEncoderTest.java
#	core/src/test/java/com/graphhopper/routing/util/EncodingManagerTest.java
#	core/src/test/java/com/graphhopper/routing/util/MountainBikeFlagEncoderTest.java
#	core/src/test/java/com/graphhopper/routing/util/parsers/OSMMaxAxleLoadParserTest.java
#	core/src/test/java/com/graphhopper/routing/util/parsers/OSMRoadClassParserTest.java
#	core/src/test/java/com/graphhopper/routing/util/parsers/OSMTollParserTest.java
#	core/src/test/java/com/graphhopper/routing/util/parsers/OSMTrackTypeParserTest.java
#	core/src/test/java/com/graphhopper/util/PathSimplificationTest.java
#	reader-osm/src/main/java/com/graphhopper/reader/osm/OSMReader.java
#	reader-osm/src/test/java/com/graphhopper/reader/osm/OSMReaderTest.java
@easbar

easbar commented Nov 11, 2019

Copy link
Copy Markdown
Member

Copied from now closed #1772:

Update: this would be also helpful for the branch move_tc_out_of_flag_encoder (#1775) and we could try if the following is possible:

instead of TurnCostAccess we make usage simple via:
edgeIteratorState.setTurnCost(carTurnCostEnc, nextEdgeId, 10.0) // base->adj->nextEdgeId
we move tcFlags inside EdgeIteratorState (remove it e.g. in TurnWeighting and TurnCostAccess)
we should be able to remove entire TurnCostAccess

easbar and others added 3 commits November 11, 2019 13:12
# Conflicts:
#	core/src/main/java/com/graphhopper/storage/TurnCostExtension.java
#	core/src/test/java/com/graphhopper/routing/BidirPathExtractorTest.java
#	core/src/test/java/com/graphhopper/routing/CHQueryWithTurnCostsTest.java
#	core/src/test/java/com/graphhopper/routing/RandomCHRoutingTest.java
#	core/src/test/java/com/graphhopper/routing/ch/EdgeBasedNodeContractorTest.java
#	core/src/test/java/com/graphhopper/routing/ch/Path4CHTest.java
#	core/src/test/java/com/graphhopper/routing/querygraph/QueryGraphTest.java
#	core/src/test/java/com/graphhopper/storage/GraphHopperStorageWithTurnCostsTest.java
#	core/src/test/java/com/graphhopper/storage/ShortcutUnpackerTest.java
#	core/src/test/java/com/graphhopper/storage/TurnCostExtensionTest.java
#	reader-osm/src/main/java/com/graphhopper/reader/osm/OSMReader.java
# Conflicts:
#	core/src/main/java/com/graphhopper/storage/TurnCostExtension.java
@karussell karussell changed the title WIP: move relation and turn relation parsing out of FlagEncoder move relation and turn relation parsing out of FlagEncoder Nov 23, 2019
@karussell karussell added this to the 1.0 milestone Nov 23, 2019
# Conflicts:
#	core/src/main/java/com/graphhopper/routing/ch/PrepareContractionHierarchies.java
#	core/src/main/java/com/graphhopper/routing/querygraph/QueryGraph.java
#	core/src/main/java/com/graphhopper/routing/querygraph/QueryGraphTurnExt.java
#	core/src/main/java/com/graphhopper/routing/weighting/TurnWeighting.java
#	core/src/main/java/com/graphhopper/util/GHUtility.java
#	core/src/test/java/com/graphhopper/routing/BidirPathExtractorTest.java
#	core/src/test/java/com/graphhopper/routing/CHQueryWithTurnCostsTest.java
#	core/src/test/java/com/graphhopper/routing/DirectedBidirectionalDijkstraTest.java
#	core/src/test/java/com/graphhopper/routing/RandomCHRoutingTest.java
#	core/src/test/java/com/graphhopper/routing/ch/CHTurnCostTest.java
#	core/src/test/java/com/graphhopper/routing/ch/EdgeBasedNodeContractorTest.java
#	core/src/test/java/com/graphhopper/routing/ch/Path4CHTest.java
#	core/src/test/java/com/graphhopper/routing/querygraph/QueryGraphTest.java
#	core/src/test/java/com/graphhopper/routing/weighting/DirectedRoutingTest.java
#	core/src/test/java/com/graphhopper/storage/GraphHopperStorageWithTurnCostsTest.java
#	core/src/test/java/com/graphhopper/storage/ShortcutUnpackerTest.java
#	core/src/test/java/com/graphhopper/storage/TurnCostStorageTest.java
#	reader-osm/src/main/java/com/graphhopper/reader/osm/OSMReader.java
# Conflicts:
#	core/src/test/java/com/graphhopper/routing/CHQueryWithTurnCostsTest.java
#	core/src/test/java/com/graphhopper/routing/DirectedBidirectionalDijkstraTest.java
#	core/src/test/java/com/graphhopper/routing/EdgeBasedRoutingAlgorithmTest.java
#	core/src/test/java/com/graphhopper/routing/ch/CHTurnCostTest.java
#	core/src/test/java/com/graphhopper/routing/ch/EdgeBasedNodeContractorTest.java
#	core/src/test/java/com/graphhopper/routing/ch/Path4CHTest.java
#	core/src/test/java/com/graphhopper/routing/weighting/TurnWeightingTest.java
#	core/src/test/java/com/graphhopper/storage/ShortcutUnpackerTest.java
// todo:
// also this does not allow TurnCostEncoder to set the u-turn costs to zero explicitly, like FootFlagEncoder!
// this problem is a bit hidden, because if you do not apply any turn restrictions (like FootFlagEncoder)
// you never do a u-turn anyway.

@easbar easbar Nov 24, 2019 •

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.

the comment (or at least the line before 'todo' still applies, no ? setting u-turn costs on turnCostExt has no effect, because the uTurnCosts take a higher priority here.

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.

Ah, ok. This is what was meant with the comment before the todo. I'll revert the removal of that.

Regarding the TODO: the FootFlagEncoder does not have any turn restriction stuff but still overwriting/overruling is not possible.

BTW: could we make isUTurn dependent on turnCostEnc and then remove this comment?

* This creates an EncodedValue specifically for the turn costs
*/
public static DecimalEncodedValue create(String name, int maxTurnCosts) {
int turnBits = Helper.countBitValue(maxTurnCosts);

@easbar easbar Nov 25, 2019 •

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.

Not sure if this is relevant here, but IntelliJ complains about return counter++ in Helper#countBitValue (counter is incremented "after" it is returned)

IntsRef tcFlags = new IntsRef(turnCostFlags.length);
getTurnCostEnc().setDecimal(false, tcFlags, Double.POSITIVE_INFINITY);
entries.add(entry);
tcs.setTurnCost(tcFlags, edgeIdFrom, viaNode, iter.getEdge());

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.

Why can we not use tcs.set(...) here and why do we (need to) create a new IntsRef everytime we are here ?

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.

Ah, yes. It is indeed no longer required to create a new IntsRef now that we do no collect the TurnCostEntry. And will also try to use tcs.set...

@easbar

easbar commented Nov 25, 2019

Copy link
Copy Markdown
Member

LGTM

@karussell

Copy link
Copy Markdown
Member Author

Thanks a lot for the review - I finally could get rid of a bit more code :)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants