Skip to content

WIP: Via way restrictions - #2656

Closed
lukasalexanderweber wants to merge 24 commits into
graphhopper:masterfrom
lukasalexanderweber:via_way_restrictions
Closed

lukasalexanderweber wants to merge 24 commits into
graphhopper:masterfrom
lukasalexanderweber:via_way_restrictions

Conversation

@lukasalexanderweber

@lukasalexanderweber lukasalexanderweber commented Sep 7, 2022 •

Copy link
Copy Markdown
Contributor

background: https://discuss.graphhopper.com/t/add-support-for-complex-turn-restrictions/7326

I implemented the reading of via way and multi via way turn restrictions. The next step would be to consider this information in the graph creation. For now, I would just ask you if you are fine with the way those turn restrictions are read?

@lukasalexanderweber
lukasalexanderweber force-pushed the via_way_restrictions branch 3 times, most recently from 7988305 to 9e42b1e Compare September 8, 2022 06:15
@lukasalexanderweber

Copy link
Copy Markdown
Contributor Author

At the moment I think that the Restriction graph approach of OSRM could be applicable for graphhoppers graph creation, too. If you think so too, i would try to implement this.

@karussell

Copy link
Copy Markdown
Member

At the moment I think that the Restriction graph approach of Project-OSRM/osrm-backend#5907 could be applicable for graphhoppers graph creation, too. If you think so too, i would try to implement this.

Not sure if it is applicable as they use an edge-based graph (nodes are road segments) and our graph is node-based (nodes are junctions)

@lukasalexanderweber
lukasalexanderweber force-pushed the via_way_restrictions branch 2 times, most recently from ad33bf9 to 1e71812 Compare September 8, 2022 08:43
@lukasalexanderweber

This comment was marked as outdated.

@lukasalexanderweber

This comment was marked as outdated.

@karussell

karussell commented Sep 14, 2022 •

Copy link
Copy Markdown
Member

I'm not deep into this matter, but from "far away" this sounds good to me and makes sense.

See also the existing issue where @easbar showed a slightly different approach ( I think :) )

Multi Via Way

Maybe focus on the single via ways for now (especially when the multi-via-way handling is more complicated) and when everything is working (including the snap prevention etc) we revisit this :)

Removal of the copied node bn (as a shortcut) should be prevented, since then the navigation instruction to turn left would be missing

What do you mean here?

@lukasalexanderweber

This comment was marked as outdated.

@lukasalexanderweber

This comment was marked as outdated.

@karussell

karussell commented Sep 14, 2022 •

Copy link
Copy Markdown
Member

will the graph still be correct if the distance between bn and b is 0? So is there "place" for 1n?

Yes, edges with a 0 distance might make problems - see #2636 or #2302. But we already create edges with distance==0 for barriers (see WaySegmentParser.splitSegmentAtSplitNodes), so the code might be (otherwise) relative robust :)

@lukasalexanderweber

Copy link
Copy Markdown
Contributor Author

Ok, to summarize:

Given the graph

original_s

with the no_u_turn restriction from 1 via 2 to 3

During graph preperation, we will:

  1. introduce an artificial node bn and edges a -> bn 1n and bn -> b 1
  2. add an artificial edge (oneway) bn -> c 2n
  3. deny the turn 1 -> b -> 2
  4. deny the turn 2n -> c -> 3
  5. deny the turn 1 -> bn -> 2n

umleitung_s

