Skip to content

Preparing support of turn restrictions (3): Import of turn restrictions - #135

Merged
karussell merged 13 commits into
graphhopper:masterfrom
kschrab:master
Jan 7, 2014
Merged

karussell merged 13 commits into
graphhopper:masterfrom
kschrab:master

Conversation

@kschrab

@kschrab kschrab commented Dec 27, 2013

Copy link
Copy Markdown
Contributor

OSM relations of type "restriction" can be imported. According to the restriction type, several entries will be added to the turn cost table. Furthermore, the turn flag encoder is now implemented by the current edge encoders (e.g., foot flag encoder do not store any turn flags) instead of additional turn flag encoders. Import of TurnRestrictions can be enabled by GraphHopper#setEnableTurnRestrictions(true), which is disabled by default and won't be considered by any routing algorithms yet.

The next step will be edge-based routing algorithms which are able to consider those restrictions.

OSM relations of type "restriction" will be imported. According to the
restriction type, several entries will be added to a turn cost table.
Furthermore, the turn flag encoder is now implemented by the current
edge encoders (e.g., foot flag encoder do not store any turn flags).
Import can be enabled by GraphHopper#setEnableTurnRestrictions(true),
which is disabled by default.
@karussell

Copy link
Copy Markdown
Member

Thanks! Looks good!

Some questions:

  • instead of the new bit methods in Helper can you use BitUtil instead which takes care of LITTLE/BIG?
  • In TurnCostItemEntry.getItemId how important is it to avoid uniqueness? Probably type 'long' or XORing would be better?
  • Is the static in static Collection<TurnCostTableEntry> getRestrictionAsEntries really necessary as the first arg is already a OSMTurnRelation (?)
  • Info for me: determineRequiredBits looks valuable for EncodedValue to avoid specifying the bits

@kschrab

kschrab commented Jan 5, 2014

Copy link
Copy Markdown
Contributor Author

I added a new commit with your desired changes :)

@karussell

Copy link
Copy Markdown
Member

Thanks!

One major problem is the edgeOsmIds - this will either require lots of RAM or slow down the import if mmapped. I'll have to think about it. This is mainly the same problem we have for nodes and its mapped properties. But introducing another fat map for edges is not good as the node map is already around 8GB for the world wide case :(

Hmmh, but there is another problem that there are more than one edge IDs for every way ID as the way will split at junctions and barriers.

@karussell

Copy link
Copy Markdown
Member

I've not fixed this problem but still you can "git cherry-pick" the one commit from my temporary issue_135 branch: https://github.com/graphhopper/graphhopper/commits/issue_135. I cannot push to your repo which would be necessary to list the commit here. Not sure why it is so complicated.

@kschrab

kschrab commented Jan 6, 2014

Copy link
Copy Markdown
Contributor Author

I cherry-picked your commit, and I gave you the permission to push to my repo.

But introducing another fat map for edges is not good as the node map is already around 8GB for the world wide case :(

We definitely need to store the osmids for each edge to apply turn restrictions, since relations are always at the end of the osm file. However, maybe we could read out relations at first and in a second run we create nodes/edges and apply turn restrictions. In this case we only need to map edgeid->osmid for all osmids which have been found in relevant relations. This would slow down the import process due to reading the osm file twice, but should reduce the memory usage a lot on the other hand . What do you think?
UPDATE: I see, the osm file is already processed twice, maybe we should use this.
However, if we map only a part of edge ids to osmids then we cannot use the DataAccess interface due to missing pointer information. Would it be a problem if we use a TIntLongMap to map all relevant edgeids->osmids? I have no experience with the world wide scenario, how many relations of type restriction does the world wide osm file contain?

Hmmh, but there is another problem that there are more than one edge IDs for every way ID

Yep, because of this I map edgeid->osmid and search for the relevant edge later in getRestrictionsAsEntries using the edge explorer pattern. Or what do you mean?

@karussell

Copy link
Copy Markdown
Member

I cherry-picked your commit, and I gave you the permission to push to my repo.

thanks

UPDATE: I see, the osm file is already processed twice, maybe we should use this.

Yes, would be nice :) !

TIntLongMap to map all relevant edgeids->osmids

This should be okay - at least a lot better than storing every edge. And at some point in the future we re-code the whole import process to make this all a lot easier and probably file based, similar to what https://github.com/jillesvangurp/osm2geojson is doing (import all nodes and write a sorted file which mapes ID to json, the same for ways + relations).

Or what do you mean?

ah, yes so this is okay.

@karussell

Copy link
Copy Markdown
Member

Would you mind to go ahead one more time and use the "double-parse" logic :) ? Would really appreciate it as there is another (big) problem for a pull request.

@kschrab

kschrab commented Jan 6, 2014

Copy link
Copy Markdown
Contributor Author

there it is

@karussell

Copy link
Copy Markdown
Member

Wow, that was fast! I'll merge soon and test if a world wide import is possible.

