@@ -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 ¤t, 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