Skip to content

Commit ea583a7

Browse files
Moritz KobitzschTheMarex
authored andcommitted
reduce verbosity of use-lane in combination with lane-anticipation
1 parent dd999e1 commit ea583a7

File tree

4 files changed

+65
-15
lines changed

4 files changed

+65
-15
lines changed

features/guidance/anticipate-lanes.feature

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,3 +818,37 @@ Feature: Turn Lane Guidance
818818
When I route I should get
819819
| waypoints | route | turns | lanes |
820820
| a,e | MySt,MySt,MySt,MySt | depart,continue right,turn right,arrive | ,straight:false straight:false right:false right:true,left:false right:true, |
821+
822+
@anticipate
823+
Scenario: Don't Overdo It
824+
Given the node map
825+
"""
826+
q r s t u v
827+
| | | | | |
828+
a - - - - - - - - - - b - - - - - - - - - - c - - - - - - - - - - d - - - - - - - - - - e - - - - - - - - - - f - - - - - - - - - - g - h - i
829+
| | | | | | |
830+
p o n m l k j
831+
"""
832+
833+
And the ways
834+
| nodes | name | turn:lanes:forward | oneway |
835+
| ab | road | left\|\|\| | yes |
836+
| bc | road | left\|\|\| | yes |
837+
| cd | road | left\|\|\| | yes |
838+
| de | road | left\|\|\| | yes |
839+
| ef | road | left\|\|\| | yes |
840+
| fg | road | left\|\|\| | yes |
841+
| gh | road | \|\|right | yes |
842+
| hi | road | | yes |
843+
| qbp | 1st | | no |
844+
| rco | 2nd | | no |
845+
| sdn | 3rd | | no |
846+
| tem | 4th | | no |
847+
| ufl | 5th | | no |
848+
| vgk | 6th | | no |
849+
| hj | 7th | | no |
850+
851+
When I route I should get
852+
| waypoints | route | turns | locations | lanes |
853+
| a,i | road,road,road | depart,use lane straight,arrive | a,g,i | ,left:false none:true none:true none:false, |
854+
| a,j | road,road,7th,7th | depart,use lane straight,turn right,arrive | a,f,h,j | ,left:false none:false none:false none:true,none:false none:false right:true, |

include/engine/guidance/lane_processing.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace guidance
2020
// as separate maneuvers.
2121
OSRM_ATTR_WARN_UNUSED
2222
std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps,
23-
const double min_duration_needed_for_lane_change = 15);
23+
const double min_duration_needed_for_lane_change = 10);
2424

2525
} // namespace guidance
2626
} // namespace engine

include/engine/guidance/post_processing.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ std::vector<RouteStep> collapseTurns(std::vector<RouteStep> steps);
2828

2929
// A check whether two instructions can be treated as one. This is only the case for very short
3030
// maneuvers that can, in some form, be seen as one. Lookahead of one step.
31+
// This is only a pre-check and does not necessarily allow collapsing turns!!!
3132
bool collapsable(const RouteStep &step, const RouteStep &next);
3233

3334
// trim initial/final segment of very short length.

src/engine/guidance/lane_processing.cpp

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps,
7474

