Skip to content

Commit bfb74c2

Browse files
authored
Fix snapping target locations to ways used in turn restrictions (#6339)
Currently there is an edge-case in the turn restriction implementation, such that routes can not be found if the target input location snaps to a way used in a (multi) via restriction. With the addition of snapping input locations to multiple ways, we can now also snap to the "duplicate" edges created for the restriction graph, thereby fixing the problem. This is achieved by adding the duplicate restriction edges to the geospatial search RTree. This does open up the possibility of multiple paths representing exactly the same route - one using the original edge as a source, the other using the duplicate restriction graph edge as source. This is fine, as both edges are represented by the same geometry, so will generate the same result.
1 parent 3d5db45 commit bfb74c2

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
- ADDED: Add support for non-round-trips with a single fixed endpoint. [#6050](https://github.com/Project-OSRM/osrm-backend/pull/6050)
5151
- FIXED: Improvements to maneuver override processing [#6125](https://github.com/Project-OSRM/osrm-backend/pull/6125)
5252
- ADDED: Support snapping to multiple ways at an input location. [#5953](https://github.com/Project-OSRM/osrm-backend/pull/5953)
53+
- FIXED: Fix snapping target locations to ways used in turn restrictions. [#6339](https://github.com/Project-OSRM/osrm-backend/pull/6339)
5354

5455
# 5.26.0
5556
- Changes from 5.25.0

features/car/multi_via_restrictions.feature

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,3 +1031,61 @@ Feature: Car - Multiple Via Turn restrictions
10311031
| from | to | route | locations |
10321032
| a | f | ab,bc,cd,de,ef,ef | a,b,c,d,e,f |
10331033

1034+
1035+
@restriction-way
1036+
Scenario: Snap source/target to via restriction way
1037+
Given the node map
1038+
"""
1039+
a-1-b-2-c-3-d
1040+
"""
1041+
1042+
And the ways
1043+
| nodes |
1044+
| ab |
1045+
| bc |
1046+
| cd |
1047+
1048+
And the relations
1049+
| type | way:from | way:via | way:to | restriction |
1050+
| restriction | ab | bc | cd | no_straight_on |
1051+
1052+
When I route I should get
1053+
| from | to | route |
1054+
| 1 | 2 | ab,bc,bc |
1055+
| 2 | 3 | bc,cd,cd |
1056+
1057+
1058+
@restriction-way
1059+
Scenario: Car - Snap source/target to multi-via restriction way
1060+
# Example: https://www.openstreetmap.org/relation/11787041
1061+
Given the node map
1062+
"""
1063+
|--g---f---e
1064+
a | 1
1065+
|--b---c---d
1066+
1067+
"""
1068+
1069+
And the nodes
1070+
| node | highway |
1071+
| b | traffic_signals |
1072+
1073+
And the ways
1074+
| nodes | oneway | name |
1075+
| ab | yes | enter |
1076+
| bc | yes | enter |
1077+
| cd | yes | right |
1078+
| de | yes | up |
1079+
| ef | yes | left |
1080+
| fc | yes | down |
1081+
| fg | yes | exit |
1082+
| ga | yes | exit |
1083+
1084+
And the relations
1085+
| type | way:from | way:via | way:to | restriction |
1086+
| restriction | bc | cd,de,ef | fg | no_u_turn |
1087+
1088+
When I route I should get
1089+
| from | to | route | locations |
1090+
| a | 1 | enter,right,up,up | a,c,d,_ |
1091+
| 1 | a | up,left,exit,exit | _,e,f,a |

src/extractor/edge_based_graph_factory.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,48 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedNodes(const WayRestrictionMap &way_re
414414
// the only consumer of this mapping).
415415
mapping.push_back(NBGToEBG{node_u, node_v, edge_based_node_id, SPECIAL_NODEID});
416416

417+
// We also want to include duplicate via edges in the list of segments that
418+
// an input location can snap to. Without this, it would be possible to not find
419+
// certain routes that end on a via-way, because they are only routable via the
420+
// duplicated edge.
421+
const auto &forward_geometry = m_compressed_edge_container.GetBucketReference(eid);
422+
const auto segment_count = forward_geometry.size();
423+
424+
NodeID current_edge_source_coordinate_id = node_u;
425+
const EdgeData &forward_data = m_node_based_graph.GetEdgeData(eid);
426+
427+
const auto edge_id_to_segment_id = [](const NodeID edge_based_node_id) {
428+
if (edge_based_node_id == SPECIAL_NODEID)
429+
{
430+
return SegmentID{SPECIAL_SEGMENTID, false};
431+
}
432+
433+
return SegmentID{edge_based_node_id, true};
434+
};
435+
436+
// Add segments of edge-based nodes
437+
for (const auto i : util::irange(std::size_t{0}, segment_count))
438+
{
439+
const NodeID current_edge_target_coordinate_id = forward_geometry[i].node_id;
440+
441+
// don't add node-segments for penalties
442+
if (current_edge_target_coordinate_id == current_edge_source_coordinate_id)
443+
continue;
444+
445+
BOOST_ASSERT(current_edge_target_coordinate_id !=
446+
current_edge_source_coordinate_id);
447+
448+
// build edges
449+
m_edge_based_node_segments.emplace_back(edge_id_to_segment_id(edge_based_node_id),
450+
SegmentID{SPECIAL_SEGMENTID, false},
451+
current_edge_source_coordinate_id,
452+
current_edge_target_coordinate_id,
453+
i,
454+
forward_data.flags.startpoint);
455+
456+
current_edge_source_coordinate_id = current_edge_target_coordinate_id;
457+
}
458+
417459
edge_based_node_id++;
418460
progress.PrintStatus(progress_counter++);
419461
}

0 commit comments

Comments
 (0)