SUMO - Simulation of Urban MObility
MSLCM_LC2013.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // A lane change model developed by D. Krajzewicz, J. Erdmann et al. between 2004 and 2013
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <iostream>
37 #include <microsim/MSEdge.h>
38 #include <microsim/MSLane.h>
39 #include <microsim/MSNet.h>
40 #include "MSLCM_LC2013.h"
41 
42 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 //#define DEBUG_VEHICLE_GUI_SELECTION 1
47 #ifdef DEBUG_VEHICLE_GUI_SELECTION
49 #include <guisim/GUIVehicle.h>
50 #include <guisim/GUILane.h>
51 #endif
52 
53 
54 
55 // ===========================================================================
56 // variable definitions
57 // ===========================================================================
58 // 80km/h will be the threshold for dividing between long/short foresight
59 #define LOOK_FORWARD_SPEED_DIVIDER (SUMOReal)14.
60 
61 #define LOOK_FORWARD_RIGHT (SUMOReal)10.
62 #define LOOK_FORWARD_LEFT (SUMOReal)20.
63 
64 #define JAM_FACTOR (SUMOReal)1.
65 
66 #define LCA_RIGHT_IMPATIENCE (SUMOReal)-1.
67 #define CUT_IN_LEFT_SPEED_THRESHOLD (SUMOReal)27.
68 
69 #define LOOK_AHEAD_MIN_SPEED (SUMOReal)0.0
70 #define LOOK_AHEAD_SPEED_MEMORY (SUMOReal)0.9
71 #define LOOK_AHEAD_SPEED_DECREMENT 6.
72 
73 #define HELP_DECEL_FACTOR (SUMOReal)1.0
74 
75 #define HELP_OVERTAKE (SUMOReal)(10.0 / 3.6)
76 #define MIN_FALLBEHIND (SUMOReal)(14.0 / 3.6)
77 
78 #define URGENCY (SUMOReal)2.0
79 
80 #define ROUNDABOUT_DIST_BONUS (SUMOReal)80.0
81 
82 #define CHANGE_PROB_THRESHOLD_RIGHT (SUMOReal)2.0
83 #define CHANGE_PROB_THRESHOLD_LEFT (SUMOReal)0.2
84 #define KEEP_RIGHT_TIME (SUMOReal)5.0 // the number of seconds after which a vehicle should move to the right lane
85 #define KEEP_RIGHT_ACCEPTANCE (SUMOReal)2.0 // calibration factor for determining the desire to keep right
86 
87 #define RELGAIN_NORMALIZATION_MIN_SPEED (SUMOReal)10.0
88 
89 // ===========================================================================
90 // member method definitions
91 // ===========================================================================
94  mySpeedGainProbability(0),
95  myKeepRightProbability(0),
96  myLeadingBlockerLength(0),
97  myLeftSpace(0),
98  myLookAheadSpeed(LOOK_AHEAD_MIN_SPEED)
99 {}
100 
102  changed(0);
103 }
104 
105 
106 int
108  int laneOffset,
110  int blocked,
111  const std::pair<MSVehicle*, SUMOReal>& leader,
112  const std::pair<MSVehicle*, SUMOReal>& neighLead,
113  const std::pair<MSVehicle*, SUMOReal>& neighFollow,
114  const MSLane& neighLane,
115  const std::vector<MSVehicle::LaneQ>& preb,
116  MSVehicle** lastBlocked,
117  MSVehicle** firstBlocked) {
118  const int result = _wantsChange(laneOffset, msgPass, blocked, leader, neighLead, neighFollow, neighLane, preb, lastBlocked, firstBlocked);
119  return result;
120 }
121 
122 
123 SUMOReal
124 MSLCM_LC2013::patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max, const MSCFModel& cfModel) {
125  const SUMOReal newSpeed = _patchSpeed(min, wanted, max, cfModel);
126  return newSpeed;
127 }
128 
129 
130 SUMOReal
131 MSLCM_LC2013::_patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max, const MSCFModel& cfModel) {
132  int state = myOwnState;
133 
134  // letting vehicles merge in at the end of the lane in case of counter-lane change, step#2
135  SUMOReal MAGIC_offset = 1.;
136  // if we want to change and have a blocking leader and there is enough room for him in front of us
137  if (myLeadingBlockerLength != 0) {
139  if (space > 0) {
140  // compute speed for decelerating towards a place which allows the blocking leader to merge in in front
141  SUMOReal safe = cfModel.stopSpeed(&myVehicle, myVehicle.getSpeed(), space);
142  // if we are approaching this place
143  if (safe < wanted) {
144  // return this speed as the speed to use
145  return MAX2(min, safe);
146  }
147  }
148  }
149 
150  SUMOReal nVSafe = wanted;
151  bool gotOne = false;
152  for (std::vector<SUMOReal>::const_iterator i = myVSafes.begin(); i != myVSafes.end(); ++i) {
153  SUMOReal v = (*i);
154  if (v >= min && v <= max) {
155  nVSafe = MIN2(v, nVSafe);
156  gotOne = true;
157  } else {
158  }
159  }
160 
161  if (gotOne && !myDontBrake) {
162  return nVSafe;
163  }
164 
165  // check whether the vehicle is blocked
166  if ((state & LCA_WANTS_LANECHANGE) != 0 && (state & LCA_BLOCKED) != 0) {
167  if ((state & LCA_STRATEGIC) != 0) {
168  // necessary decelerations are controlled via vSafe. If there are
169  // none it means we should speed up
170  return (max + wanted) / (SUMOReal) 2.0;
171  } else if ((state & LCA_COOPERATIVE) != 0) {
172  // only minor adjustments in speed should be done
173  if ((state & LCA_BLOCKED_BY_LEADER) != 0) {
174  return (min + wanted) / (SUMOReal) 2.0;
175  }
176  if ((state & LCA_BLOCKED_BY_FOLLOWER) != 0) {
177  return (max + wanted) / (SUMOReal) 2.0;
178  }
179  }
180  }
181 
182  // accelerate if being a blocking leader or blocking follower not able to brake
183  // (and does not have to change lanes)
184  if ((state & LCA_AMBLOCKINGLEADER) != 0) {
185  return (max + wanted) / (SUMOReal) 2.0;
186  }
187 
188  if ((state & LCA_AMBLOCKINGFOLLOWER_DONTBRAKE) != 0) {
189  }
190  if (myVehicle.getLane()->getEdge().getLanes().size() == 1) {
191  // remove chaning information if on a road with a single lane
192  changed(0);
193  }
194  return wanted;
195 }
196 
197 
198 void*
199 MSLCM_LC2013::inform(void* info, MSVehicle* /* sender */) {
200  Info* pinfo = (Info*) info;
201  myVSafes.push_back(pinfo->first);
202  myOwnState |= pinfo->second;
203  delete pinfo;
204  return (void*) true;
205 }
206 
207 
208 SUMOReal
210  int blocked,
211  int dir,
212  const std::pair<MSVehicle*, SUMOReal>& neighLead,
213  SUMOReal remainingSeconds) {
214  SUMOReal plannedSpeed = MIN2(myVehicle.getSpeed(),
216  for (std::vector<SUMOReal>::const_iterator i = myVSafes.begin(); i != myVSafes.end(); ++i) {
217  SUMOReal v = (*i);
219  plannedSpeed = MIN2(plannedSpeed, v);
220  }
221  }
222  if ((blocked & LCA_BLOCKED_BY_LEADER) != 0) {
223  assert(neighLead.first != 0);
224  MSVehicle* nv = neighLead.first;
225  // decide whether we want to overtake the leader or follow it
226  const SUMOReal dv = plannedSpeed - nv->getSpeed();
227  const SUMOReal overtakeDist = (neighLead.second // drive to back of follower
228  + nv->getVehicleType().getLengthWithGap() // drive to front of follower
229  + myVehicle.getVehicleType().getLength() // ego back reaches follower front
230  + nv->getCarFollowModel().getSecureGap( // save gap to follower
232 
233  if (dv < 0
234  // overtaking on the right on an uncongested highway is forbidden (noOvertakeLCLeft)
236  // not enough space to overtake?
237  || myLeftSpace < overtakeDist
238  // not enough time to overtake?
239  || dv * remainingSeconds < overtakeDist) {
240  // cannot overtake
241  msgPass.informNeighLeader(new Info(-1, dir | LCA_AMBLOCKINGLEADER), &myVehicle);
242  // slow down smoothly to follow leader
243  const SUMOReal targetSpeed = myCarFollowModel.followSpeed(
244  &myVehicle, myVehicle.getSpeed(), neighLead.second, nv->getSpeed(), nv->getCarFollowModel().getMaxDecel());
245  if (targetSpeed < myVehicle.getSpeed()) {
246  // slow down smoothly to follow leader
248  MAX2(MIN_FALLBEHIND, (myVehicle.getSpeed() - targetSpeed) / remainingSeconds)));
249  const SUMOReal nextSpeed = MIN2(plannedSpeed, myVehicle.getSpeed() - decel);
250  myVSafes.push_back(nextSpeed);
251  return nextSpeed;
252  } else {
253  // leader is fast enough anyway
254  myVSafes.push_back(targetSpeed);
255  return plannedSpeed;
256  }
257  } else {
258  // overtaking, leader should not accelerate
259  msgPass.informNeighLeader(new Info(nv->getSpeed(), dir | LCA_AMBLOCKINGLEADER), &myVehicle);
260  return -1;
261  }
262  } else if (neighLead.first != 0) { // (remainUnblocked)
263  // we are not blocked now. make sure we stay far enough from the leader
264  MSVehicle* nv = neighLead.first;
265  const SUMOReal nextNVSpeed = nv->getSpeed() - HELP_OVERTAKE; // conservative
266  const SUMOReal dv = SPEED2DIST(myVehicle.getSpeed() - nextNVSpeed);
267  const SUMOReal targetSpeed = myCarFollowModel.followSpeed(
268  &myVehicle, myVehicle.getSpeed(), neighLead.second - dv, nextNVSpeed, nv->getCarFollowModel().getMaxDecel());
269  myVSafes.push_back(targetSpeed);
270  return MIN2(targetSpeed, plannedSpeed);
271  } else {
272  // not overtaking
273  return plannedSpeed;
274  }
275 }
276 
277 
278 void
280  int blocked,
281  int dir,
282  const std::pair<MSVehicle*, SUMOReal>& neighFollow,
283  SUMOReal remainingSeconds,
284  SUMOReal plannedSpeed) {
285  if ((blocked & LCA_BLOCKED_BY_FOLLOWER) != 0) {
286  assert(neighFollow.first != 0);
287  MSVehicle* nv = neighFollow.first;
288 
289  // are we fast enough to cut in without any help?
290  if (plannedSpeed - nv->getSpeed() >= HELP_OVERTAKE) {
291  const SUMOReal neededGap = nv->getCarFollowModel().getSecureGap(nv->getSpeed(), plannedSpeed, myVehicle.getCarFollowModel().getMaxDecel());
292  if ((neededGap - neighFollow.second) / remainingSeconds < (plannedSpeed - nv->getSpeed())) {
293  // follower might even accelerate but not to much
294  msgPass.informNeighFollower(new Info(plannedSpeed - HELP_OVERTAKE, dir | LCA_AMBLOCKINGFOLLOWER), &myVehicle);
295  return;
296  }
297  }
298  // decide whether we will request help to cut in before the follower or allow to be overtaken
299 
300  // PARAMETERS
301  // assume other vehicle will assume the equivalent of 1 second of
302  // maximum deceleration to help us (will probably be spread over
303  // multiple seconds)
304  // -----------
305  const SUMOReal helpDecel = nv->getCarFollowModel().getMaxDecel() * HELP_DECEL_FACTOR ;
306 
307  // change in the gap between ego and blocker over 1 second (not STEP!)
308  const SUMOReal neighNewSpeed = MAX2((SUMOReal)0, nv->getSpeed() - ACCEL2SPEED(helpDecel));
309  const SUMOReal neighNewSpeed1s = MAX2((SUMOReal)0, nv->getSpeed() - helpDecel);
310  const SUMOReal dv = plannedSpeed - neighNewSpeed1s;
311  // new gap between follower and self in case the follower does brake for 1s
312  const SUMOReal decelGap = neighFollow.second + dv;
313  const SUMOReal secureGap = nv->getCarFollowModel().getSecureGap(neighNewSpeed1s, plannedSpeed, myVehicle.getCarFollowModel().getMaxDecel());
314  if (decelGap > 0 && decelGap >= secureGap) {
315  // if the blocking neighbor brakes it could actually help
316  // how hard does it actually need to be?
317  const SUMOReal vsafe = MAX2(neighNewSpeed, nv->getCarFollowModel().followSpeed(
318  nv, nv->getSpeed(), neighFollow.second, plannedSpeed, myVehicle.getCarFollowModel().getMaxDecel()));
319  msgPass.informNeighFollower(new Info(vsafe, dir | LCA_AMBLOCKINGFOLLOWER), &myVehicle);
320  } else if (dv > 0 && dv * remainingSeconds > (secureGap - decelGap + POSITION_EPS)) {
321  // decelerating once is sufficient to open up a large enough gap in time
322  msgPass.informNeighFollower(new Info(neighNewSpeed, dir | LCA_AMBLOCKINGFOLLOWER), &myVehicle);
323  } else {
325  //if (dir == LCA_MRIGHT && myVehicle.getWaitingSeconds() > LCA_RIGHT_IMPATIENCE &&
326  // nv->getSpeed() > myVehicle.getSpeed()) {
327  if (nv->getSpeed() > myVehicle.getSpeed() &&
329  || (dir == LCA_MLEFT && plannedSpeed > CUT_IN_LEFT_SPEED_THRESHOLD) // VARIANT_22 (slowDownLeft)
330  )) {
331  // let the follower slow down to increase the likelyhood that later vehicles will be slow enough to help
332  // follower should still be fast enough to open a gap
333  vhelp = MAX2(neighNewSpeed, myVehicle.getSpeed() + HELP_OVERTAKE);
334  if ((nv->getSpeed() - myVehicle.getSpeed()) / helpDecel < remainingSeconds) {
335  msgPass.informNeighFollower(new Info(vhelp, dir | LCA_AMBLOCKINGFOLLOWER), &myVehicle);
336  return;
337  }
338  }
339  msgPass.informNeighFollower(new Info(vhelp, dir | LCA_AMBLOCKINGFOLLOWER), &myVehicle);
340  // this follower is supposed to overtake us. slow down smoothly to allow this
341  const SUMOReal overtakeDist = (neighFollow.second // follower reaches ego back
342  + myVehicle.getVehicleType().getLengthWithGap() // follower reaches ego front
343  + nv->getVehicleType().getLength() // follower back at ego front
344  + myVehicle.getCarFollowModel().getSecureGap( // follower has safe dist to ego
345  plannedSpeed, vhelp, nv->getCarFollowModel().getMaxDecel()));
346  // speed difference to create a sufficiently large gap
347  const SUMOReal needDV = overtakeDist / remainingSeconds;
348  // make sure the deceleration is not to strong
349  myVSafes.push_back(MAX2(vhelp - needDV, myVehicle.getSpeed() - ACCEL2SPEED(myVehicle.getCarFollowModel().getMaxDecel())));
350  }
351  }
352 }
353 
354 
355 void
357  // keep information about strategic change direction
360  myLeftSpace = 0;
361  myVSafes.clear();
362  myDontBrake = false;
363  // truncate to work around numerical instability between different builds
364  mySpeedGainProbability = ceil(mySpeedGainProbability * 100000.0) * 0.00001;
365  myKeepRightProbability = ceil(myKeepRightProbability * 100000.0) * 0.00001;
366 }
367 
368 
369 void
371  myOwnState = 0;
374  if (myVehicle.getBestLaneOffset() == 0) {
375  // if we are not yet on our best lane there might still be unseen blockers
376  // (during patchSpeed)
378  myLeftSpace = 0;
379  }
381  myVSafes.clear();
382  myDontBrake = false;
384 }
385 
386 
387 int
389  int laneOffset,
391  int blocked,
392  const std::pair<MSVehicle*, SUMOReal>& leader,
393  const std::pair<MSVehicle*, SUMOReal>& neighLead,
394  const std::pair<MSVehicle*, SUMOReal>& neighFollow,
395  const MSLane& neighLane,
396  const std::vector<MSVehicle::LaneQ>& preb,
397  MSVehicle** lastBlocked,
398  MSVehicle** firstBlocked) {
399  assert(laneOffset == 1 || laneOffset == -1);
400  const SUMOTime currentTime = MSNet::getInstance()->getCurrentTimeStep();
401  // compute bestLaneOffset
402  MSVehicle::LaneQ curr, neigh, best;
403  int bestLaneOffset = 0;
404  SUMOReal currentDist = 0;
405  SUMOReal neighDist = 0;
406  int currIdx = 0;
407  MSLane* prebLane = myVehicle.getLane();
408  if (prebLane->getEdge().getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL) {
409  // internal edges are not kept inside the bestLanes structure
410  prebLane = prebLane->getLinkCont()[0]->getLane();
411  }
412  for (int p = 0; p < (int) preb.size(); ++p) {
413  if (preb[p].lane == prebLane && p + laneOffset >= 0) {
414  assert(p + laneOffset < (int)preb.size());
415  curr = preb[p];
416  neigh = preb[p + laneOffset];
417  currentDist = curr.length;
418  neighDist = neigh.length;
419  bestLaneOffset = curr.bestLaneOffset;
420  if (bestLaneOffset == 0 && preb[p + laneOffset].bestLaneOffset == 0) {
421  bestLaneOffset = laneOffset;
422  }
423  best = preb[p + bestLaneOffset];
424  currIdx = p;
425  break;
426  }
427  }
428  // direction specific constants
429  const bool right = (laneOffset == -1);
430  const int lca = (right ? LCA_RIGHT : LCA_LEFT);
431  const int myLca = (right ? LCA_MRIGHT : LCA_MLEFT);
432  const int lcaCounter = (right ? LCA_LEFT : LCA_RIGHT);
433  const bool changeToBest = (right && bestLaneOffset < 0) || (!right && bestLaneOffset > 0);
434  // keep information about being a leader/follower
435  int ret = (myOwnState & 0xffff0000);
436  int req = 0; // the request to change or stay
437 
438  ret = slowDownForBlocked(lastBlocked, ret);
439  if (lastBlocked != firstBlocked) {
440  ret = slowDownForBlocked(firstBlocked, ret);
441  }
442 
443 
444  // we try to estimate the distance which is necessary to get on a lane
445  // we have to get on in order to keep our route
446  // we assume we need something that depends on our velocity
447  // and compare this with the free space on our wished lane
448  //
449  // if the free space is somehow less than the space we need, we should
450  // definitely try to get to the desired lane
451  //
452  // this rule forces our vehicle to change the lane if a lane changing is necessary soon
453  // lookAheadDistance:
454  // we do not want the lookahead distance to change all the time so we discrectize the speed a bit
455 
458  } else {
461  }
463  laDist += myVehicle.getVehicleType().getLengthWithGap() * (SUMOReal) 2.;
464  // free space that is available for changing
465  //const SUMOReal neighSpeed = (neighLead.first != 0 ? neighLead.first->getSpeed() :
466  // neighFollow.first != 0 ? neighFollow.first->getSpeed() :
467  // best.lane->getSpeedLimit());
468  // @note: while this lets vehicles change earlier into the correct direction
469  // it also makes the vehicles more "selfish" and prevents changes which are necessary to help others
470 
471  int roundaboutEdgesAhead = 0;
472  for (std::vector<MSLane*>::iterator it = curr.bestContinuations.begin(); it != curr.bestContinuations.end(); ++it) {
473  if ((*it) != 0 && (*it)->getEdge().isRoundabout()) {
474  roundaboutEdgesAhead += 1;
475  } else if (roundaboutEdgesAhead > 0) {
476  // only check the next roundabout
477  break;
478  }
479  }
480  int roundaboutEdgesAheadNeigh = 0;
481  for (std::vector<MSLane*>::iterator it = neigh.bestContinuations.begin(); it != neigh.bestContinuations.end(); ++it) {
482  if ((*it) != 0 && (*it)->getEdge().isRoundabout()) {
483  roundaboutEdgesAheadNeigh += 1;
484  } else if (roundaboutEdgesAheadNeigh > 0) {
485  // only check the next roundabout
486  break;
487  }
488  }
489  if (roundaboutEdgesAhead > 1) {
490  currentDist += roundaboutEdgesAhead * ROUNDABOUT_DIST_BONUS;
491  neighDist += roundaboutEdgesAheadNeigh * ROUNDABOUT_DIST_BONUS;
492  }
493 
494  const SUMOReal usableDist = (currentDist - myVehicle.getPositionOnLane() - best.occupation * JAM_FACTOR);
495  const SUMOReal maxJam = MAX2(preb[currIdx + laneOffset].occupation, preb[currIdx].occupation);
496  const SUMOReal neighLeftPlace = MAX2((SUMOReal) 0, neighDist - myVehicle.getPositionOnLane() - maxJam);
497 
498  if (changeToBest && bestLaneOffset == curr.bestLaneOffset
499  && currentDistDisallows(usableDist, bestLaneOffset, laDist)) {
501  ret = ret | lca | LCA_STRATEGIC | LCA_URGENT;
502  } else {
503 
504  if (!myAllowOvertakingRight && !right && !myVehicle.congested() && neighLead.first != 0) {
505  // check for slower leader on the left. we should not overtake but
506  // rather move left ourselves (unless congested)
507  MSVehicle* nv = neighLead.first;
508  if (nv->getSpeed() < myVehicle.getSpeed()) {
509  const SUMOReal vSafe = myCarFollowModel.followSpeed(
510  &myVehicle, myVehicle.getSpeed(), neighLead.second, nv->getSpeed(), nv->getCarFollowModel().getMaxDecel());
511  myVSafes.push_back(vSafe);
512  if (vSafe < myVehicle.getSpeed()) {
514  }
515  }
516  }
517 
518  if (!changeToBest && (currentDistDisallows(neighLeftPlace, abs(bestLaneOffset) + 2, laDist))) {
519  // the opposite lane-changing direction should be done than the one examined herein
520  // we'll check whether we assume we could change anyhow and get back in time...
521  //
522  // this rule prevents the vehicle from moving in opposite direction of the best lane
523  // unless the way till the end where the vehicle has to be on the best lane
524  // is long enough
525  ret = ret | LCA_STAY | LCA_STRATEGIC;
526  } else if (bestLaneOffset == 0 && (neighLeftPlace * 2. < laDist)) {
527  // the current lane is the best and a lane-changing would cause a situation
528  // of which we assume we will not be able to return to the lane we have to be on.
529  // this rule prevents the vehicle from leaving the current, best lane when it is
530  // close to this lane's end
531  ret = ret | LCA_STAY | LCA_STRATEGIC;
532  }
533  }
534  // check for overriding TraCI requests
536  if ((ret & lcaCounter) != 0) {
537  // we are not interested in traci requests for the opposite direction here
538  ret &= ~(LCA_TRACI | lcaCounter | LCA_URGENT);
539  }
540 
541  if ((ret & LCA_STAY) != 0) {
542  return ret;
543  }
544  if ((ret & LCA_URGENT) != 0) {
545  // prepare urgent lane change maneuver
546  // save the left space
547  myLeftSpace = currentDist - myVehicle.getPositionOnLane();
548  if (changeToBest && abs(bestLaneOffset) > 1) {
549  // there might be a vehicle which needs to counter-lane-change one lane further and we cannot see it yet
550  myLeadingBlockerLength = MAX2((SUMOReal)(right ? 20.0 : 40.0), myLeadingBlockerLength);
551  }
552 
553  // letting vehicles merge in at the end of the lane in case of counter-lane change, step#1
554  // if there is a leader and he wants to change to the opposite direction
555  saveBlockerLength(neighLead.first, lcaCounter);
556  if (*firstBlocked != neighLead.first) {
557  saveBlockerLength(*firstBlocked, lcaCounter);
558  }
559 
560  const SUMOReal remainingSeconds = ((ret & LCA_TRACI) == 0 ?
563  const SUMOReal plannedSpeed = informLeader(msgPass, blocked, myLca, neighLead, remainingSeconds);
564  if (plannedSpeed >= 0) {
565  // maybe we need to deal with a blocking follower
566  informFollower(msgPass, blocked, myLca, neighFollow, remainingSeconds, plannedSpeed);
567  }
568 
569  return ret;
570  }
571 
572  if (roundaboutEdgesAhead > 1) {
573  // try to use the inner lanes of a roundabout to increase throughput
574  // unless we are approaching the exit
575  if (lca == LCA_LEFT) {
576  req = ret | lca | LCA_COOPERATIVE;
577  } else {
578  req = ret | LCA_STAY | LCA_COOPERATIVE;
579  }
580  if (!cancelRequest(req)) {
581  return ret | req;
582  }
583  }
584 
585  // let's also regard the case where the vehicle is driving on a highway...
586  // in this case, we do not want to get to the dead-end of an on-ramp
587  if (right) {
588  if (bestLaneOffset == 0 && myVehicle.getLane()->getSpeedLimit() > 80. / 3.6 && myLookAheadSpeed > SUMO_const_haltingSpeed) {
589  req = ret | LCA_STAY | LCA_STRATEGIC;
590  if (!cancelRequest(req)) {
591  return ret | req;
592  }
593  }
594  }
595  // --------
596 
597  // -------- make place on current lane if blocking follower
598  //if (amBlockingFollowerPlusNB()) {
599  // std::cout << myVehicle.getID() << ", " << currentDistAllows(neighDist, bestLaneOffset, laDist)
600  // << " neighDist=" << neighDist
601  // << " currentDist=" << currentDist
602  // << "\n";
603  //}
605  && (changeToBest || currentDistAllows(neighDist, abs(bestLaneOffset) + 1, laDist))) {
606 
607  req = ret | lca | LCA_COOPERATIVE | LCA_URGENT ;//| LCA_CHANGE_TO_HELP;
608  if (!cancelRequest(req)) {
609  return ret | req;
610  }
611  }
612 
613  // --------
614 
615 
618  //if ((blocked & LCA_BLOCKED) != 0) {
619  // return ret;
620  //}
622 
623  // -------- higher speed
624  //if ((congested(neighLead.first) && neighLead.second < 20) || predInteraction(leader.first)) { //!!!
625  // return ret;
626  //}
628  SUMOReal neighLaneVSafe = neighLane.getVehicleMaxSpeed(&myVehicle);
629  if (neighLead.first == 0) {
630  neighLaneVSafe = MIN2(neighLaneVSafe, myCarFollowModel.followSpeed(&myVehicle, myVehicle.getSpeed(), neighDist, 0, 0));
631  } else {
632  // @todo: what if leader is below safe gap?!!!
633  neighLaneVSafe = MIN2(neighLaneVSafe, myCarFollowModel.followSpeed(
634  &myVehicle, myVehicle.getSpeed(), neighLead.second, neighLead.first->getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel()));
635  }
636  if (leader.first == 0) {
637  thisLaneVSafe = MIN2(thisLaneVSafe, myCarFollowModel.followSpeed(&myVehicle, myVehicle.getSpeed(), currentDist, 0, 0));
638  } else {
639  // @todo: what if leader is below safe gap?!!!
640  thisLaneVSafe = MIN2(thisLaneVSafe, myCarFollowModel.followSpeed(&myVehicle, myVehicle.getSpeed(), leader.second, leader.first->getSpeed(), leader.first->getCarFollowModel().getMaxDecel()));
641  }
642 
644  thisLaneVSafe = MIN2(thisLaneVSafe, vMax);
645  neighLaneVSafe = MIN2(neighLaneVSafe, vMax);
646  const SUMOReal relativeGain = (neighLaneVSafe - thisLaneVSafe) / MAX2(neighLaneVSafe,
648 
649  if (right) {
650  // ONLY FOR CHANGING TO THE RIGHT
651  if (thisLaneVSafe - 5 / 3.6 > neighLaneVSafe) {
652  // ok, the current lane is faster than the right one...
653  if (mySpeedGainProbability < 0) {
654  mySpeedGainProbability /= 2.0;
655  //myKeepRightProbability /= 2.0;
656  }
657  } else {
658  // ok, the current lane is not faster than the right one
659  mySpeedGainProbability -= relativeGain;
660 
661  // honor the obligation to keep right (Rechtsfahrgebot)
662  // XXX consider fast approaching followers on the current lane
663  //const SUMOReal vMax = myLookAheadSpeed;
664  const SUMOReal acceptanceTime = KEEP_RIGHT_ACCEPTANCE * vMax * MAX2((SUMOReal)1, myVehicle.getSpeed()) / myVehicle.getLane()->getSpeedLimit();
665  SUMOReal fullSpeedGap = MAX2((SUMOReal)0, neighDist - myVehicle.getCarFollowModel().brakeGap(vMax));
666  SUMOReal fullSpeedDrivingSeconds = MIN2(acceptanceTime, fullSpeedGap / vMax);
667  if (neighLead.first != 0 && neighLead.first->getSpeed() < vMax) {
668  fullSpeedGap = MAX2((SUMOReal)0, MIN2(fullSpeedGap,
669  neighLead.second - myVehicle.getCarFollowModel().getSecureGap(
670  vMax, neighLead.first->getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel())));
671  fullSpeedDrivingSeconds = MIN2(fullSpeedDrivingSeconds, fullSpeedGap / (vMax - neighLead.first->getSpeed()));
672  }
673  const SUMOReal deltaProb = (CHANGE_PROB_THRESHOLD_RIGHT
675  * (fullSpeedDrivingSeconds / acceptanceTime) / KEEP_RIGHT_TIME);
676  myKeepRightProbability -= deltaProb;
677 
678  if (gDebugFlag2) {
679  std::cout << STEPS2TIME(currentTime)
680  << " veh=" << myVehicle.getID()
681  << " vMax=" << vMax
682  << " neighDist=" << neighDist
683  << " brakeGap=" << myVehicle.getCarFollowModel().brakeGap(myVehicle.getSpeed())
684  << " leaderSpeed=" << (neighLead.first == 0 ? -1 : neighLead.first->getSpeed())
685  << " secGap=" << (neighLead.first == 0 ? -1 : myVehicle.getCarFollowModel().getSecureGap(
686  myVehicle.getSpeed(), neighLead.first->getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel()))
687  << " acceptanceTime=" << acceptanceTime
688  << " fullSpeedGap=" << fullSpeedGap
689  << " fullSpeedDrivingSeconds=" << fullSpeedDrivingSeconds
690  << " dProb=" << deltaProb
691  << "\n";
692  }
694  req = ret | lca | LCA_KEEPRIGHT;
695  if (!cancelRequest(req)) {
696  return ret | req;
697  }
698  }
699  }
700 
702  && neighDist / MAX2((SUMOReal) .1, myVehicle.getSpeed()) > 20.) { //./MAX2((SUMOReal) .1, myVehicle.getSpeed())) { // -.1
703  req = ret | lca | LCA_SPEEDGAIN;
704  if (!cancelRequest(req)) {
705  return ret | req;
706  }
707  }
708  } else {
709  // ONLY FOR CHANGING TO THE LEFT
710  if (thisLaneVSafe > neighLaneVSafe) {
711  // this lane is better
712  if (mySpeedGainProbability > 0) {
713  mySpeedGainProbability /= 2.0;
714  }
715  } else {
716  // left lane is better
717  mySpeedGainProbability += relativeGain;
718  }
719  if (mySpeedGainProbability > CHANGE_PROB_THRESHOLD_LEFT && neighDist / MAX2((SUMOReal) .1, myVehicle.getSpeed()) > 20.) { // .1
720  req = ret | lca | LCA_SPEEDGAIN;
721  if (!cancelRequest(req)) {
722  return ret | req;
723  }
724  }
725  }
726  // --------
727  if (changeToBest && bestLaneOffset == curr.bestLaneOffset
728  && (right ? mySpeedGainProbability < 0 : mySpeedGainProbability > 0)) {
729  // change towards the correct lane, speedwise it does not hurt
730  req = ret | lca | LCA_STRATEGIC;
731  if (!cancelRequest(req)) {
732  return ret | req;
733  }
734  }
735 
736  return ret;
737 }
738 
739 
740 int
742  // if this vehicle is blocking someone in front, we maybe decelerate to let him in
743  if ((*blocked) != 0) {
744  SUMOReal gap = (*blocked)->getPositionOnLane() - (*blocked)->getVehicleType().getLength() - myVehicle.getPositionOnLane() - myVehicle.getVehicleType().getMinGap();
745  if (gap > POSITION_EPS) {
747  if ((*blocked)->getSpeed() < SUMO_const_haltingSpeed) {
749  } else {
750  state |= LCA_AMBACKBLOCKER;
751  }
754  (SUMOReal)(gap - POSITION_EPS), (*blocked)->getSpeed(),
755  (*blocked)->getCarFollowModel().getMaxDecel()));
756  }
757  }
758  }
759  return state;
760 }
761 
762 
763 void
764 MSLCM_LC2013::saveBlockerLength(MSVehicle* blocker, int lcaCounter) {
765  if (blocker != 0 && (blocker->getLaneChangeModel().getOwnState() & lcaCounter) != 0) {
766  // is there enough space in front of us for the blocker?
769  if (blocker->getVehicleType().getLengthWithGap() <= potential) {
770  // save at least his length in myLeadingBlockerLength
772  } else {
773  // we cannot save enough space for the blocker. It needs to save
774  // space for ego instead
776  }
777  }
778 }
779 /****************************************************************************/
780 
void changed(int dir)
void saveBlockerLength(MSVehicle *blocker, int lcaCounter)
save space for vehicles which need to counter-lane-change
#define CHANGE_PROB_THRESHOLD_RIGHT
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:455
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
SUMOReal getMaxSpeed() const
Get vehicle's maximum speed [m/s].
MSLCM_LC2013(MSVehicle &v)
#define SPEED2DIST(x)
Definition: SUMOTime.h:55
int wantsChange(int laneOffset, MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, const std::pair< MSVehicle *, SUMOReal > &leader, const std::pair< MSVehicle *, SUMOReal > &neighLead, const std::pair< MSVehicle *, SUMOReal > &neighFollow, const MSLane &neighLane, const std::vector< MSVehicle::LaneQ > &preb, MSVehicle **lastBlocked, MSVehicle **firstBlocked)
Called to examine whether the vehicle wants to change using the given laneOffset. This method gets th...
void prepareStep()
#define min(a, b)
Definition: polyfonts.c:66
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
Definition: MSVehicle.h:540
#define MIN_FALLBEHIND
SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max, const MSCFModel &cfModel)
Called to adapt the speed in order to allow a lane change.
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:61
#define LOOK_FORWARD_RIGHT
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:186
The action is done to help someone else.
SUMOReal getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
int bestLaneOffset
The (signed) number of lanes to be crossed to get to the lane which allows to continue the drive...
Definition: MSVehicle.h:466
bool congested() const
Definition: MSVehicle.h:393
virtual SUMOReal followSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const =0
Computes the vehicle's follow speed (no dawdling)
#define KEEP_RIGHT_ACCEPTANCE
The car-following model abstraction.
Definition: MSCFModel.h:59
SUMOReal myKeepRightProbability
Definition: MSLCM_LC2013.h:181
void * informNeighFollower(void *info, MSVehicle *sender)
Informs the follower on the desired lane.
SUMOReal getLength() const
Get vehicle's length [m].
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
T MAX2(T a, T b)
Definition: StdDefs.h:74
SUMOReal getSecureGap(const SUMOReal speed, const SUMOReal leaderSpeed, const SUMOReal leaderMaxDecel) const
Returns the minimum gap to reserve if the leader is braking at maximum.
Definition: MSCFModel.h:270
SUMOReal getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:286
std::vector< SUMOReal > myVSafes
Definition: MSLCM_LC2013.h:190
#define TS
Definition: SUMOTime.h:52
The action is due to a TraCI request.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:235
SUMOReal length
The overall length which may be driven when using this lane without a lane change.
Definition: MSVehicle.h:460
The action is urgent (to be defined by lc-model)
#define abs(a)
Definition: polyfonts.c:67
void informFollower(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, SUMOReal > &neighFollow, SUMOReal remainingSeconds, SUMOReal plannedSpeed)
decide whether we will try cut in before the follower or allow to be overtaken
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:1884
#define ROUNDABOUT_DIST_BONUS
static bool myAllowOvertakingRight
whether overtaking on the right is permitted
A class responsible for exchanging messages between cars involved in lane-change interaction.
Wants go to the left.
bool currentDistDisallows(SUMOReal dist, int laneOffset, SUMOReal lookForwardDist)
Definition: MSLCM_LC2013.h:163
bool currentDistAllows(SUMOReal dist, int laneOffset, SUMOReal lookForwardDist)
Definition: MSLCM_LC2013.h:166
#define max(a, b)
Definition: polyfonts.c:65
bool cancelRequest(int state)
whether the influencer cancels the given request
SUMOReal brakeGap(const SUMOReal speed) const
Returns the distance the vehicle needs to halt including driver's reaction time.
Definition: MSCFModel.h:232
SUMOReal myLeadingBlockerLength
Definition: MSLCM_LC2013.h:183
SUMOReal getMinGap() const
Get the free space in front of vehicles of this class.
#define CUT_IN_LEFT_SPEED_THRESHOLD
SUMOReal myLookAheadSpeed
Definition: MSLCM_LC2013.h:188
#define LOOK_AHEAD_SPEED_MEMORY
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
int slowDownForBlocked(MSVehicle **blocked, int state)
compute useful slowdowns for blocked vehicles
T MIN2(T a, T b)
Definition: StdDefs.h:68
#define CHANGE_PROB_THRESHOLD_LEFT
#define RELGAIN_NORMALIZATION_MIN_SPEED
virtual SUMOReal stopSpeed(const MSVehicle *const veh, const SUMOReal speed, SUMOReal gap2pred) const =0
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling) ...
#define POSITION_EPS
Definition: config.h:189
SUMOReal getSpeedLimit() const
Returns the lane's maximum allowed speed.
Definition: MSLane.h:362
A structure representing the best lanes for continuing the route.
Definition: MSVehicle.h:456
SUMOReal getMaxDecel() const
Get the vehicle type's maximum deceleration [m/s^2].
Definition: MSCFModel.h:184
SUMOReal changeRequestRemainingSeconds(const SUMOTime currentTime) const
Return the remaining number of seconds of the current laneTimeLine assuming one exists.
Definition: MSVehicle.cpp:301
int myOwnState
The current state of the vehicle.
SUMOReal informLeader(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, SUMOReal > &neighLead, SUMOReal remainingSeconds)
Wants go to the right.
virtual void saveBlockerLength(SUMOReal length)
reserve space at the end of the lane to avoid dead locks
std::pair< SUMOReal, int > Info
information regarding save velocity (unused) and state flags of the ego vehicle
Definition: MSLCM_LC2013.h:171
int _wantsChange(int laneOffset, MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, const std::pair< MSVehicle *, SUMOReal > &leader, const std::pair< MSVehicle *, SUMOReal > &neighLead, const std::pair< MSVehicle *, SUMOReal > &neighFollow, const MSLane &neighLane, const std::vector< MSVehicle::LaneQ > &preb, MSVehicle **lastBlocked, MSVehicle **firstBlocked)
helper function for doing the actual work
MSVehicle & myVehicle
The vehicle this lane-changer belongs to.
void * informNeighLeader(void *info, MSVehicle *sender)
Informs the leader on the desired lane.
The action is needed to follow the route (navigational lc)
EdgeBasicFunction getPurpose() const
Returns the edge type (EdgeBasicFunction)
Definition: MSEdge.h:235
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition: MSVehicle.cpp:2510
#define JAM_FACTOR
SUMOReal occupation
The overall vehicle sum on consecutive lanes which can be passed without a lane change.
Definition: MSVehicle.h:462
std::vector< MSLane * > bestContinuations
Consecutive lane that can be followed without a lane change (contribute to length and occupation) ...
Definition: MSVehicle.h:470
The action is due to the default of keeping right "Rechtsfahrgebot".
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:90
#define URGENCY
const SUMOReal SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
Definition: StdDefs.h:54
Needs to stay on the current lane.
virtual ~MSLCM_LC2013()
SUMOReal getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:294
int SUMOTime
Definition: SUMOTime.h:43
SUMOReal getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:370
#define LOOK_FORWARD_LEFT
SUMOReal mySpeedGainProbability
a value for tracking the probability that a change to the offset with the same sign is beneficial ...
Definition: MSLCM_LC2013.h:177
SUMOReal myLeftSpace
Definition: MSLCM_LC2013.h:184
bool gDebugFlag2
Definition: StdDefs.cpp:100
#define SUMOReal
Definition: config.h:218
#define NUMERICAL_EPS
Definition: config.h:162
bool amBlockingFollowerPlusNB()
Definition: MSLCM_LC2013.h:160
#define HELP_OVERTAKE
#define DELTA_T
Definition: SUMOTime.h:50
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:1026
SUMOReal _patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max, const MSCFModel &cfModel)
#define LOOK_AHEAD_MIN_SPEED
#define LCA_RIGHT_IMPATIENCE
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
Definition: MSLane.h:354
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:331
int influenceChangeDecision(int state)
allow TraCI to influence a lane change decision
Definition: MSVehicle.cpp:2528
The edge is an internal edge.
Definition: MSEdge.h:98
void * inform(void *info, MSVehicle *sender)
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
const MSCFModel & myCarFollowModel
The vehicle's car following model.
Interface for lane-change models.
int getBestLaneOffset() const
returns the current offset from the best lane
Definition: MSVehicle.cpp:2196
#define HELP_DECEL_FACTOR
const std::string & getID() const
Returns the name of the vehicle.
The action is due to the wish to be faster (tactical lc)
#define KEEP_RIGHT_TIME