7575
// We're walking backwards over all adjacent turns:
7676
// the current turn lanes constrain the lanes we have to take in the previous turn.
77+
78+
// state for the lamda
79+
// the number of lanes we have to change depends on the number of lanes that are allowed for
80+
// a turn (in general) and the set of lanes which would allow for us to do the turn without
81+
// a problem. In a sequence of turns, we have to look at how much time we need to switch the
82+
// sequence. Given the turns in between, we would expect a bit longer than on a straight
83+
// segment for a lane switch, but the total time shouldn't be unlimited.
84+
double time_to_constrained = 0.0;
85+
7786
util::for_each_pair(rev_first, rev_last, [&](RouteStep &current, RouteStep &previous) {
7887
const auto current_inst = current.maneuver.instruction;
7988
const auto current_lanes = current.intersections.front().lanes;
@@ -88,7 +97,18 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps,
8897
const bool lanes_to_constrain = previous_lanes.lanes_in_turn > 1;
8998
const bool lanes_fan_in = previous_lanes.lanes_in_turn > current_lanes.lanes_in_turn;
9099

91-
if (!lanes_to_constrain || !lanes_fan_in)
100+
// only prevent use lanes due to making all turns. don't make turns during curvy
101+
// segments
102+
if (previous_inst.type == TurnType::UseLane)
103+
time_to_constrained += previous.duration;
104+
else
105+
time_to_constrained = 0;
106+
107+
const auto lane_delta = previous_lanes.lanes_in_turn - current_lanes.lanes_in_turn;
108+
const auto can_make_all_turns =
109+
time_to_constrained > lane_delta * min_duration_needed_for_lane_change;
110+
111+
if (!lanes_to_constrain || !lanes_fan_in || can_make_all_turns)
92112
return;
93113

94114
// We do not have a mapping from lanes to lanes. All we have is the lanes in the turn
@@ -99,9 +119,6 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps,
99119
const LaneID current_num_lanes_right_of_turn = current.NumLanesToTheRight();
100120
const LaneID current_num_lanes_left_of_turn = current.NumLanesToTheLeft();
101121

102-
const LaneID num_shared_lanes = std::min(current_lanes.lanes_in_turn, //
103-
previous_lanes.lanes_in_turn); //
104-
105122
// 0/ Tag keep straight with the next turn's direction if available
106123
const auto previous_is_straight =
107124
!isLeftTurn(previous_inst) && !isRightTurn(previous_inst);
@@ -121,14 +138,14 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps,
121138
LaneID new_first_lane_from_the_right =
122139
previous_lanes.first_lane_from_the_right // start from rightmost lane
123140
+ previous_lanes.lanes_in_turn // one past leftmost lane
124-
- num_shared_lanes; // back number of new lanes
141+
- current_lanes.lanes_in_turn; // back number of new lanes
125142

126143
// The leftmost target lanes might not be involved in the turn. Figure out
127144
// how many lanes are to the left and not in the turn.
128145
new_first_lane_from_the_right -=
129-
std::min(current_num_lanes_left_of_turn, num_shared_lanes);
146+
std::min(current_num_lanes_left_of_turn, current_lanes.lanes_in_turn);
130147

131-
previous_lanes = {num_shared_lanes, new_first_lane_from_the_right};
148+
previous_lanes = {current_lanes.lanes_in_turn, new_first_lane_from_the_right};
132149
};
133150

134151
const auto anticipate_for_right_turn = [&] {
@@ -139,9 +156,9 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps,
139156
// The rightmost target lanes might not be involved in the turn. Figure out
140157
// how many lanes are to the right and not in the turn.
141158
new_first_lane_from_the_right +=
142-
std::min(current_num_lanes_right_of_turn, num_shared_lanes);
159+
std::min(current_num_lanes_right_of_turn, current_lanes.lanes_in_turn);
143160

144-
previous_lanes = {num_shared_lanes, new_first_lane_from_the_right};
161+
previous_lanes = {current_lanes.lanes_in_turn, new_first_lane_from_the_right};
145162
};
146163

147164
// 2/ When to anticipate a left, right turn
@@ -179,13 +196,11 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps,
179196
anticipate_for_right_turn();
180197
}
181198

182-
// We might have constrained the previous step in a way that makes it compatible
183-
// with the current step. If we did so we collapse it here and mark the current
184-
// step as invalid, scheduled for later removal.
185-
if (collapsable(previous, current))
199+
if (previous_inst.type == TurnType::UseLane && current_inst.type == TurnType::UseLane &&
200+
previous.mode == current.mode && previous_lanes == current_lanes)
186201
{
187202
previous.ElongateBy(current);
188-
current.maneuver.instruction = TurnInstruction::NO_TURN();
203+
current.Invalidate();
189204
}
190205
});
191206
};

0 commit comments

Comments
 (0)