SUMO - Simulation of Urban MObility
MSAbstractLaneChangeModel.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
20 // Interface for lane-change models
21 /****************************************************************************/
22 
23 // ===========================================================================
24 // DEBUG
25 // ===========================================================================
26 //#define DEBUG_TARGET_LANE
27 //#define DEBUG_SHADOWLANE
28 #define DEBUG_COND (myVehicle.isSelected())
29 
30 
31 // ===========================================================================
32 // included modules
33 // ===========================================================================
34 #include <config.h>
35 
38 #include <microsim/MSNet.h>
39 #include <microsim/MSEdge.h>
40 #include <microsim/MSLane.h>
41 #include <microsim/MSGlobals.h>
42 #include "MSLCM_DK2008.h"
43 #include "MSLCM_LC2013.h"
44 #include "MSLCM_SL2015.h"
45 
46 /* -------------------------------------------------------------------------
47  * static members
48  * ----------------------------------------------------------------------- */
53 const double MSAbstractLaneChangeModel::NO_NEIGHBOR(std::numeric_limits<double>::max());
54 
55 /* -------------------------------------------------------------------------
56  * MSAbstractLaneChangeModel-methods
57  * ----------------------------------------------------------------------- */
58 
59 void
61  myAllowOvertakingRight = oc.getBool("lanechange.overtake-right");
62  myLCOutput = oc.isSet("lanechange-output");
63  myLCStartedOutput = oc.getBool("lanechange-output.started");
64  myLCEndedOutput = oc.getBool("lanechange-output.ended");
65 }
66 
67 
70  if (MSGlobals::gLateralResolution > 0 && lcm != LCM_SL2015 && lcm != LCM_DEFAULT) {
71  throw ProcessError("Lane change model '" + toString(lcm) + "' is not compatible with sublane simulation");
72  }
73  switch (lcm) {
74  case LCM_DK2008:
75  return new MSLCM_DK2008(v);
76  case LCM_LC2013:
77  return new MSLCM_LC2013(v);
78  case LCM_SL2015:
79  return new MSLCM_SL2015(v);
80  case LCM_DEFAULT:
82  return new MSLCM_LC2013(v);
83  } else {
84  return new MSLCM_SL2015(v);
85  }
86  default:
87  throw ProcessError("Lane change model '" + toString(lcm) + "' not implemented");
88  }
89 }
90 
91 
93  myVehicle(v),
94  myOwnState(0),
95  myPreviousState(0),
97  mySpeedLat(0),
101  myManeuverDist(0.),
102  myAlreadyChanged(false),
103  myShadowLane(nullptr),
104  myTargetLane(nullptr),
105  myCarFollowModel(v.getCarFollowModel()),
106  myModel(model),
109  myLastLeaderGap(0.),
110  myLastFollowerGap(0.),
115  myDontResetLCGaps(false),
116  myMaxSpeedLatStanding(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_MAXSPEEDLATSTANDING, v.getVehicleType().getMaxSpeedLat())),
117  myMaxSpeedLatFactor(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_MAXSPEEDLATFACTOR, 1)),
119  myAmOpposite(false) {
120 }
121 
122 
124 }
125 
126 void
129  myOwnState = state;
130  myPreviousState = state; // myOwnState is modified in prepareStep so we make a backup
131 }
132 
133 void
134 MSAbstractLaneChangeModel::updateSafeLatDist(const double travelledLatDist) {
135  UNUSED_PARAMETER(travelledLatDist);
136 }
137 
138 
139 void
141 #ifdef DEBUG_MANEUVER
142  if DEBUG_COND {
143  std::cout << SIMTIME
144  << " veh=" << myVehicle.getID()
145  << " setManeuverDist() old=" << myManeuverDist << " new=" << dist
146  << std::endl;
147  }
148 #endif
149  myManeuverDist = dist;
150 }
151 
152 
153 double
155  return myManeuverDist;
156 }
157 
158 
159 bool
161  if (neighLeader == 0) {
162  return false;
163  }
164  // Congested situation are relevant only on highways (maxSpeed > 70km/h)
165  // and congested on German Highways means that the vehicles have speeds
166  // below 60km/h. Overtaking on the right is allowed then.
167  if ((myVehicle.getLane()->getSpeedLimit() <= 70.0 / 3.6) || (neighLeader->getLane()->getSpeedLimit() <= 70.0 / 3.6)) {
168 
169  return false;
170  }
171  if (myVehicle.congested() && neighLeader->congested()) {
172  return true;
173  }
174  return false;
175 }
176 
177 
178 
179 bool
180 MSAbstractLaneChangeModel::predInteraction(const std::pair<MSVehicle*, double>& leader) {
181  if (leader.first == 0) {
182  return false;
183  }
184  // let's check it on highways only
185  if (leader.first->getSpeed() < (80.0 / 3.6)) {
186  return false;
187  }
188  return leader.second < myCarFollowModel.interactionGap(&myVehicle, leader.first->getSpeed());
189 }
190 
191 
192 bool
194  if (&source->getEdge() != &target->getEdge()) {
196  }
199  myLaneChangeDirection = direction;
200  setManeuverDist(target->getCenterOnEdge() - source->getCenterOnEdge());
203  if (myLCOutput) {
205  }
206  return true;
207  } else {
208  primaryLaneChanged(source, target, direction);
209  return false;
210  }
211 }
212 
213 void
215  myDontResetLCGaps = true;
216 }
217 
218 void
220  myDontResetLCGaps = false;
221 }
222 
223 void
225  initLastLaneChangeOffset(direction);
227  source->leftByLaneChange(&myVehicle);
229  target->enteredByLaneChange(&myVehicle);
230  laneChangeOutput("change", source, target, direction);
231  // Assure that the drive items are up to date (even if the following step is no actionstep for the vehicle).
232  // This is necessary because the lane advance uses the target lane from the corresponding drive item.
234  changed();
235 }
236 
237 void
238 MSAbstractLaneChangeModel::laneChangeOutput(const std::string& tag, MSLane* source, MSLane* target, int direction) {
239  if (myLCOutput) {
240  OutputDevice& of = OutputDevice::getDeviceByOption("lanechange-output");
241  of.openTag(tag);
244  of.writeAttr(SUMO_ATTR_TIME, time2string(MSNet::getInstance()->getCurrentTimeStep()));
245  of.writeAttr(SUMO_ATTR_FROM, source->getID());
246  of.writeAttr(SUMO_ATTR_TO, target->getID());
247  of.writeAttr(SUMO_ATTR_DIR, direction);
251  of.writeAttr("leaderGap", myLastLeaderGap == NO_NEIGHBOR ? "None" : toString(myLastLeaderGap));
252  of.writeAttr("leaderSecureGap", myLastLeaderSecureGap == NO_NEIGHBOR ? "None" : toString(myLastLeaderSecureGap));
253  of.writeAttr("followerGap", myLastFollowerGap == NO_NEIGHBOR ? "None" : toString(myLastFollowerGap));
254  of.writeAttr("followerSecureGap", myLastFollowerSecureGap == NO_NEIGHBOR ? "None" : toString(myLastFollowerSecureGap));
255  of.writeAttr("origLeaderGap", myLastOrigLeaderGap == NO_NEIGHBOR ? "None" : toString(myLastOrigLeaderGap));
256  of.writeAttr("origLeaderSecureGap", myLastOrigLeaderSecureGap == NO_NEIGHBOR ? "None" : toString(myLastOrigLeaderSecureGap));
258  const double latGap = direction < 0 ? myLastLateralGapRight : myLastLateralGapLeft;
259  of.writeAttr("latGap", latGap == NO_NEIGHBOR ? "None" : toString(latGap));
260  }
261  of.closeTag();
264  }
265  }
266 }
267 
268 
269 double
270 MSAbstractLaneChangeModel::computeSpeedLat(double /*latDist*/, double& maneuverDist) {
272  int stepsToChange = (int)ceil(maneuverDist / SPEED2DIST(myVehicle.getVehicleType().getMaxSpeedLat()));
273  return DIST2SPEED(maneuverDist / stepsToChange);
274  } else {
275  return maneuverDist / STEPS2TIME(MSGlobals::gLaneChangeDuration);
276  }
277 }
278 
279 
280 double
282  throw ProcessError("Method getAssumedDecelForLaneChangeDuration() not implemented by model " + toString(myModel));
283 }
284 
285 
286 bool
288  const bool pastBefore = pastMidpoint();
289  // maneuverDist is not updated in the context of continuous lane changing but represents the full LC distance
290  double maneuverDist = getManeuverDist();
291  mySpeedLat = computeSpeedLat(0, maneuverDist);
293  return !pastBefore && pastMidpoint();
294 }
295 
296 
297 void
299  UNUSED_PARAMETER(reason);
306  if (myAmOpposite) {
308  }
309 }
310 
311 
312 MSLane*
313 MSAbstractLaneChangeModel::getShadowLane(const MSLane* lane, double posLat) const {
315  // initialize shadow lane
316  const double overlap = myVehicle.getLateralOverlap(posLat);
317 #ifdef DEBUG_SHADOWLANE
318  if (debugVehicle()) {
319  std::cout << SIMTIME << " veh=" << myVehicle.getID() << " posLat=" << posLat << " overlap=" << overlap << "\n";
320  }
321 #endif
322  if (overlap > NUMERICAL_EPS) {
323  const int shadowDirection = posLat < 0 ? -1 : 1;
324  return lane->getParallelLane(shadowDirection);
325  } else if (isChangingLanes() && myLaneChangeCompletion < 0.5) {
326  // "reserve" target lane even when there is no overlap yet
328  } else {
329  return 0;
330  }
331  } else {
332  return 0;
333  }
334 }
335 
336 
337 MSLane*
340 }
341 
342 
343 void
345  if (myShadowLane != 0) {
346  if (debugVehicle()) {
347  std::cout << SIMTIME << " cleanupShadowLane\n";
348  }
350  myShadowLane = 0;
351  }
352  for (std::vector<MSLane*>::const_iterator it = myShadowFurtherLanes.begin(); it != myShadowFurtherLanes.end(); ++it) {
353  if (debugVehicle()) {
354  std::cout << SIMTIME << " cleanupShadowLane2\n";
355  }
356  (*it)->resetPartialOccupation(&myVehicle);
357  }
358  myShadowFurtherLanes.clear();
360 }
361 
362 void
364  if (myTargetLane != 0) {
365  if (debugVehicle()) {
366  std::cout << SIMTIME << " cleanupTargetLane\n";
367  }
369  myTargetLane = 0;
370  }
371  for (std::vector<MSLane*>::const_iterator it = myFurtherTargetLanes.begin(); it != myFurtherTargetLanes.end(); ++it) {
372  if (debugVehicle()) {
373  std::cout << SIMTIME << " cleanupTargetLane\n";
374  }
375  if (*it != nullptr) {
376  (*it)->resetManeuverReservation(&myVehicle);
377  }
378  }
379  myFurtherTargetLanes.clear();
380 // myNoPartiallyOccupatedByShadow.clear();
381 }
382 
383 
384 bool
385 MSAbstractLaneChangeModel::cancelRequest(int state, int laneOffset) {
386  // store request before canceling
387  myCanceledStates[laneOffset] |= state;
388  int ret = myVehicle.influenceChangeDecision(state);
389  return ret != state;
390 }
391 
392 
393 void
395  if (dir > 0) {
397  } else if (dir < 0) {
399  }
400 }
401 
402 void
404  if (!haveLateralDynamics()) {
405  // assume each vehicle drives at the center of its lane and act as if it fits
406  return;
407  }
408  if (myShadowLane != 0) {
409 #ifdef DEBUG_SHADOWLANE
410  if (debugVehicle()) {
411  std::cout << SIMTIME << " updateShadowLane()\n";
412  }
413 #endif
415  }
417  std::vector<MSLane*> passed;
418  if (myShadowLane != 0) {
420  const std::vector<MSLane*>& further = myVehicle.getFurtherLanes();
421  const std::vector<double>& furtherPosLat = myVehicle.getFurtherLanesPosLat();
422  assert(further.size() == furtherPosLat.size());
423  passed.push_back(myShadowLane);
424  for (int i = 0; i < (int)further.size(); ++i) {
425  MSLane* shadowFurther = getShadowLane(further[i], furtherPosLat[i]);
426 #ifdef DEBUG_SHADOWLANE
427  if (debugVehicle()) {
428  std::cout << SIMTIME << " further=" << further[i]->getID() << " (posLat=" << furtherPosLat[i] << ") shadowFurther=" << Named::getIDSecure(shadowFurther) << "\n";
429  }
430 #endif
431  if (shadowFurther != 0 && MSLinkContHelper::getConnectingLink(*shadowFurther, *passed.back()) != 0) {
432  passed.push_back(shadowFurther);
433  }
434  }
435  std::reverse(passed.begin(), passed.end());
436  } else {
438  WRITE_WARNING("Vehicle '" + myVehicle.getID() + "' could not finish continuous lane change (lane disappeared) time=" +
439  time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
441  }
442  }
443 #ifdef DEBUG_SHADOWLANE
444  if (debugVehicle()) {
445  std::cout << SIMTIME << " updateShadowLane() veh=" << myVehicle.getID()
446  << " newShadowLane=" << Named::getIDSecure(myShadowLane)
447  << "\n before:" << " myShadowFurtherLanes=" << toString(myShadowFurtherLanes) << " further=" << toString(myVehicle.getFurtherLanes()) << " passed=" << toString(passed);
448  std::cout << std::endl;
449  }
450 #endif
452 #ifdef DEBUG_SHADOWLANE
453  if (debugVehicle()) std::cout
454  << "\n after:" << " myShadowFurtherLanes=" << toString(myShadowFurtherLanes) << "\n";
455 #endif
456 }
457 
458 
459 int
461  if (isChangingLanes()) {
462  if (pastMidpoint()) {
463  return -myLaneChangeDirection;
464  } else {
465  return myLaneChangeDirection;
466  }
467  } else if (myShadowLane == 0) {
468  return 0;
469  } else {
470  assert(&myShadowLane->getEdge() == &myVehicle.getLane()->getEdge());
472  }
473 }
474 
475 
476 void
478 #ifdef DEBUG_TARGET_LANE
479  MSLane* oldTarget = myTargetLane;
480  std::vector<MSLane*> oldFurtherTargets = myFurtherTargetLanes;
481  if (debugVehicle()) {
482  std::cout << SIMTIME << " veh '" << myVehicle.getID() << "' (lane=" << myVehicle.getLane()->getID() << ") updateTargetLane()"
483  << "\n oldTarget: " << (oldTarget == nullptr ? "NULL" : oldTarget->getID())
484  << " oldFurtherTargets: " << toString(oldFurtherTargets);
485  }
486 #endif
487  if (myTargetLane != nullptr) {
489  }
490  // Clear old further target lanes
491  for (MSLane* oldTargetLane : myFurtherTargetLanes) {
492  if (oldTargetLane != nullptr) {
493  oldTargetLane->resetManeuverReservation(&myVehicle);
494  }
495  }
496  myFurtherTargetLanes.clear();
497 
498  // Get new target lanes and issue a maneuver reservation.
499  int targetDir;
500  myTargetLane = determineTargetLane(targetDir);
501  if (myTargetLane != nullptr) {
503  // further targets are just the target lanes corresponding to the vehicle's further lanes
504  // @note In a neglectable amount of situations we might add a reservation for a shadow further lane.
505  for (MSLane* furtherLane : myVehicle.getFurtherLanes()) {
506  MSLane* furtherTargetLane = furtherLane->getParallelLane(targetDir);
507  myFurtherTargetLanes.push_back(furtherTargetLane);
508  if (furtherTargetLane != nullptr) {
509  furtherTargetLane->setManeuverReservation(&myVehicle);
510  }
511  }
512  }
513 #ifdef DEBUG_TARGET_LANE
514  if (debugVehicle()) {
515  std::cout << "\n newTarget (offset=" << targetDir << "): " << (myTargetLane == nullptr ? "NULL" : myTargetLane->getID())
516  << " newFurtherTargets: " << toString(myFurtherTargetLanes)
517  << std::endl;
518  }
519 #endif
520 }
521 
522 
523 MSLane*
525  targetDir = 0;
526  if (myManeuverDist == 0) {
527  return nullptr;
528  }
529  // Current lateral boundaries of the vehicle
530  const double vehRight = myVehicle.getLateralPositionOnLane() - 0.5 * myVehicle.getWidth();
531  const double vehLeft = myVehicle.getLateralPositionOnLane() + 0.5 * myVehicle.getWidth();
532  const double halfLaneWidth = 0.5 * myVehicle.getLane()->getWidth();
533 
534  if (vehRight + myManeuverDist < -halfLaneWidth) {
535  // Vehicle intends to traverse the right lane boundary
536  targetDir = -1;
537  } else if (vehLeft + myManeuverDist > halfLaneWidth) {
538  // Vehicle intends to traverse the left lane boundary
539  targetDir = 1;
540  }
541  if (targetDir == 0) {
542  // Presently, no maneuvering into another lane is begun.
543  return nullptr;
544  }
545  MSLane* target = myVehicle.getLane()->getParallelLane(targetDir);
546  if (target == nullptr || target == myShadowLane) {
547  return nullptr;
548  } else {
549  return target;
550  }
551 }
552 
553 
554 
555 double
558  return myLaneChangeDirection * angleOffset;
559 }
560 
561 
562 double
563 MSAbstractLaneChangeModel::estimateLCDuration(const double speed, const double remainingManeuverDist, const double decel) const {
564 
566  if (lcParams.find(SUMO_ATTR_LCA_MAXSPEEDLATSTANDING) == lcParams.end() && lcParams.find(SUMO_ATTR_LCA_MAXSPEEDLATFACTOR) == lcParams.end()) {
568  // no dependency of lateral speed on longitudinal speed. (Only called prior to LC initialization to determine whether it could be completed)
570  } else {
571  return remainingManeuverDist / myVehicle.getVehicleType().getMaxSpeedLat();
572  }
573  }
574 
575  if (remainingManeuverDist == 0) {
576  return 0;
577  }
578 
579  // Check argument assumptions
580  assert(speed >= 0);
581  assert(remainingManeuverDist >= 0);
582  assert(decel > 0);
583  assert(myVehicle.getVehicleType().getMaxSpeedLat() > 0);
585  assert(myMaxSpeedLatStanding >= 0);
586 
587  // for brevity
588  const double v0 = speed;
589  const double D = remainingManeuverDist;
590  const double b = decel;
591  const double wmin = myMaxSpeedLatStanding;
592  const double f = myMaxSpeedLatFactor;
593  const double wmax = myVehicle.getVehicleType().getMaxSpeedLat();
594 
595  /* Here's the approach for the calculation of the required time for the LC:
596  * To obtain the maximal LC-duration, for v(t) we assume that v(t)=max(0, v0-b*t),
597  * Where v(t)=0 <=> t >= ts:=v0/b
598  * For the lateral speed w(t) this gives:
599  * w(t) = min(wmax, wmin + f*v(t))
600  * The lateral distance covered until t is
601  * d(t) = int_0^t w(s) ds
602  * We distinguish three possibilities for the solution d(T)=D, where T is the time of the LC completion.
603  * 1) w(T) = wmax, i.e. v(T)>(wmax-wmin)/f
604  * 2) wmin < w(T) < wmax, i.e. (wmax-wmin)/f > v(T) > 0
605  * 3) w(T) = wmin, i.e., v(T)=0
606  */
607  const double vm = (wmax - wmin) / f;
608  double distSoFar = 0.;
609  double timeSoFar = 0.;
610  double v = v0;
611  if (v > vm) {
612  const double wmaxTime = (v0 - vm) / b;
613  const double d1 = wmax * wmaxTime;
614  if (d1 >= D) {
615  return D / wmax;
616  } else {
617  distSoFar += d1;
618  timeSoFar += wmaxTime;
619  v = vm;
620  }
621  }
622  if (v > 0) {
623  /* Here, w(t1+t) = wmin + f*v(t1+t) = wmin + f*(v - b*t)
624  * Thus, the additional lateral distance covered after time t is:
625  * d2 = (wmin + f*v)*t - 0.5*f*b*t^2
626  * and the additional lateral distance covered until v=0 at t=v/b is:
627  * d2 = (wmin + 0.5*f*v)*t
628  */
629  const double t = v / b; // stop time
630  const double d2 = (wmin + 0.5 * f * v) * t; // lateral distance covered until stop
631  assert(d2 > 0);
632  if (distSoFar + d2 >= D) {
633  // LC is completed during this phase
634  const double x = 0.5 * f * b;
635  const double y = wmin + f * v;
636  /* Solve D - distSoFar = y*t - x*t^2.
637  * 0 = x*t^2 - y*t/x + (D - distSoFar)/x
638  */
639  const double p = 0.5 * y / x;
640  const double q = (D - distSoFar) / x;
641  assert(p * p - q > 0);
642  const double t2 = p + sqrt(p * p - q);
643  return timeSoFar + t2;
644  } else {
645  distSoFar += d2;
646  timeSoFar += t;
647  //v = 0;
648  }
649  }
650  // If we didn't return yet this means the LC was not completed until the vehicle stops (if braking with rate b)
651  if (wmin == 0) {
652  // LC won't be completed if vehicle stands
653  return -1;
654  } else {
655  // complete LC with lateral speed wmin
656  return timeSoFar + (D - distSoFar) / wmin;
657  }
658 }
659 
660 SUMOTime
662  assert(isChangingLanes()); // Only to be called during ongoing lane change
664  if (lcParams.find(SUMO_ATTR_LCA_MAXSPEEDLATSTANDING) == lcParams.end() && lcParams.find(SUMO_ATTR_LCA_MAXSPEEDLATFACTOR) == lcParams.end()) {
667  } else {
669  }
670  }
671  // Using maxSpeedLat(Factor/Standing)
673 }
674 
675 
676 void
678  //std::cout << SIMTIME << " veh=" << myVehicle.getID() << " @=" << &myVehicle << " set shadow approaching=" << link->getViaLaneOrLane()->getID() << "\n";
679  myApproachedByShadow.push_back(link);
680 }
681 
682 void
684  for (std::vector<MSLink*>::iterator it = myApproachedByShadow.begin(); it != myApproachedByShadow.end(); ++it) {
685  //std::cout << SIMTIME << " veh=" << myVehicle.getID() << " @=" << &myVehicle << " remove shadow approaching=" << (*it)->getViaLaneOrLane()->getID() << "\n";
686  (*it)->removeApproaching(&myVehicle);
687  }
688  myApproachedByShadow.clear();
689 }
690 
691 
692 
693 void
696  int oldstate = myVehicle.getLaneChangeModel().getOwnState();
697  if (myOwnState != newstate) {
699  // Calculate and set the lateral maneuver distance corresponding to the change request
700  // to induce a corresponding sublane change.
701  const int dir = (newstate & LCA_RIGHT) != 0 ? -1 : ((newstate & LCA_LEFT) != 0 ? 1 : 0);
702  // minimum distance to move the vehicle fully onto the lane at offset dir
703  const double latLaneDist = myVehicle.lateralDistanceToLane(dir);
704  if ((newstate & LCA_TRACI) != 0) {
705  if ((newstate & LCA_STAY) != 0) {
706  setManeuverDist(0.);
707  } else if (((newstate & LCA_RIGHT) != 0 && dir < 0)
708  || ((newstate & LCA_LEFT) != 0 && dir > 0)) {
709  setManeuverDist(latLaneDist);
710  }
711  }
712  if (myVehicle.hasInfluencer()) {
713  // lane change requests override sublane change requests
715  }
716 
717  }
718  setOwnState(newstate);
719  } else {
720  // Check for sublane change requests
722  const double maneuverDist = myVehicle.getInfluencer().getLatDist();
725  newstate |= LCA_TRACI;
726  if (myOwnState != newstate) {
727  setOwnState(newstate);
728  }
729  if (gDebugFlag2) {
730  std::cout << " traci influenced maneuverDist=" << maneuverDist << "\n";
731  }
732  }
733  }
734  if (DEBUG_COND) {
735  std::cout << SIMTIME << " veh=" << myVehicle.getID() << " stateAfterTraCI=" << toString((LaneChangeAction)newstate) << " original=" << toString((LaneChangeAction)oldstate) << "\n";
736  }
737 }
738 
739 void
742  myAlreadyChanged = true;
743 }
744 
745 void
747  if (follower.first != 0) {
748  myLastFollowerGap = follower.second + follower.first->getVehicleType().getMinGap();
749  myLastFollowerSecureGap = secGap;
750  }
751 }
752 
753 void
755  if (leader.first != 0) {
756  myLastLeaderGap = leader.second + myVehicle.getVehicleType().getMinGap();
757  myLastLeaderSecureGap = secGap;
758  }
759 }
760 
761 void
763  if (leader.first != 0) {
765  myLastOrigLeaderSecureGap = secGap;
766  }
767 }
768 
769 void
771  int rightmost;
772  int leftmost;
773  vehicles.getSubLanes(&myVehicle, 0, rightmost, leftmost);
774  for (int i = rightmost; i <= leftmost; ++i) {
775  CLeaderDist vehDist = vehicles[i];
776  if (vehDist.first != 0) {
777  const MSVehicle* leader = &myVehicle;
778  const MSVehicle* follower = vehDist.first;
779  const double netGap = vehDist.second + follower->getVehicleType().getMinGap();
780  if (netGap < myLastFollowerGap && netGap >= 0) {
781  myLastFollowerGap = netGap;
782  myLastFollowerSecureGap = follower->getCarFollowModel().getSecureGap(follower->getSpeed(), leader->getSpeed(), leader->getCarFollowModel().getMaxDecel());
783  }
784  }
785  }
786 }
787 
788 void
790  int rightmost;
791  int leftmost;
792  vehicles.getSubLanes(&myVehicle, 0, rightmost, leftmost);
793  for (int i = rightmost; i <= leftmost; ++i) {
794  CLeaderDist vehDist = vehicles[i];
795  if (vehDist.first != 0) {
796  const MSVehicle* leader = vehDist.first;
797  const MSVehicle* follower = &myVehicle;
798  const double netGap = vehDist.second + follower->getVehicleType().getMinGap();
799  if (netGap < myLastLeaderGap && netGap >= 0) {
800  myLastLeaderGap = netGap;
801  myLastLeaderSecureGap = follower->getCarFollowModel().getSecureGap(follower->getSpeed(), leader->getSpeed(), leader->getCarFollowModel().getMaxDecel());
802  }
803  }
804  }
805 }
806 
807 void
809  int rightmost;
810  int leftmost;
811  vehicles.getSubLanes(&myVehicle, 0, rightmost, leftmost);
812  for (int i = rightmost; i <= leftmost; ++i) {
813  CLeaderDist vehDist = vehicles[i];
814  if (vehDist.first != 0) {
815  const MSVehicle* leader = vehDist.first;
816  const MSVehicle* follower = &myVehicle;
817  const double netGap = vehDist.second + follower->getVehicleType().getMinGap();
818  if (netGap < myLastOrigLeaderGap && netGap >= 0) {
819  myLastOrigLeaderGap = netGap;
821  }
822  }
823  }
824 }
bool myDontResetLCGaps
Flag to prevent resetting the memorized values for LC relevant gaps until the LC output is triggered ...
bool isChangingLanes() const
return true if the vehicle currently performs a lane change maneuver
static double gLateralResolution
Definition: MSGlobals.h:85
A lane change model developed by J. Erdmann.
Definition: MSLCM_SL2015.h:38
#define DIST2SPEED(x)
Definition: SUMOTime.h:50
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
const SubParams & getLCParams() const
Returns the LC parameter.
saves leader/follower vehicles and their distances relative to an ego vehicle
Definition: MSLeaderInfo.h:129
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:617
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
long long int SUMOTime
Definition: SUMOTime.h:36
#define SPEED2DIST(x)
Definition: SUMOTime.h:48
std::map< SumoXMLAttr, std::string > SubParams
sub-model parameters
int myPreviousState
lane changing state from the previous simulation step
virtual double getAssumedDecelForLaneChangeDuration() const
Returns a deceleration value which is used for the estimation of the duration of a lane change...
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:561
void setLeaderGaps(CLeaderDist, double secGap)
double myLastLeaderGap
the actual minimum longitudinal distances to vehicles on the target lane
int getShadowDirection() const
return the direction in which the current shadow lane lies
double getManeuverDist() const
Returns the remaining unblocked distance for the current maneuver. (only used by sublane model) ...
double myLaneChangeCompletion
progress of the lane change maneuver 0:started, 1:complete
static bool haveLateralDynamics()
whether any kind of lateral dynamics is active
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:399
Notification
Definition of a vehicle state.
virtual void resetManeuverReservation(MSVehicle *v)
Unregisters a vehicle, which previously registered for maneuvering into this lane.
Definition: MSLane.cpp:274
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
Wants go to the right.
static bool myLCOutput
whether to record lane-changing
double lateralDistanceToLane(const int offset) const
Get the minimal lateral distance required to move fully onto the lane at given offset.
Definition: MSVehicle.cpp:4756
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:160
double myLastOrigLeaderGap
acutal and secure distance to closest leader vehicle on the original when performing lane change ...
SUMOTime DELTA_T
Definition: SUMOTime.cpp:35
double getAngleOffset() const
return the angle offset during a continuous change maneuver
#define DEBUG_COND
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:62
virtual std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this laneChangeModel. Throw exception for unsupported key ...
void leftByLaneChange(MSVehicle *v)
Definition: MSLane.cpp:2472
MSLane * myShadowLane
A lane that is partially occupied by the front of the vehicle but that is not the primary lane...
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const std::string & getID() const
Returns the id.
Definition: Named.h:69
virtual bool predInteraction(const std::pair< MSVehicle *, double > &leader)
#define TIME2STEPS(x)
Definition: SUMOTime.h:60
virtual double setPartialOccupation(MSVehicle *v)
Sets the information about a vehicle lapping into this lane.
Definition: MSLane.cpp:231
const int VTYPEPARS_MAXSPEED_LAT_SET
Wants go to the left.
MSLane * myTargetLane
The target lane for the vehicle&#39;s current maneuver.
virtual void setManeuverReservation(MSVehicle *v)
Registers the lane change intentions (towards this lane) for the given vehicle.
Definition: MSLane.cpp:263
double getWidth() const
Returns the lane&#39;s width.
Definition: MSLane.h:523
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:33
SUMOTime remainingTime() const
Compute the remaining time until LC completion.
void enterLaneAtLaneChange(MSLane *enteredLane)
Update when the vehicle enters a new lane in the laneChange step.
Definition: MSVehicle.cpp:3867
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:242
void memorizeGapsAtLCInit()
Control for resetting the memorized values for LC relevant gaps until the LC output is triggered in t...
void checkTraCICommands()
Check for commands issued for the vehicle via TraCI and apply the appropriate state changes For the s...
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:4027
#define SIMTIME
Definition: SUMOTime.h:65
Right blinker lights are switched on.
Definition: MSVehicle.h:1173
bool wasSet(int what) const
Returns whether the given parameter was set.
Definition: MSVehicleType.h:83
std::vector< double > myShadowFurtherLanesPosLat
void setFollowerGaps(CLeaderDist follower, double secGap)
Needs to stay on the current lane.
const LaneChangeModel myModel
the type of this model
static bool myAllowOvertakingRight
whether overtaking on the right is permitted
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
LaneChangeModel
void leaveLane(const MSMoveReminder::Notification reason, const MSLane *approachedLane=0)
Update of members if vehicle leaves a new lane in the lane change step or at arrival.
Definition: MSVehicle.cpp:3977
The vehicle changes lanes (micro only)
virtual double estimateLCDuration(const double speed, const double remainingManeuverDist, const double decel) const
Calculates the maximal time needed to complete a lane change maneuver if lcMaxSpeedLatFactor and lcMa...
const MSCFModel & getCarFollowModel() const
Returns the vehicle&#39;s car following model definition.
Definition: MSVehicle.h:887
A lane change model developed by D. Krajzewicz, J. Erdmann et al. between 2004 and 2013...
Definition: MSLCM_LC2013.h:48
int getIndex() const
Returns the lane&#39;s index.
Definition: MSLane.h:530
Left blinker lights are switched on.
Definition: MSVehicle.h:1175
std::vector< MSLane * > myNoPartiallyOccupatedByShadow
double myManeuverDist
The complete lateral distance the vehicle wants to travel to finish its maneuver Only used by sublane...
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
virtual void resetPartialOccupation(MSVehicle *v)
Removes the information about a vehicle lapping into this lane.
Definition: MSLane.cpp:244
double getLateralOverlap() const
return the amount by which the vehicle extends laterally outside it&#39;s primary lane ...
Definition: MSVehicle.cpp:4806
double updateFurtherLanes(std::vector< MSLane *> &furtherLanes, std::vector< double > &furtherLanesPosLat, const std::vector< MSLane *> &passedLanes)
update a vector of further lanes and return the new backPos
Definition: MSVehicle.cpp:3374
double getCenterOnEdge() const
Definition: MSLane.h:989
void enteredByLaneChange(MSVehicle *v)
Definition: MSLane.cpp:2479
std::vector< MSLane * > myShadowFurtherLanes
const std::vector< MSLane * > & getFurtherLanes() const
Definition: MSVehicle.h:785
double getSpeedLimit() const
Returns the lane&#39;s maximum allowed speed.
Definition: MSLane.h:499
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
void getSubLanes(const MSVehicle *veh, double latOffset, int &rightmost, int &leftmost) const
virtual double interactionGap(const MSVehicle *const veh, double vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
Definition: MSCFModel.cpp:218
int myLaneChangeDirection
direction of the lane change maneuver -1 means right, 1 means left
bool hasInfluencer() const
Definition: MSVehicle.h:1572
bool pastMidpoint() const
return whether the vehicle passed the midpoint of a continuous lane change maneuver ...
double getMinGap() const
Get the free space in front of vehicles of this class.
virtual void changed()=0
static void initGlobalOptions(const OptionsCont &oc)
init global model parameters
double getMaxDecel() const
Get the vehicle type&#39;s maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:218
void fixPosition()
repair errors in vehicle position after changing between internal edges
Definition: MSVehicle.cpp:4426
void setShadowApproachingInformation(MSLink *link) const
set approach information for the shadow vehicle
double myLastLeaderSecureGap
the minimum longitudinal distances to vehicles on the target lane that would be necessary for stringe...
int myOwnState
The current state of the vehicle.
MSLane * determineTargetLane(int &targetDir) const
virtual bool debugVehicle() const
whether the current vehicles shall be debugged
bool cancelRequest(int state, int laneOffset)
whether the influencer cancels the given request
const SUMOVTypeParameter & getParameter() const
double getLateralPositionOnLane() const
Get the vehicle&#39;s lateral position on the lane.
Definition: MSVehicle.h:436
void setOrigLeaderGaps(CLeaderDist, double secGap)
bool startLaneChangeManeuver(MSLane *source, MSLane *target, int direction)
start the lane change maneuver and return whether it continues
const std::vector< double > & getFurtherLanesPosLat() const
Definition: MSVehicle.h:789
double getMaxSpeedLat() const
Get vehicle&#39;s maximum lateral speed [m/s].
void primaryLaneChanged(MSLane *source, MSLane *target, int direction)
called once when the vehicles primary lane changes
MSVehicle & myVehicle
The vehicle this lane-changer belongs to.
std::pair< const MSVehicle *, double > CLeaderDist
Definition: MSLeaderInfo.h:35
trigger: the time of the step
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition: MSVehicle.cpp:5196
LaneChangeAction
The state of a vehicle&#39;s lane-change behavior.
virtual void setOwnState(const int state)
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
A storage for options typed value containers)
Definition: OptionsCont.h:92
std::vector< MSLane * > myFurtherTargetLanes
double mySpeedLat
the current lateral speed
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
The abstract direction of a link.
A lane change model developed by D. Krajzewicz between 2004 and 2010.
Definition: MSLCM_DK2008.h:40
virtual double computeSpeedLat(double latDist, double &maneuverDist)
decides the next lateral speed depending on the remaining lane change distance to be covered and upda...
The action is due to a TraCI request.
bool gDebugFlag2
Definition: StdDefs.cpp:33
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void changedToOpposite()
called when a vehicle changes between lanes in opposite directions
void switchOffSignal(int signal)
Switches the given signal off.
Definition: MSVehicle.h:1234
void switchOnSignal(int signal)
Switches the given signal on.
Definition: MSVehicle.h:1226
double myCommittedSpeed
the speed when committing to a change maneuver
#define NUMERICAL_EPS
Definition: config.h:148
std::vector< MSLink * > myApproachedByShadow
links which are approached by the shadow vehicle
MSLane * getShadowLane() const
Returns the lane the vehicle&#39;s shadow is on during continuous/sublane lane change.
void setManeuverDist(const double dist)
Updates the remaining distance for the current maneuver while it is continued within non-action steps...
double getSecureGap(const double speed, const double leaderSpeed, const double leaderMaxDecel) const
Returns the minimum gap to reserve if the leader is braking at maximum (>=0)
Definition: MSCFModel.h:322
virtual void updateSafeLatDist(const double travelledLatDist)
Updates the value of safe lateral distances (in SL2015) during maneuver continuation in non-action st...
int myPreviousState2
lane changing state from step before the previous simulation step
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:479
int influenceChangeDecision(int state)
allow TraCI to influence a lane change decision
Definition: MSVehicle.cpp:5220
double myLastLateralGapLeft
the minimum lateral gaps to other vehicles that were found when last changing to the left and right ...
double getLatDist() const
Definition: MSVehicle.h:1488
static SUMOTime gLaneChangeDuration
Definition: MSGlobals.h:82
void laneChangeOutput(const std::string &tag, MSLane *source, MSLane *target, int direction)
called once the vehicle ends a lane change manoeuvre (non-instant)
static MSAbstractLaneChangeModel * build(LaneChangeModel lcm, MSVehicle &vehicle)
Factory method for instantiating new lane changing models.
const std::string & getID() const
Returns the name of the vehicle.
Representation of a lane in the micro simulation.
Definition: MSLane.h:71
bool myAlreadyChanged
whether the vehicle has already moved this step
const MSCFModel & myCarFollowModel
The vehicle&#39;s car following model.
bool myAmOpposite
whether the vehicle is driving in the opposite direction
MSAbstractLaneChangeModel(MSVehicle &v, const LaneChangeModel model)
Constructor.
Interface for lane-change models.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
double getWidth() const
Returns the vehicle&#39;s width.
MSLane * getParallelLane(int offset) const
Returns the lane with the given offset parallel to this one or 0 if it does not exist.
Definition: MSLane.cpp:2028
virtual bool congested(const MSVehicle *const neighLeader)
void endLaneChangeManeuver(const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_LANE_CHANGE)
void updateDriveItems()
Check whether the drive items (myLFLinkLanes) are up to date, and update them if required.
Definition: MSVehicle.cpp:2785
bool congested() const
Definition: MSVehicle.h:711
virtual ~MSAbstractLaneChangeModel()
Destructor.