Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSAbstractLaneChangeModel.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/****************************************************************************/
23// Interface for lane-change models
24/****************************************************************************/
25
26// ===========================================================================
27// DEBUG
28// ===========================================================================
29//#define DEBUG_TARGET_LANE
30//#define DEBUG_SHADOWLANE
31//#define DEBUG_OPPOSITE
32//#define DEBUG_MANEUVER
33#define DEBUG_COND (myVehicle.isSelected())
34
35#include <config.h>
36
40#include <microsim/MSNet.h>
41#include <microsim/MSEdge.h>
42#include <microsim/MSLane.h>
43#include <microsim/MSLink.h>
44#include <microsim/MSStop.h>
47#include <microsim/MSGlobals.h>
49#include "MSLCM_DK2008.h"
50#include "MSLCM_LC2013.h"
51#include "MSLCM_LC2013_CC.h"
52#include "MSLCM_SL2015.h"
54
55/* -------------------------------------------------------------------------
56 * static members
57 * ----------------------------------------------------------------------- */
63const double MSAbstractLaneChangeModel::NO_NEIGHBOR(std::numeric_limits<double>::max());
65
66#define LC_ASSUMED_DECEL 1.0 // the minimal constant deceleration assumed to estimate the duration of a continuous lane-change at its initiation.
67
68/* -------------------------------------------------------------------------
69 * MSAbstractLaneChangeModel-methods
70 * ----------------------------------------------------------------------- */
71
72void
74 myAllowOvertakingRight = oc.getBool("lanechange.overtake-right");
75 myLCOutput = oc.isSet("lanechange-output");
76 myLCStartedOutput = oc.getBool("lanechange-output.started");
77 myLCEndedOutput = oc.getBool("lanechange-output.ended");
78 myLCXYOutput = oc.getBool("lanechange-output.xy");
79}
80
81
85 throw ProcessError(TLF("Lane change model '%' is not compatible with sublane simulation", toString(lcm)));
86 }
87 switch (lcm) {
89 return new MSLCM_DK2008(v);
91 return new MSLCM_LC2013(v);
93 return new MSLCM_LC2013_CC(v);
95 return new MSLCM_SL2015(v);
98 return new MSLCM_LC2013(v);
99 } else {
100 return new MSLCM_SL2015(v);
101 }
102 default:
103 throw ProcessError(TLF("Lane change model '%' not implemented", toString(lcm)));
104 }
105}
106
107
109 myVehicle(v),
110 myOwnState(0),
111 myPreviousState(0),
112 myPreviousState2(0),
113 myCanceledStateRight(LCA_NONE),
114 myCanceledStateCenter(LCA_NONE),
115 myCanceledStateLeft(LCA_NONE),
116 mySpeedLat(0),
117 myAccelerationLat(0),
118 myAngleOffset(0),
119 myPreviousAngleOffset(0),
120 myCommittedSpeed(0),
121 myLaneChangeCompletion(1.0),
122 myLaneChangeDirection(0),
123 myAlreadyChanged(false),
124 myShadowLane(nullptr),
125 myTargetLane(nullptr),
126 myModel(model),
127 myLastLateralGapLeft(0.),
128 myLastLateralGapRight(0.),
129 myLastLeaderGap(0.),
130 myLastFollowerGap(0.),
131 myLastLeaderSecureGap(0.),
132 myLastFollowerSecureGap(0.),
133 myLastOrigLeaderGap(0.),
134 myLastOrigLeaderSecureGap(0.),
135 myLastLeaderSpeed(0),
136 myLastFollowerSpeed(0),
137 myLastOrigLeaderSpeed(0),
138 myDontResetLCGaps(false),
139 myStrategicLookahead(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_STRATEGIC_LOOKAHEAD, UNDEFINED_LOOKAHEAD)),
140 myMaxSpeedLatStanding(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_MAXSPEEDLATSTANDING, v.getVehicleType().getMaxSpeedLat())),
141 myMaxSpeedLatFactor(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_MAXSPEEDLATFACTOR, 1)),
142 myMaxDistLatStanding(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_MAXDISTLATSTANDING,
143 // prevent lateral sliding for cars but permit for two-wheelers due to better maneuverability
144 (v.getVClass() & (SVC_BICYCLE | SVC_MOTORCYCLE | SVC_MOPED)) != 0 ? std::numeric_limits<double>::max() : 1.6)),
145 mySigma(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_SIGMA, 0.0)),
146 myOvertakeRightParam(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_OVERTAKE_RIGHT, 0)),
147 myAssertive(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_ASSERTIVE, 1)),
148 myCooperativeHelpTime(TIME2STEPS(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_COOPERATIVE_HELPTIME, 60))),
149 myCooperativeHelpThreshold(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_COOPERATIVE_HELPTHRESHOLD, -1)),
150 myCooperativeMinSpeed(v.getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_COOPERATIVE_MINSPEED, 0)),
151 myHaveBlueLight(v.getDevice(typeid(MSDevice_Bluelight)) != nullptr), // see MSVehicle::initDevices
152 myLastLaneChangeOffset(0),
153 myAmOpposite(false),
154 myManeuverDist(0.),
155 myPreviousManeuverDist(0.) {
159}
160
161
164
165void
168 myOwnState = state;
169 myPreviousState = state; // myOwnState is modified in prepareStep so we make a backup
170}
171
172void
173MSAbstractLaneChangeModel::updateSafeLatDist(const double travelledLatDist) {
174 UNUSED_PARAMETER(travelledLatDist);
175}
176
177
178void
180#ifdef DEBUG_MANEUVER
181 if (DEBUG_COND) {
182 std::cout << SIMTIME
183 << " veh=" << myVehicle.getID()
184 << " setManeuverDist() old=" << myManeuverDist << " new=" << dist
185 << std::endl;
186 }
187#endif
188 myManeuverDist = fabs(dist) < NUMERICAL_EPS ? 0. : dist;
189 // store value which may be modified by the model during the next step
191}
192
193
194double
198
199double
203
204bool
206 if (neighLeader == nullptr) {
207 return false;
208 }
209 // Congested situation are relevant only on highways (maxSpeed > 70km/h)
210 // and congested on German Highways means that the vehicles have speeds
211 // below 60km/h. Overtaking on the right is allowed then.
212 if ((myVehicle.getLane()->getSpeedLimit() <= 70.0 / 3.6) || (neighLeader->getLane()->getSpeedLimit() <= 70.0 / 3.6)) {
213
214 return false;
215 }
216 if (myVehicle.congested() && neighLeader->congested()) {
217 return true;
218 }
219 return false;
220}
221
222
223bool
224MSAbstractLaneChangeModel::avoidOvertakeRight(const MSVehicle* const neighLeader, const bool allowProb) const {
225 return (!myAllowOvertakingRight // the highway case
226 && !myVehicle.congested()
229 (neighLeader != nullptr && neighLeader->isStopped() // the bus stop case
230 && neighLeader->getStops().front().busstop != nullptr
231 && !StringUtils::toBool(neighLeader->getStops().front().busstop->getParameter("allowOvertakeRight", "true")));
232}
233
234bool
235MSAbstractLaneChangeModel::predInteraction(const std::pair<MSVehicle*, double>& leader) {
236 if (leader.first == 0) {
237 return false;
238 }
239 // let's check it on highways only
240 if (leader.first->getSpeed() < (80.0 / 3.6)) {
241 return false;
242 }
243 return leader.second < getCarFollowModel().interactionGap(&myVehicle, leader.first->getSpeed());
244}
245
246
247bool
251 myLaneChangeDirection = direction;
252 setManeuverDist((target->getWidth() + source->getWidth()) * 0.5 * direction);
255 if (myLCOutput) {
257 }
258 return true;
259 } else {
260 primaryLaneChanged(source, target, direction);
261 return false;
262 }
263}
264
265void
269
270void
274
275void
277 initLastLaneChangeOffset(direction);
279 source->leftByLaneChange(&myVehicle);
280 laneChangeOutput("change", source, target, direction); // record position on the source edge in case of opposite change
281 if (&source->getEdge() != &target->getEdge()) {
283#ifdef DEBUG_OPPOSITE
284 if (debugVehicle()) {
285 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " primaryLaneChanged source=" << source->getID() << " target=" << target->getID() << " nowOpposite=" << myAmOpposite << "\n";
286 }
287#endif
290 } else if (myAmOpposite) {
291#ifdef DEBUG_OPPOSITE
292 if (debugVehicle()) {
293 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " primaryLaneChanged source=" << source->getID() << " target=" << target->getID() << " stayOpposite\n";
294 }
295#endif
296 myAlreadyChanged = true;
298 if (!MSGlobals::gSublane) {
299 // in the continous case, the vehicle is added to the target lane via MSLaneChanger::continueChange / registerHop
300 // in the sublane case, the vehicle is added to the target lane via MSLaneChangerSublane::checkChangeOppositeSublane / MSLane::myTmpVehicles
302 }
303 } else {
306 }
307 // Assure that the drive items are up to date (even if the following step is no actionstep for the vehicle).
308 // This is necessary because the lane advance uses the target lane from the corresponding drive item.
310 changed();
311}
312
313void
314MSAbstractLaneChangeModel::laneChangeOutput(const std::string& tag, MSLane* source, MSLane* target, int direction, double maneuverDist) {
315 if (myLCOutput) {
316 OutputDevice& of = OptionsCont::getDeviceByOption("lanechange-output");
317 of.openTag(tag);
320 of.writeAttr(SUMO_ATTR_TIME, time2string(MSNet::getInstance()->getCurrentTimeStep()));
321 of.writeAttr(SUMO_ATTR_FROM, source->getID());
322 of.writeAttr(SUMO_ATTR_TO, target->getID());
323 of.writeAttr(SUMO_ATTR_DIR, direction);
341 const double latGap = direction < 0 ? myLastLateralGapRight : myLastLateralGapLeft;
342 of.writeAttr("latGap", latGap == NO_NEIGHBOR ? "None" : toString(latGap), latGap == NO_NEIGHBOR);
343 if (maneuverDist != 0) {
344 of.writeAttr("maneuverDistance", toString(maneuverDist));
345 }
346 }
347 if (myLCXYOutput) {
350 }
351 of.closeTag();
354 }
355 }
356}
357
358
359double
360MSAbstractLaneChangeModel::computeSpeedLat(double /*latDist*/, double& maneuverDist, bool /*urgent*/) const {
362 int stepsToChange = (int)ceil(fabs(maneuverDist) / SPEED2DIST(myVehicle.getVehicleType().getMaxSpeedLat()));
363 return DIST2SPEED(maneuverDist / stepsToChange);
364 } else {
365 return maneuverDist / STEPS2TIME(MSGlobals::gLaneChangeDuration);
366 }
367}
368
369
370double
374
375void
378 mySpeedLat = speedLat;
379}
380
381
382void
388
389
390bool
392 const bool pastBefore = pastMidpoint();
393 // maneuverDist is not updated in the context of continuous lane changing but represents the full LC distance
394 double maneuverDist = getManeuverDist();
395 setSpeedLat(computeSpeedLat(0, maneuverDist, (myOwnState & LCA_URGENT) != 0));
397 return !pastBefore && pastMidpoint();
398}
399
400
401void
403 UNUSED_PARAMETER(reason);
412 // opposite driving continues after parking
413 } else {
414 // aborted maneuver
415#ifdef DEBUG_OPPOSITE
416 if (debugVehicle()) {
417 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " aborted maneuver (no longer opposite)\n";
418 }
419#endif
421 }
422 }
423}
424
425
426MSLane*
427MSAbstractLaneChangeModel::getShadowLane(const MSLane* lane, double posLat) const {
429 // initialize shadow lane
430 const double overlap = myVehicle.getLateralOverlap(posLat, lane);
431#ifdef DEBUG_SHADOWLANE
432 if (debugVehicle()) {
433 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " posLat=" << posLat << " overlap=" << overlap << "\n";
434 }
435#endif
436 if (myAmOpposite) {
437 // return the neigh-lane in forward direction
438 return lane->getParallelLane(1);
439 } else if (overlap > NUMERICAL_EPS) {
440 const int shadowDirection = posLat < 0 ? -1 : 1;
441 return lane->getParallelLane(shadowDirection);
442 } else if (isChangingLanes() && myLaneChangeCompletion < 0.5) {
443 // "reserve" target lane even when there is no overlap yet
445 } else {
446 return nullptr;
447 }
448 } else {
449 return nullptr;
450 }
451}
452
453
454MSLane*
458
459
460void
462 if (myShadowLane != nullptr) {
463 if (debugVehicle()) {
464 std::cout << SIMTIME << " cleanupShadowLane\n";
465 }
467 myShadowLane = nullptr;
468 }
469 for (MSLane* further : myShadowFurtherLanes) {
470 if (debugVehicle()) {
471 std::cout << SIMTIME << " cleanupShadowLane2\n";
472 }
474 if (further->getBidiLane() != nullptr) {
475 further->getBidiLane()->resetPartialOccupation(&myVehicle);
476 }
477 }
478 myShadowFurtherLanes.clear();
480}
481
482void
484 if (myTargetLane != nullptr) {
485 if (debugVehicle()) {
486 std::cout << SIMTIME << " cleanupTargetLane\n";
487 }
489 myTargetLane = nullptr;
490 }
491 for (std::vector<MSLane*>::const_iterator it = myFurtherTargetLanes.begin(); it != myFurtherTargetLanes.end(); ++it) {
492 if (debugVehicle()) {
493 std::cout << SIMTIME << " cleanupTargetLane\n";
494 }
495 if (*it != nullptr) {
497 }
498 }
499 myFurtherTargetLanes.clear();
500// myNoPartiallyOccupatedByShadow.clear();
501}
502
503
504bool
506 // store request before canceling
507 getCanceledState(laneOffset) |= state;
508 int ret = myVehicle.influenceChangeDecision(state);
509 return ret != state;
510}
511
512double
516
517void
519 if (dir > 0) {
521 } else if (dir < 0) {
523 }
524}
525
526void
528 if (!MSGlobals::gSublane) {
529 // assume each vehicle drives at the center of its lane and act as if it fits
530 return;
531 }
532 if (myShadowLane != nullptr) {
533#ifdef DEBUG_SHADOWLANE
534 if (debugVehicle()) {
535 std::cout << SIMTIME << " updateShadowLane()\n";
536 }
537#endif
539 }
541 std::vector<MSLane*> passed;
542 if (myShadowLane != nullptr) {
544 const std::vector<MSLane*>& further = myVehicle.getFurtherLanes();
545 if (myAmOpposite) {
546 assert(further.size() == 0);
547 } else {
548 const std::vector<double>& furtherPosLat = myVehicle.getFurtherLanesPosLat();
549 assert(further.size() == furtherPosLat.size());
550 passed.push_back(myShadowLane);
551 for (int i = 0; i < (int)further.size(); ++i) {
552 MSLane* shadowFurther = getShadowLane(further[i], furtherPosLat[i]);
553#ifdef DEBUG_SHADOWLANE
554 if (debugVehicle()) {
555 std::cout << SIMTIME << " further=" << further[i]->getID() << " (posLat=" << furtherPosLat[i] << ") shadowFurther=" << Named::getIDSecure(shadowFurther) << "\n";
556 }
557#endif
558 if (shadowFurther != nullptr && shadowFurther->getLinkTo(passed.back()) != nullptr) {
559 passed.push_back(shadowFurther);
560 }
561 }
562 std::reverse(passed.begin(), passed.end());
563 }
564 } else {
565 if (isChangingLanes() && myVehicle.getLateralOverlap() > NUMERICAL_EPS) {
566 WRITE_WARNING("Vehicle '" + myVehicle.getID() + "' could not finish continuous lane change (lane disappeared) time=" +
567 time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
569 }
570 }
571#ifdef DEBUG_SHADOWLANE
572 if (debugVehicle()) {
573 std::cout << SIMTIME << " updateShadowLane() veh=" << myVehicle.getID()
574 << " newShadowLane=" << Named::getIDSecure(myShadowLane)
575 << "\n before:" << " myShadowFurtherLanes=" << toString(myShadowFurtherLanes) << " further=" << toString(myVehicle.getFurtherLanes()) << " passed=" << toString(passed);
576 std::cout << std::endl;
577 }
578#endif
580#ifdef DEBUG_SHADOWLANE
581 if (debugVehicle()) std::cout
582 << "\n after:" << " myShadowFurtherLanes=" << toString(myShadowFurtherLanes) << "\n";
583#endif
584}
585
586
587int
589 if (isChangingLanes()) {
590 if (pastMidpoint()) {
591 return -myLaneChangeDirection;
592 } else {
594 }
595 } else if (myShadowLane == nullptr) {
596 return 0;
597 } else if (myAmOpposite) {
598 // return neigh-lane in forward direction
599 return 1;
600 } else if (&myShadowLane->getEdge() == &myVehicle.getLane()->getEdge()) {
602 } else {
603 // overlap with opposite direction lane
604 return 1;
605 }
606}
607
608
609MSLane*
611#ifdef DEBUG_TARGET_LANE
612 MSLane* oldTarget = myTargetLane;
613 std::vector<MSLane*> oldFurtherTargets = myFurtherTargetLanes;
614 if (debugVehicle()) {
615 std::cout << SIMTIME << " veh '" << myVehicle.getID() << "' (lane=" << myVehicle.getLane()->getID() << ") updateTargetLane()"
616 << "\n oldTarget: " << (oldTarget == nullptr ? "NULL" : oldTarget->getID())
617 << " oldFurtherTargets: " << toString(oldFurtherTargets);
618 }
619#endif
620 if (myTargetLane != nullptr) {
622 }
623 // Clear old further target lanes
624 for (MSLane* oldTargetLane : myFurtherTargetLanes) {
625 if (oldTargetLane != nullptr) {
626 oldTargetLane->resetManeuverReservation(&myVehicle);
627 }
628 }
629 myFurtherTargetLanes.clear();
630
631 // Get new target lanes and issue a maneuver reservation.
632 int targetDir;
634 if (myTargetLane != nullptr) {
636 // further targets are just the target lanes corresponding to the vehicle's further lanes
637 // @note In a neglectable amount of situations we might add a reservation for a shadow further lane.
638 for (MSLane* furtherLane : myVehicle.getFurtherLanes()) {
639 MSLane* furtherTargetLane = furtherLane->getParallelLane(targetDir);
640 myFurtherTargetLanes.push_back(furtherTargetLane);
641 if (furtherTargetLane != nullptr) {
642 furtherTargetLane->setManeuverReservation(&myVehicle);
643 }
644 }
645 }
646#ifdef DEBUG_TARGET_LANE
647 if (debugVehicle()) {
648 std::cout << "\n newTarget (maneuverDist=" << myManeuverDist << " offset=" << targetDir << "): " << (myTargetLane == nullptr ? "NULL" : myTargetLane->getID())
649 << " newFurtherTargets: " << toString(myFurtherTargetLanes)
650 << std::endl;
651 }
652#endif
653 return myTargetLane;
654}
655
656
657MSLane*
659 targetDir = 0;
660 if (myManeuverDist == 0) {
661 return nullptr;
662 }
663 // Current lateral boundaries of the vehicle
664 const double vehRight = myVehicle.getLateralPositionOnLane() - 0.5 * myVehicle.getWidth();
665 const double vehLeft = myVehicle.getLateralPositionOnLane() + 0.5 * myVehicle.getWidth();
666 const double halfLaneWidth = 0.5 * myVehicle.getLane()->getWidth();
667
668 if (vehRight + myManeuverDist < -halfLaneWidth) {
669 // Vehicle intends to traverse the right lane boundary
670 targetDir = -1;
671 } else if (vehLeft + myManeuverDist > halfLaneWidth) {
672 // Vehicle intends to traverse the left lane boundary
673 targetDir = 1;
674 }
675 if (targetDir == 0) {
676 // Presently, no maneuvering into another lane is begun.
677 return nullptr;
678 }
679 MSLane* target = myVehicle.getLane()->getParallelLane(targetDir);
680 if (target == nullptr || target == myShadowLane) {
681 return nullptr;
682 } else {
683 return target;
684 }
685}
686
687
688
689double
691 double result = 0.;
692 if (!(fabs(mySpeedLat) < NUMERICAL_EPS && fabs(myPreviousAngleOffset * 180 / M_PI) < NUMERICAL_EPS)) {
694 result = atan2(mySpeedLat, myVehicle.getSpeed());
695 } else {
697 }
698 }
699
700 myAngleOffset = result;
701 return result;
702}
703
704
705double
706MSAbstractLaneChangeModel::estimateLCDuration(const double speed, const double remainingManeuverDist, const double decel, bool urgent) const {
707
709 if (lcParams.find(SUMO_ATTR_LCA_MAXSPEEDLATSTANDING) == lcParams.end() && lcParams.find(SUMO_ATTR_LCA_MAXSPEEDLATFACTOR) == lcParams.end()) {
711 // no dependency of lateral speed on longitudinal speed. (Only called prior to LC initialization to determine whether it could be completed)
713 } else {
714 return remainingManeuverDist / myVehicle.getVehicleType().getMaxSpeedLat();
715 }
716 }
717
718 if (remainingManeuverDist == 0) {
719 return 0;
720 }
721
722 // Check argument assumptions
723 assert(speed >= 0);
724 assert(remainingManeuverDist >= 0);
725 assert(decel > 0);
728 assert(myMaxSpeedLatStanding >= 0);
729
730 // for brevity
731 const double v0 = speed;
732 const double D = remainingManeuverDist;
733 const double b = decel;
734 const double wmin = myMaxSpeedLatStanding;
735 const double f = myMaxSpeedLatFactor;
736 const double wmax = myVehicle.getVehicleType().getMaxSpeedLat();
737
738 /* Here's the approach for the calculation of the required time for the LC:
739 * To obtain the maximal LC-duration, for v(t) we assume that v(t)=max(0, v0-b*t),
740 * Where v(t)=0 <=> t >= ts:=v0/b
741 * For the lateral speed w(t) this gives:
742 * w(t) = min(wmax, wmin + f*v(t))
743 * The lateral distance covered until t is
744 * d(t) = int_0^t w(s) ds
745 * We distinguish three possibilities for the solution d(T)=D, where T is the time of the LC completion.
746 * 1) w(T) = wmax, i.e. v(T)>(wmax-wmin)/f
747 * 2) wmin < w(T) < wmax, i.e. (wmax-wmin)/f > v(T) > 0
748 * 3) w(T) = wmin, i.e., v(T)=0
749 */
750 const double vm = (wmax - wmin) / f;
751 double distSoFar = 0.;
752 double timeSoFar = 0.;
753 double v = v0;
754 if (v > vm) {
755 const double wmaxTime = (v0 - vm) / b;
756 const double d1 = wmax * wmaxTime;
757 if (d1 >= D) {
758 return D / wmax;
759 } else {
760 distSoFar += d1;
761 timeSoFar += wmaxTime;
762 v = vm;
763 }
764 }
765 if (v > 0) {
766 /* Here, w(t1+t) = wmin + f*v(t1+t) = wmin + f*(v - b*t)
767 * Thus, the additional lateral distance covered after time t is:
768 * d2 = (wmin + f*v)*t - 0.5*f*b*t^2
769 * and the additional lateral distance covered until v=0 at t=v/b is:
770 * d2 = (wmin + 0.5*f*v)*t
771 */
772 const double t = v / b; // stop time
773 const double d2 = (wmin + 0.5 * f * v) * t; // lateral distance covered until stop
774 assert(d2 > 0);
775 if (distSoFar + d2 >= D) {
776 // LC is completed during this phase
777 const double x = 0.5 * f * b;
778 const double y = wmin + f * v;
779 /* Solve D - distSoFar = y*t - x*t^2.
780 * 0 = x*t^2 - y*t/x + (D - distSoFar)/x
781 */
782 const double p = 0.5 * y / x;
783 const double q = (D - distSoFar) / x;
784 assert(p * p - q > 0);
785 const double t2 = p + sqrt(p * p - q);
786 return timeSoFar + t2;
787 } else {
788 distSoFar += d2;
789 timeSoFar += t;
790 //v = 0;
791 }
792 }
793 // If we didn't return yet this means the LC was not completed until the vehicle stops (if braking with rate b)
794 if (wmin == 0) {
795 // LC won't be completed if vehicle stands
796 double maneuverDist = remainingManeuverDist;
797 const double vModel = computeSpeedLat(maneuverDist, maneuverDist, urgent);
798 double result = D / vModel;
799 // make sure that the vehicle isn't braking to a stop during the manuever
800 if (vModel > SUMO_const_haltingSpeed && (vModel + myVehicle.getAcceleration() * result) > SUMO_const_haltingSpeed) {
801 // unless the model tells us something different
802 return result;
803 } else {
804 return -1;
805 }
806 } else {
807 // complete LC with lateral speed wmin
808 return timeSoFar + (D - distSoFar) / wmin;
809 }
810}
811
814 assert(isChangingLanes()); // Only to be called during ongoing lane change
816 if (lcParams.find(SUMO_ATTR_LCA_MAXSPEEDLATSTANDING) == lcParams.end() && lcParams.find(SUMO_ATTR_LCA_MAXSPEEDLATFACTOR) == lcParams.end()) {
819 } else {
821 }
822 }
823 // Using maxSpeedLat(Factor/Standing)
824 const bool urgent = (myOwnState & LCA_URGENT) != 0;
828}
829
830
831void
833 //std::cout << SIMTIME << " veh=" << myVehicle.getID() << " @=" << &myVehicle << " set shadow approaching=" << link->getViaLaneOrLane()->getID() << "\n";
834 myApproachedByShadow.push_back(link);
835}
836
837void
839 for (std::vector<MSLink*>::iterator it = myApproachedByShadow.begin(); it != myApproachedByShadow.end(); ++it) {
840 //std::cout << SIMTIME << " veh=" << myVehicle.getID() << " @=" << &myVehicle << " remove shadow approaching=" << (*it)->getViaLaneOrLane()->getID() << "\n";
841 (*it)->removeApproaching(&myVehicle);
842 }
843 myApproachedByShadow.clear();
844}
845
846
847
848void
851 int oldstate = myVehicle.getLaneChangeModel().getOwnState();
852 if (myOwnState != newstate) {
854 // Calculate and set the lateral maneuver distance corresponding to the change request
855 // to induce a corresponding sublane change.
856 const int dir = (newstate & LCA_RIGHT) != 0 ? -1 : ((newstate & LCA_LEFT) != 0 ? 1 : 0);
857 // minimum distance to move the vehicle fully onto the lane at offset dir
858 const double latLaneDist = myVehicle.lateralDistanceToLane(dir);
859 if ((newstate & LCA_TRACI) != 0) {
860 if ((newstate & LCA_STAY) != 0) {
861 setManeuverDist(0.);
862 } else if (((newstate & LCA_RIGHT) != 0 && dir < 0)
863 || ((newstate & LCA_LEFT) != 0 && dir > 0)) {
864 setManeuverDist(latLaneDist);
865 }
866 }
867 if (myVehicle.hasInfluencer()) {
868 // lane change requests override sublane change requests
870 }
871
872 }
873 setOwnState(newstate);
874 } else {
875 // Check for sublane change requests
877 const double maneuverDist = myVehicle.getInfluencer().getLatDist();
880 newstate |= LCA_TRACI;
881 if (myOwnState != newstate) {
882 setOwnState(newstate);
883 }
884 if (gDebugFlag2) {
885 std::cout << " traci influenced maneuverDist=" << maneuverDist << "\n";
886 }
887 }
888 }
889 if (gDebugFlag2) {
890 std::cout << SIMTIME << " veh=" << myVehicle.getID() << " stateAfterTraCI=" << toString((LaneChangeAction)newstate) << " original=" << toString((LaneChangeAction)oldstate) << "\n";
891 }
892}
893
894void
899
900void
902 if (follower.first != 0) {
903 myLastFollowerGap = follower.second + follower.first->getVehicleType().getMinGap();
905 myLastFollowerSpeed = follower.first->getSpeed();
906 }
907}
908
909void
911 if (leader.first != 0) {
913 myLastLeaderSecureGap = secGap;
914 myLastLeaderSpeed = leader.first->getSpeed();
915 }
916}
917
918void
920 if (leader.first != 0) {
923 myLastOrigLeaderSpeed = leader.first->getSpeed();
924 }
925}
926
927void
951
952void
954 int rightmost;
955 int leftmost;
956 vehicles.getSubLanes(&myVehicle, 0, rightmost, leftmost);
957 for (int i = rightmost; i <= leftmost; ++i) {
958 CLeaderDist vehDist = vehicles[i];
959 if (vehDist.first != 0) {
960 const MSVehicle* leader = &myVehicle;
961 const MSVehicle* follower = vehDist.first;
962 const double netGap = vehDist.second + follower->getVehicleType().getMinGap();
963 if (netGap < myLastFollowerGap && netGap >= 0) {
964 myLastFollowerGap = netGap;
965 myLastFollowerSecureGap = follower->getCarFollowModel().getSecureGap(follower, leader, follower->getSpeed(), leader->getSpeed(), leader->getCarFollowModel().getMaxDecel());
966 myLastFollowerSpeed = follower->getSpeed();
967 }
968 }
969 }
970}
971
972void
974 int rightmost;
975 int leftmost;
976 vehicles.getSubLanes(&myVehicle, 0, rightmost, leftmost);
977 for (int i = rightmost; i <= leftmost; ++i) {
978 CLeaderDist vehDist = vehicles[i];
979 if (vehDist.first != 0) {
980 const MSVehicle* leader = vehDist.first;
981 const MSVehicle* follower = &myVehicle;
982 const double netGap = vehDist.second + follower->getVehicleType().getMinGap();
983 if (netGap < myLastLeaderGap && netGap >= 0) {
984 myLastLeaderGap = netGap;
985 myLastLeaderSecureGap = follower->getCarFollowModel().getSecureGap(follower, leader, follower->getSpeed(), leader->getSpeed(), leader->getCarFollowModel().getMaxDecel());
986 myLastLeaderSpeed = leader->getSpeed();
987 }
988 }
989 }
990}
991
992void
994 int rightmost;
995 int leftmost;
996 vehicles.getSubLanes(&myVehicle, 0, rightmost, leftmost);
997 for (int i = rightmost; i <= leftmost; ++i) {
998 CLeaderDist vehDist = vehicles[i];
999 if (vehDist.first != 0) {
1000 const MSVehicle* leader = vehDist.first;
1001 const MSVehicle* follower = &myVehicle;
1002 const double netGap = vehDist.second + follower->getVehicleType().getMinGap();
1003 if (netGap < myLastOrigLeaderGap && netGap >= 0) {
1004 myLastOrigLeaderGap = netGap;
1005 myLastOrigLeaderSecureGap = follower->getCarFollowModel().getSecureGap(follower, leader, follower->getSpeed(), leader->getSpeed(), leader->getCarFollowModel().getMaxDecel());
1006 myLastOrigLeaderSpeed = leader->getSpeed();
1007 }
1008 }
1009 }
1010}
1011
1012
1013bool
1015 const int stateRight = mySavedStateRight.second;
1016 if (
1017 (stateRight & LCA_STRATEGIC) != 0
1018 && (stateRight & LCA_RIGHT) != 0
1019 && (stateRight & LCA_BLOCKED) != 0) {
1020 return true;
1021 }
1022 const int stateLeft = mySavedStateLeft.second;
1023 if (
1024 (stateLeft & LCA_STRATEGIC) != 0
1025 && (stateLeft & LCA_LEFT) != 0
1026 && (stateLeft & LCA_BLOCKED) != 0) {
1027 return true;
1028 }
1029 return false;
1030}
1031
1032double
1036
1037
1038int
1040 const int i = myVehicle.getLane()->getIndex();
1041 if (myAmOpposite) {
1043 } else {
1044 return i;
1045 }
1046}
1047
1048void
1049MSAbstractLaneChangeModel::addLCSpeedAdvice(const double vSafe, int flag) {
1050 const double accel = SPEED2ACCEL(vSafe - myVehicle.getSpeed());
1051 myLCAccelerationAdvices.push_back({accel, flag});
1052}
1053
1054
1055bool
1056MSAbstractLaneChangeModel::canOvertakeRight(const MSVehicle* const nv, const double dist, const double maxSpeedDiff, const double helpOvertakeSpeed, double& vSafe, double& deltaV) const {
1057 deltaV = MAX2(maxSpeedDiff, myVehicle.getSpeed() - nv->getSpeed());
1058 if (deltaV > 0) {
1059 const double vMaxDecel = getCarFollowModel().getSpeedAfterMaxDecel(myVehicle.getSpeed());
1060 const double vSafeFollow = getCarFollowModel().followSpeed(
1062 const double vStayBehind = nv->getSpeed() - helpOvertakeSpeed;
1063 if (vSafeFollow >= vMaxDecel) {
1064 vSafe = vSafeFollow;
1065 } else {
1066 vSafe = MAX2(vMaxDecel, vStayBehind);
1067 }
1068 return true;
1069 }
1070 return false;
1071}
1072
1073
1074void
1076 std::vector<double> lcState;
1077 lcState.push_back((double)myOwnState);
1078 for (const auto& item : myLCAccelerationAdvices) {
1079 lcState.push_back(item.first);
1080 lcState.push_back((double)item.second);
1081 }
1082 out.writeAttr(SUMO_ATTR_LCSTATE_BASE, lcState);
1083
1086 }
1087}
1088
1089void
1092 std::istringstream bis(attrs.getString(SUMO_ATTR_LCSTATE_BASE));
1093 double token;
1094 bis >> token;
1095 myOwnState = (int)token; // double is suffciently precise
1096 double prev = std::numeric_limits<double>::max();
1097 while (bis >> token) {
1098 if (prev != std::numeric_limits<double>::max()) {
1099 myLCAccelerationAdvices.push_back(std::make_pair(prev, (int)token));
1100 prev = std::numeric_limits<double>::max();
1101 }
1102 prev = token;
1103 }
1104 }
1105 if (attrs.hasAttribute(SUMO_ATTR_LCSTATE)) {
1106 std::istringstream bis(attrs.getString(SUMO_ATTR_LCSTATE));
1107 bis >> mySpeedLat;
1109 bis >> myLaneChangeDirection;
1110 }
1111}
1112
1113
1114double
1115MSAbstractLaneChangeModel::getExtraReservation(int bestLaneOffset, double neighExtraDist) const {
1116 if (neighExtraDist > myVehicle.getVehicleType().getLengthWithGap()) {
1117 return 0;
1118 }
1119 if (bestLaneOffset < -1) {
1120 return 20;
1121 } else if (bestLaneOffset > 1) {
1122 return 40;
1123 }
1124 return 0;
1125}
1126
1127
1128double
1129MSAbstractLaneChangeModel::getCooperativeHelpSpeed(const MSLane* lane, double distToLaneEnd) const {
1130 if (myCooperativeHelpTime >= 0) {
1131 std::pair<double, SUMOTime> backAndWaiting = lane->getEdge().getLastBlocked(lane->getIndex());
1132 if (backAndWaiting.second >= myCooperativeHelpTime) {
1133 double gap = distToLaneEnd - lane->getLength() + backAndWaiting.first - myVehicle.getVehicleType().getMinGap() - NUMERICAL_EPS;
1134 if (backAndWaiting.first < 0) {
1135 if (myVehicle.getLane()->getToJunction() == lane->getFromJunction()) {
1136 if (myVehicle.getLane()->isInternal()) {
1137 // already on the junction, potentially blocking lane change, do not stop
1138 gap = -1;
1139 } else {
1140 // stop before entering the junction
1142 }
1143 }
1144 }
1145 if (gap > 0) {
1146 double stopSpeed = myVehicle.getCarFollowModel().stopSpeed(&myVehicle, myVehicle.getSpeed(), gap);
1147 //if (myVehicle.isSelected() && stopSpeed < myVehicle.getSpeed()) {
1148 // std::cout << SIMTIME << " veh=" << myVehicle.getID() << " lane=" << lane->getID() << " dte=" << distToLaneEnd << " gap=" << gap << " backPos=" << backAndWaiting.first << " waiting=" << backAndWaiting.second << " helpTime=" << myCooperativeHelpTime << " stopSpeed=" << stopSpeed << " minNext=" << myVehicle.getCarFollowModel().minNextSpeed(myVehicle.getSpeed(), &myVehicle) << "\n";
1149 //}
1151 // regular braking is helpful
1152 return stopSpeed;
1153 }
1154 }
1155 }
1156 }
1157 // do not restrict speed
1158 return std::numeric_limits<double>::max();
1159}
long long int SUMOTime
Definition GUI.h:36
#define LC_ASSUMED_DECEL
std::pair< const MSVehicle *, double > CLeaderDist
#define WRITE_WARNING(msg)
Definition MsgHandler.h:298
#define TLF(string,...)
Definition MsgHandler.h:318
SUMOTime DELTA_T
Definition SUMOTime.cpp:39
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:107
#define STEPS2TIME(x)
Definition SUMOTime.h:58
#define SPEED2DIST(x)
Definition SUMOTime.h:48
constexpr SUMOTime TIME2STEPS(double x)
Definition SUMOTime.h:60
#define SIMTIME
Definition SUMOTime.h:70
#define DIST2SPEED(x)
Definition SUMOTime.h:50
#define SPEED2ACCEL(x)
Definition SUMOTime.h:56
const long long int VTYPEPARS_MAXSPEED_LAT_SET
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_MOTORCYCLE
vehicle is a motorcycle
@ SVC_EMERGENCY
public emergency vehicles
@ SVC_MOPED
vehicle is a moped
LaneChangeAction
The state of a vehicle's lane-change behavior.
@ LCA_UNKNOWN
The action has not been determined.
@ 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_AMBACKBLOCKER
@ LCA_AMBLOCKINGLEADER
@ 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_RIGHT
Wants go to the right.
@ LCA_AMBLOCKINGFOLLOWER
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_LCA_ASSERTIVE
@ SUMO_ATTR_Y
@ SUMO_ATTR_LCA_COOPERATIVE_MINSPEED
@ SUMO_ATTR_X
@ SUMO_ATTR_LCA_MAXDISTLATSTANDING
@ SUMO_ATTR_LCA_COOPERATIVE_HELPTIME
@ SUMO_ATTR_LCA_MAXSPEEDLATFACTOR
@ SUMO_ATTR_LCA_MAXSPEEDLATSTANDING
@ SUMO_ATTR_LCA_STRATEGIC_LOOKAHEAD
@ SUMO_ATTR_TO
@ SUMO_ATTR_FROM
@ SUMO_ATTR_LCA_SIGMA
@ SUMO_ATTR_LCSTATE_BASE
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_LCA_COOPERATIVE_HELPTHRESHOLD
@ SUMO_ATTR_ID
@ SUMO_ATTR_LCSTATE
The state of the lanechange model.
@ SUMO_ATTR_LCA_OVERTAKE_RIGHT
@ SUMO_ATTR_DIR
The abstract direction of a link.
@ SUMO_ATTR_POSITION
@ SUMO_ATTR_TIME
trigger: the time of the step
bool gDebugFlag2
Definition StdDefs.cpp:45
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
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
Interface for lane-change models.
double getForwardPos() const
get vehicle position relative to the forward direction lane
double myAccelerationLat
the current lateral acceleration
void setFollowerGaps(CLeaderDist follower, double secGap)
virtual double getExtraReservation(int bestLaneOffset, double neighExtraDist=0) const
std::vector< MSLane * > myFurtherTargetLanes
bool myAlreadyChanged
whether the vehicle has already moved this step
bool myAmOpposite
whether the vehicle is driving in the opposite direction
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 void setOwnState(const int state)
bool pastMidpoint() const
return whether the vehicle passed the midpoint of a continuous lane change maneuver
double myPreviousAngleOffset
the angle offset of the previous time step resulting from lane change and sigma
virtual double getAssumedDecelForLaneChangeDuration() const
Returns a deceleration value which is used for the estimation of the duration of a lane change.
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...
virtual double estimateLCDuration(const double speed, const double remainingManeuverDist, const double decel, bool urgent) const
Calculates the maximal time needed to complete a lane change maneuver if lcMaxSpeedLatFactor and lcMa...
int myPreviousState
lane changing state from the previous simulation step
double getManeuverDist() const
Returns the remaining unblocked distance for the current maneuver. (only used by sublane model)
int myOwnState
The current state of the vehicle.
double myLastOrigLeaderGap
acutal and secure distance to closest leader vehicle on the original when performing lane change
virtual bool predInteraction(const std::pair< MSVehicle *, double > &leader)
void laneChangeOutput(const std::string &tag, MSLane *source, MSLane *target, int direction, double maneuverDist=0)
called once the vehicle ends a lane change manoeuvre (non-instant)
bool myDontResetLCGaps
Flag to prevent resetting the memorized values for LC relevant gaps until the LC output is triggered ...
int myPreviousState2
lane changing state from step before the previous simulation step
MSLane * getShadowLane() const
Returns the lane the vehicle's shadow is on during continuous/sublane lane change.
double myCommittedSpeed
the speed when committing to a change maneuver
static bool myLCOutput
whether to record lane-changing
bool startLaneChangeManeuver(MSLane *source, MSLane *target, int direction)
start the lane change maneuver and return whether it continues
virtual void saveState(OutputDevice &out) const
Save the state of the laneChangeModel.
std::pair< int, int > mySavedStateRight
double myLastLeaderSecureGap
the minimum longitudinal distances to vehicles on the target lane that would be necessary for stringe...
void endLaneChangeManeuver(const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_LANE_CHANGE)
void saveLCState(const int dir, int stateWithoutTraCI, const int state)
static bool myAllowOvertakingRight
whether overtaking on the right is permitted
std::vector< MSLink * > myApproachedByShadow
links which are approached by the shadow vehicle
bool canOvertakeRight(const MSVehicle *const nv, const double dist, const double maxSpeedDiff, const double helpOvertakeSpeed, double &vSafe, double &deltaV) const
void setLeaderGaps(CLeaderDist, double secGap)
std::vector< MSLane * > myNoPartiallyOccupatedByShadow
bool cancelRequest(int state, int laneOffset)
whether the influencer cancels the given request
double myLastLeaderGap
the actual minimum longitudinal distances to vehicles on the target lane
SUMOTime remainingTime() const
Compute the remaining time until LC completion.
void setOrigLeaderGaps(CLeaderDist, double secGap)
void setManeuverDist(const double dist)
Updates the remaining distance for the current maneuver while it is continued within non-action steps...
void setShadowApproachingInformation(MSLink *link) const
set approach information for the shadow vehicle
double getCooperativeHelpSpeed(const MSLane *lane, double distToLaneEnd) const
return speed for helping a vehicle that is blocked from changing
virtual bool avoidOvertakeRight(const MSVehicle *const neighLeader, const bool allowProb=false) const
int getNormalizedLaneIndex()
brief return lane index that treats opposite lanes like normal lanes to the left of the forward lanes
static MSAbstractLaneChangeModel * build(LaneChangeModel lcm, MSVehicle &vehicle)
Factory method for instantiating new lane changing models.
void changedToOpposite()
called when a vehicle changes between lanes in opposite directions
void setSpeedLat(double speedLat)
set the lateral speed and update lateral acceleraton
MSLane * myTargetLane
The target lane for the vehicle's current maneuver.
MSLane * determineTargetLane(int &targetDir) const
double myPreviousManeuverDist
Maneuver distance from the previous simulation step.
double getMaxSpeedLat2() const
return the max of maxSpeedLat and lcMaxSpeedLatStanding
std::vector< double > myShadowFurtherLanesPosLat
const MSCFModel & getCarFollowModel() const
The vehicle's car following model.
MSLane * myShadowLane
A lane that is partially occupied by the front of the vehicle but that is not the primary lane.
double mySpeedLat
the current lateral speed
virtual void updateSafeLatDist(const double travelledLatDist)
Updates the value of safe lateral distances (in SL2015) during maneuver continuation in non-action st...
void checkTraCICommands()
Check for commands issued for the vehicle via TraCI and apply the appropriate state changes For the s...
double myManeuverDist
The complete lateral distance the vehicle wants to travel to finish its maneuver Only used by sublane...
int myLaneChangeDirection
direction of the lane change maneuver -1 means right, 1 means left
void primaryLaneChanged(MSLane *source, MSLane *target, int direction)
called once when the vehicles primary lane changes
int getShadowDirection() const
return the direction in which the current shadow lane lies
double myLastLeaderSpeed
speeds of surrounding vehicles at the time of lane change
virtual void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the laneChangeModel from the given attributes.
MSAbstractLaneChangeModel(MSVehicle &v, const LaneChangeModel model)
Constructor.
MSVehicle & myVehicle
The vehicle this lane-changer belongs to.
double calcAngleOffset()
return the angle offset during a continuous change maneuver
double myAngleOffset
the current angle offset resulting from lane change and sigma
double myLastLateralGapLeft
the minimum lateral gaps to other vehicles that were found when last changing to the left and right
virtual ~MSAbstractLaneChangeModel()
Destructor.
static void initGlobalOptions(const OptionsCont &oc)
init global model parameters
virtual void prepareStep(SumoRNG *rng)
rng belongs to the lane that moves the vehicle (not the lane it just entered)
void memorizeGapsAtLCInit()
Control for resetting the memorized values for LC relevant gaps until the LC output is triggered in t...
double myLaneChangeCompletion
progress of the lane change maneuver 0:started, 1:complete
virtual bool debugVehicle() const
whether the current vehicles shall be debugged
virtual void changed()=0
bool isChangingLanes() const
return true if the vehicle currently performs a lane change maneuver
std::vector< MSLane * > myShadowFurtherLanes
virtual bool congested(const MSVehicle *const neighLeader)
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
double getLength() const
Returns the vehicle's length.
double getWidth() const
Returns the vehicle's width.
const std::list< MSStop > & getStops() const
SumoRNG * getRNG() const
const MSStop & getNextStop() const
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
bool isStopped() const
Returns whether the vehicle is at a stop.
virtual double interactionGap(const MSVehicle *const veh, double vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
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...
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 getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
Definition MSCFModel.h:285
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition MSCFModel.h:447
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
A device which collects info on the vehicle trip (mainly on departure and arrival)
std::pair< double, SUMOTime > getLastBlocked(int index) const
retrieve properties of a blocked vehicle that wants to chane to the lane with the given index
Definition MSEdge.cpp:1760
int getNumLanes() const
Definition MSEdge.h:173
static double gLateralResolution
Definition MSGlobals.h:100
static bool gLefthand
Whether lefthand-drive is being simulated.
Definition MSGlobals.h:177
static bool gSublane
whether sublane simulation is enabled (sublane model or continuous lanechanging)
Definition MSGlobals.h:168
static SUMOTime gLaneChangeDuration
Definition MSGlobals.h:97
A lane change model developed by D. Krajzewicz between 2004 and 2010.
A lane change model developed by D. Krajzewicz, J. Erdmann et al. between 2004 and 2013,...
A lane change model developed by D. Krajzewicz, J. Erdmann et al. between 2004 and 2013.
A lane change model developed by J. Erdmann.
Representation of a lane in the micro simulation.
Definition MSLane.h:84
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
virtual void resetManeuverReservation(MSVehicle *v)
Unregisters a vehicle, which previously registered for maneuvering into this lane.
Definition MSLane.cpp:439
const MSLink * getLinkTo(const MSLane *const) const
returns the link to the given lane or nullptr, if it is not connected
Definition MSLane.cpp:2801
void forceVehicleInsertion(MSVehicle *veh, double pos, MSMoveReminder::Notification notification, double posLat=0)
Inserts the given vehicle at the given position.
Definition MSLane.cpp:1435
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
Definition MSLane.h:602
void enteredByLaneChange(MSVehicle *v)
Definition MSLane.cpp:3414
const MSJunction * getToJunction() const
Definition MSLane.cpp:4833
double getLength() const
Returns the lane's length.
Definition MSLane.h:632
const MSJunction * getFromJunction() const
Definition MSLane.cpp:4827
virtual double setPartialOccupation(MSVehicle *v)
Sets the information about a vehicle lapping into this lane.
Definition MSLane.cpp:386
int getIndex() const
Returns the lane's index.
Definition MSLane.h:668
void leftByLaneChange(MSVehicle *v)
Definition MSLane.cpp:3407
double getOppositePos(double pos) const
return the corresponding position on the opposite lane
Definition MSLane.cpp:4477
bool isInternal() const
Definition MSLane.cpp:2669
virtual void resetPartialOccupation(MSVehicle *v)
Removes the information about a vehicle lapping into this lane.
Definition MSLane.cpp:405
virtual void setManeuverReservation(MSVehicle *v)
Registers the lane change intentions (towards this lane) for the given vehicle.
Definition MSLane.cpp:428
MSLane * getParallelOpposite() const
return the opposite direction lane of this lanes edge or nullptr
Definition MSLane.cpp:4471
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:790
double getWidth() const
Returns the lane's width.
Definition MSLane.h:661
saves leader/follower vehicles and their distances relative to an ego vehicle
void getSubLanes(const MSVehicle *veh, double latOffset, int &rightmost, int &leftmost) const
Notification
Definition of a vehicle state.
@ NOTIFICATION_LANE_CHANGE
The vehicle changes lanes (micro only)
@ NOTIFICATION_PARKING
The vehicle starts or ends parking.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:201
bool isOpposite
whether this an opposite-direction stop
Definition MSStop.h:87
double getLatDist() const
Definition MSVehicle.h:1607
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
const std::vector< double > & getFurtherLanesPosLat() const
Definition MSVehicle.h:843
void setTentativeLaneAndPosition(MSLane *lane, double pos, double posLat=0)
set tentative lane and position during insertion to ensure that all cfmodels work (some of them requi...
MSAbstractLaneChangeModel & getLaneChangeModel()
int influenceChangeDecision(int state)
allow TraCI to influence a lane change decision
void fixPosition()
repair errors in vehicle position after changing between internal edges
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
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
double lateralDistanceToLane(const int offset) const
Get the minimal lateral distance required to move fully onto the lane at given offset.
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.
void switchOffSignal(int signal)
Switches the given signal off.
Definition MSVehicle.h:1177
@ VEH_SIGNAL_BLINKER_RIGHT
Right blinker lights are switched on.
Definition MSVehicle.h:1116
@ VEH_SIGNAL_BLINKER_LEFT
Left blinker lights are switched on.
Definition MSVehicle.h:1118
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition MSVehicle.h:581
void enterLaneAtLaneChange(MSLane *enteredLane)
Update when the vehicle enters a new lane in the laneChange step.
Influencer & getInfluencer()
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
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
Definition MSVehicle.h:413
bool congested() const
double getSpeed() const
Returns the vehicle's current speed.
Definition MSVehicle.h:490
const std::vector< MSLane * > & getFurtherLanes() const
Definition MSVehicle.h:839
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
bool hasInfluencer() const
whether the vehicle is individually influenced (via TraCI or special parameters)
Definition MSVehicle.h:1706
void switchOnSignal(int signal)
Switches the given signal on.
Definition MSVehicle.h:1169
void updateDriveItems()
Check whether the drive items (myLFLinkLanes) are up to date, and update them if required.
double getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
const std::string & getID() const
Returns the name of the vehicle type.
double getMinGap() const
Get the free space in front of vehicles of this class.
bool wasSet(long long int what) const
Returns whether the given parameter was set.
double getMaxSpeedLat() const
Get vehicle's maximum lateral speed [m/s].
const SUMOVTypeParameter & getParameter() const
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
A storage for options typed value containers)
Definition OptionsCont.h:92
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
double x() const
Returns the x-position.
Definition Position.h:52
double y() const
Returns the y-position.
Definition Position.h:57
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
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.
std::map< SumoXMLAttr, std::string > SubParams
sub-model parameters
const SubParams & getLCParams() const
Returns the LC parameter.
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter
#define UNUSED_PARAMETER(x)
#define DEBUG_COND
Definition json.hpp:5639
#define M_PI
Definition odrSpiral.cpp:45