Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSLCM_LC2013.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
24// A lane change model developed by J. Erdmann
25// based on the model of D. Krajzewicz developed between 2004 and 2011 (MSLCM_DK2004)
26/****************************************************************************/
27#include <config.h>
28
29#include <iostream>
35#include <microsim/MSEdge.h>
36#include <microsim/MSLane.h>
37#include <microsim/MSLink.h>
39#include <microsim/MSNet.h>
40#include <microsim/MSStop.h>
41#include "MSLCHelper.h"
42#include "MSLCM_LC2013.h"
43
44
45// ===========================================================================
46// variable definitions
47// ===========================================================================
48#define LOOK_FORWARD 10.
49
50#define JAM_FACTOR 1.
51
52#define LCA_RIGHT_IMPATIENCE -1.
53#define CUT_IN_LEFT_SPEED_THRESHOLD 27.
54
55#define LOOK_AHEAD_MIN_SPEED 0.0
56#define LOOK_AHEAD_SPEED_MEMORY 0.9
57
58#define HELP_DECEL_FACTOR 1.0
59
60#define HELP_OVERTAKE (10.0 / 3.6)
61#define MIN_FALLBEHIND (7.0 / 3.6)
62
63#define RELGAIN_NORMALIZATION_MIN_SPEED 10.0
64#define URGENCY 2.0
65#define OPPOSITE_URGENCY 5.0
66
67#define KEEP_RIGHT_TIME 5.0 // the number of seconds after which a vehicle should move to the right lane
68
69#define KEEP_RIGHT_HEADWAY 2.0
70#define MAX_ONRAMP_LENGTH 200.
71#define TURN_LANE_DIST 200.0 // the distance at which a lane leading elsewhere is considered to be a turn-lane that must be avoided
72
73#define LC_RESOLUTION_SPEED_LAT 0.5 // the lateral speed (in m/s) for a standing vehicle which was unable to finish a continuous LC in time (in case mySpeedLatStanding==0), see #3771
74
75#define REACT_TO_STOPPED_DISTANCE 100
76#define BLOCKER_IS_BLOCKED_TIME_THRESHOLD 5 // the time after which a blocking neighbor is treated similar to a stopped vehicle
77
78#define HYST_PRECISION 10000000
79
80// ===========================================================================
81// debug defines
82// ===========================================================================
83//#define DEBUG_CONSTRUCTOR
84//#define DEBUG_PATCH_SPEED
85//#define DEBUG_INFORMED
86//#define DEBUG_INFORMER
87//#define DEBUG_WANTS_CHANGE
88//#define DEBUG_SLOW_DOWN
89//#define DEBUG_COOPERATE
90//#define DEBUG_SAVE_BLOCKER_LENGTH
91
92//#define DEBUG_COND (myVehicle.getID() == "ego")
93#define DEBUG_COND (myVehicle.isSelected())
94//#define DEBUG_COND (true)
95
96// ===========================================================================
97// member method definitions
98// ===========================================================================
101 mySpeedGainProbabilityLeft(0),
102 mySpeedGainProbabilityRight(0),
103 myKeepRightProbability(0),
104 myLeadingBlockerLength(0),
105 myLeftSpace(0),
106 myLookAheadSpeed(LOOK_AHEAD_MIN_SPEED),
107 myDontBrake(false),
108 myStrategicParam(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_STRATEGIC_PARAM, 1)),
109 myCooperativeParam(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_COOPERATIVE_PARAM, 1)),
110 mySpeedGainParam(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_SPEEDGAIN_PARAM, 1)),
111 myKeepRightParam(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_KEEPRIGHT_PARAM, 1)),
112 myOppositeParam(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_OPPOSITE_PARAM, 1)),
113 myLookaheadLeft(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_LOOKAHEADLEFT, 2.0)),
114 mySpeedGainRight(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_SPEEDGAINRIGHT, 0.1)),
115 mySpeedGainLookahead(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_SPEEDGAIN_LOOKAHEAD, 0)),
116 mySpeedGainRemainTime(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_SPEEDGAIN_REMAIN_TIME, 20)),
117 mySpeedGainUrgency(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_SPEEDGAIN_URGENCY, 50)),
118 myRoundaboutBonus(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_COOPERATIVE_ROUNDABOUT, myCooperativeParam)),
119 myCooperativeSpeed(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_COOPERATIVE_SPEED, myCooperativeParam)),
120 myKeepRightAcceptanceTime(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_KEEPRIGHT_ACCEPTANCE_TIME, -1)),
121 myOvertakeDeltaSpeedFactor(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_OVERTAKE_DELTASPEED_FACTOR, 0)),
122 myExperimentalParam1(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_EXPERIMENTAL1, 0)) {
124#ifdef DEBUG_CONSTRUCTOR
125 if (DEBUG_COND) {
126 std::cout << SIMTIME
127 << " create lcModel veh=" << myVehicle.getID()
128 << " lcStrategic=" << myStrategicParam
129 << " lcCooperative=" << myCooperativeParam
130 << " lcSpeedGain=" << mySpeedGainParam
131 << " lcKeepRight=" << myKeepRightParam
132 << "\n";
133 }
134#endif
135}
136
140
141
142void
144 if (mySpeedGainParam <= 0) {
145 myChangeProbThresholdRight = std::numeric_limits<long long int>::max();
146 myChangeProbThresholdLeft = std::numeric_limits<long long int>::max();
147 } else {
150 }
151 // the keepRight threshold scales the probability increment as well, so its value only serves as a reference.
152 // It must not become infinite when speedGain is disabled because this would disable keepRight as well (#17793)
154}
155
156
157bool
159 return DEBUG_COND;
160}
161
162
163int
165 int laneOffset,
167 int blocked,
168 const std::pair<MSVehicle*, double>& leader,
169 const std::pair<MSVehicle*, double>& follower,
170 const std::pair<MSVehicle*, double>& neighLead,
171 const std::pair<MSVehicle*, double>& neighFollow,
172 const MSLane& neighLane,
173 const std::vector<MSVehicle::LaneQ>& preb,
174 MSVehicle** lastBlocked,
175 MSVehicle** firstBlocked) {
176
177#ifdef DEBUG_WANTS_CHANGE
178 if (DEBUG_COND) {
179 std::cout << "\nWANTS_CHANGE\n" << SIMTIME
180 << std::setprecision(gPrecision)
181 << " veh=" << myVehicle.getID()
182 << " lane=" << myVehicle.getLane()->getID()
183 << " pos=" << myVehicle.getPositionOnLane()
184 << " posLat=" << myVehicle.getLateralPositionOnLane()
185 << " speed=" << myVehicle.getSpeed()
186 << " considerChangeTo=" << (laneOffset == -1 ? "right" : "left")
187 << "\n";
188 }
189#endif
190
191 const int result = _wantsChange(laneOffset, msgPass, blocked, leader, follower, neighLead, neighFollow, neighLane, preb, *lastBlocked, *firstBlocked);
192
193#ifdef DEBUG_WANTS_CHANGE
194 if (DEBUG_COND) {
195 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " result=" << toString((LaneChangeAction)result) << " blocked=" << toString((LaneChangeAction)blocked) << "\n\n\n";
196 }
197#endif
198
199 return result;
200}
201
202
203double
204MSLCM_LC2013::patchSpeed(const double min, const double wanted, const double max, const MSCFModel& cfModel) {
205
206#ifdef DEBUG_PATCH_SPEED
207 if (DEBUG_COND) {
208 std::cout << "\nPATCH_SPEED\n"
209 << SIMTIME
210 << " veh=" << myVehicle.getID()
211 << " lane=" << myVehicle.getLane()->getID()
212 << " pos=" << myVehicle.getPositionOnLane()
213 << " v=" << myVehicle.getSpeed()
214 << " min=" << min
215 << " wanted=" << wanted
216 << " max=" << max
217 << "\n";
218 }
219#endif
220
221 // negative min speed may be passed when using ballistic updated
222 const double newSpeed = _patchSpeed(MAX2(min, 0.0), wanted, max, cfModel);
223
224#ifdef DEBUG_PATCH_SPEED
225 if (DEBUG_COND) {
226 const std::string patched = (wanted != newSpeed ? " patched=" + toString(newSpeed) : "");
227 std::cout << patched
228 << "\n";
229 }
230#endif
231
232 return newSpeed;
233}
234
235
236double
237MSLCM_LC2013::_patchSpeed(double min, const double wanted, double max, const MSCFModel& cfModel) {
238 int state = myOwnState;
239#ifdef DEBUG_PATCH_SPEED
240 if (DEBUG_COND) {
241 std::cout
242 << "\n" << SIMTIME << std::setprecision(gPrecision)
243 << " patchSpeed state=" << toString((LaneChangeAction)state) << " myLCAccelerationAdvices=" << toString(myLCAccelerationAdvices)
244 << "\n speed=" << myVehicle.getSpeed() << " min=" << min << " wanted=" << wanted
245 << "\n myLeadingBlockerLength=" << myLeadingBlockerLength
246 << "\n";
247 }
248#endif
249
250 // letting vehicles merge in at the end of the lane in case of counter-lane change, step#2
251 double nVSafe = wanted;
252 bool gotOne = false;
253 // if we want to change and have a blocking leader and there is enough room for him in front of us
254 if (myLeadingBlockerLength != 0) {
255 double space = myLeftSpace - myLeadingBlockerLength - POSITION_EPS;
256#ifdef DEBUG_PATCH_SPEED
257 if (DEBUG_COND) {
258 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " myLeftSpace=" << myLeftSpace << " myLeadingBlockerLength=" << myLeadingBlockerLength << " space=" << space << "\n";
259 }
260#endif
261 if (space > 0 && (myVehicle.getLane()->isNormal() || myVehicle.getCurrentEdge()->isRoundabout())) {
262 // compute speed for decelerating towards a place which allows the blocking leader to merge in in front
265 max = MIN2(max, MAX2(safe, vMinEmergency));
266 // if we are approaching this place
267 if (safe < wanted) {
268 // return this speed as the speed to use
269 if (safe < min) {
270 if (safe >= vMinEmergency) {
271 // permit harder braking if needed and helpful
272 min = MAX2(vMinEmergency, safe);
273 }
274 }
275#ifdef DEBUG_PATCH_SPEED
276 if (DEBUG_COND) {
277 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " slowing down for leading blocker, safe=" << safe << (safe + NUMERICAL_EPS < min ? " (not enough)" : "") << "\n";
278 }
279#endif
280 nVSafe = MAX2(min, safe);
281 gotOne = true;
282 }
283 }
284 }
285
286 const double coopWeight = MAX2(0.0, MIN2(1.0, myCooperativeSpeed));
287 int filter = (
288 ((myOwnState & LCA_LEFT) != 0 ? LCA_MLEFT : 0) |
289 ((myOwnState & LCA_RIGHT) != 0 ? LCA_MRIGHT : 0));
290 for (auto i : myLCAccelerationAdvices) {
291 double a = i.first;
292 double v = myVehicle.getSpeed() + ACCEL2SPEED(a);
293
294 if (v >= min && v <= max && (MSGlobals::gSemiImplicitEulerUpdate
295 // ballistic update: (negative speeds may appear, e.g. min<0, v<0), BUT:
296 // XXX: LaneChanging returns -1 to indicate no restrictions, which leads to probs here (Leo), refs. #2577
297 // As a quick fix, we just dismiss cases where v=-1
298 // VERY rarely (whenever a requested help-acceleration is really indicated by v=-1)
299 // this can lead to failing lane-change attempts, though)
300 || v != -1)) {
301 if (i.second & LCA_CHANGE_TO_HELP) {
302 nVSafe = MIN2(v * coopWeight + (1 - coopWeight) * wanted, nVSafe);
303 } else if ((i.second & filter) != filter) {
304#ifdef DEBUG_PATCH_SPEED
305 if (DEBUG_COND) {
306 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " ignoring nVSafe=" << v
307 << " (flag=" << toString((LaneChangeAction)i.second)
308 << " state=" << toString((LaneChangeAction)myOwnState) << "\n";
309 }
310#endif
311 continue;
312 } else {
313 // own advice, no scaling needed
314 nVSafe = MIN2(v, nVSafe);
315 }
316 gotOne = true;
317#ifdef DEBUG_PATCH_SPEED
318 if (DEBUG_COND) {
319 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " got nVSafe=" << nVSafe << " isOwn: " << toString((LaneChangeAction)i.second) << " rawV=" << v << "\n";
320 }
321#endif
322 } else {
323 if (v < min) {
324#ifdef DEBUG_PATCH_SPEED
325 if (DEBUG_COND) {
326 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " ignoring low nVSafe=" << v << " min=" << min << "\n";
327 }
328#endif
329 } else {
330#ifdef DEBUG_PATCH_SPEED
331 if (DEBUG_COND) {
332 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " ignoring high nVSafe=" << v << " max=" << max << "\n";
333 }
334#endif
335 }
336 }
337 }
338 // myDontBrake is used in counter-lane-change situations with relief connection
339 if (gotOne && !myDontBrake) {
340#ifdef DEBUG_PATCH_SPEED
341 if (DEBUG_COND) {
342 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " got vSafe\n";
343 }
344#endif
345 return nVSafe;
346 }
347
348 // check whether the vehicle is blocked
349 if ((state & LCA_WANTS_LANECHANGE) != 0 && (state & LCA_BLOCKED) != 0) {
350 if ((state & LCA_STRATEGIC) != 0) {
351 // necessary decelerations are controlled via vSafe. If there are
352 // none it means we should speed up
353#ifdef DEBUG_PATCH_SPEED
354 if (DEBUG_COND) {
355 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " LCA_WANTS_LANECHANGE (strat, no vSafe)\n";
356 }
357#endif
358 return (max + wanted) / 2.0;
359 } else if ((state & LCA_COOPERATIVE) != 0) {
360 // only minor adjustments in speed should be done
361 if ((state & LCA_BLOCKED_BY_LEADER) != 0) {
362#ifdef DEBUG_PATCH_SPEED
363 if (DEBUG_COND) {
364 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " LCA_BLOCKED_BY_LEADER (coop)\n";
365 }
366#endif
367 if (wanted >= 0.) {
368 return (MAX2(0., min) + wanted) / 2.0;
369 } else {
370 return wanted;
371 }
372 }
373 if ((state & LCA_BLOCKED_BY_FOLLOWER) != 0) {
374#ifdef DEBUG_PATCH_SPEED
375 if (DEBUG_COND) {
376 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " LCA_BLOCKED_BY_FOLLOWER (coop)\n";
377 }
378#endif
379 return (max + wanted) / 2.0;
380 }
381 //} else { // VARIANT_16
382 // // only accelerations should be performed
383 // if ((state & LCA_BLOCKED_BY_FOLLOWER) != 0) {
384 // if (gDebugFlag2) std::cout << SIMTIME << " veh=" << myVehicle.getID() << " LCA_BLOCKED_BY_FOLLOWER\n";
385 // return (max + wanted) / 2.0;
386 // }
387 }
388 }
389
390 /*
391 // decelerate if being a blocking follower
392 // (and does not have to change lanes)
393 if ((state & LCA_AMBLOCKINGFOLLOWER) != 0) {
394 if (fabs(max - myVehicle.getCarFollowModel().maxNextSpeed(myVehicle.getSpeed(), &myVehicle)) < 0.001 && min == 0) { // !!! was standing
395 if (gDebugFlag2) std::cout << SIMTIME << " veh=" << myVehicle.getID() << " LCA_AMBLOCKINGFOLLOWER (standing)\n";
396 return 0;
397 }
398 if (gDebugFlag2) std::cout << SIMTIME << " veh=" << myVehicle.getID() << " LCA_AMBLOCKINGFOLLOWER\n";
399
400 //return min; // VARIANT_3 (brakeStrong)
401 return (min + wanted) / 2.0;
402 }
403 if ((state & LCA_AMBACKBLOCKER) != 0) {
404 if (max <= myVehicle.getCarFollowModel().maxNextSpeed(myVehicle.getSpeed(), &myVehicle) && min == 0) { // !!! was standing
405 if (gDebugFlag2) std::cout << SIMTIME << " veh=" << myVehicle.getID() << " LCA_AMBACKBLOCKER (standing)\n";
406 //return min; VARIANT_9 (backBlockVSafe)
407 return nVSafe;
408 }
409 }
410 if ((state & LCA_AMBACKBLOCKER_STANDING) != 0) {
411 if (gDebugFlag2) std::cout << SIMTIME << " veh=" << myVehicle.getID() << " LCA_AMBACKBLOCKER_STANDING\n";
412 //return min;
413 return nVSafe;
414 }
415 */
416
417 // accelerate if being a blocking leader or blocking follower not able to brake
418 // (and does not have to change lanes)
419 if ((state & LCA_AMBLOCKINGLEADER) != 0 && myCooperativeSpeed >= 0) {
420#ifdef DEBUG_PATCH_SPEED
421 if (DEBUG_COND) {
422 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " LCA_AMBLOCKINGLEADER\n";
423 }
424#endif
425 return (max + wanted) / 2.0;
426 }
427
428 if ((state & LCA_AMBLOCKINGFOLLOWER_DONTBRAKE) != 0) {
429#ifdef DEBUG_PATCH_SPEED
430 if (DEBUG_COND) {
431 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " LCA_AMBLOCKINGFOLLOWER_DONTBRAKE\n";
432 }
433#endif
434 /*
435 // VARIANT_4 (dontbrake)
436 if (max <= myVehicle.getCarFollowModel().maxNextSpeed(myVehicle.getSpeed(), &myVehicle) && min == 0) { // !!! was standing
437 return wanted;
438 }
439 return (min + wanted) / 2.0;
440 */
441 }
443 // remove chaning information if on a road with a single lane
444 changed();
445 }
446 return wanted;
447}
448
449
450void*
451MSLCM_LC2013::inform(void* info, MSVehicle* sender) {
452 UNUSED_PARAMETER(sender);
453 Info* pinfo = (Info*)info;
454 assert(pinfo->first >= 0 || !MSGlobals::gSemiImplicitEulerUpdate);
456 myOwnState |= pinfo->second;
457#ifdef DEBUG_INFORMED
458 if (DEBUG_COND) {
459 std::cout << SIMTIME
460 << " veh=" << myVehicle.getID()
461 << " informedBy=" << sender->getID()
462 << " info=" << pinfo->second
463 << " vSafe=" << pinfo->first
464 << "\n";
465 }
466#endif
467 delete pinfo;
468 return (void*) true;
469}
470
471double
472MSLCM_LC2013::overtakeDistance(const MSVehicle* follower, const MSVehicle* leader, const double gap, double followerSpeed, double leaderSpeed) {
473 followerSpeed = followerSpeed == INVALID_SPEED ? follower->getSpeed() : followerSpeed;
474 leaderSpeed = leaderSpeed == INVALID_SPEED ? leader->getSpeed() : leaderSpeed;
475 double overtakeDist = (gap // drive to back of leader
476 + leader->getVehicleType().getLengthWithGap() // drive to front of leader
477 + follower->getVehicleType().getLength() // follower back reaches leader front
478 + leader->getCarFollowModel().getSecureGap( // save gap to leader
479 leader, follower, leaderSpeed, followerSpeed, follower->getCarFollowModel().getMaxDecel()));
480 return MAX2(overtakeDist, 0.);
481}
482
483
484double
486 int blocked,
487 int dir,
488 const std::pair<MSVehicle*, double>& neighLead,
489 double remainingSeconds) {
490 double plannedSpeed = myVehicle.getSpeed();
491 if (!isOpposite()) {
492 plannedSpeed = MIN2(plannedSpeed,
494 }
495 for (auto i : myLCAccelerationAdvices) {
496 const double a = i.first;
498 plannedSpeed = MIN2(plannedSpeed, myVehicle.getSpeed() + ACCEL2SPEED(a));
499 }
500 }
501#ifdef DEBUG_INFORMER
502 if (DEBUG_COND) {
503 std::cout << "\nINFORM_LEADER"
504 << "\nspeed=" << myVehicle.getSpeed() << " planned=" << plannedSpeed << "\n";
505 }
506#endif
507
508 const MSVehicle* const nv = neighLead.first;
509 if (nv == nullptr) {
510 // not overtaking
511 return plannedSpeed;
512 }
513 const double neighNextSpeed = MIN2(nv->getSpeed() - ACCEL2SPEED(MAX2(1.0, -nv->getAcceleration())),
514 // assume that we know when a neighboring vehicle intends to stop
515 nv->nextStopDist() <= nv->getLane()->getLength() ? nv->getCarFollowModel().minNextSpeed(nv->getSpeed(), nv) : nv->getSpeed());
516 double neighNextGap;
518 neighNextGap = neighLead.second + SPEED2DIST(neighNextSpeed - plannedSpeed);
519 } else {
520 neighNextGap = neighLead.second + SPEED2DIST((nv->getSpeed() + neighNextSpeed) / 2) - SPEED2DIST((myVehicle.getSpeed() + plannedSpeed) / 2);
521 }
522 if ((blocked & LCA_BLOCKED_BY_LEADER) != 0) {
524 //std::cout << SIMTIME << " ego=" << myVehicle.getID() << " ignoresDivergentBlockingLeader=" << nv->getID() << "\n";
525 return plannedSpeed;
526 }
527#ifdef DEBUG_INFORMER
528 if (DEBUG_COND) {
529 std::cout << " blocked by leader nv=" << nv->getID() << " nvSpeed=" << nv->getSpeed() << " needGap="
531 }
532#endif
533 // decide whether we want to overtake the leader or follow it
534 double overtakeTime;
535 const double overtakeDist = overtakeDistance(&myVehicle, nv, neighLead.second);
536 const double dv = plannedSpeed - nv->getSpeed();
537
539 overtakeTime = overtakeDist / dv;
541 && !isOpposite()
543 // -> set overtakeTime to indicate possibility of overtaking (only if there is enough space)
544 overtakeTime = remainingSeconds - 1;
545 } else {
546 // -> set overtakeTime to something indicating impossibility of overtaking
547 overtakeTime = remainingSeconds + 1;
548 }
549
550#ifdef DEBUG_INFORMER
551 if (DEBUG_COND) {
552 std::cout << SIMTIME << " informLeader() of " << myVehicle.getID()
553 << "\nnv = " << nv->getID()
554 << "\nplannedSpeed = " << plannedSpeed
555 << "\nleaderSpeed = " << nv->getSpeed()
556 << "\nmyLeftSpace = " << myLeftSpace
557 << "\nremainingSeconds = " << remainingSeconds
558 << "\novertakeDist = " << overtakeDist
559 << "\novertakeTime = " << overtakeTime
560 << std::endl;
561 }
562#endif
563
565 // overtaking on the right on an uncongested highway is forbidden (noOvertakeLCLeft)
566 || (dir == LCA_MLEFT && avoidOvertakeRight(neighLead.first))
567 // not enough space to overtake?
569 // using brakeGap() without headway seems adequate in a situation where the obstacle (the lane end) is not moving [XXX implemented in branch ticket860, can be used in general if desired, refs. #2575] (Leo).
571 // not enough time to overtake? (skipped for a stopped leader [currently only for ballistic update XXX: check if appropriate for euler, too, refs. #2575] to ensure that it can be overtaken if only enough space is exists) (Leo)
572 || (remainingSeconds < overtakeTime && (MSGlobals::gSemiImplicitEulerUpdate || !nv->isStopped())))
573 // opposite driving and must overtake
574 && (!neighLead.first->isStopped() || (isOpposite() && neighLead.second >= 0))) {
575 // cannot overtake
576 msgPass.informNeighLeader(new Info(std::numeric_limits<double>::max(), dir | LCA_AMBLOCKINGLEADER), &myVehicle);
577 // slow down smoothly to follow leader
578 // account for minor decelerations by the leader (dawdling)
580 getCarFollowModel().followSpeed(&myVehicle, myVehicle.getSpeed(), neighNextGap, neighNextSpeed, nv->getCarFollowModel().getMaxDecel()),
581 // avoid changing on intersection
583 if (targetSpeed < myVehicle.getSpeed()) {
584 // slow down smoothly to follow leader
585 const double decel = remainingSeconds == 0. ? myVehicle.getCarFollowModel().getMaxDecel() :
587 MAX2(MIN_FALLBEHIND, (myVehicle.getSpeed() - targetSpeed) / remainingSeconds));
588 const double nextSpeed = MIN2(plannedSpeed, MAX2(0.0, myVehicle.getSpeed() - ACCEL2SPEED(decel)));
589#ifdef DEBUG_INFORMER
590 if (DEBUG_COND) {
591 std::cout << SIMTIME
592 << " cannot overtake leader nv=" << nv->getID()
593 << " dv=" << dv
594 << " myLookAheadSpeed=" << myLookAheadSpeed
595 << " myLeftSpace=" << myLeftSpace
596 << " overtakeDist=" << overtakeDist
597 << " overtakeTime=" << overtakeTime
598 << " remainingSeconds=" << remainingSeconds
599 << " currentGap=" << neighLead.second
600 << " brakeGap=" << myVehicle.getCarFollowModel().brakeGap(myVehicle.getSpeed(), getCarFollowModel().getMaxDecel(), 0.)
601 << " neighNextSpeed=" << neighNextSpeed
602 << " neighNextGap=" << neighNextGap
603 << " targetSpeed=" << targetSpeed
604 << " nextSpeed=" << nextSpeed
605 << "\n";
606 }
607#endif
608 addLCSpeedAdvice(nextSpeed, dir);
609 return nextSpeed;
610 } else {
611 // leader is fast enough anyway
612#ifdef DEBUG_INFORMER
613 if (DEBUG_COND) {
614 std::cout << SIMTIME
615 << " cannot overtake fast leader nv=" << nv->getID()
616 << " dv=" << dv
617 << " myLookAheadSpeed=" << myLookAheadSpeed
618 << " myLeftSpace=" << myLeftSpace
619 << " overtakeDist=" << overtakeDist
620 << " myLeadingBlockerLength=" << myLeadingBlockerLength
621 << " overtakeTime=" << overtakeTime
622 << " remainingSeconds=" << remainingSeconds
623 << " currentGap=" << neighLead.second
624 << " neighNextSpeed=" << neighNextSpeed
625 << " neighNextGap=" << neighNextGap
626 << " targetSpeed=" << targetSpeed
627 << "\n";
628 }
629#endif
630 addLCSpeedAdvice(targetSpeed, dir);
631 return plannedSpeed;
632 }
633 } else {
634 // overtaking, leader should not accelerate
635#ifdef DEBUG_INFORMER
636 if (DEBUG_COND) {
637 std::cout << SIMTIME
638 << " wants to overtake leader nv=" << nv->getID()
639 << " dv=" << dv
640 << " overtakeDist=" << overtakeDist
641 << " remainingSeconds=" << remainingSeconds
642 << " overtakeTime=" << overtakeTime
643 << " currentGap=" << neighLead.second
645 << "\n";
646 }
647#endif
648 // no need to pass a message if the neighbor is waiting/stuck anyway (but sending it would risk deadlock)
650 msgPass.informNeighLeader(new Info(nv->getSpeed(), dir | LCA_AMBLOCKINGLEADER), &myVehicle);
651 }
652 return -1; // XXX: using -1 is ambiguous for the ballistic update! Currently this is being caught in patchSpeed() (Leo), consider returning INVALID_SPEED, refs. #2577
653 }
654 } else { // (remainUnblocked)
655 // we are not blocked now. make sure we stay far enough from the leader
656 const double targetSpeed = MAX2(
658 getCarFollowModel().followSpeed(&myVehicle, myVehicle.getSpeed(), neighNextGap, neighNextSpeed, nv->getCarFollowModel().getMaxDecel()));
659 addLCSpeedAdvice(targetSpeed, dir);
660#ifdef DEBUG_INFORMER
661 if (DEBUG_COND) {
662 std::cout << " not blocked by leader nv=" << nv->getID()
663 << " nvSpeed=" << nv->getSpeed()
664 << " gap=" << neighLead.second
665 << " neighNextSpeed=" << neighNextSpeed
666 << " neighNextGap=" << neighNextGap
668 << " targetSpeed=" << targetSpeed
669 << "\n";
670 }
671#endif
672 return MIN2(targetSpeed, plannedSpeed);
673 }
674}
675
676void
678 int blocked,
679 int dir,
680 const std::pair<MSVehicle*, double>& neighFollow,
681 double remainingSeconds,
682 double plannedSpeed) {
683
684 MSVehicle* nv = neighFollow.first;
685 const double plannedAccel = SPEED2ACCEL(MAX2(MIN2(getCarFollowModel().getMaxAccel(), plannedSpeed - myVehicle.getSpeed()), -getCarFollowModel().getMaxDecel()));
686
687#ifdef DEBUG_INFORMER
688 if (DEBUG_COND) {
689 std::cout << "\nINFORM_FOLLOWER"
690 << "\nspeed=" << myVehicle.getSpeed() << " planned=" << plannedSpeed << "\n";
691 }
692#endif
693
694 // decide whether we will request help to cut in before the follower or allow to be overtaken
695 if (nv != nullptr && MSLCHelper::unwillingToHelp(myVehicle, plannedSpeed, *nv)) {
696 // @note: this check needs to come first because even if the follower is not blocking, getSpeedPreservingSecureGap may request a slow-down
697#ifdef DEBUG_INFORMER
698 if (DEBUG_COND) {
699 std::cout << "\n nv=" << nv->getID() << " not willing to help\n";
700 }
701#endif
702 return;
703 }
704
705 if ((blocked & LCA_BLOCKED_BY_FOLLOWER) != 0 && nv != nullptr) {
707 //std::cout << SIMTIME << " ego=" << myVehicle.getID() << " ignoresDivergentBlockingFollower=" << nv->getID() << "\n";
708 return;
709 }
710#ifdef DEBUG_INFORMER
711 if (DEBUG_COND) {
712 std::cout << " blocked by follower nv=" << nv->getID() << " nvSpeed=" << nv->getSpeed() << " needGap="
713 << nv->getCarFollowModel().getSecureGap(nv, &myVehicle, nv->getSpeed(), myVehicle.getSpeed(), myVehicle.getCarFollowModel().getMaxDecel()) << " planned=" << plannedSpeed << "\n";
714 }
715#endif
716 // are we fast enough to cut in without any help?
717 if (MAX2(plannedSpeed, 0.) - nv->getSpeed() >= HELP_OVERTAKE) {
718 const double neededGap = nv->getCarFollowModel().getSecureGap(nv, &myVehicle, nv->getSpeed(), plannedSpeed, myVehicle.getCarFollowModel().getMaxDecel());
719 if ((neededGap - neighFollow.second) / remainingSeconds < (MAX2(plannedSpeed, 0.) - nv->getSpeed())) {
720#ifdef DEBUG_INFORMER
721 if (DEBUG_COND) {
722 std::cout << " wants to cut in before nv=" << nv->getID() << " without any help." << "\nneededGap = " << neededGap << "\n";
723 }
724#endif
725 // follower might even accelerate but not to much
726 // XXX: I don't understand this. The needed gap was determined for nv->getSpeed(), not for (plannedSpeed - HELP_OVERTAKE)?! (Leo), refs. #2578
727 msgPass.informNeighFollower(new Info(MAX2(plannedSpeed, 0.) - HELP_OVERTAKE, dir | LCA_AMBLOCKINGFOLLOWER), &myVehicle);
728 return;
729 }
730 }
731
732 // PARAMETERS
733 // assume other vehicle will assume the equivalent of 1 second of
734 // maximum deceleration to help us (will probably be spread over
735 // multiple seconds)
736 // -----------
737 const double helpDecel = nv->getCarFollowModel().getMaxDecel() * HELP_DECEL_FACTOR;
738
739 // follower's new speed in next step
740 double neighNewSpeed;
741 // follower's new speed after 1s.
742 double neighNewSpeed1s;
743 // velocity difference, gap after follower-deceleration
744 double dv, decelGap;
745
747 // euler
748 neighNewSpeed = MAX2(0., nv->getSpeed() - ACCEL2SPEED(helpDecel));
749 neighNewSpeed1s = MAX2(0., nv->getSpeed() - helpDecel); // TODO: consider introduction of a configurable anticipationTime here (see far below in the !blocked part). Refs. #2578
750 // change in the gap between ego and blocker over 1 second (not STEP!)
751 // XXX: though here it is calculated as if it were one step!? (Leo) Refs. #2578
752 dv = plannedSpeed - neighNewSpeed1s; // XXX: what is this quantity (if TS!=1)?
753 // new gap between follower and self in case the follower does brake for 1s
754 // XXX: if the step-length is not 1s., this is not the gap after 1s. deceleration!
755 // And this formula overestimates the real gap. Isn't that problematic? (Leo)
756 // Below, it seems that decelGap > secureGap is taken to indicate the possibility
757 // to cut in within the next time-step. However, this is not the case, if TS<1s.,
758 // since decelGap is (not exactly, though!) the gap after 1s. Refs. #2578
759 decelGap = neighFollow.second + dv;
760 } else {
761 // ballistic
762 // negative newSpeed-extrapolation possible, if stop lies within the next time-step
763 // XXX: this code should work for the euler case as well, since gapExtrapolation() takes
764 // care of this, but for TS!=1 we will have different behavior (see previous remark) Refs. #2578
765 neighNewSpeed = nv->getSpeed() - ACCEL2SPEED(helpDecel);
766 neighNewSpeed1s = nv->getSpeed() - helpDecel;
767
768 dv = myVehicle.getSpeed() - nv->getSpeed(); // current velocity difference
769 decelGap = getCarFollowModel().gapExtrapolation(1., neighFollow.second, myVehicle.getSpeed(),
770 nv->getSpeed(), plannedAccel, -helpDecel, myVehicle.getMaxSpeedOnLane(), nv->getMaxSpeedOnLane());
771 }
772
773 const double secureGap = nv->getCarFollowModel().getSecureGap(nv, &myVehicle, MAX2(neighNewSpeed1s, 0.),
774 MAX2(plannedSpeed, 0.), myVehicle.getCarFollowModel().getMaxDecel());
775
776 const double onRampThreshold = myVehicle.getLane()->getSpeedLimit() * 0.8 * myExperimentalParam1 * (1 - myVehicle.getImpatience());
777
778#ifdef DEBUG_INFORMER
779 if (DEBUG_COND) {
780 std::cout << SIMTIME
781 << " speed=" << myVehicle.getSpeed()
782 << " plannedSpeed=" << plannedSpeed
783 << " threshold=" << onRampThreshold
784 << " neighNewSpeed=" << neighNewSpeed
785 << " neighNewSpeed1s=" << neighNewSpeed1s
786 << " dv=" << dv
787 << " gap=" << neighFollow.second
788 << " decelGap=" << decelGap
789 << " secureGap=" << secureGap
790 << "\n";
791 }
792#endif
793 // prevent vehicles on an on ramp stopping the main flow
794 if (dir == LCA_MLEFT
796 && neighNewSpeed1s < onRampThreshold) {
797 return;
798 }
799
800 if (decelGap > 0 && decelGap >= secureGap) {
801 // XXX: This does not assure that the leader can cut in in the next step if TS < 1 (see above)
802 // this seems to be supposed in the following (euler code)...?! (Leo) Refs. #2578
803
804 // if the blocking follower brakes it could help
805 // how hard does it actually need to be?
806 // to be safe in the next step the following equation has to hold for the follower's vsafe:
807 // vsafe <= followSpeed(gap=currentGap - SPEED2DIST(vsafe), ...)
808 double vsafe, vsafe1;
809
811 // euler
812 // we compute an upper bound on vsafe by doing the computation twice
813 vsafe1 = MAX2(neighNewSpeed, nv->getCarFollowModel().followSpeed(
814 nv, nv->getSpeed(), neighFollow.second + SPEED2DIST(plannedSpeed), plannedSpeed, getCarFollowModel().getMaxDecel()));
815 vsafe = MAX2(neighNewSpeed, nv->getCarFollowModel().followSpeed(
816 nv, nv->getSpeed(), neighFollow.second + SPEED2DIST(plannedSpeed - vsafe1), plannedSpeed, getCarFollowModel().getMaxDecel()));
817 //assert(vsafe <= vsafe1); assertion does not hold for models with randomness in followSpeed (W99)
818 } else {
819 // ballistic
820
821 // XXX: This block should actually do as well for euler update (TODO: test!), refs #2575
822 // we compute an upper bound on vsafe
823 // next step's gap without help deceleration (nv's speed assumed constant)
824 double nextGap = getCarFollowModel().gapExtrapolation(TS,
825 neighFollow.second, myVehicle.getSpeed(),
826 nv->getSpeed(), plannedAccel, 0,
828#ifdef DEBUG_INFORMER
829 if (DEBUG_COND) {
830 std::cout << "nextGap=" << nextGap << " (without help decel) \n";
831 }
832#endif
833
834 // NOTE: the second argument of MIN2() can get larger than nv->getSpeed()
835 vsafe1 = MIN2(nv->getSpeed(), MAX2(neighNewSpeed,
837 nv->getSpeed(), nextGap,
838 MAX2(0., plannedSpeed),
839 getCarFollowModel().getMaxDecel())));
840
841
842 // next step's gap with possibly less than maximal help deceleration (in case vsafe1 > neighNewSpeed)
843 double decel2 = SPEED2ACCEL(nv->getSpeed() - vsafe1);
845 neighFollow.second, myVehicle.getSpeed(),
846 nv->getSpeed(), plannedAccel, -decel2,
848
849 // vsafe = MAX(neighNewSpeed, safe speed assuming next_gap)
850 // Thus, the gap resulting from vsafe is larger or equal to next_gap
851 // in contrast to the euler case, where nv's follow speed doesn't depend on the actual speed,
852 // we need to assure, that nv doesn't accelerate
853 vsafe = MIN2(nv->getSpeed(), MAX2(neighNewSpeed,
855 nv->getSpeed(), nextGap,
856 MAX2(0., plannedSpeed),
857 getCarFollowModel().getMaxDecel())));
858
859 assert(vsafe >= vsafe1 - NUMERICAL_EPS);
860
861#ifdef DEBUG_INFORMER
862 if (DEBUG_COND) {
863 std::cout << "nextGap=" << nextGap
864 << " (with vsafe1 and help decel) \nvsafe1=" << vsafe1
865 << " vsafe=" << vsafe
866 << "\n";
867 }
868#endif
869
870 // For subsecond simulation, this might not lead to secure gaps for a long time,
871 // we seek to establish a secure gap as soon as possible
872 double nextSecureGap = nv->getCarFollowModel().getSecureGap(nv, &myVehicle, vsafe, plannedSpeed, getCarFollowModel().getMaxDecel());
873
874 if (nextGap < nextSecureGap) {
875 // establish a secureGap as soon as possible
876 vsafe = neighNewSpeed;
877 }
878
879#ifdef DEBUG_INFORMER
880 if (DEBUG_COND) {
881 std::cout << "nextGap=" << nextGap
882 << " minNextSecureGap=" << nextSecureGap
883 << " vsafe=" << vsafe << "\n";
884 }
885#endif
886
887 }
888 msgPass.informNeighFollower(
889 new Info(vsafe, dir | LCA_AMBLOCKINGFOLLOWER), &myVehicle);
890
891#ifdef DEBUG_INFORMER
892 if (DEBUG_COND) {
893 std::cout << " wants to cut in before nv=" << nv->getID()
894 << " vsafe1=" << vsafe1 << " vsafe=" << vsafe
895 << " newSecGap="
896 << nv->getCarFollowModel().getSecureGap(nv, &myVehicle, vsafe,
897 plannedSpeed,
899 << "\n";
900 }
901#endif
902 } else if ((MSGlobals::gSemiImplicitEulerUpdate && dv > 0 && dv * remainingSeconds > (secureGap - decelGap + POSITION_EPS))
903 || (!MSGlobals::gSemiImplicitEulerUpdate && dv > 0 && dv * (remainingSeconds - 1) > secureGap - decelGap + POSITION_EPS)
904 ) {
905
906 // XXX: Alternative formulation (encapsulating differences of euler and ballistic) TODO: test, refs. #2575
907 // double eventualGap = getCarFollowModel().gapExtrapolation(remainingSeconds - 1., decelGap, plannedSpeed, neighNewSpeed1s);
908 // } else if (eventualGap > secureGap + POSITION_EPS) {
909
910
911 // NOTE: This case corresponds to the situation, where some time is left to perform the lc
912 // For the ballistic case this is interpreted as follows:
913 // If the follower breaks with helpDecel for one second, this vehicle maintains the plannedSpeed,
914 // and both continue with their speeds for remainingSeconds seconds the gap will suffice for a laneChange
915 // For the euler case we had the following comment:
916 // 'decelerating once is sufficient to open up a large enough gap in time', but:
917 // XXX: 1) Decelerating *once* does not necessarily lead to the gap decelGap! (if TS<1s.) (Leo)
918 // 2) Probably, the if() for euler should test for dv * (remainingSeconds-1) > ..., too ?!, refs. #2578
919 msgPass.informNeighFollower(new Info(neighNewSpeed, dir | LCA_AMBLOCKINGFOLLOWER), &myVehicle);
920#ifdef DEBUG_INFORMER
921 if (DEBUG_COND) {
922 std::cout << " wants to cut in before nv=" << nv->getID() << " (eventually)\n";
923 }
924#endif
925 } else if (dir == LCA_MRIGHT && nv->getLaneChangeModel().avoidOvertakeRight(&myVehicle)) {
926 // XXX: check if this requires a special treatment for the ballistic update, refs. #2575
927 const double vhelp = MAX2(neighNewSpeed, HELP_OVERTAKE);
928 msgPass.informNeighFollower(new Info(vhelp, dir | LCA_AMBLOCKINGFOLLOWER), &myVehicle);
929#ifdef DEBUG_INFORMER
930 if (DEBUG_COND) {
931 std::cout << " wants to cut in before nv=" << nv->getID() << " (nv cannot overtake right)\n";
932 }
933#endif
934 } else {
935 double vhelp = MAX2(nv->getSpeed(), myVehicle.getSpeed() + HELP_OVERTAKE);
936 //if (dir == LCA_MRIGHT && myVehicle.getWaitingSeconds() > LCA_RIGHT_IMPATIENCE &&
937 // nv->getSpeed() > myVehicle.getSpeed()) {
938 if (nv->getSpeed() > myVehicle.getSpeed() &&
939 ((dir == LCA_MRIGHT && myVehicle.getWaitingSeconds() > LCA_RIGHT_IMPATIENCE) // NOTE: it might be considered to use myVehicle.getAccumulatedWaitingSeconds() > LCA_RIGHT_IMPATIENCE instead (Leo). Refs. #2578
940 || (dir == LCA_MLEFT && plannedSpeed > CUT_IN_LEFT_SPEED_THRESHOLD) // VARIANT_22 (slowDownLeft)
941 // XXX this is a hack to determine whether the vehicles is on an on-ramp. This information should be retrieved from the network itself
943 )) {
944 // let the follower slow down to increase the likelihood that later vehicles will be slow enough to help
945 // follower should still be fast enough to open a gap
946 // XXX: The probability for that success would be larger if the slow down of the appropriate following vehicle
947 // would take place without the immediate follower slowing down. We might consider to model reactions of
948 // vehicles that are not immediate followers. (Leo) -> see ticket #2532
949 vhelp = MAX2(neighNewSpeed, myVehicle.getSpeed() + HELP_OVERTAKE);
950#ifdef DEBUG_INFORMER
951 if (DEBUG_COND) {
952 // NOTE: the condition labeled "VARIANT_22" seems to imply that this could as well concern the *left* follower?! (Leo)
953 // Further, vhelp might be larger than nv->getSpeed(), so the request issued below is not to slow down!? (see below) Refs. #2578
954 std::cout << " wants right follower to slow down a bit\n";
955 }
956#endif
958 // euler
959 if ((nv->getSpeed() - myVehicle.getSpeed()) / helpDecel < remainingSeconds) {
960
961#ifdef DEBUG_INFORMER
962 if (DEBUG_COND) {
963 // NOTE: the condition labeled "VARIANT_22" seems to imply that this could as well concern the *left* follower?! Refs. #2578
964 std::cout << " wants to cut in before right follower nv=" << nv->getID() << " (eventually)\n";
965 }
966#endif
967 // XXX: I don't understand. This vhelp might be larger than nv->getSpeed() but the above condition seems to rely
968 // on the reasoning that if nv breaks with helpDecel for remaining Seconds, nv will be so slow, that this
969 // vehicle will be able to cut in. But nv might have overtaken this vehicle already (or am I missing sth?). (Leo)
970 // Ad: To my impression, the intention behind allowing larger speeds for the blocking follower is to prevent a
971 // situation, where an overlapping follower keeps blocking the ego vehicle. Refs. #2578
972 msgPass.informNeighFollower(new Info(vhelp, dir | LCA_AMBLOCKINGFOLLOWER), &myVehicle);
973 return;
974 }
975 } else {
976
977 // ballistic (this block is a bit different to the logic in the euler part, but in general suited to work on euler as well.. must be tested <- TODO, refs. #2575)
978 // estimate gap after remainingSeconds.
979 // Assumptions:
980 // (A1) leader continues with currentSpeed. (XXX: That might be wrong: Think of accelerating on an on-ramp or of a congested region ahead!)
981 // (A2) follower breaks with helpDecel.
982 const double gapAfterRemainingSecs = getCarFollowModel().gapExtrapolation(
983 remainingSeconds, neighFollow.second, myVehicle.getSpeed(), nv->getSpeed(), 0, -helpDecel, myVehicle.getMaxSpeedOnLane(), nv->getMaxSpeedOnLane());
984 const double secureGapAfterRemainingSecs = nv->getCarFollowModel().getSecureGap(nv, &myVehicle,
985 MAX2(nv->getSpeed() - remainingSeconds * helpDecel, 0.), myVehicle.getSpeed(), myVehicle.getCarFollowModel().getMaxDecel());
986 if (gapAfterRemainingSecs >= secureGapAfterRemainingSecs) { // XXX: here it would be wise to check whether there is enough space for eventual braking if the maneuver doesn't succeed
987#ifdef DEBUG_INFORMER
988 if (DEBUG_COND) {
989 std::cout << " wants to cut in before follower nv=" << nv->getID() << " (eventually)\n";
990 }
991#endif
992 // NOTE: ballistic uses neighNewSpeed instead of vhelp, see my note above. (Leo)
993 // TODO: recheck if this might cause suboptimal behaviour in some LC-situations. Refs. #2578
994 msgPass.informNeighFollower(new Info(neighNewSpeed, dir | LCA_AMBLOCKINGFOLLOWER), &myVehicle);
995 return;
996 }
997 }
998
999
1000 }
1001
1002#ifdef DEBUG_INFORMER
1003 if (DEBUG_COND) {
1004 std::cout << SIMTIME
1005 << " veh=" << myVehicle.getID()
1006 << " informs follower " << nv->getID()
1007 << " vhelp=" << vhelp
1008 << "\n";
1009 }
1010#endif
1011
1012 msgPass.informNeighFollower(new Info(vhelp, dir | LCA_AMBLOCKINGFOLLOWER), &myVehicle);
1013 // This follower is supposed to overtake us. Slow down smoothly to allow this.
1014 const double overtakeDist = overtakeDistance(nv, &myVehicle, neighFollow.second, vhelp, plannedSpeed);
1015 // speed difference to create a sufficiently large gap
1016 const double needDV = overtakeDist / remainingSeconds;
1017 // make sure the deceleration is not to strong (XXX: should be assured in finalizeSpeed -> TODO: remove the MAX2 if agreed) -> prob with possibly non-existing maximal deceleration for som CF Models(?) Refs. #2578
1019
1020#ifdef DEBUG_INFORMER
1021 if (DEBUG_COND) {
1022 std::cout << SIMTIME
1023 << " veh=" << myVehicle.getID()
1024 << " wants to be overtaken by=" << nv->getID()
1025 << " overtakeDist=" << overtakeDist
1026 << " vneigh=" << nv->getSpeed()
1027 << " vhelp=" << vhelp
1028 << " needDV=" << needDV
1029 << " vsafe=" << myLCAccelerationAdvices.back().first
1030 << "\n";
1031 }
1032#endif
1033 }
1034 } else if (neighFollow.first != nullptr && (blocked & LCA_BLOCKED_BY_LEADER)) {
1035 // we are not blocked by the follower now, make sure it remains that way
1036 const double vsafe = MSLCHelper::getSpeedPreservingSecureGap(myVehicle, *neighFollow.first, neighFollow.second, plannedSpeed);
1037 msgPass.informNeighFollower(new Info(vsafe, dir), &myVehicle);
1038
1039#ifdef DEBUG_INFORMER
1040 if (DEBUG_COND) {
1041 std::cout << " wants to cut in before non-blocking follower nv=" << nv->getID() << "\n";
1042 }
1043#endif
1044 }
1045}
1046
1047
1048void
1051 // keep information about strategic change direction
1052 if (!isChangingLanes()) {
1054 }
1056 myLeftSpace = 0;
1058 myDontBrake = false;
1059 // truncate to work around numerical instability between different builds
1060 if (mySigma > 0 && !isChangingLanes()) {
1061 // disturb lateral position directly
1062 const double maxDist = SPEED2DIST(myVehicle.getVehicleType().getMaxSpeedLat());
1063 const double oldPosLat = myVehicle.getLateralPositionOnLane();
1064 const double overlap = myVehicle.getLateralOverlap();
1065 double scaledDelta;
1066 if (overlap > 0) {
1067 // return to within lane boundary
1068 scaledDelta = MIN2(overlap, maxDist);
1070 scaledDelta *= -1;
1071 }
1072 } else {
1073 // random drift
1074 double deltaPosLat = OUProcess::step(oldPosLat,
1076 MAX2(NUMERICAL_EPS, (1 - mySigma) * 100), mySigma, rng) - oldPosLat;
1077 deltaPosLat = MAX2(MIN2(deltaPosLat, maxDist), -maxDist);
1078 scaledDelta = deltaPosLat * myVehicle.getSpeed() / myVehicle.getLane()->getSpeedLimit();
1079 }
1080 myVehicle.setLateralPositionOnLane(oldPosLat + scaledDelta);
1081 setSpeedLat(DIST2SPEED(scaledDelta));
1082 } else {
1083 resetSpeedLat();
1084 }
1085}
1086
1087
1088void
1090 myOwnState = 0;
1094 if (myVehicle.getBestLaneOffset() == 0) {
1095 // if we are not yet on our best lane there might still be unseen blockers
1096 // (during patchSpeed)
1098 myLeftSpace = 0;
1099 }
1102 myDontBrake = false;
1104}
1105
1106
1107void
1119
1120
1121int
1123 int laneOffset,
1125 int blocked,
1126 const std::pair<MSVehicle*, double>& leader,
1127 const std::pair<MSVehicle*, double>& follower,
1128 const std::pair<MSVehicle*, double>& neighLead,
1129 const std::pair<MSVehicle*, double>& neighFollow,
1130 const MSLane& neighLane,
1131 const std::vector<MSVehicle::LaneQ>& preb,
1132 MSVehicle* lastBlocked,
1133 MSVehicle* firstBlocked) {
1134 assert(laneOffset == 1 || laneOffset == -1);
1135 const SUMOTime currentTime = MSNet::getInstance()->getCurrentTimeStep();
1136 // compute bestLaneOffset
1137 const MSVehicle::LaneQ* curr = nullptr;
1138 const MSVehicle::LaneQ* neigh = nullptr;
1139 const MSVehicle::LaneQ* best = nullptr;
1140 int bestLaneOffset = 0;
1141 // What do these "dists" mean? Please comment. (Leo) Ad: I now think the following:
1142 // currentDist is the distance that the vehicle can go on its route without having to
1143 // change lanes from the current lane. neighDist as currentDist for the considered target lane (i.e., neigh)
1144 // If this is true I suggest to put this into the docu of wantsChange()
1145 double currentDist = 0;
1146 double neighDist = 0;
1147 int currIdx = 0;
1148 const bool checkOpposite = &neighLane.getEdge() != &myVehicle.getLane()->getEdge();
1149 const MSLane* prebLane = myVehicle.getLane();
1150 if (prebLane->getEdge().isInternal()) {
1151 // internal edges are not kept inside the bestLanes structure
1152 if (isOpposite()) {
1153 prebLane = prebLane->getNormalPredecessorLane();
1154 } else {
1155 prebLane = prebLane->getLinkCont()[0]->getLane();
1156 }
1157 }
1158 // special case: vehicle considers changing to the opposite direction edge
1159 const int prebOffset = laneOffset;
1160 for (int p = 0; p < (int) preb.size(); ++p) {
1161 //if (DEBUG_COND) {
1162 // std::cout << " p=" << p << " prebLane=" << prebLane->getID() << " preb.p=" << preb[p].lane->getID() << "\n";
1163 //}
1164 if (preb[p].lane == prebLane && p + laneOffset >= 0) {
1165 assert(p + prebOffset < (int)preb.size());
1166 curr = &preb[p];
1167 neigh = &preb[p + prebOffset];
1168 currentDist = curr->length;
1169 neighDist = neigh->length;
1170 bestLaneOffset = curr->bestLaneOffset;
1171 if (bestLaneOffset == 0 && preb[p + prebOffset].bestLaneOffset == 0 && !checkOpposite) {
1172#ifdef DEBUG_WANTS_CHANGE
1173 if (DEBUG_COND) {
1174 std::cout << STEPS2TIME(currentTime)
1175 << " veh=" << myVehicle.getID()
1176 << " bestLaneOffsetOld=" << bestLaneOffset
1177 << " bestLaneOffsetNew=" << laneOffset
1178 << "\n";
1179 }
1180#endif
1181 bestLaneOffset = prebOffset;
1182 }
1183 best = &preb[p + bestLaneOffset];
1184 currIdx = p;
1185 break;
1186 }
1187 }
1188 assert(curr->lane != nullptr);
1189 assert(neigh->lane != nullptr);
1190 assert(best->lane != nullptr);
1191 // direction specific constants
1192 const bool right = (laneOffset == -1);
1193 const double posOnLane = getForwardPos();
1194 double driveToNextStop = -std::numeric_limits<double>::max();
1195 if (myVehicle.nextStopDist() < std::numeric_limits<double>::max()
1197 // vehicle can always drive up to stop distance
1198 // @note this information is dynamic and thus not available in updateBestLanes()
1199 // @note: nextStopDist was compute before the vehicle moved
1200 driveToNextStop = myVehicle.nextStopDist();
1201 const double stopPos = posOnLane + myVehicle.nextStopDist() - myVehicle.getLastStepDist();
1202#ifdef DEBUG_WANTS_CHANGE
1203 if (DEBUG_COND) {
1204 std::cout << SIMTIME << std::setprecision(gPrecision) << " veh=" << myVehicle.getID()
1205 << " stopDist=" << myVehicle.nextStopDist()
1206 << " lastDist=" << myVehicle.getLastStepDist()
1207 << " stopPos=" << stopPos
1208 << " currentDist=" << currentDist
1209 << " neighDist=" << neighDist
1210 << "\n";
1211 }
1212#endif
1213 currentDist = MAX2(currentDist, stopPos);
1214 neighDist = MAX2(neighDist, stopPos);
1215 }
1216 const int lca = (right ? LCA_RIGHT : LCA_LEFT);
1217 const int myLca = (right ? LCA_MRIGHT : LCA_MLEFT);
1218 const int lcaCounter = (right ? LCA_LEFT : LCA_RIGHT);
1219 bool changeToBest = (right && bestLaneOffset < 0) || (!right && bestLaneOffset > 0);
1220 // keep information about being a leader/follower
1221 int ret = (myOwnState & 0xffff0000);
1222 int req = 0; // the request to change or stay
1223
1224 ret = slowDownForBlocked(lastBlocked, ret);
1225 if (lastBlocked != firstBlocked) {
1226 ret = slowDownForBlocked(firstBlocked, ret);
1227 }
1228
1229#ifdef DEBUG_WANTS_CHANGE
1230 if (DEBUG_COND) {
1231 std::cout << SIMTIME
1232 << " veh=" << myVehicle.getID()
1233 << " _wantsChange state=" << myOwnState
1234 << " myLCAccelerationAdvices=" << toString(myLCAccelerationAdvices)
1235 << " firstBlocked=" << Named::getIDSecure(firstBlocked)
1236 << " lastBlocked=" << Named::getIDSecure(lastBlocked)
1237 << " leader=" << Named::getIDSecure(leader.first)
1238 << " leaderGap=" << leader.second
1239 << " follower=" << Named::getIDSecure(follower.first)
1240 << " followerGap=" << follower.second
1241 << " neighLead=" << Named::getIDSecure(neighLead.first)
1242 << " neighLeadGap=" << neighLead.second
1243 << " neighFollow=" << Named::getIDSecure(neighFollow.first)
1244 << " neighFollowGap=" << neighFollow.second
1245 << "\n";
1246 }
1247#endif
1248
1249 // we try to estimate the distance which is necessary to get on a lane
1250 // we have to get on in order to keep our route
1251 // we assume we need something that depends on our velocity
1252 // and compare this with the free space on our wished lane
1253 //
1254 // if the free space is somehow(<-?) less than the space we need, we should
1255 // definitely try to get to the desired lane
1256 //
1257 // this rule forces our vehicle to change the lane if a lane changing is necessary soon
1258
1259
1260 // we do not want the lookahead distance to change all the time so we let it decay slowly
1261 // (in contrast, growth is applied instantaneously)
1264 } else {
1265 // memory decay factor for this action step
1266 const double memoryFactor = 1. - (1. - LOOK_AHEAD_SPEED_MEMORY) * myVehicle.getActionStepLengthSecs();
1267 assert(memoryFactor > 0.);
1269 (memoryFactor * myLookAheadSpeed + (1 - memoryFactor) * myVehicle.getSpeed()));
1270 }
1271 double laDist = myLookAheadSpeed * LOOK_FORWARD * myStrategicParam * (right ? 1 : myLookaheadLeft);
1272 laDist += myVehicle.getVehicleType().getLengthWithGap() * 2.;
1273 const bool hasStoppedLeader = leader.first != 0 && leader.first->isStopped() && leader.second < (currentDist - posOnLane);
1274 const bool hasBidiLeader = myVehicle.getLane()->getBidiLane() != nullptr && MSLCHelper::isBidiLeader(leader.first, curr->bestContinuations);
1275 const bool hasBidiNeighLeader = neighLane.getBidiLane() != nullptr && MSLCHelper::isBidiLeader(neighLead.first, neigh->bestContinuations);
1276 const bool hasJunctionLeader = leader.first != nullptr && leader.first == neighLead.first;
1277
1278 if (bestLaneOffset == 0 && hasBidiLeader) {
1279 // getting out of the way is enough to clear the blockage
1280 laDist = 0;
1281 } else if (bestLaneOffset == 0 && hasStoppedLeader) {
1282 // react to a stopped leader on the current lane
1283 // The value of laDist is doubled below for the check whether the lc-maneuver can be taken out
1284 // on the remaining distance (because the vehicle has to change back and forth). Therefore multiply with 0.5.
1285 laDist = 0.5 * (myVehicle.getVehicleType().getLengthWithGap()
1286 + leader.first->getVehicleType().getLengthWithGap()
1287 + leader.second);
1288 } else if (bestLaneOffset == laneOffset && neighLead.first != 0 && (neighLead.first->isStopped() || hasBidiNeighLeader) && neighLead.second < (currentDist - posOnLane)) {
1289 // react to a stopped leader on the target lane (if it is the bestLane)
1290 if (isOpposite()) {
1291 // always allow changing back
1293 + neighLead.first->getVehicleType().getLengthWithGap()
1294 + neighLead.second);
1295 } else if (!hasStoppedLeader &&
1296 ((neighLead.second + myVehicle.getVehicleType().getLengthWithGap() + neighLead.first->getVehicleType().getLengthWithGap()) < (currentDist - posOnLane)
1297 || hasBidiNeighLeader)) {
1298 // do not change to the target lane until passing the stopped vehicle
1299 // (unless the vehicle blocks our intended stopping position, then we have to wait anyway)
1300 changeToBest = false;
1301 }
1302 }
1303 if (myStrategicParam < 0) {
1304 laDist = -1e3; // never perform strategic change
1305 }
1306
1307 // free space that is available for changing
1308 //const double neighSpeed = (neighLead.first != 0 ? neighLead.first->getSpeed() :
1309 // neighFollow.first != 0 ? neighFollow.first->getSpeed() :
1310 // best.lane->getSpeedLimit());
1311 // @note: while this lets vehicles change earlier into the correct direction
1312 // it also makes the vehicles more "selfish" and prevents changes which are necessary to help others
1313
1314
1315
1316 // Next we assign to roundabout edges a larger distance than to normal edges
1317 // in order to decrease sense of lc urgency and induce higher usage of inner roundabout lanes.
1318 const double roundaboutBonus = MSLCHelper::getRoundaboutDistBonus(myVehicle, myRoundaboutBonus, *curr, *neigh, *best);
1319 currentDist += roundaboutBonus;
1320 neighDist += roundaboutBonus;
1321
1322 const double usableDist = MAX2(currentDist - posOnLane - best->occupation * JAM_FACTOR, driveToNextStop);
1323 //- (best.lane->getVehicleNumber() * neighSpeed)); // VARIANT 9 jfSpeed
1324 const double maxJam = MAX2(preb[currIdx + prebOffset].occupation, preb[currIdx].occupation);
1325 const double vMax = myVehicle.getLane()->getVehicleMaxSpeed(&myVehicle);
1326 const double neighVMax = neighLane.getVehicleMaxSpeed(&myVehicle);
1327 // upper bound which will be restricted successively
1328 double thisLaneVSafe = vMax;
1329 const bool checkOverTakeRight = avoidOvertakeRight(neighLead.first, true);
1330
1331 double neighLeftPlace = MAX2(0.0, neighDist - posOnLane - maxJam);
1332 if (neighLead.first != 0 && neighLead.first->isStopped()) {
1333 neighLeftPlace = MIN2(neighLeftPlace, neighLead.second);
1334 }
1335
1336#ifdef DEBUG_WANTS_CHANGE
1337 if (DEBUG_COND) {
1338 std::cout << STEPS2TIME(currentTime)
1339 << " veh=" << myVehicle.getID()
1340 << " laSpeed=" << myLookAheadSpeed
1341 << " laDist=" << laDist
1342 << " currentDist=" << currentDist
1343 << " usableDist=" << usableDist
1344 << " bestLaneOffset=" << bestLaneOffset
1345 << " best.occupation=" << best->occupation
1346 << " best.length=" << best->length
1347 << "\n roundaboutBonus=" << roundaboutBonus
1348 << " maxJam=" << maxJam
1349 << " neighDist=" << neighDist
1350 << " neighLeftPlace=" << neighLeftPlace
1351 << (hasBidiLeader ? " bidiLeader" : "")
1352 << (hasBidiNeighLeader ? " bidiNeighLeader" : "")
1353 << "\n";
1354 }
1355#endif
1356
1357 bool changeLeftToAvoidOvertakeRight = false;
1358 if (changeToBest && bestLaneOffset == curr->bestLaneOffset
1359 && currentDistDisallows(usableDist, bestLaneOffset, laDist)) {
1361 ret = ret | lca | LCA_STRATEGIC | LCA_URGENT;
1362 } else {
1363 // VARIANT_20 (noOvertakeRight)
1364 if (neighLead.first != 0 && checkOverTakeRight && !right) {
1365 // check for slower leader on the left. we should not overtake but
1366 // rather move left ourselves (unless congested)
1367 const MSVehicle* nv = neighLead.first;
1368 double deltaV = 0.;
1369 double vSafe = 0.;
1370 if (canOvertakeRight(nv, neighLead.second, vMax - neighLane.getVehicleMaxSpeed(nv), HELP_OVERTAKE, vSafe, deltaV)) {
1372 vSafe = MAX2(vSafe, nv->getSpeed());
1373 }
1374 thisLaneVSafe = MIN2(thisLaneVSafe, vSafe);
1375 addLCSpeedAdvice(vSafe, myLca);
1376 // only generate impulse for overtaking left shortly before braking would be necessary
1377 const double deltaGapFuture = deltaV * 8;
1378 const double vSafeFuture = getCarFollowModel().followSpeed(
1379 &myVehicle, myVehicle.getSpeed(), neighLead.second - deltaGapFuture, nv->getSpeed(), nv->getCarFollowModel().getMaxDecel());
1380 if (vSafeFuture < vSafe) {
1381 const double relativeGain = deltaV / MAX2(vMax,
1383 mySpeedGainProbabilityLeft += (long long int)(myVehicle.getActionStepLengthSecs() * relativeGain * HYST_PRECISION);
1384 changeLeftToAvoidOvertakeRight = true;
1385 }
1386#ifdef DEBUG_WANTS_CHANGE
1387 if (DEBUG_COND) {
1388 std::cout << STEPS2TIME(currentTime)
1389 << " avoid overtaking on the right nv=" << nv->getID()
1390 << " deltaV=" << deltaV
1391 << " nvSpeed=" << nv->getSpeed()
1392 << " speedGainL=" << (double)mySpeedGainProbabilityLeft / HYST_PRECISION
1393 << " speedGainR=" << (double)mySpeedGainProbabilityRight / HYST_PRECISION
1394 << " planned acceleration =" << myLCAccelerationAdvices.back().first
1395 << "\n";
1396 }
1397#endif
1398 }
1399 }
1400 const bool currFreeUntilNeighEnd = leader.first == nullptr || neighDist - posOnLane <= leader.second;
1401 const double overtakeDist = (leader.first == 0 || hasBidiLeader ? -1 :
1402 leader.second + myVehicle.getVehicleType().getLength() + leader.first->getVehicleType().getLengthWithGap());
1403 const double overtakeDist2 = (neighLead.first == 0 || !neighLead.first->isStopped() ? -1 :
1404 neighLead.second + myVehicle.getVehicleType().getLength() + neighLead.first->getVehicleType().getLengthWithGap());
1405 if (leader.first != 0 && (leader.first->isStopped() || hasBidiLeader) && leader.second < REACT_TO_STOPPED_DISTANCE
1406 // current destination leaves enough space to overtake the leader
1407 && MIN2(neighDist, currentDist) - posOnLane > overtakeDist
1408 // maybe do not overtake on the right at high speed
1409 && (!checkOverTakeRight || !right)
1410 && myStrategicParam >= 0
1411 && (neighLead.first == 0 || !neighLead.first->isStopped()
1412 // neighboring stopped vehicle leaves enough space to overtake leader
1413 || neighLead.second > overtakeDist
1414 // if we cannot pass neighLead before reaching leader we must find another free lane
1415 || (overtakeDist2 > leader.second && hasFreeLane(laneOffset, neighLead)))) {
1416 // avoid becoming stuck behind a stopped leader
1417 currentDist = myVehicle.getPositionOnLane() + leader.second;
1418#ifdef DEBUG_WANTS_CHANGE
1419 if (DEBUG_COND) {
1420 std::cout << " veh=" << myVehicle.getID()
1421 << " overtake " << (hasBidiLeader ? "bidi" : "stopped") << " leader=" << leader.first->getID()
1422 << " overtakeDist=" << overtakeDist
1423 << " overtakeDist2=" << overtakeDist
1424 << " hasFreeLane=" << hasFreeLane(laneOffset, neighLead)
1425 << " remaining=" << MIN2(neighDist, currentDist) - posOnLane
1426 << "\n";
1427 }
1428#endif
1429 ret = ret | lca | LCA_STRATEGIC | LCA_URGENT;
1430 } else if (!changeToBest && currentDistDisallows(neighLeftPlace, abs(bestLaneOffset) + 2, laDist) && !hasBidiLeader) {
1431 // the opposite lane-changing direction should be done than the one examined herein
1432 // we'll check whether we assume we could change anyhow and get back in time...
1433 //
1434 // this rule prevents the vehicle from moving in opposite direction of the best lane
1435 // unless the way till the end where the vehicle has to be on the best lane
1436 // is long enough
1437#ifdef DEBUG_WANTS_CHANGE
1438 if (DEBUG_COND) {
1439 std::cout << " veh=" << myVehicle.getID() << " could not change back and forth in time (1) neighLeftPlace=" << neighLeftPlace << "\n";
1440 }
1441#endif
1442 ret = ret | LCA_STAY | LCA_STRATEGIC;
1443 } else if (bestLaneOffset == 0 && (neighLeftPlace * 2. < laDist)) {
1444 // the current lane is the best and a lane-changing would cause a situation
1445 // of which we assume we will not be able to return to the lane we have to be on.
1446 // this rule prevents the vehicle from leaving the current, best lane when it is
1447 // close to this lane's end
1448#ifdef DEBUG_WANTS_CHANGE
1449 if (DEBUG_COND) {
1450 std::cout << " veh=" << myVehicle.getID() << " could not change back and forth in time (2) neighLeftPlace=" << neighLeftPlace << "\n";
1451 }
1452#endif
1453 ret = ret | LCA_STAY | LCA_STRATEGIC;
1454 } else if (bestLaneOffset == 0
1455 && (leader.first == 0 || !leader.first->isStopped())
1456 && !hasBidiLeader
1457 && neigh->bestContinuations.back()->getLinkCont().size() != 0
1458 && roundaboutBonus == 0
1459 && !checkOpposite
1460 && ((myStrategicParam >= 0 && neighDist < TURN_LANE_DIST)
1461 // lane changing cannot possibly help
1462 || (myStrategicParam < 0 && currFreeUntilNeighEnd))
1463 ) {
1464 // VARIANT_21 (stayOnBest)
1465 // we do not want to leave the best lane for a lane which leads elsewhere
1466 // unless our leader is stopped or we are approaching a roundabout
1467#ifdef DEBUG_WANTS_CHANGE
1468 if (DEBUG_COND) {
1469 std::cout << " veh=" << myVehicle.getID() << " does not want to leave the bestLane (neighDist=" << neighDist << ")\n";
1470 }
1471#endif
1472 ret = ret | LCA_STAY | LCA_STRATEGIC;
1473 }
1474 }
1475 // check for overriding TraCI requests
1476#ifdef DEBUG_WANTS_CHANGE
1477 if (DEBUG_COND) {
1478 std::cout << STEPS2TIME(currentTime) << " veh=" << myVehicle.getID() << " ret=" << toString((LaneChangeAction)ret);
1479 }
1480#endif
1481 // store state before canceling
1482 getCanceledState(laneOffset) |= ret | blocked;
1484 if ((ret & lcaCounter) != 0) {
1485 // we are not interested in traci requests for the opposite direction here
1486 ret &= ~(LCA_TRACI | lcaCounter | LCA_URGENT);
1487 }
1488#ifdef DEBUG_WANTS_CHANGE
1489 if (DEBUG_COND) {
1490 std::cout << " retAfterInfluence=" << toString((LaneChangeAction)ret) << "\n";
1491 }
1492#endif
1493
1494 if ((ret & LCA_STAY) != 0) {
1495 // remove TraCI flags because it should not be included in "state-without-traci"
1496 ret = getCanceledState(laneOffset);
1497 return ret;
1498 }
1499 if ((ret & LCA_URGENT) != 0) {
1500 // prepare urgent lane change maneuver
1501 // save the left space
1502 myLeftSpace = currentDist - posOnLane;
1503 if (changeToBest && abs(bestLaneOffset) > 1 && myVehicle.getNumRemainingEdges() > 1) {
1504 // there might be a vehicle which needs to counter-lane-change one lane further and we cannot see it yet
1505 myLeadingBlockerLength = MAX2(getExtraReservation(bestLaneOffset, neighDist - currentDist), myLeadingBlockerLength);
1506#ifdef DEBUG_SAVE_BLOCKER_LENGTH
1507 if (DEBUG_COND) {
1508 std::cout << " reserving space for unseen blockers myLeadingBlockerLength=" << myLeadingBlockerLength << "\n";
1509 }
1510#endif
1511 }
1512
1513 // letting vehicles merge in at the end of the lane in case of counter-lane change, step#1
1514 // if there is a leader and he wants to change to the opposite direction
1515 const bool canContinue = curr->bestContinuations.size() > 1;
1516 bool canReserve = MSLCHelper::updateBlockerLength(myVehicle, neighLead.first, lcaCounter, myLeftSpace - POSITION_EPS, canContinue, myLeadingBlockerLength);
1517 if (firstBlocked != neighLead.first) {
1518 canReserve &= MSLCHelper::updateBlockerLength(myVehicle, firstBlocked, lcaCounter, myLeftSpace - POSITION_EPS, canContinue, myLeadingBlockerLength);
1519 }
1520#ifdef DEBUG_SAVE_BLOCKER_LENGTH
1521 if (DEBUG_COND) {
1522 std::cout << SIMTIME << " canReserve=" << canReserve << " canContinue=" << canContinue << "\n";
1523 }
1524#endif
1525 if (!canReserve && !isOpposite()) {
1526 // we have a low-priority relief connection
1527 // std::cout << SIMTIME << " veh=" << myVehicle.getID() << " cannotReserve for blockers\n";
1528 myDontBrake = canContinue;
1529 }
1530
1531 const int remainingLanes = MAX2(1, abs(bestLaneOffset));
1532 const double urgency = isOpposite() ? OPPOSITE_URGENCY : URGENCY;
1533 const double remainingSeconds = ((ret & LCA_TRACI) == 0 ?
1534 //MAX2(STEPS2TIME(TS), (myLeftSpace-myLeadingBlockerLength) / MAX2(myLookAheadSpeed, NUMERICAL_EPS) / remainingLanes / urgency) :
1535 MAX2(STEPS2TIME(TS), myLeftSpace / MAX2(myLookAheadSpeed, NUMERICAL_EPS) / remainingLanes / urgency) :
1537 if (!hasBidiNeighLeader && !hasJunctionLeader) {
1538 const double plannedSpeed = informLeader(msgPass, blocked, myLca, neighLead, remainingSeconds);
1539 // NOTE: for the ballistic update case negative speeds may indicate a stop request,
1540 // while informLeader returns -1 in that case. Refs. #2577
1541 if (plannedSpeed >= 0 || (!MSGlobals::gSemiImplicitEulerUpdate && plannedSpeed != -1)) {
1542 // maybe we need to deal with a blocking follower
1543 const bool hasBidiNeighFollower = neighLane.getBidiLane() != nullptr && MSLCHelper::isBidiFollower(&myVehicle, neighFollow.first);
1544 if (!hasBidiNeighFollower) {
1545 informFollower(msgPass, blocked, myLca, neighFollow, remainingSeconds, plannedSpeed);
1546 }
1547 }
1548#ifdef DEBUG_WANTS_CHANGE
1549 if (DEBUG_COND) {
1550 std::cout << STEPS2TIME(currentTime)
1551 << " veh=" << myVehicle.getID()
1552 << " myLeftSpace=" << myLeftSpace
1553 << " remainingSeconds=" << remainingSeconds
1554 << " plannedSpeed=" << plannedSpeed
1555 << "\n";
1556 }
1557#endif
1558 } else {
1559#ifdef DEBUG_WANTS_CHANGE
1560 if (DEBUG_COND) {
1561 std::cout << STEPS2TIME(currentTime)
1562 << " veh=" << myVehicle.getID()
1563 << " myLeftSpace=" << myLeftSpace
1564 << " remainingSeconds=" << remainingSeconds
1565 << " hasBidiNeighLeader=" << hasBidiNeighLeader
1566 << " hasJunctionLeader=" << hasJunctionLeader << "\n";
1567 }
1568#endif
1569 }
1570
1571
1572 // remove TraCI flags because it should not be included in "state-without-traci"
1573 ret = getCanceledState(laneOffset);
1574 return ret;
1575 }
1576
1577 // we wish to anticipate future speeds. This is difficult when the leading
1578 // vehicles are still accelerating so we resort to comparing speeds for the near future (1s) in this case
1579 const bool acceleratingLeader = (neighLead.first != 0 && neighLead.first->getAcceleration() > 0)
1580 || (leader.first != 0 && leader.first->getAcceleration() > 0);
1581 double neighLaneVSafe = MIN2(neighVMax, anticipateFollowSpeed(neighLead, neighDist, neighVMax, acceleratingLeader));
1582 thisLaneVSafe = MIN2(thisLaneVSafe, anticipateFollowSpeed(leader, currentDist, vMax, acceleratingLeader));
1583 //std::cout << SIMTIME << " veh=" << myVehicle.getID() << " thisLaneVSafe=" << thisLaneVSafe << " neighLaneVSafe=" << neighLaneVSafe << "\n";
1584
1585
1586 // a high inconvenience prevents cooperative changes and the following things are inconvenient:
1587 // - a desire to change in the opposite direction for speedGain
1588 // - low anticipated speed on the neighboring lane
1589 // - high occupancy on the neighboring lane while in a roundabout
1590
1591 double inconvenience = laneOffset < 0
1594
1595 const double relSpeedDiff = thisLaneVSafe == 0 ? 0 : (thisLaneVSafe - neighLaneVSafe) / MAX2(thisLaneVSafe, neighLaneVSafe);
1596 inconvenience = MAX2(relSpeedDiff, inconvenience);
1597 inconvenience = MIN2(1.0, inconvenience);
1598
1599 const bool speedGainInconvenient = inconvenience > myCooperativeParam;
1600 const bool neighOccupancyInconvenient = neigh->lane->getBruttoOccupancy() > curr->lane->getBruttoOccupancy();
1601#ifdef DEBUG_WANTS_CHANGE
1602 if (DEBUG_COND) {
1603 std::cout << STEPS2TIME(currentTime)
1604 << " veh=" << myVehicle.getID()
1605 << " speedGainL=" << (double)mySpeedGainProbabilityLeft / HYST_PRECISION
1606 << " speedGainR=" << (double)mySpeedGainProbabilityRight / HYST_PRECISION
1607 << " neighSpeedFactor=" << (thisLaneVSafe / neighLaneVSafe - 1)
1608 << " inconvenience=" << inconvenience
1609 << " speedInconv=" << speedGainInconvenient
1610 << " occInconv=" << neighOccupancyInconvenient
1611 << "\n";
1612 }
1613#endif
1614
1615 // VARIANT_15
1616 if (roundaboutBonus > 0) {
1617
1618#ifdef DEBUG_WANTS_CHANGE
1619 if (DEBUG_COND) {
1620 std::cout << STEPS2TIME(currentTime)
1621 << " veh=" << myVehicle.getID()
1622 << " roundaboutBonus=" << roundaboutBonus
1623 << " myLeftSpace=" << myLeftSpace
1624 << "\n";
1625 }
1626#endif
1627 // try to use the inner lanes of a roundabout to increase throughput
1628 // unless we are approaching the exit
1629 if (lca == LCA_LEFT) {
1630 // if inconvenience is not too high, request collaborative change (currently only for ballistic update)
1631 // TODO: test this for euler update! Refs. #2575
1632 if (MSGlobals::gSemiImplicitEulerUpdate || !neighOccupancyInconvenient) {
1633// if(MSGlobals::gSemiImplicitEulerUpdate || !speedGainInconvenient){
1634 req = ret | lca | LCA_COOPERATIVE;
1635 }
1636 } else {
1637 // if inconvenience is not too high, request collaborative change (currently only for ballistic update)
1638 if (MSGlobals::gSemiImplicitEulerUpdate || neighOccupancyInconvenient) {
1639// if(MSGlobals::gSemiImplicitEulerUpdate || speedGainInconvenient){
1640 req = ret | LCA_STAY | LCA_COOPERATIVE;
1641 }
1642 }
1643 if (!cancelRequest(req, laneOffset)) {
1644 return ret | req;
1645 }
1646 }
1647
1648 // let's also regard the case where the vehicle is driving on a highway...
1649 // in this case, we do not want to get to the dead-end of an on-ramp
1650 if (right) {
1651 if (bestLaneOffset == 0 && myVehicle.getLane()->getSpeedLimit() > 80. / 3.6 && myLookAheadSpeed > SUMO_const_haltingSpeed) {
1652#ifdef DEBUG_WANTS_CHANGE
1653 if (DEBUG_COND) {
1654 std::cout << " veh=" << myVehicle.getID() << " does not want to get stranded on the on-ramp of a highway\n";
1655 }
1656#endif
1657 req = ret | LCA_STAY | LCA_STRATEGIC;
1658 if (!cancelRequest(req, laneOffset)) {
1659 return ret | req;
1660 }
1661 }
1662 }
1663 // --------
1664
1665 // -------- make place on current lane if blocking follower
1666 //if (amBlockingFollowerPlusNB()) {
1667 // std::cout << myVehicle.getID() << ", " << currentDistAllows(neighDist, bestLaneOffset, laDist)
1668 // << " neighDist=" << neighDist
1669 // << " currentDist=" << currentDist
1670 // << "\n";
1671 //}
1672
1674 && (!speedGainInconvenient)
1675 && ((myOwnState & myLca) != 0) // VARIANT_6 : counterNoHelp
1676 && (changeToBest || currentDistAllows(neighDist, abs(bestLaneOffset) + 1, laDist))) {
1677
1678 // VARIANT_2 (nbWhenChangingToHelp)
1679#ifdef DEBUG_COOPERATE
1680 if (DEBUG_COND) {
1681 std::cout << STEPS2TIME(currentTime)
1682 << " veh=" << myVehicle.getID()
1683 << " wantsChangeToHelp=" << (right ? "right" : "left")
1684 << " state=" << myOwnState
1685 << (((myOwnState & myLca) == 0) ? " (counter)" : "")
1686 << "\n";
1687 }
1688#endif
1689 req = ret | lca | LCA_COOPERATIVE | LCA_URGENT ;//| LCA_CHANGE_TO_HELP;
1690 if (!cancelRequest(req, laneOffset)) {
1691 if ((blocked & LCA_BLOCKED_BY_LEFT_FOLLOWER) && !right && mySpeedGainProbabilityLeft > (long long int)(mySpeedGainUrgency * HYST_PRECISION)) {
1692 MSVehicle* nv = neighFollow.first;
1693 const bool hasBidiNeighFollower = neighLane.getBidiLane() != nullptr && MSLCHelper::isBidiFollower(&myVehicle, nv);
1694 if (nv != nullptr && !hasBidiNeighFollower && !MSLCHelper::unwillingToHelp(myVehicle, myVehicle.getSpeed(), *nv)) {
1695 const double helpSpeed = MAX2(nv->getCarFollowModel().minNextSpeed(nv->getSpeed(), nv), myVehicle.getSpeed() - 1);
1696 msgPass.informNeighFollower(new Info(helpSpeed, myLca | LCA_AMBLOCKINGFOLLOWER), &myVehicle);
1697 }
1698 }
1699 return ret | req;
1700 }
1701 }
1702
1703 // --------
1704
1705
1708 //if ((blocked & LCA_BLOCKED) != 0) {
1709 // return ret;
1710 //}
1712
1713 // -------- higher speed
1714 //if ((congested(neighLead.first) && neighLead.second < 20) || predInteraction(leader.first)) { //!!!
1715 // return ret;
1716 //}
1717
1718 if (neighLane.getEdge().getPersons().size() > 0) {
1719 // react to pedestrians
1720 adaptSpeedToPedestrians(myVehicle.getLane(), thisLaneVSafe);
1721 adaptSpeedToPedestrians(&neighLane, neighLaneVSafe);
1722 }
1723
1724 const double relativeGain = (neighLaneVSafe - thisLaneVSafe) / MAX2(neighLaneVSafe,
1726
1727#ifdef DEBUG_WANTS_CHANGE
1728 if (DEBUG_COND) {
1729 std::cout << STEPS2TIME(currentTime)
1730 << " veh=" << myVehicle.getID()
1731 << " currentDist=" << currentDist
1732 << " neighDist=" << neighDist
1733 << " thisVSafe=" << thisLaneVSafe
1734 << " neighVSafe=" << neighLaneVSafe
1735 << " relGain=" << toString(relativeGain, 8)
1736 << "\n";
1737 }
1738#endif
1739
1740 if (right) {
1741 // ONLY FOR CHANGING TO THE RIGHT
1742 if (thisLaneVSafe - 5 / 3.6 > neighLaneVSafe) {
1743 // ok, the current lane is faster than the right one...
1745 //myKeepRightProbability /= 2.0;
1746 } else {
1747 // ok, the current lane is not (much) faster than the right one
1748 mySpeedGainProbabilityRight += (long long int)(myVehicle.getActionStepLengthSecs() * relativeGain * HYST_PRECISION);
1749
1750 // honor the obligation to keep right (Rechtsfahrgebot)
1751 const double roadSpeedFactor = vMax / myVehicle.getLane()->getSpeedLimit(); // differse from speedFactor if vMax < speedLimit
1752 double acceptanceTime;
1753 if (myKeepRightAcceptanceTime == -1) {
1754 // legacy behavior: scale acceptance time with current speed and
1755 // use old hard-coded constant
1756 acceptanceTime = 7 * roadSpeedFactor * MAX2(1.0, myVehicle.getSpeed());
1757 } else {
1758 acceptanceTime = myKeepRightAcceptanceTime * roadSpeedFactor;
1759 if (follower.first != nullptr && follower.second < 2 * follower.first->getCarFollowModel().brakeGap(follower.first->getSpeed())) {
1760 // reduce acceptanceTime if the follower vehicle is faster or wants to drive faster
1761 if (follower.first->getSpeed() >= myVehicle.getSpeed()) {
1762 acceptanceTime *= MAX2(1.0, myVehicle.getSpeed()) / MAX2(1.0, follower.first->getSpeed());
1763 const double fRSF = follower.first->getLane()->getVehicleMaxSpeed(follower.first) / follower.first->getLane()->getSpeedLimit();
1764 if (fRSF > roadSpeedFactor) {
1765 acceptanceTime /= fRSF;
1766 }
1767 }
1768 }
1769 }
1770 double fullSpeedGap = MAX2(0., neighDist - myVehicle.getCarFollowModel().brakeGap(vMax));
1771 double fullSpeedDrivingSeconds = MIN2(acceptanceTime, fullSpeedGap / vMax);
1772 if (neighLead.first != 0 && neighLead.first->getSpeed() < vMax) {
1773 fullSpeedGap = MAX2(0., MIN2(fullSpeedGap,
1774 neighLead.second - myVehicle.getCarFollowModel().getSecureGap(&myVehicle, neighLead.first,
1775 vMax, neighLead.first->getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel())));
1776 fullSpeedDrivingSeconds = MIN2(fullSpeedDrivingSeconds, fullSpeedGap / (vMax - neighLead.first->getSpeed()));
1777 }
1778 // stay on the current lane if we cannot overtake a slow leader on the right
1779 if (checkOverTakeRight && leader.first != 0
1780 && leader.first->getLane()->getVehicleMaxSpeed(leader.first) < vMax) {
1781 fullSpeedGap = MIN2(fullSpeedGap, leader.second);
1782 fullSpeedDrivingSeconds = MIN2(fullSpeedDrivingSeconds, fullSpeedGap / (vMax - leader.first->getSpeed()));
1783 }
1784
1785 const double deltaProb = (double)myKeepRightProbThreshold * (fullSpeedDrivingSeconds / acceptanceTime) / KEEP_RIGHT_TIME;
1786 myKeepRightProbability -= (long long int)(myVehicle.getActionStepLengthSecs() * deltaProb);
1787
1788 //std::cout << STEPS2TIME(currentTime)
1789 // << " veh=" << myVehicle.getID()
1790 // << " acceptanceTime=" << acceptanceTime
1791 // << " fullSpeedDrivingSeconds=" << fullSpeedDrivingSeconds
1792 // << " dProb=" << deltaProb
1793 // << " myKeepRightProbability=" << myKeepRightProbability
1794 // << "\n";
1795
1796#ifdef DEBUG_WANTS_CHANGE
1797 if (DEBUG_COND) {
1798 std::cout << STEPS2TIME(currentTime)
1799 << " veh=" << myVehicle.getID()
1800 << " vMax=" << vMax
1801 << " neighDist=" << neighDist
1802 << " brakeGap=" << myVehicle.getCarFollowModel().brakeGap(myVehicle.getSpeed())
1803 << " leaderSpeed=" << (neighLead.first == 0 ? -1 : neighLead.first->getSpeed())
1804 << " secGap=" << (neighLead.first == 0 ? -1 : myVehicle.getCarFollowModel().getSecureGap(&myVehicle, neighLead.first,
1805 myVehicle.getSpeed(), neighLead.first->getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel()))
1806 << " acceptanceTime=" << acceptanceTime
1807 << " fullSpeedGap=" << fullSpeedGap
1808 << " fullSpeedDrivingSeconds=" << fullSpeedDrivingSeconds
1809 << " dProb=" << (double)deltaProb / HYST_PRECISION
1810 << " myKeepRightProbability=" << (double)myKeepRightProbability / HYST_PRECISION
1811 << "\n";
1812 }
1813#endif
1814 if ((long long int)((double)myKeepRightProbability * myKeepRightParam) < -myKeepRightProbThreshold) {
1815 req = ret | lca | LCA_KEEPRIGHT;
1816 if (!cancelRequest(req, laneOffset)) {
1817 return ret | req;
1818 }
1819 }
1820 }
1821
1822#ifdef DEBUG_WANTS_CHANGE
1823 if (DEBUG_COND) {
1824 std::cout << STEPS2TIME(currentTime)
1825 << " veh=" << myVehicle.getID()
1826 << " speed=" << myVehicle.getSpeed()
1827 << " speedGainL=" << (double)mySpeedGainProbabilityLeft / HYST_PRECISION
1828 << " speedGainR=" << (double)mySpeedGainProbabilityRight / HYST_PRECISION
1829 << " thisLaneVSafe=" << thisLaneVSafe
1830 << " neighLaneVSafe=" << neighLaneVSafe
1831 << " relativeGain=" << relativeGain
1832 << " blocked=" << blocked
1833 << "\n";
1834 }
1835#endif
1836
1838 && neighDist / MAX2(.1, myVehicle.getSpeed()) > mySpeedGainRemainTime) { //./MAX2( .1, myVehicle.getSpeed())) { // -.1
1839 req = ret | lca | LCA_SPEEDGAIN;
1841 req |= LCA_URGENT;
1842 }
1843 if (!cancelRequest(req, laneOffset)) {
1844 return ret | req;
1845 }
1846 }
1847 } else {
1848 // ONLY FOR CHANGING TO THE LEFT
1849 if (thisLaneVSafe > neighLaneVSafe) {
1850 // this lane is better
1852 } else if (thisLaneVSafe == neighLaneVSafe) {
1854 } else {
1855 mySpeedGainProbabilityLeft += (long long int)(myVehicle.getActionStepLengthSecs() * relativeGain * HYST_PRECISION);
1856 }
1857 // VARIANT_19 (stayRight)
1858 //if (neighFollow.first != 0) {
1859 // MSVehicle* nv = neighFollow.first;
1860 // const double secGap = nv->getCarFollowModel().getSecureGap(nv, &myVehicle, nv->getSpeed(), myVehicle.getSpeed(), myVehicle.getCarFollowModel().getMaxDecel());
1861 // if (neighFollow.second < secGap * KEEP_RIGHT_HEADWAY) {
1862 // // do not change left if it would inconvenience faster followers
1863 // return ret | LCA_STAY | LCA_SPEEDGAIN;
1864 // }
1865 //}
1866
1867#ifdef DEBUG_WANTS_CHANGE
1868 if (DEBUG_COND) {
1869 std::cout << STEPS2TIME(currentTime)
1870 << " veh=" << myVehicle.getID()
1871 << " speed=" << myVehicle.getSpeed()
1872 << " speedGainL=" << (double)mySpeedGainProbabilityLeft / HYST_PRECISION
1873 << " speedGainR=" << (double)mySpeedGainProbabilityRight / HYST_PRECISION
1874 << " thisLaneVSafe=" << thisLaneVSafe
1875 << " neighLaneVSafe=" << neighLaneVSafe
1876 << " relativeGain=" << relativeGain
1877 << " blocked=" << blocked
1878 << "\n";
1879 }
1880#endif
1881
1883 && (relativeGain > NUMERICAL_EPS || changeLeftToAvoidOvertakeRight)
1884 && neighDist / MAX2(.1, myVehicle.getSpeed()) > mySpeedGainRemainTime) { // .1
1885 req = ret | lca | LCA_SPEEDGAIN;
1887 req |= LCA_URGENT;
1888 }
1889 if (!cancelRequest(req, laneOffset)) {
1890 if ((req & LCA_URGENT) && (blocked & LCA_BLOCKED_BY_LEFT_FOLLOWER)) {
1891 MSVehicle* nv = neighFollow.first;
1892 const bool hasBidiNeighFollower = neighLane.getBidiLane() != nullptr && MSLCHelper::isBidiFollower(&myVehicle, nv);
1893 if (nv != nullptr && !hasBidiNeighFollower && !MSLCHelper::unwillingToHelp(myVehicle, myVehicle.getSpeed(), *nv)) {
1894 const double helpSpeed = MAX2(nv->getCarFollowModel().minNextSpeed(nv->getSpeed(), nv), myVehicle.getSpeed() - 1);
1895 msgPass.informNeighFollower(new Info(helpSpeed, myLca | LCA_AMBLOCKINGFOLLOWER), &myVehicle);
1896 }
1897 }
1898 return ret | req;
1899 }
1900 }
1901 }
1902 // --------
1903 if (changeToBest && bestLaneOffset == curr->bestLaneOffset
1904 && myStrategicParam >= 0
1905 && relativeGain >= 0
1907 // change towards the correct lane, speedwise it does not hurt
1908 req = ret | lca | LCA_STRATEGIC;
1909 if (!cancelRequest(req, laneOffset)) {
1910 return ret | req;
1911 }
1912 }
1913#ifdef DEBUG_WANTS_CHANGE
1914 if (DEBUG_COND) {
1915 std::cout << STEPS2TIME(currentTime)
1916 << " veh=" << myVehicle.getID()
1917 << " speedGainL=" << (double)mySpeedGainProbabilityLeft / HYST_PRECISION
1918 << " speedGainR=" << (double)mySpeedGainProbabilityRight / HYST_PRECISION
1919 << " myKeepRightProbability=" << (double)myKeepRightProbability / HYST_PRECISION
1920 << " thisLaneVSafe=" << thisLaneVSafe
1921 << " neighLaneVSafe=" << neighLaneVSafe
1922 << "\n";
1923 }
1924#endif
1925
1926 return ret;
1927}
1928
1929
1930double
1931MSLCM_LC2013::anticipateFollowSpeed(const std::pair<MSVehicle*, double>& leaderDist, double dist, double vMax, bool acceleratingLeader) {
1932 const MSVehicle* leader = leaderDist.first;
1933 const double gap = leaderDist.second;
1934 double futureSpeed;
1935 if (acceleratingLeader) {
1936 // XXX see #6562
1937 const double maxSpeed1s = (myVehicle.getSpeed() + myVehicle.getCarFollowModel().getMaxAccel()
1939 if (leader == nullptr) {
1940 if (hasBlueLight()) {
1941 // can continue from any lane if necessary
1942 futureSpeed = vMax;
1943 } else {
1944 futureSpeed = getCarFollowModel().followSpeed(&myVehicle, maxSpeed1s, dist, 0, 0);
1945 }
1946 } else {
1947 futureSpeed = getCarFollowModel().followSpeed(&myVehicle, maxSpeed1s, gap, leader->getSpeed(), leader->getCarFollowModel().getMaxDecel());
1948 }
1949 } else {
1950 // onInsertion = true because the vehicle has already moved
1951 if (leader == nullptr) {
1952 if (hasBlueLight()) {
1953 // can continue from any lane if necessary
1954 futureSpeed = vMax;
1955 } else {
1956 futureSpeed = getCarFollowModel().maximumSafeStopSpeed(dist, getCarFollowModel().getMaxDecel(), myVehicle.getSpeed(), true);
1957 }
1958 } else {
1959 futureSpeed = getCarFollowModel().maximumSafeFollowSpeed(gap, myVehicle.getSpeed(), leader->getSpeed(), leader->getCarFollowModel().getMaxDecel(), true);
1960 }
1961 }
1962 futureSpeed = MIN2(vMax, futureSpeed);
1963 if (leader != nullptr && gap > 0 && mySpeedGainLookahead > 0) {
1964 const double futureLeaderSpeed = acceleratingLeader ? leader->getLane()->getVehicleMaxSpeed(leader) : leader->getSpeed();
1965 const double deltaV = vMax - futureLeaderSpeed;
1966 if (deltaV > 0 && gap > 0) {
1967 const double secGap = getCarFollowModel().getSecureGap(&myVehicle, leader, futureSpeed, leader->getSpeed(), getCarFollowModel().getMaxDecel());
1968 const double fullSpeedGap = gap - secGap;
1969 if (fullSpeedGap / deltaV < mySpeedGainLookahead) {
1970 // anticipate future braking by computing the average
1971 // speed over the next few seconds
1972 const double gapClosingTime = MAX2(0.0, fullSpeedGap / deltaV);
1973 const double foreCastTime = mySpeedGainLookahead * 2;
1974 //if (DEBUG_COND) std::cout << SIMTIME << " veh=" << myVehicle.getID() << " leader=" << leader->getID() << " gap=" << gap << " deltaV=" << deltaV << " futureSpeed=" << futureSpeed << " futureLeaderSpeed=" << futureLeaderSpeed;
1975 futureSpeed = MIN2(futureSpeed, (gapClosingTime * futureSpeed + (foreCastTime - gapClosingTime) * futureLeaderSpeed) / foreCastTime);
1976 //if (DEBUG_COND) std::cout << " newFutureSpeed=" << futureSpeed << "\n";
1977 }
1978 }
1979 }
1980 return futureSpeed;
1981}
1982
1983
1984int
1986 // if this vehicle is blocking someone in front, we maybe decelerate to let him in
1987 if (blocked != nullptr) {
1989#ifdef DEBUG_SLOW_DOWN
1990 if (DEBUG_COND) {
1991 std::cout << SIMTIME
1992 << " veh=" << myVehicle.getID()
1993 << " blocked=" << Named::getIDSecure(blocked)
1994 << " gap=" << gap
1995 << "\n";
1996 }
1997#endif
1998 if (gap > POSITION_EPS) {
1999 //const bool blockedWantsUrgentRight = (((*blocked)->getLaneChangeModel().getOwnState() & LCA_RIGHT != 0)
2000 // && ((*blocked)->getLaneChangeModel().getOwnState() & LCA_URGENT != 0));
2001
2003 //|| blockedWantsUrgentRight // VARIANT_10 (helpblockedRight)
2004 ) {
2005 if (blocked->getSpeed() < SUMO_const_haltingSpeed) {
2007 } else {
2008 state |= LCA_AMBACKBLOCKER;
2009 }
2010 addLCSpeedAdvice(getCarFollowModel().followSpeed(
2012 gap - POSITION_EPS, blocked->getSpeed(),
2014
2015 //(*blocked) = 0; // VARIANT_14 (furtherBlock)
2016#ifdef DEBUG_SLOW_DOWN
2017 if (DEBUG_COND) {
2018 std::cout << SIMTIME
2019 << " veh=" << myVehicle.getID()
2020 << " slowing down for"
2021 << " blocked=" << Named::getIDSecure(blocked)
2022 << " helpSpeed=" << myLCAccelerationAdvices.back().first
2023 << "\n";
2024 }
2025#endif
2026 } /*else if ((*blocked)->getWaitingSeconds() > 30 && gap > myVehicle.getBrakeGap()) {
2027 // experimental else-branch...
2028
2029 state |= LCA_AMBACKBLOCKER;
2030 addLCSpeedAdvice(getCarFollowModel().followSpeed(
2031 &myVehicle, myVehicle.getSpeed(),
2032 (gap - POSITION_EPS), (*blocked)->getSpeed(),
2033 (*blocked)->getCarFollowModel().getMaxDecel()));
2034 } */
2035 }
2036 }
2037 return state;
2038}
2039
2040
2041void
2043 if (lane->hasPedestrians()) {
2044#ifdef DEBUG_WANTS_CHANGE
2045 if (DEBUG_COND) {
2046 std::cout << SIMTIME << " adapt to pedestrians on lane=" << lane->getID() << "\n";
2047 }
2048#endif
2052 if (leader.first != 0) {
2053 const double stopSpeed = myVehicle.getCarFollowModel().stopSpeed(&myVehicle, myVehicle.getSpeed(), leader.second - myVehicle.getVehicleType().getMinGap());
2054 v = MIN2(v, stopSpeed);
2055#ifdef DEBUG_WANTS_CHANGE
2056 if (DEBUG_COND) {
2057 std::cout << SIMTIME << " pedLeader=" << leader.first->getID() << " dist=" << leader.second << " v=" << v << "\n";
2058 }
2059#endif
2060 }
2061 }
2062}
2063
2064
2065double
2066MSLCM_LC2013::computeSpeedLat(double latDist, double& maneuverDist, bool urgent) const {
2067 double result = MSAbstractLaneChangeModel::computeSpeedLat(latDist, maneuverDist, urgent);
2068#ifdef DEBUG_WANTS_CHANGE
2069 if (DEBUG_COND) {
2070 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " myLeftSpace=" << myLeftSpace << " latDist=" << latDist << " maneuverDist=" << maneuverDist << " result=" << result << "\n";
2071 }
2072#endif
2073 if (myLeftSpace > POSITION_EPS || !urgent) {
2075 if (isChangingLanes()) {
2076 speedBound = MAX2(LC_RESOLUTION_SPEED_LAT, speedBound);
2077 }
2078 result = MAX2(-speedBound, MIN2(speedBound, result));
2079 }
2080 return result;
2081}
2082
2083
2084double
2086 return 1 / myAssertive;
2087}
2088
2089double
2091 return myOppositeParam <= 0 ? std::numeric_limits<double>::max() : 1 / myOppositeParam;
2092}
2093
2094bool
2095MSLCM_LC2013::saveBlockerLength(double length, double foeLeftSpace) {
2096 const bool canReserve = MSLCHelper::canSaveBlockerLength(myVehicle, length, myLeftSpace);
2097 if (!isOpposite() && (canReserve || myLeftSpace > foeLeftSpace)) {
2099#ifdef DEBUG_SAVE_BLOCKER_LENGTH
2100 if (DEBUG_COND) {
2101 std::cout << SIMTIME << " saveBlockerLength veh=" << myVehicle.getID() << " canReserve=" << canReserve << " myLeftSpace=" << myLeftSpace << " foeLeftSpace=" << foeLeftSpace << "\n";
2102 }
2103#endif
2104 if (myLeftSpace == 0 && foeLeftSpace < 0) {
2105 // called from opposite overtaking, myLeftSpace must be initialized
2107 }
2108 return true;
2109 } else {
2110 return false;
2111 }
2112}
2113
2114
2115bool
2116MSLCM_LC2013::hasFreeLane(int laneOffset, const std::pair<MSVehicle*, double>& neighLeadStopped) const {
2117 if (neighLeadStopped.first == nullptr) {
2118 return true;
2119 }
2120 int dir = (laneOffset > 0 ? 1 : -1);
2121 const MSLane* neigh = myVehicle.getLane()->getParallelLane(laneOffset);
2122 if (dir > 0 && !neigh->allowsChangingLeft(myVehicle.getVClass())) {
2123 return false;
2124 } else if (dir < 0 && !neigh->allowsChangingRight(myVehicle.getVClass())) {
2125 return false;
2126 }
2127 int nextOffset = laneOffset + dir;
2128 const MSLane* next = myVehicle.getLane()->getParallelLane(nextOffset);
2129 if (next == nullptr || !next->allowsVehicleClass(myVehicle.getVClass())) {
2130 return false;
2131 }
2132 const double overtakeDist = neighLeadStopped.second + neighLeadStopped.first->getVehicleType().getLengthWithGap() + myVehicle.getLength() + POSITION_EPS;
2133 std::pair<MSVehicle* const, double> nextLead = next->getLeader(&myVehicle, myVehicle.getPositionOnLane(), myVehicle.getBestLanesContinuation(next), overtakeDist);
2134 return nextLead.first == nullptr || nextLead.second >= overtakeDist || hasFreeLane(nextOffset, nextLead);
2135}
2136
2137
2138std::string
2139MSLCM_LC2013::getParameter(const std::string& key) const {
2141 return toString(myStrategicParam);
2142 } else if (key == toString(SUMO_ATTR_LCA_COOPERATIVE_PARAM)) {
2144 } else if (key == toString(SUMO_ATTR_LCA_SPEEDGAIN_PARAM)) {
2145 return toString(mySpeedGainParam);
2146 } else if (key == toString(SUMO_ATTR_LCA_KEEPRIGHT_PARAM)) {
2147 return toString(myKeepRightParam);
2148 } else if (key == toString(SUMO_ATTR_LCA_OPPOSITE_PARAM)) {
2149 return toString(myOppositeParam);
2150 } else if (key == toString(SUMO_ATTR_LCA_LOOKAHEADLEFT)) {
2151 return toString(myLookaheadLeft);
2152 } else if (key == toString(SUMO_ATTR_LCA_SPEEDGAINRIGHT)) {
2153 return toString(mySpeedGainRight);
2154 } else if (key == toString(SUMO_ATTR_LCA_ASSERTIVE)) {
2155 return toString(myAssertive);
2156 } else if (key == toString(SUMO_ATTR_LCA_OVERTAKE_RIGHT)) {
2158 } else if (key == toString(SUMO_ATTR_LCA_SIGMA)) {
2159 return toString(mySigma);
2164 } else if (key == toString(SUMO_ATTR_LCA_STRATEGIC_LOOKAHEAD)) {
2166 } else if (key == toString(SUMO_ATTR_LCA_SPEEDGAIN_LOOKAHEAD)) {
2168 } else if (key == toString(SUMO_ATTR_LCA_SPEEDGAIN_REMAIN_TIME)) {
2172 } else if (key == toString(SUMO_ATTR_LCA_COOPERATIVE_SPEED)) {
2174 } else if (key == toString(SUMO_ATTR_LCA_MAXSPEEDLATSTANDING)) {
2176 } else if (key == toString(SUMO_ATTR_LCA_MAXSPEEDLATFACTOR)) {
2178 } else if (key == toString(SUMO_ATTR_LCA_MAXDISTLATSTANDING)) {
2180 // access to internal state for debugging in sumo-gui (not documented since it may change at any time)
2181 } else if (key == "speedGainProbabilityRight") {
2183 } else if (key == "speedGainProbabilityLeft") {
2185 } else if (key == "keepRightProbability") {
2186 return toString((double) - myKeepRightProbability / HYST_PRECISION);
2187 } else if (key == "lookAheadSpeed") {
2188 return toString(myLookAheadSpeed);
2189 // motivation relative to threshold
2190 } else if (key == "speedGainRP") {
2192 } else if (key == "speedGainLP") {
2194 } else if (key == "keepRightP") {
2196 }
2197 throw InvalidArgument("Parameter '" + key + "' is not supported for laneChangeModel of type '" + toString(myModel) + "'");
2198}
2199
2200
2201void
2202MSLCM_LC2013::setParameter(const std::string& key, const std::string& value) {
2203 double doubleValue;
2204 try {
2205 doubleValue = StringUtils::toDouble(value);
2206 } catch (NumberFormatException&) {
2207 throw InvalidArgument("Setting parameter '" + key + "' requires a number for laneChangeModel of type '" + toString(myModel) + "'");
2208 }
2210 myStrategicParam = doubleValue;
2211 } else if (key == toString(SUMO_ATTR_LCA_COOPERATIVE_PARAM)) {
2212 myCooperativeParam = doubleValue;
2213 } else if (key == toString(SUMO_ATTR_LCA_SPEEDGAIN_PARAM)) {
2214 mySpeedGainParam = doubleValue;
2215 } else if (key == toString(SUMO_ATTR_LCA_KEEPRIGHT_PARAM)) {
2216 myKeepRightParam = doubleValue;
2217 } else if (key == toString(SUMO_ATTR_LCA_OPPOSITE_PARAM)) {
2218 myOppositeParam = doubleValue;
2219 } else if (key == toString(SUMO_ATTR_LCA_LOOKAHEADLEFT)) {
2220 myLookaheadLeft = doubleValue;
2221 } else if (key == toString(SUMO_ATTR_LCA_SPEEDGAINRIGHT)) {
2222 mySpeedGainRight = doubleValue;
2223 } else if (key == toString(SUMO_ATTR_LCA_ASSERTIVE)) {
2224 myAssertive = doubleValue;
2225 } else if (key == toString(SUMO_ATTR_LCA_OVERTAKE_RIGHT)) {
2226 myOvertakeRightParam = doubleValue;
2227 } else if (key == toString(SUMO_ATTR_LCA_SIGMA)) {
2228 mySigma = doubleValue;
2230 myKeepRightAcceptanceTime = doubleValue;
2232 myOvertakeDeltaSpeedFactor = doubleValue;
2233 } else if (key == toString(SUMO_ATTR_LCA_STRATEGIC_LOOKAHEAD)) {
2234 myStrategicLookahead = doubleValue;
2235 } else if (key == toString(SUMO_ATTR_LCA_SPEEDGAIN_LOOKAHEAD)) {
2236 mySpeedGainLookahead = doubleValue;
2237 } else if (key == toString(SUMO_ATTR_LCA_SPEEDGAIN_REMAIN_TIME)) {
2238 mySpeedGainRemainTime = doubleValue;
2240 myRoundaboutBonus = doubleValue;
2241 } else if (key == toString(SUMO_ATTR_LCA_COOPERATIVE_SPEED)) {
2242 myCooperativeSpeed = doubleValue;
2243 } else if (key == toString(SUMO_ATTR_LCA_MAXSPEEDLATSTANDING)) {
2244 myMaxSpeedLatStanding = doubleValue;
2245 } else if (key == toString(SUMO_ATTR_LCA_MAXSPEEDLATFACTOR)) {
2246 myMaxSpeedLatFactor = doubleValue;
2247 } else if (key == toString(SUMO_ATTR_LCA_MAXDISTLATSTANDING)) {
2248 myMaxDistLatStanding = doubleValue;
2249 // access to internal state
2250 } else if (key == "speedGainProbabilityRight") {
2251 mySpeedGainProbabilityRight = (long long int)(doubleValue * HYST_PRECISION);
2252 } else if (key == "speedGainProbabilityLeft") {
2253 mySpeedGainProbabilityLeft = (long long int)(doubleValue * HYST_PRECISION);
2254 } else if (key == "keepRightProbability") {
2255 myKeepRightProbability = (long long int)(-doubleValue * HYST_PRECISION);
2256 } else if (key == "lookAheadSpeed") {
2257 myLookAheadSpeed = doubleValue;
2258 } else {
2259 throw InvalidArgument("Setting parameter '" + key + "' is not supported for laneChangeModel of type '" + toString(myModel) + "'");
2260 }
2262}
2263
2264
2265void
2268 std::vector<long long int> lcState;
2269 lcState.push_back(mySpeedGainProbabilityLeft);
2270 lcState.push_back(mySpeedGainProbabilityRight);
2271 lcState.push_back(myKeepRightProbability);
2272 lcState.push_back((long long int)(myLookAheadSpeed * HYST_PRECISION));
2273 lcState.push_back(myDontBrake);
2274 out.writeAttr(SUMO_ATTR_LCSTATE2, lcState);
2275}
2276
2277
2278void
2281 if (attrs.hasAttribute(SUMO_ATTR_LCSTATE2)) {
2282 std::istringstream bis(attrs.getString(SUMO_ATTR_LCSTATE2));
2286 long long laSpeed;
2287 bis >> laSpeed;
2288 myLookAheadSpeed = (double)laSpeed / HYST_PRECISION;
2289 bis >> myDontBrake;
2290 }
2291}
2292
2293
2294
2295/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define JAM_FACTOR
#define HELP_DECEL_FACTOR
#define LOOK_AHEAD_MIN_SPEED
#define LCA_RIGHT_IMPATIENCE
#define LOOK_FORWARD
#define HELP_OVERTAKE
#define REACT_TO_STOPPED_DISTANCE
#define KEEP_RIGHT_TIME
#define RELGAIN_NORMALIZATION_MIN_SPEED
#define CUT_IN_LEFT_SPEED_THRESHOLD
#define MAX_ONRAMP_LENGTH
#define OPPOSITE_URGENCY
#define MIN_FALLBEHIND
#define HYST_PRECISION
#define URGENCY
#define LOOK_AHEAD_SPEED_MEMORY
#define BLOCKER_IS_BLOCKED_TIME_THRESHOLD
#define TURN_LANE_DIST
#define LC_RESOLUTION_SPEED_LAT
#define INVALID_SPEED
std::pair< const MSPerson *, double > PersonDist
Definition MSPModel.h:41
#define STEPS2TIME(x)
Definition SUMOTime.h:58
#define SPEED2DIST(x)
Definition SUMOTime.h:48
#define ACCEL2SPEED(x)
Definition SUMOTime.h:54
#define TS
Definition SUMOTime.h:45
#define SIMTIME
Definition SUMOTime.h:70
#define DIST2SPEED(x)
Definition SUMOTime.h:50
#define SPEED2ACCEL(x)
Definition SUMOTime.h:56
LaneChangeAction
The state of a vehicle's lane-change behavior.
@ LCA_KEEPRIGHT
The action is due to the default of keeping right "Rechtsfahrgebot".
@ LCA_CHANGE_TO_HELP
@ LCA_BLOCKED
blocked in all directions
@ LCA_URGENT
The action is urgent (to be defined by lc-model)
@ LCA_STAY
Needs to stay on the current lane.
@ LCA_BLOCKED_BY_LEADER
blocked by leader
@ LCA_AMBACKBLOCKER
@ LCA_BLOCKED_BY_LEFT_FOLLOWER
The vehicle is blocked by left follower.
@ LCA_AMBLOCKINGLEADER
@ LCA_AMBLOCKINGFOLLOWER_DONTBRAKE
@ LCA_COOPERATIVE
The action is done to help someone else.
@ LCA_LEFT
Wants go to the left.
@ LCA_STRATEGIC
The action is needed to follow the route (navigational lc)
@ LCA_AMBACKBLOCKER_STANDING
@ LCA_TRACI
The action is due to a TraCI request.
@ LCA_SPEEDGAIN
The action is due to the wish to be faster (tactical lc)
@ LCA_WANTS_LANECHANGE
lane can change
@ LCA_RIGHT
Wants go to the right.
@ LCA_BLOCKED_BY_FOLLOWER
blocker by follower
@ LCA_AMBLOCKINGFOLLOWER
@ SUMO_ATTR_LCA_COOPERATIVE_SPEED
@ SUMO_ATTR_LCSTATE2
@ SUMO_ATTR_LCA_ASSERTIVE
@ SUMO_ATTR_LCA_LOOKAHEADLEFT
@ SUMO_ATTR_LCA_SPEEDGAIN_PARAM
@ SUMO_ATTR_LCA_MAXDISTLATSTANDING
@ SUMO_ATTR_LCA_COOPERATIVE_ROUNDABOUT
@ SUMO_ATTR_LCA_SPEEDGAIN_LOOKAHEAD
@ SUMO_ATTR_LCA_MAXSPEEDLATFACTOR
@ SUMO_ATTR_LCA_MAXSPEEDLATSTANDING
@ SUMO_ATTR_LCA_KEEPRIGHT_PARAM
@ SUMO_ATTR_LCA_STRATEGIC_LOOKAHEAD
@ SUMO_ATTR_LCA_COOPERATIVE_PARAM
@ SUMO_ATTR_LCA_OPPOSITE_PARAM
@ SUMO_ATTR_LCA_SPEEDGAIN_REMAIN_TIME
@ SUMO_ATTR_LCA_OVERTAKE_DELTASPEED_FACTOR
@ SUMO_ATTR_LCA_SIGMA
@ SUMO_ATTR_LCA_OVERTAKE_RIGHT
@ SUMO_ATTR_LCA_STRATEGIC_PARAM
@ SUMO_ATTR_LCA_KEEPRIGHT_ACCEPTANCE_TIME
@ SUMO_ATTR_LCA_EXPERIMENTAL1
@ SUMO_ATTR_LCA_SPEEDGAIN_URGENCY
@ SUMO_ATTR_LCA_SPEEDGAINRIGHT
int gPrecision
the precision for floating point outputs
Definition StdDefs.cpp:27
T MIN2(T a, T b)
Definition StdDefs.h:80
const double SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
Definition StdDefs.h:62
T MAX2(T a, T b)
Definition StdDefs.h:86
T MAX3(T a, T b, T c)
Definition StdDefs.h:100
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
A class responsible for exchanging messages between cars involved in lane-change interaction.
void * informNeighFollower(void *info, MSVehicle *sender)
Informs the follower on the desired lane.
void * informNeighLeader(void *info, MSVehicle *sender)
Informs the leader on the desired lane.
Interface for lane-change models.
double getForwardPos() const
get vehicle position relative to the forward direction lane
virtual double getExtraReservation(int bestLaneOffset, double neighExtraDist=0) const
void addLCSpeedAdvice(const double vSafe, int flag)
Takes a vSafe (speed advice for speed in the next simulation step), converts it into an acceleration ...
std::vector< std::pair< double, int > > myLCAccelerationAdvices
virtual double computeSpeedLat(double latDist, double &maneuverDist, bool urgent) const
decides the next lateral speed depending on the remaining lane change distance to be covered and upda...
int myOwnState
The current state of the vehicle.
virtual void saveState(OutputDevice &out) const
Save the state of the laneChangeModel.
bool canOvertakeRight(const MSVehicle *const nv, const double dist, const double maxSpeedDiff, const double helpOvertakeSpeed, double &vSafe, double &deltaV) const
const LaneChangeModel myModel
the type of this model
bool cancelRequest(int state, int laneOffset)
whether the influencer cancels the given request
virtual bool avoidOvertakeRight(const MSVehicle *const neighLeader, const bool allowProb=false) const
void setSpeedLat(double speedLat)
set the lateral speed and update lateral acceleraton
const MSCFModel & getCarFollowModel() const
The vehicle's car following model.
virtual void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the laneChangeModel from the given attributes.
MSVehicle & myVehicle
The vehicle this lane-changer belongs to.
virtual void prepareStep(SumoRNG *rng)
rng belongs to the lane that moves the vehicle (not the lane it just entered)
bool isChangingLanes() const
return true if the vehicle currently performs a lane change maneuver
double getImpatience() const
Returns this vehicles impatience.
int getNumRemainingEdges() const
return the number of edges remaining in the route (include the current)
double getLength() const
Returns the vehicle's length.
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
const MSStop & getNextStop() const
SUMOVehicleClass getVClass() const
Returns the vehicle's access class.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
bool isStopped() const
Returns whether the vehicle is at a stop.
The car-following model abstraction.
Definition MSCFModel.h:59
static double gapExtrapolation(const double duration, const double currentGap, double v1, double v2, double a1=0, double a2=0, const double maxV1=std::numeric_limits< double >::max(), const double maxV2=std::numeric_limits< double >::max())
return the resulting gap if, starting with gap currentGap, two vehicles continue with constant accele...
virtual double minNextSpeedEmergency(double speed, const MSVehicle *const veh=0) const
Returns the minimum speed after emergency braking, given the current speed (depends on the numerical ...
virtual double minNextSpeed(double speed, const MSVehicle *const veh=0) const
Returns the minimum speed given the current speed (depends on the numerical update scheme and its ste...
double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion=false) const
Returns the maximum safe velocity for following the given leader.
@ LANE_CHANGE
the return value is used for lane change calculations
Definition MSCFModel.h:103
virtual double getSecureGap(const MSVehicle *const veh, const MSVehicle *const, const double speed, const double leaderSpeed, const double leaderMaxDecel) const
Returns the minimum gap to reserve if the leader is braking at maximum (>=0)
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
Definition MSCFModel.h:277
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
Definition MSCFModel.h:424
double maximumSafeStopSpeed(double gap, double decel, double currentSpeed, bool onInsertion=false, double headway=-1, bool relaxEmergency=true) const
Returns the maximum next velocity for stopping within gap.
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
Definition MSCFModel.h:285
virtual double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0, const CalcReason usage=CalcReason::CURRENT) const =0
Computes the vehicle's follow speed (no dawdling)
double stopSpeed(const MSVehicle *const veh, const double speed, double gap, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
Definition MSCFModel.h:189
const std::set< MSTransportable *, ComparatorNumericalIdLess > & getPersons() const
Returns this edge's persons set.
Definition MSEdge.h:205
bool hasLaneChanger() const
Definition MSEdge.h:760
bool isRoundabout() const
Definition MSEdge.h:743
bool isInternal() const
return whether this edge is an internal edge
Definition MSEdge.h:270
static bool gSemiImplicitEulerUpdate
Definition MSGlobals.h:53
static bool isBidiFollower(const MSVehicle *ego, const MSVehicle *follower)
static bool canSaveBlockerLength(const MSVehicle &veh, double requested, double leftSpace)
static double getSpeedPreservingSecureGap(const MSVehicle &leader, const MSVehicle &follower, double currentGap, double leaderPlannedSpeed)
static double getRoundaboutDistBonus(const MSVehicle &veh, double bonusParam, const MSVehicle::LaneQ &curr, const MSVehicle::LaneQ &neigh, const MSVehicle::LaneQ &best)
static bool isBidiLeader(const MSVehicle *leader, const std::vector< MSLane * > &cont)
static bool updateBlockerLength(const MSVehicle &veh, MSVehicle *blocker, int lcaCounter, double leftSpace, bool reliefConnection, double &leadingBlockerLength)
static bool unwillingToHelp(const MSVehicle &ego, double plannedSpeed, const MSVehicle &nv)
whether the neighboring vehicle nv is unwilling to yield to help ego merge
static bool divergentRoute(const MSVehicle &v1, const MSVehicle &v2)
return whether the vehicles are on the same junction but on divergent paths
bool currentDistAllows(double dist, int laneOffset, double lookForwardDist)
int wantsChange(int laneOffset, MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, const std::pair< MSVehicle *, double > &leader, const std::pair< MSVehicle *, double > &follower, const std::pair< MSVehicle *, double > &neighLead, const std::pair< MSVehicle *, double > &neighFollow, const MSLane &neighLane, const std::vector< MSVehicle::LaneQ > &preb, MSVehicle **lastBlocked, MSVehicle **firstBlocked) override
Called to examine whether the vehicle wants to change using the given laneOffset. This method gets th...
void informFollower(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, double > &neighFollow, double remainingSeconds, double plannedSpeed)
decide whether we will try cut in before the follower or allow to be overtaken
long long int myKeepRightProbability
double computeSpeedLat(double latDist, double &maneuverDist, bool urgent) const override
decides the next lateral speed (for continuous lane changing)
double myOvertakeDeltaSpeedFactor
double myLookAheadSpeed
bool debugVehicle() const override
whether the current vehicles shall be debugged
double myStrategicParam
long long int mySpeedGainProbabilityRight
double myRoundaboutBonus
double mySpeedGainLookahead
const double myExperimentalParam1
double patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel) override
Called to adapt the speed in order to allow a lane change. It uses information on LC-related desired ...
void initDerivedParameters()
init cached parameters derived directly from model parameters
double myCooperativeParam
MSLCM_LC2013(MSVehicle &v)
double anticipateFollowSpeed(const std::pair< MSVehicle *, double > &leaderDist, double dist, double vMax, bool acceleratingLeader)
anticipate future follow speed for the given leader
std::string getParameter(const std::string &key) const override
try to retrieve the given parameter from this device. Throw exception for unsupported key
void setParameter(const std::string &key, const std::string &value) override
try to set the given parameter for this laneChangeModel. Throw exception for unsupported key
bool hasFreeLane(int laneOffset, const std::pair< MSVehicle *, double > &neighLeadStopped) const
whether there is a lane beyond laneOffset that can be used to overtake the stopped leader on the neig...
double myCooperativeSpeed
long long int myKeepRightProbThreshold
double informLeader(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, double > &neighLead, double remainingSeconds)
double _patchSpeed(double min, const double wanted, double max, const MSCFModel &cfModel)
double mySpeedGainParam
double myLookaheadLeft
double myLeadingBlockerLength
int _wantsChange(int laneOffset, MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, const std::pair< MSVehicle *, double > &leader, const std::pair< MSVehicle *, double > &follower, const std::pair< MSVehicle *, double > &neighLead, const std::pair< MSVehicle *, double > &neighFollow, const MSLane &neighLane, const std::vector< MSVehicle::LaneQ > &preb, MSVehicle *lastBlocked, MSVehicle *firstBlocked)
helper function for doing the actual work
std::pair< double, int > Info
information regarding save velocity (unused) and state flags of the ego vehicle
double getSafetyFactor() const override
return factor for modifying the safety constraints of the car-following model
double myLeftSpace
double myOppositeParam
bool amBlockingFollowerPlusNB()
double myKeepRightParam
bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist)
void adaptSpeedToPedestrians(const MSLane *lane, double &v)
react to pedestrians on the given lane
virtual void saveState(OutputDevice &out) const override
Save the state of the laneChangeModel.
virtual ~MSLCM_LC2013()
long long int myChangeProbThresholdRight
double getOppositeSafetyFactor() const override
return factor for modifying the safety constraints for opposite-diretction overtaking of the car-foll...
long long int mySpeedGainProbabilityLeft
a value for tracking the probability that a change to that side is beneficial
void resetState() override
double mySpeedGainRight
double myKeepRightAcceptanceTime
double mySpeedGainUrgency
int slowDownForBlocked(MSVehicle *blocked, int state)
compute useful slowdowns for blocked vehicles
bool saveBlockerLength(double length, double foeLeftSpace) override
reserve space at the end of the lane to avoid dead locks
void changed() override
double mySpeedGainRemainTime
void * inform(void *info, MSVehicle *sender) override
long long int myChangeProbThresholdLeft
virtual void loadState(const SUMOSAXAttributes &attrs) override
Loads the state of the laneChangeModel from the given attributes.
void prepareStep(SumoRNG *rng) override
rng belongs to the lane that moves the vehicle (not the lane it just entered)
static double overtakeDistance(const MSVehicle *follower, const MSVehicle *leader, const double gap, double followerSpeed=INVALID_SPEED, double leaderSpeed=INVALID_SPEED)
Representation of a lane in the micro simulation.
Definition MSLane.h:84
std::pair< const MSPerson *, double > nextBlocking(double minPos, double minRight, double maxLeft, double stopTime=0, bool bidi=false) const
This is just a wrapper around MSPModel::nextBlocking. You should always check using hasPedestrians be...
Definition MSLane.cpp:4677
MSLane * getParallelLane(int offset, bool includeOpposite=true) const
Returns the lane with the given offset parallel to this one or 0 if it does not exist.
Definition MSLane.cpp:2905
bool isAccelLane() const
return whether this lane is an acceleration lane
Definition MSLane.h:544
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
Definition MSLane.h:602
double getLength() const
Returns the lane's length.
Definition MSLane.h:632
bool allowsChangingLeft(SUMOVehicleClass vclass) const
Returns whether the given vehicle class may change left from this lane.
Definition MSLane.h:966
bool allowsVehicleClass(SUMOVehicleClass vclass) const
Definition MSLane.h:959
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
Definition MSLane.h:575
bool hasPedestrians() const
whether the lane has pedestrians on it
Definition MSLane.cpp:4670
int getIndex() const
Returns the lane's index.
Definition MSLane.h:668
double getBruttoOccupancy() const
Returns the brutto (including minGaps) occupancy of this lane during the last step.
Definition MSLane.cpp:3451
bool isNormal() const
Definition MSLane.cpp:2675
std::pair< MSVehicle *const, double > getLeader(const MSVehicle *veh, const double vehPos, const std::vector< MSLane * > &bestLaneConts, double dist=-1, bool checkTmpVehicles=false) const
Returns the immediate leader of veh and the distance to veh starting on this lane.
Definition MSLane.cpp:2974
MSLane * getBidiLane() const
retrieve bidirectional lane or nullptr
Definition MSLane.cpp:4782
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:790
const MSLane * getNormalPredecessorLane() const
get normal lane leading to this internal lane, for normal lanes, the lane itself is returned
Definition MSLane.cpp:3296
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
Definition MSLane.h:750
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:201
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:335
const MSLane * lane
The lane to stop at (microsim only)
Definition MSStop.h:50
double changeRequestRemainingSeconds(const SUMOTime currentTime) const
Return the remaining number of seconds of the current laneTimeLine assuming one exists.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
MSAbstractLaneChangeModel & getLaneChangeModel()
double getActionStepLengthSecs() const
Returns the vehicle's action step length in secs, i.e. the interval between two action points.
Definition MSVehicle.h:533
int influenceChangeDecision(int state)
allow TraCI to influence a lane change decision
double getMaxSpeedOnLane() const
Returns the maximal speed for the vehicle on its current lane (including speed factor and deviation,...
double nextStopDist() const
return the distance to the next stop or doubleMax if there is none.
Definition MSVehicle.h:1042
double getAcceleration() const
Returns the vehicle's acceleration in m/s (this is computed as the last step's mean acceleration in c...
Definition MSVehicle.h:514
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the best sequence of lanes to continue the route starting at myLane.
int getBestLaneOffset() const
const MSEdge * getCurrentEdge() const
Returns the edge the vehicle is currently at (possibly an internal edge or nullptr)
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition MSVehicle.h:581
double getLastStepDist() const
Get the distance the vehicle covered in the previous timestep.
Definition MSVehicle.h:381
Influencer & getInfluencer()
double getRightSideOnLane() const
Get the lateral position of the vehicles right side on the lane:
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
Definition MSVehicle.h:413
double getSpeed() const
Returns the vehicle's current speed.
Definition MSVehicle.h:490
const std::vector< LaneQ > & getBestLanes() const
Returns the description of best lanes to use in order to continue the route.
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
Definition MSVehicle.h:973
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition MSVehicle.h:374
double getLateralOverlap() const
return the amount by which the vehicle extends laterally outside it's primary lane
void setLateralPositionOnLane(double posLat)
Definition MSVehicle.h:417
double getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
double getMinGap() const
Get the free space in front of vehicles of this class.
double getMaxSpeedLat() const
Get vehicle's maximum lateral speed [m/s].
double getLength() const
Get vehicle's length [m].
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
Definition Named.h:66
const std::string & getID() const
Returns the id.
Definition Named.h:73
void step(double dt, SumoRNG *rng)
evolve for a time step of length dt.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
Encapsulated SAX-Attributes.
virtual std::string getString(int id, bool *isPresent=nullptr) const =0
Returns the string-value of the named (by its enum-value) attribute.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
#define UNUSED_PARAMETER(x)
#define DEBUG_COND
A structure representing the best lanes for continuing the current route starting at 'lane'.
Definition MSVehicle.h:861
double length
The overall length which may be driven when using this lane without a lane change.
Definition MSVehicle.h:865
std::vector< MSLane * > bestContinuations
Definition MSVehicle.h:881
MSLane * lane
The described lane.
Definition MSVehicle.h:863
int bestLaneOffset
The (signed) number of lanes to be crossed to get to the lane which allows to continue the drive.
Definition MSVehicle.h:873
double occupation
The overall vehicle sum on consecutive lanes which can be passed without a lane change.
Definition MSVehicle.h:869