Notes:

  • The distance between b and bn is 0
  • The edge 2n should be 'hidden' for the location index (see ferries: #322)

Proof of Concept:

original.osm
<?xml version='1.0' encoding='UTF-8'?>
<osm version="0.6" generator="pbf2osm">
    <!-- 
	
	    10
	    |
    1~~~2~~~3~~~4
        |   |   |
        |   5~~~6 
        |   |
    7~~~8~~~9
        |
		11

    (1,2)->(2,8)->(8,7): no_u_turn
    (2,3)->(3,5)->(5,9)->(9,8): no_u_turn
    -->

    <node id="1" lat="0.050" lon="0.010" version="1"></node>
    <node id="2" lat="0.052" lon="0.010" version="1"></node>
    <node id="3" lat="0.054" lon="0.010" version="1"></node>
    <node id="4" lat="0.056" lon="0.010" version="1"></node>
    <node id="5" lat="0.054" lon="0.012" version="1"></node>
    <node id="6" lat="0.056" lon="0.012" version="1"></node>
    <node id="7" lat="0.050" lon="0.014" version="1"></node>
    <node id="8" lat="0.052" lon="0.014" version="1"></node>
    <node id="9" lat="0.054" lon="0.014" version="1"></node>
    <node id="10" lat="0.052" lon="0.008" version="1"></node>
    <node id="11" lat="0.052" lon="0.016" version="1"></node>

    <!-- 10-2 -->
    <way id="102" version="1">
        <nd ref="10"/>
        <nd ref="2"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 1-2 -->
    <way id="12" version="1">
        <nd ref="1"/>
        <nd ref="2"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 2-3 -->
    <way id="23" version="1">
        <nd ref="2"/>
        <nd ref="3"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 3-4 -->
    <way id="34" version="1">
        <nd ref="3"/>
        <nd ref="4"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 2-8 -->
    <way id="28" version="1">
        <nd ref="2"/>
        <nd ref="8"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 3-5 -->
    <way id="35" version="1">
        <nd ref="3"/>
        <nd ref="5"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 4-6 -->
    <way id="46" version="1">
        <nd ref="4"/>
        <nd ref="6"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 5-6 -->
    <way id="56" version="1">
        <nd ref="5"/>
        <nd ref="6"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 5-9 -->
    <way id="59" version="1">
        <nd ref="5"/>
        <nd ref="9"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 7-8 -->
    <way id="78" version="1">
        <nd ref="7"/>
        <nd ref="8"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 8-9 -->
    <way id="89" version="1">
        <nd ref="8"/>
        <nd ref="9"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 8-11 -->
    <way id="811" version="1">
        <nd ref="8"/>
        <nd ref="11"/>
        <tag k="highway" v="motorway"/>
    </way>

    <relation id="1001" version="1">
        <member type="way" ref="12" role="from"/>
        <member type="way" ref="28" role="via"/>
        <member type="way" ref="78" role="to"/>
        <tag k="restriction" v="no_u_turn"/>
        <tag k="type" v="restriction"/>
    </relation>

    <relation id="1002" version="1">
        <member type="way" ref="23" role="from"/>
        <member type="way" ref="35" role="via"/>
        <member type="way" ref="59" role="via"/>
        <member type="way" ref="89" role="to"/>
        <tag k="restriction" v="no_u_turn"/>
        <tag k="type" v="restriction"/>
    </relation>

</osm>
modified.osm
<?xml version='1.0' encoding='UTF-8'?>
<osm version="0.6" generator="pbf2osm">
    <!-- 
	
        10
        |
    1~~~2~~~3~~~4
        |   |   |
        |   5~~~6 
        |   |
    7~~~8~~~9
        |
        11

    (1,2)->(2,8)->(8,7): no_u_turn
    (2,3)->(3,5)->(5,9)->(9,8): no_u_turn
    -->

    <node id="1" lat="0.050" lon="0.010" version="1"></node>
    <node id="2" lat="0.052" lon="0.010" version="1"></node>
    <node id="3" lat="0.054" lon="0.010" version="1"></node>
    <node id="4" lat="0.056" lon="0.010" version="1"></node>
    <node id="5" lat="0.054" lon="0.012" version="1"></node>
    <node id="6" lat="0.056" lon="0.012" version="1"></node>
    <node id="7" lat="0.050" lon="0.014" version="1"></node>
    <node id="8" lat="0.052" lon="0.014" version="1"></node>
    <node id="80" lat="0.052" lon="0.014" version="1"></node>
    <node id="9" lat="0.054" lon="0.014" version="1"></node>
    <node id="10" lat="0.052" lon="0.008" version="1"></node>
    <node id="11" lat="0.052" lon="0.016" version="1"></node>

    <!-- 10-2 -->
    <way id="102" version="1">
        <nd ref="10"/>
        <nd ref="2"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 1-2 -->
    <way id="12" version="1">
        <nd ref="1"/>
        <nd ref="2"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 2-3 -->
    <way id="23" version="1">
        <nd ref="2"/>
        <nd ref="3"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 3-4 -->
    <way id="34" version="1">
        <nd ref="3"/>
        <nd ref="4"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 2-8 -->
    <way id="28" version="1">
        <nd ref="2"/>
        <nd ref="8"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 2-80 -->
    <way id="280" version="1">
        <nd ref="2"/>
        <nd ref="80"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 3-5 -->
    <way id="35" version="1">
        <nd ref="3"/>
        <nd ref="5"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 4-6 -->
    <way id="46" version="1">
        <nd ref="4"/>
        <nd ref="6"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 5-6 -->
    <way id="56" version="1">
        <nd ref="5"/>
        <nd ref="6"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 5-9 -->
    <way id="59" version="1">
        <nd ref="5"/>
        <nd ref="9"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 7-8n -->
    <way id="78" version="1">
        <nd ref="7"/>
        <nd ref="80"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 8-8n -->
    <way id="88" version="1">
        <nd ref="80"/>
        <nd ref="8"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 8-9 -->
    <way id="89" version="1">
        <nd ref="8"/>
        <nd ref="9"/>
        <tag k="highway" v="motorway"/>
    </way>

    <!-- 8-11 -->
    <way id="811" version="1">
        <nd ref="8"/>
        <nd ref="11"/>
        <tag k="highway" v="motorway"/>
    </way>

    <relation id="1001" version="1">
        <member type="way" ref="88" role="from"/>
        <member type="node" ref="8" role="via"/>
        <member type="way" ref="28" role="to"/>
        <tag k="restriction" v="no_left_turn"/>
        <tag k="type" v="restriction"/>
    </relation>

    <relation id="1002" version="1">
        <member type="way" ref="280" role="from"/>
        <member type="node" ref="2" role="via"/>
        <member type="way" ref="12" role="to"/>
        <tag k="restriction" v="no_left_turn"/>
        <tag k="type" v="restriction"/>
    </relation>

</osm>

Routing on modified.osm yields the desired result, preventing the u turn while allowing a left turn:

image

@lukasalexanderweber
lukasalexanderweber force-pushed the via_way_restrictions branch 2 times, most recently from af86a9d to ce9aede Compare September 15, 2022 11:40
@lukasalexanderweber
lukasalexanderweber force-pushed the via_way_restrictions branch 3 times, most recently from e777970 to 171f981 Compare September 28, 2022 12:48

@lukasalexanderweber lukasalexanderweber left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...

@lukasalexanderweber lukasalexanderweber left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first tests are successfull for real life turn restrictions. Now some refinements are needed.

LongArrayList longalist = new LongArrayList();
longalist.add(artificialViaNodes.get(r.getVia()));
longalist.add(r.getVia());
ReaderWay artificial_way2 = new ReaderWay(newOsmId2, way.getTags(), longalist);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somehow the tags (street names) and navigation instructions are not working correctly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe because of negative Ids?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further analysis shows that the navigation instructions are only manipulated on the edges with distance 0. Maybe we can collect some ideas on how to handle this.

if one way being part of the turn restriction don't have exactly two tower nodes, it won't be proccessed.
For these restrictions we need to dig deeper into where we put node restrictions.
WaySegmentParser makes most of the OSM reading and got quite complex.

To-Dos:
- Logging
- Correct State Transitions during Parsing
@otbutz

otbutz commented Oct 6, 2022

Copy link
Copy Markdown
Contributor

Could we simplify/breakup the OSMReader in a different PR?

@lukasalexanderweber

Copy link
Copy Markdown
Contributor Author

yeah as things got bigger than expected, I will split this in multiple PRs.

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