There is one minor thing which I will probably work on later: EncodingManager.analyzeTurnRelation has too many dependencies like the OSMReader and the GraphStorage and the EdgeExplorers. I would like to somehow avoid them there and move the parts more into the OSMReader. At least the OSMReader should move away as this is is "OSM stuff" whereas turn costs should be more generic.

@karussell

Copy link
Copy Markdown
Member

BTW: For which cases did you create the OSMRelationFactory? Ah and also the license header (+ @author in some cases) should be added to the new stuff

@kschrab

kschrab commented Jan 6, 2014

Copy link
Copy Markdown
Contributor Author

For which cases did you create the OSMRelationFactory?

Meeh, I'm not sure. Maybe I thought "that could be useful sometime", e.g. if other relation types should be processed. There is no particular reason. So if you want to kick it out, I'll do so.

@karussell

Copy link
Copy Markdown
Member

So if you want to kick it out, I'll do so.

Yes, please :) ... although I think there is something in common with the relation stuff done for the bike route stuff and so something like this could be useful later.

@karussell

Copy link
Copy Markdown
Member

BTW: if you ever need to test real world turn instruction and need a nice overview, here I found one: http://map.comlu.com/ (zoom in to see what I mean)

karussell pushed a commit that referenced this pull request Jan 7, 2014
Preparing support of turn restrictions (3): Import of turn restrictions
@karussell
karussell merged commit 3beffe7 into graphhopper:master Jan 7, 2014
@kschrab

kschrab commented Jan 7, 2014

Copy link
Copy Markdown
Contributor Author

👍

@renauddl

Copy link
Copy Markdown

Hi there,

I was reading the code regarding turn cost found at:

https://github.com/graphhopper/graphhopper/pull/135/files

I feel that there is something wrong with the criterion for inserting a
shortcut during the PrepareContraction

Let be the following graph portion:

w x
\ /
a - c - b
/
y z

we want to find shortcuts for contracting c.

The criterion currently used is:
is the path from a to b passing through c the strictly cheapest one?
if yes, a shortcut is needed.
This criterion includes the cost of manoeuvring from the segment a-c to
the segment c-b

I might be wrong, but I believe that there is a problem with this
criterion.

When computing a path, you actually arrive from an incoming edge, say
from w in the picture above, and you leave b through an outgoing edge,
say through z.
There are also cost of manoeuvring from w-a to a-c, and from c-b to b-z.
These "boundary costs" might be different when passing through c, or
when avoiding c, since you will enter another segment than a-c, and
leave through another segment than c-b.

I therefore believe that the criterion for adding a shortcut a-b when
contracting c should be the following

if
for any incoming edges to a called I (eg: w-a, and y-a)
for any outgoing edge from b called O (eg: b-x, and b-z)
the path I-a-c-b-O is the strictly cheapest one binding I to O then
then a shortcut must be added

This criterion is more expensive to compute, and I believe that it is
also a bit more demanding, that is: more shortcuts might be added.

Renaud De Landtsheer, Ir, Phd
Sr R&D Engineer
CETIC
Rue des Frères Wright, 29/3
B-6041 Charleroi
Phone: +32 71 490 754

@karussell

Copy link
Copy Markdown
Member

(question was answered on mailing list)

I just wanted to test the memory behaviour of this feature and an error occured:

java.lang.RuntimeException: Couldn't process file maps/bayern.pbf
        at com.graphhopper.reader.OSMReader.writeOsm2Graph(OSMReader.java:323)
        at com.graphhopper.reader.OSMReader.doOSM2Graph(OSMReader.java:151)
        at com.graphhopper.GraphHopper.importOSM(GraphHopper.java:482)
        at com.graphhopper.GraphHopper.process(GraphHopper.java:454)
        at com.graphhopper.GraphHopper.importOrLoad(GraphHopper.java:434)
        at com.graphhopper.GraphHopper.main(GraphHopper.java:47)
Caused by: java.lang.IllegalStateException: Could not built node costs table for relation of node [osmId:1981656728].
        at com.graphhopper.reader.OSMTurnRelation.getRestrictionAsEntries(OSMTurnRelation.java:148)
        at com.graphhopper.routing.util.CarFlagEncoder.analyzeTurnRelation(CarFlagEncoder.java:250)
        at com.graphhopper.routing.util.EncodingManager.analyzeTurnRelation(EncodingManager.java:414)
        at com.graphhopper.reader.OSMReader.processRelation(OSMReader.java:472)
        at com.graphhopper.reader.OSMReader.writeOsm2Graph(OSMReader.java:311)
        ... 5 more
Caused by: java.lang.IllegalArgumentException: Unknown node osm id
        at com.graphhopper.reader.OSMTurnRelation.getRestrictionAsEntries(OSMTurnRelation.java:90)
        ... 9 more

karussell pushed a commit that referenced this pull request Jul 18, 2014
dabiih pushed a commit to dabiih/graphhopper that referenced this pull request Jan 7, 2025
dabiih pushed a commit to dabiih/graphhopper that referenced this pull request Jan 7, 2025
dabiih pushed a commit to dabiih/graphhopper that referenced this pull request Jan 7, 2025
dabiih pushed a commit to dabiih/graphhopper that referenced this pull request Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants