Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSVehicle.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/****************************************************************************/
31// Representation of a vehicle in the micro simulation
32/****************************************************************************/
33#include <config.h>
34
35#include <iostream>
36#include <cassert>
37#include <cmath>
38#include <cstdlib>
39#include <algorithm>
40#include <map>
41#include <memory>
71#include "MSEdgeControl.h"
72#include "MSVehicleControl.h"
73#include "MSInsertionControl.h"
74#include "MSVehicleTransfer.h"
75#include "MSGlobals.h"
76#include "MSJunctionLogic.h"
77#include "MSStop.h"
78#include "MSStoppingPlace.h"
79#include "MSParkingArea.h"
80#include "MSMoveReminder.h"
81#include "MSLane.h"
82#include "MSJunction.h"
83#include "MSEdge.h"
84#include "MSVehicleType.h"
85#include "MSNet.h"
86#include "MSRoute.h"
87#include "MSLeaderInfo.h"
88#include "MSDriverState.h"
89#include "MSVehicle.h"
90
91
92//#define DEBUG_PLAN_MOVE
93//#define DEBUG_PLAN_MOVE_LEADERINFO
94//#define DEBUG_CHECKREWINDLINKLANES
95//#define DEBUG_EXEC_MOVE
96//#define DEBUG_FURTHER
97//#define DEBUG_SETFURTHER
98//#define DEBUG_TARGET_LANE
99//#define DEBUG_STOPS
100//#define DEBUG_BESTLANES
101//#define DEBUG_IGNORE_RED
102//#define DEBUG_ACTIONSTEPS
103//#define DEBUG_NEXT_TURN
104//#define DEBUG_TRACI
105//#define DEBUG_REVERSE_BIDI
106//#define DEBUG_EXTRAPOLATE_DEPARTPOS
107//#define DEBUG_REMOTECONTROL
108//#define DEBUG_MOVEREMINDERS
109//#define DEBUG_COND (getID() == "ego")
110//#define DEBUG_COND (true)
111#define DEBUG_COND (isSelected())
112//#define DEBUG_COND2(obj) (obj->getID() == "ego")
113#define DEBUG_COND2(obj) (obj->isSelected())
114
115//#define PARALLEL_STOPWATCH
116
117
118#define STOPPING_PLACE_OFFSET 0.5
119
120#define CRLL_LOOK_AHEAD 5
121
122#define JUNCTION_BLOCKAGE_TIME 5 // s
123
124// @todo Calibrate with real-world values / make configurable
125#define DIST_TO_STOPLINE_EXPECT_PRIORITY 1.0
126
127#define NUMERICAL_EPS_SPEED (0.1 * NUMERICAL_EPS * TS)
128
129// ===========================================================================
130// static value definitions
131// ===========================================================================
132std::vector<MSLane*> MSVehicle::myEmptyLaneVector;
133
134
135// ===========================================================================
136// method definitions
137// ===========================================================================
138/* -------------------------------------------------------------------------
139 * methods of MSVehicle::State
140 * ----------------------------------------------------------------------- */
142 myPos = state.myPos;
143 mySpeed = state.mySpeed;
144 myPosLat = state.myPosLat;
145 myBackPos = state.myBackPos;
148}
149
150
153 myPos = state.myPos;
154 mySpeed = state.mySpeed;
155 myPosLat = state.myPosLat;
156 myBackPos = state.myBackPos;
157 myPreviousSpeed = state.myPreviousSpeed;
158 myLastCoveredDist = state.myLastCoveredDist;
159 return *this;
160}
161
162
163bool
165 return (myPos != state.myPos ||
166 mySpeed != state.mySpeed ||
167 myPosLat != state.myPosLat ||
168 myLastCoveredDist != state.myLastCoveredDist ||
169 myPreviousSpeed != state.myPreviousSpeed ||
170 myBackPos != state.myBackPos);
171}
172
173
174MSVehicle::State::State(double pos, double speed, double posLat, double backPos, double previousSpeed) :
175 myPos(pos), mySpeed(speed), myPosLat(posLat), myBackPos(backPos), myPreviousSpeed(previousSpeed), myLastCoveredDist(SPEED2DIST(speed)) {}
176
177
178
179/* -------------------------------------------------------------------------
180 * methods of MSVehicle::WaitingTimeCollector
181 * ----------------------------------------------------------------------- */
183
184
187 assert(memorySpan <= myMemorySize);
188 if (memorySpan == -1) {
189 memorySpan = myMemorySize;
190 }
191 SUMOTime totalWaitingTime = 0;
192 for (const auto& interval : myWaitingIntervals) {
193 if (interval.second >= memorySpan) {
194 if (interval.first >= memorySpan) {
195 break;
196 } else {
197 totalWaitingTime += memorySpan - interval.first;
198 }
199 } else {
200 totalWaitingTime += interval.second - interval.first;
201 }
202 }
203 return totalWaitingTime;
204}
205
206
207void
209 auto i = myWaitingIntervals.begin();
210 const auto end = myWaitingIntervals.end();
211 const bool startNewInterval = i == end || (i->first != 0);
212 while (i != end) {
213 i->first += dt;
214 if (i->first >= myMemorySize) {
215 break;
216 }
217 i->second += dt;
218 i++;
219 }
220
221 // remove intervals beyond memorySize
222 auto d = std::distance(i, end);
223 while (d > 0) {
224 myWaitingIntervals.pop_back();
225 d--;
226 }
227
228 if (!waiting) {
229 return;
230 } else if (!startNewInterval) {
231 myWaitingIntervals.begin()->first = 0;
232 } else {
233 myWaitingIntervals.push_front(std::make_pair(0, dt));
234 }
235 return;
236}
237
238
239const std::string
241 std::ostringstream state;
242 state << myMemorySize << " " << myWaitingIntervals.size();
243 for (const auto& interval : myWaitingIntervals) {
244 state << " " << interval.first << " " << interval.second;
245 }
246 return state.str();
247}
248
249
250void
252 std::istringstream is(state);
253 int numIntervals;
254 SUMOTime begin, end;
255 is >> myMemorySize >> numIntervals;
256 while (numIntervals-- > 0) {
257 is >> begin >> end;
258 myWaitingIntervals.emplace_back(begin, end);
259 }
260}
261
262
263/* -------------------------------------------------------------------------
264 * methods of MSVehicle::Influencer::GapControlState
265 * ----------------------------------------------------------------------- */
266void
268// std::cout << "GapControlVehStateListener::vehicleStateChanged() vehicle=" << vehicle->getID() << ", to=" << to << std::endl;
269 switch (to) {
273 // Vehicle left road
274// Look up reference vehicle in refVehMap and in case deactivate corresponding gap control
275 const MSVehicle* msVeh = static_cast<const MSVehicle*>(vehicle);
276// std::cout << "GapControlVehStateListener::vehicleStateChanged() vehicle=" << vehicle->getID() << " left the road." << std::endl;
277 if (GapControlState::refVehMap.find(msVeh) != end(GapControlState::refVehMap)) {
278// std::cout << "GapControlVehStateListener::deactivating ref vehicle=" << vehicle->getID() << std::endl;
279 GapControlState::refVehMap[msVeh]->deactivate();
280 }
281 }
282 break;
283 default:
284 {};
285 // do nothing, vehicle still on road
286 }
287}
288
289std::map<const MSVehicle*, MSVehicle::Influencer::GapControlState*>
291
293
295 tauOriginal(-1), tauCurrent(-1), tauTarget(-1), addGapCurrent(-1), addGapTarget(-1),
296 remainingDuration(-1), changeRate(-1), maxDecel(-1), referenceVeh(nullptr), active(false), gapAttained(false), prevLeader(nullptr),
297 lastUpdate(-1), timeHeadwayIncrement(0.0), spaceHeadwayIncrement(0.0) {}
298
299
303
304void
306 if (MSNet::hasInstance()) {
307 if (myVehStateListener == nullptr) {
308 //std::cout << "GapControlState::init()" << std::endl;
309 myVehStateListener = new GapControlVehStateListener();
310 MSNet::getInstance()->addVehicleStateListener(myVehStateListener);
311 }
312 } else {
313 WRITE_ERROR("MSVehicle::Influencer::GapControlState::init(): No MSNet instance found!")
314 }
315}
316
317void
319 if (myVehStateListener != nullptr) {
320 MSNet::getInstance()->removeVehicleStateListener(myVehStateListener);
321 delete myVehStateListener;
322 myVehStateListener = nullptr;
323 }
324}
325
326void
327MSVehicle::Influencer::GapControlState::activate(double tauOrig, double tauNew, double additionalGap, double dur, double rate, double decel, const MSVehicle* refVeh) {
329 WRITE_ERROR(TL("No gap control available for meso."))
330 } else {
331 // always deactivate control before activating (triggers clean-up of refVehMap)
332// std::cout << "activate gap control with refVeh=" << (refVeh==nullptr? "NULL" : refVeh->getID()) << std::endl;
333 tauOriginal = tauOrig;
334 tauCurrent = tauOrig;
335 tauTarget = tauNew;
336 addGapCurrent = 0.0;
337 addGapTarget = additionalGap;
338 remainingDuration = dur;
339 changeRate = rate;
340 maxDecel = decel;
341 referenceVeh = refVeh;
342 active = true;
343 gapAttained = false;
344 prevLeader = nullptr;
345 lastUpdate = SIMSTEP - DELTA_T;
346 timeHeadwayIncrement = changeRate * TS * (tauTarget - tauOriginal);
347 spaceHeadwayIncrement = changeRate * TS * addGapTarget;
348
349 if (referenceVeh != nullptr) {
350 // Add refVeh to refVehMap
351 GapControlState::refVehMap[referenceVeh] = this;
352 }
353 }
354}
355
356void
358 active = false;
359 if (referenceVeh != nullptr) {
360 // Remove corresponding refVehMapEntry if appropriate
361 GapControlState::refVehMap.erase(referenceVeh);
362 referenceVeh = nullptr;
363 }
364}
365
366
367/* -------------------------------------------------------------------------
368 * methods of MSVehicle::Influencer
369 * ----------------------------------------------------------------------- */
391
392
394
395void
397 GapControlState::init();
398}
399
400void
402 GapControlState::cleanup();
403}
404
405void
406MSVehicle::Influencer::setSpeedTimeLine(const std::vector<std::pair<SUMOTime, double> >& speedTimeLine) {
407 mySpeedAdaptationStarted = true;
408 mySpeedTimeLine = speedTimeLine;
409}
410
411void
412MSVehicle::Influencer::activateGapController(double originalTau, double newTimeHeadway, double newSpaceHeadway, double duration, double changeRate, double maxDecel, MSVehicle* refVeh) {
413 if (myGapControlState == nullptr) {
414 myGapControlState = std::make_shared<GapControlState>();
415 init(); // only does things on first call
416 }
417 myGapControlState->activate(originalTau, newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel, refVeh);
418}
419
420void
422 if (myGapControlState != nullptr && myGapControlState->active) {
423 myGapControlState->deactivate();
424 }
425}
426
427void
428MSVehicle::Influencer::setLaneTimeLine(const std::vector<std::pair<SUMOTime, int> >& laneTimeLine) {
429 myLaneTimeLine = laneTimeLine;
430}
431
432
433void
435 for (auto& item : myLaneTimeLine) {
436 item.second += indexShift;
437 }
438}
439
440
441void
443 myLatDist = latDist;
444}
445
446int
448 return (1 * myConsiderSafeVelocity +
449 2 * myConsiderMaxAcceleration +
450 4 * myConsiderMaxDeceleration +
451 8 * myRespectJunctionPriority +
452 16 * myEmergencyBrakeRedLight +
453 32 * !myRespectJunctionLeaderPriority + // inverted!
454 64 * !myConsiderSpeedLimit // inverted!
455 );
456}
457
458
459int
461 return (1 * myStrategicLC +
462 4 * myCooperativeLC +
463 16 * mySpeedGainLC +
464 64 * myRightDriveLC +
465 256 * myTraciLaneChangePriority +
466 1024 * mySublaneLC);
467}
468
471 SUMOTime duration = -1;
472 for (std::vector<std::pair<SUMOTime, int>>::iterator i = myLaneTimeLine.begin(); i != myLaneTimeLine.end(); ++i) {
473 if (duration < 0) {
474 duration = i->first;
475 } else {
476 duration -= i->first;
477 }
478 }
479 return -duration;
480}
481
484 if (!myLaneTimeLine.empty()) {
485 return myLaneTimeLine.back().first;
486 } else {
487 return -1;
488 }
489}
490
491
492double
493MSVehicle::Influencer::influenceSpeed(SUMOTime currentTime, double speed, double vSafe, double vMin, double vMax) {
494 // remove leading commands which are no longer valid
495 while (mySpeedTimeLine.size() == 1 || (mySpeedTimeLine.size() > 1 && currentTime > mySpeedTimeLine[1].first)) {
496 mySpeedTimeLine.erase(mySpeedTimeLine.begin());
497 }
498
499 if (!(mySpeedTimeLine.size() < 2 || currentTime < mySpeedTimeLine[0].first)) {
500 // Speed advice is active -> compute new speed according to speedTimeLine
501 if (!mySpeedAdaptationStarted) {
502 mySpeedTimeLine[0].second = speed;
503 mySpeedAdaptationStarted = true;
504 }
505 currentTime += DELTA_T; // start slowing down in the step in which this command was issued (the input value of currentTime still reflects the previous step)
506 const double td = MIN2(1.0, STEPS2TIME(currentTime - mySpeedTimeLine[0].first) / MAX2(TS, STEPS2TIME(mySpeedTimeLine[1].first - mySpeedTimeLine[0].first)));
507
508 speed = mySpeedTimeLine[0].second - (mySpeedTimeLine[0].second - mySpeedTimeLine[1].second) * td;
509 if (myConsiderSafeVelocity) {
510 speed = MIN2(speed, vSafe);
511 }
512 if (myConsiderMaxAcceleration) {
513 speed = MIN2(speed, vMax);
514 }
515 if (myConsiderMaxDeceleration) {
516 speed = MAX2(speed, vMin);
517 }
518 }
519 return speed;
520}
521
522double
523MSVehicle::Influencer::gapControlSpeed(SUMOTime currentTime, const SUMOVehicle* veh, double speed, double vSafe, double vMin, double vMax) {
524#ifdef DEBUG_TRACI
525 if DEBUG_COND2(veh) {
526 std::cout << currentTime << " Influencer::gapControlSpeed(): speed=" << speed
527 << ", vSafe=" << vSafe
528 << ", vMin=" << vMin
529 << ", vMax=" << vMax
530 << std::endl;
531 }
532#endif
533 double gapControlSpeed = speed;
534 if (myGapControlState != nullptr && myGapControlState->active) {
535 // Determine leader and the speed that would be chosen by the gap controller
536 const double currentSpeed = veh->getSpeed();
537 const MSVehicle* msVeh = dynamic_cast<const MSVehicle*>(veh);
538 assert(msVeh != nullptr);
539 const double desiredTargetTimeSpacing = myGapControlState->tauTarget * currentSpeed;
540 std::pair<const MSVehicle*, double> leaderInfo;
541 if (myGapControlState->referenceVeh == nullptr) {
542 // No reference vehicle specified -> use current leader as reference
543 const double brakeGap = msVeh->getBrakeGap(true);
544 leaderInfo = msVeh->getLeader(MAX2(desiredTargetTimeSpacing, myGapControlState->addGapCurrent) + MAX2(brakeGap, 20.0));
545#ifdef DEBUG_TRACI
546 if DEBUG_COND2(veh) {
547 std::cout << " --- no refVeh; myGapControlState->addGapCurrent: " << myGapControlState->addGapCurrent << ", brakeGap: " << brakeGap << " in simstep: " << SIMSTEP << std::endl;
548 }
549#endif
550 } else {
551 // Control gap wrt reference vehicle
552 const MSVehicle* leader = myGapControlState->referenceVeh;
553 double dist = msVeh->getDistanceToPosition(leader->getPositionOnLane(), leader->getLane()) - leader->getLength();
554 if (dist > 100000) {
555 // Reference vehicle was not found downstream the ego's route
556 // Maybe, it is behind the ego vehicle
557 dist = - leader->getDistanceToPosition(msVeh->getPositionOnLane(), msVeh->getLane()) - leader->getLength();
558#ifdef DEBUG_TRACI
559 if DEBUG_COND2(veh) {
560 if (dist < -100000) {
561 // also the ego vehicle is not ahead of the reference vehicle -> no CF-relation
562 std::cout << " Ego and reference vehicle are not in CF relation..." << std::endl;
563 } else {
564 std::cout << " Reference vehicle is behind ego..." << std::endl;
565 }
566 }
567#endif
568 }
569 leaderInfo = std::make_pair(leader, dist - msVeh->getVehicleType().getMinGap());
570 }
571 const double fakeDist = MAX2(0.0, leaderInfo.second - myGapControlState->addGapCurrent);
572#ifdef DEBUG_TRACI
573 if DEBUG_COND2(veh) {
574 const double desiredCurrentSpacing = myGapControlState->tauCurrent * currentSpeed;
575 std::cout << " Gap control active:"
576 << " currentSpeed=" << currentSpeed
577 << ", desiredTargetTimeSpacing=" << desiredTargetTimeSpacing
578 << ", desiredCurrentSpacing=" << desiredCurrentSpacing
579 << ", leader=" << (leaderInfo.first == nullptr ? "NULL" : leaderInfo.first->getID())
580 << ", dist=" << leaderInfo.second
581 << ", fakeDist=" << fakeDist
582 << ",\n tauOriginal=" << myGapControlState->tauOriginal
583 << ", tauTarget=" << myGapControlState->tauTarget
584 << ", tauCurrent=" << myGapControlState->tauCurrent
585 << std::endl;
586 }
587#endif
588 if (leaderInfo.first != nullptr) {
589 if (myGapControlState->prevLeader != nullptr && myGapControlState->prevLeader != leaderInfo.first) {
590 // TODO: The leader changed. What to do?
591 }
592 // Remember leader
593 myGapControlState->prevLeader = leaderInfo.first;
594
595 // Calculate desired following speed assuming the alternative headway time
596 MSCFModel* cfm = (MSCFModel*) & (msVeh->getVehicleType().getCarFollowModel());
597 const double origTau = cfm->getHeadwayTime();
598 cfm->setHeadwayTime(myGapControlState->tauCurrent);
599 gapControlSpeed = MIN2(gapControlSpeed,
600 cfm->followSpeed(msVeh, currentSpeed, fakeDist, leaderInfo.first->getSpeed(), leaderInfo.first->getCurrentApparentDecel(), leaderInfo.first));
601 cfm->setHeadwayTime(origTau);
602#ifdef DEBUG_TRACI
603 if DEBUG_COND2(veh) {
604 std::cout << " -> gapControlSpeed=" << gapControlSpeed;
605 if (myGapControlState->maxDecel > 0) {
606 std::cout << ", with maxDecel bound: " << MAX2(gapControlSpeed, currentSpeed - TS * myGapControlState->maxDecel);
607 }
608 std::cout << std::endl;
609 }
610#endif
611 if (myGapControlState->maxDecel > 0) {
612 gapControlSpeed = MAX2(gapControlSpeed, currentSpeed - TS * myGapControlState->maxDecel);
613 }
614 }
615
616 // Update gap controller
617 // Check (1) if the gap control has established the desired gap,
618 // and (2) if it has maintained active for the given duration afterwards
619 if (myGapControlState->lastUpdate < currentTime) {
620#ifdef DEBUG_TRACI
621 if DEBUG_COND2(veh) {
622 std::cout << " Updating GapControlState." << std::endl;
623 }
624#endif
625 if (myGapControlState->tauCurrent == myGapControlState->tauTarget && myGapControlState->addGapCurrent == myGapControlState->addGapTarget) {
626 if (!myGapControlState->gapAttained) {
627 // Check if the desired gap was established (add the POSITION_EPS to avoid infinite asymptotic behavior without having established the gap)
628 myGapControlState->gapAttained = leaderInfo.first == nullptr || leaderInfo.second > MAX2(desiredTargetTimeSpacing, myGapControlState->addGapTarget) - POSITION_EPS;
629#ifdef DEBUG_TRACI
630 if DEBUG_COND2(veh) {
631 if (myGapControlState->gapAttained) {
632 std::cout << " Target gap was established." << std::endl;
633 }
634 }
635#endif
636 } else {
637 // Count down remaining time if desired gap was established
638 myGapControlState->remainingDuration -= TS;
639#ifdef DEBUG_TRACI
640 if DEBUG_COND2(veh) {
641 std::cout << " Gap control remaining duration: " << myGapControlState->remainingDuration << std::endl;
642 }
643#endif
644 if (myGapControlState->remainingDuration <= 0) {
645#ifdef DEBUG_TRACI
646 if DEBUG_COND2(veh) {
647 std::cout << " Gap control duration expired, deactivating control." << std::endl;
648 }
649#endif
650 // switch off gap control
651 myGapControlState->deactivate();
652 }
653 }
654 } else {
655 // Adjust current headway values
656 myGapControlState->tauCurrent = MIN2(myGapControlState->tauCurrent + myGapControlState->timeHeadwayIncrement, myGapControlState->tauTarget);
657 myGapControlState->addGapCurrent = MIN2(myGapControlState->addGapCurrent + myGapControlState->spaceHeadwayIncrement, myGapControlState->addGapTarget);
658 }
659 }
660 if (myConsiderSafeVelocity) {
661 gapControlSpeed = MIN2(gapControlSpeed, vSafe);
662 }
663 if (myConsiderMaxAcceleration) {
664 gapControlSpeed = MIN2(gapControlSpeed, vMax);
665 }
666 if (myConsiderMaxDeceleration) {
667 gapControlSpeed = MAX2(gapControlSpeed, vMin);
668 }
669 return MIN2(speed, gapControlSpeed);
670 } else {
671 return speed;
672 }
673}
674
675double
677 return myOriginalSpeed;
678}
679
680void
682 myOriginalSpeed = speed;
683}
684
685
686int
687MSVehicle::Influencer::influenceChangeDecision(const SUMOTime currentTime, const MSEdge& currentEdge, const int currentLaneIndex, int state) {
688 // remove leading commands which are no longer valid
689 while (myLaneTimeLine.size() == 1 || (myLaneTimeLine.size() > 1 && currentTime > myLaneTimeLine[1].first)) {
690 myLaneTimeLine.erase(myLaneTimeLine.begin());
691 }
692 ChangeRequest changeRequest = REQUEST_NONE;
693 // do nothing if the time line does not apply for the current time
694 if (myLaneTimeLine.size() >= 2 && currentTime >= myLaneTimeLine[0].first) {
695 const int destinationLaneIndex = myLaneTimeLine[1].second;
696 if (destinationLaneIndex < (int)currentEdge.getLanes().size()) {
697 if (currentLaneIndex > destinationLaneIndex) {
698 changeRequest = REQUEST_RIGHT;
699 } else if (currentLaneIndex < destinationLaneIndex) {
700 changeRequest = REQUEST_LEFT;
701 } else {
702 changeRequest = REQUEST_HOLD;
703 }
704 } else if (currentEdge.getLanes().back()->getOpposite() != nullptr) { // change to opposite direction driving
705 changeRequest = REQUEST_LEFT;
706 state = state | LCA_TRACI;
707 }
708 }
709 // check whether the current reason shall be canceled / overridden
710 if ((state & LCA_WANTS_LANECHANGE_OR_STAY) != 0) {
711 // flags for the current reason
713 if ((state & LCA_TRACI) != 0 && myLatDist != 0) {
714 // security checks
715 if ((myTraciLaneChangePriority == LCP_ALWAYS)
716 || (myTraciLaneChangePriority == LCP_NOOVERLAP && (state & LCA_OVERLAPPING) == 0)) {
717 state &= ~(LCA_BLOCKED | LCA_OVERLAPPING);
718 }
719 // continue sublane change manoeuvre
720 return state;
721 } else if ((state & LCA_STRATEGIC) != 0) {
722 mode = myStrategicLC;
723 } else if ((state & LCA_COOPERATIVE) != 0) {
724 mode = myCooperativeLC;
725 } else if ((state & LCA_SPEEDGAIN) != 0) {
726 mode = mySpeedGainLC;
727 } else if ((state & LCA_KEEPRIGHT) != 0) {
728 mode = myRightDriveLC;
729 } else if ((state & LCA_SUBLANE) != 0) {
730 mode = mySublaneLC;
731 } else if ((state & LCA_TRACI) != 0) {
732 mode = LC_NEVER;
733 } else {
734 WRITE_WARNINGF(TL("Lane change model did not provide a reason for changing (state=%, time=%\n"), toString(state), time2string(currentTime));
735 }
736 if (mode == LC_NEVER) {
737 // cancel all lcModel requests
738 state &= ~LCA_WANTS_LANECHANGE_OR_STAY;
739 state &= ~LCA_URGENT;
740 if (changeRequest == REQUEST_NONE) {
741 // also remove all reasons except TRACI
742 state &= ~LCA_CHANGE_REASONS | LCA_TRACI;
743 }
744 } else if (mode == LC_NOCONFLICT && changeRequest != REQUEST_NONE) {
745 if (
746 ((state & LCA_LEFT) != 0 && changeRequest != REQUEST_LEFT) ||
747 ((state & LCA_RIGHT) != 0 && changeRequest != REQUEST_RIGHT) ||
748 ((state & LCA_STAY) != 0 && changeRequest != REQUEST_HOLD)) {
749 // cancel conflicting lcModel request
750 state &= ~LCA_WANTS_LANECHANGE_OR_STAY;
751 state &= ~LCA_URGENT;
752 }
753 } else if (mode == LC_ALWAYS) {
754 // ignore any TraCI requests
755 return state;
756 }
757 }
758 // apply traci requests
759 if (changeRequest == REQUEST_NONE) {
760 return state;
761 } else {
762 state |= LCA_TRACI;
763 // security checks
764 if ((myTraciLaneChangePriority == LCP_ALWAYS)
765 || (myTraciLaneChangePriority == LCP_NOOVERLAP && (state & LCA_OVERLAPPING) == 0)) {
766 state &= ~(LCA_BLOCKED | LCA_OVERLAPPING);
767 }
768 if (changeRequest != REQUEST_HOLD && myTraciLaneChangePriority != LCP_OPPORTUNISTIC) {
769 state |= LCA_URGENT;
770 }
771 switch (changeRequest) {
772 case REQUEST_HOLD:
773 return state | LCA_STAY;
774 case REQUEST_LEFT:
775 return state | LCA_LEFT;
776 case REQUEST_RIGHT:
777 return state | LCA_RIGHT;
778 default:
779 throw ProcessError(TL("should not happen"));
780 }
781 }
782}
783
784
785double
787 assert(myLaneTimeLine.size() >= 2);
788 assert(currentTime >= myLaneTimeLine[0].first);
789 return STEPS2TIME(myLaneTimeLine[1].first - currentTime);
790}
791
792
793void
795 myConsiderSafeVelocity = ((speedMode & 1) != 0);
796 myConsiderMaxAcceleration = ((speedMode & 2) != 0);
797 myConsiderMaxDeceleration = ((speedMode & 4) != 0);
798 myRespectJunctionPriority = ((speedMode & 8) != 0);
799 myEmergencyBrakeRedLight = ((speedMode & 16) != 0);
800 myRespectJunctionLeaderPriority = ((speedMode & 32) == 0); // inverted!
801 myConsiderSpeedLimit = ((speedMode & 64) == 0); // inverted!
802}
803
804
805void
807 myStrategicLC = (LaneChangeMode)(value & (1 + 2));
808 myCooperativeLC = (LaneChangeMode)((value & (4 + 8)) >> 2);
809 mySpeedGainLC = (LaneChangeMode)((value & (16 + 32)) >> 4);
810 myRightDriveLC = (LaneChangeMode)((value & (64 + 128)) >> 6);
811 myTraciLaneChangePriority = (TraciLaneChangePriority)((value & (256 + 512)) >> 8);
812 mySublaneLC = (LaneChangeMode)((value & (1024 + 2048)) >> 10);
813}
814
815
816void
817MSVehicle::Influencer::setRemoteControlled(Position xyPos, MSLane* l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector& route, SUMOTime t) {
818 myRemoteXYPos = xyPos;
819 myRemoteLane = l;
820 myRemotePos = pos;
821 myRemotePosLat = posLat;
822 myRemoteAngle = angle;
823 myRemoteEdgeOffset = edgeOffset;
824 myRemoteRoute = route;
825 myLastRemoteAccess = t;
826}
827
828
829bool
831 return myLastRemoteAccess == MSNet::getInstance()->getCurrentTimeStep();
832}
833
834
835bool
837 return myLastRemoteAccess >= t - TIME2STEPS(10);
838}
839
840
841void
843 if (myRemoteRoute.size() != 0 && myRemoteRoute != v->getRoute().getEdges()) {
844 // only replace route at this time if the vehicle is moving with the flow
845 const bool isForward = v->getLane() != 0 && &v->getLane()->getEdge() == myRemoteRoute[0];
846#ifdef DEBUG_REMOTECONTROL
847 std::cout << SIMSTEP << " updateRemoteControlRoute veh=" << v->getID() << " old=" << toString(v->getRoute().getEdges()) << " new=" << toString(myRemoteRoute) << " fwd=" << isForward << "\n";
848#endif
849 if (isForward) {
850 v->replaceRouteEdges(myRemoteRoute, -1, 0, "traci:moveToXY", true);
851 v->updateBestLanes();
852 }
853 }
854}
855
856
857void
859 const bool wasOnRoad = v->isOnRoad();
860 const bool withinLane = myRemoteLane != nullptr && fabs(myRemotePosLat) < 0.5 * (myRemoteLane->getWidth() + v->getVehicleType().getWidth());
861 const bool keepLane = wasOnRoad && v->getLane() == myRemoteLane;
862 if (v->isOnRoad() && !(keepLane && withinLane)) {
863 if (myRemoteLane != nullptr && &v->getLane()->getEdge() == &myRemoteLane->getEdge()) {
864 // correct odometer which gets incremented via onRemovalFromNet->leaveLane
865 v->myOdometer -= v->getLane()->getLength();
866 }
869 }
870 if (myRemoteRoute.size() != 0 && myRemoteRoute != v->getRoute().getEdges()) {
871 // needed for the insertion step
872#ifdef DEBUG_REMOTECONTROL
873 std::cout << SIMSTEP << " postProcessRemoteControl veh=" << v->getID()
874 << "\n oldLane=" << Named::getIDSecure(v->getLane())
875 << " oldRoute=" << toString(v->getRoute().getEdges())
876 << "\n newLane=" << Named::getIDSecure(myRemoteLane)
877 << " newRoute=" << toString(myRemoteRoute)
878 << " newRouteEdge=" << myRemoteRoute[myRemoteEdgeOffset]->getID()
879 << "\n";
880#endif
881 // clear any prior stops because they cannot apply to the new route
882 const_cast<SUMOVehicleParameter&>(v->getParameter()).stops.clear();
883 v->replaceRouteEdges(myRemoteRoute, -1, 0, "traci:moveToXY", true);
884 myRemoteRoute.clear();
885 }
886 v->myCurrEdge = v->getRoute().begin() + myRemoteEdgeOffset;
887 if (myRemoteLane != nullptr && myRemotePos > myRemoteLane->getLength()) {
888 myRemotePos = myRemoteLane->getLength();
889 }
890 if (myRemoteLane != nullptr && withinLane) {
891 if (keepLane) {
892 // TODO this handles only the case when the new vehicle is completely on the edge
893 const bool needFurtherUpdate = v->myState.myPos < v->getVehicleType().getLength() && myRemotePos >= v->getVehicleType().getLength();
894 v->myState.myPos = myRemotePos;
895 v->myState.myPosLat = myRemotePosLat;
896 if (needFurtherUpdate) {
897 v->myState.myBackPos = v->updateFurtherLanes(v->myFurtherLanes, v->myFurtherLanesPosLat, std::vector<MSLane*>());
898 }
899 } else {
903 if (!v->isOnRoad()) {
904 MSVehicleTransfer::getInstance()->remove(v); // TODO may need optimization, this is linear in the number of vehicles in transfer
905 }
906 myRemoteLane->forceVehicleInsertion(v, myRemotePos, notify, myRemotePosLat);
907 v->updateBestLanes();
908 }
909 if (!wasOnRoad) {
910 v->drawOutsideNetwork(false);
911 }
912 //std::cout << "on road network p=" << myRemoteXYPos << " a=" << myRemoteAngle << " l=" << Named::getIDSecure(myRemoteLane) << " pos=" << myRemotePos << " posLat=" << myRemotePosLat << "\n";
913 myRemoteLane->requireCollisionCheck();
914 } else {
915 if (v->getDeparture() == NOT_YET_DEPARTED) {
916 v->onDepart();
917 }
918 v->drawOutsideNetwork(true);
919 // see updateState
920 double vNext = v->processTraCISpeedControl(
921 v->getMaxSpeed(), v->getSpeed());
922 v->setBrakingSignals(vNext);
924 v->myAcceleration = SPEED2ACCEL(vNext - v->getSpeed());
925 v->myState.mySpeed = vNext;
926 v->updateWaitingTime(vNext);
927 //std::cout << "outside network p=" << myRemoteXYPos << " a=" << myRemoteAngle << " l=" << Named::getIDSecure(myRemoteLane) << "\n";
928 }
929 // ensure that the position is correct (i.e. when the lanePosition is ambiguous at corners)
930 v->setRemoteState(myRemoteXYPos);
931 v->setAngle(GeomHelper::fromNaviDegree(myRemoteAngle));
932}
933
934
935double
937 if (veh->getPosition() == Position::INVALID) {
938 return oldSpeed;
939 }
940 double dist = veh->getPosition().distanceTo2D(myRemoteXYPos);
941 if (myRemoteLane != nullptr) {
942 // if the vehicles is frequently placed on a new edge, the route may
943 // consist only of a single edge. In this case the new edge may not be
944 // on the route so distAlongRoute will be double::max.
945 // In this case we still want a sensible speed value
946 const double distAlongRoute = veh->getDistanceToPosition(myRemotePos, myRemoteLane);
947 if (distAlongRoute != std::numeric_limits<double>::max()) {
948 dist = distAlongRoute;
949 }
950 }
951 //std::cout << SIMTIME << " veh=" << veh->getID() << " oldPos=" << veh->getPosition() << " traciPos=" << myRemoteXYPos << " dist=" << dist << "\n";
952 const double minSpeed = myConsiderMaxDeceleration ?
953 veh->getCarFollowModel().minNextSpeedEmergency(oldSpeed, veh) : 0;
954 const double maxSpeed = (myRemoteLane != nullptr
955 ? myRemoteLane->getVehicleMaxSpeed(veh)
956 : (veh->getLane() != nullptr
957 ? veh->getLane()->getVehicleMaxSpeed(veh)
958 : veh->getMaxSpeed()));
959 return MIN2(maxSpeed, MAX2(minSpeed, DIST2SPEED(dist)));
960}
961
962
963double
965 double dist = 0;
966 if (myRemoteLane == nullptr) {
967 dist = veh->getPosition().distanceTo2D(myRemoteXYPos);
968 } else {
969 // if the vehicles is frequently placed on a new edge, the route may
970 // consist only of a single edge. In this case the new edge may not be
971 // on the route so getDistanceToPosition will return double::max.
972 // In this case we would rather not move the vehicle in executeMove
973 // (updateState) as it would result in emergency braking
974 dist = veh->getDistanceToPosition(myRemotePos, myRemoteLane);
975 }
976 if (dist == std::numeric_limits<double>::max()) {
977 return 0;
978 } else {
979 if (DIST2SPEED(dist) > veh->getMaxSpeed() * 1.1) {
980 WRITE_WARNINGF(TL("Vehicle '%' moved by TraCI from % to % (dist %) with implied speed of % (exceeding maximum speed %). time=%."),
981 veh->getID(), veh->getPosition(), myRemoteXYPos, dist, DIST2SPEED(dist), veh->getMaxSpeed(), time2string(SIMSTEP));
982 // some sanity check here
983 dist = MIN2(dist, SPEED2DIST(veh->getMaxSpeed() * 2));
984 }
985 return dist;
986 }
987}
988
989
990/* -------------------------------------------------------------------------
991 * MSVehicle-methods
992 * ----------------------------------------------------------------------- */
994 MSVehicleType* type, const double speedFactor) :
995 MSBaseVehicle(pars, route, type, speedFactor),
996 myWaitingTime(0),
998 myTimeLoss(0),
999 myState(0, 0, 0, 0, 0),
1000 myDriverState(nullptr),
1001 myActionStep(true),
1003 myLane(nullptr),
1004 myLaneChangeModel(nullptr),
1005 myLastBestLanesEdge(nullptr),
1007 myAcceleration(0),
1008 myNextTurn(0., nullptr),
1009 mySignals(0),
1010 myAmOnNet(false),
1011 myAmIdling(false),
1013 myAngle(0),
1014 myRawAngle(0),
1016 myStopDist(std::numeric_limits<double>::max()),
1017 myStopSpeed(std::numeric_limits<double>::max()),
1023 myTimeSinceStartup(TIME2STEPS(3600 * 24)),
1024 myHaveStoppedFor(nullptr),
1025 myInfluencer(nullptr) {
1028}
1029
1030
1041
1042
1043void
1045 for (MSLane* further : myFurtherLanes) {
1046 further->resetPartialOccupation(this);
1047 if (further->getBidiLane() != nullptr
1048 && (!isRailway(getVClass()) || (further->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
1049 further->getBidiLane()->resetPartialOccupation(this);
1050 }
1051 }
1052 if (myLaneChangeModel != nullptr) {
1056 // still needed when calling resetPartialOccupation (getShadowLane) and when removing
1057 // approach information from parallel links
1058 }
1059 myFurtherLanes.clear();
1060 myFurtherLanesPosLat.clear();
1061}
1062
1063
1064void
1066#ifdef DEBUG_ACTIONSTEPS
1067 if (DEBUG_COND) {
1068 std::cout << SIMTIME << " Removing vehicle '" << getID() << "' (reason: " << toString(reason) << ")" << std::endl;
1069 }
1070#endif
1073 leaveLane(reason);
1076 }
1077}
1078
1079
1080void
1087
1088
1089// ------------ interaction with the route
1090bool
1092 // note: not a const method because getDepartLane may call updateBestLanes
1093 if (!(*myCurrEdge)->isTazConnector()) {
1096 if ((*myCurrEdge)->getDepartLane(*this) == nullptr) {
1097 msg = "Invalid departLane definition for vehicle '" + getID() + "'.";
1098 if (myParameter->departLane >= (int)(*myCurrEdge)->getLanes().size()) {
1100 } else {
1102 }
1103 return false;
1104 }
1105 } else {
1106 if ((*myCurrEdge)->allowedLanes(getVClass(), ignoreTransientPermissions()) == nullptr) {
1107 msg = "Vehicle '" + getID() + "' is not allowed to depart on any lane of edge '" + (*myCurrEdge)->getID() + "'.";
1109 return false;
1110 }
1111 }
1113 msg = "Departure speed for vehicle '" + getID() + "' is too high for the vehicle type '" + myType->getID() + "'.";
1115 return false;
1116 }
1117 }
1119 return true;
1120}
1121
1122
1123bool
1125 return hasArrivedInternal(false);
1126}
1127
1128
1129bool
1130MSVehicle::hasArrivedInternal(bool oppositeTransformed) const {
1131 return ((myCurrEdge == myRoute->end() - 1 || (myParameter->arrivalEdge >= 0 && getRoutePosition() >= myParameter->arrivalEdge))
1132 && (myStops.empty() || myStops.front().edge != myCurrEdge || myStops.front().getSpeed() > 0)
1133 && ((myLaneChangeModel->isOpposite() && !oppositeTransformed) ? myLane->getLength() - myState.myPos : myState.myPos) > MIN2(myLane->getLength(), myArrivalPos) - POSITION_EPS
1134 && !isRemoteControlled());
1135}
1136
1137
1138bool
1139MSVehicle::replaceRoute(ConstMSRoutePtr newRoute, const std::string& info, bool onInit, int offset, bool addRouteStops, bool removeStops, std::string* msgReturn) {
1140 if (MSBaseVehicle::replaceRoute(newRoute, info, onInit, offset, addRouteStops, removeStops, msgReturn)) {
1141 // update best lanes (after stops were added)
1142 myLastBestLanesEdge = nullptr;
1144 updateBestLanes(true, onInit ? (*myCurrEdge)->getLanes().front() : 0);
1145 assert(!removeStops || haveValidStopEdges());
1146 if (myStops.size() == 0) {
1147 myStopDist = std::numeric_limits<double>::max();
1148 }
1149 return true;
1150 }
1151 return false;
1152}
1153
1154
1155// ------------ Interaction with move reminders
1156void
1157MSVehicle::workOnMoveReminders(double oldPos, double newPos, double newSpeed) {
1158 // This erasure-idiom works for all stl-sequence-containers
1159 // See Meyers: Effective STL, Item 9
1160 for (MoveReminderCont::iterator rem = myMoveReminders.begin(); rem != myMoveReminders.end();) {
1161 // XXX: calling notifyMove with newSpeed seems not the best choice. For the ballistic update, the average speed is calculated and used
1162 // although a higher order quadrature-formula might be more adequate.
1163 // For the euler case (where the speed is considered constant for each time step) it is conceivable that
1164 // the current calculations may lead to systematic errors for large time steps (compared to reality). Refs. #2579
1165 if (!rem->first->notifyMove(*this, oldPos + rem->second, newPos + rem->second, MAX2(0., newSpeed))) {
1166#ifdef _DEBUG
1167 if (myTraceMoveReminders) {
1168 traceMoveReminder("notifyMove", rem->first, rem->second, false);
1169 }
1170#endif
1171 rem = myMoveReminders.erase(rem);
1172 } else {
1173#ifdef _DEBUG
1174 if (myTraceMoveReminders) {
1175 traceMoveReminder("notifyMove", rem->first, rem->second, true);
1176 }
1177#endif
1178 ++rem;
1179 }
1180 }
1181 if (myEnergyParams != nullptr) {
1182 // TODO make the vehicle energy params a derived class which is a move reminder
1184 }
1185}
1186
1187
1188void
1190 updateWaitingTime(0.); // cf issue 2233
1191
1192 // vehicle move reminders
1193 for (const auto& rem : myMoveReminders) {
1194 rem.first->notifyIdle(*this);
1195 }
1196
1197 // lane move reminders - for aggregated values
1198 for (MSMoveReminder* rem : getLane()->getMoveReminders()) {
1199 rem->notifyIdle(*this);
1200 }
1201}
1202
1203// XXX: consider renaming...
1204void
1206 // save the old work reminders, patching the position information
1207 // add the information about the new offset to the old lane reminders
1208 const double oldLaneLength = myLane->getLength();
1209 for (auto& rem : myMoveReminders) {
1210 rem.second += oldLaneLength;
1211#ifdef _DEBUG
1212// if (rem->first==0) std::cout << "Null reminder (?!)" << std::endl;
1213// std::cout << "Adapted MoveReminder on lane " << ((rem->first->getLane()==0) ? "NULL" : rem->first->getLane()->getID()) <<" position to " << rem->second << std::endl;
1214 if (myTraceMoveReminders) {
1215 traceMoveReminder("adaptedPos", rem.first, rem.second, true);
1216 }
1217#endif
1218 }
1219 for (MSMoveReminder* const rem : enteredLane.getMoveReminders()) {
1220 addReminder(rem);
1221 }
1222}
1223
1224
1225// ------------ Other getter methods
1226double
1228 if (isParking() && getStops().begin()->parkingarea != nullptr) {
1229 return getStops().begin()->parkingarea->getVehicleSlope(*this);
1230 }
1231 if (myLane == nullptr) {
1232 return 0;
1233 }
1235 MSLane* centerLane = myLane;
1236 double centerPos = getPositionOnLane() - getLength() / 2;
1237 int furtherIndex = 0;
1238 while (centerPos < 0 && furtherIndex < (int)myFurtherLanes.size()) {
1239 centerLane = myFurtherLanes[furtherIndex];
1240 centerPos += centerLane->getLength();
1241 furtherIndex++;
1242 }
1243 return centerLane->getShape().slopeDegreeAtOffset(centerLane->interpolateLanePosToGeometryPos(centerPos));
1244 }
1245 const double posLat = myState.myPosLat; // @todo get rid of the '-'
1246 Position p1 = getPosition();
1248 if (p2 == Position::INVALID) {
1249 // Handle special case of vehicle's back reaching out of the network
1250 if (myFurtherLanes.size() > 0) {
1251 p2 = myFurtherLanes.back()->geometryPositionAtOffset(0, -myFurtherLanesPosLat.back());
1252 if (p2 == Position::INVALID) {
1253 // unsuitable lane geometry
1254 p2 = myLane->geometryPositionAtOffset(0, posLat);
1255 }
1256 } else {
1257 p2 = myLane->geometryPositionAtOffset(0, posLat);
1258 }
1259 }
1261}
1262
1263
1265MSVehicle::getPosition(const double offset) const {
1266 if (myLane == nullptr) {
1267 // when called in the context of GUI-Drawing, the simulation step is already incremented
1269 return myCachedPosition;
1270 } else {
1271 return Position::INVALID;
1272 }
1273 }
1274 if (isParking()) {
1275 if (myInfluencer != nullptr && myInfluencer->getLastAccessTimeStep() > getNextStopParameter()->started) {
1276 return myCachedPosition;
1277 }
1278 if (myStops.begin()->parkingarea != nullptr) {
1279 return myStops.begin()->parkingarea->getVehiclePosition(*this);
1280 } else {
1281 // position beside the road
1282 PositionVector shp = myLane->getEdge().getLanes()[0]->getShape();
1285 }
1286 }
1287 const bool changingLanes = myLaneChangeModel->isChangingLanes();
1288 const double posLat = (MSGlobals::gLefthand ? 1 : -1) * getLateralPositionOnLane();
1289 if (offset == 0. && !changingLanes) {
1292 if (MSNet::getInstance()->hasElevation() && MSGlobals::gSublane) {
1294 }
1295 }
1296 return myCachedPosition;
1297 }
1298 Position result = validatePosition(myLane->geometryPositionAtOffset(getPositionOnLane() + offset, posLat), offset);
1299 interpolateLateralZ(result, getPositionOnLane() + offset, posLat);
1300 return result;
1301}
1302
1303
1304void
1305MSVehicle::interpolateLateralZ(Position& pos, double offset, double posLat) const {
1306 const MSLane* shadow = myLaneChangeModel->getShadowLane();
1307 if (shadow != nullptr && pos != Position::INVALID) {
1308 // ignore negative offset
1309 const Position shadowPos = shadow->geometryPositionAtOffset(MAX2(0.0, offset));
1310 if (shadowPos != Position::INVALID && pos.z() != shadowPos.z()) {
1311 const double centerDist = (myLane->getWidth() + shadow->getWidth()) * 0.5;
1312 double relOffset = fabs(posLat) / centerDist;
1313 double newZ = (1 - relOffset) * pos.z() + relOffset * shadowPos.z();
1314 pos.setz(newZ);
1315 }
1316 }
1317}
1318
1319
1320double
1322 double result = getLength() - getPositionOnLane();
1323 if (myLane->isNormal()) {
1324 return MAX2(0.0, result);
1325 }
1326 const MSLane* lane = myLane;
1327 while (lane->isInternal()) {
1328 result += lane->getLength();
1329 lane = lane->getCanonicalSuccessorLane();
1330 }
1331 return result;
1332}
1333
1334
1338 if (!isOnRoad()) {
1339 return Position::INVALID;
1340 }
1341 const std::vector<MSLane*>& bestLanes = getBestLanesContinuation();
1342 auto nextBestLane = bestLanes.begin();
1343 const bool opposite = myLaneChangeModel->isOpposite();
1344 double pos = opposite ? myLane->getLength() - myState.myPos : myState.myPos;
1345 const MSLane* lane = opposite ? myLane->getParallelOpposite() : getLane();
1346 assert(lane != 0);
1347 bool success = true;
1348
1349 while (offset > 0) {
1350 // take into account lengths along internal lanes
1351 while (lane->isInternal() && offset > 0) {
1352 if (offset > lane->getLength() - pos) {
1353 offset -= lane->getLength() - pos;
1354 lane = lane->getLinkCont()[0]->getViaLaneOrLane();
1355 pos = 0.;
1356 if (lane == nullptr) {
1357 success = false;
1358 offset = 0.;
1359 }
1360 } else {
1361 pos += offset;
1362 offset = 0;
1363 }
1364 }
1365 // set nextBestLane to next non-internal lane
1366 while (nextBestLane != bestLanes.end() && *nextBestLane == nullptr) {
1367 ++nextBestLane;
1368 }
1369 if (offset > 0) {
1370 assert(!lane->isInternal());
1371 assert(lane == *nextBestLane);
1372 if (offset > lane->getLength() - pos) {
1373 offset -= lane->getLength() - pos;
1374 ++nextBestLane;
1375 assert(nextBestLane == bestLanes.end() || *nextBestLane != 0);
1376 if (nextBestLane == bestLanes.end()) {
1377 success = false;
1378 offset = 0.;
1379 } else {
1380 const MSLink* link = lane->getLinkTo(*nextBestLane);
1381 assert(link != nullptr);
1382 lane = link->getViaLaneOrLane();
1383 pos = 0.;
1384 }
1385 } else {
1386 pos += offset;
1387 offset = 0;
1388 }
1389 }
1390
1391 }
1392
1393 if (success) {
1395 } else {
1396 return Position::INVALID;
1397 }
1398}
1399
1400
1401double
1403 if (myLane != nullptr) {
1404 return myLane->getVehicleMaxSpeed(this);
1405 }
1406 return myType->getMaxSpeed();
1407}
1408
1409
1411MSVehicle::validatePosition(Position result, double offset) const {
1412 int furtherIndex = 0;
1413 double lastLength = getPositionOnLane();
1414 while (result == Position::INVALID) {
1415 if (furtherIndex >= (int)myFurtherLanes.size()) {
1416 //WRITE_WARNINGF(TL("Could not compute position for vehicle '%', time=%."), getID(), time2string(MSNet::getInstance()->getCurrentTimeStep()));
1417 break;
1418 }
1419 //std::cout << SIMTIME << " veh=" << getID() << " lane=" << myLane->getID() << " pos=" << getPositionOnLane() << " posLat=" << getLateralPositionOnLane() << " offset=" << offset << " result=" << result << " i=" << furtherIndex << " further=" << myFurtherLanes.size() << "\n";
1420 MSLane* further = myFurtherLanes[furtherIndex];
1421 offset += lastLength;
1422 result = further->geometryPositionAtOffset(further->getLength() + offset, -getLateralPositionOnLane());
1423 lastLength = further->getLength();
1424 furtherIndex++;
1425 //std::cout << SIMTIME << " newResult=" << result << "\n";
1426 }
1427 return result;
1428}
1429
1430
1431ConstMSEdgeVector::const_iterator
1433 // too close to the next junction, so avoid an emergency brake here
1434 if (myLane != nullptr && (myCurrEdge + 1) != myRoute->end() && !isRailway(getVClass())) {
1435 if (myLane->isInternal()) {
1436 return myCurrEdge + 1;
1437 }
1438 if (myState.myPos > myLane->getLength() - getCarFollowModel().brakeGap(myState.mySpeed, getCarFollowModel().getMaxDecel(), 0.)) {
1439 return myCurrEdge + 1;
1440 }
1442 return myCurrEdge + 1;
1443 }
1444 }
1445 return myCurrEdge;
1446}
1447
1448
1449double
1453
1454double
1456 const double angleDiff = getAngleDiff();
1457 return angleDiff == 0
1458 ? std::numeric_limits<double>::max()
1459 : SPEED2DIST(getSpeed()) / fabs(angleDiff);
1460}
1461
1462
1463void
1464MSVehicle::setAngle(double angle, bool straightenFurther) {
1465#ifdef DEBUG_FURTHER
1466 if (DEBUG_COND) {
1467 std::cout << SIMTIME << " veh '" << getID() << " setAngle(" << angle << ") straightenFurther=" << straightenFurther << std::endl;
1468 }
1469#endif
1470 myAngle = angle;
1471 MSLane* next = myLane;
1472 if (straightenFurther && myFurtherLanesPosLat.size() > 0) {
1473 for (int i = 0; i < (int)myFurtherLanes.size(); i++) {
1474 MSLane* further = myFurtherLanes[i];
1475 const MSLink* link = further->getLinkTo(next);
1476 if (link != nullptr) {
1478 next = further;
1479 } else {
1480 break;
1481 }
1482 }
1483 }
1484}
1485
1486
1487void
1488MSVehicle::setActionStepLength(double actionStepLength, bool resetOffset) {
1489 SUMOTime actionStepLengthMillisecs = SUMOVehicleParserHelper::processActionStepLength(actionStepLength);
1490 SUMOTime previousActionStepLength = getActionStepLength();
1491 const bool newActionStepLength = actionStepLengthMillisecs != previousActionStepLength;
1492 if (newActionStepLength) {
1493 getSingularType().setActionStepLength(actionStepLengthMillisecs, resetOffset);
1494 if (!resetOffset) {
1495 updateActionOffset(previousActionStepLength, actionStepLengthMillisecs);
1496 }
1497 }
1498 if (resetOffset) {
1500 }
1501}
1502
1503
1504bool
1506 return myState.mySpeed < (60.0 / 3.6) || myLane->getSpeedLimit() < (60.1 / 3.6);
1507}
1508
1509
1510double
1512 Position p1;
1513 const double posLat = -myState.myPosLat; // @todo get rid of the '-'
1514 const double lefthandSign = (MSGlobals::gLefthand ? -1 : 1);
1515
1516 // if parking manoeuvre is happening then rotate vehicle on each step
1519 }
1520
1521 if (isParking()) {
1522 if (myStops.begin()->parkingarea != nullptr) {
1523 return myStops.begin()->parkingarea->getVehicleAngle(*this);
1524 } else {
1526 }
1527 }
1529 // cannot use getPosition() because it already includes the offset to the side and thus messes up the angle
1530 p1 = myLane->geometryPositionAtOffset(myState.myPos, lefthandSign * posLat);
1531 if (p1 == Position::INVALID && myLane->getShape().length2D() == 0. && myLane->isInternal()) {
1532 // workaround: extrapolate the preceding lane shape
1533 MSLane* predecessorLane = myLane->getCanonicalPredecessorLane();
1534 p1 = predecessorLane->geometryPositionAtOffset(predecessorLane->getLength() + myState.myPos, lefthandSign * posLat);
1535 }
1536 } else {
1537 p1 = getPosition();
1538 }
1539
1540 Position p2;
1541 if (getVehicleType().getParameter().locomotiveLength > 0) {
1542 // articulated vehicle should use the heading of the first part
1543 const double locoLength = MIN2(getVehicleType().getParameter().locomotiveLength, getLength());
1544 p2 = getPosition(-locoLength);
1545 } else {
1546 p2 = getBackPosition();
1547 }
1548 if (p2 == Position::INVALID) {
1549 // Handle special case of vehicle's back reaching out of the network
1550 if (myFurtherLanes.size() > 0) {
1551 p2 = myFurtherLanes.back()->geometryPositionAtOffset(0, -myFurtherLanesPosLat.back());
1552 if (p2 == Position::INVALID) {
1553 // unsuitable lane geometry
1554 p2 = myLane->geometryPositionAtOffset(0, posLat);
1555 }
1556 } else {
1557 p2 = myLane->geometryPositionAtOffset(0, posLat);
1558 }
1559 }
1560 double result = (p1 != p2 ? p2.angleTo2D(p1) :
1562
1563 result += lefthandSign * myLaneChangeModel->calcAngleOffset();
1564
1565#ifdef DEBUG_FURTHER
1566 if (DEBUG_COND) {
1567 std::cout << SIMTIME << " computeAngle veh=" << getID() << " p1=" << p1 << " p2=" << p2 << " angle=" << RAD2DEG(result) << " naviDegree=" << GeomHelper::naviDegree(result) << "\n";
1568 }
1569#endif
1570 return result;
1571}
1572
1573
1574const Position
1576 const double posLat = MSGlobals::gLefthand ? myState.myPosLat : -myState.myPosLat;
1577 Position result;
1578 if (myState.myPos >= myType->getLength()) {
1579 // vehicle is fully on the new lane
1581 } else {
1583 // special case where the target lane has no predecessor
1584#ifdef DEBUG_FURTHER
1585 if (DEBUG_COND) {
1586 std::cout << " getBackPosition veh=" << getID() << " specialCase using myLane=" << myLane->getID() << " pos=0 posLat=" << myState.myPosLat << " result=" << myLane->geometryPositionAtOffset(0, posLat) << "\n";
1587 }
1588#endif
1589 result = myLane->geometryPositionAtOffset(0, posLat);
1590 } else {
1591#ifdef DEBUG_FURTHER
1592 if (DEBUG_COND) {
1593 std::cout << " getBackPosition veh=" << getID() << " myLane=" << myLane->getID() << " further=" << toString(myFurtherLanes) << " myFurtherLanesPosLat=" << toString(myFurtherLanesPosLat) << "\n";
1594 }
1595#endif
1596 if (myFurtherLanes.size() > 0 && !myLaneChangeModel->isChangingLanes()) {
1597 // truncate to 0 if vehicle starts on an edge that is shorter than its length
1598 const double backPos = MAX2(0.0, getBackPositionOnLane(myFurtherLanes.back()));
1599 result = myFurtherLanes.back()->geometryPositionAtOffset(backPos, -myFurtherLanesPosLat.back() * (MSGlobals::gLefthand ? -1 : 1));
1600 } else {
1601 result = myLane->geometryPositionAtOffset(0, posLat);
1602 }
1603 }
1604 }
1606 interpolateLateralZ(result, myState.myPos - myType->getLength(), posLat);
1607 }
1608 return result;
1609}
1610
1611
1612bool
1614 return !isStopped() && !myStops.empty() && myLane != nullptr && &myStops.front().lane->getEdge() == &myLane->getEdge();
1615}
1616
1617bool
1619 return isStopped() && myStops.front().lane == myLane;
1620}
1621
1622bool
1623MSVehicle::keepStopping(bool afterProcessing) const {
1624 if (isStopped()) {
1625 // when coming out of vehicleTransfer we must shift the time forward
1626 return (myStops.front().duration - (afterProcessing ? DELTA_T : 0) > 0 || isStoppedTriggered() || myStops.front().pars.collision
1627 || myStops.front().pars.breakDown || (myStops.front().getSpeed() > 0
1628 && (myState.myPos < MIN2(myStops.front().pars.endPos, myStops.front().lane->getLength() - POSITION_EPS))
1629 && (myStops.front().pars.parking == ParkingType::ONROAD || getSpeed() >= SUMO_const_haltingSpeed)));
1630 } else {
1631 return false;
1632 }
1633}
1634
1635
1638 if (isStopped()) {
1639 return myStops.front().duration;
1640 }
1641 return 0;
1642}
1643
1644
1647 return (myStops.empty() || !myStops.front().pars.collision) ? myCollisionImmunity : MAX2((SUMOTime)0, myStops.front().duration);
1648}
1649
1650
1651bool
1653 return isStopped() && !myStops.empty() && myStops.front().pars.breakDown;
1654}
1655
1656
1657bool
1659 return myCollisionImmunity > 0;
1660}
1661
1662
1663double
1664MSVehicle::processNextStop(double currentVelocity) {
1665 if (myStops.empty()) {
1666 // no stops; pass
1667 return currentVelocity;
1668 }
1669
1670#ifdef DEBUG_STOPS
1671 if (DEBUG_COND) {
1672 std::cout << "\nPROCESS_NEXT_STOP\n" << SIMTIME << " vehicle '" << getID() << "'" << std::endl;
1673 }
1674#endif
1675
1676 MSStop& stop = myStops.front();
1678 if (stop.reached) {
1679 stop.duration -= getActionStepLength();
1680 if (getSpeed() > 0) {
1681 // re-enter stopping places to correct waiting position (except for parkingArea since it's place-based)
1682 if (stop.busstop != nullptr) {
1683 // let the bus stop know the vehicle
1684 stop.busstop->enter(this, stop.pars.parking == ParkingType::OFFROAD);
1685 }
1686 if (stop.containerstop != nullptr) {
1687 // let the container stop know the vehicle
1689 }
1690 if (stop.chargingStation != nullptr) {
1691 // let the container stop know the vehicle
1693 }
1694 if (stop.getSpeed() <= 0) {
1695 stop.entryPos = getPositionOnLane();
1696 }
1697 }
1698
1699#ifdef DEBUG_STOPS
1700 if (DEBUG_COND) {
1701 std::cout << SIMTIME << " vehicle '" << getID() << "' reached stop.\n"
1702 << "Remaining duration: " << STEPS2TIME(stop.duration) << std::endl;
1703 if (stop.getSpeed() > 0) {
1704 std::cout << " waypointSpeed=" << stop.getSpeed() << " vehPos=" << myState.myPos << " endPos=" << stop.pars.endPos << "\n";
1705 }
1706 }
1707#endif
1708 if (stop.duration <= 0 && stop.pars.join != "") {
1709 // join this train (part) to another one
1710 MSVehicle* joinVeh = dynamic_cast<MSVehicle*>(MSNet::getInstance()->getVehicleControl().getVehicle(stop.pars.join));
1711 if (joinVeh && joinVeh->hasDeparted() && (joinVeh->joinTrainPart(this) || joinVeh->joinTrainPartFront(this))) {
1712 stop.joinTriggered = false;
1716 }
1717 // avoid collision warning before this vehicle is removed (joinVeh was already made longer)
1719 // mark this vehicle as arrived
1721 const_cast<SUMOVehicleParameter*>(myParameter)->arrivalEdge = getRoutePosition();
1722 // handle transportables that want to continue in the other vehicle
1723 if (myPersonDevice != nullptr) {
1725 }
1726 if (myContainerDevice != nullptr) {
1728 }
1729 }
1730 }
1731 boardTransportables(stop);
1732 if (time > stop.endBoarding) {
1733 // for taxi: cancel customers
1734 MSDevice_Taxi* taxiDevice = static_cast<MSDevice_Taxi*>(getDevice(typeid(MSDevice_Taxi)));
1735 if (taxiDevice != nullptr) {
1736 // may invalidate stops including the current reference
1737 taxiDevice->cancelCurrentCustomers();
1739 return currentVelocity;
1740 }
1741 }
1742 if (!keepStopping() && isOnRoad()) {
1743#ifdef DEBUG_STOPS
1744 if (DEBUG_COND) {
1745 std::cout << SIMTIME << " vehicle '" << getID() << "' resumes from stopping." << std::endl;
1746 }
1747#endif
1749 if (isRail() && hasStops()) {
1750 // stay on the current lane in case of a double stop
1751 const MSStop& nextStop = getNextStop();
1752 if (nextStop.edge == myCurrEdge) {
1753 const double stopSpeed = getCarFollowModel().stopSpeed(this, getSpeed(), nextStop.pars.endPos - myState.myPos);
1754 //std::cout << SIMTIME << " veh=" << getID() << " resumedFromStopping currentVelocity=" << currentVelocity << " stopSpeed=" << stopSpeed << "\n";
1755 return stopSpeed;
1756 }
1757 }
1758 } else {
1759 if (stop.triggered) {
1760 if (getVehicleType().getPersonCapacity() == getPersonNumber()) {
1761 WRITE_WARNINGF(TL("Vehicle '%' ignores triggered stop on lane '%' due to capacity constraints."), getID(), stop.lane->getID());
1762 stop.triggered = false;
1763 } else if (!myAmRegisteredAsWaiting && stop.duration <= DELTA_T) {
1764 // we can only register after waiting for one step. otherwise we might falsely signal a deadlock
1767#ifdef DEBUG_STOPS
1768 if (DEBUG_COND) {
1769 std::cout << SIMTIME << " vehicle '" << getID() << "' registers as waiting for person." << std::endl;
1770 }
1771#endif
1772 }
1773 }
1774 if (stop.containerTriggered) {
1775 if (getVehicleType().getContainerCapacity() == getContainerNumber()) {
1776 WRITE_WARNINGF(TL("Vehicle '%' ignores container triggered stop on lane '%' due to capacity constraints."), getID(), stop.lane->getID());
1777 stop.containerTriggered = false;
1778 } else if (stop.containerTriggered && !myAmRegisteredAsWaiting && stop.duration <= DELTA_T) {
1779 // we can only register after waiting for one step. otherwise we might falsely signal a deadlock
1782#ifdef DEBUG_STOPS
1783 if (DEBUG_COND) {
1784 std::cout << SIMTIME << " vehicle '" << getID() << "' registers as waiting for container." << std::endl;
1785 }
1786#endif
1787 }
1788 }
1789 // joining only takes place after stop duration is over
1791 && stop.duration <= (stop.pars.extension >= 0 ? -stop.pars.extension : 0)) {
1792 if (stop.pars.extension >= 0) {
1793 WRITE_WARNINGF(TL("Vehicle '%' aborts joining after extension of %s at time %."), getID(), STEPS2TIME(stop.pars.extension), time2string(SIMSTEP));
1794 stop.joinTriggered = false;
1795 } else {
1796 // keep stopping indefinitely but ensure that simulation terminates
1799 }
1800 }
1801 if (stop.getSpeed() > 0) {
1802 //waypoint mode
1803 if (stop.duration == 0) {
1804 return stop.getSpeed();
1805 } else {
1806 // stop for 'until' (computed in planMove)
1807 return currentVelocity;
1808 }
1809 } else {
1810 // brake
1812 return 0;
1813 } else {
1814 // ballistic:
1815 return getSpeed() - getCarFollowModel().getMaxDecel();
1816 }
1817 }
1818 }
1819 } else {
1820
1821#ifdef DEBUG_STOPS
1822 if (DEBUG_COND) {
1823 std::cout << SIMTIME << " vehicle '" << getID() << "' hasn't reached next stop." << std::endl;
1824 }
1825#endif
1826 //std::cout << SIMTIME << " myStopDist=" << myStopDist << " bGap=" << getBrakeGap(myLane->getVehicleMaxSpeed(this)) << "\n";
1827 if (stop.pars.onDemand && !stop.skipOnDemand && myStopDist <= getCarFollowModel().brakeGap(myLane->getVehicleMaxSpeed(this))) {
1828 MSNet* const net = MSNet::getInstance();
1829 const bool noExits = ((myPersonDevice == nullptr || !myPersonDevice->anyLeavingAtStop(stop))
1830 && (myContainerDevice == nullptr || !myContainerDevice->anyLeavingAtStop(stop)));
1831 const bool noEntries = ((!net->hasPersons() || !net->getPersonControl().hasAnyWaiting(stop.getEdge(), this))
1832 && (!net->hasContainers() || !net->getContainerControl().hasAnyWaiting(stop.getEdge(), this)));
1833 if (noExits && noEntries) {
1834 //std::cout << " skipOnDemand\n";
1835 stop.skipOnDemand = true;
1836 // bestLanes must be extended past this stop
1837 updateBestLanes(true);
1838 }
1839 }
1840 // is the next stop on the current lane?
1841 if (stop.edge == myCurrEdge) {
1842 // get the stopping position
1843 bool useStoppingPlace = stop.busstop != nullptr || stop.containerstop != nullptr || stop.parkingarea != nullptr;
1844 bool fitsOnStoppingPlace = true;
1845 if (!stop.skipOnDemand) { // no need to check available space if we skip it anyway
1846 if (stop.busstop != nullptr) {
1847 fitsOnStoppingPlace &= stop.busstop->fits(myState.myPos, *this);
1848 }
1849 if (stop.containerstop != nullptr) {
1850 fitsOnStoppingPlace &= stop.containerstop->fits(myState.myPos, *this);
1851 }
1852 // if the stop is a parking area we check if there is a free position on the area
1853 if (stop.parkingarea != nullptr) {
1854 fitsOnStoppingPlace &= myState.myPos > stop.parkingarea->getBeginLanePosition();
1855 if (stop.parkingarea->getOccupancy() >= stop.parkingarea->getCapacity()) {
1856 fitsOnStoppingPlace = false;
1857 // trigger potential parkingZoneReroute
1858 MSParkingArea* oldParkingArea = stop.parkingarea;
1859 for (MSMoveReminder* rem : myLane->getMoveReminders()) {
1860 if (rem->isParkingRerouter()) {
1861 rem->notifyEnter(*this, MSMoveReminder::NOTIFICATION_PARKING_REROUTE, myLane);
1862 }
1863 }
1864 if (myStops.empty() || myStops.front().parkingarea != oldParkingArea) {
1865 // rerouted, keep driving
1866 return currentVelocity;
1867 }
1868 } else if (stop.parkingarea->getOccupancyIncludingReservations(this) >= stop.parkingarea->getCapacity()) {
1869 fitsOnStoppingPlace = false;
1870 } else if (stop.parkingarea->parkOnRoad() && stop.parkingarea->getLotIndex(this) < 0) {
1871 fitsOnStoppingPlace = false;
1872 }
1873 }
1874 }
1875 const double targetPos = myState.myPos + myStopDist + (stop.getSpeed() > 0 ? (stop.pars.startPos - stop.pars.endPos) : 0);
1876 double reachedThreshold = (useStoppingPlace ? targetPos - STOPPING_PLACE_OFFSET : stop.getReachedThreshold()) - NUMERICAL_EPS;
1877 if (stop.busstop != nullptr && stop.getSpeed() <= 0 && getWaitingTime() > DELTA_T && myLane == stop.lane) {
1878 // count (long) busStop as reached when fully within and jammed before the designated spot
1879 reachedThreshold = MIN2(reachedThreshold, stop.pars.startPos + getLength());
1880 }
1881 const bool posReached = myState.pos() >= reachedThreshold && currentVelocity <= stop.getSpeed() + SUMO_const_haltingSpeed && myLane == stop.lane;
1882#ifdef DEBUG_STOPS
1883 if (DEBUG_COND) {
1884 std::cout << " pos=" << myState.pos() << " speed=" << currentVelocity << " targetPos=" << targetPos << " fits=" << fitsOnStoppingPlace
1885 << " reachedThresh=" << reachedThreshold
1886 << " posReached=" << posReached
1887 << " myLane=" << Named::getIDSecure(myLane)
1888 << " stopLane=" << Named::getIDSecure(stop.lane)
1889 << "\n";
1890 }
1891#endif
1892 if (posReached && !fitsOnStoppingPlace && MSStopOut::active()) {
1893 MSStopOut::getInstance()->stopBlocked(this, time);
1894 }
1895 if (fitsOnStoppingPlace && posReached && (!MSGlobals::gModelParkingManoeuver || myManoeuvre.entryManoeuvreIsComplete(this))) {
1896 // ok, we may stop (have reached the stop) and either we are not modelling maneuvering or have completed entry
1897 stop.reached = true;
1898 if (!stop.startedFromState) {
1899 stop.pars.started = time;
1900 }
1901#ifdef DEBUG_STOPS
1902 if (DEBUG_COND) {
1903 std::cout << SIMTIME << " vehicle '" << getID() << "' reached next stop." << std::endl;
1904 }
1905#endif
1906 if (MSStopOut::active()) {
1908 }
1909 myLane->getEdge().addWaiting(this);
1912 // compute stopping time
1913 stop.duration = stop.getMinDuration(time);
1914 stop.endBoarding = stop.pars.extension >= 0 ? time + stop.duration + stop.pars.extension : SUMOTime_MAX;
1915 MSDevice_Taxi* taxiDevice = static_cast<MSDevice_Taxi*>(getDevice(typeid(MSDevice_Taxi)));
1916 if (taxiDevice != nullptr && stop.pars.extension >= 0) {
1917 // earliestPickupTime is set with waitUntil
1918 stop.endBoarding = MAX2(time, stop.pars.waitUntil) + stop.pars.extension;
1919 }
1920 if (stop.getSpeed() > 0) {
1921 // ignore duration parameter in waypoint mode unless 'until' or 'ended' are set
1922 if (stop.getUntil() > time) {
1923 stop.duration = stop.getUntil() - time;
1924 } else {
1925 stop.duration = 0;
1926 }
1927 } else {
1928 stop.entryPos = getPositionOnLane();
1929 }
1930 if (stop.busstop != nullptr) {
1931 // let the bus stop know the vehicle
1932 stop.busstop->enter(this, stop.pars.parking == ParkingType::OFFROAD);
1933 }
1934 if (stop.containerstop != nullptr) {
1935 // let the container stop know the vehicle
1937 }
1938 if (stop.parkingarea != nullptr && stop.getSpeed() <= 0) {
1939 // let the parking area know the vehicle
1940 stop.parkingarea->enter(this, stop.pars.parking == ParkingType::OFFROAD);
1941 }
1942 if (stop.chargingStation != nullptr) {
1943 // let the container stop know the vehicle
1945 }
1946
1947 if (stop.pars.tripId != "") {
1948 ((SUMOVehicleParameter&)getParameter()).setParameter("tripId", stop.pars.tripId);
1949 }
1950 if (stop.pars.line != "") {
1951 ((SUMOVehicleParameter&)getParameter()).line = stop.pars.line;
1952 }
1953 if (stop.pars.split != "") {
1954 // split the train
1955 MSVehicle* splitVeh = dynamic_cast<MSVehicle*>(MSNet::getInstance()->getVehicleControl().getVehicle(stop.pars.split));
1956 if (splitVeh == nullptr) {
1957 WRITE_WARNINGF(TL("Vehicle '%' to split from vehicle '%' is not known. time=%."), stop.pars.split, getID(), SIMTIME)
1958 } else {
1960 splitVeh->getRoute().getEdges()[0]->removeWaiting(splitVeh);
1962 const double newLength = MAX2(myType->getLength() - splitVeh->getVehicleType().getLength(),
1964 getSingularType().setLength(newLength);
1965 // handle transportables that want to continue in the split part
1966 if (myPersonDevice != nullptr) {
1968 }
1969 if (myContainerDevice != nullptr) {
1971 }
1973 const double backShift = splitVeh->getLength() + getVehicleType().getMinGap();
1974 myState.myPos -= backShift;
1975 myState.myBackPos -= backShift;
1976 }
1977 }
1978 }
1979
1980 boardTransportables(stop);
1981 if (stop.pars.posLat != INVALID_DOUBLE) {
1982 myState.myPosLat = stop.pars.posLat;
1983 }
1984 }
1985 }
1986 }
1987 return currentVelocity;
1988}
1989
1990
1991void
1993 if (stop.skipOnDemand) {
1994 return;
1995 }
1996 // we have reached the stop
1997 // any waiting persons may board now
1999 MSNet* const net = MSNet::getInstance();
2000 const bool boarded = (time <= stop.endBoarding
2001 && net->hasPersons()
2003 && stop.numExpectedPerson == 0);
2004 // load containers
2005 const bool loaded = (time <= stop.endBoarding
2006 && net->hasContainers()
2008 && stop.numExpectedContainer == 0);
2009
2010 bool unregister = false;
2011 if (time > stop.endBoarding) {
2012 stop.triggered = false;
2013 stop.containerTriggered = false;
2015 unregister = true;
2017 }
2018 }
2019 if (boarded) {
2020 // the triggering condition has been fulfilled. Maybe we want to wait a bit longer for additional riders (car pooling)
2022 unregister = true;
2023 }
2024 stop.triggered = false;
2026 }
2027 if (loaded) {
2028 // the triggering condition has been fulfilled
2030 unregister = true;
2031 }
2032 stop.containerTriggered = false;
2034 }
2035
2036 if (unregister) {
2038#ifdef DEBUG_STOPS
2039 if (DEBUG_COND) {
2040 std::cout << SIMTIME << " vehicle '" << getID() << "' unregisters as waiting for transportable." << std::endl;
2041 }
2042#endif
2043 }
2044}
2045
2046bool
2048 // check if veh is close enough to be joined to the rear of this vehicle
2049 MSLane* backLane = myFurtherLanes.size() == 0 ? myLane : myFurtherLanes.back();
2050 double gap = getBackPositionOnLane() - veh->getPositionOnLane();
2051 if (isStopped() && myStops.begin()->duration <= DELTA_T && myStops.begin()->joinTriggered && backLane == veh->getLane()
2052 && gap >= 0 && gap <= getVehicleType().getMinGap() + 1) {
2053 const double newLength = myType->getLength() + veh->getVehicleType().getLength();
2054 getSingularType().setLength(newLength);
2055 myStops.begin()->joinTriggered = false;
2059 }
2060 return true;
2061 } else {
2062 return false;
2063 }
2064}
2065
2066
2067bool
2069 // check if veh is close enough to be joined to the front of this vehicle
2070 MSLane* backLane = veh->myFurtherLanes.size() == 0 ? veh->myLane : veh->myFurtherLanes.back();
2071 double gap = veh->getBackPositionOnLane(backLane) - getPositionOnLane();
2072 if (isStopped() && myStops.begin()->duration <= DELTA_T && myStops.begin()->joinTriggered && backLane == getLane()
2073 && gap >= 0 && gap <= getVehicleType().getMinGap() + 1) {
2074 double skippedLaneLengths = 0;
2075 if (veh->myFurtherLanes.size() > 0) {
2076 skippedLaneLengths += getLane()->getLength();
2077 // this vehicle must be moved to the lane of veh
2078 // ensure that lane and furtherLanes of veh match our route
2079 int routeIndex = getRoutePosition();
2080 if (myLane->isInternal()) {
2081 routeIndex++;
2082 }
2083 for (int i = (int)veh->myFurtherLanes.size() - 1; i >= 0; i--) {
2084 MSEdge* edge = &veh->myFurtherLanes[i]->getEdge();
2085 if (edge->isInternal()) {
2086 continue;
2087 }
2088 if (!edge->isInternal() && edge != myRoute->getEdges()[routeIndex]) {
2089 std::string warn = TL("Cannot join vehicle '%' to vehicle '%' due to incompatible routes. time=%.");
2090 WRITE_WARNINGF(warn, veh->getID(), getID(), time2string(SIMSTEP));
2091 return false;
2092 }
2093 routeIndex++;
2094 }
2095 if (veh->getCurrentEdge()->getNormalSuccessor() != myRoute->getEdges()[routeIndex]) {
2096 std::string warn = TL("Cannot join vehicle '%' to vehicle '%' due to incompatible routes. time=%.");
2097 WRITE_WARNINGF(warn, veh->getID(), getID(), time2string(SIMSTEP));
2098 return false;
2099 }
2100 for (int i = (int)veh->myFurtherLanes.size() - 2; i >= 0; i--) {
2101 skippedLaneLengths += veh->myFurtherLanes[i]->getLength();
2102 }
2103 }
2104
2105 const double newLength = myType->getLength() + veh->getVehicleType().getLength();
2106 getSingularType().setLength(newLength);
2107 // lane will be advanced just as for regular movement
2108 myState.myPos = skippedLaneLengths + veh->getPositionOnLane();
2109 myStops.begin()->joinTriggered = false;
2113 }
2114 return true;
2115 } else {
2116 return false;
2117 }
2118}
2119
2120double
2121MSVehicle::getBrakeGap(bool delayed) const {
2122 return getCarFollowModel().brakeGap(getSpeed(), getCarFollowModel().getMaxDecel(), delayed ? getCarFollowModel().getHeadwayTime() : 0);
2123}
2124
2125
2126bool
2129 if (myActionStep) {
2130 myLastActionTime = t;
2131 }
2132 return myActionStep;
2133}
2134
2135
2136void
2137MSVehicle::resetActionOffset(const SUMOTime timeUntilNextAction) {
2138 myLastActionTime = MSNet::getInstance()->getCurrentTimeStep() + timeUntilNextAction;
2139}
2140
2141
2142void
2143MSVehicle::updateActionOffset(const SUMOTime oldActionStepLength, const SUMOTime newActionStepLength) {
2145 SUMOTime timeSinceLastAction = now - myLastActionTime;
2146 if (timeSinceLastAction == 0) {
2147 // Action was scheduled now, may be delayed be new action step length
2148 timeSinceLastAction = oldActionStepLength;
2149 }
2150 if (timeSinceLastAction >= newActionStepLength) {
2151 // Action point required in this step
2152 myLastActionTime = now;
2153 } else {
2154 SUMOTime timeUntilNextAction = newActionStepLength - timeSinceLastAction;
2155 resetActionOffset(timeUntilNextAction);
2156 }
2157}
2158
2159
2160
2161void
2162MSVehicle::planMove(const SUMOTime t, const MSLeaderInfo& ahead, const double lengthsInFront) {
2163#ifdef DEBUG_PLAN_MOVE
2164 if (DEBUG_COND) {
2165 std::cout
2166 << "\nPLAN_MOVE\n"
2167 << SIMTIME
2168 << std::setprecision(gPrecision)
2169 << " veh=" << getID()
2170 << " lane=" << myLane->getID()
2171 << " pos=" << getPositionOnLane()
2172 << " posLat=" << getLateralPositionOnLane()
2173 << " speed=" << getSpeed()
2174 << "\n";
2175 }
2176#endif
2177 // Update the driver state
2178 if (hasDriverState()) {
2180 setActionStepLength(myDriverState->getDriverState()->getActionStepLength(), false);
2181 }
2182
2184 if (!checkActionStep(t)) {
2185#ifdef DEBUG_ACTIONSTEPS
2186 if (DEBUG_COND) {
2187 std::cout << STEPS2TIME(t) << " vehicle '" << getID() << "' skips action." << std::endl;
2188 }
2189#endif
2190 // During non-action passed drive items still need to be removed
2191 // @todo rather work with updating myCurrentDriveItem (refs #3714)
2193 return;
2194 } else {
2195#ifdef DEBUG_ACTIONSTEPS
2196 if (DEBUG_COND) {
2197 std::cout << STEPS2TIME(t) << " vehicle = '" << getID() << "' takes action." << std::endl;
2198 }
2199#endif
2201 if (myInfluencer != nullptr) {
2203 }
2205#ifdef DEBUG_PLAN_MOVE
2206 if (DEBUG_COND) {
2207 DriveItemVector::iterator i;
2208 for (i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
2209 std::cout
2210 << " vPass=" << (*i).myVLinkPass
2211 << " vWait=" << (*i).myVLinkWait
2212 << " linkLane=" << ((*i).myLink == 0 ? "NULL" : (*i).myLink->getViaLaneOrLane()->getID())
2213 << " request=" << (*i).mySetRequest
2214 << "\n";
2215 }
2216 }
2217#endif
2218 checkRewindLinkLanes(lengthsInFront, myLFLinkLanes);
2220 // ideally would only do this with the call inside planMoveInternal - but that needs a const method
2221 // so this is a kludge here - nuisance as it adds an extra check in a busy loop
2225 }
2226 }
2227 }
2229}
2230
2231
2232bool
2233MSVehicle::brakeForOverlap(const MSLink* link, const MSLane* lane) const {
2234 // @review needed
2235 //const double futurePosLat = getLateralPositionOnLane() + link->getLateralShift();
2236 //const double overlap = getLateralOverlap(futurePosLat, link->getViaLaneOrLane());
2237 //const double edgeWidth = link->getViaLaneOrLane()->getEdge().getWidth();
2238 const double futurePosLat = getLateralPositionOnLane() + (
2239 lane != myLane && lane->isInternal() ? lane->getIncomingLanes()[0].viaLink->getLateralShift() : 0);
2240 const double overlap = getLateralOverlap(futurePosLat, lane);
2241 const double edgeWidth = lane->getEdge().getWidth();
2242 const bool result = (overlap > POSITION_EPS
2243 // do not get stuck on narrow edges
2244 && getVehicleType().getWidth() <= edgeWidth
2245 && link->getViaLane() == nullptr
2246 // this is the exit link of a junction. The normal edge should support the shadow
2247 && ((myLaneChangeModel->getShadowLane(link->getLane()) == nullptr)
2248 // the shadow lane must be permitted
2249 || !myLaneChangeModel->getShadowLane(link->getLane())->allowsVehicleClass(getVClass())
2250 // the internal lane after an internal junction has no parallel lane. make sure there is no shadow before continuing
2251 || (lane->getEdge().isInternal() && lane->getIncomingLanes()[0].lane->getEdge().isInternal()))
2252 // ignore situations where the shadow lane is part of a double-connection with the current lane
2253 && (myLaneChangeModel->getShadowLane() == nullptr
2254 || myLaneChangeModel->getShadowLane()->getLinkCont().size() == 0
2255 || myLaneChangeModel->getShadowLane()->getLinkCont().front()->getLane() != link->getLane())
2256 // emergency vehicles may do some crazy stuff
2258
2259#ifdef DEBUG_PLAN_MOVE
2260 if (DEBUG_COND) {
2261 std::cout << SIMTIME << " veh=" << getID() << " link=" << link->getDescription() << " lane=" << lane->getID()
2262 << " linkLane=" << link->getLane()->getID()
2263 << " shadowLane=" << Named::getIDSecure(myLaneChangeModel->getShadowLane())
2264 << " shift=" << link->getLateralShift()
2265 << " fpLat=" << futurePosLat << " overlap=" << overlap << " w=" << getVehicleType().getWidth()
2266 << " shadowLane=" << Named::getIDSecure(myLaneChangeModel->getShadowLane(link->getLane()))
2267 << " result=" << result << "\n";
2268 }
2269#endif
2270 return result;
2271}
2272
2273
2274
2275void
2276MSVehicle::planMoveInternal(const SUMOTime t, MSLeaderInfo ahead, DriveItemVector& lfLinks, double& newStopDist, double& newStopSpeed, std::pair<double, const MSLink*>& nextTurn) const {
2277 lfLinks.clear();
2278 newStopDist = std::numeric_limits<double>::max();
2279 //
2280 const MSCFModel& cfModel = getCarFollowModel();
2281 const double vehicleLength = getVehicleType().getLength();
2282 const double maxV = cfModel.maxNextSpeed(myState.mySpeed, this);
2283 const double maxVD = MAX2(getMaxSpeed(), MIN2(maxV, getDesiredMaxSpeed()));
2284 const bool opposite = myLaneChangeModel->isOpposite();
2285 // maxVD is possibly higher than vType-maxSpeed and in this case laneMaxV may be higher as well
2286 double laneMaxV = myLane->getVehicleMaxSpeed(this, maxVD);
2287 const double vMinComfortable = cfModel.minNextSpeed(getSpeed(), this);
2288 double lateralShift = 0;
2289 if (isRail()) {
2290 // speed limits must hold for the whole length of the train
2291 for (MSLane* l : myFurtherLanes) {
2292 laneMaxV = MIN2(laneMaxV, l->getVehicleMaxSpeed(this, maxVD));
2293#ifdef DEBUG_PLAN_MOVE
2294 if (DEBUG_COND) {
2295 std::cout << " laneMaxV=" << laneMaxV << " lane=" << l->getID() << "\n";
2296 }
2297#endif
2298 }
2299 }
2300 // speed limits are not emergencies (e.g. when the limit changes suddenly due to TraCI or a variableSpeedSignal)
2301 laneMaxV = MAX2(laneMaxV, vMinComfortable);
2303 laneMaxV = std::numeric_limits<double>::max();
2304 }
2305 // v is the initial maximum velocity of this vehicle in this step
2306 double v = cfModel.maximumLaneSpeedCF(this, maxV, laneMaxV);
2307 // if we are modelling parking then we dawdle until the manoeuvre is complete - by setting a very low max speed
2308 // in practice this only applies to exit manoeuvre because entry manoeuvre just delays setting stop.reached - when the vehicle is virtually stopped
2311 }
2312
2313 if (myInfluencer != nullptr) {
2314 const double vMin = MAX2(0., cfModel.minNextSpeed(myState.mySpeed, this));
2315#ifdef DEBUG_TRACI
2316 if (DEBUG_COND) {
2317 std::cout << SIMTIME << " veh=" << getID() << " speedBeforeTraci=" << v;
2318 }
2319#endif
2320 v = myInfluencer->influenceSpeed(t, v, v, vMin, maxV);
2321#ifdef DEBUG_TRACI
2322 if (DEBUG_COND) {
2323 std::cout << " influencedSpeed=" << v;
2324 }
2325#endif
2326 v = myInfluencer->gapControlSpeed(t, this, v, v, vMin, maxV);
2327#ifdef DEBUG_TRACI
2328 if (DEBUG_COND) {
2329 std::cout << " gapControlSpeed=" << v << "\n";
2330 }
2331#endif
2332 }
2333 // all links within dist are taken into account (potentially)
2334 const double dist = SPEED2DIST(maxV) + cfModel.brakeGap(maxV);
2335
2336 const std::vector<MSLane*>& bestLaneConts = getBestLanesContinuation();
2337#ifdef DEBUG_PLAN_MOVE
2338 if (DEBUG_COND) {
2339 std::cout << " dist=" << dist << " bestLaneConts=" << toString(bestLaneConts)
2340 << "\n maxV=" << maxV << " laneMaxV=" << laneMaxV << " v=" << v << "\n";
2341 }
2342#endif
2343 assert(bestLaneConts.size() > 0);
2344 bool hadNonInternal = false;
2345 // the distance already "seen"; in the following always up to the end of the current "lane"
2346 double seen = opposite ? myState.myPos : myLane->getLength() - myState.myPos;
2347 nextTurn.first = seen;
2348 nextTurn.second = nullptr;
2349 bool encounteredTurn = (MSGlobals::gLateralResolution <= 0); // next turn is only needed for sublane
2350 double seenNonInternal = 0;
2351 double seenInternal = myLane->isInternal() ? seen : 0;
2352 double vLinkPass = MIN2(cfModel.estimateSpeedAfterDistance(seen, v, cfModel.getMaxAccel()), laneMaxV); // upper bound
2353 int view = 0;
2354 DriveProcessItem* lastLink = nullptr;
2355 bool slowedDownForMinor = false; // whether the vehicle already had to slow down on approach to a minor link
2356 double mustSeeBeforeReversal = 0;
2357 // iterator over subsequent lanes and fill lfLinks until stopping distance or stopped
2358 const MSLane* lane = opposite ? myLane->getParallelOpposite() : myLane;
2359 assert(lane != 0);
2360 const MSLane* leaderLane = myLane;
2361 bool foundRailSignal = !isRail();
2362 bool planningToStop = false;
2363#ifdef PARALLEL_STOPWATCH
2364 myLane->getStopWatch()[0].start();
2365#endif
2366
2367 // optionally slow down to match arrival time
2368 const double sfp = getVehicleType().getParameter().speedFactorPremature;
2369 if (v > vMinComfortable && hasStops() && myStops.front().pars.arrival >= 0 && sfp > 0
2370 && v > myLane->getSpeedLimit() * sfp
2371 && !myStops.front().reached) {
2372 const double vSlowDown = slowDownForSchedule(vMinComfortable);
2373 v = MIN2(v, vSlowDown);
2374 }
2375 auto stopIt = myStops.begin();
2376 while (true) {
2377 // check leader on lane
2378 // leader is given for the first edge only
2379 if (opposite &&
2380 (leaderLane->getVehicleNumberWithPartials() > 1
2381 || (leaderLane != myLane && leaderLane->getVehicleNumber() > 0))) {
2382 ahead.clear();
2383 // find opposite-driving leader that must be respected on the currently looked at lane
2384 // (only looking at one lane at a time)
2385 const double backOffset = leaderLane == myLane ? getPositionOnLane() : leaderLane->getLength();
2386 const double gapOffset = leaderLane == myLane ? 0 : seen - leaderLane->getLength();
2387 const MSLeaderDistanceInfo cands = leaderLane->getFollowersOnConsecutive(this, backOffset, true, backOffset, MSLane::MinorLinkMode::FOLLOW_NEVER);
2388 MSLeaderDistanceInfo oppositeLeaders(leaderLane->getWidth(), this, 0.);
2389 const double minTimeToLeaveLane = MSGlobals::gSublane ? MAX2(TS, (0.5 * myLane->getWidth() - getLateralPositionOnLane()) / getVehicleType().getMaxSpeedLat()) : TS;
2390 for (int i = 0; i < cands.numSublanes(); i++) {
2391 CLeaderDist cand = cands[i];
2392 if (cand.first != 0) {
2393 if ((cand.first->myLaneChangeModel->isOpposite() && cand.first->getLaneChangeModel().getShadowLane() != leaderLane)
2394 || (!cand.first->myLaneChangeModel->isOpposite() && cand.first->getLaneChangeModel().getShadowLane() == leaderLane)) {
2395 // respect leaders that also drive in the opposite direction (fully or with some overlap)
2396 oppositeLeaders.addLeader(cand.first, cand.second + gapOffset - getVehicleType().getMinGap() + cand.first->getVehicleType().getMinGap() - cand.first->getVehicleType().getLength());
2397 } else {
2398 // avoid frontal collision
2399 const bool assumeStopped = cand.first->isStopped() || cand.first->getWaitingSeconds() > 1;
2400 const double predMaxDist = cand.first->getSpeed() + (assumeStopped ? 0 : cand.first->getCarFollowModel().getMaxAccel()) * minTimeToLeaveLane;
2401 if (cand.second >= 0 && (cand.second - v * minTimeToLeaveLane - predMaxDist < 0 || assumeStopped)) {
2402 oppositeLeaders.addLeader(cand.first, cand.second + gapOffset - predMaxDist - getVehicleType().getMinGap());
2403 }
2404 }
2405 }
2406 }
2407#ifdef DEBUG_PLAN_MOVE
2408 if (DEBUG_COND) {
2409 std::cout << " leaderLane=" << leaderLane->getID() << " gapOffset=" << gapOffset << " minTimeToLeaveLane=" << minTimeToLeaveLane
2410 << " cands=" << cands.toString() << " oppositeLeaders=" << oppositeLeaders.toString() << "\n";
2411 }
2412#endif
2413 adaptToLeaderDistance(oppositeLeaders, 0, seen, lastLink, v, vLinkPass);
2414 } else {
2416 const double rightOL = getRightSideOnLane(lane) + lateralShift;
2417 const double leftOL = getLeftSideOnLane(lane) + lateralShift;
2418 const bool outsideLeft = leftOL > lane->getWidth();
2419#ifdef DEBUG_PLAN_MOVE
2420 if (DEBUG_COND) {
2421 std::cout << SIMTIME << " veh=" << getID() << " lane=" << lane->getID() << " rightOL=" << rightOL << " leftOL=" << leftOL << "\n";
2422 }
2423#endif
2424 if (rightOL < 0 || outsideLeft) {
2425 MSLeaderInfo outsideLeaders(lane->getWidth());
2426 // if ego is driving outside lane bounds we must consider
2427 // potential leaders that are also outside bounds
2428 int sublaneOffset = 0;
2429 if (outsideLeft) {
2430 sublaneOffset = MIN2(-1, -(int)ceil((leftOL - lane->getWidth()) / MSGlobals::gLateralResolution));
2431 } else {
2432 sublaneOffset = MAX2(1, (int)ceil(-rightOL / MSGlobals::gLateralResolution));
2433 }
2434 outsideLeaders.setSublaneOffset(sublaneOffset);
2435#ifdef DEBUG_PLAN_MOVE
2436 if (DEBUG_COND) {
2437 std::cout << SIMTIME << " veh=" << getID() << " lane=" << lane->getID() << " sublaneOffset=" << sublaneOffset << " outsideLeft=" << outsideLeft << "\n";
2438 }
2439#endif
2440 for (const MSVehicle* cand : lane->getVehiclesSecure()) {
2441 if ((lane != myLane || cand->getPositionOnLane() > getPositionOnLane())
2442 && ((!outsideLeft && cand->getLeftSideOnEdge() < 0)
2443 || (outsideLeft && cand->getLeftSideOnEdge() > lane->getEdge().getWidth()))) {
2444 outsideLeaders.addLeader(cand, true);
2445#ifdef DEBUG_PLAN_MOVE
2446 if (DEBUG_COND) {
2447 std::cout << " outsideLeader=" << cand->getID() << " ahead=" << outsideLeaders.toString() << "\n";
2448 }
2449#endif
2450 }
2451 }
2452 lane->releaseVehicles();
2453 if (outsideLeaders.hasVehicles()) {
2454 adaptToLeaders(outsideLeaders, lateralShift, seen, lastLink, leaderLane, v, vLinkPass);
2455 }
2456 }
2457 }
2458 adaptToLeaders(ahead, lateralShift, seen, lastLink, leaderLane, v, vLinkPass);
2459 }
2460 if (lastLink != nullptr) {
2461 lastLink->myVLinkWait = MIN2(lastLink->myVLinkWait, v);
2462 }
2463#ifdef DEBUG_PLAN_MOVE
2464 if (DEBUG_COND) {
2465 std::cout << "\nv = " << v << "\n";
2466
2467 }
2468#endif
2469 // XXX efficiently adapt to shadow leaders using neighAhead by iteration over the whole edge in parallel (lanechanger-style)
2470 if (myLaneChangeModel->getShadowLane() != nullptr) {
2471 // also slow down for leaders on the shadowLane relative to the current lane
2472 const MSLane* shadowLane = myLaneChangeModel->getShadowLane(leaderLane);
2473 if (shadowLane != nullptr
2474 && (MSGlobals::gLateralResolution > 0 || getLateralOverlap() > POSITION_EPS
2475 // continous lane change cannot be stopped so we must adapt to the leader on the target lane
2477 if ((&shadowLane->getEdge() == &leaderLane->getEdge() || myLaneChangeModel->isOpposite())) {
2480 // ego posLat is added when retrieving sublanes but it
2481 // should be negated (subtract twice to compensate)
2482 latOffset = ((myLane->getWidth() + shadowLane->getWidth()) * 0.5
2483 - 2 * getLateralPositionOnLane());
2484
2485 }
2486 MSLeaderInfo shadowLeaders = shadowLane->getLastVehicleInformation(this, latOffset, lane->getLength() - seen);
2487#ifdef DEBUG_PLAN_MOVE
2489 std::cout << SIMTIME << " opposite veh=" << getID() << " shadowLane=" << shadowLane->getID() << " latOffset=" << latOffset << " shadowLeaders=" << shadowLeaders.toString() << "\n";
2490 }
2491#endif
2493 // ignore oncoming vehicles on the shadow lane
2494 shadowLeaders.removeOpposite(shadowLane);
2495 }
2496 const double turningDifference = MAX2(0.0, leaderLane->getLength() - shadowLane->getLength());
2497 adaptToLeaders(shadowLeaders, latOffset, seen - turningDifference, lastLink, shadowLane, v, vLinkPass);
2498 } else if (shadowLane == myLaneChangeModel->getShadowLane() && leaderLane == myLane) {
2499 // check for leader vehicles driving in the opposite direction on the opposite-direction shadow lane
2500 // (and thus in the same direction as ego)
2501 MSLeaderDistanceInfo shadowLeaders = shadowLane->getFollowersOnConsecutive(this, myLane->getOppositePos(getPositionOnLane()), true);
2502 const double latOffset = 0;
2503#ifdef DEBUG_PLAN_MOVE
2504 if (DEBUG_COND) {
2505 std::cout << SIMTIME << " opposite shadows veh=" << getID() << " shadowLane=" << shadowLane->getID()
2506 << " latOffset=" << latOffset << " shadowLeaders=" << shadowLeaders.toString() << "\n";
2507 }
2508#endif
2509 shadowLeaders.fixOppositeGaps(true);
2510#ifdef DEBUG_PLAN_MOVE
2511 if (DEBUG_COND) {
2512 std::cout << " shadowLeadersFixed=" << shadowLeaders.toString() << "\n";
2513 }
2514#endif
2515 adaptToLeaderDistance(shadowLeaders, latOffset, seen, lastLink, v, vLinkPass);
2516 }
2517 }
2518 }
2519 // adapt to pedestrians on the same lane
2520 if (lane->getEdge().getPersons().size() > 0 && lane->hasPedestrians()) {
2521 const double relativePos = lane->getLength() - seen;
2522#ifdef DEBUG_PLAN_MOVE
2523 if (DEBUG_COND) {
2524 std::cout << SIMTIME << " adapt to pedestrians on lane=" << lane->getID() << " relPos=" << relativePos << "\n";
2525 }
2526#endif
2527 const double stopTime = MAX2(1.0, ceil(getSpeed() / cfModel.getMaxDecel()));
2528 PersonDist leader = lane->nextBlocking(relativePos,
2529 getRightSideOnLane(lane), getRightSideOnLane(lane) + getVehicleType().getWidth(), stopTime);
2530 if (leader.first != 0) {
2531 const double stopSpeed = cfModel.stopSpeed(this, getSpeed(), leader.second - getVehicleType().getMinGap());
2532 v = MIN2(v, stopSpeed);
2533#ifdef DEBUG_PLAN_MOVE
2534 if (DEBUG_COND) {
2535 std::cout << SIMTIME << " pedLeader=" << leader.first->getID() << " dist=" << leader.second << " v=" << v << "\n";
2536 }
2537#endif
2538 }
2539 }
2540 if (lane->getBidiLane() != nullptr) {
2541 // adapt to pedestrians on the bidi lane
2542 const MSLane* bidiLane = lane->getBidiLane();
2543 if (bidiLane->getEdge().getPersons().size() > 0 && bidiLane->hasPedestrians()) {
2544 const double relativePos = seen;
2545#ifdef DEBUG_PLAN_MOVE
2546 if (DEBUG_COND) {
2547 std::cout << SIMTIME << " adapt to pedestrians on lane=" << lane->getID() << " relPos=" << relativePos << "\n";
2548 }
2549#endif
2550 const double stopTime = ceil(getSpeed() / cfModel.getMaxDecel());
2551 const double leftSideOnLane = bidiLane->getWidth() - getRightSideOnLane(lane);
2552 PersonDist leader = bidiLane->nextBlocking(relativePos,
2553 leftSideOnLane - getVehicleType().getWidth(), leftSideOnLane, stopTime, true);
2554 if (leader.first != 0) {
2555 const double stopSpeed = cfModel.stopSpeed(this, getSpeed(), leader.second - getVehicleType().getMinGap());
2556 v = MIN2(v, stopSpeed);
2557#ifdef DEBUG_PLAN_MOVE
2558 if (DEBUG_COND) {
2559 std::cout << SIMTIME << " pedLeader=" << leader.first->getID() << " dist=" << leader.second << " v=" << v << "\n";
2560 }
2561#endif
2562 }
2563 }
2564 }
2565 // adapt to vehicles blocked from (urgent) lane-changing
2566 if (!opposite && lane->getEdge().hasLaneChanger()) {
2567 const double vHelp = myLaneChangeModel->getCooperativeHelpSpeed(lane, seen);
2568#ifdef DEBUG_PLAN_MOVE
2569 if (DEBUG_COND && vHelp < v) {
2570 std::cout << SIMTIME << " applying cooperativeHelpSpeed v=" << vHelp << "\n";
2571 }
2572#endif
2573 v = MIN2(v, vHelp);
2574 }
2575
2576 // process all stops and waypoints on the current edge
2577 bool foundRealStop = false;
2578 while (stopIt != myStops.end()
2579 && ((&stopIt->lane->getEdge() == &lane->getEdge())
2580 || (stopIt->isOpposite && stopIt->lane->getEdge().getOppositeEdge() == &lane->getEdge()))
2581 // ignore stops that occur later in a looped route
2582 && stopIt->edge == myCurrEdge + view) {
2583 double stopDist = std::numeric_limits<double>::max();
2584 const MSStop& stop = *stopIt;
2585 const bool isFirstStop = stopIt == myStops.begin();
2586 stopIt++;
2587 if (!stop.reached || (stop.getSpeed() > 0 && keepStopping())) {
2588 // we are approaching a stop on the edge; must not drive further
2589 bool isWaypoint = stop.getSpeed() > 0;
2590 double endPos = stop.getEndPos(*this) + NUMERICAL_EPS;
2591 if (stop.parkingarea != nullptr) {
2592 // leave enough space so parking vehicles can exit
2593 const double brakePos = getBrakeGap() + lane->getLength() - seen;
2594 endPos = stop.parkingarea->getLastFreePosWithReservation(t, *this, brakePos);
2595 } else if (isWaypoint && !stop.reached) {
2596 endPos = stop.pars.startPos;
2597 }
2598 stopDist = seen + endPos - lane->getLength();
2599#ifdef DEBUG_STOPS
2600 if (DEBUG_COND) {
2601 std::cout << SIMTIME << " veh=" << getID() << " stopDist=" << stopDist << " stopLane=" << stop.lane->getID() << " stopEndPos=" << endPos << "\n";
2602 }
2603#endif
2604 double stopSpeed = laneMaxV;
2605 if (isWaypoint) {
2606 bool waypointWithStop = false;
2607 if (stop.getUntil() > t) {
2608 // check if we have to slow down or even stop
2609 SUMOTime time2end = 0;
2610 if (stop.reached) {
2611 time2end = TIME2STEPS((stop.pars.endPos - myState.myPos) / stop.getSpeed());
2612 } else {
2613 time2end = TIME2STEPS(
2614 // time to reach waypoint start
2615 stopDist / ((getSpeed() + stop.getSpeed()) / 2)
2616 // time to reach waypoint end
2617 + (stop.pars.endPos - stop.pars.startPos) / stop.getSpeed());
2618 }
2619 if (stop.getUntil() > t + time2end) {
2620 // we need to stop
2621 double distToEnd = stopDist;
2622 if (!stop.reached) {
2623 distToEnd += stop.pars.endPos - stop.pars.startPos;
2624 }
2625 stopSpeed = MAX2(cfModel.stopSpeed(this, getSpeed(), distToEnd), vMinComfortable);
2626 waypointWithStop = true;
2627 if (stopSpeed <= SUMO_const_haltingSpeed) {
2628 const_cast<MSStop&>(stop).waypointWithStop = true;
2629 }
2630 }
2631 }
2632 if (stop.reached) {
2633 stopSpeed = MIN2(stop.getSpeed(), stopSpeed);
2634 if (myState.myPos >= stop.pars.endPos && !waypointWithStop) {
2635 stopDist = std::numeric_limits<double>::max();
2636 }
2637 } else {
2638 stopSpeed = MIN2(MAX2(cfModel.freeSpeed(this, getSpeed(), stopDist, stop.getSpeed()), vMinComfortable), stopSpeed);
2639 if (!stop.reached) {
2640 stopDist += stop.pars.endPos - stop.pars.startPos;
2641 }
2642 if (lastLink != nullptr) {
2643 lastLink->adaptLeaveSpeed(cfModel.freeSpeed(this, vLinkPass, endPos, stop.getSpeed(), false, MSCFModel::CalcReason::FUTURE));
2644 }
2645 }
2646 } else {
2647 stopSpeed = cfModel.stopSpeed(this, getSpeed(), stopDist);
2648 if (!instantStopping()) {
2649 // regular stops are not emergencies
2650 stopSpeed = MAX2(stopSpeed, vMinComfortable);
2652 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
2653 speedTimeLine.push_back(std::make_pair(SIMSTEP, getSpeed()));
2654 speedTimeLine.push_back(std::make_pair(SIMSTEP + DELTA_T, stopSpeed));
2655 myInfluencer->setSpeedTimeLine(speedTimeLine);
2656 }
2657 if (lastLink != nullptr) {
2658 lastLink->adaptLeaveSpeed(cfModel.stopSpeed(this, vLinkPass, endPos, MSCFModel::CalcReason::FUTURE));
2659 }
2660 }
2661 if (stopSpeed < getSpeed() && getSpeed() > SUMO_const_haltingSpeed) {
2662 // only discount braking-for-stop timeLoss if we are actually braking
2663 newStopSpeed = MIN2(newStopSpeed, stopSpeed);
2664 } else if (getSpeed() < SUMO_const_haltingSpeed) {
2665 // blocked from entering a stop
2666 newStopSpeed = std::numeric_limits<double>::max();
2667 }
2668 v = MIN2(v, stopSpeed);
2669 if (lane->isInternal()) {
2670 std::vector<MSLink*>::const_iterator exitLink = MSLane::succLinkSec(*this, view + 1, *lane, bestLaneConts);
2671 assert(!lane->isLinkEnd(exitLink));
2672 bool dummySetRequest;
2673 double dummyVLinkWait;
2674 checkLinkLeaderCurrentAndParallel(*exitLink, lane, seen, lastLink, v, vLinkPass, dummyVLinkWait, dummySetRequest);
2675 }
2676
2677#ifdef DEBUG_PLAN_MOVE
2678 if (DEBUG_COND) {
2679 std::cout << "\n" << SIMTIME << " next stop: distance = " << stopDist << " requires stopSpeed = " << stopSpeed << "\n";
2680
2681 }
2682#endif
2683 if (isFirstStop) {
2684 newStopDist = stopDist;
2685 // if the vehicle is going to stop we don't need to look further
2686 // (except for trains that make use of further link-approach registration for safety purposes)
2687 if (!isWaypoint) {
2688 planningToStop = true;
2689 if (!isRail()) {
2690 lfLinks.emplace_back(v, stopDist);
2691 foundRealStop = true;
2692 break;
2693 }
2694 }
2695 }
2696 }
2697 }
2698 if (foundRealStop) {
2699 break;
2700 }
2701
2702 // move to next lane
2703 // get the next link used
2704 std::vector<MSLink*>::const_iterator link = MSLane::succLinkSec(*this, view + 1, *lane, bestLaneConts);
2705 if (lane->isLinkEnd(link) && myLaneChangeModel->hasBlueLight() && myCurrEdge != myRoute->end() - 1) {
2706 // emergency vehicle is on the wrong lane. Obtain the link that it would use from the correct turning lane
2707 const int currentIndex = lane->getIndex();
2708 const MSLane* bestJump = nullptr;
2709 for (const LaneQ& preb : getBestLanes()) {
2710 if (preb.allowsContinuation &&
2711 (bestJump == nullptr
2712 || abs(currentIndex - preb.lane->getIndex()) < abs(currentIndex - bestJump->getIndex()))) {
2713 bestJump = preb.lane;
2714 }
2715 }
2716 if (bestJump != nullptr) {
2717 const MSEdge* nextEdge = *(myCurrEdge + 1);
2718 for (auto cand_it = bestJump->getLinkCont().begin(); cand_it != bestJump->getLinkCont().end(); cand_it++) {
2719 if (&(*cand_it)->getLane()->getEdge() == nextEdge) {
2720 link = cand_it;
2721 break;
2722 }
2723 }
2724 }
2725 }
2726
2727 // Check whether this is a turn (to save info about the next upcoming turn)
2728 if (!encounteredTurn) {
2729 if (!lane->isLinkEnd(link) && lane->getLinkCont().size() > 1) {
2730 LinkDirection linkDir = (*link)->getDirection();
2731 switch (linkDir) {
2734 break;
2735 default:
2736 nextTurn.first = seen;
2737 nextTurn.second = *link;
2738 encounteredTurn = true;
2739#ifdef DEBUG_NEXT_TURN
2740 if (DEBUG_COND) {
2741 std::cout << SIMTIME << " veh '" << getID() << "' nextTurn: " << toString(linkDir)
2742 << " at " << nextTurn.first << "m." << std::endl;
2743 }
2744#endif
2745 }
2746 }
2747 }
2748
2749 // check whether the vehicle is on its final edge
2750 if (myCurrEdge + view + 1 == myRoute->end()
2751 || (myParameter->arrivalEdge >= 0 && getRoutePosition() + view == myParameter->arrivalEdge)) {
2752 const double arrivalSpeed = (myParameter->arrivalSpeedProcedure == ArrivalSpeedDefinition::GIVEN ?
2753 myParameter->arrivalSpeed : laneMaxV);
2754 // subtract the arrival speed from the remaining distance so we get one additional driving step with arrival speed
2755 // XXX: This does not work for ballistic update refs #2579
2756 const double distToArrival = seen + myArrivalPos - lane->getLength() - SPEED2DIST(arrivalSpeed);
2757 const double va = MAX2(NUMERICAL_EPS, cfModel.freeSpeed(this, getSpeed(), distToArrival, arrivalSpeed));
2758 v = MIN2(v, va);
2759 if (lastLink != nullptr) {
2760 lastLink->adaptLeaveSpeed(va);
2761 }
2762 lfLinks.push_back(DriveProcessItem(v, seen, lane->getEdge().isFringe() ? 1000 : 0));
2763 break;
2764 }
2765 // check whether the lane or the shadowLane is a dead end (allow some leeway on intersections)
2766 if (lane->isLinkEnd(link)
2767 || (MSGlobals::gSublane && brakeForOverlap(*link, lane))
2768 || (opposite && (*link)->getViaLaneOrLane()->getParallelOpposite() == nullptr
2770 double va = cfModel.stopSpeed(this, getSpeed(), seen);
2771 if (lastLink != nullptr) {
2772 lastLink->adaptLeaveSpeed(va);
2773 }
2776 } else {
2777 v = MIN2(va, v);
2778 }
2779#ifdef DEBUG_PLAN_MOVE
2780 if (DEBUG_COND) {
2781 std::cout << " braking for link end lane=" << lane->getID() << " seen=" << seen
2782 << " overlap=" << getLateralOverlap() << " va=" << va << " committed=" << myLaneChangeModel->getCommittedSpeed() << " v=" << v << "\n";
2783
2784 }
2785#endif
2786 if (lane->isLinkEnd(link)) {
2787 lfLinks.emplace_back(v, seen);
2788 break;
2789 }
2790 }
2791 lateralShift += (*link)->getLateralShift();
2792 const bool yellowOrRed = (*link)->haveRed() || (*link)->haveYellow();
2793 // We distinguish 3 cases when determining the point at which a vehicle stops:
2794 // - allway_stop: the vehicle should stop close to the stop line but may stop at larger distance
2795 // - red/yellow light: here the vehicle 'knows' that it will have priority eventually and does not need to stop on a precise spot
2796 // - other types of minor links: the vehicle needs to stop as close to the junction as necessary
2797 // to minimize the time window for passing the junction. If the
2798 // vehicle 'decides' to accelerate and cannot enter the junction in
2799 // the next step, new foes may appear and cause a collision (see #1096)
2800 // - major links: stopping point is irrelevant
2801 double laneStopOffset;
2802 const double majorStopOffset = MAX2(getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_STOPLINE_GAP, DIST_TO_STOPLINE_EXPECT_PRIORITY), lane->getVehicleStopOffset(this));
2803 // override low desired decel at yellow and red
2804 const double stopDecel = yellowOrRed && !isRail() ? MAX2(MIN2(MSGlobals::gTLSYellowMinDecel, cfModel.getEmergencyDecel()), cfModel.getMaxDecel()) : cfModel.getMaxDecel();
2805 const double brakeDist = cfModel.brakeGap(myState.mySpeed, stopDecel, 0);
2806 const bool canBrakeBeforeLaneEnd = seen >= brakeDist;
2807 const bool canBrakeBeforeStopLine = seen - lane->getVehicleStopOffset(this) >= brakeDist;
2808 if (yellowOrRed) {
2809 // Wait at red traffic light with full distance if possible
2810 laneStopOffset = majorStopOffset;
2811 } else if ((*link)->havePriority()) {
2812 // On priority link, we should never stop below visibility distance
2813 laneStopOffset = MIN2((*link)->getFoeVisibilityDistance() - POSITION_EPS, majorStopOffset);
2814 } else {
2815 double minorStopOffset = MAX2(lane->getVehicleStopOffset(this),
2816 getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_STOPLINE_CROSSING_GAP, MSPModel::SAFETY_GAP) - (*link)->getDistToFoePedCrossing());
2817#ifdef DEBUG_PLAN_MOVE
2818 if (DEBUG_COND) {
2819 std::cout << " minorStopOffset=" << minorStopOffset << " distToFoePedCrossing=" << (*link)->getDistToFoePedCrossing() << "\n";
2820 }
2821#endif
2822 if ((*link)->getState() == LINKSTATE_ALLWAY_STOP) {
2823 minorStopOffset = MAX2(minorStopOffset, getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_STOPLINE_GAP, 0));
2824 } else {
2825 minorStopOffset = MAX2(minorStopOffset, getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_STOPLINE_GAP_MINOR, 0));
2826 }
2827 // On minor link, we should likewise never stop below visibility distance
2828 laneStopOffset = MIN2((*link)->getFoeVisibilityDistance() - POSITION_EPS, minorStopOffset);
2829 }
2830#ifdef DEBUG_PLAN_MOVE
2831 if (DEBUG_COND) {
2832 std::cout << SIMTIME << " veh=" << getID() << " desired stopOffset on lane '" << lane->getID() << "' is " << laneStopOffset << "\n";
2833 }
2834#endif
2835 if (canBrakeBeforeLaneEnd) {
2836 // avoid emergency braking if possible
2837 laneStopOffset = MIN2(laneStopOffset, seen - brakeDist);
2838 }
2839 laneStopOffset = MAX2(POSITION_EPS, laneStopOffset);
2840 double stopDist = MAX2(0., seen - laneStopOffset);
2841 if (yellowOrRed && getDevice(typeid(MSDevice_GLOSA)) != nullptr
2842 && static_cast<MSDevice_GLOSA*>(getDevice(typeid(MSDevice_GLOSA)))->getOverrideSafety()
2843 && static_cast<MSDevice_GLOSA*>(getDevice(typeid(MSDevice_GLOSA)))->isSpeedAdviceActive()) {
2844 stopDist = std::numeric_limits<double>::max();
2845 }
2846 if (newStopDist != std::numeric_limits<double>::max()) {
2847 stopDist = MAX2(stopDist, newStopDist);
2848 }
2849#ifdef DEBUG_PLAN_MOVE
2850 if (DEBUG_COND) {
2851 std::cout << SIMTIME << " veh=" << getID() << " effective stopOffset on lane '" << lane->getID()
2852 << "' is " << laneStopOffset << " (-> stopDist=" << stopDist << ")" << std::endl;
2853 }
2854#endif
2855 if (isRail()
2856 && !lane->isInternal()) {
2857 // check for train direction reversal
2858 if (lane->getBidiLane() != nullptr
2859 && (*link)->getLane()->getBidiLane() == lane) {
2860 double vMustReverse = getCarFollowModel().stopSpeed(this, getSpeed(), seen - POSITION_EPS);
2861 if (seen < 1) {
2862 mustSeeBeforeReversal = 2 * seen + getLength();
2863 }
2864 v = MIN2(v, vMustReverse);
2865 }
2866 // signal that is passed in the current step does not count
2867 foundRailSignal |= ((*link)->getTLLogic() != nullptr
2868 && (*link)->getTLLogic()->getLogicType() == TrafficLightType::RAIL_SIGNAL
2869 && seen > SPEED2DIST(v));
2870 }
2871
2872 bool canReverseEventually = false;
2873 const double vReverse = checkReversal(canReverseEventually, laneMaxV, seen);
2874 v = MIN2(v, vReverse);
2875#ifdef DEBUG_PLAN_MOVE
2876 if (DEBUG_COND) {
2877 std::cout << SIMTIME << " veh=" << getID() << " canReverseEventually=" << canReverseEventually << " v=" << v << "\n";
2878 }
2879#endif
2880
2881 // check whether we need to slow down in order to finish a continuous lane change
2883 if ( // slow down to finish lane change before a turn lane
2884 ((*link)->getDirection() == LinkDirection::LEFT || (*link)->getDirection() == LinkDirection::RIGHT) ||
2885 // slow down to finish lane change before the shadow lane ends
2886 (myLaneChangeModel->getShadowLane() != nullptr &&
2887 (*link)->getViaLaneOrLane()->getParallelLane(myLaneChangeModel->getShadowDirection()) == nullptr)) {
2888 // XXX maybe this is too harsh. Vehicles could cut some corners here
2889 const double timeRemaining = STEPS2TIME(myLaneChangeModel->remainingTime());
2890 assert(timeRemaining != 0);
2891 // XXX: Euler-logic (#860), but I couldn't identify problems from this yet (Leo). Refs. #2575
2892 const double va = MAX2(cfModel.stopSpeed(this, getSpeed(), seen - POSITION_EPS),
2893 (seen - POSITION_EPS) / timeRemaining);
2894#ifdef DEBUG_PLAN_MOVE
2895 if (DEBUG_COND) {
2896 std::cout << SIMTIME << " veh=" << getID() << " slowing down to finish continuous change before"
2897 << " link=" << (*link)->getViaLaneOrLane()->getID()
2898 << " timeRemaining=" << timeRemaining
2899 << " v=" << v
2900 << " va=" << va
2901 << std::endl;
2902 }
2903#endif
2904 v = MIN2(va, v);
2905 }
2906 }
2907
2908 // - always issue a request to leave the intersection we are currently on
2909 const bool leavingCurrentIntersection = myLane->getEdge().isInternal() && lastLink == nullptr;
2910 // - do not issue a request to enter an intersection after we already slowed down for an earlier one
2911 const bool abortRequestAfterMinor = slowedDownForMinor && (*link)->getInternalLaneBefore() == nullptr;
2912 // - even if red, if we cannot break we should issue a request
2913 bool setRequest = (v > NUMERICAL_EPS_SPEED && !abortRequestAfterMinor) || (leavingCurrentIntersection);
2914
2915 double stopSpeed = cfModel.stopSpeed(this, getSpeed(), stopDist, stopDecel, MSCFModel::CalcReason::CURRENT_WAIT);
2916 double vLinkWait = MIN2(v, stopSpeed);
2917#ifdef DEBUG_PLAN_MOVE
2918 if (DEBUG_COND) {
2919 std::cout
2920 << " stopDist=" << stopDist
2921 << " stopDecel=" << stopDecel
2922 << " vLinkWait=" << vLinkWait
2923 << " brakeDist=" << brakeDist
2924 << " seen=" << seen
2925 << " leaveIntersection=" << leavingCurrentIntersection
2926 << " setRequest=" << setRequest
2927 //<< std::setprecision(16)
2928 //<< " v=" << v
2929 //<< " speedEps=" << NUMERICAL_EPS_SPEED
2930 //<< std::setprecision(gPrecision)
2931 << "\n";
2932 }
2933#endif
2934
2935 if (yellowOrRed && canBrakeBeforeStopLine && !ignoreRed(*link, canBrakeBeforeStopLine) && seen >= mustSeeBeforeReversal) {
2936 if (lane->isInternal()) {
2937 checkLinkLeaderCurrentAndParallel(*link, lane, seen, lastLink, v, vLinkPass, vLinkWait, setRequest);
2938 }
2939 // arrivalSpeed / arrivalTime when braking for red light is only relevent for rail signal switching
2940 const SUMOTime arrivalTime = getArrivalTime(t, seen, v, vLinkPass);
2941 // the vehicle is able to brake in front of a yellow/red traffic light
2942 lfLinks.push_back(DriveProcessItem(*link, v, vLinkWait, false, arrivalTime, vLinkWait, 0, seen, -1));
2943 //lfLinks.push_back(DriveProcessItem(0, vLinkWait, vLinkWait, false, 0, 0, stopDist));
2944 break;
2945 }
2946
2947 const MSLink* entryLink = (*link)->getCorrespondingEntryLink();
2948 if (entryLink->haveRed() && ignoreRed(*link, canBrakeBeforeStopLine) && STEPS2TIME(t - entryLink->getLastStateChange()) > 2) {
2949 // restrict speed when ignoring a red light
2950 const double redSpeed = MIN2(v, getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_DRIVE_RED_SPEED, v));
2951 const double va = MAX2(redSpeed, cfModel.freeSpeed(this, getSpeed(), seen, redSpeed));
2952 v = MIN2(va, v);
2953#ifdef DEBUG_PLAN_MOVE
2954 if (DEBUG_COND) std::cout
2955 << " ignoreRed spent=" << STEPS2TIME(t - (*link)->getLastStateChange())
2956 << " redSpeed=" << redSpeed
2957 << " va=" << va
2958 << " v=" << v
2959 << "\n";
2960#endif
2961 }
2962
2963 checkLinkLeaderCurrentAndParallel(*link, lane, seen, lastLink, v, vLinkPass, vLinkWait, setRequest);
2964
2965 if (lastLink != nullptr) {
2966 lastLink->adaptLeaveSpeed(laneMaxV);
2967 }
2968 double arrivalSpeed = vLinkPass;
2969 // vehicles should decelerate when approaching a minor link
2970 // - unless they are close enough to have clear visibility of all relevant foe lanes and may start to accelerate again
2971 // - and unless they are so close that stopping is impossible (i.e. when a green light turns to yellow when close to the junction)
2972
2973 // whether the vehicle/driver is close enough to the link to see all possible foes #2123
2974 const double visibilityDistance = (*link)->getFoeVisibilityDistance();
2975 const double determinedFoePresence = seen <= visibilityDistance;
2976// // VARIANT: account for time needed to recognize whether relevant vehicles are on the foe lanes. (Leo)
2977// double foeRecognitionTime = 0.0;
2978// double determinedFoePresence = seen < visibilityDistance - myState.mySpeed*foeRecognitionTime;
2979
2980#ifdef DEBUG_PLAN_MOVE
2981 if (DEBUG_COND) {
2982 std::cout << " approaching link=" << (*link)->getViaLaneOrLane()->getID() << " prio=" << (*link)->havePriority() << " seen=" << seen << " visibilityDistance=" << visibilityDistance << " brakeDist=" << brakeDist << "\n";
2983 }
2984#endif
2985
2986 const bool couldBrakeForMinor = !(*link)->havePriority() && brakeDist < seen && !(*link)->lastWasContMajor();
2987 if (couldBrakeForMinor && !determinedFoePresence) {
2988 // vehicle decelerates just enough to be able to stop if necessary and then accelerates
2989 double maxSpeedAtVisibilityDist = cfModel.maximumSafeStopSpeed(visibilityDistance, cfModel.getMaxDecel(), myState.mySpeed, false, 0., false);
2990 // XXX: estimateSpeedAfterDistance does not use euler-logic (thus returns a lower value than possible here...)
2991 double maxArrivalSpeed = cfModel.estimateSpeedAfterDistance(visibilityDistance, maxSpeedAtVisibilityDist, cfModel.getMaxAccel());
2992 arrivalSpeed = MIN2(vLinkPass, maxArrivalSpeed);
2993 slowedDownForMinor = true;
2994#ifdef DEBUG_PLAN_MOVE
2995 if (DEBUG_COND) {
2996 std::cout << " slowedDownForMinor maxSpeedAtVisDist=" << maxSpeedAtVisibilityDist << " maxArrivalSpeed=" << maxArrivalSpeed << " arrivalSpeed=" << arrivalSpeed << "\n";
2997 }
2998#endif
2999 } else if ((*link)->getState() == LINKSTATE_EQUAL && myWaitingTime > 0) {
3000 // check for deadlock (circular yielding)
3001 //std::cout << SIMTIME << " veh=" << getID() << " check rbl-deadlock\n";
3002 std::pair<const SUMOVehicle*, const MSLink*> blocker = (*link)->getFirstApproachingFoe(*link);
3003 //std::cout << " blocker=" << Named::getIDSecure(blocker.first) << "\n";
3004 int n = 100;
3005 while (blocker.second != nullptr && blocker.second != *link && n > 0) {
3006 blocker = blocker.second->getFirstApproachingFoe(*link);
3007 n--;
3008 //std::cout << " blocker=" << Named::getIDSecure(blocker.first) << "\n";
3009 }
3010 if (n == 0) {
3011 WRITE_WARNINGF(TL("Suspicious right_before_left junction '%'."), lane->getEdge().getToJunction()->getID());
3012 }
3013 //std::cout << " blockerLink=" << blocker.second << " link=" << *link << "\n";
3014 if (blocker.second == *link) {
3015 const double threshold = (*link)->getDirection() == LinkDirection::STRAIGHT ? 0.25 : 0.75;
3016 if (RandHelper::rand(getRNG()) < threshold) {
3017 //std::cout << " abort request, threshold=" << threshold << "\n";
3018 setRequest = false;
3019 }
3020 }
3021 }
3022
3023 const SUMOTime arrivalTime = getArrivalTime(t, seen, v, arrivalSpeed);
3024 if (couldBrakeForMinor && determinedFoePresence && (*link)->getLane()->getEdge().isRoundabout()) {
3025 const bool wasOpened = (*link)->opened(arrivalTime, arrivalSpeed, arrivalSpeed,
3027 getCarFollowModel().getMaxDecel(),
3029 nullptr, false, this);
3030 if (!wasOpened) {
3031 slowedDownForMinor = true;
3032 }
3033#ifdef DEBUG_PLAN_MOVE
3034 if (DEBUG_COND) {
3035 std::cout << " slowedDownForMinor at roundabout=" << (!wasOpened) << "\n";
3036 }
3037#endif
3038 }
3039
3040 // compute arrival speed and arrival time if vehicle starts braking now
3041 // if stopping is possible, arrivalTime can be arbitrarily large. A small value keeps fractional times (impatience) meaningful
3042 double arrivalSpeedBraking = 0;
3043 const double bGap = cfModel.brakeGap(v);
3044 if (seen < bGap && !isStopped() && !planningToStop) { // XXX: should this use the current speed (at least for the ballistic case)? (Leo) Refs. #2575
3045 // vehicle cannot come to a complete stop in time
3047 arrivalSpeedBraking = cfModel.getMinimalArrivalSpeedEuler(seen, v);
3048 // due to discrete/continuous mismatch (when using Euler update) we have to ensure that braking actually helps
3049 arrivalSpeedBraking = MIN2(arrivalSpeedBraking, arrivalSpeed);
3050 } else {
3051 arrivalSpeedBraking = cfModel.getMinimalArrivalSpeed(seen, myState.mySpeed);
3052 }
3053 }
3054
3055 // estimate leave speed for passing time computation
3056 // l=linkLength, a=accel, t=continuousTime, v=vLeave
3057 // l=v*t + 0.5*a*t^2, solve for t and multiply with a, then add v
3058 const double estimatedLeaveSpeed = MIN2((*link)->getViaLaneOrLane()->getVehicleMaxSpeed(this, maxVD),
3059 getCarFollowModel().estimateSpeedAfterDistance((*link)->getLength(), arrivalSpeed, getVehicleType().getCarFollowModel().getMaxAccel()));
3060 lfLinks.push_back(DriveProcessItem(*link, v, vLinkWait, setRequest,
3061 arrivalTime, arrivalSpeed,
3062 arrivalSpeedBraking,
3063 seen, estimatedLeaveSpeed));
3064 if ((*link)->getViaLane() == nullptr) {
3065 hadNonInternal = true;
3066 ++view;
3067 }
3068#ifdef DEBUG_PLAN_MOVE
3069 if (DEBUG_COND) {
3070 std::cout << " checkAbort setRequest=" << setRequest << " v=" << v << " seen=" << seen << " dist=" << dist
3071 << " seenNonInternal=" << seenNonInternal
3072 << " seenInternal=" << seenInternal << " length=" << vehicleLength << "\n";
3073 }
3074#endif
3075 // we need to look ahead far enough to see available space for checkRewindLinkLanes
3076 if ((!setRequest || v <= 0 || seen > dist) && hadNonInternal && seenNonInternal > MAX2(vehicleLength * CRLL_LOOK_AHEAD, vehicleLength + seenInternal) && foundRailSignal) {
3077 break;
3078 }
3079 // get the following lane
3080 lane = (*link)->getViaLaneOrLane();
3081 laneMaxV = lane->getVehicleMaxSpeed(this, maxVD);
3083 laneMaxV = std::numeric_limits<double>::max();
3084 }
3085 // the link was passed
3086 // compute the velocity to use when the link is not blocked by other vehicles
3087 // the vehicle shall be not faster when reaching the next lane than allowed
3088 // speed limits are not emergencies (e.g. when the limit changes suddenly due to TraCI or a variableSpeedSignal)
3089 const double va = MAX2(cfModel.freeSpeed(this, getSpeed(), seen, laneMaxV), vMinComfortable - NUMERICAL_EPS);
3090 v = MIN2(va, v);
3091#ifdef DEBUG_PLAN_MOVE
3092 if (DEBUG_COND) {
3093 std::cout << " laneMaxV=" << laneMaxV << " freeSpeed=" << va << " v=" << v << "\n";
3094 }
3095#endif
3096 if (lane->getEdge().isInternal()) {
3097 seenInternal += lane->getLength();
3098 } else {
3099 seenNonInternal += lane->getLength();
3100 }
3101 // do not restrict results to the current vehicle to allow caching for the current time step
3102 leaderLane = opposite ? lane->getParallelOpposite() : lane;
3103 if (leaderLane == nullptr) {
3104
3105 break;
3106 }
3107 ahead = opposite ? MSLeaderInfo(leaderLane->getWidth()) : leaderLane->getLastVehicleInformation(nullptr, 0);
3108 seen += lane->getLength();
3109 vLinkPass = MIN2(cfModel.estimateSpeedAfterDistance(lane->getLength(), v, cfModel.getMaxAccel()), laneMaxV); // upper bound
3110 lastLink = &lfLinks.back();
3111 }
3112
3113//#ifdef DEBUG_PLAN_MOVE
3114// if(DEBUG_COND){
3115// std::cout << "planMoveInternal found safe speed v = " << v << std::endl;
3116// }
3117//#endif
3118
3119#ifdef PARALLEL_STOPWATCH
3120 myLane->getStopWatch()[0].stop();
3121#endif
3122}
3123
3124
3125double
3126MSVehicle::slowDownForSchedule(double vMinComfortable) const {
3127 const double sfp = getVehicleType().getParameter().speedFactorPremature;
3128 const MSStop& stop = myStops.front();
3129 std::pair<double, double> timeDist = estimateTimeToNextStop();
3130 double arrivalDelay = SIMTIME + timeDist.first - STEPS2TIME(stop.pars.arrival);
3131 double t = STEPS2TIME(stop.pars.arrival - SIMSTEP);
3134 arrivalDelay += STEPS2TIME(stop.pars.arrival - flexStart);
3135 t = STEPS2TIME(flexStart - SIMSTEP);
3136 } else if (stop.pars.started >= 0 && MSGlobals::gUseStopStarted) {
3137 arrivalDelay += STEPS2TIME(stop.pars.arrival - stop.pars.started);
3138 t = STEPS2TIME(stop.pars.started - SIMSTEP);
3139 }
3140 if (arrivalDelay < 0 && sfp < getChosenSpeedFactor()) {
3141 // we can slow down to better match the schedule (and increase energy efficiency)
3142 const double vSlowDownMin = MAX2(myLane->getSpeedLimit() * sfp, vMinComfortable);
3143 const double s = timeDist.second;
3144 const double b = getCarFollowModel().getMaxDecel();
3145 // x = speed for arriving in t seconds
3146 // u = time at full speed
3147 // u * x + (t - u) * 0.5 * x = s
3148 // t - u = x / b
3149 // eliminate u, solve x
3150 const double radicand = 4 * t * t * b * b - 8 * s * b;
3151 const double x = radicand >= 0 ? t * b - sqrt(radicand) * 0.5 : vSlowDownMin;
3152 double vSlowDown = x < vSlowDownMin ? vSlowDownMin : x;
3153#ifdef DEBUG_PLAN_MOVE
3154 if (DEBUG_COND) {
3155 std::cout << SIMTIME << " veh=" << getID() << " ad=" << arrivalDelay << " t=" << t << " vsm=" << vSlowDownMin
3156 << " r=" << radicand << " vs=" << vSlowDown << "\n";
3157 }
3158#endif
3159 return vSlowDown;
3160 } else if (arrivalDelay > 0 && sfp > getChosenSpeedFactor()) {
3161 // in principle we could up to catch up with the schedule
3162 // but at this point we can only lower the speed, the
3163 // information would have to be used when computing getVehicleMaxSpeed
3164 }
3165 return getMaxSpeed();
3166}
3167
3169MSVehicle::getArrivalTime(SUMOTime t, double seen, double v, double arrivalSpeed) const {
3170 const MSCFModel& cfModel = getCarFollowModel();
3171 SUMOTime arrivalTime;
3173 // @note intuitively it would make sense to compare arrivalSpeed with getSpeed() instead of v
3174 // however, due to the current position update rule (ticket #860) the vehicle moves with v in this step
3175 // subtract DELTA_T because t is the time at the end of this step and the movement is not carried out yet
3176 arrivalTime = t - DELTA_T + cfModel.getMinimalArrivalTime(seen, v, arrivalSpeed);
3177 } else {
3178 arrivalTime = t - DELTA_T + cfModel.getMinimalArrivalTime(seen, myState.mySpeed, arrivalSpeed);
3179 }
3180 if (isStopped()) {
3181 arrivalTime += MAX2((SUMOTime)0, myStops.front().duration);
3182 }
3183 return arrivalTime;
3184}
3185
3186
3187void
3188MSVehicle::adaptToLeaders(const MSLeaderInfo& ahead, double latOffset,
3189 const double seen, DriveProcessItem* const lastLink,
3190 const MSLane* const lane, double& v, double& vLinkPass) const {
3191 int rightmost;
3192 int leftmost;
3193 ahead.getSubLanes(this, latOffset, rightmost, leftmost);
3194#ifdef DEBUG_PLAN_MOVE
3195 if (DEBUG_COND) std::cout << SIMTIME
3196 << "\nADAPT_TO_LEADERS\nveh=" << getID()
3197 << " lane=" << lane->getID()
3198 << " latOffset=" << latOffset
3199 << " rm=" << rightmost
3200 << " lm=" << leftmost
3201 << " shift=" << ahead.getSublaneOffset()
3202 << " ahead=" << ahead.toString()
3203 << "\n";
3204#endif
3205 /*
3206 if (myLaneChangeModel->getCommittedSpeed() > 0) {
3207 v = MIN2(v, myLaneChangeModel->getCommittedSpeed());
3208 vLinkPass = MIN2(vLinkPass, myLaneChangeModel->getCommittedSpeed());
3209 #ifdef DEBUG_PLAN_MOVE
3210 if (DEBUG_COND) std::cout << " hasCommitted=" << myLaneChangeModel->getCommittedSpeed() << "\n";
3211 #endif
3212 return;
3213 }
3214 */
3215 for (int sublane = rightmost; sublane <= leftmost; ++sublane) {
3216 const MSVehicle* pred = ahead[sublane];
3217 if (pred != nullptr && pred != this) {
3218 // @todo avoid multiple adaptations to the same leader
3219 const double predBack = pred->getBackPositionOnLane(lane);
3220 double gap = (lastLink == nullptr
3221 ? predBack - myState.myPos - getVehicleType().getMinGap()
3222 : predBack + seen - lane->getLength() - getVehicleType().getMinGap());
3223 bool oncoming = false;
3225 if (pred->getLaneChangeModel().isOpposite() || lane == pred->getLaneChangeModel().getShadowLane()) {
3226 // ego might and leader are driving against lane
3227 gap = (lastLink == nullptr
3228 ? myState.myPos - predBack - getVehicleType().getMinGap()
3229 : predBack + seen - lane->getLength() - getVehicleType().getMinGap());
3230 } else {
3231 // ego and leader are driving in the same direction as lane (shadowlane for ego)
3232 gap = (lastLink == nullptr
3233 ? predBack - (myLane->getLength() - myState.myPos) - getVehicleType().getMinGap()
3234 : predBack + seen - lane->getLength() - getVehicleType().getMinGap());
3235 }
3236 } else if (pred->getLaneChangeModel().isOpposite() && pred->getLaneChangeModel().getShadowLane() != lane) {
3237 // must react to stopped / dangerous oncoming vehicles
3238 gap += -pred->getVehicleType().getLength() + getVehicleType().getMinGap() - MAX2(getVehicleType().getMinGap(), pred->getVehicleType().getMinGap());
3239 // try to avoid collision in the next second
3240 const double predMaxDist = pred->getSpeed() + pred->getCarFollowModel().getMaxAccel();
3241#ifdef DEBUG_PLAN_MOVE
3242 if (DEBUG_COND) {
3243 std::cout << " fixedGap=" << gap << " predMaxDist=" << predMaxDist << "\n";
3244 }
3245#endif
3246 if (gap < predMaxDist + getSpeed() || pred->getLane() == lane->getBidiLane()) {
3247 gap -= predMaxDist;
3248 }
3249 } else if (pred->getLane() == lane->getBidiLane()) {
3250 gap -= pred->getVehicleType().getLengthWithGap();
3251 oncoming = true;
3252 }
3253#ifdef DEBUG_PLAN_MOVE
3254 if (DEBUG_COND) {
3255 std::cout << " pred=" << pred->getID() << " predLane=" << pred->getLane()->getID() << " predPos=" << pred->getPositionOnLane() << " gap=" << gap << " predBack=" << predBack << " seen=" << seen << " lane=" << lane->getID() << " myLane=" << myLane->getID() << " lastLink=" << (lastLink == nullptr ? "NULL" : lastLink->myLink->getDescription()) << " oncoming=" << oncoming << "\n";
3256 }
3257#endif
3258 if (oncoming && gap >= 0) {
3259 adaptToOncomingLeader(std::make_pair(pred, gap), lastLink, v, vLinkPass);
3260 } else {
3261 adaptToLeader(std::make_pair(pred, gap), seen, lastLink, v, vLinkPass);
3262 }
3263 }
3264 }
3265}
3266
3267void
3269 double seen,
3270 DriveProcessItem* const lastLink,
3271 double& v, double& vLinkPass) const {
3272 int rightmost;
3273 int leftmost;
3274 ahead.getSubLanes(this, latOffset, rightmost, leftmost);
3275#ifdef DEBUG_PLAN_MOVE
3276 if (DEBUG_COND) std::cout << SIMTIME
3277 << "\nADAPT_TO_LEADERS_DISTANCE\nveh=" << getID()
3278 << " latOffset=" << latOffset
3279 << " rm=" << rightmost
3280 << " lm=" << leftmost
3281 << " ahead=" << ahead.toString()
3282 << "\n";
3283#endif
3284 for (int sublane = rightmost; sublane <= leftmost; ++sublane) {
3285 CLeaderDist predDist = ahead[sublane];
3286 const MSVehicle* pred = predDist.first;
3287 if (pred != nullptr && pred != this) {
3288#ifdef DEBUG_PLAN_MOVE
3289 if (DEBUG_COND) {
3290 std::cout << " pred=" << pred->getID() << " predLane=" << pred->getLane()->getID() << " predPos=" << pred->getPositionOnLane() << " gap=" << predDist.second << "\n";
3291 }
3292#endif
3293 adaptToLeader(predDist, seen, lastLink, v, vLinkPass);
3294 }
3295 }
3296}
3297
3298
3299void
3300MSVehicle::adaptToLeader(const std::pair<const MSVehicle*, double> leaderInfo,
3301 double seen,
3302 DriveProcessItem* const lastLink,
3303 double& v, double& vLinkPass) const {
3304 if (leaderInfo.first != 0) {
3305 if (ignoreFoe(leaderInfo.first)) {
3306#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3307 if (DEBUG_COND) {
3308 std::cout << " foe ignored\n";
3309 }
3310#endif
3311 return;
3312 }
3313 const MSCFModel& cfModel = getCarFollowModel();
3314 double vsafeLeader = 0;
3316 vsafeLeader = -std::numeric_limits<double>::max();
3317 }
3318 bool backOnRoute = true;
3319 if (leaderInfo.second < 0 && lastLink != nullptr && lastLink->myLink != nullptr) {
3320 backOnRoute = false;
3321 // this can either be
3322 // a) a merging situation (leader back is is not our route) or
3323 // b) a minGap violation / collision
3324 MSLane* current = lastLink->myLink->getViaLaneOrLane();
3325 if (leaderInfo.first->getBackLane() == current) {
3326 backOnRoute = true;
3327 } else {
3328 for (MSLane* lane : getBestLanesContinuation()) {
3329 if (lane == current) {
3330 break;
3331 }
3332 if (leaderInfo.first->getBackLane() == lane) {
3333 backOnRoute = true;
3334 }
3335 }
3336 }
3337#ifdef DEBUG_PLAN_MOVE
3338 if (DEBUG_COND) {
3339 std::cout << SIMTIME << " current=" << current->getID() << " leaderBackLane=" << leaderInfo.first->getBackLane()->getID() << " backOnRoute=" << backOnRoute << "\n";
3340 }
3341#endif
3342 if (!backOnRoute) {
3343 double stopDist = seen - current->getLength() - POSITION_EPS;
3344 if (lastLink->myLink->getInternalLaneBefore() != nullptr) {
3345 // do not drive onto the junction conflict area
3346 stopDist -= lastLink->myLink->getInternalLaneBefore()->getLength();
3347 }
3348 vsafeLeader = cfModel.stopSpeed(this, getSpeed(), stopDist);
3349 }
3350 }
3351 if (backOnRoute) {
3352 vsafeLeader = cfModel.followSpeed(this, getSpeed(), leaderInfo.second, leaderInfo.first->getSpeed(), leaderInfo.first->getCurrentApparentDecel(), leaderInfo.first);
3353 }
3354 if (lastLink != nullptr) {
3355 const double futureVSafe = cfModel.followSpeed(this, lastLink->accelV, leaderInfo.second, leaderInfo.first->getSpeed(), leaderInfo.first->getCurrentApparentDecel(), leaderInfo.first, MSCFModel::CalcReason::FUTURE);
3356 lastLink->adaptLeaveSpeed(futureVSafe);
3357#ifdef DEBUG_PLAN_MOVE
3358 if (DEBUG_COND) {
3359 std::cout << " vlinkpass=" << lastLink->myVLinkPass << " futureVSafe=" << futureVSafe << "\n";
3360 }
3361#endif
3362 }
3363 v = MIN2(v, vsafeLeader);
3364 vLinkPass = MIN2(vLinkPass, vsafeLeader);
3365#ifdef DEBUG_PLAN_MOVE
3366 if (DEBUG_COND) std::cout
3367 << SIMTIME
3368 //std::cout << std::setprecision(10);
3369 << " veh=" << getID()
3370 << " lead=" << leaderInfo.first->getID()
3371 << " leadSpeed=" << leaderInfo.first->getSpeed()
3372 << " gap=" << leaderInfo.second
3373 << " leadLane=" << leaderInfo.first->getLane()->getID()
3374 << " predPos=" << leaderInfo.first->getPositionOnLane()
3375 << " myLane=" << myLane->getID()
3376 << " v=" << v
3377 << " vSafeLeader=" << vsafeLeader
3378 << " vLinkPass=" << vLinkPass
3379 << "\n";
3380#endif
3381 }
3382}
3383
3384
3385void
3386MSVehicle::adaptToJunctionLeader(const std::pair<const MSVehicle*, double> leaderInfo,
3387 const double seen, DriveProcessItem* const lastLink,
3388 const MSLane* const lane, double& v, double& vLinkPass,
3389 double distToCrossing) const {
3390 if (leaderInfo.first != 0) {
3391 if (ignoreFoe(leaderInfo.first)) {
3392#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3393 if (DEBUG_COND) {
3394 std::cout << " junction foe ignored\n";
3395 }
3396#endif
3397 return;
3398 }
3399 const MSCFModel& cfModel = getCarFollowModel();
3400 double vsafeLeader = 0;
3402 vsafeLeader = -std::numeric_limits<double>::max();
3403 }
3404 if (leaderInfo.second >= 0) {
3405 if (hasDeparted()) {
3406 vsafeLeader = cfModel.followSpeed(this, getSpeed(), leaderInfo.second, leaderInfo.first->getSpeed(), leaderInfo.first->getCurrentApparentDecel(), leaderInfo.first);
3407 } else {
3408 // called in the context of MSLane::isInsertionSuccess
3409 vsafeLeader = cfModel.insertionFollowSpeed(this, getSpeed(), leaderInfo.second, leaderInfo.first->getSpeed(), leaderInfo.first->getCurrentApparentDecel(), leaderInfo.first);
3410 }
3411 } else if (leaderInfo.first != this) {
3412 // the leading, in-lapping vehicle is occupying the complete next lane
3413 // stop before entering this lane
3414 vsafeLeader = cfModel.stopSpeed(this, getSpeed(), seen - lane->getLength() - POSITION_EPS);
3415#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3416 if (DEBUG_COND) {
3417 std::cout << SIMTIME << " veh=" << getID() << " stopping before junction: lane=" << lane->getID() << " seen=" << seen
3418 << " laneLength=" << lane->getLength()
3419 << " stopDist=" << seen - lane->getLength() - POSITION_EPS
3420 << " vsafeLeader=" << vsafeLeader
3421 << " distToCrossing=" << distToCrossing
3422 << "\n";
3423 }
3424#endif
3425 }
3426 if (distToCrossing >= 0) {
3427 // can the leader still stop in the way?
3428 const double vStop = cfModel.stopSpeed(this, getSpeed(), distToCrossing - getVehicleType().getMinGap());
3429 if (leaderInfo.first == this) {
3430 // braking for pedestrian
3431 const double vStopCrossing = cfModel.stopSpeed(this, getSpeed(), distToCrossing);
3432 vsafeLeader = vStopCrossing;
3433#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3434 if (DEBUG_COND) {
3435 std::cout << " breaking for pedestrian distToCrossing=" << distToCrossing << " vStopCrossing=" << vStopCrossing << "\n";
3436 }
3437#endif
3438 if (lastLink != nullptr) {
3439 lastLink->adaptStopSpeed(vsafeLeader);
3440 }
3441 } else if (leaderInfo.second == -std::numeric_limits<double>::max()) {
3442 // drive up to the crossing point and stop
3443#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3444 if (DEBUG_COND) {
3445 std::cout << " stop at crossing point for critical leader vStop=" << vStop << "\n";
3446 };
3447#endif
3448 vsafeLeader = MAX2(vsafeLeader, vStop);
3449 } else {
3450 const double leaderDistToCrossing = distToCrossing - leaderInfo.second;
3451 // estimate the time at which the leader has gone past the crossing point
3452 const double leaderPastCPTime = leaderDistToCrossing / MAX2(leaderInfo.first->getSpeed(), SUMO_const_haltingSpeed);
3453 // reach distToCrossing after that time
3454 // avgSpeed * leaderPastCPTime = distToCrossing
3455 // ballistic: avgSpeed = (getSpeed + vFinal) / 2
3456 const double vFinal = MAX2(getSpeed(), 2 * (distToCrossing - getVehicleType().getMinGap()) / leaderPastCPTime - getSpeed());
3457 const double v2 = getSpeed() + ACCEL2SPEED((vFinal - getSpeed()) / leaderPastCPTime);
3458 vsafeLeader = MAX2(vsafeLeader, MIN2(v2, vStop));
3459#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3460 if (DEBUG_COND) {
3461 std::cout << " driving up to the crossing point (distToCrossing=" << distToCrossing << ")"
3462 << " leaderPastCPTime=" << leaderPastCPTime
3463 << " vFinal=" << vFinal
3464 << " v2=" << v2
3465 << " vStop=" << vStop
3466 << " vsafeLeader=" << vsafeLeader << "\n";
3467 }
3468#endif
3469 }
3470 }
3471 if (lastLink != nullptr) {
3472 lastLink->adaptLeaveSpeed(vsafeLeader);
3473 }
3474 v = MIN2(v, vsafeLeader);
3475 vLinkPass = MIN2(vLinkPass, vsafeLeader);
3476#ifdef DEBUG_PLAN_MOVE
3477 if (DEBUG_COND) std::cout
3478 << SIMTIME
3479 //std::cout << std::setprecision(10);
3480 << " veh=" << getID()
3481 << " lead=" << leaderInfo.first->getID()
3482 << " leadSpeed=" << leaderInfo.first->getSpeed()
3483 << " gap=" << leaderInfo.second
3484 << " leadLane=" << leaderInfo.first->getLane()->getID()
3485 << " predPos=" << leaderInfo.first->getPositionOnLane()
3486 << " seen=" << seen
3487 << " lane=" << lane->getID()
3488 << " myLane=" << myLane->getID()
3489 << " dTC=" << distToCrossing
3490 << " v=" << v
3491 << " vSafeLeader=" << vsafeLeader
3492 << " vLinkPass=" << vLinkPass
3493 << "\n";
3494#endif
3495 }
3496}
3497
3498
3499void
3500MSVehicle::adaptToOncomingLeader(const std::pair<const MSVehicle*, double> leaderInfo,
3501 DriveProcessItem* const lastLink,
3502 double& v, double& vLinkPass) const {
3503 if (leaderInfo.first != 0) {
3504 if (ignoreFoe(leaderInfo.first)) {
3505#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3506 if (DEBUG_COND) {
3507 std::cout << " oncoming foe ignored\n";
3508 }
3509#endif
3510 return;
3511 }
3512 const MSCFModel& cfModel = getCarFollowModel();
3513 const MSVehicle* lead = leaderInfo.first;
3514 const MSCFModel& cfModelL = lead->getCarFollowModel();
3515 // assume the leader reacts symmetrically (neither stopping instantly nor ignoring ego)
3516 const double leaderBrakeGap = cfModelL.brakeGap(lead->getSpeed(), cfModelL.getMaxDecel(), 0);
3517 const double egoBrakeGap = cfModel.brakeGap(getSpeed(), cfModel.getMaxDecel(), 0);
3518 const double gapSum = leaderBrakeGap + egoBrakeGap;
3519 // ensure that both vehicles can leave an intersection if they are currently on it
3520 double egoExit = getDistanceToLeaveJunction();
3521 const double leaderExit = lead->getDistanceToLeaveJunction();
3522 double gap = leaderInfo.second;
3523 if (egoExit + leaderExit < gap) {
3524 gap -= egoExit + leaderExit;
3525 } else {
3526 egoExit = 0;
3527 }
3528 // split any distance in excess of brakeGaps evenly
3529 const double freeGap = MAX2(0.0, gap - gapSum);
3530 const double splitGap = MIN2(gap, gapSum);
3531 // assume remaining distance is allocated in proportion to braking distance
3532 const double gapRatio = gapSum > 0 ? egoBrakeGap / gapSum : 0.5;
3533 const double vsafeLeader = cfModel.stopSpeed(this, getSpeed(), splitGap * gapRatio + egoExit + 0.5 * freeGap);
3534 if (lastLink != nullptr) {
3535 const double futureVSafe = cfModel.stopSpeed(this, lastLink->accelV, leaderInfo.second, MSCFModel::CalcReason::FUTURE);
3536 lastLink->adaptLeaveSpeed(futureVSafe);
3537#ifdef DEBUG_PLAN_MOVE
3538 if (DEBUG_COND) {
3539 std::cout << " vlinkpass=" << lastLink->myVLinkPass << " futureVSafe=" << futureVSafe << "\n";
3540 }
3541#endif
3542 }
3543 v = MIN2(v, vsafeLeader);
3544 vLinkPass = MIN2(vLinkPass, vsafeLeader);
3545#ifdef DEBUG_PLAN_MOVE
3546 if (DEBUG_COND) std::cout
3547 << SIMTIME
3548 //std::cout << std::setprecision(10);
3549 << " veh=" << getID()
3550 << " oncomingLead=" << lead->getID()
3551 << " leadSpeed=" << lead->getSpeed()
3552 << " gap=" << leaderInfo.second
3553 << " gap2=" << gap
3554 << " gapRatio=" << gapRatio
3555 << " leadLane=" << lead->getLane()->getID()
3556 << " predPos=" << lead->getPositionOnLane()
3557 << " myLane=" << myLane->getID()
3558 << " v=" << v
3559 << " vSafeLeader=" << vsafeLeader
3560 << " vLinkPass=" << vLinkPass
3561 << "\n";
3562#endif
3563 }
3564}
3565
3566
3567void
3568MSVehicle::checkLinkLeaderCurrentAndParallel(const MSLink* link, const MSLane* lane, double seen,
3569 DriveProcessItem* const lastLink, double& v, double& vLinkPass, double& vLinkWait, bool& setRequest) const {
3571 // we want to pass the link but need to check for foes on internal lanes
3572 checkLinkLeader(link, lane, seen, lastLink, v, vLinkPass, vLinkWait, setRequest);
3573 if (myLaneChangeModel->getShadowLane() != nullptr) {
3574 const MSLink* const parallelLink = link->getParallelLink(myLaneChangeModel->getShadowDirection());
3575 if (parallelLink != nullptr) {
3576 checkLinkLeader(parallelLink, lane, seen, lastLink, v, vLinkPass, vLinkWait, setRequest, true);
3577 }
3578 }
3579 }
3580
3581}
3582
3583void
3584MSVehicle::checkLinkLeader(const MSLink* link, const MSLane* lane, double seen,
3585 DriveProcessItem* const lastLink, double& v, double& vLinkPass, double& vLinkWait, bool& setRequest,
3586 bool isShadowLink) const {
3587#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3588 if (DEBUG_COND) {
3589 gDebugFlag1 = true; // See MSLink::getLeaderInfo
3590 }
3591#endif
3592 const MSLink::LinkLeaders linkLeaders = link->getLeaderInfo(this, seen, nullptr, isShadowLink);
3593#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3594 if (DEBUG_COND) {
3595 gDebugFlag1 = false; // See MSLink::getLeaderInfo
3596 }
3597#endif
3598 for (MSLink::LinkLeaders::const_iterator it = linkLeaders.begin(); it != linkLeaders.end(); ++it) {
3599 // the vehicle to enter the junction first has priority
3600 const MSVehicle* leader = (*it).vehAndGap.first;
3601 if (leader == nullptr) {
3602 // leader is a pedestrian. Passing 'this' as a dummy.
3603#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3604 if (DEBUG_COND) {
3605 std::cout << SIMTIME << " veh=" << getID() << " is blocked on link to " << link->getViaLaneOrLane()->getID() << " by pedestrian. dist=" << it->distToCrossing << "\n";
3606 }
3607#endif
3610#ifdef DEBUG_PLAN_MOVE
3611 if (DEBUG_COND) {
3612 std::cout << SIMTIME << " veh=" << getID() << " is ignoring pedestrian (jmIgnoreJunctionFoeProb)\n";
3613 }
3614#endif
3615 continue;
3616 }
3617 adaptToJunctionLeader(std::make_pair(this, -1), seen, lastLink, lane, v, vLinkPass, it->distToCrossing);
3618 // if blocked by a pedestrian for too long we must yield our request
3620 setRequest = false;
3621#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3622 if (DEBUG_COND) {
3623 std::cout << " aborting request\n";
3624 }
3625#endif
3626 }
3627 } else if (isLeader(link, leader, (*it).vehAndGap.second) || (*it).inTheWay()) {
3630#ifdef DEBUG_PLAN_MOVE
3631 if (DEBUG_COND) {
3632 std::cout << SIMTIME << " veh=" << getID() << " is ignoring linkLeader=" << leader->getID() << " (jmIgnoreJunctionFoeProb)\n";
3633 }
3634#endif
3635 continue;
3636 }
3638 // sibling link (XXX: could also be partial occupator where this check fails)
3639 &leader->getLane()->getEdge() == &lane->getEdge()) {
3640 // check for sublane obstruction (trivial for sibling link leaders)
3641 const MSLane* conflictLane = link->getInternalLaneBefore();
3642 MSLeaderInfo linkLeadersAhead = MSLeaderInfo(conflictLane->getWidth());
3643 linkLeadersAhead.addLeader(leader, false, 0); // assume sibling lane has the same geometry as the leader lane
3644 const double latOffset = isShadowLink ? (getLane()->getRightSideOnEdge() - myLaneChangeModel->getShadowLane()->getRightSideOnEdge()) : 0;
3645 // leader is neither on lane nor conflictLane (the conflict is only established geometrically)
3646 adaptToLeaders(linkLeadersAhead, latOffset, seen, lastLink, leader->getLane(), v, vLinkPass);
3647#ifdef DEBUG_PLAN_MOVE
3648 if (DEBUG_COND) {
3649 std::cout << SIMTIME << " veh=" << getID()
3650 << " siblingFoe link=" << link->getViaLaneOrLane()->getID()
3651 << " isShadowLink=" << isShadowLink
3652 << " lane=" << lane->getID()
3653 << " foe=" << leader->getID()
3654 << " foeLane=" << leader->getLane()->getID()
3655 << " latOffset=" << latOffset
3656 << " latOffsetFoe=" << leader->getLatOffset(lane)
3657 << " linkLeadersAhead=" << linkLeadersAhead.toString()
3658 << "\n";
3659 }
3660#endif
3661 } else {
3662#ifdef DEBUG_PLAN_MOVE
3663 if (DEBUG_COND) {
3664 std::cout << SIMTIME << " veh=" << getID() << " linkLeader=" << leader->getID() << " gap=" << it->vehAndGap.second
3665 << " ET=" << myJunctionEntryTime << " lET=" << leader->myJunctionEntryTime
3666 << " ETN=" << myJunctionEntryTimeNeverYield << " lETN=" << leader->myJunctionEntryTimeNeverYield
3667 << " CET=" << myJunctionConflictEntryTime << " lCET=" << leader->myJunctionConflictEntryTime
3668 << "\n";
3669 }
3670#endif
3671 adaptToJunctionLeader(it->vehAndGap, seen, lastLink, lane, v, vLinkPass, it->distToCrossing);
3672 }
3673 if (lastLink != nullptr) {
3674 // we are not yet on the junction with this linkLeader.
3675 // at least we can drive up to the previous link and stop there
3676 v = MAX2(v, lastLink->myVLinkWait);
3677 }
3678 // if blocked by a leader from the same or next lane we must yield our request
3679 // also, if blocked by a stopped or blocked leader
3681 //&& leader->getSpeed() < SUMO_const_haltingSpeed
3683 || leader->getLane()->getLogicalPredecessorLane() == myLane
3684 || leader->isStopped()
3686 setRequest = false;
3687#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3688 if (DEBUG_COND) {
3689 std::cout << " aborting request\n";
3690 }
3691#endif
3692 if (lastLink != nullptr && leader->getLane()->getLogicalPredecessorLane() == myLane) {
3693 // we are not yet on the junction so must abort that request as well
3694 // (or maybe we are already on the junction and the leader is a partial occupator beyond)
3695 lastLink->mySetRequest = false;
3696#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3697 if (DEBUG_COND) {
3698 std::cout << " aborting previous request\n";
3699 }
3700#endif
3701 }
3702 }
3703 }
3704#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3705 else {
3706 if (DEBUG_COND) {
3707 std::cout << SIMTIME << " veh=" << getID() << " ignoring leader " << leader->getID() << " gap=" << (*it).vehAndGap.second << " dtC=" << (*it).distToCrossing
3708 << " ET=" << myJunctionEntryTime << " lET=" << leader->myJunctionEntryTime
3709 << " ETN=" << myJunctionEntryTimeNeverYield << " lETN=" << leader->myJunctionEntryTimeNeverYield
3710 << " CET=" << myJunctionConflictEntryTime << " lCET=" << leader->myJunctionConflictEntryTime
3711 << "\n";
3712 }
3713 }
3714#endif
3715 }
3716 // if this is the link between two internal lanes we may have to slow down for pedestrians
3717 vLinkWait = MIN2(vLinkWait, v);
3718}
3719
3720
3721double
3722MSVehicle::getDeltaPos(const double accel) const {
3723 double vNext = myState.mySpeed + ACCEL2SPEED(accel);
3725 // apply implicit Euler positional update
3726 return SPEED2DIST(MAX2(vNext, 0.));
3727 } else {
3728 // apply ballistic update
3729 if (vNext >= 0) {
3730 // assume constant acceleration during this time step
3731 return SPEED2DIST(myState.mySpeed + 0.5 * ACCEL2SPEED(accel));
3732 } else {
3733 // negative vNext indicates a stop within the middle of time step
3734 // The corresponding stop time is s = mySpeed/deceleration \in [0,dt], and the
3735 // covered distance is therefore deltaPos = mySpeed*s - 0.5*deceleration*s^2.
3736 // Here, deceleration = (myState.mySpeed - vNext)/dt is the constant deceleration
3737 // until the vehicle stops.
3738 return -SPEED2DIST(0.5 * myState.mySpeed * myState.mySpeed / ACCEL2SPEED(accel));
3739 }
3740 }
3741}
3742
3743void
3744MSVehicle::processLinkApproaches(double& vSafe, double& vSafeMin, double& vSafeMinDist) {
3745
3746 const MSCFModel& cfModel = getCarFollowModel();
3747 // Speed limit due to zipper merging
3748 double vSafeZipper = std::numeric_limits<double>::max();
3749
3750 myHaveToWaitOnNextLink = false;
3751 bool canBrakeVSafeMin = false;
3752
3753 // Get safe velocities from DriveProcessItems.
3754 assert(myLFLinkLanes.size() != 0 || isRemoteControlled());
3755 for (const DriveProcessItem& dpi : myLFLinkLanes) {
3756 MSLink* const link = dpi.myLink;
3757
3758#ifdef DEBUG_EXEC_MOVE
3759 if (DEBUG_COND) {
3760 std::cout
3761 << SIMTIME
3762 << " veh=" << getID()
3763 << " link=" << (link == 0 ? "NULL" : link->getViaLaneOrLane()->getID())
3764 << " req=" << dpi.mySetRequest
3765 << " vP=" << dpi.myVLinkPass
3766 << " vW=" << dpi.myVLinkWait
3767 << " d=" << dpi.myDistance
3768 << "\n";
3769 gDebugFlag1 = true; // See MSLink_DEBUG_OPENED
3770 }
3771#endif
3772
3773 // the vehicle must change the lane on one of the next lanes (XXX: refs to code further below???, Leo)
3774 if (link != nullptr && dpi.mySetRequest) {
3775
3776 const LinkState ls = link->getState();
3777 // vehicles should brake when running onto a yellow light if the distance allows to halt in front
3778 const bool yellow = link->haveYellow();
3779 const bool canBrake = (dpi.myDistance > cfModel.brakeGap(myState.mySpeed, cfModel.getMaxDecel(), 0.)
3781 assert(link->getLaneBefore() != nullptr);
3782 const bool beyondStopLine = dpi.myDistance < link->getLaneBefore()->getVehicleStopOffset(this);
3783 const bool ignoreRedLink = ignoreRed(link, canBrake) || beyondStopLine;
3784 if (yellow && canBrake && !ignoreRedLink) {
3785 vSafe = dpi.myVLinkWait;
3787#ifdef DEBUG_CHECKREWINDLINKLANES
3788 if (DEBUG_COND) {
3789 std::cout << SIMTIME << " veh=" << getID() << " haveToWait (yellow)\n";
3790 }
3791#endif
3792 break;
3793 }
3794 const bool influencerPrio = (myInfluencer != nullptr && !myInfluencer->getRespectJunctionPriority());
3795 MSLink::BlockingFoes collectFoes;
3796 bool opened = (yellow || influencerPrio
3797 || link->opened(dpi.myArrivalTime, dpi.myArrivalSpeed, dpi.getLeaveSpeed(),
3799 canBrake ? getImpatience() : 1,
3800 cfModel.getMaxDecel(),
3802 ls == LINKSTATE_ZIPPER ? &collectFoes : nullptr,
3803 ignoreRedLink, this, dpi.myDistance));
3804 if (opened && myLaneChangeModel->getShadowLane() != nullptr) {
3805 const MSLink* const parallelLink = dpi.myLink->getParallelLink(myLaneChangeModel->getShadowDirection());
3806 if (parallelLink != nullptr) {
3807 const double shadowLatPos = getLateralPositionOnLane() - myLaneChangeModel->getShadowDirection() * 0.5 * (
3809 opened = yellow || influencerPrio || (opened && parallelLink->opened(dpi.myArrivalTime, dpi.myArrivalSpeed, dpi.getLeaveSpeed(),
3811 cfModel.getMaxDecel(),
3812 getWaitingTimeFor(link), shadowLatPos, nullptr,
3813 ignoreRedLink, this, dpi.myDistance));
3814#ifdef DEBUG_EXEC_MOVE
3815 if (DEBUG_COND) {
3816 std::cout << SIMTIME
3817 << " veh=" << getID()
3818 << " shadowLane=" << myLaneChangeModel->getShadowLane()->getID()
3819 << " shadowDir=" << myLaneChangeModel->getShadowDirection()
3820 << " parallelLink=" << (parallelLink == 0 ? "NULL" : parallelLink->getViaLaneOrLane()->getID())
3821 << " opened=" << opened
3822 << "\n";
3823 }
3824#endif
3825 }
3826 }
3827 // vehicles should decelerate when approaching a minor link
3828#ifdef DEBUG_EXEC_MOVE
3829 if (DEBUG_COND) {
3830 std::cout << SIMTIME
3831 << " opened=" << opened
3832 << " influencerPrio=" << influencerPrio
3833 << " linkPrio=" << link->havePriority()
3834 << " lastContMajor=" << link->lastWasContMajor()
3835 << " isCont=" << link->isCont()
3836 << " ignoreRed=" << ignoreRedLink
3837 << "\n";
3838 }
3839#endif
3840 double visibilityDistance = link->getFoeVisibilityDistance();
3841 bool determinedFoePresence = dpi.myDistance <= visibilityDistance;
3842 if (opened && !influencerPrio && !link->havePriority() && !link->lastWasContMajor() && !link->isCont() && !ignoreRedLink) {
3843 if (!determinedFoePresence && (canBrake || !yellow)) {
3844 vSafe = dpi.myVLinkWait;
3846#ifdef DEBUG_CHECKREWINDLINKLANES
3847 if (DEBUG_COND) {
3848 std::cout << SIMTIME << " veh=" << getID() << " haveToWait (minor)\n";
3849 }
3850#endif
3851 break;
3852 } else {
3853 // past the point of no return. we need to drive fast enough
3854 // to make it across the link. However, minor slowdowns
3855 // should be permissible to follow leading traffic safely
3856 // basically, this code prevents dawdling
3857 // (it's harder to do this later using
3858 // SUMO_ATTR_JM_SIGMA_MINOR because we don't know whether the
3859 // vehicle is already too close to stop at that part of the code)
3860 //
3861 // XXX: There is a problem in subsecond simulation: If we cannot
3862 // make it across the minor link in one step, new traffic
3863 // could appear on a major foe link and cause a collision. Refs. #1845, #2123
3864 vSafeMinDist = dpi.myDistance; // distance that must be covered
3866 vSafeMin = MIN3((double)DIST2SPEED(vSafeMinDist + POSITION_EPS), dpi.myVLinkPass, cfModel.maxNextSafeMin(getSpeed(), this));
3867 } else {
3868 vSafeMin = MIN3((double)DIST2SPEED(2 * vSafeMinDist + NUMERICAL_EPS) - getSpeed(), dpi.myVLinkPass, cfModel.maxNextSafeMin(getSpeed(), this));
3869 }
3870 canBrakeVSafeMin = canBrake;
3871#ifdef DEBUG_EXEC_MOVE
3872 if (DEBUG_COND) {
3873 std::cout << " vSafeMin=" << vSafeMin << " vSafeMinDist=" << vSafeMinDist << " canBrake=" << canBrake << "\n";
3874 }
3875#endif
3876 }
3877 }
3878 // have waited; may pass if opened...
3879 if (opened) {
3880 vSafe = dpi.myVLinkPass;
3881 if (vSafe < cfModel.getMaxDecel() && vSafe <= dpi.myVLinkWait && vSafe < cfModel.maxNextSpeed(getSpeed(), this)) {
3882 // this vehicle is probably not gonna drive across the next junction (heuristic)
3884#ifdef DEBUG_CHECKREWINDLINKLANES
3885 if (DEBUG_COND) {
3886 std::cout << SIMTIME << " veh=" << getID() << " haveToWait (very slow)\n";
3887 }
3888#endif
3889 }
3890 if (link->mustStop() && determinedFoePresence && myHaveStoppedFor == nullptr) {
3891 myHaveStoppedFor = link;
3892 }
3893 } else if (link->getState() == LINKSTATE_ZIPPER) {
3894 vSafeZipper = MIN2(vSafeZipper,
3895 link->getZipperSpeed(this, dpi.myDistance, dpi.myVLinkPass, dpi.myArrivalTime, &collectFoes));
3896 } else if (!canBrake
3897 // always brake hard for traffic lights (since an emergency stop is necessary anyway)
3898 && link->getTLLogic() == nullptr
3899 // cannot brake even with emergency deceleration
3900 && dpi.myDistance < cfModel.brakeGap(myState.mySpeed, cfModel.getEmergencyDecel(), 0.)) {
3901#ifdef DEBUG_EXEC_MOVE
3902 if (DEBUG_COND) {
3903 std::cout << SIMTIME << " too fast to brake for closed link\n";
3904 }
3905#endif
3906 vSafe = dpi.myVLinkPass;
3907 } else {
3908 vSafe = dpi.myVLinkWait;
3910#ifdef DEBUG_CHECKREWINDLINKLANES
3911 if (DEBUG_COND) {
3912 std::cout << SIMTIME << " veh=" << getID() << " haveToWait (closed)\n";
3913 }
3914#endif
3915#ifdef DEBUG_EXEC_MOVE
3916 if (DEBUG_COND) {
3917 std::cout << SIMTIME << " braking for closed link=" << link->getViaLaneOrLane()->getID() << "\n";
3918 }
3919#endif
3920 break;
3921 }
3923 // request was renewed, restoring entry time
3924 // @note: using myJunctionEntryTimeNeverYield could lead to inconsistencies with other vehicles already on the junction
3926 }
3927 } else {
3928 if (link != nullptr && link->getInternalLaneBefore() != nullptr && myLane->isInternal() && link->getJunction() == myLane->getEdge().getToJunction()) {
3929 // blocked on the junction. yield request so other vehicles may
3930 // become junction leader
3931#ifdef DEBUG_EXEC_MOVE
3932 if (DEBUG_COND) {
3933 std::cout << SIMTIME << " resetting junctionEntryTime at junction '" << link->getJunction()->getID() << "' beause of non-request exitLink\n";
3934 }
3935#endif
3938 }
3939 // we have: i->link == 0 || !i->setRequest
3940 vSafe = dpi.myVLinkWait;
3941 if (link != nullptr || myStopDist < (myLane->getLength() - getPositionOnLane())) {
3942 if (vSafe < getSpeed()) {
3944#ifdef DEBUG_CHECKREWINDLINKLANES
3945 if (DEBUG_COND) {
3946 std::cout << SIMTIME << " veh=" << getID() << " haveToWait (no request, braking) vSafe=" << vSafe << "\n";
3947 }
3948#endif
3949 } else if (vSafe < SUMO_const_haltingSpeed) {
3951#ifdef DEBUG_CHECKREWINDLINKLANES
3952 if (DEBUG_COND) {
3953 std::cout << SIMTIME << " veh=" << getID() << " haveToWait (no request, stopping)\n";
3954 }
3955#endif
3956 }
3957 }
3958 if (link == nullptr && myLFLinkLanes.size() == 1
3959 && getBestLanesContinuation().size() > 1
3960 && getBestLanesContinuation()[1]->hadPermissionChanges()
3961 && myLane->getFirstAnyVehicle() == this) {
3962 // temporal lane closing without notification, visible to the
3963 // vehicle at the front of the queue
3964 updateBestLanes(true);
3965 //std::cout << SIMTIME << " veh=" << getID() << " updated bestLanes=" << toString(getBestLanesContinuation()) << "\n";
3966 }
3967 break;
3968 }
3969 }
3970
3971//#ifdef DEBUG_EXEC_MOVE
3972// if (DEBUG_COND) {
3973// std::cout << "\nvCurrent = " << toString(getSpeed(), 24) << "" << std::endl;
3974// std::cout << "vSafe = " << toString(vSafe, 24) << "" << std::endl;
3975// std::cout << "vSafeMin = " << toString(vSafeMin, 24) << "" << std::endl;
3976// std::cout << "vSafeMinDist = " << toString(vSafeMinDist, 24) << "" << std::endl;
3977//
3978// double gap = getLeader().second;
3979// std::cout << "gap = " << toString(gap, 24) << std::endl;
3980// std::cout << "vSafeStoppedLeader = " << toString(getCarFollowModel().stopSpeed(this, getSpeed(), gap, MSCFModel::CalcReason::FUTURE), 24)
3981// << "\n" << std::endl;
3982// }
3983//#endif
3984
3985 if ((MSGlobals::gSemiImplicitEulerUpdate && vSafe + NUMERICAL_EPS < vSafeMin)
3986 || (!MSGlobals::gSemiImplicitEulerUpdate && (vSafe + NUMERICAL_EPS < vSafeMin && vSafeMin != 0))) { // this might be good for the euler case as well
3987 // XXX: (Leo) This often called stopSpeed with vSafeMinDist==0 (for the ballistic update), since vSafe can become negative
3988 // For the Euler update the term '+ NUMERICAL_EPS' prevented a call here... Recheck, consider of -INVALID_SPEED instead of 0 to indicate absence of vSafeMin restrictions. Refs. #2577
3989#ifdef DEBUG_EXEC_MOVE
3990 if (DEBUG_COND) {
3991 std::cout << "vSafeMin Problem? vSafe=" << vSafe << " vSafeMin=" << vSafeMin << " vSafeMinDist=" << vSafeMinDist << std::endl;
3992 }
3993#endif
3994 if (canBrakeVSafeMin && vSafe < getSpeed()) {
3995 // cannot drive across a link so we need to stop before it
3996 vSafe = MIN2(vSafe, MAX2(getCarFollowModel().minNextSpeed(getSpeed(), this),
3997 getCarFollowModel().stopSpeed(this, getSpeed(), vSafeMinDist)));
3998 vSafeMin = 0;
4000#ifdef DEBUG_CHECKREWINDLINKLANES
4001 if (DEBUG_COND) {
4002 std::cout << SIMTIME << " veh=" << getID() << " haveToWait (vSafe=" << vSafe << " < vSafeMin=" << vSafeMin << ")\n";
4003 }
4004#endif
4005 } else {
4006 // if the link is yellow or visibility distance is large
4007 // then we might not make it across the link in one step anyway..
4008 // Possibly, the lane after the intersection has a lower speed limit so
4009 // we really need to drive slower already
4010 // -> keep driving without dawdling
4011 vSafeMin = vSafe;
4012 }
4013 }
4014
4015 // vehicles inside a roundabout should maintain their requests
4016 if (myLane->getEdge().isRoundabout()) {
4017 myHaveToWaitOnNextLink = false;
4018 }
4019
4020 vSafe = MIN2(vSafe, vSafeZipper);
4021}
4022
4023
4024double
4025MSVehicle::processTraCISpeedControl(double vSafe, double vNext) {
4026 if (myInfluencer != nullptr) {
4028#ifdef DEBUG_TRACI
4029 if DEBUG_COND2(this) {
4030 std::cout << SIMTIME << " MSVehicle::processTraCISpeedControl() for vehicle '" << getID() << "'"
4031 << " vSafe=" << vSafe << " (init)vNext=" << vNext << " keepStopping=" << keepStopping();
4032 }
4033#endif
4036 }
4037 const double vMax = getVehicleType().getCarFollowModel().maxNextSpeed(myState.mySpeed, this);
4040 vMin = MAX2(0., vMin);
4041 }
4042 vNext = myInfluencer->influenceSpeed(MSNet::getInstance()->getCurrentTimeStep(), vNext, vSafe, vMin, vMax);
4043 if (keepStopping() && myStops.front().getSpeed() == 0) {
4044 // avoid driving while stopped (unless it's actually a waypoint
4045 vNext = myInfluencer->getOriginalSpeed();
4046 }
4047#ifdef DEBUG_TRACI
4048 if DEBUG_COND2(this) {
4049 std::cout << " (processed)vNext=" << vNext << std::endl;
4050 }
4051#endif
4052 }
4053 return vNext;
4054}
4055
4056
4057void
4059#ifdef DEBUG_ACTIONSTEPS
4060 if (DEBUG_COND) {
4061 std::cout << SIMTIME << " veh=" << getID() << " removePassedDriveItems()\n"
4062 << " Current items: ";
4063 for (auto& j : myLFLinkLanes) {
4064 if (j.myLink == 0) {
4065 std::cout << "\n Stop at distance " << j.myDistance;
4066 } else {
4067 const MSLane* to = j.myLink->getViaLaneOrLane();
4068 const MSLane* from = j.myLink->getLaneBefore();
4069 std::cout << "\n Link at distance " << j.myDistance << ": '"
4070 << (from == 0 ? "NONE" : from->getID()) << "' -> '" << (to == 0 ? "NONE" : to->getID()) << "'";
4071 }
4072 }
4073 std::cout << "\n myNextDriveItem: ";
4074 if (myLFLinkLanes.size() != 0) {
4075 if (myNextDriveItem->myLink == 0) {
4076 std::cout << "\n Stop at distance " << myNextDriveItem->myDistance;
4077 } else {
4078 const MSLane* to = myNextDriveItem->myLink->getViaLaneOrLane();
4079 const MSLane* from = myNextDriveItem->myLink->getLaneBefore();
4080 std::cout << "\n Link at distance " << myNextDriveItem->myDistance << ": '"
4081 << (from == 0 ? "NONE" : from->getID()) << "' -> '" << (to == 0 ? "NONE" : to->getID()) << "'";
4082 }
4083 }
4084 std::cout << std::endl;
4085 }
4086#endif
4087 for (auto j = myLFLinkLanes.begin(); j != myNextDriveItem; ++j) {
4088#ifdef DEBUG_ACTIONSTEPS
4089 if (DEBUG_COND) {
4090 std::cout << " Removing item: ";
4091 if (j->myLink == 0) {
4092 std::cout << "Stop at distance " << j->myDistance;
4093 } else {
4094 const MSLane* to = j->myLink->getViaLaneOrLane();
4095 const MSLane* from = j->myLink->getLaneBefore();
4096 std::cout << "Link at distance " << j->myDistance << ": '"
4097 << (from == 0 ? "NONE" : from->getID()) << "' -> '" << (to == 0 ? "NONE" : to->getID()) << "'";
4098 }
4099 std::cout << std::endl;
4100 }
4101#endif
4102 if (j->myLink != nullptr) {
4103 j->myLink->removeApproaching(this);
4104 }
4105 }
4108}
4109
4110
4111void
4113#ifdef DEBUG_ACTIONSTEPS
4114 if (DEBUG_COND) {
4115 std::cout << SIMTIME << " updateDriveItems(), veh='" << getID() << "' (lane: '" << getLane()->getID() << "')\nCurrent drive items:" << std::endl;
4116 for (const auto& dpi : myLFLinkLanes) {
4117 std::cout
4118 << " vPass=" << dpi.myVLinkPass
4119 << " vWait=" << dpi.myVLinkWait
4120 << " linkLane=" << (dpi.myLink == 0 ? "NULL" : dpi.myLink->getViaLaneOrLane()->getID())
4121 << " request=" << dpi.mySetRequest
4122 << "\n";
4123 }
4124 std::cout << " myNextDriveItem's linked lane: " << (myNextDriveItem->myLink == 0 ? "NULL" : myNextDriveItem->myLink->getViaLaneOrLane()->getID()) << std::endl;
4125 }
4126#endif
4127 if (myLFLinkLanes.size() == 0) {
4128 // nothing to update
4129 return;
4130 }
4131 const MSLink* nextPlannedLink = nullptr;
4132// auto i = myLFLinkLanes.begin();
4133 auto i = myNextDriveItem;
4134 while (i != myLFLinkLanes.end() && nextPlannedLink == nullptr) {
4135 nextPlannedLink = i->myLink;
4136 ++i;
4137 }
4138
4139 if (nextPlannedLink == nullptr) {
4140 // No link for upcoming item -> no need for an update
4141#ifdef DEBUG_ACTIONSTEPS
4142 if (DEBUG_COND) {
4143 std::cout << "Found no link-related drive item." << std::endl;
4144 }
4145#endif
4146 return;
4147 }
4148
4149 if (getLane() == nextPlannedLink->getLaneBefore()) {
4150 // Current lane approaches the stored next link, i.e. no LC happend and no update is required.
4151#ifdef DEBUG_ACTIONSTEPS
4152 if (DEBUG_COND) {
4153 std::cout << "Continuing on planned lane sequence, no update required." << std::endl;
4154 }
4155#endif
4156 return;
4157 }
4158 // Lane must have been changed, determine the change direction
4159 const MSLink* parallelLink = nextPlannedLink->getParallelLink(1);
4160 if (parallelLink != nullptr && parallelLink->getLaneBefore() == getLane()) {
4161 // lcDir = 1;
4162 } else {
4163 parallelLink = nextPlannedLink->getParallelLink(-1);
4164 if (parallelLink != nullptr && parallelLink->getLaneBefore() == getLane()) {
4165 // lcDir = -1;
4166 } else {
4167 // If the vehicle's current lane is not the approaching lane for the next
4168 // drive process item's link, it is expected to lead to a parallel link,
4169 // XXX: What if the lc was an overtaking maneuver and there is no upcoming link?
4170 // Then a stop item should be scheduled! -> TODO!
4171 //assert(false);
4172 return;
4173 }
4174 }
4175#ifdef DEBUG_ACTIONSTEPS
4176 if (DEBUG_COND) {
4177 std::cout << "Changed lane. Drive items will be updated along the current lane continuation." << std::endl;
4178 }
4179#endif
4180 // Trace link sequence along current best lanes and transfer drive items to the corresponding links
4181// DriveItemVector::iterator driveItemIt = myLFLinkLanes.begin();
4182 DriveItemVector::iterator driveItemIt = myNextDriveItem;
4183 // In the loop below, lane holds the currently considered lane on the vehicles continuation (including internal lanes)
4184 const MSLane* lane = myLane;
4185 assert(myLane == parallelLink->getLaneBefore());
4186 // *lit is a pointer to the next lane in best continuations for the current lane (always non-internal)
4187 std::vector<MSLane*>::const_iterator bestLaneIt = getBestLanesContinuation().begin() + 1;
4188 // Pointer to the new link for the current drive process item
4189 MSLink* newLink = nullptr;
4190 while (driveItemIt != myLFLinkLanes.end()) {
4191 if (driveItemIt->myLink == nullptr) {
4192 // Items not related to a specific link are not updated
4193 // (XXX: when a stop item corresponded to a dead end, which is overcome by the LC that made
4194 // the update necessary, this may slow down the vehicle's continuation on the new lane...)
4195 ++driveItemIt;
4196 continue;
4197 }
4198 // Continuation links for current best lanes are less than for the former drive items (myLFLinkLanes)
4199 // We just remove the leftover link-items, as they cannot be mapped to new links.
4200 if (bestLaneIt == getBestLanesContinuation().end()) {
4201#ifdef DEBUG_ACTIONSTEPS
4202 if (DEBUG_COND) {
4203 std::cout << "Reached end of the new continuation sequence. Erasing leftover link-items." << std::endl;
4204 }
4205#endif
4206 while (driveItemIt != myLFLinkLanes.end()) {
4207 if (driveItemIt->myLink == nullptr) {
4208 ++driveItemIt;
4209 continue;
4210 } else {
4211 driveItemIt->myLink->removeApproaching(this);
4212 driveItemIt = myLFLinkLanes.erase(driveItemIt);
4213 }
4214 }
4215 break;
4216 }
4217 // Do the actual link-remapping for the item. And un/register approaching information on the corresponding links
4218 const MSLane* const target = *bestLaneIt;
4219 assert(!target->isInternal());
4220 newLink = nullptr;
4221 for (MSLink* const link : lane->getLinkCont()) {
4222 if (link->getLane() == target) {
4223 newLink = link;
4224 break;
4225 }
4226 }
4227
4228 if (newLink == driveItemIt->myLink) {
4229 // new continuation merged into previous - stop update
4230#ifdef DEBUG_ACTIONSTEPS
4231 if (DEBUG_COND) {
4232 std::cout << "Old and new continuation sequences merge at link\n"
4233 << "'" << newLink->getLaneBefore()->getID() << "'->'" << newLink->getViaLaneOrLane()->getID() << "'"
4234 << "\nNo update beyond merge required." << std::endl;
4235 }
4236#endif
4237 break;
4238 }
4239
4240#ifdef DEBUG_ACTIONSTEPS
4241 if (DEBUG_COND) {
4242 std::cout << "lane=" << lane->getID() << "\nUpdating link\n '" << driveItemIt->myLink->getLaneBefore()->getID() << "'->'" << driveItemIt->myLink->getViaLaneOrLane()->getID() << "'"
4243 << "==> " << "'" << newLink->getLaneBefore()->getID() << "'->'" << newLink->getViaLaneOrLane()->getID() << "'" << std::endl;
4244 }
4245#endif
4246 newLink->setApproaching(this, driveItemIt->myLink->getApproaching(this));
4247 driveItemIt->myLink->removeApproaching(this);
4248 driveItemIt->myLink = newLink;
4249 lane = newLink->getViaLaneOrLane();
4250 ++driveItemIt;
4251 if (!lane->isInternal()) {
4252 ++bestLaneIt;
4253 }
4254 }
4255#ifdef DEBUG_ACTIONSTEPS
4256 if (DEBUG_COND) {
4257 std::cout << "Updated drive items:" << std::endl;
4258 for (const auto& dpi : myLFLinkLanes) {
4259 std::cout
4260 << " vPass=" << dpi.myVLinkPass
4261 << " vWait=" << dpi.myVLinkWait
4262 << " linkLane=" << (dpi.myLink == 0 ? "NULL" : dpi.myLink->getViaLaneOrLane()->getID())
4263 << " request=" << dpi.mySetRequest
4264 << "\n";
4265 }
4266 }
4267#endif
4268}
4269
4270
4271void
4273 // To avoid casual blinking brake lights at high speeds due to dawdling of the
4274 // leading vehicle, we don't show brake lights when the deceleration could be caused
4275 // by frictional forces and air resistance (i.e. proportional to v^2, coefficient could be adapted further)
4276 double pseudoFriction = (0.05 + 0.005 * getSpeed()) * getSpeed();
4277 bool brakelightsOn = vNext < getSpeed() - ACCEL2SPEED(pseudoFriction);
4278
4279 if (vNext <= SUMO_const_haltingSpeed) {
4280 brakelightsOn = true;
4281 }
4282 if (brakelightsOn && !isStopped()) {
4284 } else {
4286 }
4287}
4288
4289
4290void
4295 } else {
4296 myWaitingTime = 0;
4298 if (hasInfluencer()) {
4300 }
4301 }
4302}
4303
4304
4305void
4307 // update time loss (depends on the updated edge)
4308 if (!isStopped()) {
4309 // some cfModels (i.e. EIDM may drive faster than predicted by maxNextSpeed)
4310 const double vmax = MIN2(myLane->getVehicleMaxSpeed(this), MAX2(myStopSpeed, vNext));
4311 if (vmax > 0) {
4312 myTimeLoss += TS * (vmax - vNext) / vmax;
4313 }
4314 }
4315}
4316
4317
4318double
4319MSVehicle::checkReversal(bool& canReverse, double speedThreshold, double seen) const {
4320 const bool stopOk = (myStops.empty() || myStops.front().edge != myCurrEdge
4321 || (myStops.front().getSpeed() > 0 && myState.myPos > myStops.front().pars.endPos - 2 * POSITION_EPS));
4322#ifdef DEBUG_REVERSE_BIDI
4323 if (DEBUG_COND) std::cout << SIMTIME << " checkReversal lane=" << myLane->getID()
4324 << " pos=" << myState.myPos
4325 << " speed=" << std::setprecision(6) << getPreviousSpeed() << std::setprecision(gPrecision)
4326 << " speedThreshold=" << speedThreshold
4327 << " seen=" << seen
4328 << " isRail=" << isRail()
4329 << " speedOk=" << (getPreviousSpeed() <= speedThreshold)
4330 << " posOK=" << (myState.myPos <= myLane->getLength())
4331 << " normal=" << !myLane->isInternal()
4332 << " routeOK=" << ((myCurrEdge + 1) != myRoute->end())
4333 << " bidi=" << (myLane->getEdge().getBidiEdge() == *(myCurrEdge + 1))
4334 << " stopOk=" << stopOk
4335 << "\n";
4336#endif
4337 if ((getVClass() & SVC_RAIL_CLASSES) != 0
4338 && getPreviousSpeed() <= speedThreshold
4339 && myState.myPos <= myLane->getLength()
4340 && !myLane->isInternal()
4341 && (myCurrEdge + 1) != myRoute->end()
4342 && myLane->getEdge().getBidiEdge() == *(myCurrEdge + 1)
4343 // ensure there are no further stops on this edge
4344 && stopOk
4345 ) {
4346 //if (isSelected()) std::cout << " check1 passed\n";
4347
4348 // ensure that the vehicle is fully on bidi edges that allow reversal
4349 const int neededFutureRoute = 1 + (int)(MSGlobals::gUsingInternalLanes
4350 ? myFurtherLanes.size()
4351 : ceil((double)myFurtherLanes.size() / 2.0));
4352 const int remainingRoute = int(myRoute->end() - myCurrEdge) - 1;
4353 if (remainingRoute < neededFutureRoute) {
4354#ifdef DEBUG_REVERSE_BIDI
4355 if (DEBUG_COND) {
4356 std::cout << " fail: remainingEdges=" << ((int)(myRoute->end() - myCurrEdge)) << " further=" << myFurtherLanes.size() << "\n";
4357 }
4358#endif
4359 return getMaxSpeed();
4360 }
4361 //if (isSelected()) std::cout << " check2 passed\n";
4362
4363 // ensure that the turn-around connection exists from the current edge to its bidi-edge
4364 const MSEdgeVector& succ = myLane->getEdge().getSuccessors();
4365 if (std::find(succ.begin(), succ.end(), myLane->getEdge().getBidiEdge()) == succ.end()) {
4366#ifdef DEBUG_REVERSE_BIDI
4367 if (DEBUG_COND) {
4368 std::cout << " noTurn (bidi=" << myLane->getEdge().getBidiEdge()->getID() << " succ=" << toString(succ) << "\n";
4369 }
4370#endif
4371 return getMaxSpeed();
4372 }
4373 //if (isSelected()) std::cout << " check3 passed\n";
4374
4375 // ensure that the vehicle front will not move past a stop on the bidi edge of the current edge
4376 if (!myStops.empty() && myStops.front().edge == (myCurrEdge + 1)) {
4377 const double stopPos = myStops.front().getEndPos(*this);
4378 const double brakeDist = getCarFollowModel().brakeGap(getSpeed(), getCarFollowModel().getMaxDecel(), 0);
4379 const double newPos = myLane->getLength() - (getBackPositionOnLane() + brakeDist);
4380 if (newPos > stopPos) {
4381#ifdef DEBUG_REVERSE_BIDI
4382 if (DEBUG_COND) {
4383 std::cout << " reversal would go past stop on " << myLane->getBidiLane()->getID() << "\n";
4384 }
4385#endif
4386 if (seen > MAX2(brakeDist, 1.0)) {
4387 return getMaxSpeed();
4388 } else {
4389#ifdef DEBUG_REVERSE_BIDI
4390 if (DEBUG_COND) {
4391 std::cout << " train is too long, skipping stop at " << stopPos << " cannot be avoided\n";
4392 }
4393#endif
4394 }
4395 }
4396 }
4397 //if (isSelected()) std::cout << " check4 passed\n";
4398
4399 // ensure that bidi-edges exist for all further edges
4400 // and that no stops will be skipped when reversing
4401 // and that the train will not be on top of a red rail signal after reversal
4402 const MSLane* bidi = myLane->getBidiLane();
4403 int view = 2;
4404 for (MSLane* further : myFurtherLanes) {
4405 if (!further->getEdge().isInternal()) {
4406 if (further->getEdge().getBidiEdge() != *(myCurrEdge + view)) {
4407#ifdef DEBUG_REVERSE_BIDI
4408 if (DEBUG_COND) {
4409 std::cout << " noBidi view=" << view << " further=" << further->getID() << " furtherBidi=" << Named::getIDSecure(further->getEdge().getBidiEdge()) << " future=" << (*(myCurrEdge + view))->getID() << "\n";
4410 }
4411#endif
4412 return getMaxSpeed();
4413 }
4414 const MSLane* nextBidi = further->getBidiLane();
4415 const MSLink* toNext = bidi->getLinkTo(nextBidi);
4416 if (toNext == nullptr) {
4417 // can only happen if the route is invalid
4418 return getMaxSpeed();
4419 }
4420 if (toNext->haveRed()) {
4421#ifdef DEBUG_REVERSE_BIDI
4422 if (DEBUG_COND) {
4423 std::cout << " do not reverse on a red signal\n";
4424 }
4425#endif
4426 return getMaxSpeed();
4427 }
4428 bidi = nextBidi;
4429 if (!myStops.empty() && myStops.front().edge == (myCurrEdge + view)) {
4430 const double brakeDist = getCarFollowModel().brakeGap(getSpeed(), getCarFollowModel().getMaxDecel(), 0);
4431 const double stopPos = myStops.front().getEndPos(*this);
4432 const double newPos = further->getLength() - (getBackPositionOnLane(further) + brakeDist);
4433 if (newPos > stopPos) {
4434#ifdef DEBUG_REVERSE_BIDI
4435 if (DEBUG_COND) {
4436 std::cout << " reversal would go past stop on further-opposite lane " << further->getBidiLane()->getID() << "\n";
4437 }
4438#endif
4439 if (seen > MAX2(brakeDist, 1.0)) {
4440 canReverse = false;
4441 return getMaxSpeed();
4442 } else {
4443#ifdef DEBUG_REVERSE_BIDI
4444 if (DEBUG_COND) {
4445 std::cout << " train is too long, skipping stop at " << stopPos << " cannot be avoided\n";
4446 }
4447#endif
4448 }
4449 }
4450 }
4451 view++;
4452 }
4453 }
4454 // reverse as soon as comfortably possible
4455 const double vMinComfortable = getCarFollowModel().minNextSpeed(getSpeed(), this);
4456#ifdef DEBUG_REVERSE_BIDI
4457 if (DEBUG_COND) {
4458 std::cout << SIMTIME << " seen=" << seen << " vReverseOK=" << vMinComfortable << "\n";
4459 }
4460#endif
4461 canReverse = true;
4462 return vMinComfortable;
4463 }
4464 return getMaxSpeed();
4465}
4466
4467
4468void
4469MSVehicle::processLaneAdvances(std::vector<MSLane*>& passedLanes, std::string& emergencyReason) {
4470 for (std::vector<MSLane*>::reverse_iterator i = myFurtherLanes.rbegin(); i != myFurtherLanes.rend(); ++i) {
4471 passedLanes.push_back(*i);
4472 }
4473 if (passedLanes.size() == 0 || passedLanes.back() != myLane) {
4474 passedLanes.push_back(myLane);
4475 }
4476 // let trains reverse direction
4477 bool reverseTrain = false;
4478 checkReversal(reverseTrain);
4479 if (reverseTrain) {
4480 // Train is 'reversing' so toggle the logical state
4482 // add some slack to ensure that the back of train does appear looped
4483 myState.myPos += 2 * (myLane->getLength() - myState.myPos) + myType->getLength() + NUMERICAL_EPS;
4484 myState.mySpeed = 0;
4485#ifdef DEBUG_REVERSE_BIDI
4486 if (DEBUG_COND) {
4487 std::cout << SIMTIME << " reversing train=" << getID() << " newPos=" << myState.myPos << "\n";
4488 }
4489#endif
4490 }
4491 // move on lane(s)
4492 if (myState.myPos > myLane->getLength()) {
4493 // The vehicle has moved at least to the next lane (maybe it passed even more than one)
4494 if (myCurrEdge != myRoute->end() - 1) {
4495 MSLane* approachedLane = myLane;
4496 // move the vehicle forward
4498 while (myNextDriveItem != myLFLinkLanes.end() && approachedLane != nullptr && myState.myPos > approachedLane->getLength()) {
4499 const MSLink* link = myNextDriveItem->myLink;
4500 const double linkDist = myNextDriveItem->myDistance;
4502 // check whether the vehicle was allowed to enter lane
4503 // otherwise it is decelerated and we do not need to test for it's
4504 // approach on the following lanes when a lane changing is performed
4505 // proceed to the next lane
4506 if (approachedLane->mustCheckJunctionCollisions()) {
4507 // vehicle moves past approachedLane within a single step, collision checking must still be done
4509 }
4510 if (link != nullptr) {
4511 if ((getVClass() & SVC_RAIL_CLASSES) != 0
4512 && !myLane->isInternal()
4513 && myLane->getBidiLane() != nullptr
4514 && link->getLane()->getBidiLane() == myLane
4515 && !reverseTrain) {
4516 emergencyReason = " because it must reverse direction";
4517 approachedLane = nullptr;
4518 break;
4519 }
4520 if ((getVClass() & SVC_RAIL_CLASSES) != 0
4521 && myState.myPos < myLane->getLength() + NUMERICAL_EPS
4522 && hasStops() && getNextStop().edge == myCurrEdge) {
4523 // avoid skipping stop due to numerical instability
4524 // this is a special case for rail vehicles because they
4525 // continue myLFLinkLanes past stops
4526 approachedLane = myLane;
4528 break;
4529 }
4530 approachedLane = link->getViaLaneOrLane();
4532 bool beyondStopLine = linkDist < link->getLaneBefore()->getVehicleStopOffset(this);
4533 if (link->haveRed() && !ignoreRed(link, false) && !beyondStopLine && !reverseTrain) {
4534 emergencyReason = " because of a red traffic light";
4535 break;
4536 }
4537 }
4538 if (reverseTrain && approachedLane->isInternal()) {
4539 // avoid getting stuck on a slow turn-around internal lane
4540 myState.myPos += approachedLane->getLength();
4541 }
4542 } else if (myState.myPos < myLane->getLength() + NUMERICAL_EPS) {
4543 // avoid warning due to numerical instability
4544 approachedLane = myLane;
4546 } else if (reverseTrain) {
4547 approachedLane = (*(myCurrEdge + 1))->getLanes()[0];
4548 link = myLane->getLinkTo(approachedLane);
4549 assert(link != 0);
4550 while (link->getViaLane() != nullptr) {
4551 link = link->getViaLane()->getLinkCont()[0];
4552 }
4554 } else {
4555 emergencyReason = " because there is no connection to the next edge";
4556 approachedLane = nullptr;
4557 break;
4558 }
4559 if (approachedLane != myLane && approachedLane != nullptr) {
4562 assert(myState.myPos > 0);
4563 enterLaneAtMove(approachedLane);
4564 if (link->isEntryLink()) {
4567 myHaveStoppedFor = nullptr;
4568 }
4569 if (link->isConflictEntryLink()) {
4571 // renew yielded request
4573 }
4574 if (link->isExitLink()) {
4575 // passed junction, reset for approaching the next one
4579 }
4580#ifdef DEBUG_PLAN_MOVE_LEADERINFO
4581 if (DEBUG_COND) {
4582 std::cout << "Update junctionTimes link=" << link->getViaLaneOrLane()->getID()
4583 << " entry=" << link->isEntryLink() << " conflict=" << link->isConflictEntryLink() << " exit=" << link->isExitLink()
4584 << " ET=" << myJunctionEntryTime
4585 << " ETN=" << myJunctionEntryTimeNeverYield
4586 << " CET=" << myJunctionConflictEntryTime
4587 << "\n";
4588 }
4589#endif
4590 if (hasArrivedInternal()) {
4591 break;
4592 }
4595 // abort lane change
4596 WRITE_WARNINGF("Vehicle '%' could not finish continuous lane change (turn lane) time=%.", getID(), time2string(SIMSTEP));
4598 }
4599 }
4600 if (approachedLane->getEdge().isVaporizing()) {
4602 break;
4603 }
4604 passedLanes.push_back(approachedLane);
4605 }
4606 }
4607 // NOTE: Passed drive items will be erased in the next simstep's planMove()
4608
4609#ifdef DEBUG_ACTIONSTEPS
4610 if (DEBUG_COND && myNextDriveItem != myLFLinkLanes.begin()) {
4611 std::cout << "Updated drive items:" << std::endl;
4612 for (DriveItemVector::iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
4613 std::cout
4614 << " vPass=" << (*i).myVLinkPass
4615 << " vWait=" << (*i).myVLinkWait
4616 << " linkLane=" << ((*i).myLink == 0 ? "NULL" : (*i).myLink->getViaLaneOrLane()->getID())
4617 << " request=" << (*i).mySetRequest
4618 << "\n";
4619 }
4620 }
4621#endif
4622 } else if (!hasArrivedInternal() && myState.myPos < myLane->getLength() + NUMERICAL_EPS) {
4623 // avoid warning due to numerical instability when stopping at the end of the route
4625 }
4626
4627 }
4628}
4629
4630
4631
4632bool
4634#ifdef DEBUG_EXEC_MOVE
4635 if (DEBUG_COND) {
4636 std::cout << "\nEXECUTE_MOVE\n"
4637 << SIMTIME
4638 << " veh=" << getID()
4639 << " speed=" << getSpeed() // toString(getSpeed(), 24)
4640 << std::endl;
4641 }
4642#endif
4643
4644
4645 // Maximum safe velocity
4646 double vSafe = std::numeric_limits<double>::max();
4647 // Minimum safe velocity (lower bound).
4648 double vSafeMin = -std::numeric_limits<double>::max();
4649 // The distance to a link, which should either be crossed this step
4650 // or in front of which we need to stop.
4651 double vSafeMinDist = 0;
4652
4653 if (myActionStep) {
4654 // Actuate control (i.e. choose bounds for safe speed in current simstep (euler), resp. after current sim step (ballistic))
4655 processLinkApproaches(vSafe, vSafeMin, vSafeMinDist);
4656#ifdef DEBUG_ACTIONSTEPS
4657 if (DEBUG_COND) {
4658 std::cout << SIMTIME << " vehicle '" << getID() << "'\n"
4659 " vsafe from processLinkApproaches(): vsafe " << vSafe << std::endl;
4660 }
4661#endif
4662 } else {
4663 // Continue with current acceleration
4664 vSafe = getSpeed() + ACCEL2SPEED(myAcceleration);
4665#ifdef DEBUG_ACTIONSTEPS
4666 if (DEBUG_COND) {
4667 std::cout << SIMTIME << " vehicle '" << getID() << "' skips processLinkApproaches()\n"
4668 " continues with constant accel " << myAcceleration << "...\n"
4669 << "speed: " << getSpeed() << " -> " << vSafe << std::endl;
4670 }
4671#endif
4672 }
4673
4674
4675//#ifdef DEBUG_EXEC_MOVE
4676// if (DEBUG_COND) {
4677// std::cout << "vSafe = " << toString(vSafe,12) << "\n" << std::endl;
4678// }
4679//#endif
4680
4681 // Determine vNext = speed after current sim step (ballistic), resp. in current simstep (euler)
4682 // Call to finalizeSpeed applies speed reduction due to dawdling / lane changing but ensures minimum safe speed
4683 double vNext = vSafe;
4684 const MSCFModel& cfModel = getCarFollowModel();
4685 const double rawAccel = SPEED2ACCEL(MAX2(vNext, 0.) - myState.mySpeed);
4686 if (vNext <= SUMO_const_haltingSpeed * TS && myWaitingTime > MSGlobals::gStartupWaitThreshold && rawAccel <= accelThresholdForWaiting() && myActionStep) {
4688 } else if (isStopped()) {
4689 // do not apply startupDelay for waypoints
4690 if (cfModel.startupDelayStopped() && getNextStop().pars.speed <= 0) {
4692 } else {
4693 // do not apply startupDelay but signal that a stop has taken place
4695 }
4696 } else {
4697 // identify potential startup (before other effects reduce the speed again)
4699 }
4700 if (myActionStep) {
4701 vNext = cfModel.finalizeSpeed(this, vSafe);
4702 if (vNext > 0) {
4703 vNext = MAX2(vNext, vSafeMin);
4704 }
4705 }
4706 // (Leo) to avoid tiny oscillations (< 1e-10) of vNext in a standing vehicle column (observed for ballistic update), we cap off vNext
4707 // (We assure to do this only for vNext<<NUMERICAL_EPS since otherwise this would nullify the workaround for #2995
4708 // (Jakob) We also need to make sure to reach a stop at the start of the next edge
4709 if (fabs(vNext) < NUMERICAL_EPS_SPEED && (myStopDist > POSITION_EPS || (hasStops() && myCurrEdge == getNextStop().edge))) {
4710 vNext = 0.;
4711 }
4712#ifdef DEBUG_EXEC_MOVE
4713 if (DEBUG_COND) {
4714 std::cout << SIMTIME << " finalizeSpeed vSafe=" << vSafe << " vSafeMin=" << (vSafeMin == -std::numeric_limits<double>::max() ? "-Inf" : toString(vSafeMin))
4715 << " vNext=" << vNext << " (i.e. accel=" << SPEED2ACCEL(vNext - getSpeed()) << ")" << std::endl;
4716 }
4717#endif
4718
4719 // vNext may be higher than vSafe without implying a bug:
4720 // - when approaching a green light that suddenly switches to yellow
4721 // - when using unregulated junctions
4722 // - when using tau < step-size
4723 // - when using unsafe car following models
4724 // - when using TraCI and some speedMode / laneChangeMode settings
4725 //if (vNext > vSafe + NUMERICAL_EPS) {
4726 // WRITE_WARNING("vehicle '" + getID() + "' cannot brake hard enough to reach safe speed "
4727 // + toString(vSafe, 4) + ", moving at " + toString(vNext, 4) + " instead. time="
4728 // + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
4729 //}
4730
4732 vNext = MAX2(vNext, 0.);
4733 } else {
4734 // (Leo) Ballistic: negative vNext can be used to indicate a stop within next step.
4735 }
4736
4737 // Check for speed advices from the traci client
4738 vNext = processTraCISpeedControl(vSafe, vNext);
4739
4740 // the acceleration of a vehicle equipped with the elecHybrid device is restricted by the maximal power of the electric drive as well
4741 MSDevice_ElecHybrid* elecHybridOfVehicle = dynamic_cast<MSDevice_ElecHybrid*>(getDevice(typeid(MSDevice_ElecHybrid)));
4742 if (elecHybridOfVehicle != nullptr) {
4743 // this is the consumption given by the car following model-computed acceleration
4744 elecHybridOfVehicle->setConsum(elecHybridOfVehicle->consumption(*this, (vNext - this->getSpeed()) / TS, vNext));
4745 // but the maximum power of the electric motor may be lower
4746 // it needs to be converted from [W] to [Wh/s] (3600s / 1h) so that TS can be taken into account
4747 double maxPower = getEmissionParameters()->getDoubleOptional(SUMO_ATTR_MAXIMUMPOWER, 100000.) / 3600;
4748 if (elecHybridOfVehicle->getConsum() / TS > maxPower) {
4749 // no, we cannot accelerate that fast, recompute the maximum possible acceleration
4750 double accel = elecHybridOfVehicle->acceleration(*this, maxPower, this->getSpeed());
4751 // and update the speed of the vehicle
4752 vNext = MIN2(vNext, this->getSpeed() + accel * TS);
4753 vNext = MAX2(vNext, 0.);
4754 // and set the vehicle consumption to reflect this
4755 elecHybridOfVehicle->setConsum(elecHybridOfVehicle->consumption(*this, (vNext - this->getSpeed()) / TS, vNext));
4756 }
4757 }
4758
4759 setBrakingSignals(vNext);
4760
4761 // update position and speed
4762 int oldLaneOffset = myLane->getEdge().getNumLanes() - myLane->getIndex();
4763 const MSLane* oldLaneMaybeOpposite = myLane;
4765 // transform to the forward-direction lane, move and then transform back
4768 }
4769 updateState(vNext);
4770 updateWaitingTime(vNext);
4771
4772 // Lanes, which the vehicle touched at some moment of the executed simstep
4773 std::vector<MSLane*> passedLanes;
4774 // remember previous lane (myLane is updated in processLaneAdvances)
4775 const MSLane* oldLane = myLane;
4776 // Reason for a possible emergency stop
4777 std::string emergencyReason;
4778 processLaneAdvances(passedLanes, emergencyReason);
4779
4780 updateTimeLoss(vNext);
4782
4784 if (myState.myPos > myLane->getLength()) {
4785 if (emergencyReason == "") {
4786 emergencyReason = TL(" for unknown reasons");
4787 }
4788 WRITE_WARNINGF(TL("Vehicle '%' performs emergency stop at the end of lane '%'% (decel=%, offset=%), time=%."),
4789 getID(), myLane->getID(), emergencyReason, myAcceleration - myState.mySpeed,
4794 myState.mySpeed = 0;
4795 myAcceleration = 0;
4796 }
4797 const MSLane* oldBackLane = getBackLane();
4799 passedLanes.clear(); // ignore back occupation
4800 }
4801#ifdef DEBUG_ACTIONSTEPS
4802 if (DEBUG_COND) {
4803 std::cout << SIMTIME << " veh '" << getID() << "' updates further lanes." << std::endl;
4804 }
4805#endif
4807 if (passedLanes.size() > 1 && isRail()) {
4808 for (auto pi = passedLanes.rbegin(); pi != passedLanes.rend(); ++pi) {
4809 MSLane* pLane = *pi;
4810 if (pLane != myLane && std::find(myFurtherLanes.begin(), myFurtherLanes.end(), pLane) == myFurtherLanes.end()) {
4812 }
4813 }
4814 }
4815 // bestLanes need to be updated before lane changing starts. NOTE: This call is also a presumption for updateDriveItems()
4817 if (myLane != oldLane || oldBackLane != getBackLane()) {
4818 if (myLaneChangeModel->getShadowLane() != nullptr || getLateralOverlap() > POSITION_EPS) {
4819 // shadow lane must be updated if the front or back lane changed
4820 // either if we already have a shadowLane or if there is lateral overlap
4822 }
4824 // The vehicles target lane must be also be updated if the front or back lane changed
4826 }
4827 }
4828 setBlinkerInformation(); // needs updated bestLanes
4829 //change the blue light only for emergency vehicles SUMOVehicleClass
4831 setEmergencyBlueLight(MSNet::getInstance()->getCurrentTimeStep());
4832 }
4833 // must be done before angle computation
4834 // State needs to be reset for all vehicles before the next call to MSEdgeControl::changeLanes
4835 if (myActionStep) {
4836 // check (#2681): Can this be skipped?
4838 } else {
4840#ifdef DEBUG_ACTIONSTEPS
4841 if (DEBUG_COND) {
4842 std::cout << SIMTIME << " veh '" << getID() << "' skips LCM->prepareStep()." << std::endl;
4843 }
4844#endif
4845 }
4848 }
4849
4850#ifdef DEBUG_EXEC_MOVE
4851 if (DEBUG_COND) {
4852 std::cout << SIMTIME << " executeMove finished veh=" << getID() << " lane=" << myLane->getID() << " myPos=" << getPositionOnLane() << " myPosLat=" << getLateralPositionOnLane() << "\n";
4853 gDebugFlag1 = false; // See MSLink_DEBUG_OPENED
4854 }
4855#endif
4857 // transform back to the opposite-direction lane
4858 MSLane* newOpposite = nullptr;
4859 const MSEdge* newOppositeEdge = myLane->getEdge().getOppositeEdge();
4860 if (newOppositeEdge != nullptr) {
4861 newOpposite = newOppositeEdge->getLanes()[newOppositeEdge->getNumLanes() - MAX2(1, oldLaneOffset)];
4862#ifdef DEBUG_EXEC_MOVE
4863 if (DEBUG_COND) {
4864 std::cout << SIMTIME << " newOppositeEdge=" << newOppositeEdge->getID() << " oldLaneOffset=" << oldLaneOffset << " leftMost=" << newOppositeEdge->getNumLanes() - 1 << " newOpposite=" << Named::getIDSecure(newOpposite) << "\n";
4865 }
4866#endif
4867 }
4868 if (newOpposite == nullptr) {
4870 // unusual overtaking at junctions is ok for emergency vehicles
4871 WRITE_WARNINGF(TL("Unexpected end of opposite lane for vehicle '%' at lane '%', time=%."),
4873 }
4875 if (myState.myPos < getLength()) {
4876 // further lanes is always cleared during opposite driving
4877 MSLane* oldOpposite = oldLane->getOpposite();
4878 if (oldOpposite != nullptr) {
4879 myFurtherLanes.push_back(oldOpposite);
4880 myFurtherLanesPosLat.push_back(0);
4881 // small value since the lane is going in the other direction
4884 } else {
4885 SOFT_ASSERT(false);
4886 }
4887 }
4888 } else {
4890 myLane = newOpposite;
4891 oldLane = oldLaneMaybeOpposite;
4892 //std::cout << SIMTIME << " updated myLane=" << Named::getIDSecure(myLane) << " oldLane=" << oldLane->getID() << "\n";
4895 }
4896 }
4897 // myAngle was already updated. Update lastAngle so moveRemindes have consisent angleDiff (after finalizeSpeed because it uses the old angles)
4899 // store angle before lane changing
4901
4903 // Return whether the vehicle did move to another lane
4904 return myLane != oldLane;
4905}
4906
4907void
4909 myState.myPos += dist;
4912
4913 const std::vector<const MSLane*> lanes = getUpcomingLanesUntil(dist);
4915 for (int i = 0; i < (int)lanes.size(); i++) {
4916 MSLink* link = nullptr;
4917 if (i + 1 < (int)lanes.size()) {
4918 const MSLane* const to = lanes[i + 1];
4919 const bool internal = to->isInternal();
4920 for (MSLink* const l : lanes[i]->getLinkCont()) {
4921 if ((internal && l->getViaLane() == to) || (!internal && l->getLane() == to)) {
4922 link = l;
4923 break;
4924 }
4925 }
4926 }
4927 myLFLinkLanes.emplace_back(link, getSpeed(), getSpeed(), true, t, getSpeed(), 0, 0, dist);
4928 }
4929 // minimum execute move:
4930 std::vector<MSLane*> passedLanes;
4931 // Reason for a possible emergency stop
4932 if (lanes.size() > 1) {
4934 }
4935 std::string emergencyReason;
4936 processLaneAdvances(passedLanes, emergencyReason);
4937#ifdef DEBUG_EXTRAPOLATE_DEPARTPOS
4938 if (DEBUG_COND) {
4939 std::cout << SIMTIME << " veh=" << getID() << " executeFractionalMove dist=" << dist
4940 << " passedLanes=" << toString(passedLanes) << " lanes=" << toString(lanes)
4941 << " finalPos=" << myState.myPos
4942 << " speed=" << getSpeed()
4943 << " myFurtherLanes=" << toString(myFurtherLanes)
4944 << "\n";
4945 }
4946#endif
4948 if (lanes.size() > 1) {
4949 for (std::vector<MSLane*>::iterator i = myFurtherLanes.begin(); i != myFurtherLanes.end(); ++i) {
4950#ifdef DEBUG_FURTHER
4951 if (DEBUG_COND) {
4952 std::cout << SIMTIME << " leaveLane \n";
4953 }
4954#endif
4955 (*i)->resetPartialOccupation(this);
4956 }
4957 myFurtherLanes.clear();
4958 myFurtherLanesPosLat.clear();
4960 }
4961}
4962
4963
4964void
4965MSVehicle::updateState(double vNext, bool parking) {
4966 // update position and speed
4967 double deltaPos; // positional change
4969 // euler
4970 deltaPos = SPEED2DIST(vNext);
4971 } else {
4972 // ballistic
4973 deltaPos = getDeltaPos(SPEED2ACCEL(vNext - myState.mySpeed));
4974 }
4975
4976 // the *mean* acceleration during the next step (probably most appropriate for emission calculation)
4977 // NOTE: for the ballistic update vNext may be negative, indicating a stop.
4979
4980#ifdef DEBUG_EXEC_MOVE
4981 if (DEBUG_COND) {
4982 std::cout << SIMTIME << " updateState() for veh '" << getID() << "': deltaPos=" << deltaPos
4983 << " pos=" << myState.myPos << " newPos=" << myState.myPos + deltaPos << std::endl;
4984 }
4985#endif
4986 double decelPlus = -myAcceleration - getCarFollowModel().getMaxDecel() - NUMERICAL_EPS;
4987 if (decelPlus > 0) {
4988 const double previousAcceleration = SPEED2ACCEL(myState.mySpeed - myState.myPreviousSpeed);
4989 if (myAcceleration + NUMERICAL_EPS < previousAcceleration) {
4990 // vehicle brakes beyond wished maximum deceleration (only warn at the start of the braking manoeuvre)
4991 decelPlus += 2 * NUMERICAL_EPS;
4992 const double emergencyFraction = decelPlus / MAX2(NUMERICAL_EPS, getCarFollowModel().getEmergencyDecel() - getCarFollowModel().getMaxDecel());
4993 if (emergencyFraction >= MSGlobals::gEmergencyDecelWarningThreshold) {
4994 WRITE_WARNINGF(TL("Vehicle '%' performs emergency braking on lane '%' with decel=%, wished=%, severity=%, time=%."),
4995 //+ " decelPlus=" + toString(decelPlus)
4996 //+ " prevAccel=" + toString(previousAcceleration)
4997 //+ " reserve=" + toString(MAX2(NUMERICAL_EPS, getCarFollowModel().getEmergencyDecel() - getCarFollowModel().getMaxDecel()))
4998 getID(), myLane->getID(), -myAcceleration, getCarFollowModel().getMaxDecel(), emergencyFraction, time2string(SIMSTEP));
5000 }
5001 }
5002 }
5003
5005 myState.mySpeed = MAX2(vNext, 0.);
5006
5007 if (isRemoteControlled()) {
5008 deltaPos = myInfluencer->implicitDeltaPosRemote(this);
5009 }
5010
5011 myState.myPos += deltaPos;
5012 myState.myLastCoveredDist = deltaPos;
5013 myNextTurn.first -= deltaPos;
5014
5015 if (!parking) {
5017 }
5018}
5019
5020void
5022 updateState(0, true);
5023 // deboard while parked
5024 if (myPersonDevice != nullptr) {
5026 }
5027 if (myContainerDevice != nullptr) {
5029 }
5030 for (MSVehicleDevice* const dev : myDevices) {
5031 dev->notifyParking();
5032 }
5033}
5034
5035
5036void
5042
5043
5044const MSLane*
5046 if (myFurtherLanes.size() > 0) {
5047 return myFurtherLanes.back();
5048 } else {
5049 return myLane;
5050 }
5051}
5052
5053
5054double
5055MSVehicle::updateFurtherLanes(std::vector<MSLane*>& furtherLanes, std::vector<double>& furtherLanesPosLat,
5056 const std::vector<MSLane*>& passedLanes) {
5057#ifdef DEBUG_SETFURTHER
5058 if (DEBUG_COND) std::cout << SIMTIME << " veh=" << getID()
5059 << " updateFurtherLanes oldFurther=" << toString(furtherLanes)
5060 << " oldFurtherPosLat=" << toString(furtherLanesPosLat)
5061 << " passed=" << toString(passedLanes)
5062 << "\n";
5063#endif
5064 for (MSLane* further : furtherLanes) {
5065 further->resetPartialOccupation(this);
5066 if (further->getBidiLane() != nullptr
5067 && (!isRailway(getVClass()) || (further->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5068 further->getBidiLane()->resetPartialOccupation(this);
5069 }
5070 }
5071
5072 std::vector<MSLane*> newFurther;
5073 std::vector<double> newFurtherPosLat;
5074 double backPosOnPreviousLane = myState.myPos - getLength();
5075 bool widthShift = myFurtherLanesPosLat.size() > myFurtherLanes.size();
5076 if (passedLanes.size() > 1) {
5077 // There are candidates for further lanes. (passedLanes[-1] is the current lane, or current shadow lane in context of updateShadowLanes())
5078 std::vector<MSLane*>::const_iterator fi = furtherLanes.begin();
5079 std::vector<double>::const_iterator fpi = furtherLanesPosLat.begin();
5080 for (auto pi = passedLanes.rbegin() + 1; pi != passedLanes.rend() && backPosOnPreviousLane < 0; ++pi) {
5081 // As long as vehicle back reaches into passed lane, add it to the further lanes
5082 MSLane* further = *pi;
5083 newFurther.push_back(further);
5084 backPosOnPreviousLane += further->setPartialOccupation(this);
5085 if (further->getBidiLane() != nullptr
5086 && (!isRailway(getVClass()) || (further->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5087 further->getBidiLane()->setPartialOccupation(this);
5088 }
5089 if (fi != furtherLanes.end() && further == *fi) {
5090 // Lateral position on this lane is already known. Assume constant and use old value.
5091 newFurtherPosLat.push_back(*fpi);
5092 ++fi;
5093 ++fpi;
5094 } else {
5095 // The lane *pi was not in furtherLanes before.
5096 // If it is downstream, we assume as lateral position the current position
5097 // If it is a new lane upstream (can appear as shadow further in case of LC-maneuvering, e.g.)
5098 // we assign the last known lateral position.
5099 if (newFurtherPosLat.size() == 0) {
5100 if (widthShift) {
5101 newFurtherPosLat.push_back(myFurtherLanesPosLat.back());
5102 } else {
5103 newFurtherPosLat.push_back(myState.myPosLat);
5104 }
5105 } else {
5106 newFurtherPosLat.push_back(newFurtherPosLat.back());
5107 }
5108 }
5109#ifdef DEBUG_SETFURTHER
5110 if (DEBUG_COND) {
5111 std::cout << SIMTIME << " updateFurtherLanes \n"
5112 << " further lane '" << further->getID() << "' backPosOnPreviousLane=" << backPosOnPreviousLane
5113 << std::endl;
5114 }
5115#endif
5116 }
5117 furtherLanes = newFurther;
5118 furtherLanesPosLat = newFurtherPosLat;
5119 } else {
5120 furtherLanes.clear();
5121 furtherLanesPosLat.clear();
5122 }
5123#ifdef DEBUG_SETFURTHER
5124 if (DEBUG_COND) std::cout
5125 << " newFurther=" << toString(furtherLanes)
5126 << " newFurtherPosLat=" << toString(furtherLanesPosLat)
5127 << " newBackPos=" << backPosOnPreviousLane
5128 << "\n";
5129#endif
5130 return backPosOnPreviousLane;
5131}
5132
5133
5134double
5135MSVehicle::getBackPositionOnLane(const MSLane* lane, bool calledByGetPosition) const {
5136#ifdef DEBUG_FURTHER
5137 if (DEBUG_COND) {
5138 std::cout << SIMTIME
5139 << " getBackPositionOnLane veh=" << getID()
5140 << " lane=" << Named::getIDSecure(lane)
5141 << " cbgP=" << calledByGetPosition
5142 << " pos=" << myState.myPos
5143 << " backPos=" << myState.myBackPos
5144 << " myLane=" << myLane->getID()
5145 << " myLaneBidi=" << Named::getIDSecure(myLane->getBidiLane())
5146 << " further=" << toString(myFurtherLanes)
5147 << " furtherPosLat=" << toString(myFurtherLanesPosLat)
5148 << "\n shadowLane=" << Named::getIDSecure(myLaneChangeModel->getShadowLane())
5149 << " shadowFurther=" << toString(myLaneChangeModel->getShadowFurtherLanes())
5150 << " shadowFurtherPosLat=" << toString(myLaneChangeModel->getShadowFurtherLanesPosLat())
5151 << "\n targetLane=" << Named::getIDSecure(myLaneChangeModel->getTargetLane())
5152 << " furtherTargets=" << toString(myLaneChangeModel->getFurtherTargetLanes())
5153 << std::endl;
5154 }
5155#endif
5156 if (lane == myLane
5157 || lane == myLaneChangeModel->getShadowLane()
5158 || lane == myLaneChangeModel->getTargetLane()) {
5160 if (lane == myLaneChangeModel->getShadowLane()) {
5161 return lane->getLength() - myState.myPos - myType->getLength();
5162 } else {
5163 return myState.myPos + (calledByGetPosition ? -1 : 1) * myType->getLength();
5164 }
5165 } else if (&lane->getEdge() != &myLane->getEdge()) {
5166 return lane->getLength() - myState.myPos + (calledByGetPosition ? -1 : 1) * myType->getLength();
5167 } else {
5168 // account for parallel lanes of different lengths in the most conservative manner (i.e. while turning)
5169 return myState.myPos - myType->getLength() + MIN2(0.0, lane->getLength() - myLane->getLength());
5170 }
5171 } else if (lane == myLane->getBidiLane()) {
5172 return lane->getLength() - myState.myPos + myType->getLength() * (calledByGetPosition ? -1 : 1);
5173 } else if (myFurtherLanes.size() > 0 && lane == myFurtherLanes.back()) {
5174 return myState.myBackPos;
5175 } else if ((myLaneChangeModel->getShadowFurtherLanes().size() > 0 && lane == myLaneChangeModel->getShadowFurtherLanes().back())
5176 || (myLaneChangeModel->getFurtherTargetLanes().size() > 0 && lane == myLaneChangeModel->getFurtherTargetLanes().back())) {
5177 assert(myFurtherLanes.size() > 0);
5178 if (lane->getLength() == myFurtherLanes.back()->getLength()) {
5179 return myState.myBackPos;
5180 } else {
5181 // interpolate
5182 //if (DEBUG_COND) {
5183 //if (myFurtherLanes.back()->getLength() != lane->getLength()) {
5184 // std::cout << SIMTIME << " veh=" << getID() << " lane=" << lane->getID() << " further=" << myFurtherLanes.back()->getID()
5185 // << " len=" << lane->getLength() << " fLen=" << myFurtherLanes.back()->getLength()
5186 // << " backPos=" << myState.myBackPos << " result=" << myState.myBackPos / myFurtherLanes.back()->getLength() * lane->getLength() << "\n";
5187 //}
5188 return myState.myBackPos / myFurtherLanes.back()->getLength() * lane->getLength();
5189 }
5190 } else {
5191 //if (DEBUG_COND) std::cout << SIMTIME << " veh=" << getID() << " myFurtherLanes=" << toString(myFurtherLanes) << "\n";
5192 double leftLength = myType->getLength() - myState.myPos;
5193
5194 std::vector<MSLane*>::const_iterator i = myFurtherLanes.begin();
5195 while (leftLength > 0 && i != myFurtherLanes.end()) {
5196 leftLength -= (*i)->getLength();
5197 //if (DEBUG_COND) std::cout << " comparing i=" << (*i)->getID() << " lane=" << lane->getID() << "\n";
5198 if (*i == lane) {
5199 return -leftLength;
5200 } else if (*i == lane->getBidiLane()) {
5201 return lane->getLength() + leftLength - (calledByGetPosition ? 2 * myType->getLength() : 0);
5202 }
5203 ++i;
5204 }
5205 //if (DEBUG_COND) std::cout << SIMTIME << " veh=" << getID() << " myShadowFurtherLanes=" << toString(myLaneChangeModel->getShadowFurtherLanes()) << "\n";
5206 leftLength = myType->getLength() - myState.myPos;
5208 while (leftLength > 0 && i != myLaneChangeModel->getShadowFurtherLanes().end()) {
5209 leftLength -= (*i)->getLength();
5210 //if (DEBUG_COND) std::cout << " comparing i=" << (*i)->getID() << " lane=" << lane->getID() << "\n";
5211 if (*i == lane) {
5212 return -leftLength;
5213 } else if (*i == lane->getBidiLane()) {
5214 return lane->getLength() + leftLength - (calledByGetPosition ? 2 * myType->getLength() : 0);
5215 }
5216 ++i;
5217 }
5218 //if (DEBUG_COND) std::cout << SIMTIME << " veh=" << getID() << " myFurtherTargetLanes=" << toString(myLaneChangeModel->getFurtherTargetLanes()) << "\n";
5219 leftLength = myType->getLength() - myState.myPos;
5220 i = getFurtherLanes().begin();
5221 const std::vector<MSLane*> furtherTargetLanes = myLaneChangeModel->getFurtherTargetLanes();
5222 auto j = furtherTargetLanes.begin();
5223 while (leftLength > 0 && j != furtherTargetLanes.end()) {
5224 leftLength -= (*i)->getLength();
5225 // if (DEBUG_COND) std::cout << " comparing i=" << (*i)->getID() << " lane=" << lane->getID() << "\n";
5226 if (*j == lane) {
5227 return -leftLength;
5228 } else if (*j == lane->getBidiLane()) {
5229 return lane->getLength() + leftLength - (calledByGetPosition ? 2 * myType->getLength() : 0);
5230 }
5231 ++i;
5232 ++j;
5233 }
5234 WRITE_WARNINGF("Request backPos of vehicle '%' for invalid lane '%' time=%.",
5236 SOFT_ASSERT(false);
5237 return myState.myBackPos;
5238 }
5239}
5240
5241
5242double
5244 return getBackPositionOnLane(lane, true) + myType->getLength();
5245}
5246
5247
5248bool
5250 return lane == myLane || lane == myLaneChangeModel->getShadowLane() || lane == myLane->getBidiLane();
5251}
5252
5253
5254void
5255MSVehicle::checkRewindLinkLanes(const double lengthsInFront, DriveItemVector& lfLinks) const {
5257 double seenSpace = -lengthsInFront;
5258#ifdef DEBUG_CHECKREWINDLINKLANES
5259 if (DEBUG_COND) {
5260 std::cout << "\nCHECK_REWIND_LINKLANES\n" << " veh=" << getID() << " lengthsInFront=" << lengthsInFront << "\n";
5261 };
5262#endif
5263 bool foundStopped = false;
5264 // compute available space until a stopped vehicle is found
5265 // this is the sum of non-interal lane length minus in-between vehicle lengths
5266 for (int i = 0; i < (int)lfLinks.size(); ++i) {
5267 // skip unset links
5268 DriveProcessItem& item = lfLinks[i];
5269#ifdef DEBUG_CHECKREWINDLINKLANES
5270 if (DEBUG_COND) std::cout << SIMTIME
5271 << " link=" << (item.myLink == 0 ? "NULL" : item.myLink->getViaLaneOrLane()->getID())
5272 << " foundStopped=" << foundStopped;
5273#endif
5274 if (item.myLink == nullptr || foundStopped) {
5275 if (!foundStopped) {
5276 item.availableSpace += seenSpace;
5277 } else {
5278 item.availableSpace = seenSpace;
5279 }
5280#ifdef DEBUG_CHECKREWINDLINKLANES
5281 if (DEBUG_COND) {
5282 std::cout << " avail=" << item.availableSpace << "\n";
5283 }
5284#endif
5285 continue;
5286 }
5287 // get the next lane, determine whether it is an internal lane
5288 const MSLane* approachedLane = item.myLink->getViaLane();
5289 if (approachedLane != nullptr) {
5290 if (keepClear(item.myLink)) {
5291 seenSpace = seenSpace - approachedLane->getBruttoVehLenSum();
5292 if (approachedLane == myLane) {
5293 seenSpace += getVehicleType().getLengthWithGap();
5294 }
5295 } else {
5296 seenSpace = seenSpace + approachedLane->getSpaceTillLastStanding(this, foundStopped);// - approachedLane->getBruttoVehLenSum() + approachedLane->getLength();
5297 }
5298 item.availableSpace = seenSpace;
5299#ifdef DEBUG_CHECKREWINDLINKLANES
5300 if (DEBUG_COND) std::cout
5301 << " approached=" << approachedLane->getID()
5302 << " approachedBrutto=" << approachedLane->getBruttoVehLenSum()
5303 << " avail=" << item.availableSpace
5304 << " seenSpace=" << seenSpace
5305 << " hadStoppedVehicle=" << item.hadStoppedVehicle
5306 << " lengthsInFront=" << lengthsInFront
5307 << "\n";
5308#endif
5309 continue;
5310 }
5311 approachedLane = item.myLink->getLane();
5312 const MSVehicle* last = approachedLane->getLastAnyVehicle();
5313 if (last == nullptr || last == this) {
5314 if (approachedLane->getLength() > getVehicleType().getLength()
5315 || keepClear(item.myLink)) {
5316 seenSpace += approachedLane->getLength();
5317 }
5318 item.availableSpace = seenSpace;
5319#ifdef DEBUG_CHECKREWINDLINKLANES
5320 if (DEBUG_COND) {
5321 std::cout << " last=" << Named::getIDSecure(last) << " laneLength=" << approachedLane->getLength() << " avail=" << item.availableSpace << "\n";
5322 }
5323#endif
5324 } else {
5325 bool foundStopped2 = false;
5326 double spaceTillLastStanding = approachedLane->getSpaceTillLastStanding(this, foundStopped2);
5327 if (approachedLane->getBidiLane() != nullptr) {
5328 const MSVehicle* oncomingVeh = approachedLane->getBidiLane()->getFirstFullVehicle();
5329 if (oncomingVeh) {
5330 const double oncomingGap = approachedLane->getLength() - oncomingVeh->getPositionOnLane();
5331 const double oncomingBGap = oncomingVeh->getBrakeGap(true);
5332 // oncoming movement until ego enters the junction
5333 const double oncomingMove = STEPS2TIME(item.myArrivalTime - SIMSTEP) * oncomingVeh->getSpeed();
5334 const double spaceTillOncoming = oncomingGap - oncomingBGap - oncomingMove;
5335 spaceTillLastStanding = MIN2(spaceTillLastStanding, spaceTillOncoming);
5336 if (spaceTillOncoming <= getVehicleType().getLengthWithGap()) {
5337 foundStopped = true;
5338 }
5339#ifdef DEBUG_CHECKREWINDLINKLANES
5340 if (DEBUG_COND) {
5341 std::cout << " oVeh=" << oncomingVeh->getID()
5342 << " oGap=" << oncomingGap
5343 << " bGap=" << oncomingBGap
5344 << " mGap=" << oncomingMove
5345 << " sto=" << spaceTillOncoming;
5346 }
5347#endif
5348 }
5349 }
5350 seenSpace += spaceTillLastStanding;
5351 if (foundStopped2) {
5352 foundStopped = true;
5353 item.hadStoppedVehicle = true;
5354 }
5355 item.availableSpace = seenSpace;
5356 if (last->myHaveToWaitOnNextLink || last->isStopped()) {
5357 foundStopped = true;
5358 item.hadStoppedVehicle = true;
5359 }
5360#ifdef DEBUG_CHECKREWINDLINKLANES
5361 if (DEBUG_COND) std::cout
5362 << " approached=" << approachedLane->getID()
5363 << " last=" << last->getID()
5364 << " lastHasToWait=" << last->myHaveToWaitOnNextLink
5365 << " lastBrakeLight=" << last->signalSet(VEH_SIGNAL_BRAKELIGHT)
5366 << " lastBrakeGap=" << last->getCarFollowModel().brakeGap(last->getSpeed())
5367 << " lastGap=" << (last->getBackPositionOnLane(approachedLane) + last->getCarFollowModel().brakeGap(last->getSpeed()) - last->getSpeed() * last->getCarFollowModel().getHeadwayTime()
5368 // gap of last up to the next intersection
5369 - last->getVehicleType().getMinGap())
5370 << " stls=" << spaceTillLastStanding
5371 << " avail=" << item.availableSpace
5372 << " seenSpace=" << seenSpace
5373 << " foundStopped=" << foundStopped
5374 << " foundStopped2=" << foundStopped2
5375 << "\n";
5376#endif
5377 }
5378 }
5379
5380 // check which links allow continuation and add pass available to the previous item
5381 for (int i = ((int)lfLinks.size() - 1); i > 0; --i) {
5382 DriveProcessItem& item = lfLinks[i - 1];
5383 DriveProcessItem& nextItem = lfLinks[i];
5384 const bool canLeaveJunction = item.myLink->getViaLane() == nullptr || nextItem.myLink == nullptr || nextItem.mySetRequest;
5385 const bool opened = (item.myLink != nullptr
5386 && (canLeaveJunction || (
5387 // indirect bicycle turn
5388 nextItem.myLink != nullptr && nextItem.myLink->isInternalJunctionLink() && nextItem.myLink->haveRed()))
5389 && (
5390 item.myLink->havePriority()
5391 || i == 1 // the upcoming link (item 0) is checked in executeMove anyway. No need to use outdata approachData here
5393 || item.myLink->opened(item.myArrivalTime, item.myArrivalSpeed,
5396 bool allowsContinuation = (item.myLink == nullptr || item.myLink->isCont() || opened) && !item.hadStoppedVehicle;
5397#ifdef DEBUG_CHECKREWINDLINKLANES
5398 if (DEBUG_COND) std::cout
5399 << " link=" << (item.myLink == 0 ? "NULL" : item.myLink->getViaLaneOrLane()->getID())
5400 << " canLeave=" << canLeaveJunction
5401 << " opened=" << opened
5402 << " allowsContinuation=" << allowsContinuation
5403 << " foundStopped=" << foundStopped
5404 << "\n";
5405#endif
5406 if (!opened && item.myLink != nullptr) {
5407 foundStopped = true;
5408 if (i > 1) {
5409 DriveProcessItem& item2 = lfLinks[i - 2];
5410 if (item2.myLink != nullptr && item2.myLink->isCont()) {
5411 allowsContinuation = true;
5412 }
5413 }
5414 }
5415 if (allowsContinuation) {
5416 item.availableSpace = nextItem.availableSpace;
5417#ifdef DEBUG_CHECKREWINDLINKLANES
5418 if (DEBUG_COND) std::cout
5419 << " link=" << (item.myLink == nullptr ? "NULL" : item.myLink->getViaLaneOrLane()->getID())
5420 << " copy nextAvail=" << nextItem.availableSpace
5421 << "\n";
5422#endif
5423 }
5424 }
5425
5426 // find removalBegin
5427 int removalBegin = -1;
5428 for (int i = 0; foundStopped && i < (int)lfLinks.size() && removalBegin < 0; ++i) {
5429 // skip unset links
5430 const DriveProcessItem& item = lfLinks[i];
5431 if (item.myLink == nullptr) {
5432 continue;
5433 }
5434 /*
5435 double impatienceCorrection = MAX2(0., double(double(myWaitingTime)));
5436 if (seenSpace<getVehicleType().getLengthWithGap()-impatienceCorrection/10.&&nextSeenNonInternal!=0) {
5437 removalBegin = lastLinkToInternal;
5438 }
5439 */
5440
5441 const double leftSpace = item.availableSpace - getVehicleType().getLengthWithGap();
5442#ifdef DEBUG_CHECKREWINDLINKLANES
5443 if (DEBUG_COND) std::cout
5444 << SIMTIME
5445 << " veh=" << getID()
5446 << " link=" << (item.myLink == 0 ? "NULL" : item.myLink->getViaLaneOrLane()->getID())
5447 << " avail=" << item.availableSpace
5448 << " leftSpace=" << leftSpace
5449 << "\n";
5450#endif
5451 if (leftSpace < 0/* && item.myLink->willHaveBlockedFoe()*/) {
5452 double impatienceCorrection = 0;
5453 /*
5454 if(item.myLink->getState()==LINKSTATE_MINOR) {
5455 impatienceCorrection = MAX2(0., STEPS2TIME(myWaitingTime));
5456 }
5457 */
5458 // may ignore keepClear rules
5459 if (leftSpace < -impatienceCorrection / 10. && keepClear(item.myLink)) {
5460 removalBegin = i;
5461 }
5462 //removalBegin = i;
5463 }
5464 }
5465 // abort requests
5466 if (removalBegin != -1 && !(removalBegin == 0 && myLane->getEdge().isInternal())) {
5467 const double brakeGap = getCarFollowModel().brakeGap(myState.mySpeed, getCarFollowModel().getMaxDecel(), 0.);
5468 while (removalBegin < (int)(lfLinks.size())) {
5469 DriveProcessItem& dpi = lfLinks[removalBegin];
5470 if (dpi.myLink == nullptr) {
5471 break;
5472 }
5473 dpi.myVLinkPass = dpi.myVLinkWait;
5474#ifdef DEBUG_CHECKREWINDLINKLANES
5475 if (DEBUG_COND) {
5476 std::cout << " removalBegin=" << removalBegin << " brakeGap=" << brakeGap << " dist=" << dpi.myDistance << " speed=" << myState.mySpeed << " a2s=" << ACCEL2SPEED(getCarFollowModel().getMaxDecel()) << "\n";
5477 }
5478#endif
5479 if (dpi.myDistance >= brakeGap + POSITION_EPS) {
5480 // always leave junctions after requesting to enter
5481 if (!dpi.myLink->isExitLink() || !lfLinks[removalBegin - 1].mySetRequest) {
5482 dpi.mySetRequest = false;
5483 }
5484 }
5485 ++removalBegin;
5486 }
5487 }
5488 }
5489}
5490
5491
5492void
5494 if (!myActionStep) {
5495 return;
5496 }
5498 for (DriveProcessItem& dpi : myLFLinkLanes) {
5499 if (dpi.myLink != nullptr) {
5500 if (dpi.myLink->getState() == LINKSTATE_ALLWAY_STOP) {
5501 dpi.myArrivalTime += (SUMOTime)RandHelper::rand((int)2, getRNG()); // tie braker
5502 }
5503 dpi.myLink->setApproaching(this, dpi.myArrivalTime, dpi.myArrivalSpeed, dpi.getLeaveSpeed(),
5504 dpi.mySetRequest, dpi.myArrivalSpeedBraking, getWaitingTimeFor(dpi.myLink), dpi.myDistance, getLateralPositionOnLane());
5505 }
5506 }
5507 if (isRail()) {
5508 for (DriveProcessItem& dpi : myLFLinkLanes) {
5509 if (dpi.myLink != nullptr && dpi.myLink->getTLLogic() != nullptr && dpi.myLink->getTLLogic()->getLogicType() == TrafficLightType::RAIL_SIGNAL) {
5511 }
5512 }
5513 }
5514 if (myLaneChangeModel->getShadowLane() != nullptr) {
5515 // register on all shadow links
5516 for (const DriveProcessItem& dpi : myLFLinkLanes) {
5517 if (dpi.myLink != nullptr) {
5518 MSLink* parallelLink = dpi.myLink->getParallelLink(myLaneChangeModel->getShadowDirection());
5519 if (parallelLink == nullptr && getLaneChangeModel().isOpposite() && dpi.myLink->isEntryLink()) {
5520 // register on opposite direction entry link to warn foes at minor side road
5521 parallelLink = dpi.myLink->getOppositeDirectionLink();
5522 }
5523 if (parallelLink != nullptr) {
5524 const double latOffset = getLane()->getRightSideOnEdge() - myLaneChangeModel->getShadowLane()->getRightSideOnEdge();
5525 parallelLink->setApproaching(this, dpi.myArrivalTime, dpi.myArrivalSpeed, dpi.getLeaveSpeed(),
5526 dpi.mySetRequest, dpi.myArrivalSpeedBraking, getWaitingTimeFor(dpi.myLink), dpi.myDistance,
5527 latOffset);
5529 }
5530 }
5531 }
5532 }
5533#ifdef DEBUG_PLAN_MOVE
5534 if (DEBUG_COND) {
5535 std::cout << SIMTIME
5536 << " veh=" << getID()
5537 << " after checkRewindLinkLanes\n";
5538 for (DriveProcessItem& dpi : myLFLinkLanes) {
5539 std::cout
5540 << " vPass=" << dpi.myVLinkPass
5541 << " vWait=" << dpi.myVLinkWait
5542 << " linkLane=" << (dpi.myLink == 0 ? "NULL" : dpi.myLink->getViaLaneOrLane()->getID())
5543 << " request=" << dpi.mySetRequest
5544 << " atime=" << dpi.myArrivalTime
5545 << "\n";
5546 }
5547 }
5548#endif
5549}
5550
5551
5552void
5554 DriveProcessItem dpi(0, dist);
5555 dpi.myLink = link;
5556 const double arrivalSpeedBraking = getCarFollowModel().getMinimalArrivalSpeedEuler(dist, getSpeed());
5557 link->setApproaching(this, SUMOTime_MAX, 0, 0, false, arrivalSpeedBraking, 0, dpi.myDistance, 0);
5558 // ensure cleanup in the next step
5559 myLFLinkLanes.push_back(dpi);
5561}
5562
5563
5564void
5565MSVehicle::enterLaneAtMove(MSLane* enteredLane, bool onTeleporting) {
5566 myAmOnNet = !onTeleporting;
5567 // vaporizing edge?
5568 /*
5569 if (enteredLane->getEdge().isVaporizing()) {
5570 // yep, let's do the vaporization...
5571 myLane = enteredLane;
5572 return true;
5573 }
5574 */
5575 // Adjust MoveReminder offset to the next lane
5576 adaptLaneEntering2MoveReminder(*enteredLane);
5577 // set the entered lane as the current lane
5578 MSLane* oldLane = myLane;
5579 myLane = enteredLane;
5580 myLastBestLanesEdge = nullptr;
5581
5582 // internal edges are not a part of the route...
5583 if (!enteredLane->getEdge().isInternal()) {
5584 ++myCurrEdge;
5586 }
5587 if (myInfluencer != nullptr) {
5589 }
5590 if (!onTeleporting) {
5594 // transform lateral position when the lane width changes
5595 assert(oldLane != nullptr);
5596 const MSLink* const link = oldLane->getLinkTo(myLane);
5597 if (link != nullptr) {
5598 myState.myPosLat += link->getLateralShift();
5599 } else {
5601 }
5602 } else if (fabs(myState.myPosLat) > NUMERICAL_EPS) {
5603 const double overlap = MAX2(0.0, getLateralOverlap(myState.myPosLat, oldLane));
5604 const double range = (oldLane->getWidth() - getVehicleType().getWidth()) * 0.5 + overlap;
5605 const double range2 = (myLane->getWidth() - getVehicleType().getWidth()) * 0.5 + overlap;
5606 myState.myPosLat *= range2 / range;
5607 }
5608 if (myLane->getBidiLane() != nullptr && (!isRailway(getVClass()) || (myLane->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5609 // railways don't need to "see" each other when moving in opposite directions on the same track (efficiency)
5610 // (unless the lane is shared with cars)
5612 }
5613 } else {
5614 // normal move() isn't called so reset position here. must be done
5615 // before calling reminders
5616 myState.myPos = 0;
5619 }
5620 // update via
5621 if (myParameter->via.size() > 0 && myLane->getEdge().getID() == myParameter->via.front()) {
5622 myParameter->via.erase(myParameter->via.begin());
5623 }
5624}
5625
5626
5627void
5629 myAmOnNet = true;
5630 myLane = enteredLane;
5632 // need to update myCurrentLaneInBestLanes
5634 // switch to and activate the new lane's reminders
5635 // keep OldLaneReminders
5636 for (std::vector< MSMoveReminder* >::const_iterator rem = enteredLane->getMoveReminders().begin(); rem != enteredLane->getMoveReminders().end(); ++rem) {
5637 addReminder(*rem);
5638 }
5640 MSLane* lane = myLane;
5641 double leftLength = getVehicleType().getLength() - myState.myPos;
5642 int deleteFurther = 0;
5643#ifdef DEBUG_SETFURTHER
5644 if (DEBUG_COND) {
5645 std::cout << SIMTIME << " enterLaneAtLaneChange entered=" << Named::getIDSecure(enteredLane) << " oldFurther=" << toString(myFurtherLanes) << "\n";
5646 }
5647#endif
5648 if (myLane->getBidiLane() != nullptr && (!isRailway(getVClass()) || (myLane->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5649 // railways don't need to "see" each other when moving in opposite directions on the same track (efficiency)
5650 // (unless the lane is shared with cars)
5652 }
5653 for (int i = 0; i < (int)myFurtherLanes.size(); i++) {
5654 if (lane != nullptr) {
5656 }
5657#ifdef DEBUG_SETFURTHER
5658 if (DEBUG_COND) {
5659 std::cout << " enterLaneAtLaneChange i=" << i << " lane=" << Named::getIDSecure(lane) << " leftLength=" << leftLength << "\n";
5660 }
5661#endif
5662 if (leftLength > 0) {
5663 if (lane != nullptr) {
5665 if (myFurtherLanes[i]->getBidiLane() != nullptr
5666 && (!isRailway(getVClass()) || (myFurtherLanes[i]->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5667 myFurtherLanes[i]->getBidiLane()->resetPartialOccupation(this);
5668 }
5669 // lane changing onto longer lanes may reduce the number of
5670 // remaining further lanes
5671 myFurtherLanes[i] = lane;
5673 leftLength -= lane->setPartialOccupation(this);
5674 if (lane->getBidiLane() != nullptr
5675 && (!isRailway(getVClass()) || (lane->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5676 lane->getBidiLane()->setPartialOccupation(this);
5677 }
5678 myState.myBackPos = -leftLength;
5679#ifdef DEBUG_SETFURTHER
5680 if (DEBUG_COND) {
5681 std::cout << SIMTIME << " newBackPos=" << myState.myBackPos << "\n";
5682 }
5683#endif
5684 } else {
5685 // keep the old values, but ensure there is no shadow
5688 }
5689 if (myState.myBackPos < 0) {
5690 myState.myBackPos += myFurtherLanes[i]->getLength();
5691 }
5692#ifdef DEBUG_SETFURTHER
5693 if (DEBUG_COND) {
5694 std::cout << SIMTIME << " i=" << i << " further=" << myFurtherLanes[i]->getID() << " newBackPos=" << myState.myBackPos << "\n";
5695 }
5696#endif
5697 }
5698 } else {
5699 myFurtherLanes[i]->resetPartialOccupation(this);
5700 if (myFurtherLanes[i]->getBidiLane() != nullptr
5701 && (!isRailway(getVClass()) || (myFurtherLanes[i]->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5702 myFurtherLanes[i]->getBidiLane()->resetPartialOccupation(this);
5703 }
5704 deleteFurther++;
5705 }
5706 }
5707 if (deleteFurther > 0) {
5708#ifdef DEBUG_SETFURTHER
5709 if (DEBUG_COND) {
5710 std::cout << SIMTIME << " veh=" << getID() << " shortening myFurtherLanes by " << deleteFurther << "\n";
5711 }
5712#endif
5713 myFurtherLanes.erase(myFurtherLanes.end() - deleteFurther, myFurtherLanes.end());
5714 myFurtherLanesPosLat.erase(myFurtherLanesPosLat.end() - deleteFurther, myFurtherLanesPosLat.end());
5715 }
5716#ifdef DEBUG_SETFURTHER
5717 if (DEBUG_COND) {
5718 std::cout << SIMTIME << " enterLaneAtLaneChange new furtherLanes=" << toString(myFurtherLanes)
5719 << " furterLanesPosLat=" << toString(myFurtherLanesPosLat) << "\n";
5720 }
5721#endif
5723}
5724
5725
5726void
5727MSVehicle::computeFurtherLanes(MSLane* enteredLane, double pos, bool collision) {
5728 // build the list of lanes the vehicle is lapping into
5729 if (!myLaneChangeModel->isOpposite()) {
5730 double leftLength = myType->getLength() - pos;
5731 MSLane* clane = enteredLane;
5732 int routeIndex = getRoutePosition();
5733 while (leftLength > 0) {
5734 if (routeIndex > 0 && clane->getEdge().isNormal()) {
5735 // get predecessor lane that corresponds to prior route
5736 routeIndex--;
5737 const MSEdge* fromRouteEdge = myRoute->getEdges()[routeIndex];
5738 MSLane* target = clane;
5739 clane = nullptr;
5740 for (auto ili : target->getIncomingLanes()) {
5741 if (ili.lane->getEdge().getNormalBefore() == fromRouteEdge) {
5742 clane = ili.lane;
5743 break;
5744 }
5745 }
5746 } else {
5747 clane = clane->getLogicalPredecessorLane();
5748 }
5749 if (clane == nullptr || clane == myLane || clane == myLane->getBidiLane()
5750 || (clane->isInternal() && (
5751 clane->getLinkCont()[0]->getDirection() == LinkDirection::TURN
5752 || clane->getLinkCont()[0]->getDirection() == LinkDirection::TURN_LEFTHAND))) {
5753 break;
5754 }
5755 if (!collision || std::find(myFurtherLanes.begin(), myFurtherLanes.end(), clane) == myFurtherLanes.end()) {
5756 myFurtherLanes.push_back(clane);
5758 clane->setPartialOccupation(this);
5759 if (clane->getBidiLane() != nullptr
5760 && (!isRailway(getVClass()) || (clane->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5761 clane->getBidiLane()->setPartialOccupation(this);
5762 }
5763 }
5764 leftLength -= clane->getLength();
5765 }
5766 myState.myBackPos = -leftLength;
5767#ifdef DEBUG_SETFURTHER
5768 if (DEBUG_COND) {
5769 std::cout << SIMTIME << " computeFurtherLanes veh=" << getID() << " pos=" << pos << " myFurtherLanes=" << toString(myFurtherLanes) << " backPos=" << myState.myBackPos << "\n";
5770 }
5771#endif
5772 } else {
5773 // clear partial occupation
5774 for (MSLane* further : myFurtherLanes) {
5775#ifdef DEBUG_SETFURTHER
5776 if (DEBUG_COND) {
5777 std::cout << SIMTIME << " opposite: resetPartialOccupation " << further->getID() << " \n";
5778 }
5779#endif
5780 further->resetPartialOccupation(this);
5781 if (further->getBidiLane() != nullptr
5782 && (!isRailway(getVClass()) || (further->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5783 further->getBidiLane()->resetPartialOccupation(this);
5784 }
5785 }
5786 myFurtherLanes.clear();
5787 myFurtherLanesPosLat.clear();
5788 }
5789}
5790
5791
5792void
5793MSVehicle::enterLaneAtInsertion(MSLane* enteredLane, double pos, double speed, double posLat, MSMoveReminder::Notification notification) {
5794 myState = State(pos, speed, posLat, pos - getVehicleType().getLength(), hasDeparted() ? myState.myPreviousSpeed : speed);
5796 onDepart();
5797 }
5798 if (enteredLane->isInternal() && myJunctionEntryTime == SUMOTime_MAX) {
5801 assert(enteredLane->getIncomingLanes().size() == 1);
5802 if (enteredLane->getIncomingLanes().front().viaLink->isConflictEntryLink()) {
5804 }
5805 }
5807 assert(myState.myPos >= 0);
5808 assert(myState.mySpeed >= 0);
5809 myLane = enteredLane;
5810 myAmOnNet = true;
5811 // schedule action for the next timestep
5813 if (notification != MSMoveReminder::NOTIFICATION_TELEPORT) {
5814 if (notification == MSMoveReminder::NOTIFICATION_PARKING && myInfluencer != nullptr) {
5815 drawOutsideNetwork(false);
5816 }
5817 // set and activate the new lane's reminders, teleports already did that at enterLaneAtMove
5818 for (std::vector< MSMoveReminder* >::const_iterator rem = enteredLane->getMoveReminders().begin(); rem != enteredLane->getMoveReminders().end(); ++rem) {
5819 addReminder(*rem);
5820 }
5821 activateReminders(notification, enteredLane);
5822 } else {
5823 myLastBestLanesEdge = nullptr;
5826 while (!myStops.empty() && myStops.front().edge == myCurrEdge && &myStops.front().lane->getEdge() == &myLane->getEdge()
5827 && myStops.front().pars.endPos < pos) {
5828 WRITE_WARNINGF(TL("Vehicle '%' skips stop on lane '%' time=%."), getID(), myStops.front().lane->getID(),
5829 time2string(MSNet::getInstance()->getCurrentTimeStep()));
5831 myStops.pop_front();
5832 }
5833 // avoid startup-effects after teleport
5835 myStopSpeed = std::numeric_limits<double>::max();
5836 }
5837 computeFurtherLanes(enteredLane, pos);
5841 } else if (MSGlobals::gLaneChangeDuration > 0) {
5843 }
5844 if (notification != MSMoveReminder::NOTIFICATION_LOAD_STATE) {
5848 myAngle += M_PI;
5849 }
5850 }
5851 if (MSNet::getInstance()->hasPersons()) {
5852 for (MSLane* further : myFurtherLanes) {
5853 if (further->mustCheckJunctionCollisions()) {
5855 }
5856 }
5857 }
5858}
5859
5860
5861void
5862MSVehicle::leaveLane(const MSMoveReminder::Notification reason, const MSLane* approachedLane) {
5863 for (MoveReminderCont::iterator rem = myMoveReminders.begin(); rem != myMoveReminders.end();) {
5864 if (rem->first->notifyLeave(*this, myState.myPos + rem->second, reason, approachedLane)) {
5865#ifdef _DEBUG
5866 if (myTraceMoveReminders) {
5867 traceMoveReminder("notifyLeave", rem->first, rem->second, true);
5868 }
5869#endif
5870 ++rem;
5871 } else {
5872#ifdef _DEBUG
5873 if (myTraceMoveReminders) {
5874 traceMoveReminder("notifyLeave", rem->first, rem->second, false);
5875 }
5876#endif
5877 rem = myMoveReminders.erase(rem);
5878 }
5879 }
5883 && myLane != nullptr) {
5885 }
5886 if (myLane != nullptr && myLane->getBidiLane() != nullptr && myAmOnNet
5887 && (!isRailway(getVClass()) || (myLane->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5889 }
5891 // @note. In case of lane change, myFurtherLanes and partial occupation
5892 // are handled in enterLaneAtLaneChange()
5893 for (MSLane* further : myFurtherLanes) {
5894#ifdef DEBUG_FURTHER
5895 if (DEBUG_COND) {
5896 std::cout << SIMTIME << " leaveLane \n";
5897 }
5898#endif
5899 further->resetPartialOccupation(this);
5900 if (further->getBidiLane() != nullptr
5901 && (!isRailway(getVClass()) || (further->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5902 further->getBidiLane()->resetPartialOccupation(this);
5903 }
5904 }
5905 myFurtherLanes.clear();
5906 myFurtherLanesPosLat.clear();
5907 }
5909 myAmOnNet = false;
5910 myWaitingTime = 0;
5911 }
5913 myStopDist = std::numeric_limits<double>::max();
5914 if (myPastStops.back().speed <= 0) {
5915 WRITE_WARNINGF(TL("Vehicle '%' aborts stop."), getID());
5916 }
5917 }
5919 while (!myStops.empty() && myStops.front().edge == myCurrEdge && &myStops.front().lane->getEdge() == &myLane->getEdge()) {
5920 if (myStops.front().getSpeed() <= 0) {
5921 WRITE_WARNINGF(TL("Vehicle '%' skips stop on lane '%' time=%."), getID(), myStops.front().lane->getID(),
5922 time2string(MSNet::getInstance()->getCurrentTimeStep()));
5924 if (MSStopOut::active()) {
5925 // clean up if stopBlocked was called
5927 }
5928 myStops.pop_front();
5929 } else {
5930 MSStop& stop = myStops.front();
5931 // passed waypoint at the end of the lane
5932 if (!stop.reached) {
5933 if (MSStopOut::active()) {
5935 }
5936 stop.reached = true;
5937 // enter stopping place so leaveFrom works as expected
5938 if (stop.busstop != nullptr) {
5939 // let the bus stop know the vehicle
5940 stop.busstop->enter(this, stop.pars.parking == ParkingType::OFFROAD);
5941 }
5942 if (stop.containerstop != nullptr) {
5943 // let the container stop know the vehicle
5945 }
5946 // do not enter parkingarea!
5947 if (stop.chargingStation != nullptr) {
5948 // let the container stop know the vehicle
5950 }
5951 }
5953 }
5954 myStopDist = std::numeric_limits<double>::max();
5955 }
5956 }
5957}
5958
5959
5960void
5962 for (MoveReminderCont::iterator rem = myMoveReminders.begin(); rem != myMoveReminders.end();) {
5963 if (rem->first->notifyLeaveBack(*this, reason, leftLane)) {
5964#ifdef _DEBUG
5965 if (myTraceMoveReminders) {
5966 traceMoveReminder("notifyLeaveBack", rem->first, rem->second, true);
5967 }
5968#endif
5969 ++rem;
5970 } else {
5971#ifdef _DEBUG
5972 if (myTraceMoveReminders) {
5973 traceMoveReminder("notifyLeaveBack", rem->first, rem->second, false);
5974 }
5975#endif
5976 rem = myMoveReminders.erase(rem);
5977 }
5978 }
5979#ifdef DEBUG_MOVEREMINDERS
5980 if (DEBUG_COND) {
5981 std::cout << SIMTIME << " veh=" << getID() << " myReminders:";
5982 for (auto rem : myMoveReminders) {
5983 std::cout << rem.first->getDescription() << " ";
5984 }
5985 std::cout << "\n";
5986 }
5987#endif
5988}
5989
5990
5995
5996
6001
6002bool
6004 return (lane->isInternal()
6005 ? & (lane->getLinkCont()[0]->getLane()->getEdge()) != *(myCurrEdge + 1)
6006 : &lane->getEdge() != *myCurrEdge);
6007}
6008
6009const std::vector<MSVehicle::LaneQ>&
6011 return *myBestLanes.begin();
6012}
6013
6014
6015void
6016MSVehicle::updateBestLanes(bool forceRebuild, const MSLane* startLane) {
6017#ifdef DEBUG_BESTLANES
6018 if (DEBUG_COND) {
6019 std::cout << SIMTIME << " updateBestLanes veh=" << getID() << " force=" << forceRebuild << " startLane1=" << Named::getIDSecure(startLane) << " myLane=" << Named::getIDSecure(myLane) << "\n";
6020 }
6021#endif
6022 if (startLane == nullptr) {
6023 startLane = myLane;
6024 }
6025 assert(startLane != 0);
6027 // depending on the calling context, startLane might be the forward lane
6028 // or the reverse-direction lane. In the latter case we need to
6029 // transform it to the forward lane.
6030 if (isOppositeLane(startLane)) {
6031 // use leftmost lane of forward edge
6032 startLane = startLane->getEdge().getOppositeEdge()->getLanes().back();
6033 assert(startLane != 0);
6034#ifdef DEBUG_BESTLANES
6035 if (DEBUG_COND) {
6036 std::cout << " startLaneIsOpposite newStartLane=" << startLane->getID() << "\n";
6037 }
6038#endif
6039 }
6040 }
6041 if (forceRebuild) {
6042 myLastBestLanesEdge = nullptr;
6044 }
6045 if (myBestLanes.size() > 0 && !forceRebuild && myLastBestLanesEdge == &startLane->getEdge()) {
6047#ifdef DEBUG_BESTLANES
6048 if (DEBUG_COND) {
6049 std::cout << " only updateOccupancyAndCurrentBestLane\n";
6050 }
6051#endif
6052 return;
6053 }
6054 if (startLane->getEdge().isInternal()) {
6055 if (myBestLanes.size() == 0 || forceRebuild) {
6056 // rebuilt from previous non-internal lane (may backtrack twice if behind an internal junction)
6057 updateBestLanes(true, startLane->getLogicalPredecessorLane());
6058 }
6059 if (myLastBestLanesInternalLane == startLane && !forceRebuild) {
6060#ifdef DEBUG_BESTLANES
6061 if (DEBUG_COND) {
6062 std::cout << " nothing to do on internal\n";
6063 }
6064#endif
6065 return;
6066 }
6067 // adapt best lanes to fit the current internal edge:
6068 // keep the entries that are reachable from this edge
6069 const MSEdge* nextEdge = startLane->getNextNormal();
6070 assert(!nextEdge->isInternal());
6071 for (std::vector<std::vector<LaneQ> >::iterator it = myBestLanes.begin(); it != myBestLanes.end();) {
6072 std::vector<LaneQ>& lanes = *it;
6073 assert(lanes.size() > 0);
6074 if (&(lanes[0].lane->getEdge()) == nextEdge) {
6075 // keep those lanes which are successors of internal lanes from the edge of startLane
6076 std::vector<LaneQ> oldLanes = lanes;
6077 lanes.clear();
6078 const std::vector<MSLane*>& sourceLanes = startLane->getEdge().getLanes();
6079 for (std::vector<MSLane*>::const_iterator it_source = sourceLanes.begin(); it_source != sourceLanes.end(); ++it_source) {
6080 for (std::vector<LaneQ>::iterator it_lane = oldLanes.begin(); it_lane != oldLanes.end(); ++it_lane) {
6081 if ((*it_source)->getLinkCont()[0]->getLane() == (*it_lane).lane) {
6082 lanes.push_back(*it_lane);
6083 break;
6084 }
6085 }
6086 }
6087 assert(lanes.size() == startLane->getEdge().getLanes().size());
6088 // patch invalid bestLaneOffset and updated myCurrentLaneInBestLanes
6089 for (int i = 0; i < (int)lanes.size(); ++i) {
6090 if (i + lanes[i].bestLaneOffset < 0) {
6091 lanes[i].bestLaneOffset = -i;
6092 }
6093 if (i + lanes[i].bestLaneOffset >= (int)lanes.size()) {
6094 lanes[i].bestLaneOffset = (int)lanes.size() - i - 1;
6095 }
6096 assert(i + lanes[i].bestLaneOffset >= 0);
6097 assert(i + lanes[i].bestLaneOffset < (int)lanes.size());
6098 if (lanes[i].bestContinuations[0] != 0) {
6099 // patch length of bestContinuation to match expectations (only once)
6100 lanes[i].bestContinuations.insert(lanes[i].bestContinuations.begin(), (MSLane*)nullptr);
6101 }
6102 if (startLane->getLinkCont()[0]->getLane() == lanes[i].lane) {
6103 myCurrentLaneInBestLanes = lanes.begin() + i;
6104 }
6105 assert(&(lanes[i].lane->getEdge()) == nextEdge);
6106 }
6107 myLastBestLanesInternalLane = startLane;
6109#ifdef DEBUG_BESTLANES
6110 if (DEBUG_COND) {
6111 std::cout << " updated for internal\n";
6112 }
6113#endif
6114 return;
6115 } else {
6116 // remove passed edges
6117 it = myBestLanes.erase(it);
6118 }
6119 }
6120 assert(false); // should always find the next edge
6121 }
6122 // start rebuilding
6124 myLastBestLanesEdge = &startLane->getEdge();
6126
6127 // get information about the next stop
6128 MSRouteIterator nextStopEdge = myRoute->end();
6129 const MSLane* nextStopLane = nullptr;
6130 double nextStopPos = 0;
6131 if (!myStops.empty()) {
6132 const MSStop& nextStop = myStops.front();
6133 nextStopLane = nextStop.lane;
6134 if (nextStop.isOpposite) {
6135 // target leftmost lane in forward direction
6136 nextStopLane = nextStopLane->getEdge().getOppositeEdge()->getLanes().back();
6137 }
6138 nextStopEdge = nextStop.edge;
6139 nextStopPos = nextStop.pars.startPos;
6140 }
6141 // myArrivalTime = -1 in the context of validating departSpeed with departLane=best
6142 if (myParameter->arrivalLaneProcedure >= ArrivalLaneDefinition::GIVEN && nextStopEdge == myRoute->end() && myArrivalLane >= 0) {
6143 nextStopEdge = (myRoute->end() - 1);
6144 nextStopLane = (*nextStopEdge)->getLanes()[myArrivalLane];
6145 nextStopPos = myArrivalPos;
6146 }
6147 if (nextStopEdge != myRoute->end()) {
6148 // make sure that the "wrong" lanes get a penalty. (penalty needs to be
6149 // large enough to overcome a magic threshold in MSLaneChangeModel::DK2004.cpp:383)
6150 nextStopPos = MAX2(POSITION_EPS, MIN2((double)nextStopPos, (double)(nextStopLane->getLength() - 2 * POSITION_EPS)));
6151 if (nextStopLane->isInternal()) {
6152 // switch to the correct lane before entering the intersection
6153 nextStopPos = (*nextStopEdge)->getLength();
6154 }
6155 }
6156
6157 // go forward along the next lanes; always look past stops to ensure that we
6158 // know where to go once the stop ends
6159 // trains do not have to deal with lane-changing for stops but their best
6160 // lanes lookahead is needed for rail signal control
6161 int seen = 0;
6162 double seenLength = 0;
6163 bool progress = true;
6164 // bestLanes must cover the braking distance even when at the very end of the current lane to avoid unecessary slow down
6165 const double maxBrakeDist = startLane->getLength() + getCarFollowModel().getHeadwayTime() * getMaxSpeed() + getCarFollowModel().brakeGap(getMaxSpeed()) + getVehicleType().getMinGap();
6166 const double lookahead = getLaneChangeModel().getStrategicLookahead();
6167 for (MSRouteIterator ce = myCurrEdge; progress;) {
6168 std::vector<LaneQ> currentLanes;
6169 const std::vector<MSLane*>* allowed = nullptr;
6170 const MSEdge* nextEdge = nullptr;
6171 if (ce != myRoute->end() && ce + 1 != myRoute->end()) {
6172 nextEdge = *(ce + 1);
6173 allowed = (*ce)->allowedLanes(*nextEdge, myType->getVehicleClass());
6174 }
6175 const std::vector<MSLane*>& lanes = (*ce)->getLanes();
6176 for (std::vector<MSLane*>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
6177 LaneQ q;
6178 MSLane* cl = *i;
6179 q.lane = cl;
6180 q.bestContinuations.push_back(cl);
6181 q.bestLaneOffset = 0;
6182 q.length = cl->allowsVehicleClass(myType->getVehicleClass()) ? (*ce)->getLength() : 0;
6183 q.currentLength = q.length;
6184 // if all lanes are forbidden (i.e. due to a dynamic closing) we want to express no preference
6185 q.allowsContinuation = allowed == nullptr || std::find(allowed->begin(), allowed->end(), cl) != allowed->end();
6186 q.occupation = 0;
6187 q.nextOccupation = 0;
6188 currentLanes.push_back(q);
6189 }
6190 //
6191 if (nextStopEdge == ce
6192 // already past the stop edge
6193 && !(ce == myCurrEdge && myLane != nullptr && myLane->isInternal())) {
6194 const MSLane* normalStopLane = nextStopLane->getNormalPredecessorLane();
6195 for (std::vector<LaneQ>::iterator q = currentLanes.begin(); q != currentLanes.end(); ++q) {
6196 if (nextStopLane != nullptr && normalStopLane != (*q).lane) {
6197 (*q).allowsContinuation = false;
6198 (*q).length = nextStopPos;
6199 (*q).currentLength = (*q).length;
6200 }
6201 }
6202 }
6203
6204 myBestLanes.push_back(currentLanes);
6205 ++seen;
6206 seenLength += currentLanes[0].lane->getLength();
6207 ++ce;
6208 if (lookahead >= 0) {
6209 progress &= (seen <= 2 || seenLength < lookahead); // custom (but we need to look at least one edge ahead)
6210 } else {
6211 progress &= (seen <= 4 || seenLength < MAX2(maxBrakeDist, 3000.0)); // motorway
6212 progress &= (seen <= 8 || seenLength < MAX2(maxBrakeDist, 200.0) || isRailway(getVClass())); // urban
6213 }
6214 progress &= ce != myRoute->end();
6215 /*
6216 if(progress) {
6217 progress &= (currentLanes.size()!=1||(*ce)->getLanes().size()!=1);
6218 }
6219 */
6220 }
6221
6222 // we are examining the last lane explicitly
6223 if (myBestLanes.size() != 0) {
6224 double bestLength = -1;
6225 // minimum and maximum lane index with best length
6226 int bestThisIndex = 0;
6227 int bestThisMaxIndex = 0;
6228 int index = 0;
6229 std::vector<LaneQ>& last = myBestLanes.back();
6230 for (std::vector<LaneQ>::iterator j = last.begin(); j != last.end(); ++j, ++index) {
6231 if ((*j).length > bestLength) {
6232 bestLength = (*j).length;
6233 bestThisIndex = index;
6234 bestThisMaxIndex = index;
6235 } else if ((*j).length == bestLength) {
6236 bestThisMaxIndex = index;
6237 }
6238 }
6239 index = 0;
6240 bool requiredChangeRightForbidden = false;
6241 int requireChangeToLeftForbidden = -1;
6242 for (std::vector<LaneQ>::iterator j = last.begin(); j != last.end(); ++j, ++index) {
6243 if ((*j).length < bestLength) {
6244 if (abs(bestThisIndex - index) < abs(bestThisMaxIndex - index)) {
6245 (*j).bestLaneOffset = bestThisIndex - index;
6246 } else {
6247 (*j).bestLaneOffset = bestThisMaxIndex - index;
6248 }
6249 if (!(*j).allowsContinuation) {
6250 if ((*j).bestLaneOffset < 0 && (!(*j).lane->allowsChangingRight(getVClass())
6251 || !(*j).lane->getParallelLane(-1, false)->allowsVehicleClass(getVClass())
6252 || requiredChangeRightForbidden)) {
6253 // this lane and all further lanes to the left cannot be used
6254 requiredChangeRightForbidden = true;
6255 (*j).length = 0;
6256 } else if ((*j).bestLaneOffset > 0 && (!(*j).lane->allowsChangingLeft(getVClass())
6257 || !(*j).lane->getParallelLane(1, false)->allowsVehicleClass(getVClass()))) {
6258 // this lane and all previous lanes to the right cannot be used
6259 requireChangeToLeftForbidden = (*j).lane->getIndex();
6260 }
6261 }
6262 }
6263 }
6264 for (int i = requireChangeToLeftForbidden; i >= 0; i--) {
6265 if (last[i].bestLaneOffset > 0) {
6266 last[i].length = 0;
6267 }
6268 }
6269#ifdef DEBUG_BESTLANES
6270 if (DEBUG_COND) {
6271 std::cout << " last edge=" << last.front().lane->getEdge().getID() << " (bestIndex=" << bestThisIndex << " bestMaxIndex=" << bestThisMaxIndex << "):\n";
6272 std::vector<LaneQ>& laneQs = myBestLanes.back();
6273 for (std::vector<LaneQ>::iterator j = laneQs.begin(); j != laneQs.end(); ++j) {
6274 std::cout << " lane=" << (*j).lane->getID() << " length=" << (*j).length << " bestOffset=" << (*j).bestLaneOffset << "\n";
6275 }
6276 }
6277#endif
6278 }
6279 // go backward through the lanes
6280 // track back best lane and compute the best prior lane(s)
6281 for (std::vector<std::vector<LaneQ> >::reverse_iterator i = myBestLanes.rbegin() + 1; i != myBestLanes.rend(); ++i) {
6282 std::vector<LaneQ>& nextLanes = (*(i - 1));
6283 std::vector<LaneQ>& clanes = (*i);
6284 MSEdge* const cE = &clanes[0].lane->getEdge();
6285 int index = 0;
6286 double bestConnectedLength = -1;
6287 double bestLength = -1;
6288 for (const LaneQ& j : nextLanes) {
6289 if (j.lane->isApproachedFrom(cE) && bestConnectedLength < j.length) {
6290 bestConnectedLength = j.length;
6291 }
6292 if (bestLength < j.length) {
6293 bestLength = j.length;
6294 }
6295 }
6296 // compute index of the best lane (highest length and least offset from the best next lane)
6297 int bestThisIndex = 0;
6298 int bestThisMaxIndex = 0;
6299 if (bestConnectedLength > 0) {
6300 index = 0;
6301 for (LaneQ& j : clanes) {
6302 const LaneQ* bestConnectedNext = nullptr;
6303 if (j.allowsContinuation) {
6304 for (const LaneQ& m : nextLanes) {
6305 if ((m.lane->allowsVehicleClass(getVClass()) || m.lane->hadPermissionChanges())
6306 && m.lane->isApproachedFrom(j.lane, getVClass())) {
6307 if (betterContinuation(bestConnectedNext, m)) {
6308 bestConnectedNext = &m;
6309 }
6310 }
6311 }
6312 if (bestConnectedNext != nullptr) {
6313 if (bestConnectedNext->length == bestConnectedLength && abs(bestConnectedNext->bestLaneOffset) < 2) {
6314 j.length += bestLength;
6315 } else {
6316 j.length += bestConnectedNext->length;
6317 }
6318 j.bestLaneOffset = bestConnectedNext->bestLaneOffset;
6319 }
6320 }
6321 if (bestConnectedNext != nullptr && (bestConnectedNext->allowsContinuation || bestConnectedNext->length > 0)) {
6322 copy(bestConnectedNext->bestContinuations.begin(), bestConnectedNext->bestContinuations.end(), back_inserter(j.bestContinuations));
6323 } else {
6324 j.allowsContinuation = false;
6325 }
6326 if (clanes[bestThisIndex].length < j.length
6327 || (clanes[bestThisIndex].length == j.length && abs(clanes[bestThisIndex].bestLaneOffset) > abs(j.bestLaneOffset))
6328 || (clanes[bestThisIndex].length == j.length && abs(clanes[bestThisIndex].bestLaneOffset) == abs(j.bestLaneOffset) &&
6329 nextLinkPriority(clanes[bestThisIndex].bestContinuations) < nextLinkPriority(j.bestContinuations))
6330 ) {
6331 bestThisIndex = index;
6332 bestThisMaxIndex = index;
6333 } else if (clanes[bestThisIndex].length == j.length
6334 && abs(clanes[bestThisIndex].bestLaneOffset) == abs(j.bestLaneOffset)
6335 && nextLinkPriority(clanes[bestThisIndex].bestContinuations) == nextLinkPriority(j.bestContinuations)) {
6336 bestThisMaxIndex = index;
6337 }
6338 index++;
6339 }
6340
6341 //vehicle with elecHybrid device prefers running under an overhead wire
6342 if (getDevice(typeid(MSDevice_ElecHybrid)) != nullptr) {
6343 index = 0;
6344 for (const LaneQ& j : clanes) {
6345 std::string overheadWireSegmentID = MSNet::getInstance()->getStoppingPlaceID(j.lane, j.currentLength / 2., SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
6346 if (overheadWireSegmentID != "") {
6347 bestThisIndex = index;
6348 bestThisMaxIndex = index;
6349 }
6350 index++;
6351 }
6352 }
6353
6354 } else {
6355 // only needed in case of disconnected routes
6356 int bestNextIndex = 0;
6357 int bestDistToNeeded = (int) clanes.size();
6358 index = 0;
6359 for (std::vector<LaneQ>::iterator j = clanes.begin(); j != clanes.end(); ++j, ++index) {
6360 if ((*j).allowsContinuation) {
6361 int nextIndex = 0;
6362 for (std::vector<LaneQ>::const_iterator m = nextLanes.begin(); m != nextLanes.end(); ++m, ++nextIndex) {
6363 if ((*m).lane->isApproachedFrom((*j).lane, getVClass())) {
6364 if (bestDistToNeeded > abs((*m).bestLaneOffset)) {
6365 bestDistToNeeded = abs((*m).bestLaneOffset);
6366 bestThisIndex = index;
6367 bestThisMaxIndex = index;
6368 bestNextIndex = nextIndex;
6369 }
6370 }
6371 }
6372 }
6373 }
6374 clanes[bestThisIndex].length += nextLanes[bestNextIndex].length;
6375 copy(nextLanes[bestNextIndex].bestContinuations.begin(), nextLanes[bestNextIndex].bestContinuations.end(), back_inserter(clanes[bestThisIndex].bestContinuations));
6376
6377 }
6378 // set bestLaneOffset for all lanes
6379 index = 0;
6380 bool requiredChangeRightForbidden = false;
6381 int requireChangeToLeftForbidden = -1;
6382 for (std::vector<LaneQ>::iterator j = clanes.begin(); j != clanes.end(); ++j, ++index) {
6383 if ((*j).length < clanes[bestThisIndex].length
6384 || ((*j).length == clanes[bestThisIndex].length && abs((*j).bestLaneOffset) > abs(clanes[bestThisIndex].bestLaneOffset))
6385 || (nextLinkPriority((*j).bestContinuations)) < nextLinkPriority(clanes[bestThisIndex].bestContinuations)
6386 ) {
6387 if (abs(bestThisIndex - index) < abs(bestThisMaxIndex - index)) {
6388 (*j).bestLaneOffset = bestThisIndex - index;
6389 } else {
6390 (*j).bestLaneOffset = bestThisMaxIndex - index;
6391 }
6392 if ((nextLinkPriority((*j).bestContinuations)) < nextLinkPriority(clanes[bestThisIndex].bestContinuations)) {
6393 // try to move away from the lower-priority lane before it ends
6394 (*j).length = (*j).currentLength;
6395 }
6396 if (!(*j).allowsContinuation) {
6397 if ((*j).bestLaneOffset < 0 && (!(*j).lane->allowsChangingRight(getVClass())
6398 || !(*j).lane->getParallelLane(-1, false)->allowsVehicleClass(getVClass())
6399 || requiredChangeRightForbidden)) {
6400 // this lane and all further lanes to the left cannot be used
6401 requiredChangeRightForbidden = true;
6402 if ((*j).length == (*j).currentLength) {
6403 (*j).length = 0;
6404 }
6405 } else if ((*j).bestLaneOffset > 0 && (!(*j).lane->allowsChangingLeft(getVClass())
6406 || !(*j).lane->getParallelLane(1, false)->allowsVehicleClass(getVClass()))) {
6407 // this lane and all previous lanes to the right cannot be used
6408 requireChangeToLeftForbidden = (*j).lane->getIndex();
6409 }
6410 }
6411 } else {
6412 (*j).bestLaneOffset = 0;
6413 }
6414 }
6415 for (int idx = requireChangeToLeftForbidden; idx >= 0; idx--) {
6416 if (clanes[idx].length == clanes[idx].currentLength) {
6417 clanes[idx].length = 0;
6418 };
6419 }
6420
6421 //vehicle with elecHybrid device prefers running under an overhead wire
6422 if (static_cast<MSDevice_ElecHybrid*>(getDevice(typeid(MSDevice_ElecHybrid))) != 0) {
6423 index = 0;
6424 std::string overheadWireID = MSNet::getInstance()->getStoppingPlaceID(clanes[bestThisIndex].lane, (clanes[bestThisIndex].currentLength) / 2, SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
6425 if (overheadWireID != "") {
6426 for (std::vector<LaneQ>::iterator j = clanes.begin(); j != clanes.end(); ++j, ++index) {
6427 (*j).bestLaneOffset = bestThisIndex - index;
6428 }
6429 }
6430 }
6431
6432#ifdef DEBUG_BESTLANES
6433 if (DEBUG_COND) {
6434 std::cout << " edge=" << cE->getID() << " (bestIndex=" << bestThisIndex << " bestMaxIndex=" << bestThisMaxIndex << "):\n";
6435 std::vector<LaneQ>& laneQs = clanes;
6436 for (std::vector<LaneQ>::iterator j = laneQs.begin(); j != laneQs.end(); ++j) {
6437 std::cout << " lane=" << (*j).lane->getID() << " length=" << (*j).length << " bestOffset=" << (*j).bestLaneOffset << " allowCont=" << (*j).allowsContinuation << "\n";
6438 }
6439 }
6440#endif
6441
6442 }
6443 if (myBestLanes.front().front().lane->isInternal()) {
6444 // route starts on an internal lane
6445 if (myLane != nullptr) {
6446 startLane = myLane;
6447 } else {
6448 // vehicle not yet departed
6449 startLane = myBestLanes.front().front().lane;
6450 }
6451 }
6453#ifdef DEBUG_BESTLANES
6454 if (DEBUG_COND) {
6455 std::cout << SIMTIME << " veh=" << getID() << " bestCont=" << toString(getBestLanesContinuation()) << "\n";
6456 }
6457#endif
6458}
6459
6460void
6462 if (myLane != nullptr) {
6464 }
6465}
6466
6467bool
6468MSVehicle::betterContinuation(const LaneQ* bestConnectedNext, const LaneQ& m) const {
6469 if (bestConnectedNext == nullptr) {
6470 return true;
6471 } else if (m.lane->getBidiLane() != nullptr && bestConnectedNext->lane->getBidiLane() == nullptr) {
6472 return false;
6473 } else if (bestConnectedNext->lane->getBidiLane() != nullptr && m.lane->getBidiLane() == nullptr) {
6474 return true;
6475 } else if (bestConnectedNext->length < m.length) {
6476 return true;
6477 } else if (bestConnectedNext->length == m.length) {
6478 if (abs(bestConnectedNext->bestLaneOffset) > abs(m.bestLaneOffset)) {
6479 return true;
6480 }
6481 const double contRight = getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_CONTRIGHT, 1);
6482 if (contRight < 1
6483 // if we don't check for adjacency, the rightmost line will get
6484 // multiple chances to be better which leads to an uninituitve distribution
6485 && (m.lane->getIndex() - bestConnectedNext->lane->getIndex()) == 1
6486 && RandHelper::rand(getRNG()) > contRight) {
6487 return true;
6488 }
6489 }
6490 return false;
6491}
6492
6493
6494int
6495MSVehicle::nextLinkPriority(const std::vector<MSLane*>& conts) {
6496 if (conts.size() < 2) {
6497 return -1;
6498 } else {
6499 const MSLink* const link = conts[0]->getLinkTo(conts[1]);
6500 if (link != nullptr) {
6501 return link->havePriority() ? 1 : 0;
6502 } else {
6503 // disconnected route
6504 return -1;
6505 }
6506 }
6507}
6508
6509
6510void
6512 std::vector<LaneQ>& currLanes = *myBestLanes.begin();
6513 std::vector<LaneQ>::iterator i;
6514#ifdef _DEBUG
6515 bool found = false;
6516#endif
6517 for (i = currLanes.begin(); i != currLanes.end(); ++i) {
6518 double nextOccupation = 0;
6519 for (std::vector<MSLane*>::const_iterator j = (*i).bestContinuations.begin() + 1; j != (*i).bestContinuations.end(); ++j) {
6520 nextOccupation += (*j)->getBruttoVehLenSum();
6521 }
6522 (*i).nextOccupation = nextOccupation;
6523#ifdef DEBUG_BESTLANES
6524 if (DEBUG_COND) {
6525 std::cout << " lane=" << (*i).lane->getID() << " nextOccupation=" << nextOccupation << "\n";
6526 }
6527#endif
6528 if ((*i).lane == startLane) {
6530#ifdef _DEBUG
6531 found = true;
6532#endif
6533 }
6534 }
6535#ifdef _DEBUG
6536 assert(found || startLane->isInternal());
6537#endif
6538}
6539
6540
6541const std::vector<MSLane*>&
6543 if (myBestLanes.empty() || myBestLanes[0].empty()) {
6544 return myEmptyLaneVector;
6545 }
6546 return (*myCurrentLaneInBestLanes).bestContinuations;
6547}
6548
6549
6550const std::vector<MSLane*>&
6552 const MSLane* lane = l;
6553 // XXX: shouldn't this be a "while" to cover more than one internal lane? (Leo) Refs. #2575
6554 if (lane->getEdge().isInternal()) {
6555 // internal edges are not kept inside the bestLanes structure
6556 lane = lane->getLinkCont()[0]->getLane();
6557 }
6558 if (myBestLanes.size() == 0) {
6559 return myEmptyLaneVector;
6560 }
6561 for (std::vector<LaneQ>::const_iterator i = myBestLanes[0].begin(); i != myBestLanes[0].end(); ++i) {
6562 if ((*i).lane == lane) {
6563 return (*i).bestContinuations;
6564 }
6565 }
6566 return myEmptyLaneVector;
6567}
6568
6569const std::vector<const MSLane*>
6570MSVehicle::getUpcomingLanesUntil(double distance) const {
6571 std::vector<const MSLane*> lanes;
6572
6573 if (distance <= 0. || hasArrived()) {
6574 // WRITE_WARNINGF(TL("MSVehicle::getUpcomingLanesUntil(): distance ('%') should be greater than 0."), distance);
6575 return lanes;
6576 }
6577
6578 if (!myLaneChangeModel->isOpposite()) {
6579 distance += getPositionOnLane();
6580 } else {
6581 distance += myLane->getOppositePos(getPositionOnLane());
6582 }
6584 while (lane->isInternal() && (distance > 0.)) { // include initial internal lanes
6585 lanes.insert(lanes.end(), lane);
6586 distance -= lane->getLength();
6587 lane = lane->getLinkCont().front()->getViaLaneOrLane();
6588 }
6589
6590 const std::vector<MSLane*>& contLanes = getBestLanesContinuation();
6591 if (contLanes.empty()) {
6592 return lanes;
6593 }
6594 auto contLanesIt = contLanes.begin();
6595 MSRouteIterator routeIt = myCurrEdge; // keep track of covered edges in myRoute
6596 while (distance > 0.) {
6597 MSLane* l = nullptr;
6598 if (contLanesIt != contLanes.end()) {
6599 l = *contLanesIt;
6600 if (l != nullptr) {
6601 assert(l->getEdge().getID() == (*routeIt)->getLanes().front()->getEdge().getID());
6602 }
6603 ++contLanesIt;
6604 if (l != nullptr || myLane->isInternal()) {
6605 ++routeIt;
6606 }
6607 if (l == nullptr) {
6608 continue;
6609 }
6610 } else if (routeIt != myRoute->end()) { // bestLanes didn't get us far enough
6611 // choose left-most lane as default (avoid sidewalks, bike lanes etc)
6612 l = (*routeIt)->getLanes().back();
6613 ++routeIt;
6614 } else { // the search distance goes beyond our route
6615 break;
6616 }
6617
6618 assert(l != nullptr);
6619
6620 // insert internal lanes if applicable
6621 const MSLane* internalLane = lanes.size() > 0 ? lanes.back()->getInternalFollowingLane(l) : nullptr;
6622 while ((internalLane != nullptr) && internalLane->isInternal() && (distance > 0.)) {
6623 lanes.insert(lanes.end(), internalLane);
6624 distance -= internalLane->getLength();
6625 internalLane = internalLane->getLinkCont().front()->getViaLaneOrLane();
6626 }
6627 if (distance <= 0.) {
6628 break;
6629 }
6630
6631 lanes.insert(lanes.end(), l);
6632 distance -= l->getLength();
6633 }
6634
6635 return lanes;
6636}
6637
6638const std::vector<const MSLane*>
6639MSVehicle::getPastLanesUntil(double distance) const {
6640 std::vector<const MSLane*> lanes;
6641
6642 if (distance <= 0.) {
6643 // WRITE_WARNINGF(TL("MSVehicle::getPastLanesUntil(): distance ('%') should be greater than 0."), distance);
6644 return lanes;
6645 }
6646
6647 MSRouteIterator routeIt = myCurrEdge;
6648 if (!myLaneChangeModel->isOpposite()) {
6649 distance += myLane->getLength() - getPositionOnLane();
6650 } else {
6652 }
6654 while (lane->isInternal() && (distance > 0.)) { // include initial internal lanes
6655 lanes.insert(lanes.end(), lane);
6656 distance -= lane->getLength();
6657 lane = lane->getLogicalPredecessorLane();
6658 }
6659
6660 while (distance > 0.) {
6661 // choose left-most lane as default (avoid sidewalks, bike lanes etc)
6662 MSLane* l = (*routeIt)->getLanes().back();
6663
6664 // insert internal lanes if applicable
6665 const MSEdge* internalEdge = lanes.size() > 0 ? (*routeIt)->getInternalFollowingEdge(&(lanes.back()->getEdge()), getVClass()) : nullptr;
6666 const MSLane* internalLane = internalEdge != nullptr ? internalEdge->getLanes().front() : nullptr;
6667 std::vector<const MSLane*> internalLanes;
6668 while ((internalLane != nullptr) && internalLane->isInternal()) { // collect all internal successor lanes
6669 internalLanes.insert(internalLanes.begin(), internalLane);
6670 internalLane = internalLane->getLinkCont().front()->getViaLaneOrLane();
6671 }
6672 for (auto it = internalLanes.begin(); (it != internalLanes.end()) && (distance > 0.); ++it) { // check remaining distance in correct order
6673 lanes.insert(lanes.end(), *it);
6674 distance -= (*it)->getLength();
6675 }
6676 if (distance <= 0.) {
6677 break;
6678 }
6679
6680 lanes.insert(lanes.end(), l);
6681 distance -= l->getLength();
6682
6683 // NOTE: we're going backwards with the (bi-directional) Iterator
6684 // TODO: consider make reverse_iterator() when moving on to C++14 or later
6685 if (routeIt != myRoute->begin()) {
6686 --routeIt;
6687 } else { // we went backwards to begin() and already processed the first and final element
6688 break;
6689 }
6690 }
6691
6692 return lanes;
6693}
6694
6695
6696const std::vector<MSLane*>
6698 const std::vector<const MSLane*> routeLanes = getPastLanesUntil(myLane->getMaximumBrakeDist());
6699 std::vector<MSLane*> result;
6700 for (const MSLane* lane : routeLanes) {
6701 MSLane* opposite = lane->getOpposite();
6702 if (opposite != nullptr) {
6703 result.push_back(opposite);
6704 } else {
6705 break;
6706 }
6707 }
6708 return result;
6709}
6710
6711
6712int
6714 if (myBestLanes.empty() || myBestLanes[0].empty()) {
6715 return 0;
6716 } else {
6717 return (*myCurrentLaneInBestLanes).bestLaneOffset;
6718 }
6719}
6720
6721double
6723 if (myBestLanes.empty() || myBestLanes[0].empty()) {
6724 return -1;
6725 } else {
6726 return (*myCurrentLaneInBestLanes).length;
6727 }
6728}
6729
6730
6731
6732void
6733MSVehicle::adaptBestLanesOccupation(int laneIndex, double density) {
6734 std::vector<MSVehicle::LaneQ>& preb = myBestLanes.front();
6735 assert(laneIndex < (int)preb.size());
6736 preb[laneIndex].occupation = density + preb[laneIndex].nextOccupation;
6737}
6738
6739
6740void
6746
6747std::pair<const MSLane*, double>
6748MSVehicle::getLanePosAfterDist(double distance) const {
6749 if (distance == 0) {
6750 return std::make_pair(myLane, getPositionOnLane());
6751 }
6752 const std::vector<const MSLane*> lanes = getUpcomingLanesUntil(distance);
6753 distance += getPositionOnLane();
6754 for (const MSLane* lane : lanes) {
6755 if (lane->getLength() > distance) {
6756 return std::make_pair(lane, distance);
6757 }
6758 distance -= lane->getLength();
6759 }
6760 return std::make_pair(nullptr, -1);
6761}
6762
6763
6764double
6765MSVehicle::getDistanceToPosition(double destPos, const MSLane* destLane) const {
6766 if (isOnRoad() && destLane != nullptr) {
6767 return myRoute->getDistanceBetween(getPositionOnLane(), destPos, myLane, destLane);
6768 }
6769 return std::numeric_limits<double>::max();
6770}
6771
6772
6773std::pair<const MSVehicle* const, double>
6774MSVehicle::getLeader(double dist, bool considerCrossingFoes) const {
6775 if (myLane == nullptr) {
6776 return std::make_pair(static_cast<const MSVehicle*>(nullptr), -1);
6777 }
6778 if (dist == 0) {
6780 }
6781 const MSVehicle* lead = nullptr;
6782 const MSLane* lane = myLane; // ensure lane does not change between getVehiclesSecure and releaseVehicles;
6783 const MSLane::VehCont& vehs = lane->getVehiclesSecure();
6784 // vehicle might be outside the road network
6785 MSLane::VehCont::const_iterator it = std::find(vehs.begin(), vehs.end(), this);
6786 if (it != vehs.end() && it + 1 != vehs.end()) {
6787 lead = *(it + 1);
6788 }
6789 if (lead != nullptr) {
6790 std::pair<const MSVehicle* const, double> result(
6791 lead, lead->getBackPositionOnLane(myLane) - getPositionOnLane() - getVehicleType().getMinGap());
6792 lane->releaseVehicles();
6793 return result;
6794 }
6795 const double seen = myLane->getLength() - getPositionOnLane();
6796 const std::vector<MSLane*>& bestLaneConts = getBestLanesContinuation(myLane);
6797 std::pair<const MSVehicle* const, double> result = myLane->getLeaderOnConsecutive(dist, seen, getSpeed(), *this, bestLaneConts, considerCrossingFoes);
6798 lane->releaseVehicles();
6799 return result;
6800}
6801
6802
6803std::pair<const MSVehicle* const, double>
6804MSVehicle::getFollower(double dist) const {
6805 if (myLane == nullptr) {
6806 return std::make_pair(static_cast<const MSVehicle*>(nullptr), -1);
6807 }
6808 if (dist == 0) {
6809 dist = getCarFollowModel().brakeGap(myLane->getEdge().getSpeedLimit() * 2, 4.5, 0);
6810 }
6812}
6813
6814
6815double
6817 // calling getLeader with 0 would induce a dist calculation but we only want to look for the leaders on the current lane
6818 std::pair<const MSVehicle* const, double> leaderInfo = getLeader(-1);
6819 if (leaderInfo.first == nullptr || getSpeed() == 0) {
6820 return -1;
6821 }
6822 return (leaderInfo.second + getVehicleType().getMinGap()) / getSpeed();
6823}
6824
6825
6826void
6828 MSBaseVehicle::addTransportable(transportable);
6829 if (myStops.size() > 0 && myStops.front().reached) {
6830 if (transportable->isPerson()) {
6831 if (myStops.front().triggered && myStops.front().numExpectedPerson > 0) {
6832 myStops.front().numExpectedPerson -= (int)myStops.front().pars.awaitedPersons.count(transportable->getID());
6833 }
6834 } else {
6835 if (myStops.front().pars.containerTriggered && myStops.front().numExpectedContainer > 0) {
6836 myStops.front().numExpectedContainer -= (int)myStops.front().pars.awaitedContainers.count(transportable->getID());
6837 }
6838 }
6839 }
6840}
6841
6842
6843void
6846 int state = myLaneChangeModel->getOwnState();
6847 // do not set blinker for sublane changes or when blocked from changing to the right
6848 const bool blinkerManoeuvre = (((state & LCA_SUBLANE) == 0) && (
6849 (state & LCA_KEEPRIGHT) == 0 || (state & LCA_BLOCKED) == 0));
6853 // lane indices increase from left to right
6854 std::swap(left, right);
6855 }
6856 if ((state & LCA_LEFT) != 0 && blinkerManoeuvre) {
6857 switchOnSignal(left);
6858 } else if ((state & LCA_RIGHT) != 0 && blinkerManoeuvre) {
6859 switchOnSignal(right);
6860 } else if (myLaneChangeModel->isChangingLanes()) {
6862 switchOnSignal(left);
6863 } else {
6864 switchOnSignal(right);
6865 }
6866 } else {
6867 const MSLane* lane = getLane();
6868 std::vector<MSLink*>::const_iterator link = MSLane::succLinkSec(*this, 1, *lane, getBestLanesContinuation());
6869 if (link != lane->getLinkCont().end() && lane->getLength() - getPositionOnLane() < lane->getVehicleMaxSpeed(this) * (double) 7.) {
6870 switch ((*link)->getDirection()) {
6875 break;
6879 break;
6880 default:
6881 break;
6882 }
6883 }
6884 }
6885 // stopping related signals
6886 if (hasStops()
6887 && (myStops.begin()->reached ||
6889 && myStopDist < getCarFollowModel().brakeGap(myLane->getVehicleMaxSpeed(this), getCarFollowModel().getMaxDecel(), 3)))) {
6890 if (myStops.begin()->lane->getIndex() > 0 && myStops.begin()->lane->getParallelLane(-1)->allowsVehicleClass(getVClass())) {
6891 // not stopping on the right. Activate emergency blinkers
6893 } else if (!myStops.begin()->reached && (myStops.begin()->pars.parking == ParkingType::OFFROAD)) {
6894 // signal upcoming parking stop on the current lane when within braking distance (~2 seconds before braking)
6896 }
6897 }
6898 if (myInfluencer != nullptr && myInfluencer->getSignals() >= 0) {
6900 myInfluencer->setSignals(-1); // overwrite computed signals only once
6901 }
6902}
6903
6904void
6906
6907 //TODO look if timestep ist SIMSTEP
6908 if (currentTime % 1000 == 0) {
6911 } else {
6913 }
6914 }
6915}
6916
6917
6918int
6920 return myLane == nullptr ? -1 : myLane->getIndex();
6921}
6922
6923
6924void
6925MSVehicle::setTentativeLaneAndPosition(MSLane* lane, double pos, double posLat) {
6926 myLane = lane;
6927 myState.myPos = pos;
6928 myState.myPosLat = posLat;
6930}
6931
6932
6933double
6935 return myState.myPosLat + 0.5 * myLane->getWidth() - 0.5 * getVehicleType().getWidth();
6936}
6937
6938
6939double
6941 return myState.myPosLat + 0.5 * myLane->getWidth() + 0.5 * getVehicleType().getWidth();
6942}
6943
6944
6945double
6947 return myState.myPosLat + 0.5 * lane->getWidth() - 0.5 * getVehicleType().getWidth();
6948}
6949
6950
6951double
6953 return myState.myPosLat + 0.5 * lane->getWidth() + 0.5 * getVehicleType().getWidth();
6954}
6955
6956
6957double
6959 return getCenterOnEdge(lane) - 0.5 * getVehicleType().getWidth();
6960}
6961
6962
6963double
6965 return getCenterOnEdge(lane) + 0.5 * getVehicleType().getWidth();
6966}
6967
6968
6969double
6971 if (lane == nullptr || &lane->getEdge() == &myLane->getEdge()) {
6973 } else if (lane == myLaneChangeModel->getShadowLane()) {
6974 if (myLaneChangeModel->isOpposite() && &lane->getEdge() != &myLane->getEdge()) {
6975 return lane->getRightSideOnEdge() + lane->getWidth() - myState.myPosLat + 0.5 * myLane->getWidth();
6976 }
6978 return lane->getRightSideOnEdge() + lane->getWidth() + myState.myPosLat + 0.5 * myLane->getWidth();
6979 } else {
6980 return lane->getRightSideOnEdge() - myLane->getWidth() + myState.myPosLat + 0.5 * myLane->getWidth();
6981 }
6982 } else if (lane == myLane->getBidiLane()) {
6983 return lane->getRightSideOnEdge() - myState.myPosLat + 0.5 * lane->getWidth();
6984 } else {
6985 assert(myFurtherLanes.size() == myFurtherLanesPosLat.size());
6986 for (int i = 0; i < (int)myFurtherLanes.size(); ++i) {
6987 if (myFurtherLanes[i] == lane) {
6988#ifdef DEBUG_FURTHER
6989 if (DEBUG_COND) std::cout << " getCenterOnEdge veh=" << getID() << " lane=" << lane->getID() << " i=" << i << " furtherLat=" << myFurtherLanesPosLat[i]
6990 << " result=" << lane->getRightSideOnEdge() + myFurtherLanesPosLat[i] + 0.5 * lane->getWidth()
6991 << "\n";
6992#endif
6993 return lane->getRightSideOnEdge() + myFurtherLanesPosLat[i] + 0.5 * lane->getWidth();
6994 } else if (myFurtherLanes[i]->getBidiLane() == lane) {
6995#ifdef DEBUG_FURTHER
6996 if (DEBUG_COND) std::cout << " getCenterOnEdge veh=" << getID() << " lane=" << lane->getID() << " i=" << i << " furtherLat(bidi)=" << myFurtherLanesPosLat[i]
6997 << " result=" << lane->getRightSideOnEdge() + myFurtherLanesPosLat[i] + 0.5 * lane->getWidth()
6998 << "\n";
6999#endif
7000 return lane->getRightSideOnEdge() - myFurtherLanesPosLat[i] + 0.5 * lane->getWidth();
7001 }
7002 }
7003 //if (DEBUG_COND) std::cout << SIMTIME << " veh=" << getID() << " myShadowFurtherLanes=" << toString(myLaneChangeModel->getShadowFurtherLanes()) << "\n";
7004 const std::vector<MSLane*>& shadowFurther = myLaneChangeModel->getShadowFurtherLanes();
7005 for (int i = 0; i < (int)shadowFurther.size(); ++i) {
7006 //if (DEBUG_COND) std::cout << " comparing i=" << (*i)->getID() << " lane=" << lane->getID() << "\n";
7007 if (shadowFurther[i] == lane) {
7008 assert(myLaneChangeModel->getShadowLane() != 0);
7009 return (lane->getRightSideOnEdge() + myLaneChangeModel->getShadowFurtherLanesPosLat()[i] + 0.5 * lane->getWidth()
7011 }
7012 }
7013 assert(false);
7014 throw ProcessError("Request lateral pos of vehicle '" + getID() + "' for invalid lane '" + Named::getIDSecure(lane) + "'");
7015 }
7016}
7017
7018
7019double
7021 assert(lane != 0);
7022 if (&lane->getEdge() == &myLane->getEdge()) {
7023 return myLane->getRightSideOnEdge() - lane->getRightSideOnEdge();
7024 } else if (myLane->getParallelOpposite() == lane) {
7025 return (myLane->getWidth() + lane->getWidth()) * 0.5 - 2 * getLateralPositionOnLane();
7026 } else if (myLane->getBidiLane() == lane) {
7027 return -2 * getLateralPositionOnLane();
7028 } else {
7029 // Check whether the lane is a further lane for the vehicle
7030 for (int i = 0; i < (int)myFurtherLanes.size(); ++i) {
7031 if (myFurtherLanes[i] == lane) {
7032#ifdef DEBUG_FURTHER
7033 if (DEBUG_COND) {
7034 std::cout << " getLatOffset veh=" << getID() << " lane=" << lane->getID() << " i=" << i << " posLat=" << myState.myPosLat << " furtherLat=" << myFurtherLanesPosLat[i] << "\n";
7035 }
7036#endif
7038 } else if (myFurtherLanes[i]->getBidiLane() == lane) {
7039#ifdef DEBUG_FURTHER
7040 if (DEBUG_COND) {
7041 std::cout << " getLatOffset veh=" << getID() << " lane=" << lane->getID() << " i=" << i << " posLat=" << myState.myPosLat << " furtherBidiLat=" << myFurtherLanesPosLat[i] << "\n";
7042 }
7043#endif
7044 return -2 * (myFurtherLanesPosLat[i] - myState.myPosLat);
7045 }
7046 }
7047#ifdef DEBUG_FURTHER
7048 if (DEBUG_COND) {
7049 std::cout << SIMTIME << " veh=" << getID() << " myShadowFurtherLanes=" << toString(myLaneChangeModel->getShadowFurtherLanes()) << "\n";
7050 }
7051#endif
7052 // Check whether the lane is a "shadow further lane" for the vehicle
7053 const std::vector<MSLane*>& shadowFurther = myLaneChangeModel->getShadowFurtherLanes();
7054 for (int i = 0; i < (int)shadowFurther.size(); ++i) {
7055 if (shadowFurther[i] == lane) {
7056#ifdef DEBUG_FURTHER
7057 if (DEBUG_COND) std::cout << " getLatOffset veh=" << getID()
7058 << " shadowLane=" << Named::getIDSecure(myLaneChangeModel->getShadowLane())
7059 << " lane=" << lane->getID()
7060 << " i=" << i
7061 << " posLat=" << myState.myPosLat
7062 << " shadowPosLat=" << getLatOffset(myLaneChangeModel->getShadowLane())
7063 << " shadowFurtherLat=" << myLaneChangeModel->getShadowFurtherLanesPosLat()[i]
7064 << "\n";
7065#endif
7067 } else if (shadowFurther[i]->getBidiLane() == lane) {
7068#ifdef DEBUG_FURTHER
7069 if (DEBUG_COND) {
7070 std::cout << " getLatOffset veh=" << getID() << " shadowbidilane=" << lane->getID() << " i=" << i << " posLat=" << myState.myPosLat << " furtherBidiLat=" << myFurtherLanesPosLat[i] << "\n";
7071 }
7072#endif
7074 }
7075 }
7076 // Check whether the vehicle issued a maneuverReservation on the lane.
7077 const std::vector<MSLane*>& furtherTargets = myLaneChangeModel->getFurtherTargetLanes();
7078 for (int i = 0; i < (int)myFurtherLanes.size(); ++i) {
7079 // Further target lanes are just neighboring lanes of the vehicle's further lanes, @see MSAbstractLaneChangeModel::updateTargetLane()
7080 MSLane* targetLane = furtherTargets[i];
7081 if (targetLane == lane) {
7082 const double targetDir = myLaneChangeModel->getManeuverDist() < 0 ? -1. : 1.;
7083 const double latOffset = myFurtherLanesPosLat[i] - myState.myPosLat + targetDir * 0.5 * (myFurtherLanes[i]->getWidth() + targetLane->getWidth());
7084#ifdef DEBUG_TARGET_LANE
7085 if (DEBUG_COND) {
7086 std::cout << " getLatOffset veh=" << getID()
7087 << " wrt targetLane=" << Named::getIDSecure(myLaneChangeModel->getTargetLane())
7088 << "\n i=" << i
7089 << " posLat=" << myState.myPosLat
7090 << " furtherPosLat=" << myFurtherLanesPosLat[i]
7091 << " maneuverDist=" << myLaneChangeModel->getManeuverDist()
7092 << " targetDir=" << targetDir
7093 << " latOffset=" << latOffset
7094 << std::endl;
7095 }
7096#endif
7097 return latOffset;
7098 } else if (targetLane != nullptr && targetLane->getBidiLane() == lane) {
7099 const double targetDir = myLaneChangeModel->getManeuverDist() < 0 ? -1. : 1.;
7100 const double latOffset = myFurtherLanesPosLat[i] - myState.myPosLat + targetDir * 0.5 * (myFurtherLanes[i]->getWidth() + targetLane->getWidth());
7101#ifdef DEBUG_FURTHER
7102 if (DEBUG_COND) {
7103 std::cout << " getLatOffset veh=" << getID() << " furthertargetbidilane=" << lane->getID() << " i=" << i << " posLat=" << myState.myPosLat << " furtherBidiLat=" << myFurtherLanesPosLat[i] << "\n";
7104 }
7105#endif
7106 return -2 * latOffset;
7107 }
7108 }
7109 assert(false);
7110 throw ProcessError("Request lateral offset of vehicle '" + getID() + "' for invalid lane '" + Named::getIDSecure(lane) + "'");
7111 }
7112}
7113
7114
7115double
7116MSVehicle::lateralDistanceToLane(const int offset) const {
7117 // compute the distance when changing to the neighboring lane
7118 // (ensure we do not lap into the line behind neighLane since there might be unseen blockers)
7119 assert(offset == 0 || offset == 1 || offset == -1);
7120 assert(myLane != nullptr);
7121 assert(myLane->getParallelLane(offset) != nullptr || myLane->getParallelOpposite() != nullptr);
7122 const double halfCurrentLaneWidth = 0.5 * myLane->getWidth();
7123 const double halfVehWidth = 0.5 * (getWidth() + NUMERICAL_EPS);
7124 const double latPos = getLateralPositionOnLane();
7125 const double oppositeSign = getLaneChangeModel().isOpposite() ? -1 : 1;
7126 double leftLimit = halfCurrentLaneWidth - halfVehWidth - oppositeSign * latPos;
7127 double rightLimit = -halfCurrentLaneWidth + halfVehWidth - oppositeSign * latPos;
7128 double latLaneDist = 0; // minimum distance to move the vehicle fully onto the new lane
7129 if (offset == 0) {
7130 if (latPos + halfVehWidth > halfCurrentLaneWidth) {
7131 // correct overlapping left
7132 latLaneDist = halfCurrentLaneWidth - latPos - halfVehWidth;
7133 } else if (latPos - halfVehWidth < -halfCurrentLaneWidth) {
7134 // correct overlapping right
7135 latLaneDist = -halfCurrentLaneWidth - latPos + halfVehWidth;
7136 }
7137 latLaneDist *= oppositeSign;
7138 } else if (offset == -1) {
7139 latLaneDist = rightLimit - (getWidth() + NUMERICAL_EPS);
7140 } else if (offset == 1) {
7141 latLaneDist = leftLimit + (getWidth() + NUMERICAL_EPS);
7142 }
7143#ifdef DEBUG_ACTIONSTEPS
7144 if (DEBUG_COND) {
7145 std::cout << SIMTIME
7146 << " veh=" << getID()
7147 << " halfCurrentLaneWidth=" << halfCurrentLaneWidth
7148 << " halfVehWidth=" << halfVehWidth
7149 << " latPos=" << latPos
7150 << " latLaneDist=" << latLaneDist
7151 << " leftLimit=" << leftLimit
7152 << " rightLimit=" << rightLimit
7153 << "\n";
7154 }
7155#endif
7156 return latLaneDist;
7157}
7158
7159
7160double
7161MSVehicle::getLateralOverlap(double posLat, const MSLane* lane) const {
7162 return (fabs(posLat) + 0.5 * getVehicleType().getWidth()
7163 - 0.5 * lane->getWidth());
7164}
7165
7166double
7170
7171double
7175
7176
7177void
7179 for (const DriveProcessItem& dpi : lfLinks) {
7180 if (dpi.myLink != nullptr) {
7181 dpi.myLink->removeApproaching(this);
7182 }
7183 }
7184 // unregister on all shadow links
7186}
7187
7188
7189bool
7190MSVehicle::unsafeLinkAhead(const MSLane* lane, double zipperDist) const {
7191 // the following links are unsafe:
7192 // - zipper links if they are close enough and have approaching vehicles in the relevant time range
7193 // - unprioritized links if the vehicle is currently approaching a prioritzed link and unable to stop in time
7194 double seen = myLane->getLength() - getPositionOnLane();
7195 const double dist = MAX2(zipperDist, getCarFollowModel().brakeGap(getSpeed(), getCarFollowModel().getMaxDecel(), 0));
7196 if (seen < dist) {
7197 const std::vector<MSLane*>& bestLaneConts = getBestLanesContinuation(lane);
7198 int view = 1;
7199 std::vector<MSLink*>::const_iterator link = MSLane::succLinkSec(*this, view, *lane, bestLaneConts);
7200 DriveItemVector::const_iterator di = myLFLinkLanes.begin();
7201 while (!lane->isLinkEnd(link) && seen <= dist) {
7202 if ((!lane->isInternal()
7203 && (((*link)->getState() == LINKSTATE_ZIPPER && seen < (*link)->getFoeVisibilityDistance())
7204 || !(*link)->havePriority()))
7205 || (lane->isInternal() && zipperDist > 0)) {
7206 // find the drive item corresponding to this link
7207 bool found = false;
7208 while (di != myLFLinkLanes.end() && !found) {
7209 if ((*di).myLink != nullptr) {
7210 const MSLane* diPredLane = (*di).myLink->getLaneBefore();
7211 if (diPredLane != nullptr) {
7212 if (&diPredLane->getEdge() == &lane->getEdge()) {
7213 found = true;
7214 }
7215 }
7216 }
7217 if (!found) {
7218 di++;
7219 }
7220 }
7221 if (found) {
7222 const SUMOTime leaveTime = (*link)->getLeaveTime((*di).myArrivalTime, (*di).myArrivalSpeed,
7223 (*di).getLeaveSpeed(), getVehicleType().getLength());
7224 const MSLink* entry = (*link)->getCorrespondingEntryLink();
7225 //if (DEBUG_COND) {
7226 // std::cout << SIMTIME << " veh=" << getID() << " changeTo=" << Named::getIDSecure(bestLaneConts.front()) << " linkState=" << toString((*link)->getState()) << " seen=" << seen << " dist=" << dist << " zipperDist=" << zipperDist << " aT=" << STEPS2TIME((*di).myArrivalTime) << " lT=" << STEPS2TIME(leaveTime) << "\n";
7227 //}
7228 if (entry->hasApproachingFoe((*di).myArrivalTime, leaveTime, (*di).myArrivalSpeed, getCarFollowModel().getMaxDecel())) {
7229 //std::cout << SIMTIME << " veh=" << getID() << " aborting changeTo=" << Named::getIDSecure(bestLaneConts.front()) << " linkState=" << toString((*link)->getState()) << " seen=" << seen << " dist=" << dist << "\n";
7230 return true;
7231 }
7232 }
7233 // no drive item is found if the vehicle aborts its request within dist
7234 }
7235 lane = (*link)->getViaLaneOrLane();
7236 if (!lane->getEdge().isInternal()) {
7237 view++;
7238 }
7239 seen += lane->getLength();
7240 link = MSLane::succLinkSec(*this, view, *lane, bestLaneConts);
7241 }
7242 }
7243 return false;
7244}
7245
7246
7248MSVehicle::getBoundingBox(double offset) const {
7249 PositionVector centerLine;
7250 Position pos = getPosition();
7251 centerLine.push_back(pos);
7252 switch (myType->getGuiShape()) {
7259 for (MSLane* lane : myFurtherLanes) {
7260 centerLine.push_back(lane->getShape().back());
7261 }
7262 break;
7263 }
7264 default:
7265 break;
7266 }
7267 double l = getLength();
7268 Position backPos = getBackPosition();
7269 if (pos.distanceTo2D(backPos) > l + NUMERICAL_EPS) {
7270 // getBackPosition may not match the visual back in networks without internal lanes
7271 double a = getAngle() + M_PI; // angle pointing backwards
7272 backPos = pos + Position(l * cos(a), l * sin(a));
7273 }
7274 centerLine.push_back(backPos);
7275 if (offset != 0) {
7276 centerLine.extrapolate2D(offset);
7277 }
7278 PositionVector result = centerLine;
7279 result.move2side(MAX2(0.0, 0.5 * myType->getWidth() + offset));
7280 centerLine.move2side(MIN2(0.0, -0.5 * myType->getWidth() - offset));
7281 result.append(centerLine.reverse(), POSITION_EPS);
7282 return result;
7283}
7284
7285
7287MSVehicle::getBoundingPoly(double offset) const {
7288 switch (myType->getGuiShape()) {
7294 // box with corners cut off
7295 PositionVector result;
7296 PositionVector centerLine;
7297 centerLine.push_back(getPosition());
7298 centerLine.push_back(getBackPosition());
7299 if (offset != 0) {
7300 centerLine.extrapolate2D(offset);
7301 }
7302 PositionVector line1 = centerLine;
7303 PositionVector line2 = centerLine;
7304 line1.move2side(MAX2(0.0, 0.3 * myType->getWidth() + offset));
7305 line2.move2side(MAX2(0.0, 0.5 * myType->getWidth() + offset));
7306 line2.scaleRelative(0.8);
7307 result.push_back(line1[0]);
7308 result.push_back(line2[0]);
7309 result.push_back(line2[1]);
7310 result.push_back(line1[1]);
7311 line1.move2side(MIN2(0.0, -0.6 * myType->getWidth() - offset));
7312 line2.move2side(MIN2(0.0, -1.0 * myType->getWidth() - offset));
7313 result.push_back(line1[1]);
7314 result.push_back(line2[1]);
7315 result.push_back(line2[0]);
7316 result.push_back(line1[0]);
7317 return result;
7318 }
7319 default:
7320 return getBoundingBox();
7321 }
7322}
7323
7324
7325bool
7327 for (std::vector<MSLane*>::const_iterator i = myFurtherLanes.begin(); i != myFurtherLanes.end(); ++i) {
7328 if (&(*i)->getEdge() == edge) {
7329 return true;
7330 }
7331 }
7332 return false;
7333}
7334
7335
7336bool
7337MSVehicle::isBidiOn(const MSLane* lane) const {
7338 return lane->getBidiLane() != nullptr && (
7339 myLane == lane->getBidiLane()
7340 || onFurtherEdge(&lane->getBidiLane()->getEdge()));
7341}
7342
7343
7344bool
7345MSVehicle::rerouteParkingArea(const std::string& parkingAreaID, std::string& errorMsg) {
7346 // this function is based on MSTriggeredRerouter::rerouteParkingArea in order to keep
7347 // consistency in the behaviour.
7348
7349 // get vehicle params
7350 MSParkingArea* destParkArea = getNextParkingArea();
7351 const MSRoute& route = getRoute();
7352 const MSEdge* lastEdge = route.getLastEdge();
7353
7354 if (destParkArea == nullptr) {
7355 // not driving towards a parking area
7356 errorMsg = "Vehicle " + getID() + " is not driving to a parking area so it cannot be rerouted.";
7357 return false;
7358 }
7359
7360 // if the current route ends at the parking area, the new route will also and at the new area
7361 bool newDestination = (&destParkArea->getLane().getEdge() == route.getLastEdge()
7362 && getArrivalPos() >= destParkArea->getBeginLanePosition()
7363 && getArrivalPos() <= destParkArea->getEndLanePosition());
7364
7365 // retrieve info on the new parking area
7367 parkingAreaID, SumoXMLTag::SUMO_TAG_PARKING_AREA);
7368
7369 if (newParkingArea == nullptr) {
7370 errorMsg = "Parking area ID " + toString(parkingAreaID) + " not found in the network.";
7371 return false;
7372 }
7373
7374 const MSEdge* newEdge = &(newParkingArea->getLane().getEdge());
7376
7377 // Compute the route from the current edge to the parking area edge
7378 ConstMSEdgeVector edgesToPark;
7379 router.compute(getEdge(), getPositionOnLane(), newEdge, newParkingArea->getEndLanePosition(), this, MSNet::getInstance()->getCurrentTimeStep(), edgesToPark);
7380
7381 // Compute the route from the parking area edge to the end of the route
7382 ConstMSEdgeVector edgesFromPark;
7383 if (!newDestination) {
7384 router.compute(newEdge, lastEdge, this, MSNet::getInstance()->getCurrentTimeStep(), edgesFromPark);
7385 } else {
7386 // adapt plans of any riders
7387 for (MSTransportable* p : getPersons()) {
7388 p->rerouteParkingArea(getNextParkingArea(), newParkingArea);
7389 }
7390 }
7391
7392 // we have a new destination, let's replace the vehicle route
7393 ConstMSEdgeVector edges = edgesToPark;
7394 if (edgesFromPark.size() > 0) {
7395 edges.insert(edges.end(), edgesFromPark.begin() + 1, edgesFromPark.end());
7396 }
7397
7399 SUMOVehicleParameter* newParameter = new SUMOVehicleParameter();
7400 *newParameter = getParameter();
7402 newParameter->arrivalPos = newParkingArea->getEndLanePosition();
7403 replaceParameter(newParameter);
7404 }
7405 const double routeCost = router.recomputeCosts(edges, this, MSNet::getInstance()->getCurrentTimeStep());
7406 ConstMSEdgeVector prevEdges(myCurrEdge, myRoute->end());
7407 const double savings = router.recomputeCosts(prevEdges, this, MSNet::getInstance()->getCurrentTimeStep());
7408 if (replaceParkingArea(newParkingArea, errorMsg)) {
7409 const bool onInit = myLane == nullptr;
7410 replaceRouteEdges(edges, routeCost, savings, "TraCI:" + toString(SUMO_TAG_PARKING_AREA_REROUTE), onInit, false, false);
7411 } else {
7412 WRITE_WARNINGF("Vehicle '%' could not reroute to new parkingArea '%' reason=%, time=%.",
7413 getID(), newParkingArea->getID(), errorMsg, time2string(SIMSTEP));
7414 return false;
7415 }
7416 return true;
7417}
7418
7419
7420bool
7422 const int numStops = (int)myStops.size();
7423 const bool result = MSBaseVehicle::addTraciStop(stop, errorMsg);
7424 if (myLane != nullptr && numStops != (int)myStops.size()) {
7425 updateBestLanes(true);
7426 }
7427 return result;
7428}
7429
7430
7431bool
7432MSVehicle::handleCollisionStop(MSStop& stop, const double distToStop) {
7433 if (myCurrEdge == stop.edge && distToStop + POSITION_EPS < getCarFollowModel().brakeGap(myState.mySpeed, getCarFollowModel().getMaxDecel(), 0)) {
7434 if (distToStop < getCarFollowModel().brakeGap(myState.mySpeed, getCarFollowModel().getEmergencyDecel(), 0)) {
7435 double vNew = getCarFollowModel().maximumSafeStopSpeed(distToStop, getCarFollowModel().getMaxDecel(), getSpeed(), false, 0);
7436 //std::cout << SIMTIME << " veh=" << getID() << " v=" << myState.mySpeed << " distToStop=" << distToStop
7437 // << " vMinNex=" << getCarFollowModel().minNextSpeed(getSpeed(), this)
7438 // << " bg1=" << getCarFollowModel().brakeGap(myState.mySpeed)
7439 // << " bg2=" << getCarFollowModel().brakeGap(myState.mySpeed, getCarFollowModel().getEmergencyDecel(), 0)
7440 // << " vNew=" << vNew
7441 // << "\n";
7442 myState.mySpeed = MIN2(myState.mySpeed, vNew + ACCEL2SPEED(getCarFollowModel().getEmergencyDecel()));
7445 if (myState.myPos < myType->getLength()) {
7449 myAngle += M_PI;
7450 }
7451 }
7452 }
7453 }
7454 return true;
7455}
7456
7457
7458bool
7460 if (isStopped()) {
7464 }
7465 MSStop& stop = myStops.front();
7466 // we have waited long enough and fulfilled any passenger-requirements
7467 if (stop.busstop != nullptr) {
7468 // inform bus stop about leaving it
7469 stop.busstop->leaveFrom(this);
7470 }
7471 // we have waited long enough and fulfilled any container-requirements
7472 if (stop.containerstop != nullptr) {
7473 // inform container stop about leaving it
7474 stop.containerstop->leaveFrom(this);
7475 }
7476 if (stop.parkingarea != nullptr && stop.getSpeed() <= 0) {
7477 // inform parking area about leaving it
7478 stop.parkingarea->leaveFrom(this);
7479 }
7480 if (stop.chargingStation != nullptr) {
7481 // inform charging station about leaving it
7482 stop.chargingStation->leaveFrom(this);
7483 }
7484 // the current stop is no longer valid
7485 myLane->getEdge().removeWaiting(this);
7486 // MSStopOut needs to know whether the stop had a loaded 'ended' value so we call this before replacing the value
7487 if (stop.pars.started == -1) {
7488 // waypoint edge was passed in a single step
7490 }
7491 if (MSStopOut::active()) {
7492 MSStopOut::getInstance()->stopEnded(this, stop);
7493 }
7495 for (const auto& rem : myMoveReminders) {
7496 rem.first->notifyStopEnded();
7497 }
7499 myCollisionImmunity = TIME2STEPS(5); // leave the conflict area
7500 }
7502 // reset lateral position to default
7503 myState.myPosLat = 0;
7504 }
7505 const bool wasWaypoint = stop.getSpeed() > 0;
7506 myPastStops.push_back(stop.pars);
7507 myPastStops.back().routeIndex = (int)(stop.edge - myRoute->begin());
7508 myStops.pop_front();
7509 myStopDist = std::numeric_limits<double>::max();
7510 // do not count the stopping time towards gridlock time.
7511 // Other outputs use an independent counter and are not affected.
7512 myWaitingTime = 0;
7514 // maybe the next stop is on the same edge; let's rebuild best lanes
7515 updateBestLanes(true);
7516 // continue as wished...
7519 return !wasWaypoint;
7520 }
7521 return false;
7522}
7523
7524
7527 if (myInfluencer == nullptr) {
7528 myInfluencer = new Influencer();
7529 }
7530 return *myInfluencer;
7531}
7532
7537
7538
7541 return myInfluencer;
7542}
7543
7546 return myInfluencer;
7547}
7548
7549
7550double
7552 if (myInfluencer != nullptr && myInfluencer->getOriginalSpeed() >= 0) {
7553 // influencer original speed is -1 on initialization
7555 }
7556 return myState.mySpeed;
7557}
7558
7559
7560int
7562 if (hasInfluencer()) {
7564 MSNet::getInstance()->getCurrentTimeStep(),
7565 myLane->getEdge(),
7566 getLaneIndex(),
7567 state);
7568 }
7569 return state;
7570}
7571
7572
7573void
7577
7578
7579bool
7583
7584
7585bool
7589
7590
7591bool
7592MSVehicle::keepClear(const MSLink* link) const {
7593 if (link->hasFoes() && link->keepClear() /* && item.myLink->willHaveBlockedFoe()*/) {
7594 const double keepClearTime = getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_IGNORE_KEEPCLEAR_TIME, -1);
7595 //std::cout << SIMTIME << " veh=" << getID() << " keepClearTime=" << keepClearTime << " accWait=" << getAccumulatedWaitingSeconds() << " keepClear=" << (keepClearTime < 0 || getAccumulatedWaitingSeconds() < keepClearTime) << "\n";
7596 return keepClearTime < 0 || getAccumulatedWaitingSeconds() < keepClearTime;
7597 } else {
7598 return false;
7599 }
7600}
7601
7602
7603bool
7604MSVehicle::ignoreRed(const MSLink* link, bool canBrake) const {
7605 if ((myInfluencer != nullptr && !myInfluencer->getEmergencyBrakeRedLight())) {
7606 return true;
7607 }
7608 const double ignoreRedTime = getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_DRIVE_AFTER_RED_TIME, -1);
7609#ifdef DEBUG_IGNORE_RED
7610 if (DEBUG_COND) {
7611 std::cout << SIMTIME << " veh=" << getID() << " link=" << link->getViaLaneOrLane()->getID() << " state=" << toString(link->getState()) << "\n";
7612 }
7613#endif
7614 if (ignoreRedTime < 0) {
7615 const double ignoreYellowTime = getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_DRIVE_AFTER_YELLOW_TIME, 0);
7616 if (ignoreYellowTime > 0 && link->haveYellow()) {
7617 assert(link->getTLLogic() != 0);
7618 const double yellowDuration = STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep() - link->getLastStateChange());
7619 // when activating ignoreYellow behavior, vehicles will drive if they cannot brake
7620 return !canBrake || ignoreYellowTime > yellowDuration;
7621 } else {
7622 return false;
7623 }
7624 } else if (link->haveYellow()) {
7625 // always drive at yellow when ignoring red
7626 return true;
7627 } else if (link->haveRed()) {
7628 assert(link->getTLLogic() != 0);
7629 const double redDuration = STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep() - link->getLastStateChange());
7630#ifdef DEBUG_IGNORE_RED
7631 if (DEBUG_COND) {
7632 std::cout
7633 // << SIMTIME << " veh=" << getID() << " link=" << link->getViaLaneOrLane()->getID()
7634 << " ignoreRedTime=" << ignoreRedTime
7635 << " spentRed=" << redDuration
7636 << " canBrake=" << canBrake << "\n";
7637 }
7638#endif
7639 // when activating ignoreRed behavior, vehicles will always drive if they cannot brake
7640 return !canBrake || ignoreRedTime > redDuration;
7641 } else {
7642 return false;
7643 }
7644}
7645
7646bool
7649 return false;
7650 }
7651 for (const std::string& typeID : StringTokenizer(getParameter().getParameter(toString(SUMO_ATTR_CF_IGNORE_TYPES), "")).getVector()) {
7652 if (typeID == foe->getVehicleType().getID()) {
7653 return true;
7654 }
7655 }
7656 for (const std::string& id : StringTokenizer(getParameter().getParameter(toString(SUMO_ATTR_CF_IGNORE_IDS), "")).getVector()) {
7657 if (id == foe->getID()) {
7658 return true;
7659 }
7660 }
7661 return false;
7662}
7663
7664bool
7666 // either on an internal lane that was entered via minor link
7667 // or on approach to minor link below visibility distance
7668 if (myLane == nullptr) {
7669 return false;
7670 }
7671 if (myLane->getEdge().isInternal()) {
7672 return !myLane->getIncomingLanes().front().viaLink->havePriority();
7673 } else if (myLFLinkLanes.size() > 0 && myLFLinkLanes.front().myLink != nullptr) {
7674 MSLink* link = myLFLinkLanes.front().myLink;
7675 return !link->havePriority() && myLFLinkLanes.front().myDistance <= link->getFoeVisibilityDistance();
7676 }
7677 return false;
7678}
7679
7680bool
7681MSVehicle::isLeader(const MSLink* link, const MSVehicle* veh, const double gap) const {
7682 assert(link->fromInternalLane());
7683 if (veh == nullptr) {
7684 return false;
7685 }
7686 if (!myLane->isInternal() || myLane->getEdge().getToJunction() != link->getJunction()) {
7687 // if this vehicle is not yet on the junction, every vehicle is a leader
7688 return true;
7689 }
7690 if (veh->getLaneChangeModel().hasBlueLight()) {
7691 // blue light device automatically gets right of way
7692 return true;
7693 }
7694 const MSLane* foeLane = veh->getLane();
7695 if (foeLane->isInternal()) {
7696 if (foeLane->getEdge().getFromJunction() == link->getJunction()) {
7698 SUMOTime foeET = veh->myJunctionEntryTime;
7699 // check relationship between link and foeLane
7701 // we are entering the junction from the same lane
7703 foeET = veh->myJunctionEntryTimeNeverYield;
7706 }
7707 } else {
7708 const MSLink* foeLink = foeLane->getIncomingLanes()[0].viaLink;
7709 const MSJunctionLogic* logic = link->getJunction()->getLogic();
7710 assert(logic != nullptr);
7711 // determine who has right of way
7712 bool response; // ego response to foe
7713 bool response2; // foe response to ego
7714 // attempt 1: tlLinkState
7715 const MSLink* entry = link->getCorrespondingEntryLink();
7716 const MSLink* foeEntry = foeLink->getCorrespondingEntryLink();
7717 if (entry->haveRed() || foeEntry->haveRed()) {
7718 // ensure that vehicles which are stuck on the intersection may exit
7719 if (!foeEntry->haveRed() && veh->getSpeed() > SUMO_const_haltingSpeed && gap < 0) {
7720 // foe might be oncoming, don't drive unless foe can still brake safely
7721 const double foeNextSpeed = veh->getSpeed() + ACCEL2SPEED(veh->getCarFollowModel().getMaxAccel());
7722 const double foeBrakeGap = veh->getCarFollowModel().brakeGap(
7723 foeNextSpeed, veh->getCarFollowModel().getMaxDecel(), veh->getCarFollowModel().getHeadwayTime());
7724 // the minGap was subtracted from gap in MSLink::getLeaderInfo (enlarging the negative gap)
7725 // so the -2* makes it point in the right direction
7726 const double foeGap = -gap - veh->getLength() - 2 * getVehicleType().getMinGap();
7727#ifdef DEBUG_PLAN_MOVE_LEADERINFO
7728 if (DEBUG_COND) {
7729 std::cout << " foeGap=" << foeGap << " foeBGap=" << foeBrakeGap << "\n";
7730
7731 }
7732#endif
7733 if (foeGap < foeBrakeGap) {
7734 response = true;
7735 response2 = false;
7736 } else {
7737 response = false;
7738 response2 = true;
7739 }
7740 } else {
7741 // let conflict entry time decide
7742 response = true;
7743 response2 = true;
7744 }
7745 } else if (entry->havePriority() != foeEntry->havePriority()) {
7746 response = !entry->havePriority();
7747 response2 = !foeEntry->havePriority();
7748 } else if (entry->haveYellow() && foeEntry->haveYellow()) {
7749 // let the faster vehicle keep moving
7750 response = veh->getSpeed() >= getSpeed();
7751 response2 = getSpeed() >= veh->getSpeed();
7752 } else {
7753 // fallback if pedestrian crossings are involved
7754 response = logic->getResponseFor(link->getIndex()).test(foeLink->getIndex());
7755 response2 = logic->getResponseFor(foeLink->getIndex()).test(link->getIndex());
7756 }
7757#ifdef DEBUG_PLAN_MOVE_LEADERINFO
7758 if (DEBUG_COND) {
7759 std::cout << SIMTIME
7760 << " foeLane=" << foeLane->getID()
7761 << " foeLink=" << foeLink->getViaLaneOrLane()->getID()
7762 << " linkIndex=" << link->getIndex()
7763 << " foeLinkIndex=" << foeLink->getIndex()
7764 << " entryState=" << toString(entry->getState())
7765 << " entryState2=" << toString(foeEntry->getState())
7766 << " response=" << response
7767 << " response2=" << response2
7768 << "\n";
7769 }
7770#endif
7771 if (!response) {
7772 // if we have right of way over the foe, entryTime does not matter
7773 foeET = veh->myJunctionConflictEntryTime;
7774 egoET = myJunctionEntryTime;
7775 } else if (response && response2) {
7776 // in a mutual conflict scenario, use entry time to avoid deadlock
7777 foeET = veh->myJunctionConflictEntryTime;
7779 }
7780 }
7781 if (egoET == foeET) {
7782 // try to use speed as tie braker
7783 if (getSpeed() == veh->getSpeed()) {
7784 // use ID as tie braker
7785#ifdef DEBUG_PLAN_MOVE_LEADERINFO
7786 if (DEBUG_COND) {
7787 std::cout << SIMTIME << " veh=" << getID() << " equal ET " << egoET << " with foe " << veh->getID()
7788 << " foeIsLeaderByID=" << (getID() < veh->getID()) << "\n";
7789 }
7790#endif
7791 return getID() < veh->getID();
7792 } else {
7793#ifdef DEBUG_PLAN_MOVE_LEADERINFO
7794 if (DEBUG_COND) {
7795 std::cout << SIMTIME << " veh=" << getID() << " equal ET " << egoET << " with foe " << veh->getID()
7796 << " foeIsLeaderBySpeed=" << (getSpeed() < veh->getSpeed())
7797 << " v=" << getSpeed() << " foeV=" << veh->getSpeed()
7798 << "\n";
7799 }
7800#endif
7801 return getSpeed() < veh->getSpeed();
7802 }
7803 } else {
7804 // leader was on the junction first
7805#ifdef DEBUG_PLAN_MOVE_LEADERINFO
7806 if (DEBUG_COND) {
7807 std::cout << SIMTIME << " veh=" << getID() << " egoET " << egoET << " with foe " << veh->getID()
7808 << " foeET=" << foeET << " isLeader=" << (egoET > foeET) << "\n";
7809 }
7810#endif
7811 return egoET > foeET;
7812 }
7813 } else {
7814 // vehicle can only be partially on the junction. Must be a leader
7815 return true;
7816 }
7817 } else {
7818 // vehicle can only be partially on the junction. Must be a leader
7819 return true;
7820 }
7821}
7822
7823void
7826 // here starts the vehicle internal part (see loading)
7827 std::vector<std::string> internals;
7828 internals.push_back(toString(myParameter->parametersSet));
7829 internals.push_back(toString(myDeparture));
7830 internals.push_back(toString(distance(myRoute->begin(), myCurrEdge)));
7831 internals.push_back(toString(myDepartPos));
7832 internals.push_back(toString(myWaitingTime));
7833 internals.push_back(toString(myTimeLoss));
7834 internals.push_back(toString(myLastActionTime));
7835 internals.push_back(toString(isStopped()));
7836 internals.push_back(toString(isStopped() ? myStops.front().duration : 0));
7837 internals.push_back(toString(myPastStops.size()));
7838 out.writeAttr(SUMO_ATTR_STATE, internals);
7840 out.writeAttr(SUMO_ATTR_SPEED, std::vector<double> { myState.mySpeed, myState.myPreviousSpeed });
7844 if (isStopped() && myStops.front().entryPos != getPositionOnLane()) {
7845 out.writeAttr(SUMO_ATTR_ENTRYPOS, myStops.front().entryPos);
7846 }
7848 // save past stops
7850 stop.write(out, false);
7851 // do not write started and ended twice
7852 if ((stop.parametersSet & STOP_STARTED_SET) == 0) {
7853 out.writeAttr(SUMO_ATTR_STARTED, time2string(stop.started));
7854 }
7855 if ((stop.parametersSet & STOP_ENDED_SET) == 0) {
7856 out.writeAttr(SUMO_ATTR_ENDED, time2string(stop.ended));
7857 }
7858 stop.writeParams(out);
7859 out.closeTag();
7860 }
7861 // save upcoming stops
7862 for (MSStop& stop : myStops) {
7863 stop.write(out);
7864 }
7865 // save parameters and device states
7867 for (MSVehicleDevice* const dev : myDevices) {
7868 dev->saveState(out);
7869 }
7870 if (myCFVariables != nullptr) {
7872 }
7873 out.closeTag();
7874}
7875
7876void
7878 if (!attrs.hasAttribute(SUMO_ATTR_POSITION)) {
7879 throw ProcessError(TL("Error: Invalid vehicles in state (may be a meso state)!"));
7880 }
7881 bool ok;
7882 int routeOffset;
7883 bool stopped;
7884 SUMOTime stopDuration;
7885 int pastStops;
7886
7887 std::istringstream bis(attrs.getString(SUMO_ATTR_STATE));
7888 bis >> myParameter->parametersSet;
7889 bis >> myDeparture;
7890 bis >> routeOffset;
7891 bis >> myDepartPos;
7892 bis >> myWaitingTime;
7893 bis >> myTimeLoss;
7894 bis >> myLastActionTime;
7895 bis >> stopped;
7896 bis >> stopDuration;
7897 bis >> pastStops;
7898
7900 myArrivalPos = attrs.get<double>(SUMO_ATTR_ARRIVALPOS_RANDOMIZED, getID().c_str(), ok);
7901 }
7902 // load stops
7903 myStops.clear();
7905
7906 if (hasDeparted()) {
7907 myCurrEdge = myRoute->begin() + routeOffset;
7908 myDeparture -= offset;
7909 // fix stops
7910 while (pastStops > 0) {
7911 SUMOVehicleParameter::Stop& pars = const_cast<SUMOVehicleParameter::Stop&>(myStops.front().pars);
7912 // assumed these attributes were only added to restore vehroute-output.exit-times
7914 pars.parametersSet &= ~STOP_ENDED_SET;
7915 }
7917 pars.parametersSet &= ~STOP_STARTED_SET;
7918 }
7919 for (const auto& rem : myMoveReminders) {
7920 rem.first->notifyStopEnded();
7921 }
7922 myPastStops.push_back(myStops.front().pars);
7923 myPastStops.back().routeIndex = (int)(myStops.front().edge - myRoute->begin());
7924 myStops.pop_front();
7925 pastStops--;
7926 }
7927 // see MSBaseVehicle constructor
7930 }
7931 // a (tentative lane is needed for calling hasArrivedInternal
7932 myLane = (*myCurrEdge)->getLanes()[0];
7933 }
7936 WRITE_WARNINGF(TL("Action steps are out of sync for loaded vehicle '%'."), getID());
7937 }
7938 std::istringstream pis(attrs.getString(SUMO_ATTR_POSITION));
7940 std::istringstream sis(attrs.getString(SUMO_ATTR_SPEED));
7946 std::istringstream dis(attrs.getString(SUMO_ATTR_DISTANCE));
7947 dis >> myOdometer >> myNumberReroutes;
7949 if (stopped) {
7950 double realPos = getPositionOnLane();
7951 double entryPos = attrs.getOpt<double>(SUMO_ATTR_ENTRYPOS, getID().c_str(), ok, realPos);
7952 myStops.front().startedFromState = true;
7953 if (entryPos != realPos) {
7954 myStops.front().entryPos = entryPos;
7955 }
7956 myLane = const_cast<MSLane*>(myStops.front().lane);
7957 myStopDist = 0;
7958 myState.myPos = entryPos; // fake position for replication stop entry which happened before the position was updated
7960 myState.myPos = realPos; // reset fake position
7961 if (myStops.front().pars.parking != ParkingType::ONROAD) {
7962 // processNextStop is called again during MSVehicleTransfer::loadState
7963 stopDuration += getActionStepLength();
7964 }
7965 myStops.front().duration = stopDuration;
7967 SUMOVehicleParameter::Stop& pars = const_cast<SUMOVehicleParameter::Stop&>(myStops.front().pars);
7968 pars.parametersSet &= ~STOP_STARTED_SET;
7969 }
7970 }
7972 // no need to reset myCachedPosition here since state loading happens directly after creation
7973}
7974
7975void
7977 SUMOTime arrivalTime, double arrivalSpeed,
7978 double arrivalSpeedBraking,
7979 double dist, double leaveSpeed) {
7980 // ensure that approach information is reset on the next call to setApproachingForAllLinks
7981 myLFLinkLanes.push_back(DriveProcessItem(link, 0, 0, setRequest,
7982 arrivalTime, arrivalSpeed, arrivalSpeedBraking, dist, leaveSpeed));
7983
7984}
7985
7986
7987std::shared_ptr<MSSimpleDriverState>
7991
7992
7993double
7995 return myFrictionDevice == nullptr ? 1. : myFrictionDevice->getMeasuredFriction();
7996}
7997
7998
7999void
8000MSVehicle::setPreviousSpeed(double prevSpeed, double prevAcceleration) {
8001 myState.mySpeed = MAX2(0., prevSpeed);
8002 // also retcon acceleration
8003 if (prevAcceleration != std::numeric_limits<double>::min()) {
8004 myAcceleration = prevAcceleration;
8005 } else {
8007 }
8008}
8009
8010
8011double
8013 //return MAX2(-myAcceleration, getCarFollowModel().getApparentDecel());
8015}
8016
8017/****************************************************************************/
8018bool
8022
8023/* -------------------------------------------------------------------------
8024 * methods of MSVehicle::manoeuvre
8025 * ----------------------------------------------------------------------- */
8026
8027MSVehicle::Manoeuvre::Manoeuvre() : myManoeuvreStop(""), myManoeuvreStartTime(0), myManoeuvreCompleteTime(0), myManoeuvreType(MSVehicle::MANOEUVRE_NONE), myGUIIncrement(0) {}
8028
8029
8031 myManoeuvreStop = manoeuvre.myManoeuvreStop;
8032 myManoeuvreStartTime = manoeuvre.myManoeuvreStartTime;
8033 myManoeuvreCompleteTime = manoeuvre.myManoeuvreCompleteTime;
8034 myManoeuvreType = manoeuvre.myManoeuvreType;
8035 myGUIIncrement = manoeuvre.myGUIIncrement;
8036}
8037
8038
8041 myManoeuvreStop = manoeuvre.myManoeuvreStop;
8042 myManoeuvreStartTime = manoeuvre.myManoeuvreStartTime;
8043 myManoeuvreCompleteTime = manoeuvre.myManoeuvreCompleteTime;
8044 myManoeuvreType = manoeuvre.myManoeuvreType;
8045 myGUIIncrement = manoeuvre.myGUIIncrement;
8046 return *this;
8047}
8048
8049
8050bool
8052 return (myManoeuvreStop != manoeuvre.myManoeuvreStop ||
8053 myManoeuvreStartTime != manoeuvre.myManoeuvreStartTime ||
8054 myManoeuvreCompleteTime != manoeuvre.myManoeuvreCompleteTime ||
8055 myManoeuvreType != manoeuvre.myManoeuvreType ||
8056 myGUIIncrement != manoeuvre.myGUIIncrement
8057 );
8058}
8059
8060
8061double
8063 return (myGUIIncrement);
8064}
8065
8066
8069 return (myManoeuvreType);
8070}
8071
8072
8077
8078
8079void
8083
8084
8085void
8087 myManoeuvreType = mType;
8088}
8089
8090
8091bool
8093 if (!veh->hasStops()) {
8094 return false; // should never happen - checked before call
8095 }
8096
8097 const SUMOTime currentTime = MSNet::getInstance()->getCurrentTimeStep();
8098 const MSStop& stop = veh->getNextStop();
8099
8100 int manoeuverAngle = stop.parkingarea->getLastFreeLotAngle();
8101 double GUIAngle = stop.parkingarea->getLastFreeLotGUIAngle();
8102 if (abs(GUIAngle) < 0.1) {
8103 GUIAngle = -0.1; // Wiggle vehicle on parallel entry
8104 }
8105 myManoeuvreVehicleID = veh->getID();
8106 myManoeuvreStop = stop.parkingarea->getID();
8107 myManoeuvreType = MSVehicle::MANOEUVRE_ENTRY;
8108 myManoeuvreStartTime = currentTime;
8109 myManoeuvreCompleteTime = currentTime + veh->myType->getEntryManoeuvreTime(manoeuverAngle);
8110 myGUIIncrement = GUIAngle / (STEPS2TIME(myManoeuvreCompleteTime - myManoeuvreStartTime) / TS);
8111
8112#ifdef DEBUG_STOPS
8113 if (veh->isSelected()) {
8114 std::cout << "ENTRY manoeuvre start: vehicle=" << veh->getID() << " Manoeuvre Angle=" << manoeuverAngle << " Rotation angle=" << RAD2DEG(GUIAngle) << " Road Angle" << RAD2DEG(veh->getAngle()) << " increment=" << RAD2DEG(myGUIIncrement) << " currentTime=" << currentTime <<
8115 " endTime=" << myManoeuvreCompleteTime << " manoeuvre time=" << myManoeuvreCompleteTime - currentTime << " parkArea=" << myManoeuvreStop << std::endl;
8116 }
8117#endif
8118
8119 return (true);
8120}
8121
8122
8123bool
8125 // At the moment we only want to set for parking areas
8126 if (!veh->hasStops()) {
8127 return true;
8128 }
8129 if (veh->getNextStop().parkingarea == nullptr) {
8130 return true;
8131 }
8132
8133 if (myManoeuvreType != MSVehicle::MANOEUVRE_NONE) {
8134 return (false);
8135 }
8136
8137 const SUMOTime currentTime = MSNet::getInstance()->getCurrentTimeStep();
8138
8139 int manoeuverAngle = veh->getCurrentParkingArea()->getManoeuverAngle(*veh);
8140 double GUIAngle = veh->getCurrentParkingArea()->getGUIAngle(*veh);
8141 if (abs(GUIAngle) < 0.1) {
8142 GUIAngle = 0.1; // Wiggle vehicle on parallel exit
8143 }
8144
8145 myManoeuvreVehicleID = veh->getID();
8146 myManoeuvreStop = veh->getCurrentParkingArea()->getID();
8147 myManoeuvreType = MSVehicle::MANOEUVRE_EXIT;
8148 myManoeuvreStartTime = currentTime;
8149 myManoeuvreCompleteTime = currentTime + veh->myType->getExitManoeuvreTime(manoeuverAngle);
8150 myGUIIncrement = -GUIAngle / (STEPS2TIME(myManoeuvreCompleteTime - myManoeuvreStartTime) / TS);
8151 if (veh->remainingStopDuration() > 0) {
8152 myManoeuvreCompleteTime += veh->remainingStopDuration();
8153 }
8154
8155#ifdef DEBUG_STOPS
8156 if (veh->isSelected()) {
8157 std::cout << "EXIT manoeuvre start: vehicle=" << veh->getID() << " Manoeuvre Angle=" << manoeuverAngle << " increment=" << RAD2DEG(myGUIIncrement) << " currentTime=" << currentTime
8158 << " endTime=" << myManoeuvreCompleteTime << " manoeuvre time=" << myManoeuvreCompleteTime - currentTime << " parkArea=" << myManoeuvreStop << std::endl;
8159 }
8160#endif
8161
8162 return (true);
8163}
8164
8165
8166bool
8168 // At the moment we only want to consider parking areas - need to check because we could be setting up a manoeuvre
8169 if (!veh->hasStops()) {
8170 return (true);
8171 }
8172 MSStop* currentStop = &veh->myStops.front();
8173 if (currentStop->parkingarea == nullptr) {
8174 return true;
8175 } else if (currentStop->parkingarea->getID() != myManoeuvreStop || MSVehicle::MANOEUVRE_ENTRY != myManoeuvreType) {
8176 if (configureEntryManoeuvre(veh)) {
8178 return (false);
8179 } else { // cannot configure entry so stop trying
8180 return true;
8181 }
8182 } else if (MSNet::getInstance()->getCurrentTimeStep() < myManoeuvreCompleteTime) {
8183 return false;
8184 } else { // manoeuvre complete
8185 myManoeuvreType = MSVehicle::MANOEUVRE_NONE;
8186 return true;
8187 }
8188}
8189
8190
8191bool
8193 if (checkType != myManoeuvreType) {
8194 return true; // we're not maneuvering / wrong manoeuvre
8195 }
8196
8197 if (MSNet::getInstance()->getCurrentTimeStep() < myManoeuvreCompleteTime) {
8198 return false;
8199 } else {
8200 return true;
8201 }
8202}
8203
8204
8205bool
8207 return (MSNet::getInstance()->getCurrentTimeStep() >= myManoeuvreCompleteTime);
8208}
8209
8210
8211bool
8215
8216
8217std::pair<double, double>
8219 if (hasStops()) {
8220 MSLane* lane = myLane;
8221 if (lane == nullptr) {
8222 // not in network
8223 lane = getEdge()->getLanes()[0];
8224 }
8225 const MSStop& stop = myStops.front();
8226 auto it = myCurrEdge + 1;
8227 // drive to end of current edge
8228 double dist = (lane->getLength() - getPositionOnLane());
8229 double travelTime = lane->getEdge().getMinimumTravelTime(this) * dist / lane->getLength();
8230 // drive until stop edge
8231 while (it != myRoute->end() && it < stop.edge) {
8232 travelTime += (*it)->getMinimumTravelTime(this);
8233 dist += (*it)->getLength();
8234 it++;
8235 }
8236 // drive up to the stop position
8237 const double stopEdgeDist = stop.pars.endPos - (lane == stop.lane ? lane->getLength() : 0);
8238 dist += stopEdgeDist;
8239 travelTime += stop.lane->getEdge().getMinimumTravelTime(this) * (stopEdgeDist / stop.lane->getLength());
8240 // estimate time loss due to acceleration and deceleration
8241 // maximum speed is limited by available distance:
8242 const double a = getCarFollowModel().getMaxAccel();
8243 const double b = getCarFollowModel().getMaxDecel();
8244 const double c = getSpeed();
8245 const double d = dist;
8246 const double len = getVehicleType().getLength();
8247 const double vs = MIN2(MAX2(stop.getSpeed(), 0.0), stop.lane->getVehicleMaxSpeed(this));
8248 // distAccel = (v - c)^2 / (2a)
8249 // distDecel = (v + vs)*(v - vs) / 2b = (v^2 - vs^2) / (2b)
8250 // distAccel + distDecel < d
8251 const double maxVD = MAX2(c, ((sqrt(MAX2(0.0, pow(2 * c * b, 2) + (4 * ((b * ((a * (2 * d * (b + a) + (vs * vs) - (c * c))) - (b * (c * c))))
8252 + pow((a * vs), 2))))) * 0.5) + (c * b)) / (b + a));
8253 it = myCurrEdge;
8254 double v0 = c;
8255 bool v0Stable = getAcceleration() == 0 && v0 > 0;
8256 double timeLossAccel = 0;
8257 double timeLossDecel = 0;
8258 double timeLossLength = 0;
8259 while (it != myRoute->end() && it <= stop.edge) {
8260 double v = MIN2(maxVD, (*it)->getVehicleMaxSpeed(this));
8261 double edgeLength = (it == stop.edge ? stop.pars.endPos : (*it)->getLength()) - (it == myCurrEdge ? getPositionOnLane() : 0);
8262 if (edgeLength <= len && v0Stable && v0 < v) {
8263 const double lengthDist = MIN2(len, edgeLength);
8264 const double dTL = lengthDist / v0 - lengthDist / v;
8265 //std::cout << " e=" << (*it)->getID() << " v0=" << v0 << " v=" << v << " el=" << edgeLength << " lDist=" << lengthDist << " newTLL=" << dTL<< "\n";
8266 timeLossLength += dTL;
8267 }
8268 if (edgeLength > len) {
8269 const double dv = v - v0;
8270 if (dv > 0) {
8271 // timeLossAccel = timeAccel - timeMaxspeed = dv / a - distAccel / v
8272 const double dTA = dv / a - dv * (v + v0) / (2 * a * v);
8273 //std::cout << " e=" << (*it)->getID() << " v0=" << v0 << " v=" << v << " newTLA=" << dTA << "\n";
8274 timeLossAccel += dTA;
8275 // time loss from vehicle length
8276 } else if (dv < 0) {
8277 // timeLossDecel = timeDecel - timeMaxspeed = dv / b - distDecel / v
8278 const double dTD = -dv / b + dv * (v + v0) / (2 * b * v0);
8279 //std::cout << " e=" << (*it)->getID() << " v0=" << v0 << " v=" << v << " newTLD=" << dTD << "\n";
8280 timeLossDecel += dTD;
8281 }
8282 v0 = v;
8283 v0Stable = true;
8284 }
8285 it++;
8286 }
8287 // final deceleration to stop (may also be acceleration or deceleration to waypoint speed)
8288 double v = vs;
8289 const double dv = v - v0;
8290 if (dv > 0) {
8291 // timeLossAccel = timeAccel - timeMaxspeed = dv / a - distAccel / v
8292 const double dTA = dv / a - dv * (v + v0) / (2 * a * v);
8293 //std::cout << " final e=" << (*it)->getID() << " v0=" << v0 << " v=" << v << " newTLA=" << dTA << "\n";
8294 timeLossAccel += dTA;
8295 // time loss from vehicle length
8296 } else if (dv < 0) {
8297 // timeLossDecel = timeDecel - timeMaxspeed = dv / b - distDecel / v
8298 const double dTD = -dv / b + dv * (v + v0) / (2 * b * v0);
8299 //std::cout << " final e=" << (*it)->getID() << " v0=" << v0 << " v=" << v << " newTLD=" << dTD << "\n";
8300 timeLossDecel += dTD;
8301 }
8302 const double result = travelTime + timeLossAccel + timeLossDecel + timeLossLength;
8303 //std::cout << SIMTIME << " v=" << c << " a=" << a << " b=" << b << " maxVD=" << maxVD << " tt=" << travelTime
8304 // << " ta=" << timeLossAccel << " td=" << timeLossDecel << " tl=" << timeLossLength << " res=" << result << "\n";
8305 return {MAX2(0.0, result), dist};
8306 } else {
8308 }
8309}
8310
8311
8312double
8314 if (hasStops() && myStops.front().pars.until >= 0) {
8315 const MSStop& stop = myStops.front();
8316 SUMOTime estimatedDepart = MSNet::getInstance()->getCurrentTimeStep() - DELTA_T;
8317 if (stop.reached) {
8318 return STEPS2TIME(estimatedDepart + stop.duration - stop.pars.until);
8319 }
8320 if (stop.pars.duration > 0) {
8321 estimatedDepart += stop.pars.duration;
8322 }
8323 estimatedDepart += TIME2STEPS(estimateTimeToNextStop().first);
8324 const double result = MAX2(0.0, STEPS2TIME(estimatedDepart - stop.pars.until));
8325 return result;
8326 } else {
8327 // vehicles cannot drive before 'until' so stop delay can never be
8328 // negative and we can use -1 to signal "undefined"
8329 return -1;
8330 }
8331}
8332
8333
8334double
8336 if (hasStops() && myStops.front().pars.arrival >= 0) {
8337 const MSStop& stop = myStops.front();
8338 if (stop.reached) {
8339 return STEPS2TIME(stop.pars.started - stop.pars.arrival);
8340 } else {
8341 return STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep()) + estimateTimeToNextStop().first - STEPS2TIME(stop.pars.arrival);
8342 }
8343 } else {
8344 // vehicles can arrive earlier than planned so arrival delay can be negative
8345 return INVALID_DOUBLE;
8346 }
8347}
8348
8349
8350const MSEdge*
8352 return myLane != nullptr ? &myLane->getEdge() : getEdge();
8353}
8354
8355
8356const MSEdge*
8358 if (myLane == nullptr || (myCurrEdge + 1) == myRoute->end()) {
8359 return nullptr;
8360 }
8361 if (myLane->isInternal()) {
8363 } else {
8364 const MSEdge* nextNormal = succEdge(1);
8365 const MSEdge* nextInternal = myLane->getEdge().getInternalFollowingEdge(nextNormal, getVClass());
8366 return nextInternal ? nextInternal : nextNormal;
8367 }
8368}
8369
8370
8371const MSLane*
8372MSVehicle::getPreviousLane(const MSLane* current, int& furtherIndex) const {
8373 if (furtherIndex < (int)myFurtherLanes.size()) {
8374 return myFurtherLanes[furtherIndex++];
8375 } else {
8376 // try to use route information
8377 int routeIndex = getRoutePosition();
8378 bool resultInternal;
8379 if (MSGlobals::gUsingInternalLanes && MSNet::getInstance()->hasInternalLinks()) {
8380 if (myLane->isInternal()) {
8381 if (furtherIndex % 2 == 0) {
8382 routeIndex -= (furtherIndex + 0) / 2;
8383 resultInternal = false;
8384 } else {
8385 routeIndex -= (furtherIndex + 1) / 2;
8386 resultInternal = false;
8387 }
8388 } else {
8389 if (furtherIndex % 2 != 0) {
8390 routeIndex -= (furtherIndex + 1) / 2;
8391 resultInternal = false;
8392 } else {
8393 routeIndex -= (furtherIndex + 2) / 2;
8394 resultInternal = true;
8395 }
8396 }
8397 } else {
8398 routeIndex -= furtherIndex;
8399 resultInternal = false;
8400 }
8401 furtherIndex++;
8402 if (routeIndex >= 0) {
8403 if (resultInternal) {
8404 const MSEdge* prevNormal = myRoute->getEdges()[routeIndex];
8405 for (MSLane* cand : prevNormal->getLanes()) {
8406 for (MSLink* link : cand->getLinkCont()) {
8407 if (link->getLane() == current) {
8408 if (link->getViaLane() != nullptr) {
8409 return link->getViaLane();
8410 } else {
8411 return const_cast<MSLane*>(link->getLaneBefore());
8412 }
8413 }
8414 }
8415 }
8416 } else {
8417 return myRoute->getEdges()[routeIndex]->getLanes()[0];
8418 }
8419 }
8420 }
8421 return current;
8422}
8423
8426 // this vehicle currently has the highest priority on the allway_stop
8427 return link == myHaveStoppedFor ? SUMOTime_MAX : getWaitingTime();
8428}
8429
8430
8431void
8433 bool diverged = false;
8434 const ConstMSEdgeVector& route = myRoute->getEdges();
8435 int ri = getRoutePosition();
8436 for (const DriveProcessItem& dpi : myLFLinkLanes) {
8437 if (dpi.myLink != nullptr) {
8438 if (!diverged) {
8439 const MSEdge* next = route[ri + 1];
8440 if (&dpi.myLink->getLane()->getEdge() != next) {
8441 diverged = true;
8442 } else {
8443 if (dpi.myLink->getViaLane() == nullptr) {
8444 ri++;
8445 }
8446 }
8447 }
8448 if (diverged) {
8449 dpi.myLink->removeApproaching(this);
8450 }
8451 }
8452 }
8453}
8454
8455
8456bool
8460
8461/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define RAD2DEG(x)
Definition GeomHelper.h:36
#define DEBUG_COND2(obj)
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:74
std::vector< MSEdge * > MSEdgeVector
Definition MSEdge.h:73
std::pair< const MSVehicle *, double > CLeaderDist
std::pair< const MSPerson *, double > PersonDist
Definition MSPModel.h:41
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition MSRoute.h:57
#define NUMERICAL_EPS_SPEED
#define STOPPING_PLACE_OFFSET
#define JUNCTION_BLOCKAGE_TIME
#define DIST_TO_STOPLINE_EXPECT_PRIORITY
#define CRLL_LOOK_AHEAD
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:287
#define WRITE_ERROR(msg)
Definition MsgHandler.h:295
#define TL(string)
Definition MsgHandler.h:304
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
SUMOTime DELTA_T
Definition SUMOTime.cpp:38
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
#define STEPS2TIME(x)
Definition SUMOTime.h:58
#define SPEED2DIST(x)
Definition SUMOTime.h:48
#define SIMSTEP
Definition SUMOTime.h:64
#define ACCEL2SPEED(x)
Definition SUMOTime.h:54
#define SUMOTime_MAX
Definition SUMOTime.h:34
#define TS
Definition SUMOTime.h:45
#define SIMTIME
Definition SUMOTime.h:65
#define TIME2STEPS(x)
Definition SUMOTime.h:60
#define DIST2SPEED(x)
Definition SUMOTime.h:50
#define SPEED2ACCEL(x)
Definition SUMOTime.h:56
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permissions is a (exclusive) railway edge.
@ RAIL_CARGO
render as a cargo train
@ RAIL
render as a rail
@ PASSENGER_VAN
render as a van
@ PASSENGER
render as a passenger vehicle
@ RAIL_CAR
render as a (city) rail without locomotive
@ PASSENGER_HATCHBACK
render as a hatchback passenger vehicle ("Fliessheck")
@ BUS_FLEXIBLE
render as a flexible city bus
@ TRUCK_1TRAILER
render as a transport vehicle with one trailer
@ PASSENGER_SEDAN
render as a sedan passenger vehicle ("Stufenheck")
@ PASSENGER_WAGON
render as a wagon passenger vehicle ("Combi")
@ TRUCK_SEMITRAILER
render as a semi-trailer transport vehicle ("Sattelschlepper")
@ SVC_RAIL_CLASSES
classes which drive on tracks
@ SVC_EMERGENCY
public emergency vehicles
const long long int VEHPARS_FORCE_REROUTE
@ GIVEN
The lane is given.
@ DEFAULT
No information given; use default.
@ GIVEN
The speed is given.
@ SPLIT_FRONT
depart position for a split vehicle is in front of the continuing vehicle
const long long int VEHPARS_CFMODEL_PARAMS_SET
@ GIVEN
The arrival lane is given.
@ GIVEN
The speed is given.
const int STOP_ENDED_SET
@ GIVEN
The arrival position is given.
@ DEFAULT
No information given; use default.
const int STOP_STARTED_SET
@ SUMO_TAG_PARKING_AREA_REROUTE
entry for an alternative parking zone
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_OVERHEAD_WIRE_SEGMENT
An overhead wire segment.
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
@ PARTLEFT
The link is a partial left direction.
@ RIGHT
The link is a (hard) right direction.
@ TURN
The link is a 180 degree turn.
@ LEFT
The link is a (hard) left direction.
@ STRAIGHT
The link is a straight direction.
@ TURN_LEFTHAND
The link is a 180 degree turn (left-hand network)
@ PARTRIGHT
The link is a partial right direction.
@ NODIR
The link has no direction (is a dead end link)
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
@ LINKSTATE_ALLWAY_STOP
This is an uncontrolled, all-way stop link.
@ LINKSTATE_EQUAL
This is an uncontrolled, right-before-left link.
@ LINKSTATE_ZIPPER
This is an uncontrolled, zipper-merge link.
@ LCA_KEEPRIGHT
The action is due to the default of keeping right "Rechtsfahrgebot".
@ 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_SUBLANE
used by the sublane model
@ LCA_WANTS_LANECHANGE_OR_STAY
lane can change or stay
@ LCA_COOPERATIVE
The action is done to help someone else.
@ LCA_OVERLAPPING
The vehicle is blocked being overlapping.
@ LCA_LEFT
Wants go to the left.
@ LCA_STRATEGIC
The action is needed to follow the route (navigational lc)
@ LCA_TRACI
The action is due to a TraCI request.
@ LCA_SPEEDGAIN
The action is due to the wish to be faster (tactical lc)
@ LCA_RIGHT
Wants go to the right.
@ SUMO_ATTR_JM_STOPLINE_GAP_MINOR
@ SUMO_ATTR_JM_STOPLINE_CROSSING_GAP
@ SUMO_ATTR_JM_IGNORE_KEEPCLEAR_TIME
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_STARTED
@ SUMO_ATTR_MAXIMUMPOWER
Maximum Power.
@ SUMO_ATTR_WAITINGTIME
@ SUMO_ATTR_CF_IGNORE_IDS
@ SUMO_ATTR_JM_STOPLINE_GAP
@ SUMO_ATTR_POSITION_LAT
@ SUMO_ATTR_JM_DRIVE_AFTER_RED_TIME
@ SUMO_ATTR_JM_DRIVE_AFTER_YELLOW_TIME
@ SUMO_ATTR_ENDED
@ SUMO_ATTR_LCA_CONTRIGHT
@ SUMO_ATTR_ANGLE
@ SUMO_ATTR_DISTANCE
@ SUMO_ATTR_CF_IGNORE_TYPES
@ SUMO_ATTR_ARRIVALPOS_RANDOMIZED
@ SUMO_ATTR_ENTRYPOS
@ SUMO_ATTR_FLEX_ARRIVAL
@ SUMO_ATTR_JM_IGNORE_JUNCTION_FOE_PROB
@ SUMO_ATTR_POSITION
@ SUMO_ATTR_STATE
The state of a link.
@ SUMO_ATTR_JM_DRIVE_RED_SPEED
int gPrecision
the precision for floating point outputs
Definition StdDefs.cpp:27
bool gDebugFlag1
global utility flags for debugging
Definition StdDefs.cpp:44
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:68
const double SUMO_const_laneWidth
Definition StdDefs.h:52
T MIN3(T a, T b, T c)
Definition StdDefs.h:93
T MIN2(T a, T b)
Definition StdDefs.h:80
const double SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
Definition StdDefs.h:62
T MAX2(T a, T b)
Definition StdDefs.h:86
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:49
#define SOFT_ASSERT(expr)
define SOFT_ASSERT raise an assertion in debug mode everywhere except on the windows test server
double getDoubleOptional(SumoXMLAttr attr, const double def) const
Returns the value for a given key with an optional default. SUMO_ATTR_MASS and SUMO_ATTR_FRONTSURFACE...
void setDynamicValues(const SUMOTime stopDuration, const bool parking, const SUMOTime waitingTime, const double angleDiff)
Sets the values which change possibly in every simulation step and are relevant for emsssion calculat...
static double naviDegree(const double angle)
static double fromNaviDegree(const double angle)
static double angleDiff(const double angle1, const double angle2)
Returns the difference of the second angle to the first angle in radiants.
Interface for lane-change models.
double getLaneChangeCompletion() const
Get the current lane change completion ratio.
const std::vector< double > & getShadowFurtherLanesPosLat() const
double getManeuverDist() const
Returns the remaining unblocked distance for the current maneuver. (only used by sublane model)
int getLaneChangeDirection() const
return the direction of the current lane change maneuver
void resetChanged()
reset the flag whether a vehicle already moved to false
MSLane * getShadowLane() const
Returns the lane the vehicle's shadow is on during continuous/sublane lane change.
virtual void saveState(OutputDevice &out) const
Save the state of the laneChangeModel.
void endLaneChangeManeuver(const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_LANE_CHANGE)
void setNoShadowPartialOccupator(MSLane *lane)
MSLane * getTargetLane() const
Returns the lane the vehicle has committed to enter during a sublane lane change.
SUMOTime remainingTime() const
Compute the remaining time until LC completion.
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
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
int getShadowDirection() const
return the direction in which the current shadow lane lies
virtual void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the laneChangeModel from the given attributes.
double calcAngleOffset()
return the angle offset during a continuous change maneuver
void setPreviousAngleOffset(const double angleOffset)
set the angle offset of the previous time step
const std::vector< MSLane * > & getFurtherTargetLanes() const
double getAngleOffset() const
return the angle offset resulting from lane change and sigma
const std::vector< MSLane * > & getShadowFurtherLanes() const
bool isChangingLanes() const
return true if the vehicle currently performs a lane change maneuver
void setExtraImpatience(double value)
Sets routing behavior.
The base class for microscopic and mesoscopic vehicles.
double getMaxSpeed() const
Returns the maximum speed (the minimum of desired and technical maximum speed)
bool haveValidStopEdges(bool silent=false) const
check whether all stop.edge MSRouteIterators are valid and in order
virtual bool isSelected() const
whether this vehicle is selected in the GUI
std::list< MSStop > myStops
The vehicle's list of stops.
double getImpatience() const
Returns this vehicles impatience.
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
virtual void initDevices()
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs'th successor of edge the vehicle is currently at.
void calculateArrivalParams(bool onInit)
(Re-)Calculates the arrival position and lane from the vehicle parameters
virtual double getArrivalPos() const
Returns this vehicle's desired arrivalPos for its current route (may change on reroute)
MoveReminderCont myMoveReminders
Currently relevant move reminders.
double myDepartPos
The real depart position.
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
void replaceParameter(const SUMOVehicleParameter *newParameter)
replace the vehicle parameter (deleting the old one)
double getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit.
std::vector< MSVehicleDevice * > myDevices
The devices this vehicle has.
virtual void addTransportable(MSTransportable *transportable)
Adds a person or container to this vehicle.
const SUMOVehicleParameter::Stop * getNextStopParameter() const
return parameters for the next stop (SUMOVehicle Interface)
virtual bool replaceRoute(ConstMSRoutePtr route, const std::string &info, bool onInit=false, int offset=0, bool addRouteStops=true, bool removeStops=true, std::string *msgReturn=nullptr)
Replaces the current route by the given one.
bool isRail() const
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
const MSVehicleType * myType
This vehicle's type.
void cleanupParkingReservation()
unregisters from a parking reservation when changing or skipping stops
double getLength() const
Returns the vehicle's length.
bool isParking() const
Returns whether the vehicle is parking.
MSParkingArea * getCurrentParkingArea()
get the current parking area stop or nullptr
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
int getPersonNumber() const
Returns the number of persons.
MSRouteIterator myCurrEdge
Iterator to current route-edge.
StopParVector myPastStops
The list of stops that the vehicle has already reached.
bool hasDeparted() const
Returns whether this vehicle has already departed.
bool ignoreTransientPermissions() const
Returns whether this object is ignoring transient permission changes (during routing)
ConstMSRoutePtr myRoute
This vehicle's route.
double getWidth() const
Returns the vehicle's width.
MSDevice_Transportable * myContainerDevice
The containers this vehicle may have.
const std::list< MSStop > & getStops() const
double getDesiredMaxSpeed() const
void addReminder(MSMoveReminder *rem, double pos=0)
Adds a MoveReminder dynamically.
SumoRNG * getRNG() const
SUMOTime getDeparture() const
Returns this vehicle's real departure time.
EnergyParams * getEmissionParameters() const
retrieve parameters for the energy consumption model
MSDevice_Transportable * myPersonDevice
The passengers this vehicle may have.
bool hasStops() const
Returns whether the vehicle has to stop somewhere.
virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
"Activates" all current move reminder
const MSStop & getNextStop() const
@ ROUTE_START_INVALID_PERMISSIONS
void addStops(const bool ignoreStopErrors, MSRouteIterator *searchStart=nullptr, bool addRouteStops=true)
Adds stops to the built vehicle.
SUMOVehicleClass getVClass() const
Returns the vehicle's access class.
MSParkingArea * getNextParkingArea()
get the upcoming parking area stop or nullptr
int myArrivalLane
The destination lane where the vehicle stops.
SUMOTime myDeparture
The real departure time.
bool isStoppedTriggered() const
Returns whether the vehicle is on a triggered stop.
void onDepart()
Called when the vehicle is inserted into the network.
virtual bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string &errorMsg)
const MSRoute & getRoute() const
Returns the current route.
int getRoutePosition() const
return index of edge within route
bool replaceParkingArea(MSParkingArea *parkingArea, std::string &errorMsg)
replace the current parking area stop with a new stop with merge duration
static const SUMOTime NOT_YET_DEPARTED
bool myAmRegisteredAsWaiting
Whether this vehicle is registered as waiting for a person or container (for deadlock-recognition)
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT() const
EnergyParams * myEnergyParams
The emission parameters this vehicle may have.
const SUMOVehicleParameter * myParameter
This vehicle's parameter.
int myRouteValidity
status of the current vehicle route
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
bool isStopped() const
Returns whether the vehicle is at a stop.
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists, nullptr otherwise.
int myNumberReroutes
The number of reroutings.
double myArrivalPos
The position on the destination lane where the vehicle stops.
virtual void saveState(OutputDevice &out)
Saves the (common) state of a vehicle.
virtual void replaceVehicleType(const MSVehicleType *type)
Replaces the current vehicle type by the one given.
double myOdometer
A simple odometer to keep track of the length of the route already driven.
int getContainerNumber() const
Returns the number of containers.
bool replaceRouteEdges(ConstMSEdgeVector &edges, double cost, double savings, const std::string &info, bool onInit=false, bool check=false, bool removeStops=true, std::string *msgReturn=nullptr)
Replaces the current route by the given edges.
virtual void saveState(OutputDevice &out, const MSCFModel &cfm) const
Saves the vehicle variables.
Definition MSCFModel.cpp:76
The car-following model abstraction.
Definition MSCFModel.h:59
double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
virtual double minNextSpeedEmergency(double speed, const MSVehicle *const veh=0) const
Returns the minimum speed after emergency braking, given the current speed (depends on the numerical ...
virtual VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting.
Definition MSCFModel.h:268
double getEmergencyDecel() const
Get the vehicle type's maximal physically possible deceleration [m/s^2].
Definition MSCFModel.h:293
SUMOTime getStartupDelay() const
Get the vehicle type's startupDelay.
Definition MSCFModel.h:309
double getMinimalArrivalSpeed(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance.
virtual void setHeadwayTime(double headwayTime)
Sets a new value for desired headway [s].
Definition MSCFModel.h:635
virtual double freeSpeed(const MSVehicle *const veh, double speed, double seen, double maxSpeed, const bool onInsertion=false, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed without a leader.
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 insertionFollowSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0) const
Computes the vehicle's safe speed (no dawdling) This method is used during the insertion stage....
SUMOTime getMinimalArrivalTime(double dist, double currentSpeed, double arrivalSpeed) const
Computes the minimal time needed to cover a distance given the desired speed at arrival.
virtual double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences. Called at most once per simulation...
virtual bool startupDelayStopped() const
whether startupDelay should be applied after stopping
Definition MSCFModel.h:360
@ FUTURE
the return value is used for calculating future speeds
Definition MSCFModel.h:99
@ CURRENT_WAIT
the return value is used for calculating junction stop speeds
Definition MSCFModel.h:101
virtual double maxNextSafeMin(double speed, const MSVehicle *const veh=0) const
Returns the maximum speed given the current speed and regarding driving dynamics.
Definition MSCFModel.h:391
double getApparentDecel() const
Get the vehicle type's apparent deceleration [m/s^2] (the one regarded by its followers.
Definition MSCFModel.h:301
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
Definition MSCFModel.h:277
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
Definition MSCFModel.h:424
virtual double maximumLaneSpeedCF(const MSVehicle *const veh, double maxSpeed, double maxSpeedLane) const
Returns the maximum velocity the CF-model wants to achieve in the next step.
Definition MSCFModel.h:245
double maximumSafeStopSpeed(double gap, double decel, double currentSpeed, bool onInsertion=false, double headway=-1, bool relaxEmergency=true) const
Returns the maximum next velocity for stopping within gap.
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
Definition MSCFModel.h:285
double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance for Euler update.
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
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
Definition MSCFModel.h:355
The ToC Device controls transition of control between automated and manual driving.
std::shared_ptr< MSSimpleDriverState > getDriverState() const
return internal state
void update()
update internal state
A device which collects info on the vehicle trip (mainly on departure and arrival)
double consumption(SUMOVehicle &veh, double a, double newSpeed)
return energy consumption in Wh (power multiplied by TS)
void setConsum(const double consumption)
double acceleration(SUMOVehicle &veh, double power, double oldSpeed)
double getConsum() const
Get consum.
A device which collects info on current friction Coefficient on the road.
A device which collects info on the vehicle trip (mainly on departure and arrival)
A device which collects info on the vehicle trip (mainly on departure and arrival)
void cancelCurrentCustomers()
remove the persons the taxi is currently waiting for from reservations
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the vehicle is at a stop and transportable action is needed.
bool anyLeavingAtStop(const MSStop &stop) const
void transferAtSplitOrJoin(MSBaseVehicle *otherVeh)
transfers transportables that want to continue in the other train part (without boarding/loading dela...
void checkCollisionForInactive(MSLane *l)
trigger collision checking for inactive lane
A road/street connecting two junctions.
Definition MSEdge.h:77
static void clear()
Clears the dictionary.
Definition MSEdge.cpp:1126
static DepartLaneDefinition & getDefaultDepartLaneDefinition()
Definition MSEdge.h:820
const std::set< MSTransportable *, ComparatorNumericalIdLess > & getPersons() const
Returns this edge's persons set.
Definition MSEdge.h:204
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:168
const MSEdge * getOppositeEdge() const
Returns the opposite direction edge if on exists else a nullptr.
Definition MSEdge.cpp:1381
bool isFringe() const
return whether this edge is at the fringe of the network
Definition MSEdge.h:785
const MSEdge * getNormalSuccessor() const
if this edge is an internal edge, return its first normal successor, otherwise the edge itself
Definition MSEdge.cpp:981
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING, bool ignoreTransientPermissions=false) const
Get the allowed lanes to reach the destination-edge.
Definition MSEdge.cpp:480
const MSEdge * getBidiEdge() const
return opposite superposable/congruent edge, if it exist and 0 else
Definition MSEdge.h:283
bool isNormal() const
return whether this edge is an internal edge
Definition MSEdge.h:264
double getSpeedLimit() const
Returns the speed limit of the edge @caution The speed limit of the first lane is retured; should pro...
Definition MSEdge.cpp:1192
bool hasChangeProhibitions(SUMOVehicleClass svc, int index) const
return whether this edge prohibits changing for the given vClass when starting on the given lane inde...
Definition MSEdge.cpp:1403
bool hasLaneChanger() const
Definition MSEdge.h:759
const MSJunction * getToJunction() const
Definition MSEdge.h:427
const MSJunction * getFromJunction() const
Definition MSEdge.h:423
int getNumLanes() const
Definition MSEdge.h:172
double getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition MSEdge.h:485
bool isRoundabout() const
Definition MSEdge.h:742
bool isInternal() const
return whether this edge is an internal edge
Definition MSEdge.h:269
double getWidth() const
Returns the edges's width (sum over all lanes)
Definition MSEdge.h:665
bool isVaporizing() const
Returns whether vehicles on this edge shall be vaporized.
Definition MSEdge.h:443
void addWaiting(SUMOVehicle *vehicle) const
Adds a vehicle to the list of waiting vehicles.
Definition MSEdge.cpp:1492
const MSEdge * getInternalFollowingEdge(const MSEdge *followerAfterInternal, SUMOVehicleClass vClass) const
Definition MSEdge.cpp:934
void removeWaiting(const SUMOVehicle *vehicle) const
Removes a vehicle from the list of waiting vehicles.
Definition MSEdge.cpp:1501
const MSEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
Definition MSEdge.cpp:1299
static bool gModelParkingManoeuver
whether parking simulation includes manoeuver time and any associated lane blocking
Definition MSGlobals.h:165
static bool gUseMesoSim
Definition MSGlobals.h:106
static bool gUseStopStarted
Definition MSGlobals.h:134
static bool gCheckRoutes
Definition MSGlobals.h:91
static SUMOTime gStartupWaitThreshold
The minimum waiting time before applying startupDelay.
Definition MSGlobals.h:183
static double gTLSYellowMinDecel
The minimum deceleration at a yellow traffic light (only overruled by emergencyDecel)
Definition MSGlobals.h:174
static double gLateralResolution
Definition MSGlobals.h:100
static bool gSemiImplicitEulerUpdate
Definition MSGlobals.h:53
static bool gSlopeCentered
whether to use a simplified slope computation (for compatibility with other simulations)
Definition MSGlobals.h:137
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
static bool gUseStopEnded
whether the simulation should replay previous stop times
Definition MSGlobals.h:133
static double gEmergencyDecelWarningThreshold
threshold for warning about strong deceleration
Definition MSGlobals.h:155
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition MSGlobals.h:81
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
virtual const MSJunctionLogic * getLogic() const
Definition MSJunction.h:141
virtual const MSLogicJunction::LinkBits & getResponseFor(int linkIndex) const
Returns the response for the given link.
Representation of a lane in the micro simulation.
Definition MSLane.h:84
std::vector< StopWatch< std::chrono::nanoseconds > > & getStopWatch()
Definition MSLane.h:1317
const std::vector< MSMoveReminder * > & getMoveReminders() const
Return the list of this lane's move reminders.
Definition MSLane.h:324
std::pair< const MSPerson *, double > nextBlocking(double minPos, double minRight, double maxLeft, double stopTime=0, bool bidi=false) const
This is just a wrapper around MSPModel::nextBlocking. You should always check using hasPedestrians be...
Definition MSLane.cpp:4614
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:2888
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
Definition MSLane.cpp:2870
int getVehicleNumber() const
Returns the number of vehicles on this lane (for which this lane is responsible)
Definition MSLane.h:457
MSVehicle * getFirstAnyVehicle() const
returns the first vehicle that is fully or partially on this lane
Definition MSLane.cpp:2719
const MSLink * getEntryLink() const
Returns the entry link if this is an internal lane, else nullptr.
Definition MSLane.cpp:2807
int getVehicleNumberWithPartials() const
Returns the number of vehicles on this lane (including partial occupators)
Definition MSLane.h:465
double getBruttoVehLenSum() const
Returns the sum of lengths of vehicles, including their minGaps, which were on the lane during the la...
Definition MSLane.h:1190
std::pair< MSVehicle *const, double > getFollower(const MSVehicle *ego, double egoPos, double dist, MinorLinkMode mLinkMode, bool maxSearchDist=false) const
Find follower vehicle for the given ego vehicle (which may be on the opposite direction lane)
Definition MSLane.cpp:4440
static std::vector< MSLink * >::const_iterator succLinkSec(const SUMOVehicle &veh, int nRouteSuccs, const MSLane &succLinkSource, const std::vector< MSLane * > &conts)
Definition MSLane.cpp:2733
void markRecalculateBruttoSum()
Set a flag to recalculate the brutto (including minGaps) occupancy of this lane (used if mingap is ch...
Definition MSLane.cpp:2465
const MSLink * getLinkTo(const MSLane *const) const
returns the link to the given lane or nullptr, if it is not connected
Definition MSLane.cpp:2784
MSLeaderDistanceInfo getFollowersOnConsecutive(const MSVehicle *ego, double backOffset, bool allSublanes, double searchDist=-1, MinorLinkMode mLinkMode=FOLLOW_ALWAYS, bool maxSearchDist=false) const
return the sublane followers with the largest missing rear gap among all predecessor lanes (within di...
Definition MSLane.cpp:3840
void forceVehicleInsertion(MSVehicle *veh, double pos, MSMoveReminder::Notification notification, double posLat=0)
Inserts the given vehicle at the given position.
Definition MSLane.cpp:1424
double getVehicleStopOffset(const MSVehicle *veh) const
Returns vehicle class specific stopOffset for the vehicle.
Definition MSLane.cpp:3815
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
Definition MSLane.h:602
std::vector< MSVehicle * > VehCont
Container for vehicles.
Definition MSLane.h:119
const MSEdge * getNextNormal() const
Returns the lane's follower if it is an internal lane, the edge of the lane otherwise.
Definition MSLane.cpp:2497
SVCPermissions getPermissions() const
Returns the vehicle class permissions for this lane.
Definition MSLane.h:640
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
Definition MSLane.h:981
MSLane * getCanonicalPredecessorLane() const
Definition MSLane.cpp:3310
double getLength() const
Returns the lane's length.
Definition MSLane.h:632
double getMaximumBrakeDist() const
compute maximum braking distance on this lane
Definition MSLane.cpp:2945
const MSLane * getInternalFollowingLane(const MSLane *const) const
returns the internal lane leading to the given lane or nullptr, if there is none
Definition MSLane.cpp:2796
const MSLeaderInfo getLastVehicleInformation(const MSVehicle *ego, double latOffset, double minPos=0, bool allowCached=true) const
Returns the last vehicles on the lane.
Definition MSLane.cpp:1477
std::pair< MSVehicle *const, double > getLeaderOnConsecutive(double dist, double seen, double speed, const MSVehicle &veh, const std::vector< MSLane * > &bestLaneConts, bool considerCrossingFoes=true) const
Returns the immediate leader and the distance to him.
Definition MSLane.cpp:3029
bool isLinkEnd(std::vector< MSLink * >::const_iterator &i) const
Definition MSLane.h:881
bool allowsVehicleClass(SUMOVehicleClass vclass) const
Definition MSLane.h:956
virtual double setPartialOccupation(MSVehicle *v)
Sets the information about a vehicle lapping into this lane.
Definition MSLane.cpp:385
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
Definition MSLane.h:575
double getRightSideOnEdge() const
Definition MSLane.h:1226
bool hasPedestrians() const
whether the lane has pedestrians on it
Definition MSLane.cpp:4607
int getIndex() const
Returns the lane's index.
Definition MSLane.h:668
MSLane * getCanonicalSuccessorLane() const
Definition MSLane.cpp:3334
double getOppositePos(double pos) const
return the corresponding position on the opposite lane
Definition MSLane.cpp:4435
MSLane * getLogicalPredecessorLane() const
get the most likely precedecessor lane (sorted using by_connections_to_sorter). The result is cached ...
Definition MSLane.cpp:3254
double getCenterOnEdge() const
Definition MSLane.h:1234
bool isNormal() const
Definition MSLane.cpp:2658
MSVehicle * getLastAnyVehicle() const
returns the last vehicle that is fully or partially on this lane
Definition MSLane.cpp:2700
bool isInternal() const
Definition MSLane.cpp:2652
@ FOLLOW_NEVER
Definition MSLane.h:1005
virtual void resetPartialOccupation(MSVehicle *v)
Removes the information about a vehicle lapping into this lane.
Definition MSLane.cpp:404
MSLane * getOpposite() const
return the neighboring opposite direction lane for lane changing or nullptr
Definition MSLane.cpp:4423
virtual const VehCont & getVehiclesSecure() const
Returns the vehicles container; locks it for microsimulation.
Definition MSLane.h:484
virtual void releaseVehicles() const
Allows to use the container for microsimulation again.
Definition MSLane.h:514
bool mustCheckJunctionCollisions() const
whether this lane must check for junction collisions
Definition MSLane.cpp:4725
double interpolateLanePosToGeometryPos(double lanePos) const
Definition MSLane.h:555
MSLane * getBidiLane() const
retrieve bidirectional lane or nullptr
Definition MSLane.cpp:4719
@ COLLISION_ACTION_WARN
Definition MSLane.h:203
virtual const PositionVector & getShape(bool) const
Definition MSLane.h:294
MSLane * getParallelOpposite() const
return the opposite direction lane of this lanes edge or nullptr
Definition MSLane.cpp:4429
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:790
double getSpaceTillLastStanding(const MSVehicle *ego, bool &foundStopped) const
return the empty space up to the last standing vehicle or the empty space on the whole lane if no veh...
Definition MSLane.cpp:4734
const MSLane * getNormalPredecessorLane() const
get normal lane leading to this internal lane, for normal lanes, the lane itself is returned
Definition MSLane.cpp:3279
double getWidth() const
Returns the lane's width.
Definition MSLane.h:661
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
Definition MSLane.h:750
MSVehicle * getFirstFullVehicle() const
returns the first vehicle for which this lane is responsible or 0
Definition MSLane.cpp:2691
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition MSLane.h:561
static CollisionAction getCollisionAction()
Definition MSLane.h:1388
saves leader/follower vehicles and their distances relative to an ego vehicle
virtual std::string toString() const
print a debugging representation
void fixOppositeGaps(bool isFollower)
subtract vehicle length from all gaps if the leader vehicle is driving in the opposite direction
virtual int addLeader(const MSVehicle *veh, double gap, double latOffset=0, int sublane=-1)
void setSublaneOffset(int offset)
set number of sublanes by which to shift positions
void removeOpposite(const MSLane *lane)
remove vehicles that are driving in the opposite direction (fully or partially) on the given lane
int numSublanes() const
virtual int addLeader(const MSVehicle *veh, bool beyond, double latOffset=0.)
virtual std::string toString() const
print a debugging representation
virtual void clear()
discard all information
bool hasVehicles() const
int getSublaneOffset() const
void getSubLanes(const MSVehicle *veh, double latOffset, int &rightmost, int &leftmost) const
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
@ NOTIFICATION_TELEPORT_ARRIVED
The vehicle was teleported out of the net.
@ NOTIFICATION_PARKING_REROUTE
The vehicle needs another parking area.
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
@ NOTIFICATION_LANE_CHANGE
The vehicle changes lanes (micro only)
@ NOTIFICATION_VAPORIZED_VAPORIZER
The vehicle got vaporized with a vaporizer.
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
@ NOTIFICATION_PARKING
The vehicle starts or ends parking.
@ NOTIFICATION_VAPORIZED_COLLISION
The vehicle got removed by a collision.
@ NOTIFICATION_LOAD_STATE
The vehicle has been loaded from a state file.
@ NOTIFICATION_TELEPORT
The vehicle is being teleported.
@ NOTIFICATION_TELEPORT_CONTINUATION
The vehicle continues being teleported past an edge.
The simulated network and simulation perfomer.
Definition MSNet.h:89
void removeVehicleStateListener(VehicleStateListener *listener)
Removes a vehicle states listener.
Definition MSNet.cpp:1370
VehicleState
Definition of a vehicle state.
Definition MSNet.h:636
@ STARTING_STOP
The vehicles starts to stop.
@ STARTING_PARKING
The vehicles starts to park.
@ STARTING_TELEPORT
The vehicle started to teleport.
@ ENDING_STOP
The vehicle ends to stop.
@ ARRIVED
The vehicle arrived at his destination (is deleted)
@ EMERGENCYSTOP
The vehicle had to brake harder than permitted.
@ MANEUVERING
Vehicle maneuvering either entering or exiting a parking space.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:199
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition MSNet.cpp:1303
std::string getStoppingPlaceID(const MSLane *lane, const double pos, const SumoXMLTag category) const
Returns the stop of the given category close to the given position.
Definition MSNet.cpp:1525
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:334
static bool hasInstance()
Returns whether the network was already constructed.
Definition MSNet.h:158
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition MSNet.cpp:1504
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition MSNet.cpp:1362
bool hasContainers() const
Returns whether containers are simulated.
Definition MSNet.h:435
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to, const std::string &info="")
Informs all added listeners about a vehicle's state change.
Definition MSNet.cpp:1379
bool hasPersons() const
Returns whether persons are simulated.
Definition MSNet.h:419
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition MSNet.h:455
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:402
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1294
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition MSNet.h:445
bool hasElevation() const
return whether the network contains elevation data
Definition MSNet.h:821
static const double SAFETY_GAP
Definition MSPModel.h:59
A lane area vehicles can halt at.
int getOccupancyIncludingReservations(const SUMOVehicle *forVehicle) const
void enter(SUMOVehicle *veh, const bool parking) override
Called if a vehicle enters this stop.
void leaveFrom(SUMOVehicle *what) override
Called if a vehicle leaves this stop.
int getCapacity() const
Returns the area capacity.
int getLotIndex(const SUMOVehicle *veh) const
compute lot for this vehicle
int getLastFreeLotAngle() const
Return the angle of myLastFreeLot - the next parking lot only expected to be called after we have est...
bool parkOnRoad() const
whether vehicles park on the road
double getLastFreePosWithReservation(SUMOTime t, const SUMOVehicle &forVehicle, double brakePos)
Returns the last free position on this stop including reservations from the current lane and time ste...
double getLastFreeLotGUIAngle() const
Return the GUI angle of myLastFreeLot - the angle the GUI uses to rotate into the next parking lot as...
int getManoeuverAngle(const SUMOVehicle &forVehicle) const
Return the manoeuver angle of the lot where the vehicle is parked.
int getOccupancy() const
Returns the area occupancy.
double getGUIAngle(const SUMOVehicle &forVehicle) const
Return the GUI angle of the lot where the vehicle is parked.
void notifyApproach(const MSLink *link)
switch rail signal to active
static MSRailSignalControl & getInstance()
const ConstMSEdgeVector & getEdges() const
Definition MSRoute.h:128
const MSEdge * getLastEdge() const
returns the destination edge
Definition MSRoute.cpp:91
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition MSRoute.cpp:73
const MSLane * lane
The lane to stop at (microsim only)
Definition MSStop.h:50
bool triggered
whether an arriving person lets the vehicle continue
Definition MSStop.h:69
bool containerTriggered
whether an arriving container lets the vehicle continue
Definition MSStop.h:71
SUMOTime timeToLoadNextContainer
The time at which the vehicle is able to load another container.
Definition MSStop.h:83
MSStoppingPlace * containerstop
(Optional) container stop if one is assigned to the stop
Definition MSStop.h:56
double getSpeed() const
return speed for passing waypoint / skipping on-demand stop
Definition MSStop.cpp:213
bool joinTriggered
whether coupling another vehicle (train) the vehicle continue
Definition MSStop.h:73
bool isOpposite
whether this an opposite-direction stop
Definition MSStop.h:87
SUMOTime getMinDuration(SUMOTime time) const
return minimum stop duration when starting stop at time
Definition MSStop.cpp:171
int numExpectedContainer
The number of still expected containers.
Definition MSStop.h:79
bool reached
Information whether the stop has been reached.
Definition MSStop.h:75
MSRouteIterator edge
The edge in the route to stop at.
Definition MSStop.h:48
SUMOTime timeToBoardNextPerson
The time at which the vehicle is able to board another person.
Definition MSStop.h:81
bool skipOnDemand
whether the decision to skip this stop has been made
Definition MSStop.h:89
const MSEdge * getEdge() const
Definition MSStop.cpp:55
double entryPos
the exact position when entering the stop (for state saving)
Definition MSStop.h:97
double getReachedThreshold() const
return startPos taking into account opposite stopping
Definition MSStop.cpp:65
SUMOTime endBoarding
the maximum time at which persons may board this vehicle
Definition MSStop.h:85
double getEndPos(const SUMOVehicle &veh) const
return halting position for upcoming stop;
Definition MSStop.cpp:36
int numExpectedPerson
The number of still expected persons.
Definition MSStop.h:77
MSParkingArea * parkingarea
(Optional) parkingArea if one is assigned to the stop
Definition MSStop.h:58
bool startedFromState
whether the 'started' value was loaded from simulaton state
Definition MSStop.h:91
MSStoppingPlace * chargingStation
(Optional) charging station if one is assigned to the stop
Definition MSStop.h:60
SUMOTime duration
The stopping duration.
Definition MSStop.h:67
SUMOTime getUntil() const
return until / ended time
Definition MSStop.cpp:188
const SUMOVehicleParameter::Stop pars
The stop parameter.
Definition MSStop.h:65
MSStoppingPlace * busstop
(Optional) bus stop if one is assigned to the stop
Definition MSStop.h:54
void stopBlocked(const SUMOVehicle *veh, SUMOTime time)
Definition MSStopOut.cpp:67
static bool active()
Definition MSStopOut.h:55
void stopNotStarted(const SUMOVehicle *veh)
Definition MSStopOut.cpp:76
void stopStarted(const SUMOVehicle *veh, int numPersons, int numContainers, SUMOTime time)
Definition MSStopOut.cpp:83
static MSStopOut * getInstance()
Definition MSStopOut.h:61
void stopEnded(const SUMOVehicle *veh, const MSStop &stop, bool simEnd=false)
double getBeginLanePosition() const
Returns the begin position of this stop.
virtual void enter(SUMOVehicle *veh, const bool parking)
Called if a vehicle enters this stop.
bool fits(double pos, const SUMOVehicle &veh) const
return whether the given vehicle fits at the given position
double getEndLanePosition() const
Returns the end position of this stop.
const MSLane & getLane() const
Returns the lane this stop is located at.
virtual void leaveFrom(SUMOVehicle *what)
Called if a vehicle leaves this stop.
bool hasAnyWaiting(const MSEdge *edge, SUMOVehicle *vehicle) const
check whether any transportables are waiting for the given vehicle
bool loadAnyWaiting(const MSEdge *edge, SUMOVehicle *vehicle, SUMOTime &timeToLoadNext, SUMOTime &stopDuration, MSTransportable *const force=nullptr)
load any applicable transportables Loads any person / container that is waiting on that edge for the ...
bool isPerson() const override
Whether it is a person.
A static instance of this class in GapControlState deactivates gap control for vehicles whose referen...
Definition MSVehicle.h:1361
void vehicleStateChanged(const SUMOVehicle *const vehicle, MSNet::VehicleState to, const std::string &info="")
Called if a vehicle changes its state.
Changes the wished vehicle speed / lanes.
Definition MSVehicle.h:1356
void setLaneChangeMode(int value)
Sets lane changing behavior.
TraciLaneChangePriority myTraciLaneChangePriority
flags for determining the priority of traci lane change requests
Definition MSVehicle.h:1687
bool getEmergencyBrakeRedLight() const
Returns whether red lights shall be a reason to brake.
Definition MSVehicle.h:1530
SUMOTime getLaneTimeLineEnd()
void adaptLaneTimeLine(int indexShift)
Adapts lane timeline when moving to a new lane and the lane index changes.
void setRemoteControlled(Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector &route, SUMOTime t)
bool isRemoteAffected(SUMOTime t) const
int getSpeedMode() const
return the current speed mode
void deactivateGapController()
Deactivates the gap control.
Influencer()
Constructor.
void setSpeedMode(int speedMode)
Sets speed-constraining behaviors.
std::shared_ptr< GapControlState > myGapControlState
The gap control state.
Definition MSVehicle.h:1632
int getSignals() const
Definition MSVehicle.h:1603
bool myConsiderMaxDeceleration
Whether the maximum deceleration shall be regarded.
Definition MSVehicle.h:1653
void setLaneTimeLine(const std::vector< std::pair< SUMOTime, int > > &laneTimeLine)
Sets a new lane timeline.
bool hasSpeedTimeLine(SUMOTime t) const
Definition MSVehicle.h:1437
bool myRespectJunctionLeaderPriority
Whether the junction priority rules are respected (within)
Definition MSVehicle.h:1662
void setOriginalSpeed(double speed)
Stores the originally longitudinal speed.
double myOriginalSpeed
The velocity before influence.
Definition MSVehicle.h:1635
bool myConsiderSpeedLimit
Whether the speed limit shall be regarded.
Definition MSVehicle.h:1647
double implicitDeltaPosRemote(const MSVehicle *veh)
return the change in longitudinal position that is implicit in the new remote position
double implicitSpeedRemote(const MSVehicle *veh, double oldSpeed)
return the speed that is implicit in the new remote position
void postProcessRemoteControl(MSVehicle *v)
update position from remote control
double gapControlSpeed(SUMOTime currentTime, const SUMOVehicle *veh, double speed, double vSafe, double vMin, double vMax)
Applies gap control logic on the speed.
void setSublaneChange(double latDist)
Sets a new sublane-change request.
double getOriginalSpeed() const
Returns the originally longitudinal speed to use.
SUMOTime myLastRemoteAccess
Definition MSVehicle.h:1671
bool getRespectJunctionLeaderPriority() const
Returns whether junction priority rules within the junction shall be respected (concerns vehicles wit...
Definition MSVehicle.h:1538
LaneChangeMode myStrategicLC
lane changing which is necessary to follow the current route
Definition MSVehicle.h:1676
LaneChangeMode mySpeedGainLC
lane changing to travel with higher speed
Definition MSVehicle.h:1680
void init()
Static initalization.
LaneChangeMode mySublaneLC
changing to the prefered lateral alignment
Definition MSVehicle.h:1684
bool getRespectJunctionPriority() const
Returns whether junction priority rules shall be respected (concerns approaching vehicles outside the...
Definition MSVehicle.h:1522
static void cleanup()
Static cleanup.
int getLaneChangeMode() const
return the current lane change mode
SUMOTime getLaneTimeLineDuration()
double influenceSpeed(SUMOTime currentTime, double speed, double vSafe, double vMin, double vMax)
Applies stored velocity information on the speed to use.
double changeRequestRemainingSeconds(const SUMOTime currentTime) const
Return the remaining number of seconds of the current laneTimeLine assuming one exists.
bool myConsiderSafeVelocity
Whether the safe velocity shall be regarded.
Definition MSVehicle.h:1644
bool mySpeedAdaptationStarted
Whether influencing the speed has already started.
Definition MSVehicle.h:1641
~Influencer()
Destructor.
void setSignals(int signals)
Definition MSVehicle.h:1599
double myLatDist
The requested lateral change.
Definition MSVehicle.h:1638
bool considerSpeedLimit() const
Returns whether speed limits shall be considered.
Definition MSVehicle.h:1549
bool myEmergencyBrakeRedLight
Whether red lights are a reason to brake.
Definition MSVehicle.h:1659
LaneChangeMode myRightDriveLC
changing to the rightmost lane
Definition MSVehicle.h:1682
void setSpeedTimeLine(const std::vector< std::pair< SUMOTime, double > > &speedTimeLine)
Sets a new velocity timeline.
void updateRemoteControlRoute(MSVehicle *v)
update route if provided by remote control
bool considerMaxDeceleration() const
Returns whether safe velocities shall be considered.
Definition MSVehicle.h:1555
SUMOTime getLastAccessTimeStep() const
Definition MSVehicle.h:1579
bool myConsiderMaxAcceleration
Whether the maximum acceleration shall be regarded.
Definition MSVehicle.h:1650
LaneChangeMode myCooperativeLC
lane changing with the intent to help other vehicles
Definition MSVehicle.h:1678
bool isRemoteControlled() const
bool myRespectJunctionPriority
Whether the junction priority rules are respected (approaching)
Definition MSVehicle.h:1656
int influenceChangeDecision(const SUMOTime currentTime, const MSEdge &currentEdge, const int currentLaneIndex, int state)
Applies stored LaneChangeMode information and laneTimeLine.
void activateGapController(double originalTau, double newTimeHeadway, double newSpaceHeadway, double duration, double changeRate, double maxDecel, MSVehicle *refVeh=nullptr)
Activates the gap control with the given parameters,.
Container for manouevering time associated with stopping.
Definition MSVehicle.h:1280
SUMOTime myManoeuvreCompleteTime
Time at which this manoeuvre should complete.
Definition MSVehicle.h:1332
MSVehicle::ManoeuvreType getManoeuvreType() const
Accessor (get) for manoeuvre type.
std::string myManoeuvreStop
The name of the stop associated with the Manoeuvre - for debug output.
Definition MSVehicle.h:1326
bool manoeuvreIsComplete() const
Check if any manoeuver is ongoing and whether the completion time is beyond currentTime.
bool configureExitManoeuvre(MSVehicle *veh)
Setup the myManoeuvre for exiting (Sets completion time and manoeuvre type)
void setManoeuvreType(const MSVehicle::ManoeuvreType mType)
Accessor (set) for manoeuvre type.
Manoeuvre & operator=(const Manoeuvre &manoeuvre)
Assignment operator.
Manoeuvre()
Constructor.
ManoeuvreType myManoeuvreType
Manoeuvre type - currently entry, exit or none.
Definition MSVehicle.h:1335
double getGUIIncrement() const
Accessor for GUI rotation step when parking (radians)
SUMOTime myManoeuvreStartTime
Time at which the Manoeuvre for this stop started.
Definition MSVehicle.h:1329
bool operator!=(const Manoeuvre &manoeuvre)
Operator !=.
bool entryManoeuvreIsComplete(MSVehicle *veh)
Configure an entry manoeuvre if nothing is configured - otherwise check if complete.
bool manoeuvreIsComplete(const ManoeuvreType checkType) const
Check if specific manoeuver is ongoing and whether the completion time is beyond currentTime.
bool configureEntryManoeuvre(MSVehicle *veh)
Setup the entry manoeuvre for this vehicle (Sets completion time and manoeuvre type)
Container that holds the vehicles driving state (position+speed).
Definition MSVehicle.h:87
double myPosLat
the stored lateral position
Definition MSVehicle.h:140
State(double pos, double speed, double posLat, double backPos, double previousSpeed)
Constructor.
double myPreviousSpeed
the speed at the begin of the previous time step
Definition MSVehicle.h:148
double myPos
the stored position
Definition MSVehicle.h:134
bool operator!=(const State &state)
Operator !=.
double myLastCoveredDist
Definition MSVehicle.h:154
double mySpeed
the stored speed (should be >=0 at any time)
Definition MSVehicle.h:137
State & operator=(const State &state)
Assignment operator.
double pos() const
Position of this state.
Definition MSVehicle.h:107
double myBackPos
the stored back position
Definition MSVehicle.h:145
void passTime(SUMOTime dt, bool waiting)
const std::string getState() const
SUMOTime cumulatedWaitingTime(SUMOTime memory=-1) const
void setState(const std::string &state)
WaitingTimeCollector(SUMOTime memory=MSGlobals::gWaitingTimeMemory)
Constructor.
void registerEmergencyStop()
register emergency stop
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
void registerStopEnded()
register emergency stop
void registerEmergencyBraking()
register emergency stop
void removeVType(const MSVehicleType *vehType)
void registerOneWaiting()
increases the count of vehicles waiting for a transport to allow recognition of person / container re...
void unregisterOneWaiting()
decreases the count of vehicles waiting for a transport to allow recognition of person / container re...
void registerStopStarted()
register emergency stop
Abstract in-vehicle device.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
void setManoeuvreType(const MSVehicle::ManoeuvreType mType)
accessor function to myManoeuvre equivalent
TraciLaneChangePriority
modes for prioritizing traci lane change requests
Definition MSVehicle.h:1158
@ LCP_OPPORTUNISTIC
Definition MSVehicle.h:1162
double getRightSideOnEdge(const MSLane *lane=0) const
Get the vehicle's lateral position on the edge of the given lane (or its current edge if lane == 0)
bool wasRemoteControlled(SUMOTime lookBack=DELTA_T) const
Returns the information whether the vehicle is fully controlled via TraCI within the lookBack time.
void processLinkApproaches(double &vSafe, double &vSafeMin, double &vSafeMinDist)
This method iterates through the driveprocess items for the vehicle and adapts the given in/out param...
const MSLane * getPreviousLane(const MSLane *current, int &furtherIndex) const
void checkLinkLeader(const MSLink *link, const MSLane *lane, double seen, DriveProcessItem *const lastLink, double &v, double &vLinkPass, double &vLinkWait, bool &setRequest, bool isShadowLink=false) const
checks for link leaders on the given link
void checkRewindLinkLanes(const double lengthsInFront, DriveItemVector &lfLinks) const
runs heuristic for keeping the intersection clear in case of downstream jamming
bool willStop() const
Returns whether the vehicle will stop on the current edge.
bool hasDriverState() const
Whether this vehicle is equipped with a MSDriverState.
Definition MSVehicle.h:1000
static int nextLinkPriority(const std::vector< MSLane * > &conts)
get a numerical value for the priority of the upcoming link
double getTimeGapOnLane() const
Returns the time gap in seconds to the leader of the vehicle on the same lane.
void updateBestLanes(bool forceRebuild=false, const MSLane *startLane=0)
computes the best lanes to use in order to continue the route
bool myAmIdling
Whether the vehicle is trying to enter the network (eg after parking so engine is running)
Definition MSVehicle.h:1949
SUMOTime myWaitingTime
The time the vehicle waits (is not faster than 0.1m/s) in seconds.
Definition MSVehicle.h:1885
double getStopDelay() const
Returns the public transport stop delay in seconds.
double computeAngle() const
compute the current vehicle angle
double myTimeLoss
the time loss in seconds due to driving with less than maximum speed
Definition MSVehicle.h:1889
SUMOTime myLastActionTime
Action offset (actions are taken at time myActionOffset + N*getActionStepLength()) Initialized to 0,...
Definition MSVehicle.h:1904
ConstMSEdgeVector::const_iterator getRerouteOrigin() const
Returns the starting point for reroutes (usually the current edge)
bool hasArrivedInternal(bool oppositeTransformed=true) const
Returns whether this vehicle has already arived (reached the arrivalPosition on its final edge) metho...
double getFriction() const
Returns the current friction on the road as perceived by the friction device.
bool ignoreFoe(const SUMOTrafficObject *foe) const
decide whether a given foe object may be ignored
void boardTransportables(MSStop &stop)
board persons and load transportables at the given stop
const std::vector< const MSLane * > getUpcomingLanesUntil(double distance) const
Returns the upcoming (best followed by default 0) sequence of lanes to continue the route starting at...
double getCurveRadius() const
Returns the vehicle's current curve radius in m.
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition MSVehicle.h:605
void adaptLaneEntering2MoveReminder(const MSLane &enteredLane)
Adapts the vehicle's entering of a new lane.
void addTransportable(MSTransportable *transportable)
Adds a person or container to this vehicle.
SUMOTime myJunctionConflictEntryTime
Definition MSVehicle.h:1974
double getLeftSideOnEdge(const MSLane *lane=0) const
Get the vehicle's lateral position on the edge of the given lane (or its current edge if lane == 0)
PositionVector getBoundingPoly(double offset=0) const
get bounding polygon
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...
bool brakeForOverlap(const MSLink *link, const MSLane *lane) const
handle width transitions
void workOnMoveReminders(double oldPos, double newPos, double newSpeed)
Processes active move reminder.
bool isStoppedOnLane() const
double getDistanceToPosition(double destPos, const MSLane *destLane) const
bool brokeDown() const
Returns how long the vehicle has been stopped already due to lack of energy.
double myAcceleration
The current acceleration after dawdling in m/s.
Definition MSVehicle.h:1931
void registerInsertionApproach(MSLink *link, double dist)
register approach on insertion
void cleanupFurtherLanes()
remove vehicle from further lanes (on leaving the network)
void adaptToLeaders(const MSLeaderInfo &ahead, double latOffset, const double seen, DriveProcessItem *const lastLink, const MSLane *const lane, double &v, double &vLinkPass) const
const MSLane * getBackLane() const
Returns the lane the where the rear of the object is currently at.
void enterLaneAtInsertion(MSLane *enteredLane, double pos, double speed, double posLat, MSMoveReminder::Notification notification)
Update when the vehicle enters a new lane in the emit step.
double getBackPositionOnLane() const
Get the vehicle's position relative to its current lane.
Definition MSVehicle.h:405
double myStopSpeed
the speed that is needed for a scheduled stop or waypoint
Definition MSVehicle.h:1964
void setPreviousSpeed(double prevSpeed, double prevAcceleration)
Sets the influenced previous speed.
double myRawAngle
the angle in radians before lane changing
Definition MSVehicle.h:1956
SUMOTime getArrivalTime(SUMOTime t, double seen, double v, double arrivalSpeed) const
double getAccumulatedWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s) within the last millisecs.
Definition MSVehicle.h:714
SUMOTime getWaitingTime(const bool accumulated=false) const
Returns the SUMOTime waited (speed was lesser than 0.1m/s)
Definition MSVehicle.h:670
bool isFrontOnLane(const MSLane *lane) const
Returns the information whether the front of the vehicle is on the given lane.
virtual ~MSVehicle()
Destructor.
void processLaneAdvances(std::vector< MSLane * > &passedLanes, std::string &emergencyReason)
This method checks if the vehicle has advanced over one or several lanes along its route and triggers...
MSAbstractLaneChangeModel & getLaneChangeModel()
void setEmergencyBlueLight(SUMOTime currentTime)
sets the blue flashing light for emergency vehicles
bool isActionStep(SUMOTime t) const
Returns whether the next simulation step will be an action point for the vehicle.
Definition MSVehicle.h:635
MSAbstractLaneChangeModel * myLaneChangeModel
Definition MSVehicle.h:1911
Position getPositionAlongBestLanes(double offset) const
Return the (x,y)-position, which the vehicle would reach if it continued along its best continuation ...
bool hasValidRouteStart(std::string &msg)
checks wether the vehicle can depart on the first edge
double getLeftSideOnLane() const
Get the lateral position of the vehicles left side on the lane:
std::vector< MSLane * > myFurtherLanes
The information into which lanes the vehicle laps into.
Definition MSVehicle.h:1938
bool signalSet(int which) const
Returns whether the given signal is on.
Definition MSVehicle.h:1194
MSCFModel::VehicleVariables * myCFVariables
The per vehicle variables of the car following model.
Definition MSVehicle.h:2186
bool betterContinuation(const LaneQ *bestConnectedNext, const LaneQ &m) const
comparison between different continuations from the same lane
bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string &errorMsg)
void checkLinkLeaderCurrentAndParallel(const MSLink *link, const MSLane *lane, double seen, DriveProcessItem *const lastLink, double &v, double &vLinkPass, double &vLinkWait, bool &setRequest) const
checks for link leaders of the current link as well as the parallel link (if there is one)
std::pair< double, const MSLink * > myNextTurn
the upcoming turn for the vehicle
Definition MSVehicle.h:1935
double getDistanceToLeaveJunction() const
get the distance from the start of this lane to the start of the next normal lane (or 0 if this lane ...
int influenceChangeDecision(int state)
allow TraCI to influence a lane change decision
double getMaxSpeedOnLane() const
Returns the maximal speed for the vehicle on its current lane (including speed factor and deviation,...
bool isRemoteControlled() const
Returns the information whether the vehicle is fully controlled via TraCI.
bool myAmOnNet
Whether the vehicle is on the network (not parking, teleported, vaporized, or arrived)
Definition MSVehicle.h:1946
void enterLaneAtMove(MSLane *enteredLane, bool onTeleporting=false)
Update when the vehicle enters a new lane in the move step.
double myLastAngle
the angle in radians from the previous simulation step (for computing curve radius)
Definition MSVehicle.h:1958
void adaptBestLanesOccupation(int laneIndex, double density)
update occupation from MSLaneChanger
std::pair< double, double > estimateTimeToNextStop() const
return time (s) and distance to the next stop
double accelThresholdForWaiting() const
maximum acceleration to consider a vehicle as 'waiting' at low speed
Definition MSVehicle.h:2100
void setAngle(double angle, bool straightenFurther=false)
Set a custom vehicle angle in rad, optionally updates furtherLanePosLat.
std::vector< LaneQ >::iterator myCurrentLaneInBestLanes
Definition MSVehicle.h:1926
void setApproachingForAllLinks()
Register junction approaches for all link items in the current plan.
double getDeltaPos(const double accel) const
calculates the distance covered in the next integration step given an acceleration and assuming the c...
const MSLane * myLastBestLanesInternalLane
Definition MSVehicle.h:1914
void updateOccupancyAndCurrentBestLane(const MSLane *startLane)
updates LaneQ::nextOccupation and myCurrentLaneInBestLanes
const std::vector< MSLane * > getUpstreamOppositeLanes() const
Returns the sequence of opposite lanes corresponding to past lanes.
WaitingTimeCollector myWaitingTimeCollector
Definition MSVehicle.h:1886
void setRemoteState(Position xyPos)
sets position outside the road network
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
double getSpeedWithoutTraciInfluence() const
Returns the uninfluenced velocity.
PositionVector getBoundingBox(double offset=0) const
get bounding rectangle
ManoeuvreType
flag identifying which, if any, manoeuvre is in progress
Definition MSVehicle.h:1253
@ MANOEUVRE_ENTRY
Manoeuvre into stopping place.
Definition MSVehicle.h:1255
@ MANOEUVRE_NONE
not manouevring
Definition MSVehicle.h:1259
@ MANOEUVRE_EXIT
Manoeuvre out of stopping place.
Definition MSVehicle.h:1257
const MSEdge * getNextEdgePtr() const
returns the next edge (possibly an internal edge)
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
void setBrakingSignals(double vNext)
sets the braking lights on/off
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the best sequence of lanes to continue the route starting at myLane.
const MSEdge * myLastBestLanesEdge
Definition MSVehicle.h:1913
bool ignoreCollision() const
whether this vehicle is except from collision checks
Influencer * myInfluencer
An instance of a velocity/lane influencing instance; built in "getInfluencer".
Definition MSVehicle.h:2189
void saveState(OutputDevice &out)
Saves the states of a vehicle.
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
void planMove(const SUMOTime t, const MSLeaderInfo &ahead, const double lengthsInFront)
Compute safe velocities for the upcoming lanes based on positions and speeds from the last time step....
bool resumeFromStopping()
int getBestLaneOffset() const
void adaptToJunctionLeader(const std::pair< const MSVehicle *, double > leaderInfo, const double seen, DriveProcessItem *const lastLink, const MSLane *const lane, double &v, double &vLinkPass, double distToCrossing=-1) const
double lateralDistanceToLane(const int offset) const
Get the minimal lateral distance required to move fully onto the lane at given offset.
double getBackPositionOnLane(const MSLane *lane) const
Get the vehicle's position relative to the given lane.
Definition MSVehicle.h:398
void leaveLaneBack(const MSMoveReminder::Notification reason, const MSLane *leftLane)
Update of reminders if vehicle back leaves a lane during (during forward movement.
void resetActionOffset(const SUMOTime timeUntilNextAction=0)
Resets the action offset for the vehicle.
std::vector< DriveProcessItem > DriveItemVector
Container for used Links/visited Lanes during planMove() and executeMove.
Definition MSVehicle.h:2043
void interpolateLateralZ(Position &pos, double offset, double posLat) const
perform lateral z interpolation in elevated networks
void setBlinkerInformation()
sets the blue flashing light for emergency vehicles
const MSEdge * getCurrentEdge() const
Returns the edge the vehicle is currently at (possibly an internal edge or nullptr)
void adaptToLeaderDistance(const MSLeaderDistanceInfo &ahead, double latOffset, double seen, DriveProcessItem *const lastLink, double &v, double &vLinkPass) const
DriveItemVector::iterator myNextDriveItem
iterator pointing to the next item in myLFLinkLanes
Definition MSVehicle.h:2056
bool unsafeLinkAhead(const MSLane *lane, double zipperDist) const
whether the vehicle may safely move to the given lane with regard to upcoming links
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.
const MSLink * myHaveStoppedFor
Definition MSVehicle.h:1978
bool isIdling() const
Returns whether a sim vehicle is waiting to enter a lane (after parking has completed)
Definition MSVehicle.h:621
std::shared_ptr< MSSimpleDriverState > getDriverState() const
Returns the vehicle driver's state.
void removeApproachingInformation(const DriveItemVector &lfLinks) const
unregister approach from all upcoming links
double getAngleDiff() const
get the change in angle from the last simulation step
SUMOTime myJunctionEntryTimeNeverYield
Definition MSVehicle.h:1973
double getLatOffset(const MSLane *lane) const
Get the offset that that must be added to interpret myState.myPosLat for the given lane.
bool rerouteParkingArea(const std::string &parkingAreaID, std::string &errorMsg)
bool hasArrived() const
Returns whether this vehicle has already arrived (reached the arrivalPosition on its final edge)
void switchOffSignal(int signal)
Switches the given signal off.
Definition MSVehicle.h:1177
double getStopArrivalDelay() const
Returns the estimated public transport stop arrival delay in seconds.
int mySignals
State of things of the vehicle that can be on or off.
Definition MSVehicle.h:1943
bool setExitManoeuvre()
accessor function to myManoeuvre equivalent
bool isOppositeLane(const MSLane *lane) const
whether the give lane is reverse direction of the current route or not
double myStopDist
distance to the next stop or doubleMax if there is none
Definition MSVehicle.h:1961
Signalling
Some boolean values which describe the state of some vehicle parts.
Definition MSVehicle.h:1112
@ VEH_SIGNAL_BLINKER_RIGHT
Right blinker lights are switched on.
Definition MSVehicle.h:1116
@ VEH_SIGNAL_BRAKELIGHT
The brake lights are on.
Definition MSVehicle.h:1122
@ VEH_SIGNAL_EMERGENCY_BLUE
A blue emergency light is on.
Definition MSVehicle.h:1138
@ VEH_SIGNAL_BLINKER_LEFT
Left blinker lights are switched on.
Definition MSVehicle.h:1118
SUMOTime getActionStepLength() const
Returns the vehicle's action step length in millisecs, i.e. the interval between two action points.
Definition MSVehicle.h:525
bool myHaveToWaitOnNextLink
Definition MSVehicle.h:1951
SUMOTime collisionStopTime() const
Returns the remaining time a vehicle needs to stop due to a collision. A negative value indicates tha...
const std::vector< const MSLane * > getPastLanesUntil(double distance) const
Returns the sequence of past lanes (right-most on edge) based on the route starting at the current la...
double getBestLaneDist() const
returns the distance that can be driven without lane change
void replaceVehicleType(const MSVehicleType *type)
Replaces the current vehicle type by the one given.
void updateState(double vNext, bool parking=false)
updates the vehicles state, given a next value for its speed. This value can be negative in case of t...
double slowDownForSchedule(double vMinComfortable) const
optionally return an upper bound on speed to stay within the schedule
bool executeMove()
Executes planned vehicle movements with regards to right-of-way.
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition MSVehicle.h:581
std::pair< const MSVehicle *const, double > getFollower(double dist=0) const
Returns the follower of the vehicle looking for a fixed distance.
SUMOTime getWaitingTimeFor(const MSLink *link) const
getWaitingTime, but taking into account having stopped for a stop-link
ChangeRequest
Requests set via TraCI.
Definition MSVehicle.h:191
@ REQUEST_HOLD
vehicle want's to keep the current lane
Definition MSVehicle.h:199
@ REQUEST_LEFT
vehicle want's to change to left lane
Definition MSVehicle.h:195
@ REQUEST_NONE
vehicle doesn't want to change
Definition MSVehicle.h:193
@ REQUEST_RIGHT
vehicle want's to change to right lane
Definition MSVehicle.h:197
bool isLeader(const MSLink *link, const MSVehicle *veh, const double gap) const
whether the given vehicle must be followed at the given junction
void resetApproachOnReroute()
reset rail signal approach information
void computeFurtherLanes(MSLane *enteredLane, double pos, bool collision=false)
updates myFurtherLanes on lane insertion or after collision
MSLane * getMutableLane() const
Returns the lane the vehicle is on Non const version indicates that something volatile is going on.
Definition MSVehicle.h:589
std::pair< const MSLane *, double > getLanePosAfterDist(double distance) const
return lane and position along bestlanes at the given distance
SUMOTime myCollisionImmunity
amount of time for which the vehicle is immune from collisions
Definition MSVehicle.h:1967
bool passingMinor() const
decide whether the vehicle is passing a minor link or has comitted to do so
void updateWaitingTime(double vNext)
Updates the vehicle's waiting time counters (accumulated and consecutive)
void enterLaneAtLaneChange(MSLane *enteredLane)
Update when the vehicle enters a new lane in the laneChange step.
BaseInfluencer & getBaseInfluencer()
Returns the velocity/lane influencer.
Influencer & getInfluencer()
bool isBidiOn(const MSLane *lane) const
whether this vehicle is driving against lane
double getRightSideOnLane() const
Get the lateral position of the vehicles right side on the lane:
double getCurrentApparentDecel() const
get apparent deceleration based on vType parameters and current acceleration
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
DriveItemVector myLFLinkLanesPrev
planned speeds from the previous step for un-registering from junctions after the new container is fi...
Definition MSVehicle.h:2049
std::vector< std::vector< LaneQ > > myBestLanes
Definition MSVehicle.h:1921
void setActionStepLength(double actionStepLength, bool resetActionOffset=true)
Sets the action steplength of the vehicle.
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
Definition MSVehicle.h:413
double getSlope() const
Returns the slope of the road at vehicle's position in degrees.
bool myActionStep
The flag myActionStep indicates whether the current time step is an action point for the vehicle.
Definition MSVehicle.h:1901
const Position getBackPosition() const
bool congested() const
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset)
Loads the state of this vehicle from the given description.
SUMOTime myTimeSinceStartup
duration of driving (speed > SUMO_const_haltingSpeed) after the last halting episode
Definition MSVehicle.h:1977
double getSpeed() const
Returns the vehicle's current speed.
Definition MSVehicle.h:490
SUMOTime remainingStopDuration() const
Returns the remaining stop duration for a stopped vehicle or 0.
bool keepStopping(bool afterProcessing=false) const
Returns whether the vehicle is stopped and must continue to do so.
void workOnIdleReminders()
cycle through vehicle devices invoking notifyIdle
static std::vector< MSLane * > myEmptyLaneVector
Definition MSVehicle.h:1928
Position myCachedPosition
Definition MSVehicle.h:1969
bool replaceRoute(ConstMSRoutePtr route, const std::string &info, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true, std::string *msgReturn=nullptr)
Replaces the current route by the given one.
MSVehicle::ManoeuvreType getManoeuvreType() const
accessor function to myManoeuvre equivalent
double checkReversal(bool &canReverse, double speedThreshold=SUMO_const_haltingSpeed, double seen=0) const
void updateLaneBruttoSum()
Update the lane brutto occupancy after a change in minGap.
void removePassedDriveItems()
Erase passed drive items from myLFLinkLanes (and unregister approaching information for corresponding...
const std::vector< MSLane * > & getFurtherLanes() const
Definition MSVehicle.h:839
const std::vector< LaneQ > & getBestLanes() const
Returns the description of best lanes to use in order to continue the route.
std::vector< double > myFurtherLanesPosLat
lateral positions on further lanes
Definition MSVehicle.h:1940
bool checkActionStep(const SUMOTime t)
Returns whether the vehicle is supposed to take action in the current simulation step Updates myActio...
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
Definition MSVehicle.h:973
Position validatePosition(Position result, double offset=0) const
ensure that a vehicle-relative position is not invalid
void loadPreviousApproaching(MSLink *link, bool setRequest, SUMOTime arrivalTime, double arrivalSpeed, double arrivalSpeedBraking, double dist, double leaveSpeed)
bool keepClear(const MSLink *link) const
decide whether the given link must be kept clear
bool manoeuvreIsComplete() const
accessor function to myManoeuvre equivalent
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
double myAngle
the angle in radians (
Definition MSVehicle.h:1954
bool ignoreRed(const MSLink *link, bool canBrake) const
decide whether a red (or yellow light) may be ignored
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition MSVehicle.h:374
void updateTimeLoss(double vNext)
Updates the vehicle's time loss.
MSDevice_DriverState * myDriverState
This vehicle's driver state.
Definition MSVehicle.h:1895
bool joinTrainPart(MSVehicle *veh)
try joining the given vehicle to the rear of this one (to resolve joinTriggered)
MSLane * myLane
The lane the vehicle is on.
Definition MSVehicle.h:1909
bool onFurtherEdge(const MSEdge *edge) const
whether this vehicle has its back (and no its front) on the given edge
double processTraCISpeedControl(double vSafe, double vNext)
Check for speed advices from the traci client and adjust the speed vNext in the current (euler) / aft...
Manoeuvre myManoeuvre
Definition MSVehicle.h:1342
double getLateralOverlap() const
return the amount by which the vehicle extends laterally outside it's primary lane
double getAngle() const
Returns the vehicle's direction in radians.
Definition MSVehicle.h:735
bool handleCollisionStop(MSStop &stop, const double distToStop)
bool hasInfluencer() const
whether the vehicle is individually influenced (via TraCI or special parameters)
Definition MSVehicle.h:1706
MSDevice_Friction * myFrictionDevice
This vehicle's friction perception.
Definition MSVehicle.h:1898
double getPreviousSpeed() const
Returns the vehicle's speed before the previous time step.
Definition MSVehicle.h:498
MSVehicle()
invalidated default constructor
bool joinTrainPartFront(MSVehicle *veh)
try joining the given vehicle to the front of this one (to resolve joinTriggered)
void updateActionOffset(const SUMOTime oldActionStepLength, const SUMOTime newActionStepLength)
Process an updated action step length value (only affects the vehicle's action offset,...
double getBrakeGap(bool delayed=false) const
get distance for coming to a stop (used for rerouting checks)
std::pair< const MSVehicle *const, double > getLeader(double dist=0, bool considerFoes=true) const
Returns the leader of the vehicle looking for a fixed distance.
void executeFractionalMove(double dist)
move vehicle forward by the given distance during insertion
LaneChangeMode
modes for resolving conflicts between external control (traci) and vehicle control over lane changing...
Definition MSVehicle.h:1150
virtual void drawOutsideNetwork(bool)
register vehicle for drawing while outside the network
Definition MSVehicle.h:1857
void initDevices()
void adaptToOncomingLeader(const std::pair< const MSVehicle *, double > leaderInfo, DriveProcessItem *const lastLink, double &v, double &vLinkPass) const
void planMoveInternal(const SUMOTime t, MSLeaderInfo ahead, DriveItemVector &lfLinks, double &myStopDist, double &newStopSpeed, std::pair< double, const MSLink * > &myNextTurn) const
State myState
This Vehicles driving state (pos and speed)
Definition MSVehicle.h:1892
double getCenterOnEdge(const MSLane *lane=0) const
Get the vehicle's lateral position on the edge of the given lane (or its current edge if lane == 0)
void adaptToLeader(const std::pair< const MSVehicle *, double > leaderInfo, double seen, DriveProcessItem *const lastLink, double &v, double &vLinkPass) const
bool instantStopping() const
whether instant stopping is permitted
void switchOnSignal(int signal)
Switches the given signal on.
Definition MSVehicle.h:1169
static bool overlap(const MSVehicle *veh1, const MSVehicle *veh2)
Definition MSVehicle.h:767
int getLaneIndex() const
void updateParkingState()
update state while parking
DriveItemVector myLFLinkLanes
container for the planned speeds in the current step
Definition MSVehicle.h:2046
void updateDriveItems()
Check whether the drive items (myLFLinkLanes) are up to date, and update them if required.
SUMOTime myJunctionEntryTime
time at which the current junction was entered
Definition MSVehicle.h:1972
static MSVehicleTransfer * getInstance()
Returns the instance of this object.
void remove(MSVehicle *veh)
Remove a vehicle from this transfer object.
The car-following model and parameter.
double getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
double getMaxSpeed() const
Get vehicle's (technical) maximum speed [m/s].
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.
LaneChangeModel getLaneChangeModel() const
void setLength(const double &length)
Set a new value for this type's length.
SUMOTime getExitManoeuvreTime(const int angle) const
Accessor function for parameter equivalent returning exit time for a specific manoeuver angle.
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
bool isVehicleSpecific() const
Returns whether this type belongs to a single vehicle only (was modified)
void setActionStepLength(const SUMOTime actionStepLength, bool resetActionOffset)
Set a new value for this type's action step length.
double getLength() const
Get vehicle's length [m].
SUMOVehicleShape getGuiShape() const
Get this vehicle type's shape.
SUMOTime getEntryManoeuvreTime(const int angle) const
Accessor function for parameter equivalent returning entry time for a specific manoeuver angle.
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
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
bool hasParameter(const std::string &key) const
Returns whether the parameter is set.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double slopeTo2D(const Position &other) const
returns the slope of the vector pointing from here to the other position (in radians between -M_PI an...
Definition Position.h:288
static const Position INVALID
used to indicate that a position is valid
Definition Position.h:323
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition Position.h:273
void setz(double z)
set position z
Definition Position.h:77
double z() const
Returns the z-position.
Definition Position.h:62
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position (in radians bet...
Definition Position.h:283
A list of positions.
double length2D() const
Returns the length.
void append(const PositionVector &v, double sameThreshold=2.0)
double rotationAtOffset(double pos) const
Returns the rotation at the given length.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
void move2side(double amount, double maxExtension=100)
move position vector to side using certain amount
double slopeDegreeAtOffset(double pos) const
Returns the slope at the given length.
void extrapolate2D(const double val, const bool onlyFirst=false)
extrapolate position vector in two dimensions (Z is ignored)
void scaleRelative(double factor)
enlarges/shrinks the polygon by a factor based at the centroid
PositionVector reverse() const
reverse position vector
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into, bool silent=false)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
virtual double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
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.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue=T(), bool report=true) const
Tries to read given attribute assuming it is an int.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
double getFloat(int id) const
Returns the double-value of the named (by its enum-value) attribute.
Representation of a vehicle, person, or container.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual double getSpeed() const =0
Returns the object's current speed.
double locomotiveLength
the length of the locomotive
double speedFactorPremature
the possible speed reduction when a train is ahead of schedule
double getLCParam(const SumoXMLAttr attr, const double defaultValue) const
Returns the named value from the map, or the default if it is not contained there.
double getJMParam(const SumoXMLAttr attr, const double defaultValue) const
Returns the named value from the map, or the default if it is not contained there.
Representation of a vehicle.
Definition SUMOVehicle.h:63
Definition of vehicle stop (position and duration)
SUMOTime started
the time at which this stop was reached
ParkingType parking
whether the vehicle is removed from the net while stopping
SUMOTime extension
The maximum time extension for boarding / loading.
std::string split
the id of the vehicle (train portion) that splits of upon reaching this stop
double startPos
The stopping position start.
std::string line
the new line id of the trip within a cyclical public transport route
double posLat
the lateral offset when stopping
bool onDemand
whether the stop may be skipped
int parametersSet
Information for the output which parameter were set.
std::string join
the id of the vehicle (train portion) to which this vehicle shall be joined
SUMOTime until
The time at which the vehicle may continue its journey.
SUMOTime ended
the time at which this stop was ended
double endPos
The stopping position end.
SUMOTime waitUntil
The earliest pickup time for a taxi stop.
std::string tripId
id of the trip within a cyclical public transport route
bool collision
Whether this stop was triggered by a collision.
SUMOTime arrival
The (expected) time at which the vehicle reaches the stop.
SUMOTime duration
The stopping duration.
Structure representing possible vehicle parameter.
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
ArrivalSpeedDefinition arrivalSpeedProcedure
Information how the vehicle's end speed shall be chosen.
double departSpeed
(optional) The initial speed of the vehicle
std::vector< std::string > via
List of the via-edges the vehicle must visit.
ArrivalLaneDefinition arrivalLaneProcedure
Information how the vehicle shall choose the lane to arrive on.
long long int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
bool wasSet(long long int what) const
Returns whether the given parameter was set.
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle's initial speed shall be chosen.
double arrivalPos
(optional) The position the vehicle shall arrive on
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
double arrivalSpeed
(optional) The final speed of the vehicle (not used yet)
int arrivalEdge
(optional) The final edge within the route of the vehicle
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
static SUMOTime processActionStepLength(double given)
Checks and converts given value for the action step length from seconds to miliseconds assuring it be...
std::vector< std::string > getVector()
return vector of strings
#define DEBUG_COND
Definition json.hpp:4471
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition json.hpp:21884
#define M_PI
Definition odrSpiral.cpp:45
Drive process items represent bounds on the safe velocity corresponding to the upcoming links.
Definition MSVehicle.h:1985
void adaptStopSpeed(const double v)
Definition MSVehicle.h:2032
double getLeaveSpeed() const
Definition MSVehicle.h:2036
void adaptLeaveSpeed(const double v)
Definition MSVehicle.h:2024
static std::map< const MSVehicle *, GapControlState * > refVehMap
stores reference vehicles currently in use by a gapController
Definition MSVehicle.h:1415
static GapControlVehStateListener * myVehStateListener
Definition MSVehicle.h:1418
void activate(double tauOriginal, double tauTarget, double additionalGap, double duration, double changeRate, double maxDecel, const MSVehicle *refVeh)
Start gap control with given params.
static void cleanup()
Static cleanup (removes vehicle state listener)
void deactivate()
Stop gap control.
static void init()
Static initalization (adds vehicle state listener)
A structure representing the best lanes for continuing the current route starting at 'lane'.
Definition MSVehicle.h:861
double length
The overall length which may be driven when using this lane without a lane change.
Definition MSVehicle.h:865
bool allowsContinuation
Whether this lane allows to continue the drive.
Definition MSVehicle.h:875
double nextOccupation
As occupation, but without the first lane.
Definition MSVehicle.h:871
std::vector< MSLane * > bestContinuations
Definition MSVehicle.h:881
MSLane * lane
The described lane.
Definition MSVehicle.h:863
double currentLength
The length which may be driven on this lane.
Definition MSVehicle.h:867
int bestLaneOffset
The (signed) number of lanes to be crossed to get to the lane which allows to continue the drive.
Definition MSVehicle.h:873
double occupation
The overall vehicle sum on consecutive lanes which can be passed without a lane change.
Definition MSVehicle.h:869