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 myStopDist(std::numeric_limits<double>::max()),
1015 myStopSpeed(std::numeric_limits<double>::max()),
1021 myTimeSinceStartup(TIME2STEPS(3600 * 24)),
1022 myHaveStoppedFor(nullptr),
1023 myInfluencer(nullptr) {
1026}
1027
1028
1039
1040
1041void
1043 for (MSLane* further : myFurtherLanes) {
1044 further->resetPartialOccupation(this);
1045 if (further->getBidiLane() != nullptr
1046 && (!isRailway(getVClass()) || (further->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
1047 further->getBidiLane()->resetPartialOccupation(this);
1048 }
1049 }
1050 if (myLaneChangeModel != nullptr) {
1054 // still needed when calling resetPartialOccupation (getShadowLane) and when removing
1055 // approach information from parallel links
1056 }
1057 myFurtherLanes.clear();
1058 myFurtherLanesPosLat.clear();
1059}
1060
1061
1062void
1064#ifdef DEBUG_ACTIONSTEPS
1065 if (DEBUG_COND) {
1066 std::cout << SIMTIME << " Removing vehicle '" << getID() << "' (reason: " << toString(reason) << ")" << std::endl;
1067 }
1068#endif
1071 leaveLane(reason);
1074 }
1075}
1076
1077
1078void
1085
1086
1087// ------------ interaction with the route
1088bool
1090 // note: not a const method because getDepartLane may call updateBestLanes
1091 if (!(*myCurrEdge)->isTazConnector()) {
1093 if ((*myCurrEdge)->getDepartLane(*this) == nullptr) {
1094 msg = "Invalid departlane definition for vehicle '" + getID() + "'.";
1095 if (myParameter->departLane >= (int)(*myCurrEdge)->getLanes().size()) {
1097 } else {
1099 }
1100 return false;
1101 }
1102 } else {
1103 if ((*myCurrEdge)->allowedLanes(getVClass(), ignoreTransientPermissions()) == nullptr) {
1104 msg = "Vehicle '" + getID() + "' is not allowed to depart on any lane of edge '" + (*myCurrEdge)->getID() + "'.";
1106 return false;
1107 }
1108 }
1110 msg = "Departure speed for vehicle '" + getID() + "' is too high for the vehicle type '" + myType->getID() + "'.";
1112 return false;
1113 }
1114 }
1116 return true;
1117}
1118
1119
1120bool
1122 return hasArrivedInternal(false);
1123}
1124
1125
1126bool
1127MSVehicle::hasArrivedInternal(bool oppositeTransformed) const {
1128 return ((myCurrEdge == myRoute->end() - 1 || (myParameter->arrivalEdge >= 0 && getRoutePosition() >= myParameter->arrivalEdge))
1129 && (myStops.empty() || myStops.front().edge != myCurrEdge || myStops.front().getSpeed() > 0)
1130 && ((myLaneChangeModel->isOpposite() && !oppositeTransformed) ? myLane->getLength() - myState.myPos : myState.myPos) > MIN2(myLane->getLength(), myArrivalPos) - POSITION_EPS
1131 && !isRemoteControlled());
1132}
1133
1134
1135bool
1136MSVehicle::replaceRoute(ConstMSRoutePtr newRoute, const std::string& info, bool onInit, int offset, bool addRouteStops, bool removeStops, std::string* msgReturn) {
1137 if (MSBaseVehicle::replaceRoute(newRoute, info, onInit, offset, addRouteStops, removeStops, msgReturn)) {
1138 // update best lanes (after stops were added)
1139 myLastBestLanesEdge = nullptr;
1141 updateBestLanes(true, onInit ? (*myCurrEdge)->getLanes().front() : 0);
1142 assert(!removeStops || haveValidStopEdges());
1143 if (myStops.size() == 0) {
1144 myStopDist = std::numeric_limits<double>::max();
1145 }
1146 return true;
1147 }
1148 return false;
1149}
1150
1151
1152// ------------ Interaction with move reminders
1153void
1154MSVehicle::workOnMoveReminders(double oldPos, double newPos, double newSpeed) {
1155 // This erasure-idiom works for all stl-sequence-containers
1156 // See Meyers: Effective STL, Item 9
1157 for (MoveReminderCont::iterator rem = myMoveReminders.begin(); rem != myMoveReminders.end();) {
1158 // XXX: calling notifyMove with newSpeed seems not the best choice. For the ballistic update, the average speed is calculated and used
1159 // although a higher order quadrature-formula might be more adequate.
1160 // For the euler case (where the speed is considered constant for each time step) it is conceivable that
1161 // the current calculations may lead to systematic errors for large time steps (compared to reality). Refs. #2579
1162 if (!rem->first->notifyMove(*this, oldPos + rem->second, newPos + rem->second, MAX2(0., newSpeed))) {
1163#ifdef _DEBUG
1164 if (myTraceMoveReminders) {
1165 traceMoveReminder("notifyMove", rem->first, rem->second, false);
1166 }
1167#endif
1168 rem = myMoveReminders.erase(rem);
1169 } else {
1170#ifdef _DEBUG
1171 if (myTraceMoveReminders) {
1172 traceMoveReminder("notifyMove", rem->first, rem->second, true);
1173 }
1174#endif
1175 ++rem;
1176 }
1177 }
1178 if (myEnergyParams != nullptr) {
1179 // TODO make the vehicle energy params a derived class which is a move reminder
1181 }
1182}
1183
1184
1185void
1187 updateWaitingTime(0.); // cf issue 2233
1188
1189 // vehicle move reminders
1190 for (const auto& rem : myMoveReminders) {
1191 rem.first->notifyIdle(*this);
1192 }
1193
1194 // lane move reminders - for aggregated values
1195 for (MSMoveReminder* rem : getLane()->getMoveReminders()) {
1196 rem->notifyIdle(*this);
1197 }
1198}
1199
1200// XXX: consider renaming...
1201void
1203 // save the old work reminders, patching the position information
1204 // add the information about the new offset to the old lane reminders
1205 const double oldLaneLength = myLane->getLength();
1206 for (auto& rem : myMoveReminders) {
1207 rem.second += oldLaneLength;
1208#ifdef _DEBUG
1209// if (rem->first==0) std::cout << "Null reminder (?!)" << std::endl;
1210// std::cout << "Adapted MoveReminder on lane " << ((rem->first->getLane()==0) ? "NULL" : rem->first->getLane()->getID()) <<" position to " << rem->second << std::endl;
1211 if (myTraceMoveReminders) {
1212 traceMoveReminder("adaptedPos", rem.first, rem.second, true);
1213 }
1214#endif
1215 }
1216 for (MSMoveReminder* const rem : enteredLane.getMoveReminders()) {
1217 addReminder(rem);
1218 }
1219}
1220
1221
1222// ------------ Other getter methods
1223double
1225 if (isParking() && getStops().begin()->parkingarea != nullptr) {
1226 return getStops().begin()->parkingarea->getVehicleSlope(*this);
1227 }
1228 if (myLane == nullptr) {
1229 return 0;
1230 }
1231 const double posLat = myState.myPosLat; // @todo get rid of the '-'
1232 Position p1 = getPosition();
1234 if (p2 == Position::INVALID) {
1235 // Handle special case of vehicle's back reaching out of the network
1236 if (myFurtherLanes.size() > 0) {
1237 p2 = myFurtherLanes.back()->geometryPositionAtOffset(0, -myFurtherLanesPosLat.back());
1238 if (p2 == Position::INVALID) {
1239 // unsuitable lane geometry
1240 p2 = myLane->geometryPositionAtOffset(0, posLat);
1241 }
1242 } else {
1243 p2 = myLane->geometryPositionAtOffset(0, posLat);
1244 }
1245 }
1247}
1248
1249
1251MSVehicle::getPosition(const double offset) const {
1252 if (myLane == nullptr) {
1253 // when called in the context of GUI-Drawing, the simulation step is already incremented
1255 return myCachedPosition;
1256 } else {
1257 return Position::INVALID;
1258 }
1259 }
1260 if (isParking()) {
1261 if (myInfluencer != nullptr && myInfluencer->getLastAccessTimeStep() > getNextStopParameter()->started) {
1262 return myCachedPosition;
1263 }
1264 if (myStops.begin()->parkingarea != nullptr) {
1265 return myStops.begin()->parkingarea->getVehiclePosition(*this);
1266 } else {
1267 // position beside the road
1268 PositionVector shp = myLane->getEdge().getLanes()[0]->getShape();
1271 }
1272 }
1273 const bool changingLanes = myLaneChangeModel->isChangingLanes();
1274 const double posLat = (MSGlobals::gLefthand ? 1 : -1) * getLateralPositionOnLane();
1275 if (offset == 0. && !changingLanes) {
1278 if (MSNet::getInstance()->hasElevation() && MSGlobals::gSublane) {
1280 }
1281 }
1282 return myCachedPosition;
1283 }
1284 Position result = validatePosition(myLane->geometryPositionAtOffset(getPositionOnLane() + offset, posLat), offset);
1285 interpolateLateralZ(result, getPositionOnLane() + offset, posLat);
1286 return result;
1287}
1288
1289
1290void
1291MSVehicle::interpolateLateralZ(Position& pos, double offset, double posLat) const {
1292 const MSLane* shadow = myLaneChangeModel->getShadowLane();
1293 if (shadow != nullptr && pos != Position::INVALID) {
1294 // ignore negative offset
1295 const Position shadowPos = shadow->geometryPositionAtOffset(MAX2(0.0, offset));
1296 if (shadowPos != Position::INVALID && pos.z() != shadowPos.z()) {
1297 const double centerDist = (myLane->getWidth() + shadow->getWidth()) * 0.5;
1298 double relOffset = fabs(posLat) / centerDist;
1299 double newZ = (1 - relOffset) * pos.z() + relOffset * shadowPos.z();
1300 pos.setz(newZ);
1301 }
1302 }
1303}
1304
1305
1306double
1308 double result = getLength() - getPositionOnLane();
1309 if (myLane->isNormal()) {
1310 return MAX2(0.0, result);
1311 }
1312 const MSLane* lane = myLane;
1313 while (lane->isInternal()) {
1314 result += lane->getLength();
1315 lane = lane->getCanonicalSuccessorLane();
1316 }
1317 return result;
1318}
1319
1320
1324 if (!isOnRoad()) {
1325 return Position::INVALID;
1326 }
1327 const std::vector<MSLane*>& bestLanes = getBestLanesContinuation();
1328 auto nextBestLane = bestLanes.begin();
1329 const bool opposite = myLaneChangeModel->isOpposite();
1330 double pos = opposite ? myLane->getLength() - myState.myPos : myState.myPos;
1331 const MSLane* lane = opposite ? myLane->getParallelOpposite() : getLane();
1332 assert(lane != 0);
1333 bool success = true;
1334
1335 while (offset > 0) {
1336 // take into account lengths along internal lanes
1337 while (lane->isInternal() && offset > 0) {
1338 if (offset > lane->getLength() - pos) {
1339 offset -= lane->getLength() - pos;
1340 lane = lane->getLinkCont()[0]->getViaLaneOrLane();
1341 pos = 0.;
1342 if (lane == nullptr) {
1343 success = false;
1344 offset = 0.;
1345 }
1346 } else {
1347 pos += offset;
1348 offset = 0;
1349 }
1350 }
1351 // set nextBestLane to next non-internal lane
1352 while (nextBestLane != bestLanes.end() && *nextBestLane == nullptr) {
1353 ++nextBestLane;
1354 }
1355 if (offset > 0) {
1356 assert(!lane->isInternal());
1357 assert(lane == *nextBestLane);
1358 if (offset > lane->getLength() - pos) {
1359 offset -= lane->getLength() - pos;
1360 ++nextBestLane;
1361 assert(nextBestLane == bestLanes.end() || *nextBestLane != 0);
1362 if (nextBestLane == bestLanes.end()) {
1363 success = false;
1364 offset = 0.;
1365 } else {
1366 const MSLink* link = lane->getLinkTo(*nextBestLane);
1367 assert(link != nullptr);
1368 lane = link->getViaLaneOrLane();
1369 pos = 0.;
1370 }
1371 } else {
1372 pos += offset;
1373 offset = 0;
1374 }
1375 }
1376
1377 }
1378
1379 if (success) {
1381 } else {
1382 return Position::INVALID;
1383 }
1384}
1385
1386
1387double
1389 if (myLane != nullptr) {
1390 return myLane->getVehicleMaxSpeed(this);
1391 }
1392 return myType->getMaxSpeed();
1393}
1394
1395
1397MSVehicle::validatePosition(Position result, double offset) const {
1398 int furtherIndex = 0;
1399 double lastLength = getPositionOnLane();
1400 while (result == Position::INVALID) {
1401 if (furtherIndex >= (int)myFurtherLanes.size()) {
1402 //WRITE_WARNINGF(TL("Could not compute position for vehicle '%', time=%."), getID(), time2string(MSNet::getInstance()->getCurrentTimeStep()));
1403 break;
1404 }
1405 //std::cout << SIMTIME << " veh=" << getID() << " lane=" << myLane->getID() << " pos=" << getPositionOnLane() << " posLat=" << getLateralPositionOnLane() << " offset=" << offset << " result=" << result << " i=" << furtherIndex << " further=" << myFurtherLanes.size() << "\n";
1406 MSLane* further = myFurtherLanes[furtherIndex];
1407 offset += lastLength;
1408 result = further->geometryPositionAtOffset(further->getLength() + offset, -getLateralPositionOnLane());
1409 lastLength = further->getLength();
1410 furtherIndex++;
1411 //std::cout << SIMTIME << " newResult=" << result << "\n";
1412 }
1413 return result;
1414}
1415
1416
1417ConstMSEdgeVector::const_iterator
1419 // too close to the next junction, so avoid an emergency brake here
1420 if (myLane != nullptr && (myCurrEdge + 1) != myRoute->end() && !isRailway(getVClass())) {
1421 if (myLane->isInternal()) {
1422 return myCurrEdge + 1;
1423 }
1424 if (myState.myPos > myLane->getLength() - getCarFollowModel().brakeGap(myState.mySpeed, getCarFollowModel().getMaxDecel(), 0.)) {
1425 return myCurrEdge + 1;
1426 }
1428 return myCurrEdge + 1;
1429 }
1430 }
1431 return myCurrEdge;
1432}
1433
1434void
1435MSVehicle::setAngle(double angle, bool straightenFurther) {
1436#ifdef DEBUG_FURTHER
1437 if (DEBUG_COND) {
1438 std::cout << SIMTIME << " veh '" << getID() << " setAngle(" << angle << ") straightenFurther=" << straightenFurther << std::endl;
1439 }
1440#endif
1441 myAngle = angle;
1442 MSLane* next = myLane;
1443 if (straightenFurther && myFurtherLanesPosLat.size() > 0) {
1444 for (int i = 0; i < (int)myFurtherLanes.size(); i++) {
1445 MSLane* further = myFurtherLanes[i];
1446 const MSLink* link = further->getLinkTo(next);
1447 if (link != nullptr) {
1449 next = further;
1450 } else {
1451 break;
1452 }
1453 }
1454 }
1455}
1456
1457
1458void
1459MSVehicle::setActionStepLength(double actionStepLength, bool resetOffset) {
1460 SUMOTime actionStepLengthMillisecs = SUMOVehicleParserHelper::processActionStepLength(actionStepLength);
1461 SUMOTime previousActionStepLength = getActionStepLength();
1462 const bool newActionStepLength = actionStepLengthMillisecs != previousActionStepLength;
1463 if (newActionStepLength) {
1464 getSingularType().setActionStepLength(actionStepLengthMillisecs, resetOffset);
1465 if (!resetOffset) {
1466 updateActionOffset(previousActionStepLength, actionStepLengthMillisecs);
1467 }
1468 }
1469 if (resetOffset) {
1471 }
1472}
1473
1474
1475bool
1477 return myState.mySpeed < (60.0 / 3.6) || myLane->getSpeedLimit() < (60.1 / 3.6);
1478}
1479
1480
1481double
1483 Position p1;
1484 const double posLat = -myState.myPosLat; // @todo get rid of the '-'
1485 const double lefthandSign = (MSGlobals::gLefthand ? -1 : 1);
1486
1487 // if parking manoeuvre is happening then rotate vehicle on each step
1490 }
1491
1492 if (isParking()) {
1493 if (myStops.begin()->parkingarea != nullptr) {
1494 return myStops.begin()->parkingarea->getVehicleAngle(*this);
1495 } else {
1497 }
1498 }
1500 // cannot use getPosition() because it already includes the offset to the side and thus messes up the angle
1501 p1 = myLane->geometryPositionAtOffset(myState.myPos, lefthandSign * posLat);
1502 if (p1 == Position::INVALID && myLane->getShape().length2D() == 0. && myLane->isInternal()) {
1503 // workaround: extrapolate the preceding lane shape
1504 MSLane* predecessorLane = myLane->getCanonicalPredecessorLane();
1505 p1 = predecessorLane->geometryPositionAtOffset(predecessorLane->getLength() + myState.myPos, lefthandSign * posLat);
1506 }
1507 } else {
1508 p1 = getPosition();
1509 }
1510
1511 Position p2;
1512 if (getVehicleType().getParameter().locomotiveLength > 0) {
1513 // articulated vehicle should use the heading of the first part
1514 const double locoLength = MIN2(getVehicleType().getParameter().locomotiveLength, getLength());
1515 p2 = getPosition(-locoLength);
1516 } else {
1517 p2 = getBackPosition();
1518 }
1519 if (p2 == Position::INVALID) {
1520 // Handle special case of vehicle's back reaching out of the network
1521 if (myFurtherLanes.size() > 0) {
1522 p2 = myFurtherLanes.back()->geometryPositionAtOffset(0, -myFurtherLanesPosLat.back());
1523 if (p2 == Position::INVALID) {
1524 // unsuitable lane geometry
1525 p2 = myLane->geometryPositionAtOffset(0, posLat);
1526 }
1527 } else {
1528 p2 = myLane->geometryPositionAtOffset(0, posLat);
1529 }
1530 }
1531 double result = (p1 != p2 ? p2.angleTo2D(p1) :
1533
1534 result += lefthandSign * myLaneChangeModel->calcAngleOffset();
1535
1536#ifdef DEBUG_FURTHER
1537 if (DEBUG_COND) {
1538 std::cout << SIMTIME << " computeAngle veh=" << getID() << " p1=" << p1 << " p2=" << p2 << " angle=" << RAD2DEG(result) << " naviDegree=" << GeomHelper::naviDegree(result) << "\n";
1539 }
1540#endif
1541 return result;
1542}
1543
1544
1545const Position
1547 const double posLat = MSGlobals::gLefthand ? myState.myPosLat : -myState.myPosLat;
1548 Position result;
1549 if (myState.myPos >= myType->getLength()) {
1550 // vehicle is fully on the new lane
1552 } else {
1554 // special case where the target lane has no predecessor
1555#ifdef DEBUG_FURTHER
1556 if (DEBUG_COND) {
1557 std::cout << " getBackPosition veh=" << getID() << " specialCase using myLane=" << myLane->getID() << " pos=0 posLat=" << myState.myPosLat << " result=" << myLane->geometryPositionAtOffset(0, posLat) << "\n";
1558 }
1559#endif
1560 result = myLane->geometryPositionAtOffset(0, posLat);
1561 } else {
1562#ifdef DEBUG_FURTHER
1563 if (DEBUG_COND) {
1564 std::cout << " getBackPosition veh=" << getID() << " myLane=" << myLane->getID() << " further=" << toString(myFurtherLanes) << " myFurtherLanesPosLat=" << toString(myFurtherLanesPosLat) << "\n";
1565 }
1566#endif
1567 if (myFurtherLanes.size() > 0 && !myLaneChangeModel->isChangingLanes()) {
1568 // truncate to 0 if vehicle starts on an edge that is shorter than its length
1569 const double backPos = MAX2(0.0, getBackPositionOnLane(myFurtherLanes.back()));
1570 result = myFurtherLanes.back()->geometryPositionAtOffset(backPos, -myFurtherLanesPosLat.back() * (MSGlobals::gLefthand ? -1 : 1));
1571 } else {
1572 result = myLane->geometryPositionAtOffset(0, posLat);
1573 }
1574 }
1575 }
1577 interpolateLateralZ(result, myState.myPos - myType->getLength(), posLat);
1578 }
1579 return result;
1580}
1581
1582
1583bool
1585 return !isStopped() && !myStops.empty() && myLane != nullptr && &myStops.front().lane->getEdge() == &myLane->getEdge();
1586}
1587
1588bool
1590 return isStopped() && myStops.front().lane == myLane;
1591}
1592
1593bool
1594MSVehicle::keepStopping(bool afterProcessing) const {
1595 if (isStopped()) {
1596 // when coming out of vehicleTransfer we must shift the time forward
1597 return (myStops.front().duration - (afterProcessing ? DELTA_T : 0) > 0 || isStoppedTriggered() || myStops.front().pars.collision
1598 || myStops.front().pars.breakDown || (myStops.front().getSpeed() > 0
1599 && (myState.myPos < MIN2(myStops.front().pars.endPos, myStops.front().lane->getLength() - POSITION_EPS))
1600 && (myStops.front().pars.parking == ParkingType::ONROAD || getSpeed() >= SUMO_const_haltingSpeed)));
1601 } else {
1602 return false;
1603 }
1604}
1605
1606
1609 if (isStopped()) {
1610 return myStops.front().duration;
1611 }
1612 return 0;
1613}
1614
1615
1618 return (myStops.empty() || !myStops.front().pars.collision) ? myCollisionImmunity : MAX2((SUMOTime)0, myStops.front().duration);
1619}
1620
1621
1622bool
1624 return isStopped() && !myStops.empty() && myStops.front().pars.breakDown;
1625}
1626
1627
1628bool
1630 return myCollisionImmunity > 0;
1631}
1632
1633
1634double
1635MSVehicle::processNextStop(double currentVelocity) {
1636 if (myStops.empty()) {
1637 // no stops; pass
1638 return currentVelocity;
1639 }
1640
1641#ifdef DEBUG_STOPS
1642 if (DEBUG_COND) {
1643 std::cout << "\nPROCESS_NEXT_STOP\n" << SIMTIME << " vehicle '" << getID() << "'" << std::endl;
1644 }
1645#endif
1646
1647 MSStop& stop = myStops.front();
1649 if (stop.reached) {
1650 stop.duration -= getActionStepLength();
1651
1652#ifdef DEBUG_STOPS
1653 if (DEBUG_COND) {
1654 std::cout << SIMTIME << " vehicle '" << getID() << "' reached stop.\n"
1655 << "Remaining duration: " << STEPS2TIME(stop.duration) << std::endl;
1656 if (stop.getSpeed() > 0) {
1657 std::cout << " waypointSpeed=" << stop.getSpeed() << " vehPos=" << myState.myPos << " endPos=" << stop.pars.endPos << "\n";
1658 }
1659 }
1660#endif
1661 if (stop.duration <= 0 && stop.pars.join != "") {
1662 // join this train (part) to another one
1663 MSVehicle* joinVeh = dynamic_cast<MSVehicle*>(MSNet::getInstance()->getVehicleControl().getVehicle(stop.pars.join));
1664 if (joinVeh && joinVeh->hasDeparted() && (joinVeh->joinTrainPart(this) || joinVeh->joinTrainPartFront(this))) {
1665 stop.joinTriggered = false;
1669 }
1670 // avoid collision warning before this vehicle is removed (joinVeh was already made longer)
1672 // mark this vehicle as arrived
1674 const_cast<SUMOVehicleParameter*>(myParameter)->arrivalEdge = getRoutePosition();
1675 // handle transportables that want to continue in the other vehicle
1676 if (myPersonDevice != nullptr) {
1678 }
1679 if (myContainerDevice != nullptr) {
1681 }
1682 }
1683 }
1684 boardTransportables(stop);
1685 if (time > stop.endBoarding) {
1686 // for taxi: cancel customers
1687 MSDevice_Taxi* taxiDevice = static_cast<MSDevice_Taxi*>(getDevice(typeid(MSDevice_Taxi)));
1688 if (taxiDevice != nullptr) {
1689 // may invalidate stops including the current reference
1690 taxiDevice->cancelCurrentCustomers();
1692 return currentVelocity;
1693 }
1694 }
1695 if (!keepStopping() && isOnRoad()) {
1696#ifdef DEBUG_STOPS
1697 if (DEBUG_COND) {
1698 std::cout << SIMTIME << " vehicle '" << getID() << "' resumes from stopping." << std::endl;
1699 }
1700#endif
1702 if (isRail() && hasStops()) {
1703 // stay on the current lane in case of a double stop
1704 const MSStop& nextStop = getNextStop();
1705 if (nextStop.edge == myCurrEdge) {
1706 const double stopSpeed = getCarFollowModel().stopSpeed(this, getSpeed(), nextStop.pars.endPos - myState.myPos);
1707 //std::cout << SIMTIME << " veh=" << getID() << " resumedFromStopping currentVelocity=" << currentVelocity << " stopSpeed=" << stopSpeed << "\n";
1708 return stopSpeed;
1709 }
1710 }
1711 } else {
1712 if (stop.triggered) {
1713 if (getVehicleType().getPersonCapacity() == getPersonNumber()) {
1714 WRITE_WARNINGF(TL("Vehicle '%' ignores triggered stop on lane '%' due to capacity constraints."), getID(), stop.lane->getID());
1715 stop.triggered = false;
1716 } else if (!myAmRegisteredAsWaiting && stop.duration <= DELTA_T) {
1717 // we can only register after waiting for one step. otherwise we might falsely signal a deadlock
1720#ifdef DEBUG_STOPS
1721 if (DEBUG_COND) {
1722 std::cout << SIMTIME << " vehicle '" << getID() << "' registers as waiting for person." << std::endl;
1723 }
1724#endif
1725 }
1726 }
1727 if (stop.containerTriggered) {
1728 if (getVehicleType().getContainerCapacity() == getContainerNumber()) {
1729 WRITE_WARNINGF(TL("Vehicle '%' ignores container triggered stop on lane '%' due to capacity constraints."), getID(), stop.lane->getID());
1730 stop.containerTriggered = false;
1731 } else if (stop.containerTriggered && !myAmRegisteredAsWaiting && stop.duration <= DELTA_T) {
1732 // we can only register after waiting for one step. otherwise we might falsely signal a deadlock
1735#ifdef DEBUG_STOPS
1736 if (DEBUG_COND) {
1737 std::cout << SIMTIME << " vehicle '" << getID() << "' registers as waiting for container." << std::endl;
1738 }
1739#endif
1740 }
1741 }
1742 // joining only takes place after stop duration is over
1744 && stop.duration <= (stop.pars.extension >= 0 ? -stop.pars.extension : 0)) {
1745 if (stop.pars.extension >= 0) {
1746 WRITE_WARNINGF(TL("Vehicle '%' aborts joining after extension of %s at time %."), getID(), STEPS2TIME(stop.pars.extension), time2string(SIMSTEP));
1747 stop.joinTriggered = false;
1748 } else {
1749 // keep stopping indefinitely but ensure that simulation terminates
1752 }
1753 }
1754 if (stop.getSpeed() > 0) {
1755 //waypoint mode
1756 if (stop.duration == 0) {
1757 return stop.getSpeed();
1758 } else {
1759 // stop for 'until' (computed in planMove)
1760 return currentVelocity;
1761 }
1762 } else {
1763 // brake
1765 return 0;
1766 } else {
1767 // ballistic:
1768 return getSpeed() - getCarFollowModel().getMaxDecel();
1769 }
1770 }
1771 }
1772 } else {
1773
1774#ifdef DEBUG_STOPS
1775 if (DEBUG_COND) {
1776 std::cout << SIMTIME << " vehicle '" << getID() << "' hasn't reached next stop." << std::endl;
1777 }
1778#endif
1779 //std::cout << SIMTIME << " myStopDist=" << myStopDist << " bGap=" << getBrakeGap(myLane->getVehicleMaxSpeed(this)) << "\n";
1780 if (stop.pars.onDemand && !stop.skipOnDemand && myStopDist <= getCarFollowModel().brakeGap(myLane->getVehicleMaxSpeed(this))) {
1781 MSNet* const net = MSNet::getInstance();
1782 const bool noExits = ((myPersonDevice == nullptr || !myPersonDevice->anyLeavingAtStop(stop))
1783 && (myContainerDevice == nullptr || !myContainerDevice->anyLeavingAtStop(stop)));
1784 const bool noEntries = ((!net->hasPersons() || !net->getPersonControl().hasAnyWaiting(stop.getEdge(), this))
1785 && (!net->hasContainers() || !net->getContainerControl().hasAnyWaiting(stop.getEdge(), this)));
1786 if (noExits && noEntries) {
1787 //std::cout << " skipOnDemand\n";
1788 stop.skipOnDemand = true;
1789 // bestLanes must be extended past this stop
1790 updateBestLanes(true);
1791 }
1792 }
1793 // is the next stop on the current lane?
1794 if (stop.edge == myCurrEdge) {
1795 // get the stopping position
1796 bool useStoppingPlace = stop.busstop != nullptr || stop.containerstop != nullptr || stop.parkingarea != nullptr;
1797 bool fitsOnStoppingPlace = true;
1798 if (!stop.skipOnDemand) { // no need to check available space if we skip it anyway
1799 if (stop.busstop != nullptr) {
1800 fitsOnStoppingPlace &= stop.busstop->fits(myState.myPos, *this);
1801 }
1802 if (stop.containerstop != nullptr) {
1803 fitsOnStoppingPlace &= stop.containerstop->fits(myState.myPos, *this);
1804 }
1805 // if the stop is a parking area we check if there is a free position on the area
1806 if (stop.parkingarea != nullptr) {
1807 fitsOnStoppingPlace &= myState.myPos > stop.parkingarea->getBeginLanePosition();
1808 if (stop.parkingarea->getOccupancy() >= stop.parkingarea->getCapacity()) {
1809 fitsOnStoppingPlace = false;
1810 // trigger potential parkingZoneReroute
1811 MSParkingArea* oldParkingArea = stop.parkingarea;
1812 for (MSMoveReminder* rem : myLane->getMoveReminders()) {
1813 if (rem->isParkingRerouter()) {
1814 rem->notifyEnter(*this, MSMoveReminder::NOTIFICATION_PARKING_REROUTE, myLane);
1815 }
1816 }
1817 if (myStops.empty() || myStops.front().parkingarea != oldParkingArea) {
1818 // rerouted, keep driving
1819 return currentVelocity;
1820 }
1821 } else if (stop.parkingarea->getOccupancyIncludingReservations(this) >= stop.parkingarea->getCapacity()) {
1822 fitsOnStoppingPlace = false;
1823 } else if (stop.parkingarea->parkOnRoad() && stop.parkingarea->getLotIndex(this) < 0) {
1824 fitsOnStoppingPlace = false;
1825 }
1826 }
1827 }
1828 const double targetPos = myState.myPos + myStopDist + (stop.getSpeed() > 0 ? (stop.pars.startPos - stop.pars.endPos) : 0);
1829 const double reachedThreshold = (useStoppingPlace ? targetPos - STOPPING_PLACE_OFFSET : stop.getReachedThreshold()) - NUMERICAL_EPS;
1830#ifdef DEBUG_STOPS
1831 if (DEBUG_COND) {
1832 std::cout << " pos=" << myState.pos() << " speed=" << currentVelocity << " targetPos=" << targetPos << " fits=" << fitsOnStoppingPlace
1833 << " reachedThresh=" << reachedThreshold
1834 << " myLane=" << Named::getIDSecure(myLane)
1835 << " stopLane=" << Named::getIDSecure(stop.lane)
1836 << "\n";
1837 }
1838#endif
1839 const bool posReached = myState.pos() >= reachedThreshold && currentVelocity <= stop.getSpeed() + SUMO_const_haltingSpeed && myLane == stop.lane;
1840 if (posReached && !fitsOnStoppingPlace && MSStopOut::active()) {
1841 MSStopOut::getInstance()->stopBlocked(this, time);
1842 }
1843 if (fitsOnStoppingPlace && posReached && (!MSGlobals::gModelParkingManoeuver || myManoeuvre.entryManoeuvreIsComplete(this))) {
1844 // ok, we may stop (have reached the stop) and either we are not modelling maneuvering or have completed entry
1845 stop.reached = true;
1846 if (!stop.startedFromState) {
1847 stop.pars.started = time;
1848 }
1849#ifdef DEBUG_STOPS
1850 if (DEBUG_COND) {
1851 std::cout << SIMTIME << " vehicle '" << getID() << "' reached next stop." << std::endl;
1852 }
1853#endif
1854 if (MSStopOut::active()) {
1856 }
1857 myLane->getEdge().addWaiting(this);
1860 // compute stopping time
1861 stop.duration = stop.getMinDuration(time);
1862 stop.endBoarding = stop.pars.extension >= 0 ? time + stop.duration + stop.pars.extension : SUMOTime_MAX;
1863 MSDevice_Taxi* taxiDevice = static_cast<MSDevice_Taxi*>(getDevice(typeid(MSDevice_Taxi)));
1864 if (taxiDevice != nullptr && stop.pars.extension >= 0) {
1865 // earliestPickupTime is set with waitUntil
1866 stop.endBoarding = MAX2(time, stop.pars.waitUntil) + stop.pars.extension;
1867 }
1868 if (stop.getSpeed() > 0) {
1869 // ignore duration parameter in waypoint mode unless 'until' or 'ended' are set
1870 if (stop.getUntil() > time) {
1871 stop.duration = stop.getUntil() - time;
1872 } else {
1873 stop.duration = 0;
1874 }
1875 }
1876 if (stop.busstop != nullptr) {
1877 // let the bus stop know the vehicle
1878 stop.busstop->enter(this, stop.pars.parking == ParkingType::OFFROAD);
1879 }
1880 if (stop.containerstop != nullptr) {
1881 // let the container stop know the vehicle
1883 }
1884 if (stop.parkingarea != nullptr && stop.getSpeed() <= 0) {
1885 // let the parking area know the vehicle
1886 stop.parkingarea->enter(this, stop.pars.parking == ParkingType::OFFROAD);
1887 }
1888 if (stop.chargingStation != nullptr) {
1889 // let the container stop know the vehicle
1891 }
1892
1893 if (stop.pars.tripId != "") {
1894 ((SUMOVehicleParameter&)getParameter()).setParameter("tripId", stop.pars.tripId);
1895 }
1896 if (stop.pars.line != "") {
1897 ((SUMOVehicleParameter&)getParameter()).line = stop.pars.line;
1898 }
1899 if (stop.pars.split != "") {
1900 // split the train
1901 MSVehicle* splitVeh = dynamic_cast<MSVehicle*>(MSNet::getInstance()->getVehicleControl().getVehicle(stop.pars.split));
1902 if (splitVeh == nullptr) {
1903 WRITE_WARNINGF(TL("Vehicle '%' to split from vehicle '%' is not known. time=%."), stop.pars.split, getID(), SIMTIME)
1904 } else {
1906 splitVeh->getRoute().getEdges()[0]->removeWaiting(splitVeh);
1908 const double newLength = MAX2(myType->getLength() - splitVeh->getVehicleType().getLength(),
1910 getSingularType().setLength(newLength);
1911 // handle transportables that want to continue in the split part
1912 if (myPersonDevice != nullptr) {
1914 }
1915 if (myContainerDevice != nullptr) {
1917 }
1919 const double backShift = splitVeh->getLength() + getVehicleType().getMinGap();
1920 myState.myPos -= backShift;
1921 myState.myBackPos -= backShift;
1922 }
1923 }
1924 }
1925
1926 boardTransportables(stop);
1927 if (stop.pars.posLat != INVALID_DOUBLE) {
1928 myState.myPosLat = stop.pars.posLat;
1929 }
1930 }
1931 }
1932 }
1933 return currentVelocity;
1934}
1935
1936
1937void
1939 if (stop.skipOnDemand) {
1940 return;
1941 }
1942 // we have reached the stop
1943 // any waiting persons may board now
1945 MSNet* const net = MSNet::getInstance();
1946 const bool boarded = (time <= stop.endBoarding
1947 && net->hasPersons()
1949 && stop.numExpectedPerson == 0);
1950 // load containers
1951 const bool loaded = (time <= stop.endBoarding
1952 && net->hasContainers()
1954 && stop.numExpectedContainer == 0);
1955
1956 bool unregister = false;
1957 if (time > stop.endBoarding) {
1958 stop.triggered = false;
1959 stop.containerTriggered = false;
1961 unregister = true;
1963 }
1964 }
1965 if (boarded) {
1966 // the triggering condition has been fulfilled. Maybe we want to wait a bit longer for additional riders (car pooling)
1968 unregister = true;
1969 }
1970 stop.triggered = false;
1972 }
1973 if (loaded) {
1974 // the triggering condition has been fulfilled
1976 unregister = true;
1977 }
1978 stop.containerTriggered = false;
1980 }
1981
1982 if (unregister) {
1984#ifdef DEBUG_STOPS
1985 if (DEBUG_COND) {
1986 std::cout << SIMTIME << " vehicle '" << getID() << "' unregisters as waiting for transportable." << std::endl;
1987 }
1988#endif
1989 }
1990}
1991
1992bool
1994 // check if veh is close enough to be joined to the rear of this vehicle
1995 MSLane* backLane = myFurtherLanes.size() == 0 ? myLane : myFurtherLanes.back();
1996 double gap = getBackPositionOnLane() - veh->getPositionOnLane();
1997 if (isStopped() && myStops.begin()->duration <= DELTA_T && myStops.begin()->joinTriggered && backLane == veh->getLane()
1998 && gap >= 0 && gap <= getVehicleType().getMinGap() + 1) {
1999 const double newLength = myType->getLength() + veh->getVehicleType().getLength();
2000 getSingularType().setLength(newLength);
2001 myStops.begin()->joinTriggered = false;
2005 }
2006 return true;
2007 } else {
2008 return false;
2009 }
2010}
2011
2012
2013bool
2015 // check if veh is close enough to be joined to the front of this vehicle
2016 MSLane* backLane = veh->myFurtherLanes.size() == 0 ? veh->myLane : veh->myFurtherLanes.back();
2017 double gap = veh->getBackPositionOnLane(backLane) - getPositionOnLane();
2018 if (isStopped() && myStops.begin()->duration <= DELTA_T && myStops.begin()->joinTriggered && backLane == getLane()
2019 && gap >= 0 && gap <= getVehicleType().getMinGap() + 1) {
2020 double skippedLaneLengths = 0;
2021 if (veh->myFurtherLanes.size() > 0) {
2022 skippedLaneLengths += getLane()->getLength();
2023 // this vehicle must be moved to the lane of veh
2024 // ensure that lane and furtherLanes of veh match our route
2025 int routeIndex = getRoutePosition();
2026 if (myLane->isInternal()) {
2027 routeIndex++;
2028 }
2029 for (int i = (int)veh->myFurtherLanes.size() - 1; i >= 0; i--) {
2030 MSEdge* edge = &veh->myFurtherLanes[i]->getEdge();
2031 if (edge->isInternal()) {
2032 continue;
2033 }
2034 if (!edge->isInternal() && edge != myRoute->getEdges()[routeIndex]) {
2035 std::string warn = TL("Cannot join vehicle '%' to vehicle '%' due to incompatible routes. time=%.");
2036 WRITE_WARNINGF(warn, veh->getID(), getID(), time2string(SIMSTEP));
2037 return false;
2038 }
2039 routeIndex++;
2040 }
2041 if (veh->getCurrentEdge()->getNormalSuccessor() != myRoute->getEdges()[routeIndex]) {
2042 std::string warn = TL("Cannot join vehicle '%' to vehicle '%' due to incompatible routes. time=%.");
2043 WRITE_WARNINGF(warn, veh->getID(), getID(), time2string(SIMSTEP));
2044 return false;
2045 }
2046 for (int i = (int)veh->myFurtherLanes.size() - 2; i >= 0; i--) {
2047 skippedLaneLengths += veh->myFurtherLanes[i]->getLength();
2048 }
2049 }
2050
2051 const double newLength = myType->getLength() + veh->getVehicleType().getLength();
2052 getSingularType().setLength(newLength);
2053 // lane will be advanced just as for regular movement
2054 myState.myPos = skippedLaneLengths + veh->getPositionOnLane();
2055 myStops.begin()->joinTriggered = false;
2059 }
2060 return true;
2061 } else {
2062 return false;
2063 }
2064}
2065
2066double
2067MSVehicle::getBrakeGap(bool delayed) const {
2068 return getCarFollowModel().brakeGap(getSpeed(), getCarFollowModel().getMaxDecel(), delayed ? getCarFollowModel().getHeadwayTime() : 0);
2069}
2070
2071
2072bool
2075 if (myActionStep) {
2076 myLastActionTime = t;
2077 }
2078 return myActionStep;
2079}
2080
2081
2082void
2083MSVehicle::resetActionOffset(const SUMOTime timeUntilNextAction) {
2084 myLastActionTime = MSNet::getInstance()->getCurrentTimeStep() + timeUntilNextAction;
2085}
2086
2087
2088void
2089MSVehicle::updateActionOffset(const SUMOTime oldActionStepLength, const SUMOTime newActionStepLength) {
2091 SUMOTime timeSinceLastAction = now - myLastActionTime;
2092 if (timeSinceLastAction == 0) {
2093 // Action was scheduled now, may be delayed be new action step length
2094 timeSinceLastAction = oldActionStepLength;
2095 }
2096 if (timeSinceLastAction >= newActionStepLength) {
2097 // Action point required in this step
2098 myLastActionTime = now;
2099 } else {
2100 SUMOTime timeUntilNextAction = newActionStepLength - timeSinceLastAction;
2101 resetActionOffset(timeUntilNextAction);
2102 }
2103}
2104
2105
2106
2107void
2108MSVehicle::planMove(const SUMOTime t, const MSLeaderInfo& ahead, const double lengthsInFront) {
2109#ifdef DEBUG_PLAN_MOVE
2110 if (DEBUG_COND) {
2111 std::cout
2112 << "\nPLAN_MOVE\n"
2113 << SIMTIME
2114 << std::setprecision(gPrecision)
2115 << " veh=" << getID()
2116 << " lane=" << myLane->getID()
2117 << " pos=" << getPositionOnLane()
2118 << " posLat=" << getLateralPositionOnLane()
2119 << " speed=" << getSpeed()
2120 << "\n";
2121 }
2122#endif
2123 // Update the driver state
2124 if (hasDriverState()) {
2126 setActionStepLength(myDriverState->getDriverState()->getActionStepLength(), false);
2127 }
2128
2130 if (!checkActionStep(t)) {
2131#ifdef DEBUG_ACTIONSTEPS
2132 if (DEBUG_COND) {
2133 std::cout << STEPS2TIME(t) << " vehicle '" << getID() << "' skips action." << std::endl;
2134 }
2135#endif
2136 // During non-action passed drive items still need to be removed
2137 // @todo rather work with updating myCurrentDriveItem (refs #3714)
2139 return;
2140 } else {
2141#ifdef DEBUG_ACTIONSTEPS
2142 if (DEBUG_COND) {
2143 std::cout << STEPS2TIME(t) << " vehicle = '" << getID() << "' takes action." << std::endl;
2144 }
2145#endif
2147 if (myInfluencer != nullptr) {
2149 }
2151#ifdef DEBUG_PLAN_MOVE
2152 if (DEBUG_COND) {
2153 DriveItemVector::iterator i;
2154 for (i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
2155 std::cout
2156 << " vPass=" << (*i).myVLinkPass
2157 << " vWait=" << (*i).myVLinkWait
2158 << " linkLane=" << ((*i).myLink == 0 ? "NULL" : (*i).myLink->getViaLaneOrLane()->getID())
2159 << " request=" << (*i).mySetRequest
2160 << "\n";
2161 }
2162 }
2163#endif
2164 checkRewindLinkLanes(lengthsInFront, myLFLinkLanes);
2166 // ideally would only do this with the call inside planMoveInternal - but that needs a const method
2167 // so this is a kludge here - nuisance as it adds an extra check in a busy loop
2171 }
2172 }
2173 }
2175}
2176
2177
2178bool
2179MSVehicle::brakeForOverlap(const MSLink* link, const MSLane* lane) const {
2180 // @review needed
2181 //const double futurePosLat = getLateralPositionOnLane() + link->getLateralShift();
2182 //const double overlap = getLateralOverlap(futurePosLat, link->getViaLaneOrLane());
2183 //const double edgeWidth = link->getViaLaneOrLane()->getEdge().getWidth();
2184 const double futurePosLat = getLateralPositionOnLane() + (
2185 lane != myLane && lane->isInternal() ? lane->getIncomingLanes()[0].viaLink->getLateralShift() : 0);
2186 const double overlap = getLateralOverlap(futurePosLat, lane);
2187 const double edgeWidth = lane->getEdge().getWidth();
2188 const bool result = (overlap > POSITION_EPS
2189 // do not get stuck on narrow edges
2190 && getVehicleType().getWidth() <= edgeWidth
2191 && link->getViaLane() == nullptr
2192 // this is the exit link of a junction. The normal edge should support the shadow
2193 && ((myLaneChangeModel->getShadowLane(link->getLane()) == nullptr)
2194 // the shadow lane must be permitted
2195 || !myLaneChangeModel->getShadowLane(link->getLane())->allowsVehicleClass(getVClass())
2196 // the internal lane after an internal junction has no parallel lane. make sure there is no shadow before continuing
2197 || (lane->getEdge().isInternal() && lane->getIncomingLanes()[0].lane->getEdge().isInternal()))
2198 // ignore situations where the shadow lane is part of a double-connection with the current lane
2199 && (myLaneChangeModel->getShadowLane() == nullptr
2200 || myLaneChangeModel->getShadowLane()->getLinkCont().size() == 0
2201 || myLaneChangeModel->getShadowLane()->getLinkCont().front()->getLane() != link->getLane())
2202 // emergency vehicles may do some crazy stuff
2204
2205#ifdef DEBUG_PLAN_MOVE
2206 if (DEBUG_COND) {
2207 std::cout << SIMTIME << " veh=" << getID() << " link=" << link->getDescription() << " lane=" << lane->getID()
2208 << " linkLane=" << link->getLane()->getID()
2209 << " shadowLane=" << Named::getIDSecure(myLaneChangeModel->getShadowLane())
2210 << " shift=" << link->getLateralShift()
2211 << " fpLat=" << futurePosLat << " overlap=" << overlap << " w=" << getVehicleType().getWidth()
2212 << " shadowLane=" << Named::getIDSecure(myLaneChangeModel->getShadowLane(link->getLane()))
2213 << " result=" << result << "\n";
2214 }
2215#endif
2216 return result;
2217}
2218
2219
2220
2221void
2222MSVehicle::planMoveInternal(const SUMOTime t, MSLeaderInfo ahead, DriveItemVector& lfLinks, double& newStopDist, double& newStopSpeed, std::pair<double, const MSLink*>& nextTurn) const {
2223 lfLinks.clear();
2224 newStopDist = std::numeric_limits<double>::max();
2225 //
2226 const MSCFModel& cfModel = getCarFollowModel();
2227 const double vehicleLength = getVehicleType().getLength();
2228 const double maxV = cfModel.maxNextSpeed(myState.mySpeed, this);
2229 const double maxVD = MAX2(getMaxSpeed(), MIN2(maxV, getDesiredMaxSpeed()));
2230 const bool opposite = myLaneChangeModel->isOpposite();
2231 // maxVD is possibly higher than vType-maxSpeed and in this case laneMaxV may be higher as well
2232 double laneMaxV = myLane->getVehicleMaxSpeed(this, maxVD);
2233 const double vMinComfortable = cfModel.minNextSpeed(getSpeed(), this);
2234 double lateralShift = 0;
2235 if (isRail()) {
2236 // speed limits must hold for the whole length of the train
2237 for (MSLane* l : myFurtherLanes) {
2238 laneMaxV = MIN2(laneMaxV, l->getVehicleMaxSpeed(this, maxVD));
2239#ifdef DEBUG_PLAN_MOVE
2240 if (DEBUG_COND) {
2241 std::cout << " laneMaxV=" << laneMaxV << " lane=" << l->getID() << "\n";
2242 }
2243#endif
2244 }
2245 }
2246 // speed limits are not emergencies (e.g. when the limit changes suddenly due to TraCI or a variableSpeedSignal)
2247 laneMaxV = MAX2(laneMaxV, vMinComfortable);
2249 laneMaxV = std::numeric_limits<double>::max();
2250 }
2251 // v is the initial maximum velocity of this vehicle in this step
2252 double v = cfModel.maximumLaneSpeedCF(this, maxV, laneMaxV);
2253 // if we are modelling parking then we dawdle until the manoeuvre is complete - by setting a very low max speed
2254 // in practice this only applies to exit manoeuvre because entry manoeuvre just delays setting stop.reached - when the vehicle is virtually stopped
2257 }
2258
2259 if (myInfluencer != nullptr) {
2260 const double vMin = MAX2(0., cfModel.minNextSpeed(myState.mySpeed, this));
2261#ifdef DEBUG_TRACI
2262 if (DEBUG_COND) {
2263 std::cout << SIMTIME << " veh=" << getID() << " speedBeforeTraci=" << v;
2264 }
2265#endif
2266 v = myInfluencer->influenceSpeed(t, v, v, vMin, maxV);
2267#ifdef DEBUG_TRACI
2268 if (DEBUG_COND) {
2269 std::cout << " influencedSpeed=" << v;
2270 }
2271#endif
2272 v = myInfluencer->gapControlSpeed(t, this, v, v, vMin, maxV);
2273#ifdef DEBUG_TRACI
2274 if (DEBUG_COND) {
2275 std::cout << " gapControlSpeed=" << v << "\n";
2276 }
2277#endif
2278 }
2279 // all links within dist are taken into account (potentially)
2280 const double dist = SPEED2DIST(maxV) + cfModel.brakeGap(maxV);
2281
2282 const std::vector<MSLane*>& bestLaneConts = getBestLanesContinuation();
2283#ifdef DEBUG_PLAN_MOVE
2284 if (DEBUG_COND) {
2285 std::cout << " dist=" << dist << " bestLaneConts=" << toString(bestLaneConts)
2286 << "\n maxV=" << maxV << " laneMaxV=" << laneMaxV << " v=" << v << "\n";
2287 }
2288#endif
2289 assert(bestLaneConts.size() > 0);
2290 bool hadNonInternal = false;
2291 // the distance already "seen"; in the following always up to the end of the current "lane"
2292 double seen = opposite ? myState.myPos : myLane->getLength() - myState.myPos;
2293 nextTurn.first = seen;
2294 nextTurn.second = nullptr;
2295 bool encounteredTurn = (MSGlobals::gLateralResolution <= 0); // next turn is only needed for sublane
2296 double seenNonInternal = 0;
2297 double seenInternal = myLane->isInternal() ? seen : 0;
2298 double vLinkPass = MIN2(cfModel.estimateSpeedAfterDistance(seen, v, cfModel.getMaxAccel()), laneMaxV); // upper bound
2299 int view = 0;
2300 DriveProcessItem* lastLink = nullptr;
2301 bool slowedDownForMinor = false; // whether the vehicle already had to slow down on approach to a minor link
2302 double mustSeeBeforeReversal = 0;
2303 // iterator over subsequent lanes and fill lfLinks until stopping distance or stopped
2304 const MSLane* lane = opposite ? myLane->getParallelOpposite() : myLane;
2305 assert(lane != 0);
2306 const MSLane* leaderLane = myLane;
2307 bool foundRailSignal = !isRail();
2308 bool planningToStop = false;
2309#ifdef PARALLEL_STOPWATCH
2310 myLane->getStopWatch()[0].start();
2311#endif
2312
2313 // optionally slow down to match arrival time
2314 const double sfp = getVehicleType().getParameter().speedFactorPremature;
2315 if (v > vMinComfortable && hasStops() && myStops.front().pars.arrival >= 0 && sfp > 0
2316 && v > myLane->getSpeedLimit() * sfp
2317 && !myStops.front().reached) {
2318 const double vSlowDown = slowDownForSchedule(vMinComfortable);
2319 v = MIN2(v, vSlowDown);
2320 }
2321 auto stopIt = myStops.begin();
2322 while (true) {
2323 // check leader on lane
2324 // leader is given for the first edge only
2325 if (opposite &&
2326 (leaderLane->getVehicleNumberWithPartials() > 1
2327 || (leaderLane != myLane && leaderLane->getVehicleNumber() > 0))) {
2328 ahead.clear();
2329 // find opposite-driving leader that must be respected on the currently looked at lane
2330 // (only looking at one lane at a time)
2331 const double backOffset = leaderLane == myLane ? getPositionOnLane() : leaderLane->getLength();
2332 const double gapOffset = leaderLane == myLane ? 0 : seen - leaderLane->getLength();
2333 const MSLeaderDistanceInfo cands = leaderLane->getFollowersOnConsecutive(this, backOffset, true, backOffset, MSLane::MinorLinkMode::FOLLOW_NEVER);
2334 MSLeaderDistanceInfo oppositeLeaders(leaderLane->getWidth(), this, 0.);
2335 const double minTimeToLeaveLane = MSGlobals::gSublane ? MAX2(TS, (0.5 * myLane->getWidth() - getLateralPositionOnLane()) / getVehicleType().getMaxSpeedLat()) : TS;
2336 for (int i = 0; i < cands.numSublanes(); i++) {
2337 CLeaderDist cand = cands[i];
2338 if (cand.first != 0) {
2339 if ((cand.first->myLaneChangeModel->isOpposite() && cand.first->getLaneChangeModel().getShadowLane() != leaderLane)
2340 || (!cand.first->myLaneChangeModel->isOpposite() && cand.first->getLaneChangeModel().getShadowLane() == leaderLane)) {
2341 // respect leaders that also drive in the opposite direction (fully or with some overlap)
2342 oppositeLeaders.addLeader(cand.first, cand.second + gapOffset - getVehicleType().getMinGap() + cand.first->getVehicleType().getMinGap() - cand.first->getVehicleType().getLength());
2343 } else {
2344 // avoid frontal collision
2345 const bool assumeStopped = cand.first->isStopped() || cand.first->getWaitingSeconds() > 1;
2346 const double predMaxDist = cand.first->getSpeed() + (assumeStopped ? 0 : cand.first->getCarFollowModel().getMaxAccel()) * minTimeToLeaveLane;
2347 if (cand.second >= 0 && (cand.second - v * minTimeToLeaveLane - predMaxDist < 0 || assumeStopped)) {
2348 oppositeLeaders.addLeader(cand.first, cand.second + gapOffset - predMaxDist - getVehicleType().getMinGap());
2349 }
2350 }
2351 }
2352 }
2353#ifdef DEBUG_PLAN_MOVE
2354 if (DEBUG_COND) {
2355 std::cout << " leaderLane=" << leaderLane->getID() << " gapOffset=" << gapOffset << " minTimeToLeaveLane=" << minTimeToLeaveLane
2356 << " cands=" << cands.toString() << " oppositeLeaders=" << oppositeLeaders.toString() << "\n";
2357 }
2358#endif
2359 adaptToLeaderDistance(oppositeLeaders, 0, seen, lastLink, v, vLinkPass);
2360 } else {
2362 const double rightOL = getRightSideOnLane(lane) + lateralShift;
2363 const double leftOL = getLeftSideOnLane(lane) + lateralShift;
2364 const bool outsideLeft = leftOL > lane->getWidth();
2365#ifdef DEBUG_PLAN_MOVE
2366 if (DEBUG_COND) {
2367 std::cout << SIMTIME << " veh=" << getID() << " lane=" << lane->getID() << " rightOL=" << rightOL << " leftOL=" << leftOL << "\n";
2368 }
2369#endif
2370 if (rightOL < 0 || outsideLeft) {
2371 MSLeaderInfo outsideLeaders(lane->getWidth());
2372 // if ego is driving outside lane bounds we must consider
2373 // potential leaders that are also outside bounds
2374 int sublaneOffset = 0;
2375 if (outsideLeft) {
2376 sublaneOffset = MIN2(-1, -(int)ceil((leftOL - lane->getWidth()) / MSGlobals::gLateralResolution));
2377 } else {
2378 sublaneOffset = MAX2(1, (int)ceil(-rightOL / MSGlobals::gLateralResolution));
2379 }
2380 outsideLeaders.setSublaneOffset(sublaneOffset);
2381#ifdef DEBUG_PLAN_MOVE
2382 if (DEBUG_COND) {
2383 std::cout << SIMTIME << " veh=" << getID() << " lane=" << lane->getID() << " sublaneOffset=" << sublaneOffset << " outsideLeft=" << outsideLeft << "\n";
2384 }
2385#endif
2386 for (const MSVehicle* cand : lane->getVehiclesSecure()) {
2387 if ((lane != myLane || cand->getPositionOnLane() > getPositionOnLane())
2388 && ((!outsideLeft && cand->getLeftSideOnEdge() < 0)
2389 || (outsideLeft && cand->getLeftSideOnEdge() > lane->getEdge().getWidth()))) {
2390 outsideLeaders.addLeader(cand, true);
2391#ifdef DEBUG_PLAN_MOVE
2392 if (DEBUG_COND) {
2393 std::cout << " outsideLeader=" << cand->getID() << " ahead=" << outsideLeaders.toString() << "\n";
2394 }
2395#endif
2396 }
2397 }
2398 lane->releaseVehicles();
2399 if (outsideLeaders.hasVehicles()) {
2400 adaptToLeaders(outsideLeaders, lateralShift, seen, lastLink, leaderLane, v, vLinkPass);
2401 }
2402 }
2403 }
2404 adaptToLeaders(ahead, lateralShift, seen, lastLink, leaderLane, v, vLinkPass);
2405 }
2406 if (lastLink != nullptr) {
2407 lastLink->myVLinkWait = MIN2(lastLink->myVLinkWait, v);
2408 }
2409#ifdef DEBUG_PLAN_MOVE
2410 if (DEBUG_COND) {
2411 std::cout << "\nv = " << v << "\n";
2412
2413 }
2414#endif
2415 // XXX efficiently adapt to shadow leaders using neighAhead by iteration over the whole edge in parallel (lanechanger-style)
2416 if (myLaneChangeModel->getShadowLane() != nullptr) {
2417 // also slow down for leaders on the shadowLane relative to the current lane
2418 const MSLane* shadowLane = myLaneChangeModel->getShadowLane(leaderLane);
2419 if (shadowLane != nullptr
2420 && (MSGlobals::gLateralResolution > 0 || getLateralOverlap() > POSITION_EPS
2421 // continous lane change cannot be stopped so we must adapt to the leader on the target lane
2423 if ((&shadowLane->getEdge() == &leaderLane->getEdge() || myLaneChangeModel->isOpposite())) {
2426 // ego posLat is added when retrieving sublanes but it
2427 // should be negated (subtract twice to compensate)
2428 latOffset = ((myLane->getWidth() + shadowLane->getWidth()) * 0.5
2429 - 2 * getLateralPositionOnLane());
2430
2431 }
2432 MSLeaderInfo shadowLeaders = shadowLane->getLastVehicleInformation(this, latOffset, lane->getLength() - seen);
2433#ifdef DEBUG_PLAN_MOVE
2435 std::cout << SIMTIME << " opposite veh=" << getID() << " shadowLane=" << shadowLane->getID() << " latOffset=" << latOffset << " shadowLeaders=" << shadowLeaders.toString() << "\n";
2436 }
2437#endif
2439 // ignore oncoming vehicles on the shadow lane
2440 shadowLeaders.removeOpposite(shadowLane);
2441 }
2442 const double turningDifference = MAX2(0.0, leaderLane->getLength() - shadowLane->getLength());
2443 adaptToLeaders(shadowLeaders, latOffset, seen - turningDifference, lastLink, shadowLane, v, vLinkPass);
2444 } else if (shadowLane == myLaneChangeModel->getShadowLane() && leaderLane == myLane) {
2445 // check for leader vehicles driving in the opposite direction on the opposite-direction shadow lane
2446 // (and thus in the same direction as ego)
2447 MSLeaderDistanceInfo shadowLeaders = shadowLane->getFollowersOnConsecutive(this, myLane->getOppositePos(getPositionOnLane()), true);
2448 const double latOffset = 0;
2449#ifdef DEBUG_PLAN_MOVE
2450 if (DEBUG_COND) {
2451 std::cout << SIMTIME << " opposite shadows veh=" << getID() << " shadowLane=" << shadowLane->getID()
2452 << " latOffset=" << latOffset << " shadowLeaders=" << shadowLeaders.toString() << "\n";
2453 }
2454#endif
2455 shadowLeaders.fixOppositeGaps(true);
2456#ifdef DEBUG_PLAN_MOVE
2457 if (DEBUG_COND) {
2458 std::cout << " shadowLeadersFixed=" << shadowLeaders.toString() << "\n";
2459 }
2460#endif
2461 adaptToLeaderDistance(shadowLeaders, latOffset, seen, lastLink, v, vLinkPass);
2462 }
2463 }
2464 }
2465 // adapt to pedestrians on the same lane
2466 if (lane->getEdge().getPersons().size() > 0 && lane->hasPedestrians()) {
2467 const double relativePos = lane->getLength() - seen;
2468#ifdef DEBUG_PLAN_MOVE
2469 if (DEBUG_COND) {
2470 std::cout << SIMTIME << " adapt to pedestrians on lane=" << lane->getID() << " relPos=" << relativePos << "\n";
2471 }
2472#endif
2473 const double stopTime = MAX2(1.0, ceil(getSpeed() / cfModel.getMaxDecel()));
2474 PersonDist leader = lane->nextBlocking(relativePos,
2475 getRightSideOnLane(lane), getRightSideOnLane(lane) + getVehicleType().getWidth(), stopTime);
2476 if (leader.first != 0) {
2477 const double stopSpeed = cfModel.stopSpeed(this, getSpeed(), leader.second - getVehicleType().getMinGap());
2478 v = MIN2(v, stopSpeed);
2479#ifdef DEBUG_PLAN_MOVE
2480 if (DEBUG_COND) {
2481 std::cout << SIMTIME << " pedLeader=" << leader.first->getID() << " dist=" << leader.second << " v=" << v << "\n";
2482 }
2483#endif
2484 }
2485 }
2486 if (lane->getBidiLane() != nullptr) {
2487 // adapt to pedestrians on the bidi lane
2488 const MSLane* bidiLane = lane->getBidiLane();
2489 if (bidiLane->getEdge().getPersons().size() > 0 && bidiLane->hasPedestrians()) {
2490 const double relativePos = seen;
2491#ifdef DEBUG_PLAN_MOVE
2492 if (DEBUG_COND) {
2493 std::cout << SIMTIME << " adapt to pedestrians on lane=" << lane->getID() << " relPos=" << relativePos << "\n";
2494 }
2495#endif
2496 const double stopTime = ceil(getSpeed() / cfModel.getMaxDecel());
2497 const double leftSideOnLane = bidiLane->getWidth() - getRightSideOnLane(lane);
2498 PersonDist leader = bidiLane->nextBlocking(relativePos,
2499 leftSideOnLane - getVehicleType().getWidth(), leftSideOnLane, stopTime, true);
2500 if (leader.first != 0) {
2501 const double stopSpeed = cfModel.stopSpeed(this, getSpeed(), leader.second - getVehicleType().getMinGap());
2502 v = MIN2(v, stopSpeed);
2503#ifdef DEBUG_PLAN_MOVE
2504 if (DEBUG_COND) {
2505 std::cout << SIMTIME << " pedLeader=" << leader.first->getID() << " dist=" << leader.second << " v=" << v << "\n";
2506 }
2507#endif
2508 }
2509 }
2510 }
2511 // adapt to vehicles blocked from (urgent) lane-changing
2512 if (!opposite && lane->getEdge().hasLaneChanger()) {
2513 const double vHelp = myLaneChangeModel->getCooperativeHelpSpeed(lane, seen);
2514#ifdef DEBUG_PLAN_MOVE
2515 if (DEBUG_COND && vHelp < v) {
2516 std::cout << SIMTIME << " applying cooperativeHelpSpeed v=" << vHelp << "\n";
2517 }
2518#endif
2519 v = MIN2(v, vHelp);
2520 }
2521
2522 // process all stops and waypoints on the current edge
2523 bool foundRealStop = false;
2524 while (stopIt != myStops.end()
2525 && ((&stopIt->lane->getEdge() == &lane->getEdge())
2526 || (stopIt->isOpposite && stopIt->lane->getEdge().getOppositeEdge() == &lane->getEdge()))
2527 // ignore stops that occur later in a looped route
2528 && stopIt->edge == myCurrEdge + view) {
2529 double stopDist = std::numeric_limits<double>::max();
2530 const MSStop& stop = *stopIt;
2531 const bool isFirstStop = stopIt == myStops.begin();
2532 stopIt++;
2533 if (!stop.reached || (stop.getSpeed() > 0 && keepStopping())) {
2534 // we are approaching a stop on the edge; must not drive further
2535 bool isWaypoint = stop.getSpeed() > 0;
2536 double endPos = stop.getEndPos(*this) + NUMERICAL_EPS;
2537 if (stop.parkingarea != nullptr) {
2538 // leave enough space so parking vehicles can exit
2539 const double brakePos = getBrakeGap() + lane->getLength() - seen;
2540 endPos = stop.parkingarea->getLastFreePosWithReservation(t, *this, brakePos);
2541 } else if (isWaypoint && !stop.reached) {
2542 endPos = stop.pars.startPos;
2543 }
2544 stopDist = seen + endPos - lane->getLength();
2545#ifdef DEBUG_STOPS
2546 if (DEBUG_COND) {
2547 std::cout << SIMTIME << " veh=" << getID() << " stopDist=" << stopDist << " stopLane=" << stop.lane->getID() << " stopEndPos=" << endPos << "\n";
2548 }
2549#endif
2550 double stopSpeed = laneMaxV;
2551 if (isWaypoint) {
2552 bool waypointWithStop = false;
2553 if (stop.getUntil() > t) {
2554 // check if we have to slow down or even stop
2555 SUMOTime time2end = 0;
2556 if (stop.reached) {
2557 time2end = TIME2STEPS((stop.pars.endPos - myState.myPos) / stop.getSpeed());
2558 } else {
2559 time2end = TIME2STEPS(
2560 // time to reach waypoint start
2561 stopDist / ((getSpeed() + stop.getSpeed()) / 2)
2562 // time to reach waypoint end
2563 + (stop.pars.endPos - stop.pars.startPos) / stop.getSpeed());
2564 }
2565 if (stop.getUntil() > t + time2end) {
2566 // we need to stop
2567 double distToEnd = stopDist;
2568 if (!stop.reached) {
2569 distToEnd += stop.pars.endPos - stop.pars.startPos;
2570 }
2571 stopSpeed = MAX2(cfModel.stopSpeed(this, getSpeed(), distToEnd), vMinComfortable);
2572 waypointWithStop = true;
2573 }
2574 }
2575 if (stop.reached) {
2576 stopSpeed = MIN2(stop.getSpeed(), stopSpeed);
2577 if (myState.myPos >= stop.pars.endPos && !waypointWithStop) {
2578 stopDist = std::numeric_limits<double>::max();
2579 }
2580 } else {
2581 stopSpeed = MIN2(MAX2(cfModel.freeSpeed(this, getSpeed(), stopDist, stop.getSpeed()), vMinComfortable), stopSpeed);
2582 if (!stop.reached) {
2583 stopDist += stop.pars.endPos - stop.pars.startPos;
2584 }
2585 if (lastLink != nullptr) {
2586 lastLink->adaptLeaveSpeed(cfModel.freeSpeed(this, vLinkPass, endPos, stop.getSpeed(), false, MSCFModel::CalcReason::FUTURE));
2587 }
2588 }
2589 } else {
2590 stopSpeed = cfModel.stopSpeed(this, getSpeed(), stopDist);
2591 if (!instantStopping()) {
2592 // regular stops are not emergencies
2593 stopSpeed = MAX2(stopSpeed, vMinComfortable);
2595 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
2596 speedTimeLine.push_back(std::make_pair(SIMSTEP, getSpeed()));
2597 speedTimeLine.push_back(std::make_pair(SIMSTEP + DELTA_T, stopSpeed));
2598 myInfluencer->setSpeedTimeLine(speedTimeLine);
2599 }
2600 if (lastLink != nullptr) {
2601 lastLink->adaptLeaveSpeed(cfModel.stopSpeed(this, vLinkPass, endPos, MSCFModel::CalcReason::FUTURE));
2602 }
2603 }
2604 newStopSpeed = MIN2(newStopSpeed, stopSpeed);
2605 v = MIN2(v, stopSpeed);
2606 if (lane->isInternal()) {
2607 std::vector<MSLink*>::const_iterator exitLink = MSLane::succLinkSec(*this, view + 1, *lane, bestLaneConts);
2608 assert(!lane->isLinkEnd(exitLink));
2609 bool dummySetRequest;
2610 double dummyVLinkWait;
2611 checkLinkLeaderCurrentAndParallel(*exitLink, lane, seen, lastLink, v, vLinkPass, dummyVLinkWait, dummySetRequest);
2612 }
2613
2614#ifdef DEBUG_PLAN_MOVE
2615 if (DEBUG_COND) {
2616 std::cout << "\n" << SIMTIME << " next stop: distance = " << stopDist << " requires stopSpeed = " << stopSpeed << "\n";
2617
2618 }
2619#endif
2620 if (isFirstStop) {
2621 newStopDist = stopDist;
2622 // if the vehicle is going to stop we don't need to look further
2623 // (except for trains that make use of further link-approach registration for safety purposes)
2624 if (!isWaypoint) {
2625 planningToStop = true;
2626 if (!isRail()) {
2627 lfLinks.emplace_back(v, stopDist);
2628 foundRealStop = true;
2629 break;
2630 }
2631 }
2632 }
2633 }
2634 }
2635 if (foundRealStop) {
2636 break;
2637 }
2638
2639 // move to next lane
2640 // get the next link used
2641 std::vector<MSLink*>::const_iterator link = MSLane::succLinkSec(*this, view + 1, *lane, bestLaneConts);
2642 if (lane->isLinkEnd(link) && myLaneChangeModel->hasBlueLight() && myCurrEdge != myRoute->end() - 1) {
2643 // emergency vehicle is on the wrong lane. Obtain the link that it would use from the correct turning lane
2644 const int currentIndex = lane->getIndex();
2645 const MSLane* bestJump = nullptr;
2646 for (const LaneQ& preb : getBestLanes()) {
2647 if (preb.allowsContinuation &&
2648 (bestJump == nullptr
2649 || abs(currentIndex - preb.lane->getIndex()) < abs(currentIndex - bestJump->getIndex()))) {
2650 bestJump = preb.lane;
2651 }
2652 }
2653 if (bestJump != nullptr) {
2654 const MSEdge* nextEdge = *(myCurrEdge + 1);
2655 for (auto cand_it = bestJump->getLinkCont().begin(); cand_it != bestJump->getLinkCont().end(); cand_it++) {
2656 if (&(*cand_it)->getLane()->getEdge() == nextEdge) {
2657 link = cand_it;
2658 break;
2659 }
2660 }
2661 }
2662 }
2663
2664 // Check whether this is a turn (to save info about the next upcoming turn)
2665 if (!encounteredTurn) {
2666 if (!lane->isLinkEnd(link) && lane->getLinkCont().size() > 1) {
2667 LinkDirection linkDir = (*link)->getDirection();
2668 switch (linkDir) {
2671 break;
2672 default:
2673 nextTurn.first = seen;
2674 nextTurn.second = *link;
2675 encounteredTurn = true;
2676#ifdef DEBUG_NEXT_TURN
2677 if (DEBUG_COND) {
2678 std::cout << SIMTIME << " veh '" << getID() << "' nextTurn: " << toString(linkDir)
2679 << " at " << nextTurn.first << "m." << std::endl;
2680 }
2681#endif
2682 }
2683 }
2684 }
2685
2686 // check whether the vehicle is on its final edge
2687 if (myCurrEdge + view + 1 == myRoute->end()
2688 || (myParameter->arrivalEdge >= 0 && getRoutePosition() + view == myParameter->arrivalEdge)) {
2689 const double arrivalSpeed = (myParameter->arrivalSpeedProcedure == ArrivalSpeedDefinition::GIVEN ?
2690 myParameter->arrivalSpeed : laneMaxV);
2691 // subtract the arrival speed from the remaining distance so we get one additional driving step with arrival speed
2692 // XXX: This does not work for ballistic update refs #2579
2693 const double distToArrival = seen + myArrivalPos - lane->getLength() - SPEED2DIST(arrivalSpeed);
2694 const double va = MAX2(NUMERICAL_EPS, cfModel.freeSpeed(this, getSpeed(), distToArrival, arrivalSpeed));
2695 v = MIN2(v, va);
2696 if (lastLink != nullptr) {
2697 lastLink->adaptLeaveSpeed(va);
2698 }
2699 lfLinks.push_back(DriveProcessItem(v, seen, lane->getEdge().isFringe() ? 1000 : 0));
2700 break;
2701 }
2702 // check whether the lane or the shadowLane is a dead end (allow some leeway on intersections)
2703 if (lane->isLinkEnd(link)
2704 || (MSGlobals::gSublane && brakeForOverlap(*link, lane))
2705 || (opposite && (*link)->getViaLaneOrLane()->getParallelOpposite() == nullptr
2707 double va = cfModel.stopSpeed(this, getSpeed(), seen);
2708 if (lastLink != nullptr) {
2709 lastLink->adaptLeaveSpeed(va);
2710 }
2713 } else {
2714 v = MIN2(va, v);
2715 }
2716#ifdef DEBUG_PLAN_MOVE
2717 if (DEBUG_COND) {
2718 std::cout << " braking for link end lane=" << lane->getID() << " seen=" << seen
2719 << " overlap=" << getLateralOverlap() << " va=" << va << " committed=" << myLaneChangeModel->getCommittedSpeed() << " v=" << v << "\n";
2720
2721 }
2722#endif
2723 if (lane->isLinkEnd(link)) {
2724 lfLinks.emplace_back(v, seen);
2725 break;
2726 }
2727 }
2728 lateralShift += (*link)->getLateralShift();
2729 const bool yellowOrRed = (*link)->haveRed() || (*link)->haveYellow();
2730 // We distinguish 3 cases when determining the point at which a vehicle stops:
2731 // - allway_stop: the vehicle should stop close to the stop line but may stop at larger distance
2732 // - red/yellow light: here the vehicle 'knows' that it will have priority eventually and does not need to stop on a precise spot
2733 // - other types of minor links: the vehicle needs to stop as close to the junction as necessary
2734 // to minimize the time window for passing the junction. If the
2735 // vehicle 'decides' to accelerate and cannot enter the junction in
2736 // the next step, new foes may appear and cause a collision (see #1096)
2737 // - major links: stopping point is irrelevant
2738 double laneStopOffset;
2739 const double majorStopOffset = MAX2(getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_STOPLINE_GAP, DIST_TO_STOPLINE_EXPECT_PRIORITY), lane->getVehicleStopOffset(this));
2740 // override low desired decel at yellow and red
2741 const double stopDecel = yellowOrRed && !isRail() ? MAX2(MIN2(MSGlobals::gTLSYellowMinDecel, cfModel.getEmergencyDecel()), cfModel.getMaxDecel()) : cfModel.getMaxDecel();
2742 const double brakeDist = cfModel.brakeGap(myState.mySpeed, stopDecel, 0);
2743 const bool canBrakeBeforeLaneEnd = seen >= brakeDist;
2744 const bool canBrakeBeforeStopLine = seen - lane->getVehicleStopOffset(this) >= brakeDist;
2745 if (yellowOrRed) {
2746 // Wait at red traffic light with full distance if possible
2747 laneStopOffset = majorStopOffset;
2748 } else if ((*link)->havePriority()) {
2749 // On priority link, we should never stop below visibility distance
2750 laneStopOffset = MIN2((*link)->getFoeVisibilityDistance() - POSITION_EPS, majorStopOffset);
2751 } else {
2752 double minorStopOffset = MAX2(lane->getVehicleStopOffset(this),
2753 getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_STOPLINE_CROSSING_GAP, MSPModel::SAFETY_GAP) - (*link)->getDistToFoePedCrossing());
2754#ifdef DEBUG_PLAN_MOVE
2755 if (DEBUG_COND) {
2756 std::cout << " minorStopOffset=" << minorStopOffset << " distToFoePedCrossing=" << (*link)->getDistToFoePedCrossing() << "\n";
2757 }
2758#endif
2759 if ((*link)->getState() == LINKSTATE_ALLWAY_STOP) {
2760 minorStopOffset = MAX2(minorStopOffset, getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_STOPLINE_GAP, 0));
2761 } else {
2762 minorStopOffset = MAX2(minorStopOffset, getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_STOPLINE_GAP_MINOR, 0));
2763 }
2764 // On minor link, we should likewise never stop below visibility distance
2765 laneStopOffset = MIN2((*link)->getFoeVisibilityDistance() - POSITION_EPS, minorStopOffset);
2766 }
2767#ifdef DEBUG_PLAN_MOVE
2768 if (DEBUG_COND) {
2769 std::cout << SIMTIME << " veh=" << getID() << " desired stopOffset on lane '" << lane->getID() << "' is " << laneStopOffset << "\n";
2770 }
2771#endif
2772 if (canBrakeBeforeLaneEnd) {
2773 // avoid emergency braking if possible
2774 laneStopOffset = MIN2(laneStopOffset, seen - brakeDist);
2775 }
2776 laneStopOffset = MAX2(POSITION_EPS, laneStopOffset);
2777 double stopDist = MAX2(0., seen - laneStopOffset);
2778 if (yellowOrRed && getDevice(typeid(MSDevice_GLOSA)) != nullptr
2779 && static_cast<MSDevice_GLOSA*>(getDevice(typeid(MSDevice_GLOSA)))->getOverrideSafety()
2780 && static_cast<MSDevice_GLOSA*>(getDevice(typeid(MSDevice_GLOSA)))->isSpeedAdviceActive()) {
2781 stopDist = std::numeric_limits<double>::max();
2782 }
2783 if (newStopDist != std::numeric_limits<double>::max()) {
2784 stopDist = MAX2(stopDist, newStopDist);
2785 }
2786#ifdef DEBUG_PLAN_MOVE
2787 if (DEBUG_COND) {
2788 std::cout << SIMTIME << " veh=" << getID() << " effective stopOffset on lane '" << lane->getID()
2789 << "' is " << laneStopOffset << " (-> stopDist=" << stopDist << ")" << std::endl;
2790 }
2791#endif
2792 if (isRail()
2793 && !lane->isInternal()) {
2794 // check for train direction reversal
2795 if (lane->getBidiLane() != nullptr
2796 && (*link)->getLane()->getBidiLane() == lane) {
2797 double vMustReverse = getCarFollowModel().stopSpeed(this, getSpeed(), seen - POSITION_EPS);
2798 if (seen < 1) {
2799 mustSeeBeforeReversal = 2 * seen + getLength();
2800 }
2801 v = MIN2(v, vMustReverse);
2802 }
2803 // signal that is passed in the current step does not count
2804 foundRailSignal |= ((*link)->getTLLogic() != nullptr
2805 && (*link)->getTLLogic()->getLogicType() == TrafficLightType::RAIL_SIGNAL
2806 && seen > SPEED2DIST(v));
2807 }
2808
2809 bool canReverseEventually = false;
2810 const double vReverse = checkReversal(canReverseEventually, laneMaxV, seen);
2811 v = MIN2(v, vReverse);
2812#ifdef DEBUG_PLAN_MOVE
2813 if (DEBUG_COND) {
2814 std::cout << SIMTIME << " veh=" << getID() << " canReverseEventually=" << canReverseEventually << " v=" << v << "\n";
2815 }
2816#endif
2817
2818 // check whether we need to slow down in order to finish a continuous lane change
2820 if ( // slow down to finish lane change before a turn lane
2821 ((*link)->getDirection() == LinkDirection::LEFT || (*link)->getDirection() == LinkDirection::RIGHT) ||
2822 // slow down to finish lane change before the shadow lane ends
2823 (myLaneChangeModel->getShadowLane() != nullptr &&
2824 (*link)->getViaLaneOrLane()->getParallelLane(myLaneChangeModel->getShadowDirection()) == nullptr)) {
2825 // XXX maybe this is too harsh. Vehicles could cut some corners here
2826 const double timeRemaining = STEPS2TIME(myLaneChangeModel->remainingTime());
2827 assert(timeRemaining != 0);
2828 // XXX: Euler-logic (#860), but I couldn't identify problems from this yet (Leo). Refs. #2575
2829 const double va = MAX2(cfModel.stopSpeed(this, getSpeed(), seen - POSITION_EPS),
2830 (seen - POSITION_EPS) / timeRemaining);
2831#ifdef DEBUG_PLAN_MOVE
2832 if (DEBUG_COND) {
2833 std::cout << SIMTIME << " veh=" << getID() << " slowing down to finish continuous change before"
2834 << " link=" << (*link)->getViaLaneOrLane()->getID()
2835 << " timeRemaining=" << timeRemaining
2836 << " v=" << v
2837 << " va=" << va
2838 << std::endl;
2839 }
2840#endif
2841 v = MIN2(va, v);
2842 }
2843 }
2844
2845 // - always issue a request to leave the intersection we are currently on
2846 const bool leavingCurrentIntersection = myLane->getEdge().isInternal() && lastLink == nullptr;
2847 // - do not issue a request to enter an intersection after we already slowed down for an earlier one
2848 const bool abortRequestAfterMinor = slowedDownForMinor && (*link)->getInternalLaneBefore() == nullptr;
2849 // - even if red, if we cannot break we should issue a request
2850 bool setRequest = (v > NUMERICAL_EPS_SPEED && !abortRequestAfterMinor) || (leavingCurrentIntersection);
2851
2852 double stopSpeed = cfModel.stopSpeed(this, getSpeed(), stopDist, stopDecel, MSCFModel::CalcReason::CURRENT_WAIT);
2853 double vLinkWait = MIN2(v, stopSpeed);
2854#ifdef DEBUG_PLAN_MOVE
2855 if (DEBUG_COND) {
2856 std::cout
2857 << " stopDist=" << stopDist
2858 << " stopDecel=" << stopDecel
2859 << " vLinkWait=" << vLinkWait
2860 << " brakeDist=" << brakeDist
2861 << " seen=" << seen
2862 << " leaveIntersection=" << leavingCurrentIntersection
2863 << " setRequest=" << setRequest
2864 //<< std::setprecision(16)
2865 //<< " v=" << v
2866 //<< " speedEps=" << NUMERICAL_EPS_SPEED
2867 //<< std::setprecision(gPrecision)
2868 << "\n";
2869 }
2870#endif
2871
2872 if (yellowOrRed && canBrakeBeforeStopLine && !ignoreRed(*link, canBrakeBeforeStopLine) && seen >= mustSeeBeforeReversal) {
2873 if (lane->isInternal()) {
2874 checkLinkLeaderCurrentAndParallel(*link, lane, seen, lastLink, v, vLinkPass, vLinkWait, setRequest);
2875 }
2876 // arrivalSpeed / arrivalTime when braking for red light is only relevent for rail signal switching
2877 const SUMOTime arrivalTime = getArrivalTime(t, seen, v, vLinkPass);
2878 // the vehicle is able to brake in front of a yellow/red traffic light
2879 lfLinks.push_back(DriveProcessItem(*link, v, vLinkWait, false, arrivalTime, vLinkWait, 0, seen, -1));
2880 //lfLinks.push_back(DriveProcessItem(0, vLinkWait, vLinkWait, false, 0, 0, stopDist));
2881 break;
2882 }
2883
2884 const MSLink* entryLink = (*link)->getCorrespondingEntryLink();
2885 if (entryLink->haveRed() && ignoreRed(*link, canBrakeBeforeStopLine) && STEPS2TIME(t - entryLink->getLastStateChange()) > 2) {
2886 // restrict speed when ignoring a red light
2887 const double redSpeed = MIN2(v, getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_DRIVE_RED_SPEED, v));
2888 const double va = MAX2(redSpeed, cfModel.freeSpeed(this, getSpeed(), seen, redSpeed));
2889 v = MIN2(va, v);
2890#ifdef DEBUG_PLAN_MOVE
2891 if (DEBUG_COND) std::cout
2892 << " ignoreRed spent=" << STEPS2TIME(t - (*link)->getLastStateChange())
2893 << " redSpeed=" << redSpeed
2894 << " va=" << va
2895 << " v=" << v
2896 << "\n";
2897#endif
2898 }
2899
2900 checkLinkLeaderCurrentAndParallel(*link, lane, seen, lastLink, v, vLinkPass, vLinkWait, setRequest);
2901
2902 if (lastLink != nullptr) {
2903 lastLink->adaptLeaveSpeed(laneMaxV);
2904 }
2905 double arrivalSpeed = vLinkPass;
2906 // vehicles should decelerate when approaching a minor link
2907 // - unless they are close enough to have clear visibility of all relevant foe lanes and may start to accelerate again
2908 // - and unless they are so close that stopping is impossible (i.e. when a green light turns to yellow when close to the junction)
2909
2910 // whether the vehicle/driver is close enough to the link to see all possible foes #2123
2911 const double visibilityDistance = (*link)->getFoeVisibilityDistance();
2912 const double determinedFoePresence = seen <= visibilityDistance;
2913// // VARIANT: account for time needed to recognize whether relevant vehicles are on the foe lanes. (Leo)
2914// double foeRecognitionTime = 0.0;
2915// double determinedFoePresence = seen < visibilityDistance - myState.mySpeed*foeRecognitionTime;
2916
2917#ifdef DEBUG_PLAN_MOVE
2918 if (DEBUG_COND) {
2919 std::cout << " approaching link=" << (*link)->getViaLaneOrLane()->getID() << " prio=" << (*link)->havePriority() << " seen=" << seen << " visibilityDistance=" << visibilityDistance << " brakeDist=" << brakeDist << "\n";
2920 }
2921#endif
2922
2923 const bool couldBrakeForMinor = !(*link)->havePriority() && brakeDist < seen && !(*link)->lastWasContMajor();
2924 if (couldBrakeForMinor && !determinedFoePresence) {
2925 // vehicle decelerates just enough to be able to stop if necessary and then accelerates
2926 double maxSpeedAtVisibilityDist = cfModel.maximumSafeStopSpeed(visibilityDistance, cfModel.getMaxDecel(), myState.mySpeed, false, 0., false);
2927 // XXX: estimateSpeedAfterDistance does not use euler-logic (thus returns a lower value than possible here...)
2928 double maxArrivalSpeed = cfModel.estimateSpeedAfterDistance(visibilityDistance, maxSpeedAtVisibilityDist, cfModel.getMaxAccel());
2929 arrivalSpeed = MIN2(vLinkPass, maxArrivalSpeed);
2930 slowedDownForMinor = true;
2931#ifdef DEBUG_PLAN_MOVE
2932 if (DEBUG_COND) {
2933 std::cout << " slowedDownForMinor maxSpeedAtVisDist=" << maxSpeedAtVisibilityDist << " maxArrivalSpeed=" << maxArrivalSpeed << " arrivalSpeed=" << arrivalSpeed << "\n";
2934 }
2935#endif
2936 } else if ((*link)->getState() == LINKSTATE_EQUAL && myWaitingTime > 0) {
2937 // check for deadlock (circular yielding)
2938 //std::cout << SIMTIME << " veh=" << getID() << " check rbl-deadlock\n";
2939 std::pair<const SUMOVehicle*, const MSLink*> blocker = (*link)->getFirstApproachingFoe(*link);
2940 //std::cout << " blocker=" << Named::getIDSecure(blocker.first) << "\n";
2941 int n = 100;
2942 while (blocker.second != nullptr && blocker.second != *link && n > 0) {
2943 blocker = blocker.second->getFirstApproachingFoe(*link);
2944 n--;
2945 //std::cout << " blocker=" << Named::getIDSecure(blocker.first) << "\n";
2946 }
2947 if (n == 0) {
2948 WRITE_WARNINGF(TL("Suspicious right_before_left junction '%'."), lane->getEdge().getToJunction()->getID());
2949 }
2950 //std::cout << " blockerLink=" << blocker.second << " link=" << *link << "\n";
2951 if (blocker.second == *link) {
2952 const double threshold = (*link)->getDirection() == LinkDirection::STRAIGHT ? 0.25 : 0.75;
2953 if (RandHelper::rand(getRNG()) < threshold) {
2954 //std::cout << " abort request, threshold=" << threshold << "\n";
2955 setRequest = false;
2956 }
2957 }
2958 }
2959
2960 const SUMOTime arrivalTime = getArrivalTime(t, seen, v, arrivalSpeed);
2961 if (couldBrakeForMinor && determinedFoePresence && (*link)->getLane()->getEdge().isRoundabout()) {
2962 const bool wasOpened = (*link)->opened(arrivalTime, arrivalSpeed, arrivalSpeed,
2964 getCarFollowModel().getMaxDecel(),
2966 nullptr, false, this);
2967 if (!wasOpened) {
2968 slowedDownForMinor = true;
2969 }
2970#ifdef DEBUG_PLAN_MOVE
2971 if (DEBUG_COND) {
2972 std::cout << " slowedDownForMinor at roundabout=" << (!wasOpened) << "\n";
2973 }
2974#endif
2975 }
2976
2977 // compute arrival speed and arrival time if vehicle starts braking now
2978 // if stopping is possible, arrivalTime can be arbitrarily large. A small value keeps fractional times (impatience) meaningful
2979 double arrivalSpeedBraking = 0;
2980 const double bGap = cfModel.brakeGap(v);
2981 if (seen < bGap && !isStopped() && !planningToStop) { // XXX: should this use the current speed (at least for the ballistic case)? (Leo) Refs. #2575
2982 // vehicle cannot come to a complete stop in time
2984 arrivalSpeedBraking = cfModel.getMinimalArrivalSpeedEuler(seen, v);
2985 // due to discrete/continuous mismatch (when using Euler update) we have to ensure that braking actually helps
2986 arrivalSpeedBraking = MIN2(arrivalSpeedBraking, arrivalSpeed);
2987 } else {
2988 arrivalSpeedBraking = cfModel.getMinimalArrivalSpeed(seen, myState.mySpeed);
2989 }
2990 }
2991
2992 // estimate leave speed for passing time computation
2993 // l=linkLength, a=accel, t=continuousTime, v=vLeave
2994 // l=v*t + 0.5*a*t^2, solve for t and multiply with a, then add v
2995 const double estimatedLeaveSpeed = MIN2((*link)->getViaLaneOrLane()->getVehicleMaxSpeed(this, maxVD),
2996 getCarFollowModel().estimateSpeedAfterDistance((*link)->getLength(), arrivalSpeed, getVehicleType().getCarFollowModel().getMaxAccel()));
2997 lfLinks.push_back(DriveProcessItem(*link, v, vLinkWait, setRequest,
2998 arrivalTime, arrivalSpeed,
2999 arrivalSpeedBraking,
3000 seen, estimatedLeaveSpeed));
3001 if ((*link)->getViaLane() == nullptr) {
3002 hadNonInternal = true;
3003 ++view;
3004 }
3005#ifdef DEBUG_PLAN_MOVE
3006 if (DEBUG_COND) {
3007 std::cout << " checkAbort setRequest=" << setRequest << " v=" << v << " seen=" << seen << " dist=" << dist
3008 << " seenNonInternal=" << seenNonInternal
3009 << " seenInternal=" << seenInternal << " length=" << vehicleLength << "\n";
3010 }
3011#endif
3012 // we need to look ahead far enough to see available space for checkRewindLinkLanes
3013 if ((!setRequest || v <= 0 || seen > dist) && hadNonInternal && seenNonInternal > MAX2(vehicleLength * CRLL_LOOK_AHEAD, vehicleLength + seenInternal) && foundRailSignal) {
3014 break;
3015 }
3016 // get the following lane
3017 lane = (*link)->getViaLaneOrLane();
3018 laneMaxV = lane->getVehicleMaxSpeed(this, maxVD);
3020 laneMaxV = std::numeric_limits<double>::max();
3021 }
3022 // the link was passed
3023 // compute the velocity to use when the link is not blocked by other vehicles
3024 // the vehicle shall be not faster when reaching the next lane than allowed
3025 // speed limits are not emergencies (e.g. when the limit changes suddenly due to TraCI or a variableSpeedSignal)
3026 const double va = MAX2(cfModel.freeSpeed(this, getSpeed(), seen, laneMaxV), vMinComfortable);
3027 v = MIN2(va, v);
3028#ifdef DEBUG_PLAN_MOVE
3029 if (DEBUG_COND) {
3030 std::cout << " laneMaxV=" << laneMaxV << " freeSpeed=" << va << " v=" << v << "\n";
3031 }
3032#endif
3033 if (lane->getEdge().isInternal()) {
3034 seenInternal += lane->getLength();
3035 } else {
3036 seenNonInternal += lane->getLength();
3037 }
3038 // do not restrict results to the current vehicle to allow caching for the current time step
3039 leaderLane = opposite ? lane->getParallelOpposite() : lane;
3040 if (leaderLane == nullptr) {
3041
3042 break;
3043 }
3044 ahead = opposite ? MSLeaderInfo(leaderLane->getWidth()) : leaderLane->getLastVehicleInformation(nullptr, 0);
3045 seen += lane->getLength();
3046 vLinkPass = MIN2(cfModel.estimateSpeedAfterDistance(lane->getLength(), v, cfModel.getMaxAccel()), laneMaxV); // upper bound
3047 lastLink = &lfLinks.back();
3048 }
3049
3050//#ifdef DEBUG_PLAN_MOVE
3051// if(DEBUG_COND){
3052// std::cout << "planMoveInternal found safe speed v = " << v << std::endl;
3053// }
3054//#endif
3055
3056#ifdef PARALLEL_STOPWATCH
3057 myLane->getStopWatch()[0].stop();
3058#endif
3059}
3060
3061
3062double
3063MSVehicle::slowDownForSchedule(double vMinComfortable) const {
3064 const double sfp = getVehicleType().getParameter().speedFactorPremature;
3065 const MSStop& stop = myStops.front();
3066 std::pair<double, double> timeDist = estimateTimeToNextStop();
3067 double arrivalDelay = SIMTIME + timeDist.first - STEPS2TIME(stop.pars.arrival);
3068 double t = STEPS2TIME(stop.pars.arrival - SIMSTEP);
3071 arrivalDelay += STEPS2TIME(stop.pars.arrival - flexStart);
3072 t = STEPS2TIME(flexStart - SIMSTEP);
3073 } else if (stop.pars.started >= 0 && MSGlobals::gUseStopStarted) {
3074 arrivalDelay += STEPS2TIME(stop.pars.arrival - stop.pars.started);
3075 t = STEPS2TIME(stop.pars.started - SIMSTEP);
3076 }
3077 if (arrivalDelay < 0 && sfp < getChosenSpeedFactor()) {
3078 // we can slow down to better match the schedule (and increase energy efficiency)
3079 const double vSlowDownMin = MAX2(myLane->getSpeedLimit() * sfp, vMinComfortable);
3080 const double s = timeDist.second;
3081 const double b = getCarFollowModel().getMaxDecel();
3082 // x = speed for arriving in t seconds
3083 // u = time at full speed
3084 // u * x + (t - u) * 0.5 * x = s
3085 // t - u = x / b
3086 // eliminate u, solve x
3087 const double radicand = 4 * t * t * b * b - 8 * s * b;
3088 const double x = radicand >= 0 ? t * b - sqrt(radicand) * 0.5 : vSlowDownMin;
3089 double vSlowDown = x < vSlowDownMin ? vSlowDownMin : x;
3090#ifdef DEBUG_PLAN_MOVE
3091 if (DEBUG_COND) {
3092 std::cout << SIMTIME << " veh=" << getID() << " ad=" << arrivalDelay << " t=" << t << " vsm=" << vSlowDownMin
3093 << " r=" << radicand << " vs=" << vSlowDown << "\n";
3094 }
3095#endif
3096 return vSlowDown;
3097 } else if (arrivalDelay > 0 && sfp > getChosenSpeedFactor()) {
3098 // in principle we could up to catch up with the schedule
3099 // but at this point we can only lower the speed, the
3100 // information would have to be used when computing getVehicleMaxSpeed
3101 }
3102 return getMaxSpeed();
3103}
3104
3106MSVehicle::getArrivalTime(SUMOTime t, double seen, double v, double arrivalSpeed) const {
3107 const MSCFModel& cfModel = getCarFollowModel();
3108 SUMOTime arrivalTime;
3110 // @note intuitively it would make sense to compare arrivalSpeed with getSpeed() instead of v
3111 // however, due to the current position update rule (ticket #860) the vehicle moves with v in this step
3112 // subtract DELTA_T because t is the time at the end of this step and the movement is not carried out yet
3113 arrivalTime = t - DELTA_T + cfModel.getMinimalArrivalTime(seen, v, arrivalSpeed);
3114 } else {
3115 arrivalTime = t - DELTA_T + cfModel.getMinimalArrivalTime(seen, myState.mySpeed, arrivalSpeed);
3116 }
3117 if (isStopped()) {
3118 arrivalTime += MAX2((SUMOTime)0, myStops.front().duration);
3119 }
3120 return arrivalTime;
3121}
3122
3123
3124void
3125MSVehicle::adaptToLeaders(const MSLeaderInfo& ahead, double latOffset,
3126 const double seen, DriveProcessItem* const lastLink,
3127 const MSLane* const lane, double& v, double& vLinkPass) const {
3128 int rightmost;
3129 int leftmost;
3130 ahead.getSubLanes(this, latOffset, rightmost, leftmost);
3131#ifdef DEBUG_PLAN_MOVE
3132 if (DEBUG_COND) std::cout << SIMTIME
3133 << "\nADAPT_TO_LEADERS\nveh=" << getID()
3134 << " lane=" << lane->getID()
3135 << " latOffset=" << latOffset
3136 << " rm=" << rightmost
3137 << " lm=" << leftmost
3138 << " shift=" << ahead.getSublaneOffset()
3139 << " ahead=" << ahead.toString()
3140 << "\n";
3141#endif
3142 /*
3143 if (myLaneChangeModel->getCommittedSpeed() > 0) {
3144 v = MIN2(v, myLaneChangeModel->getCommittedSpeed());
3145 vLinkPass = MIN2(vLinkPass, myLaneChangeModel->getCommittedSpeed());
3146 #ifdef DEBUG_PLAN_MOVE
3147 if (DEBUG_COND) std::cout << " hasCommitted=" << myLaneChangeModel->getCommittedSpeed() << "\n";
3148 #endif
3149 return;
3150 }
3151 */
3152 for (int sublane = rightmost; sublane <= leftmost; ++sublane) {
3153 const MSVehicle* pred = ahead[sublane];
3154 if (pred != nullptr && pred != this) {
3155 // @todo avoid multiple adaptations to the same leader
3156 const double predBack = pred->getBackPositionOnLane(lane);
3157 double gap = (lastLink == nullptr
3158 ? predBack - myState.myPos - getVehicleType().getMinGap()
3159 : predBack + seen - lane->getLength() - getVehicleType().getMinGap());
3160 bool oncoming = false;
3162 if (pred->getLaneChangeModel().isOpposite() || lane == pred->getLaneChangeModel().getShadowLane()) {
3163 // ego might and leader are driving against lane
3164 gap = (lastLink == nullptr
3165 ? myState.myPos - predBack - getVehicleType().getMinGap()
3166 : predBack + seen - lane->getLength() - getVehicleType().getMinGap());
3167 } else {
3168 // ego and leader are driving in the same direction as lane (shadowlane for ego)
3169 gap = (lastLink == nullptr
3170 ? predBack - (myLane->getLength() - myState.myPos) - getVehicleType().getMinGap()
3171 : predBack + seen - lane->getLength() - getVehicleType().getMinGap());
3172 }
3173 } else if (pred->getLaneChangeModel().isOpposite() && pred->getLaneChangeModel().getShadowLane() != lane) {
3174 // must react to stopped / dangerous oncoming vehicles
3175 gap += -pred->getVehicleType().getLength() + getVehicleType().getMinGap() - MAX2(getVehicleType().getMinGap(), pred->getVehicleType().getMinGap());
3176 // try to avoid collision in the next second
3177 const double predMaxDist = pred->getSpeed() + pred->getCarFollowModel().getMaxAccel();
3178#ifdef DEBUG_PLAN_MOVE
3179 if (DEBUG_COND) {
3180 std::cout << " fixedGap=" << gap << " predMaxDist=" << predMaxDist << "\n";
3181 }
3182#endif
3183 if (gap < predMaxDist + getSpeed() || pred->getLane() == lane->getBidiLane()) {
3184 gap -= predMaxDist;
3185 }
3186 } else if (pred->getLane() == lane->getBidiLane()) {
3187 gap -= pred->getVehicleType().getLengthWithGap();
3188 oncoming = true;
3189 }
3190#ifdef DEBUG_PLAN_MOVE
3191 if (DEBUG_COND) {
3192 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";
3193 }
3194#endif
3195 if (oncoming && gap >= 0) {
3196 adaptToOncomingLeader(std::make_pair(pred, gap), lastLink, v, vLinkPass);
3197 } else {
3198 adaptToLeader(std::make_pair(pred, gap), seen, lastLink, v, vLinkPass);
3199 }
3200 }
3201 }
3202}
3203
3204void
3206 double seen,
3207 DriveProcessItem* const lastLink,
3208 double& v, double& vLinkPass) const {
3209 int rightmost;
3210 int leftmost;
3211 ahead.getSubLanes(this, latOffset, rightmost, leftmost);
3212#ifdef DEBUG_PLAN_MOVE
3213 if (DEBUG_COND) std::cout << SIMTIME
3214 << "\nADAPT_TO_LEADERS_DISTANCE\nveh=" << getID()
3215 << " latOffset=" << latOffset
3216 << " rm=" << rightmost
3217 << " lm=" << leftmost
3218 << " ahead=" << ahead.toString()
3219 << "\n";
3220#endif
3221 for (int sublane = rightmost; sublane <= leftmost; ++sublane) {
3222 CLeaderDist predDist = ahead[sublane];
3223 const MSVehicle* pred = predDist.first;
3224 if (pred != nullptr && pred != this) {
3225#ifdef DEBUG_PLAN_MOVE
3226 if (DEBUG_COND) {
3227 std::cout << " pred=" << pred->getID() << " predLane=" << pred->getLane()->getID() << " predPos=" << pred->getPositionOnLane() << " gap=" << predDist.second << "\n";
3228 }
3229#endif
3230 adaptToLeader(predDist, seen, lastLink, v, vLinkPass);
3231 }
3232 }
3233}
3234
3235
3236void
3237MSVehicle::adaptToLeader(const std::pair<const MSVehicle*, double> leaderInfo,
3238 double seen,
3239 DriveProcessItem* const lastLink,
3240 double& v, double& vLinkPass) const {
3241 if (leaderInfo.first != 0) {
3242 if (ignoreFoe(leaderInfo.first)) {
3243#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3244 if (DEBUG_COND) {
3245 std::cout << " foe ignored\n";
3246 }
3247#endif
3248 return;
3249 }
3250 const MSCFModel& cfModel = getCarFollowModel();
3251 double vsafeLeader = 0;
3253 vsafeLeader = -std::numeric_limits<double>::max();
3254 }
3255 bool backOnRoute = true;
3256 if (leaderInfo.second < 0 && lastLink != nullptr && lastLink->myLink != nullptr) {
3257 backOnRoute = false;
3258 // this can either be
3259 // a) a merging situation (leader back is is not our route) or
3260 // b) a minGap violation / collision
3261 MSLane* current = lastLink->myLink->getViaLaneOrLane();
3262 if (leaderInfo.first->getBackLane() == current) {
3263 backOnRoute = true;
3264 } else {
3265 for (MSLane* lane : getBestLanesContinuation()) {
3266 if (lane == current) {
3267 break;
3268 }
3269 if (leaderInfo.first->getBackLane() == lane) {
3270 backOnRoute = true;
3271 }
3272 }
3273 }
3274#ifdef DEBUG_PLAN_MOVE
3275 if (DEBUG_COND) {
3276 std::cout << SIMTIME << " current=" << current->getID() << " leaderBackLane=" << leaderInfo.first->getBackLane()->getID() << " backOnRoute=" << backOnRoute << "\n";
3277 }
3278#endif
3279 if (!backOnRoute) {
3280 double stopDist = seen - current->getLength() - POSITION_EPS;
3281 if (lastLink->myLink->getInternalLaneBefore() != nullptr) {
3282 // do not drive onto the junction conflict area
3283 stopDist -= lastLink->myLink->getInternalLaneBefore()->getLength();
3284 }
3285 vsafeLeader = cfModel.stopSpeed(this, getSpeed(), stopDist);
3286 }
3287 }
3288 if (backOnRoute) {
3289 vsafeLeader = cfModel.followSpeed(this, getSpeed(), leaderInfo.second, leaderInfo.first->getSpeed(), leaderInfo.first->getCurrentApparentDecel(), leaderInfo.first);
3290 }
3291 if (lastLink != nullptr) {
3292 const double futureVSafe = cfModel.followSpeed(this, lastLink->accelV, leaderInfo.second, leaderInfo.first->getSpeed(), leaderInfo.first->getCurrentApparentDecel(), leaderInfo.first, MSCFModel::CalcReason::FUTURE);
3293 lastLink->adaptLeaveSpeed(futureVSafe);
3294#ifdef DEBUG_PLAN_MOVE
3295 if (DEBUG_COND) {
3296 std::cout << " vlinkpass=" << lastLink->myVLinkPass << " futureVSafe=" << futureVSafe << "\n";
3297 }
3298#endif
3299 }
3300 v = MIN2(v, vsafeLeader);
3301 vLinkPass = MIN2(vLinkPass, vsafeLeader);
3302#ifdef DEBUG_PLAN_MOVE
3303 if (DEBUG_COND) std::cout
3304 << SIMTIME
3305 //std::cout << std::setprecision(10);
3306 << " veh=" << getID()
3307 << " lead=" << leaderInfo.first->getID()
3308 << " leadSpeed=" << leaderInfo.first->getSpeed()
3309 << " gap=" << leaderInfo.second
3310 << " leadLane=" << leaderInfo.first->getLane()->getID()
3311 << " predPos=" << leaderInfo.first->getPositionOnLane()
3312 << " myLane=" << myLane->getID()
3313 << " v=" << v
3314 << " vSafeLeader=" << vsafeLeader
3315 << " vLinkPass=" << vLinkPass
3316 << "\n";
3317#endif
3318 }
3319}
3320
3321
3322void
3323MSVehicle::adaptToJunctionLeader(const std::pair<const MSVehicle*, double> leaderInfo,
3324 const double seen, DriveProcessItem* const lastLink,
3325 const MSLane* const lane, double& v, double& vLinkPass,
3326 double distToCrossing) const {
3327 if (leaderInfo.first != 0) {
3328 if (ignoreFoe(leaderInfo.first)) {
3329#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3330 if (DEBUG_COND) {
3331 std::cout << " junction foe ignored\n";
3332 }
3333#endif
3334 return;
3335 }
3336 const MSCFModel& cfModel = getCarFollowModel();
3337 double vsafeLeader = 0;
3339 vsafeLeader = -std::numeric_limits<double>::max();
3340 }
3341 if (leaderInfo.second >= 0) {
3342 if (hasDeparted()) {
3343 vsafeLeader = cfModel.followSpeed(this, getSpeed(), leaderInfo.second, leaderInfo.first->getSpeed(), leaderInfo.first->getCurrentApparentDecel(), leaderInfo.first);
3344 } else {
3345 // called in the context of MSLane::isInsertionSuccess
3346 vsafeLeader = cfModel.insertionFollowSpeed(this, getSpeed(), leaderInfo.second, leaderInfo.first->getSpeed(), leaderInfo.first->getCurrentApparentDecel(), leaderInfo.first);
3347 }
3348 } else if (leaderInfo.first != this) {
3349 // the leading, in-lapping vehicle is occupying the complete next lane
3350 // stop before entering this lane
3351 vsafeLeader = cfModel.stopSpeed(this, getSpeed(), seen - lane->getLength() - POSITION_EPS);
3352#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3353 if (DEBUG_COND) {
3354 std::cout << SIMTIME << " veh=" << getID() << " stopping before junction: lane=" << lane->getID() << " seen=" << seen
3355 << " laneLength=" << lane->getLength()
3356 << " stopDist=" << seen - lane->getLength() - POSITION_EPS
3357 << " vsafeLeader=" << vsafeLeader
3358 << " distToCrossing=" << distToCrossing
3359 << "\n";
3360 }
3361#endif
3362 }
3363 if (distToCrossing >= 0) {
3364 // can the leader still stop in the way?
3365 const double vStop = cfModel.stopSpeed(this, getSpeed(), distToCrossing - getVehicleType().getMinGap());
3366 if (leaderInfo.first == this) {
3367 // braking for pedestrian
3368 const double vStopCrossing = cfModel.stopSpeed(this, getSpeed(), distToCrossing);
3369 vsafeLeader = vStopCrossing;
3370#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3371 if (DEBUG_COND) {
3372 std::cout << " breaking for pedestrian distToCrossing=" << distToCrossing << " vStopCrossing=" << vStopCrossing << "\n";
3373 }
3374#endif
3375 if (lastLink != nullptr) {
3376 lastLink->adaptStopSpeed(vsafeLeader);
3377 }
3378 } else if (leaderInfo.second == -std::numeric_limits<double>::max()) {
3379 // drive up to the crossing point and stop
3380#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3381 if (DEBUG_COND) {
3382 std::cout << " stop at crossing point for critical leader vStop=" << vStop << "\n";
3383 };
3384#endif
3385 vsafeLeader = MAX2(vsafeLeader, vStop);
3386 } else {
3387 const double leaderDistToCrossing = distToCrossing - leaderInfo.second;
3388 // estimate the time at which the leader has gone past the crossing point
3389 const double leaderPastCPTime = leaderDistToCrossing / MAX2(leaderInfo.first->getSpeed(), SUMO_const_haltingSpeed);
3390 // reach distToCrossing after that time
3391 // avgSpeed * leaderPastCPTime = distToCrossing
3392 // ballistic: avgSpeed = (getSpeed + vFinal) / 2
3393 const double vFinal = MAX2(getSpeed(), 2 * (distToCrossing - getVehicleType().getMinGap()) / leaderPastCPTime - getSpeed());
3394 const double v2 = getSpeed() + ACCEL2SPEED((vFinal - getSpeed()) / leaderPastCPTime);
3395 vsafeLeader = MAX2(vsafeLeader, MIN2(v2, vStop));
3396#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3397 if (DEBUG_COND) {
3398 std::cout << " driving up to the crossing point (distToCrossing=" << distToCrossing << ")"
3399 << " leaderPastCPTime=" << leaderPastCPTime
3400 << " vFinal=" << vFinal
3401 << " v2=" << v2
3402 << " vStop=" << vStop
3403 << " vsafeLeader=" << vsafeLeader << "\n";
3404 }
3405#endif
3406 }
3407 }
3408 if (lastLink != nullptr) {
3409 lastLink->adaptLeaveSpeed(vsafeLeader);
3410 }
3411 v = MIN2(v, vsafeLeader);
3412 vLinkPass = MIN2(vLinkPass, vsafeLeader);
3413#ifdef DEBUG_PLAN_MOVE
3414 if (DEBUG_COND) std::cout
3415 << SIMTIME
3416 //std::cout << std::setprecision(10);
3417 << " veh=" << getID()
3418 << " lead=" << leaderInfo.first->getID()
3419 << " leadSpeed=" << leaderInfo.first->getSpeed()
3420 << " gap=" << leaderInfo.second
3421 << " leadLane=" << leaderInfo.first->getLane()->getID()
3422 << " predPos=" << leaderInfo.first->getPositionOnLane()
3423 << " seen=" << seen
3424 << " lane=" << lane->getID()
3425 << " myLane=" << myLane->getID()
3426 << " dTC=" << distToCrossing
3427 << " v=" << v
3428 << " vSafeLeader=" << vsafeLeader
3429 << " vLinkPass=" << vLinkPass
3430 << "\n";
3431#endif
3432 }
3433}
3434
3435
3436void
3437MSVehicle::adaptToOncomingLeader(const std::pair<const MSVehicle*, double> leaderInfo,
3438 DriveProcessItem* const lastLink,
3439 double& v, double& vLinkPass) const {
3440 if (leaderInfo.first != 0) {
3441 if (ignoreFoe(leaderInfo.first)) {
3442#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3443 if (DEBUG_COND) {
3444 std::cout << " oncoming foe ignored\n";
3445 }
3446#endif
3447 return;
3448 }
3449 const MSCFModel& cfModel = getCarFollowModel();
3450 const MSVehicle* lead = leaderInfo.first;
3451 const MSCFModel& cfModelL = lead->getCarFollowModel();
3452 // assume the leader reacts symmetrically (neither stopping instantly nor ignoring ego)
3453 const double leaderBrakeGap = cfModelL.brakeGap(lead->getSpeed(), cfModelL.getMaxDecel(), 0);
3454 const double egoBrakeGap = cfModel.brakeGap(getSpeed(), cfModel.getMaxDecel(), 0);
3455 const double gapSum = leaderBrakeGap + egoBrakeGap;
3456 // ensure that both vehicles can leave an intersection if they are currently on it
3457 double egoExit = getDistanceToLeaveJunction();
3458 const double leaderExit = lead->getDistanceToLeaveJunction();
3459 double gap = leaderInfo.second;
3460 if (egoExit + leaderExit < gap) {
3461 gap -= egoExit + leaderExit;
3462 } else {
3463 egoExit = 0;
3464 }
3465 // split any distance in excess of brakeGaps evenly
3466 const double freeGap = MAX2(0.0, gap - gapSum);
3467 const double splitGap = MIN2(gap, gapSum);
3468 // assume remaining distance is allocated in proportion to braking distance
3469 const double gapRatio = gapSum > 0 ? egoBrakeGap / gapSum : 0.5;
3470 const double vsafeLeader = cfModel.stopSpeed(this, getSpeed(), splitGap * gapRatio + egoExit + 0.5 * freeGap);
3471 if (lastLink != nullptr) {
3472 const double futureVSafe = cfModel.stopSpeed(this, lastLink->accelV, leaderInfo.second, MSCFModel::CalcReason::FUTURE);
3473 lastLink->adaptLeaveSpeed(futureVSafe);
3474#ifdef DEBUG_PLAN_MOVE
3475 if (DEBUG_COND) {
3476 std::cout << " vlinkpass=" << lastLink->myVLinkPass << " futureVSafe=" << futureVSafe << "\n";
3477 }
3478#endif
3479 }
3480 v = MIN2(v, vsafeLeader);
3481 vLinkPass = MIN2(vLinkPass, vsafeLeader);
3482#ifdef DEBUG_PLAN_MOVE
3483 if (DEBUG_COND) std::cout
3484 << SIMTIME
3485 //std::cout << std::setprecision(10);
3486 << " veh=" << getID()
3487 << " oncomingLead=" << lead->getID()
3488 << " leadSpeed=" << lead->getSpeed()
3489 << " gap=" << leaderInfo.second
3490 << " gap2=" << gap
3491 << " gapRatio=" << gapRatio
3492 << " leadLane=" << lead->getLane()->getID()
3493 << " predPos=" << lead->getPositionOnLane()
3494 << " myLane=" << myLane->getID()
3495 << " v=" << v
3496 << " vSafeLeader=" << vsafeLeader
3497 << " vLinkPass=" << vLinkPass
3498 << "\n";
3499#endif
3500 }
3501}
3502
3503
3504void
3505MSVehicle::checkLinkLeaderCurrentAndParallel(const MSLink* link, const MSLane* lane, double seen,
3506 DriveProcessItem* const lastLink, double& v, double& vLinkPass, double& vLinkWait, bool& setRequest) const {
3508 // we want to pass the link but need to check for foes on internal lanes
3509 checkLinkLeader(link, lane, seen, lastLink, v, vLinkPass, vLinkWait, setRequest);
3510 if (myLaneChangeModel->getShadowLane() != nullptr) {
3511 const MSLink* const parallelLink = link->getParallelLink(myLaneChangeModel->getShadowDirection());
3512 if (parallelLink != nullptr) {
3513 checkLinkLeader(parallelLink, lane, seen, lastLink, v, vLinkPass, vLinkWait, setRequest, true);
3514 }
3515 }
3516 }
3517
3518}
3519
3520void
3521MSVehicle::checkLinkLeader(const MSLink* link, const MSLane* lane, double seen,
3522 DriveProcessItem* const lastLink, double& v, double& vLinkPass, double& vLinkWait, bool& setRequest,
3523 bool isShadowLink) const {
3524#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3525 if (DEBUG_COND) {
3526 gDebugFlag1 = true; // See MSLink::getLeaderInfo
3527 }
3528#endif
3529 const MSLink::LinkLeaders linkLeaders = link->getLeaderInfo(this, seen, nullptr, isShadowLink);
3530#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3531 if (DEBUG_COND) {
3532 gDebugFlag1 = false; // See MSLink::getLeaderInfo
3533 }
3534#endif
3535 for (MSLink::LinkLeaders::const_iterator it = linkLeaders.begin(); it != linkLeaders.end(); ++it) {
3536 // the vehicle to enter the junction first has priority
3537 const MSVehicle* leader = (*it).vehAndGap.first;
3538 if (leader == nullptr) {
3539 // leader is a pedestrian. Passing 'this' as a dummy.
3540#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3541 if (DEBUG_COND) {
3542 std::cout << SIMTIME << " veh=" << getID() << " is blocked on link to " << link->getViaLaneOrLane()->getID() << " by pedestrian. dist=" << it->distToCrossing << "\n";
3543 }
3544#endif
3547#ifdef DEBUG_PLAN_MOVE
3548 if (DEBUG_COND) {
3549 std::cout << SIMTIME << " veh=" << getID() << " is ignoring pedestrian (jmIgnoreJunctionFoeProb)\n";
3550 }
3551#endif
3552 continue;
3553 }
3554 adaptToJunctionLeader(std::make_pair(this, -1), seen, lastLink, lane, v, vLinkPass, it->distToCrossing);
3555 // if blocked by a pedestrian for too long we must yield our request
3557 setRequest = false;
3558#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3559 if (DEBUG_COND) {
3560 std::cout << " aborting request\n";
3561 }
3562#endif
3563 }
3564 } else if (isLeader(link, leader, (*it).vehAndGap.second) || (*it).inTheWay()) {
3567#ifdef DEBUG_PLAN_MOVE
3568 if (DEBUG_COND) {
3569 std::cout << SIMTIME << " veh=" << getID() << " is ignoring linkLeader=" << leader->getID() << " (jmIgnoreJunctionFoeProb)\n";
3570 }
3571#endif
3572 continue;
3573 }
3575 // sibling link (XXX: could also be partial occupator where this check fails)
3576 &leader->getLane()->getEdge() == &lane->getEdge()) {
3577 // check for sublane obstruction (trivial for sibling link leaders)
3578 const MSLane* conflictLane = link->getInternalLaneBefore();
3579 MSLeaderInfo linkLeadersAhead = MSLeaderInfo(conflictLane->getWidth());
3580 linkLeadersAhead.addLeader(leader, false, 0); // assume sibling lane has the same geometry as the leader lane
3581 const double latOffset = isShadowLink ? (getLane()->getRightSideOnEdge() - myLaneChangeModel->getShadowLane()->getRightSideOnEdge()) : 0;
3582 // leader is neither on lane nor conflictLane (the conflict is only established geometrically)
3583 adaptToLeaders(linkLeadersAhead, latOffset, seen, lastLink, leader->getLane(), v, vLinkPass);
3584#ifdef DEBUG_PLAN_MOVE
3585 if (DEBUG_COND) {
3586 std::cout << SIMTIME << " veh=" << getID()
3587 << " siblingFoe link=" << link->getViaLaneOrLane()->getID()
3588 << " isShadowLink=" << isShadowLink
3589 << " lane=" << lane->getID()
3590 << " foe=" << leader->getID()
3591 << " foeLane=" << leader->getLane()->getID()
3592 << " latOffset=" << latOffset
3593 << " latOffsetFoe=" << leader->getLatOffset(lane)
3594 << " linkLeadersAhead=" << linkLeadersAhead.toString()
3595 << "\n";
3596 }
3597#endif
3598 } else {
3599#ifdef DEBUG_PLAN_MOVE
3600 if (DEBUG_COND) {
3601 std::cout << SIMTIME << " veh=" << getID() << " linkLeader=" << leader->getID() << " gap=" << it->vehAndGap.second
3602 << " ET=" << myJunctionEntryTime << " lET=" << leader->myJunctionEntryTime
3603 << " ETN=" << myJunctionEntryTimeNeverYield << " lETN=" << leader->myJunctionEntryTimeNeverYield
3604 << " CET=" << myJunctionConflictEntryTime << " lCET=" << leader->myJunctionConflictEntryTime
3605 << "\n";
3606 }
3607#endif
3608 adaptToJunctionLeader(it->vehAndGap, seen, lastLink, lane, v, vLinkPass, it->distToCrossing);
3609 }
3610 if (lastLink != nullptr) {
3611 // we are not yet on the junction with this linkLeader.
3612 // at least we can drive up to the previous link and stop there
3613 v = MAX2(v, lastLink->myVLinkWait);
3614 }
3615 // if blocked by a leader from the same or next lane we must yield our request
3616 // also, if blocked by a stopped or blocked leader
3618 //&& leader->getSpeed() < SUMO_const_haltingSpeed
3620 || leader->getLane()->getLogicalPredecessorLane() == myLane
3621 || leader->isStopped()
3623 setRequest = false;
3624#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3625 if (DEBUG_COND) {
3626 std::cout << " aborting request\n";
3627 }
3628#endif
3629 if (lastLink != nullptr && leader->getLane()->getLogicalPredecessorLane() == myLane) {
3630 // we are not yet on the junction so must abort that request as well
3631 // (or maybe we are already on the junction and the leader is a partial occupator beyond)
3632 lastLink->mySetRequest = false;
3633#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3634 if (DEBUG_COND) {
3635 std::cout << " aborting previous request\n";
3636 }
3637#endif
3638 }
3639 }
3640 }
3641#ifdef DEBUG_PLAN_MOVE_LEADERINFO
3642 else {
3643 if (DEBUG_COND) {
3644 std::cout << SIMTIME << " veh=" << getID() << " ignoring leader " << leader->getID() << " gap=" << (*it).vehAndGap.second << " dtC=" << (*it).distToCrossing
3645 << " ET=" << myJunctionEntryTime << " lET=" << leader->myJunctionEntryTime
3646 << " ETN=" << myJunctionEntryTimeNeverYield << " lETN=" << leader->myJunctionEntryTimeNeverYield
3647 << " CET=" << myJunctionConflictEntryTime << " lCET=" << leader->myJunctionConflictEntryTime
3648 << "\n";
3649 }
3650 }
3651#endif
3652 }
3653 // if this is the link between two internal lanes we may have to slow down for pedestrians
3654 vLinkWait = MIN2(vLinkWait, v);
3655}
3656
3657
3658double
3659MSVehicle::getDeltaPos(const double accel) const {
3660 double vNext = myState.mySpeed + ACCEL2SPEED(accel);
3662 // apply implicit Euler positional update
3663 return SPEED2DIST(MAX2(vNext, 0.));
3664 } else {
3665 // apply ballistic update
3666 if (vNext >= 0) {
3667 // assume constant acceleration during this time step
3668 return SPEED2DIST(myState.mySpeed + 0.5 * ACCEL2SPEED(accel));
3669 } else {
3670 // negative vNext indicates a stop within the middle of time step
3671 // The corresponding stop time is s = mySpeed/deceleration \in [0,dt], and the
3672 // covered distance is therefore deltaPos = mySpeed*s - 0.5*deceleration*s^2.
3673 // Here, deceleration = (myState.mySpeed - vNext)/dt is the constant deceleration
3674 // until the vehicle stops.
3675 return -SPEED2DIST(0.5 * myState.mySpeed * myState.mySpeed / ACCEL2SPEED(accel));
3676 }
3677 }
3678}
3679
3680void
3681MSVehicle::processLinkApproaches(double& vSafe, double& vSafeMin, double& vSafeMinDist) {
3682
3683 // Speed limit due to zipper merging
3684 double vSafeZipper = std::numeric_limits<double>::max();
3685
3686 myHaveToWaitOnNextLink = false;
3687 bool canBrakeVSafeMin = false;
3688
3689 // Get safe velocities from DriveProcessItems.
3690 assert(myLFLinkLanes.size() != 0 || isRemoteControlled());
3691 for (const DriveProcessItem& dpi : myLFLinkLanes) {
3692 MSLink* const link = dpi.myLink;
3693
3694#ifdef DEBUG_EXEC_MOVE
3695 if (DEBUG_COND) {
3696 std::cout
3697 << SIMTIME
3698 << " veh=" << getID()
3699 << " link=" << (link == 0 ? "NULL" : link->getViaLaneOrLane()->getID())
3700 << " req=" << dpi.mySetRequest
3701 << " vP=" << dpi.myVLinkPass
3702 << " vW=" << dpi.myVLinkWait
3703 << " d=" << dpi.myDistance
3704 << "\n";
3705 gDebugFlag1 = true; // See MSLink_DEBUG_OPENED
3706 }
3707#endif
3708
3709 // the vehicle must change the lane on one of the next lanes (XXX: refs to code further below???, Leo)
3710 if (link != nullptr && dpi.mySetRequest) {
3711
3712 const LinkState ls = link->getState();
3713 // vehicles should brake when running onto a yellow light if the distance allows to halt in front
3714 const bool yellow = link->haveYellow();
3715 const bool canBrake = (dpi.myDistance > getCarFollowModel().brakeGap(myState.mySpeed, getCarFollowModel().getMaxDecel(), 0.)
3717 assert(link->getLaneBefore() != nullptr);
3718 const bool beyondStopLine = dpi.myDistance < link->getLaneBefore()->getVehicleStopOffset(this);
3719 const bool ignoreRedLink = ignoreRed(link, canBrake) || beyondStopLine;
3720 if (yellow && canBrake && !ignoreRedLink) {
3721 vSafe = dpi.myVLinkWait;
3723#ifdef DEBUG_CHECKREWINDLINKLANES
3724 if (DEBUG_COND) {
3725 std::cout << SIMTIME << " veh=" << getID() << " haveToWait (yellow)\n";
3726 }
3727#endif
3728 break;
3729 }
3730 const bool influencerPrio = (myInfluencer != nullptr && !myInfluencer->getRespectJunctionPriority());
3731 MSLink::BlockingFoes collectFoes;
3732 bool opened = (yellow || influencerPrio
3733 || link->opened(dpi.myArrivalTime, dpi.myArrivalSpeed, dpi.getLeaveSpeed(),
3735 canBrake ? getImpatience() : 1,
3738 ls == LINKSTATE_ZIPPER ? &collectFoes : nullptr,
3739 ignoreRedLink, this, dpi.myDistance));
3740 if (opened && myLaneChangeModel->getShadowLane() != nullptr) {
3741 const MSLink* const parallelLink = dpi.myLink->getParallelLink(myLaneChangeModel->getShadowDirection());
3742 if (parallelLink != nullptr) {
3743 const double shadowLatPos = getLateralPositionOnLane() - myLaneChangeModel->getShadowDirection() * 0.5 * (
3745 opened = yellow || influencerPrio || (opened && parallelLink->opened(dpi.myArrivalTime, dpi.myArrivalSpeed, dpi.getLeaveSpeed(),
3748 getWaitingTimeFor(link), shadowLatPos, nullptr,
3749 ignoreRedLink, this, dpi.myDistance));
3750#ifdef DEBUG_EXEC_MOVE
3751 if (DEBUG_COND) {
3752 std::cout << SIMTIME
3753 << " veh=" << getID()
3754 << " shadowLane=" << myLaneChangeModel->getShadowLane()->getID()
3755 << " shadowDir=" << myLaneChangeModel->getShadowDirection()
3756 << " parallelLink=" << (parallelLink == 0 ? "NULL" : parallelLink->getViaLaneOrLane()->getID())
3757 << " opened=" << opened
3758 << "\n";
3759 }
3760#endif
3761 }
3762 }
3763 // vehicles should decelerate when approaching a minor link
3764#ifdef DEBUG_EXEC_MOVE
3765 if (DEBUG_COND) {
3766 std::cout << SIMTIME
3767 << " opened=" << opened
3768 << " influencerPrio=" << influencerPrio
3769 << " linkPrio=" << link->havePriority()
3770 << " lastContMajor=" << link->lastWasContMajor()
3771 << " isCont=" << link->isCont()
3772 << " ignoreRed=" << ignoreRedLink
3773 << "\n";
3774 }
3775#endif
3776 double visibilityDistance = link->getFoeVisibilityDistance();
3777 bool determinedFoePresence = dpi.myDistance <= visibilityDistance;
3778 if (opened && !influencerPrio && !link->havePriority() && !link->lastWasContMajor() && !link->isCont() && !ignoreRedLink) {
3779 if (!determinedFoePresence && (canBrake || !yellow)) {
3780 vSafe = dpi.myVLinkWait;
3782#ifdef DEBUG_CHECKREWINDLINKLANES
3783 if (DEBUG_COND) {
3784 std::cout << SIMTIME << " veh=" << getID() << " haveToWait (minor)\n";
3785 }
3786#endif
3787 break;
3788 } else {
3789 // past the point of no return. we need to drive fast enough
3790 // to make it across the link. However, minor slowdowns
3791 // should be permissible to follow leading traffic safely
3792 // basically, this code prevents dawdling
3793 // (it's harder to do this later using
3794 // SUMO_ATTR_JM_SIGMA_MINOR because we don't know whether the
3795 // vehicle is already too close to stop at that part of the code)
3796 //
3797 // XXX: There is a problem in subsecond simulation: If we cannot
3798 // make it across the minor link in one step, new traffic
3799 // could appear on a major foe link and cause a collision. Refs. #1845, #2123
3800 vSafeMinDist = dpi.myDistance; // distance that must be covered
3802 vSafeMin = MIN3((double)DIST2SPEED(vSafeMinDist + POSITION_EPS), dpi.myVLinkPass, getCarFollowModel().maxNextSafeMin(getSpeed(), this));
3803 } else {
3804 vSafeMin = MIN3((double)DIST2SPEED(2 * vSafeMinDist + NUMERICAL_EPS) - getSpeed(), dpi.myVLinkPass, getCarFollowModel().maxNextSafeMin(getSpeed(), this));
3805 }
3806 canBrakeVSafeMin = canBrake;
3807#ifdef DEBUG_EXEC_MOVE
3808 if (DEBUG_COND) {
3809 std::cout << " vSafeMin=" << vSafeMin << " vSafeMinDist=" << vSafeMinDist << " canBrake=" << canBrake << "\n";
3810 }
3811#endif
3812 }
3813 }
3814 // have waited; may pass if opened...
3815 if (opened) {
3816 vSafe = dpi.myVLinkPass;
3817 if (vSafe < getCarFollowModel().getMaxDecel() && vSafe <= dpi.myVLinkWait && vSafe < getCarFollowModel().maxNextSpeed(getSpeed(), this)) {
3818 // this vehicle is probably not gonna drive across the next junction (heuristic)
3820#ifdef DEBUG_CHECKREWINDLINKLANES
3821 if (DEBUG_COND) {
3822 std::cout << SIMTIME << " veh=" << getID() << " haveToWait (very slow)\n";
3823 }
3824#endif
3825 }
3826 if (link->mustStop() && determinedFoePresence && myHaveStoppedFor == nullptr) {
3827 myHaveStoppedFor = link;
3828 }
3829 } else if (link->getState() == LINKSTATE_ZIPPER) {
3830 vSafeZipper = MIN2(vSafeZipper,
3831 link->getZipperSpeed(this, dpi.myDistance, dpi.myVLinkPass, dpi.myArrivalTime, &collectFoes));
3832 } else if (!canBrake
3833 // always brake hard for traffic lights (since an emergency stop is necessary anyway)
3834 && link->getTLLogic() == nullptr
3835 // cannot brake even with emergency deceleration
3836 && dpi.myDistance < getCarFollowModel().brakeGap(myState.mySpeed, getCarFollowModel().getEmergencyDecel(), 0.)) {
3837#ifdef DEBUG_EXEC_MOVE
3838 if (DEBUG_COND) {
3839 std::cout << SIMTIME << " too fast to brake for closed link\n";
3840 }
3841#endif
3842 vSafe = dpi.myVLinkPass;
3843 } else {
3844 vSafe = dpi.myVLinkWait;
3846#ifdef DEBUG_CHECKREWINDLINKLANES
3847 if (DEBUG_COND) {
3848 std::cout << SIMTIME << " veh=" << getID() << " haveToWait (closed)\n";
3849 }
3850#endif
3851#ifdef DEBUG_EXEC_MOVE
3852 if (DEBUG_COND) {
3853 std::cout << SIMTIME << " braking for closed link=" << link->getViaLaneOrLane()->getID() << "\n";
3854 }
3855#endif
3856 break;
3857 }
3859 // request was renewed, restoring entry time
3860 // @note: using myJunctionEntryTimeNeverYield could lead to inconsistencies with other vehicles already on the junction
3862 }
3863 } else {
3864 if (link != nullptr && link->getInternalLaneBefore() != nullptr && myLane->isInternal() && link->getJunction() == myLane->getEdge().getToJunction()) {
3865 // blocked on the junction. yield request so other vehicles may
3866 // become junction leader
3867#ifdef DEBUG_EXEC_MOVE
3868 if (DEBUG_COND) {
3869 std::cout << SIMTIME << " resetting junctionEntryTime at junction '" << link->getJunction()->getID() << "' beause of non-request exitLink\n";
3870 }
3871#endif
3874 }
3875 // we have: i->link == 0 || !i->setRequest
3876 vSafe = dpi.myVLinkWait;
3877 if (link != nullptr || myStopDist < (myLane->getLength() - getPositionOnLane())) {
3878 if (vSafe < getSpeed()) {
3880#ifdef DEBUG_CHECKREWINDLINKLANES
3881 if (DEBUG_COND) {
3882 std::cout << SIMTIME << " veh=" << getID() << " haveToWait (no request, braking) vSafe=" << vSafe << "\n";
3883 }
3884#endif
3885 } else if (vSafe < SUMO_const_haltingSpeed) {
3887#ifdef DEBUG_CHECKREWINDLINKLANES
3888 if (DEBUG_COND) {
3889 std::cout << SIMTIME << " veh=" << getID() << " haveToWait (no request, stopping)\n";
3890 }
3891#endif
3892 }
3893 }
3894 if (link == nullptr && myLFLinkLanes.size() == 1
3895 && getBestLanesContinuation().size() > 1
3896 && getBestLanesContinuation()[1]->hadPermissionChanges()
3897 && myLane->getFirstAnyVehicle() == this) {
3898 // temporal lane closing without notification, visible to the
3899 // vehicle at the front of the queue
3900 updateBestLanes(true);
3901 //std::cout << SIMTIME << " veh=" << getID() << " updated bestLanes=" << toString(getBestLanesContinuation()) << "\n";
3902 }
3903 break;
3904 }
3905 }
3906
3907//#ifdef DEBUG_EXEC_MOVE
3908// if (DEBUG_COND) {
3909// std::cout << "\nvCurrent = " << toString(getSpeed(), 24) << "" << std::endl;
3910// std::cout << "vSafe = " << toString(vSafe, 24) << "" << std::endl;
3911// std::cout << "vSafeMin = " << toString(vSafeMin, 24) << "" << std::endl;
3912// std::cout << "vSafeMinDist = " << toString(vSafeMinDist, 24) << "" << std::endl;
3913//
3914// double gap = getLeader().second;
3915// std::cout << "gap = " << toString(gap, 24) << std::endl;
3916// std::cout << "vSafeStoppedLeader = " << toString(getCarFollowModel().stopSpeed(this, getSpeed(), gap, MSCFModel::CalcReason::FUTURE), 24)
3917// << "\n" << std::endl;
3918// }
3919//#endif
3920
3921 if ((MSGlobals::gSemiImplicitEulerUpdate && vSafe + NUMERICAL_EPS < vSafeMin)
3922 || (!MSGlobals::gSemiImplicitEulerUpdate && (vSafe + NUMERICAL_EPS < vSafeMin && vSafeMin != 0))) { // this might be good for the euler case as well
3923 // XXX: (Leo) This often called stopSpeed with vSafeMinDist==0 (for the ballistic update), since vSafe can become negative
3924 // 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
3925#ifdef DEBUG_EXEC_MOVE
3926 if (DEBUG_COND) {
3927 std::cout << "vSafeMin Problem? vSafe=" << vSafe << " vSafeMin=" << vSafeMin << " vSafeMinDist=" << vSafeMinDist << std::endl;
3928 }
3929#endif
3930 if (canBrakeVSafeMin && vSafe < getSpeed()) {
3931 // cannot drive across a link so we need to stop before it
3932 vSafe = MIN2(vSafe, MAX2(getCarFollowModel().minNextSpeed(getSpeed(), this),
3933 getCarFollowModel().stopSpeed(this, getSpeed(), vSafeMinDist)));
3934 vSafeMin = 0;
3936#ifdef DEBUG_CHECKREWINDLINKLANES
3937 if (DEBUG_COND) {
3938 std::cout << SIMTIME << " veh=" << getID() << " haveToWait (vSafe=" << vSafe << " < vSafeMin=" << vSafeMin << ")\n";
3939 }
3940#endif
3941 } else {
3942 // if the link is yellow or visibility distance is large
3943 // then we might not make it across the link in one step anyway..
3944 // Possibly, the lane after the intersection has a lower speed limit so
3945 // we really need to drive slower already
3946 // -> keep driving without dawdling
3947 vSafeMin = vSafe;
3948 }
3949 }
3950
3951 // vehicles inside a roundabout should maintain their requests
3952 if (myLane->getEdge().isRoundabout()) {
3953 myHaveToWaitOnNextLink = false;
3954 }
3955
3956 vSafe = MIN2(vSafe, vSafeZipper);
3957}
3958
3959
3960double
3961MSVehicle::processTraCISpeedControl(double vSafe, double vNext) {
3962 if (myInfluencer != nullptr) {
3964#ifdef DEBUG_TRACI
3965 if DEBUG_COND2(this) {
3966 std::cout << SIMTIME << " MSVehicle::processTraCISpeedControl() for vehicle '" << getID() << "'"
3967 << " vSafe=" << vSafe << " (init)vNext=" << vNext << " keepStopping=" << keepStopping();
3968 }
3969#endif
3972 }
3973 const double vMax = getVehicleType().getCarFollowModel().maxNextSpeed(myState.mySpeed, this);
3976 vMin = MAX2(0., vMin);
3977 }
3978 vNext = myInfluencer->influenceSpeed(MSNet::getInstance()->getCurrentTimeStep(), vNext, vSafe, vMin, vMax);
3979 if (keepStopping() && myStops.front().getSpeed() == 0) {
3980 // avoid driving while stopped (unless it's actually a waypoint
3981 vNext = myInfluencer->getOriginalSpeed();
3982 }
3983#ifdef DEBUG_TRACI
3984 if DEBUG_COND2(this) {
3985 std::cout << " (processed)vNext=" << vNext << std::endl;
3986 }
3987#endif
3988 }
3989 return vNext;
3990}
3991
3992
3993void
3995#ifdef DEBUG_ACTIONSTEPS
3996 if (DEBUG_COND) {
3997 std::cout << SIMTIME << " veh=" << getID() << " removePassedDriveItems()\n"
3998 << " Current items: ";
3999 for (auto& j : myLFLinkLanes) {
4000 if (j.myLink == 0) {
4001 std::cout << "\n Stop at distance " << j.myDistance;
4002 } else {
4003 const MSLane* to = j.myLink->getViaLaneOrLane();
4004 const MSLane* from = j.myLink->getLaneBefore();
4005 std::cout << "\n Link at distance " << j.myDistance << ": '"
4006 << (from == 0 ? "NONE" : from->getID()) << "' -> '" << (to == 0 ? "NONE" : to->getID()) << "'";
4007 }
4008 }
4009 std::cout << "\n myNextDriveItem: ";
4010 if (myLFLinkLanes.size() != 0) {
4011 if (myNextDriveItem->myLink == 0) {
4012 std::cout << "\n Stop at distance " << myNextDriveItem->myDistance;
4013 } else {
4014 const MSLane* to = myNextDriveItem->myLink->getViaLaneOrLane();
4015 const MSLane* from = myNextDriveItem->myLink->getLaneBefore();
4016 std::cout << "\n Link at distance " << myNextDriveItem->myDistance << ": '"
4017 << (from == 0 ? "NONE" : from->getID()) << "' -> '" << (to == 0 ? "NONE" : to->getID()) << "'";
4018 }
4019 }
4020 std::cout << std::endl;
4021 }
4022#endif
4023 for (auto j = myLFLinkLanes.begin(); j != myNextDriveItem; ++j) {
4024#ifdef DEBUG_ACTIONSTEPS
4025 if (DEBUG_COND) {
4026 std::cout << " Removing item: ";
4027 if (j->myLink == 0) {
4028 std::cout << "Stop at distance " << j->myDistance;
4029 } else {
4030 const MSLane* to = j->myLink->getViaLaneOrLane();
4031 const MSLane* from = j->myLink->getLaneBefore();
4032 std::cout << "Link at distance " << j->myDistance << ": '"
4033 << (from == 0 ? "NONE" : from->getID()) << "' -> '" << (to == 0 ? "NONE" : to->getID()) << "'";
4034 }
4035 std::cout << std::endl;
4036 }
4037#endif
4038 if (j->myLink != nullptr) {
4039 j->myLink->removeApproaching(this);
4040 }
4041 }
4044}
4045
4046
4047void
4049#ifdef DEBUG_ACTIONSTEPS
4050 if (DEBUG_COND) {
4051 std::cout << SIMTIME << " updateDriveItems(), veh='" << getID() << "' (lane: '" << getLane()->getID() << "')\nCurrent drive items:" << std::endl;
4052 for (const auto& dpi : myLFLinkLanes) {
4053 std::cout
4054 << " vPass=" << dpi.myVLinkPass
4055 << " vWait=" << dpi.myVLinkWait
4056 << " linkLane=" << (dpi.myLink == 0 ? "NULL" : dpi.myLink->getViaLaneOrLane()->getID())
4057 << " request=" << dpi.mySetRequest
4058 << "\n";
4059 }
4060 std::cout << " myNextDriveItem's linked lane: " << (myNextDriveItem->myLink == 0 ? "NULL" : myNextDriveItem->myLink->getViaLaneOrLane()->getID()) << std::endl;
4061 }
4062#endif
4063 if (myLFLinkLanes.size() == 0) {
4064 // nothing to update
4065 return;
4066 }
4067 const MSLink* nextPlannedLink = nullptr;
4068// auto i = myLFLinkLanes.begin();
4069 auto i = myNextDriveItem;
4070 while (i != myLFLinkLanes.end() && nextPlannedLink == nullptr) {
4071 nextPlannedLink = i->myLink;
4072 ++i;
4073 }
4074
4075 if (nextPlannedLink == nullptr) {
4076 // No link for upcoming item -> no need for an update
4077#ifdef DEBUG_ACTIONSTEPS
4078 if (DEBUG_COND) {
4079 std::cout << "Found no link-related drive item." << std::endl;
4080 }
4081#endif
4082 return;
4083 }
4084
4085 if (getLane() == nextPlannedLink->getLaneBefore()) {
4086 // Current lane approaches the stored next link, i.e. no LC happend and no update is required.
4087#ifdef DEBUG_ACTIONSTEPS
4088 if (DEBUG_COND) {
4089 std::cout << "Continuing on planned lane sequence, no update required." << std::endl;
4090 }
4091#endif
4092 return;
4093 }
4094 // Lane must have been changed, determine the change direction
4095 const MSLink* parallelLink = nextPlannedLink->getParallelLink(1);
4096 if (parallelLink != nullptr && parallelLink->getLaneBefore() == getLane()) {
4097 // lcDir = 1;
4098 } else {
4099 parallelLink = nextPlannedLink->getParallelLink(-1);
4100 if (parallelLink != nullptr && parallelLink->getLaneBefore() == getLane()) {
4101 // lcDir = -1;
4102 } else {
4103 // If the vehicle's current lane is not the approaching lane for the next
4104 // drive process item's link, it is expected to lead to a parallel link,
4105 // XXX: What if the lc was an overtaking maneuver and there is no upcoming link?
4106 // Then a stop item should be scheduled! -> TODO!
4107 //assert(false);
4108 return;
4109 }
4110 }
4111#ifdef DEBUG_ACTIONSTEPS
4112 if (DEBUG_COND) {
4113 std::cout << "Changed lane. Drive items will be updated along the current lane continuation." << std::endl;
4114 }
4115#endif
4116 // Trace link sequence along current best lanes and transfer drive items to the corresponding links
4117// DriveItemVector::iterator driveItemIt = myLFLinkLanes.begin();
4118 DriveItemVector::iterator driveItemIt = myNextDriveItem;
4119 // In the loop below, lane holds the currently considered lane on the vehicles continuation (including internal lanes)
4120 const MSLane* lane = myLane;
4121 assert(myLane == parallelLink->getLaneBefore());
4122 // *lit is a pointer to the next lane in best continuations for the current lane (always non-internal)
4123 std::vector<MSLane*>::const_iterator bestLaneIt = getBestLanesContinuation().begin() + 1;
4124 // Pointer to the new link for the current drive process item
4125 MSLink* newLink = nullptr;
4126 while (driveItemIt != myLFLinkLanes.end()) {
4127 if (driveItemIt->myLink == nullptr) {
4128 // Items not related to a specific link are not updated
4129 // (XXX: when a stop item corresponded to a dead end, which is overcome by the LC that made
4130 // the update necessary, this may slow down the vehicle's continuation on the new lane...)
4131 ++driveItemIt;
4132 continue;
4133 }
4134 // Continuation links for current best lanes are less than for the former drive items (myLFLinkLanes)
4135 // We just remove the leftover link-items, as they cannot be mapped to new links.
4136 if (bestLaneIt == getBestLanesContinuation().end()) {
4137#ifdef DEBUG_ACTIONSTEPS
4138 if (DEBUG_COND) {
4139 std::cout << "Reached end of the new continuation sequence. Erasing leftover link-items." << std::endl;
4140 }
4141#endif
4142 while (driveItemIt != myLFLinkLanes.end()) {
4143 if (driveItemIt->myLink == nullptr) {
4144 ++driveItemIt;
4145 continue;
4146 } else {
4147 driveItemIt->myLink->removeApproaching(this);
4148 driveItemIt = myLFLinkLanes.erase(driveItemIt);
4149 }
4150 }
4151 break;
4152 }
4153 // Do the actual link-remapping for the item. And un/register approaching information on the corresponding links
4154 const MSLane* const target = *bestLaneIt;
4155 assert(!target->isInternal());
4156 newLink = nullptr;
4157 for (MSLink* const link : lane->getLinkCont()) {
4158 if (link->getLane() == target) {
4159 newLink = link;
4160 break;
4161 }
4162 }
4163
4164 if (newLink == driveItemIt->myLink) {
4165 // new continuation merged into previous - stop update
4166#ifdef DEBUG_ACTIONSTEPS
4167 if (DEBUG_COND) {
4168 std::cout << "Old and new continuation sequences merge at link\n"
4169 << "'" << newLink->getLaneBefore()->getID() << "'->'" << newLink->getViaLaneOrLane()->getID() << "'"
4170 << "\nNo update beyond merge required." << std::endl;
4171 }
4172#endif
4173 break;
4174 }
4175
4176#ifdef DEBUG_ACTIONSTEPS
4177 if (DEBUG_COND) {
4178 std::cout << "lane=" << lane->getID() << "\nUpdating link\n '" << driveItemIt->myLink->getLaneBefore()->getID() << "'->'" << driveItemIt->myLink->getViaLaneOrLane()->getID() << "'"
4179 << "==> " << "'" << newLink->getLaneBefore()->getID() << "'->'" << newLink->getViaLaneOrLane()->getID() << "'" << std::endl;
4180 }
4181#endif
4182 newLink->setApproaching(this, driveItemIt->myLink->getApproaching(this));
4183 driveItemIt->myLink->removeApproaching(this);
4184 driveItemIt->myLink = newLink;
4185 lane = newLink->getViaLaneOrLane();
4186 ++driveItemIt;
4187 if (!lane->isInternal()) {
4188 ++bestLaneIt;
4189 }
4190 }
4191#ifdef DEBUG_ACTIONSTEPS
4192 if (DEBUG_COND) {
4193 std::cout << "Updated drive items:" << std::endl;
4194 for (const auto& dpi : myLFLinkLanes) {
4195 std::cout
4196 << " vPass=" << dpi.myVLinkPass
4197 << " vWait=" << dpi.myVLinkWait
4198 << " linkLane=" << (dpi.myLink == 0 ? "NULL" : dpi.myLink->getViaLaneOrLane()->getID())
4199 << " request=" << dpi.mySetRequest
4200 << "\n";
4201 }
4202 }
4203#endif
4204}
4205
4206
4207void
4209 // To avoid casual blinking brake lights at high speeds due to dawdling of the
4210 // leading vehicle, we don't show brake lights when the deceleration could be caused
4211 // by frictional forces and air resistance (i.e. proportional to v^2, coefficient could be adapted further)
4212 double pseudoFriction = (0.05 + 0.005 * getSpeed()) * getSpeed();
4213 bool brakelightsOn = vNext < getSpeed() - ACCEL2SPEED(pseudoFriction);
4214
4215 if (vNext <= SUMO_const_haltingSpeed) {
4216 brakelightsOn = true;
4217 }
4218 if (brakelightsOn && !isStopped()) {
4220 } else {
4222 }
4223}
4224
4225
4226void
4231 } else {
4232 myWaitingTime = 0;
4234 if (hasInfluencer()) {
4236 }
4237 }
4238}
4239
4240
4241void
4243 // update time loss (depends on the updated edge)
4244 if (!isStopped()) {
4245 // some cfModels (i.e. EIDM may drive faster than predicted by maxNextSpeed)
4246 const double vmax = MIN2(myLane->getVehicleMaxSpeed(this), MAX2(myStopSpeed, vNext));
4247 if (vmax > 0) {
4248 myTimeLoss += TS * (vmax - vNext) / vmax;
4249 }
4250 }
4251}
4252
4253
4254double
4255MSVehicle::checkReversal(bool& canReverse, double speedThreshold, double seen) const {
4256 const bool stopOk = (myStops.empty() || myStops.front().edge != myCurrEdge
4257 || (myStops.front().getSpeed() > 0 && myState.myPos > myStops.front().pars.endPos - 2 * POSITION_EPS));
4258#ifdef DEBUG_REVERSE_BIDI
4259 if (DEBUG_COND) std::cout << SIMTIME << " checkReversal lane=" << myLane->getID()
4260 << " pos=" << myState.myPos
4261 << " speed=" << std::setprecision(6) << getPreviousSpeed() << std::setprecision(gPrecision)
4262 << " speedThreshold=" << speedThreshold
4263 << " seen=" << seen
4264 << " isRail=" << isRail()
4265 << " speedOk=" << (getPreviousSpeed() <= speedThreshold)
4266 << " posOK=" << (myState.myPos <= myLane->getLength())
4267 << " normal=" << !myLane->isInternal()
4268 << " routeOK=" << ((myCurrEdge + 1) != myRoute->end())
4269 << " bidi=" << (myLane->getEdge().getBidiEdge() == *(myCurrEdge + 1))
4270 << " stopOk=" << stopOk
4271 << "\n";
4272#endif
4273 if ((getVClass() & SVC_RAIL_CLASSES) != 0
4274 && getPreviousSpeed() <= speedThreshold
4275 && myState.myPos <= myLane->getLength()
4276 && !myLane->isInternal()
4277 && (myCurrEdge + 1) != myRoute->end()
4278 && myLane->getEdge().getBidiEdge() == *(myCurrEdge + 1)
4279 // ensure there are no further stops on this edge
4280 && stopOk
4281 ) {
4282 //if (isSelected()) std::cout << " check1 passed\n";
4283
4284 // ensure that the vehicle is fully on bidi edges that allow reversal
4285 const int neededFutureRoute = 1 + (int)(MSGlobals::gUsingInternalLanes
4286 ? myFurtherLanes.size()
4287 : ceil((double)myFurtherLanes.size() / 2.0));
4288 const int remainingRoute = int(myRoute->end() - myCurrEdge) - 1;
4289 if (remainingRoute < neededFutureRoute) {
4290#ifdef DEBUG_REVERSE_BIDI
4291 if (DEBUG_COND) {
4292 std::cout << " fail: remainingEdges=" << ((int)(myRoute->end() - myCurrEdge)) << " further=" << myFurtherLanes.size() << "\n";
4293 }
4294#endif
4295 return getMaxSpeed();
4296 }
4297 //if (isSelected()) std::cout << " check2 passed\n";
4298
4299 // ensure that the turn-around connection exists from the current edge to its bidi-edge
4300 const MSEdgeVector& succ = myLane->getEdge().getSuccessors();
4301 if (std::find(succ.begin(), succ.end(), myLane->getEdge().getBidiEdge()) == succ.end()) {
4302#ifdef DEBUG_REVERSE_BIDI
4303 if (DEBUG_COND) {
4304 std::cout << " noTurn (bidi=" << myLane->getEdge().getBidiEdge()->getID() << " succ=" << toString(succ) << "\n";
4305 }
4306#endif
4307 return getMaxSpeed();
4308 }
4309 //if (isSelected()) std::cout << " check3 passed\n";
4310
4311 // ensure that the vehicle front will not move past a stop on the bidi edge of the current edge
4312 if (!myStops.empty() && myStops.front().edge == (myCurrEdge + 1)) {
4313 const double stopPos = myStops.front().getEndPos(*this);
4314 const double brakeDist = getCarFollowModel().brakeGap(getSpeed(), getCarFollowModel().getMaxDecel(), 0);
4315 const double newPos = myLane->getLength() - (getBackPositionOnLane() + brakeDist);
4316 if (newPos > stopPos) {
4317#ifdef DEBUG_REVERSE_BIDI
4318 if (DEBUG_COND) {
4319 std::cout << " reversal would go past stop on " << myLane->getBidiLane()->getID() << "\n";
4320 }
4321#endif
4322 if (seen > MAX2(brakeDist, 1.0)) {
4323 return getMaxSpeed();
4324 } else {
4325#ifdef DEBUG_REVERSE_BIDI
4326 if (DEBUG_COND) {
4327 std::cout << " train is too long, skipping stop at " << stopPos << " cannot be avoided\n";
4328 }
4329#endif
4330 }
4331 }
4332 }
4333 //if (isSelected()) std::cout << " check4 passed\n";
4334
4335 // ensure that bidi-edges exist for all further edges
4336 // and that no stops will be skipped when reversing
4337 // and that the train will not be on top of a red rail signal after reversal
4338 const MSLane* bidi = myLane->getBidiLane();
4339 int view = 2;
4340 for (MSLane* further : myFurtherLanes) {
4341 if (!further->getEdge().isInternal()) {
4342 if (further->getEdge().getBidiEdge() != *(myCurrEdge + view)) {
4343#ifdef DEBUG_REVERSE_BIDI
4344 if (DEBUG_COND) {
4345 std::cout << " noBidi view=" << view << " further=" << further->getID() << " furtherBidi=" << Named::getIDSecure(further->getEdge().getBidiEdge()) << " future=" << (*(myCurrEdge + view))->getID() << "\n";
4346 }
4347#endif
4348 return getMaxSpeed();
4349 }
4350 const MSLane* nextBidi = further->getBidiLane();
4351 const MSLink* toNext = bidi->getLinkTo(nextBidi);
4352 if (toNext == nullptr) {
4353 // can only happen if the route is invalid
4354 return getMaxSpeed();
4355 }
4356 if (toNext->haveRed()) {
4357#ifdef DEBUG_REVERSE_BIDI
4358 if (DEBUG_COND) {
4359 std::cout << " do not reverse on a red signal\n";
4360 }
4361#endif
4362 return getMaxSpeed();
4363 }
4364 bidi = nextBidi;
4365 if (!myStops.empty() && myStops.front().edge == (myCurrEdge + view)) {
4366 const double brakeDist = getCarFollowModel().brakeGap(getSpeed(), getCarFollowModel().getMaxDecel(), 0);
4367 const double stopPos = myStops.front().getEndPos(*this);
4368 const double newPos = further->getLength() - (getBackPositionOnLane(further) + brakeDist);
4369 if (newPos > stopPos) {
4370#ifdef DEBUG_REVERSE_BIDI
4371 if (DEBUG_COND) {
4372 std::cout << " reversal would go past stop on further-opposite lane " << further->getBidiLane()->getID() << "\n";
4373 }
4374#endif
4375 if (seen > MAX2(brakeDist, 1.0)) {
4376 canReverse = false;
4377 return getMaxSpeed();
4378 } else {
4379#ifdef DEBUG_REVERSE_BIDI
4380 if (DEBUG_COND) {
4381 std::cout << " train is too long, skipping stop at " << stopPos << " cannot be avoided\n";
4382 }
4383#endif
4384 }
4385 }
4386 }
4387 view++;
4388 }
4389 }
4390 // reverse as soon as comfortably possible
4391 const double vMinComfortable = getCarFollowModel().minNextSpeed(getSpeed(), this);
4392#ifdef DEBUG_REVERSE_BIDI
4393 if (DEBUG_COND) {
4394 std::cout << SIMTIME << " seen=" << seen << " vReverseOK=" << vMinComfortable << "\n";
4395 }
4396#endif
4397 canReverse = true;
4398 return vMinComfortable;
4399 }
4400 return getMaxSpeed();
4401}
4402
4403
4404void
4405MSVehicle::processLaneAdvances(std::vector<MSLane*>& passedLanes, std::string& emergencyReason) {
4406 for (std::vector<MSLane*>::reverse_iterator i = myFurtherLanes.rbegin(); i != myFurtherLanes.rend(); ++i) {
4407 passedLanes.push_back(*i);
4408 }
4409 if (passedLanes.size() == 0 || passedLanes.back() != myLane) {
4410 passedLanes.push_back(myLane);
4411 }
4412 // let trains reverse direction
4413 bool reverseTrain = false;
4414 checkReversal(reverseTrain);
4415 if (reverseTrain) {
4416 // Train is 'reversing' so toggle the logical state
4418 // add some slack to ensure that the back of train does appear looped
4419 myState.myPos += 2 * (myLane->getLength() - myState.myPos) + myType->getLength() + NUMERICAL_EPS;
4420 myState.mySpeed = 0;
4421#ifdef DEBUG_REVERSE_BIDI
4422 if (DEBUG_COND) {
4423 std::cout << SIMTIME << " reversing train=" << getID() << " newPos=" << myState.myPos << "\n";
4424 }
4425#endif
4426 }
4427 // move on lane(s)
4428 if (myState.myPos > myLane->getLength()) {
4429 // The vehicle has moved at least to the next lane (maybe it passed even more than one)
4430 if (myCurrEdge != myRoute->end() - 1) {
4431 MSLane* approachedLane = myLane;
4432 // move the vehicle forward
4434 while (myNextDriveItem != myLFLinkLanes.end() && approachedLane != nullptr && myState.myPos > approachedLane->getLength()) {
4435 const MSLink* link = myNextDriveItem->myLink;
4436 const double linkDist = myNextDriveItem->myDistance;
4438 // check whether the vehicle was allowed to enter lane
4439 // otherwise it is decelerated and we do not need to test for it's
4440 // approach on the following lanes when a lane changing is performed
4441 // proceed to the next lane
4442 if (approachedLane->mustCheckJunctionCollisions()) {
4443 // vehicle moves past approachedLane within a single step, collision checking must still be done
4445 }
4446 if (link != nullptr) {
4447 if ((getVClass() & SVC_RAIL_CLASSES) != 0
4448 && !myLane->isInternal()
4449 && myLane->getBidiLane() != nullptr
4450 && link->getLane()->getBidiLane() == myLane
4451 && !reverseTrain) {
4452 emergencyReason = " because it must reverse direction";
4453 approachedLane = nullptr;
4454 break;
4455 }
4456 if ((getVClass() & SVC_RAIL_CLASSES) != 0
4457 && myState.myPos < myLane->getLength() + NUMERICAL_EPS
4458 && hasStops() && getNextStop().edge == myCurrEdge) {
4459 // avoid skipping stop due to numerical instability
4460 // this is a special case for rail vehicles because they
4461 // continue myLFLinkLanes past stops
4462 approachedLane = myLane;
4464 break;
4465 }
4466 approachedLane = link->getViaLaneOrLane();
4468 bool beyondStopLine = linkDist < link->getLaneBefore()->getVehicleStopOffset(this);
4469 if (link->haveRed() && !ignoreRed(link, false) && !beyondStopLine && !reverseTrain) {
4470 emergencyReason = " because of a red traffic light";
4471 break;
4472 }
4473 }
4474 if (reverseTrain && approachedLane->isInternal()) {
4475 // avoid getting stuck on a slow turn-around internal lane
4476 myState.myPos += approachedLane->getLength();
4477 }
4478 } else if (myState.myPos < myLane->getLength() + NUMERICAL_EPS) {
4479 // avoid warning due to numerical instability
4480 approachedLane = myLane;
4482 } else if (reverseTrain) {
4483 approachedLane = (*(myCurrEdge + 1))->getLanes()[0];
4484 link = myLane->getLinkTo(approachedLane);
4485 assert(link != 0);
4486 while (link->getViaLane() != nullptr) {
4487 link = link->getViaLane()->getLinkCont()[0];
4488 }
4490 } else {
4491 emergencyReason = " because there is no connection to the next edge";
4492 approachedLane = nullptr;
4493 break;
4494 }
4495 if (approachedLane != myLane && approachedLane != nullptr) {
4498 assert(myState.myPos > 0);
4499 enterLaneAtMove(approachedLane);
4500 if (link->isEntryLink()) {
4503 myHaveStoppedFor = nullptr;
4504 }
4505 if (link->isConflictEntryLink()) {
4507 // renew yielded request
4509 }
4510 if (link->isExitLink()) {
4511 // passed junction, reset for approaching the next one
4515 }
4516#ifdef DEBUG_PLAN_MOVE_LEADERINFO
4517 if (DEBUG_COND) {
4518 std::cout << "Update junctionTimes link=" << link->getViaLaneOrLane()->getID()
4519 << " entry=" << link->isEntryLink() << " conflict=" << link->isConflictEntryLink() << " exit=" << link->isExitLink()
4520 << " ET=" << myJunctionEntryTime
4521 << " ETN=" << myJunctionEntryTimeNeverYield
4522 << " CET=" << myJunctionConflictEntryTime
4523 << "\n";
4524 }
4525#endif
4526 if (hasArrivedInternal()) {
4527 break;
4528 }
4531 // abort lane change
4532 WRITE_WARNING("Vehicle '" + getID() + "' could not finish continuous lane change (turn lane) time=" +
4533 time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
4535 }
4536 }
4537 if (approachedLane->getEdge().isVaporizing()) {
4539 break;
4540 }
4541 passedLanes.push_back(approachedLane);
4542 }
4543 }
4544 // NOTE: Passed drive items will be erased in the next simstep's planMove()
4545
4546#ifdef DEBUG_ACTIONSTEPS
4547 if (DEBUG_COND && myNextDriveItem != myLFLinkLanes.begin()) {
4548 std::cout << "Updated drive items:" << std::endl;
4549 for (DriveItemVector::iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
4550 std::cout
4551 << " vPass=" << (*i).myVLinkPass
4552 << " vWait=" << (*i).myVLinkWait
4553 << " linkLane=" << ((*i).myLink == 0 ? "NULL" : (*i).myLink->getViaLaneOrLane()->getID())
4554 << " request=" << (*i).mySetRequest
4555 << "\n";
4556 }
4557 }
4558#endif
4559 } else if (!hasArrivedInternal() && myState.myPos < myLane->getLength() + NUMERICAL_EPS) {
4560 // avoid warning due to numerical instability when stopping at the end of the route
4562 }
4563
4564 }
4565}
4566
4567
4568
4569bool
4571#ifdef DEBUG_EXEC_MOVE
4572 if (DEBUG_COND) {
4573 std::cout << "\nEXECUTE_MOVE\n"
4574 << SIMTIME
4575 << " veh=" << getID()
4576 << " speed=" << getSpeed() // toString(getSpeed(), 24)
4577 << std::endl;
4578 }
4579#endif
4580
4581
4582 // Maximum safe velocity
4583 double vSafe = std::numeric_limits<double>::max();
4584 // Minimum safe velocity (lower bound).
4585 double vSafeMin = -std::numeric_limits<double>::max();
4586 // The distance to a link, which should either be crossed this step
4587 // or in front of which we need to stop.
4588 double vSafeMinDist = 0;
4589
4590 if (myActionStep) {
4591 // Actuate control (i.e. choose bounds for safe speed in current simstep (euler), resp. after current sim step (ballistic))
4592 processLinkApproaches(vSafe, vSafeMin, vSafeMinDist);
4593#ifdef DEBUG_ACTIONSTEPS
4594 if (DEBUG_COND) {
4595 std::cout << SIMTIME << " vehicle '" << getID() << "'\n"
4596 " vsafe from processLinkApproaches(): vsafe " << vSafe << std::endl;
4597 }
4598#endif
4599 } else {
4600 // Continue with current acceleration
4601 vSafe = getSpeed() + ACCEL2SPEED(myAcceleration);
4602#ifdef DEBUG_ACTIONSTEPS
4603 if (DEBUG_COND) {
4604 std::cout << SIMTIME << " vehicle '" << getID() << "' skips processLinkApproaches()\n"
4605 " continues with constant accel " << myAcceleration << "...\n"
4606 << "speed: " << getSpeed() << " -> " << vSafe << std::endl;
4607 }
4608#endif
4609 }
4610
4611
4612//#ifdef DEBUG_EXEC_MOVE
4613// if (DEBUG_COND) {
4614// std::cout << "vSafe = " << toString(vSafe,12) << "\n" << std::endl;
4615// }
4616//#endif
4617
4618 // Determine vNext = speed after current sim step (ballistic), resp. in current simstep (euler)
4619 // Call to finalizeSpeed applies speed reduction due to dawdling / lane changing but ensures minimum safe speed
4620 double vNext = vSafe;
4621 const double rawAccel = SPEED2ACCEL(MAX2(vNext, 0.) - myState.mySpeed);
4622 if (vNext <= SUMO_const_haltingSpeed * TS && myWaitingTime > MSGlobals::gStartupWaitThreshold && rawAccel <= accelThresholdForWaiting() && myActionStep) {
4624 } else if (isStopped()) {
4625 // do not apply startupDelay for waypoints
4626 if (getCarFollowModel().startupDelayStopped() && getNextStop().pars.speed <= 0) {
4628 } else {
4629 // do not apply startupDelay but signal that a stop has taken place
4631 }
4632 } else {
4633 // identify potential startup (before other effects reduce the speed again)
4635 }
4636 if (myActionStep) {
4637 vNext = getCarFollowModel().finalizeSpeed(this, vSafe);
4638 if (vNext > 0) {
4639 vNext = MAX2(vNext, vSafeMin);
4640 }
4641 }
4642 // (Leo) to avoid tiny oscillations (< 1e-10) of vNext in a standing vehicle column (observed for ballistic update), we cap off vNext
4643 // (We assure to do this only for vNext<<NUMERICAL_EPS since otherwise this would nullify the workaround for #2995
4644 // (Jakob) We also need to make sure to reach a stop at the start of the next edge
4645 if (fabs(vNext) < NUMERICAL_EPS_SPEED && (myStopDist > POSITION_EPS || (hasStops() && myCurrEdge == getNextStop().edge))) {
4646 vNext = 0.;
4647 }
4648#ifdef DEBUG_EXEC_MOVE
4649 if (DEBUG_COND) {
4650 std::cout << SIMTIME << " finalizeSpeed vSafe=" << vSafe << " vSafeMin=" << (vSafeMin == -std::numeric_limits<double>::max() ? "-Inf" : toString(vSafeMin))
4651 << " vNext=" << vNext << " (i.e. accel=" << SPEED2ACCEL(vNext - getSpeed()) << ")" << std::endl;
4652 }
4653#endif
4654
4655 // vNext may be higher than vSafe without implying a bug:
4656 // - when approaching a green light that suddenly switches to yellow
4657 // - when using unregulated junctions
4658 // - when using tau < step-size
4659 // - when using unsafe car following models
4660 // - when using TraCI and some speedMode / laneChangeMode settings
4661 //if (vNext > vSafe + NUMERICAL_EPS) {
4662 // WRITE_WARNING("vehicle '" + getID() + "' cannot brake hard enough to reach safe speed "
4663 // + toString(vSafe, 4) + ", moving at " + toString(vNext, 4) + " instead. time="
4664 // + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
4665 //}
4666
4668 vNext = MAX2(vNext, 0.);
4669 } else {
4670 // (Leo) Ballistic: negative vNext can be used to indicate a stop within next step.
4671 }
4672
4673 // Check for speed advices from the traci client
4674 vNext = processTraCISpeedControl(vSafe, vNext);
4675
4676 // the acceleration of a vehicle equipped with the elecHybrid device is restricted by the maximal power of the electric drive as well
4677 MSDevice_ElecHybrid* elecHybridOfVehicle = dynamic_cast<MSDevice_ElecHybrid*>(getDevice(typeid(MSDevice_ElecHybrid)));
4678 if (elecHybridOfVehicle != nullptr) {
4679 // this is the consumption given by the car following model-computed acceleration
4680 elecHybridOfVehicle->setConsum(elecHybridOfVehicle->consumption(*this, (vNext - this->getSpeed()) / TS, vNext));
4681 // but the maximum power of the electric motor may be lower
4682 // it needs to be converted from [W] to [Wh/s] (3600s / 1h) so that TS can be taken into account
4683 double maxPower = getEmissionParameters()->getDoubleOptional(SUMO_ATTR_MAXIMUMPOWER, 100000.) / 3600;
4684 if (elecHybridOfVehicle->getConsum() / TS > maxPower) {
4685 // no, we cannot accelerate that fast, recompute the maximum possible acceleration
4686 double accel = elecHybridOfVehicle->acceleration(*this, maxPower, this->getSpeed());
4687 // and update the speed of the vehicle
4688 vNext = MIN2(vNext, this->getSpeed() + accel * TS);
4689 vNext = MAX2(vNext, 0.);
4690 // and set the vehicle consumption to reflect this
4691 elecHybridOfVehicle->setConsum(elecHybridOfVehicle->consumption(*this, (vNext - this->getSpeed()) / TS, vNext));
4692 }
4693 }
4694
4695 setBrakingSignals(vNext);
4696
4697 // update position and speed
4698 int oldLaneOffset = myLane->getEdge().getNumLanes() - myLane->getIndex();
4699 const MSLane* oldLaneMaybeOpposite = myLane;
4701 // transform to the forward-direction lane, move and then transform back
4704 }
4705 updateState(vNext);
4706 updateWaitingTime(vNext);
4707
4708 // Lanes, which the vehicle touched at some moment of the executed simstep
4709 std::vector<MSLane*> passedLanes;
4710 // remember previous lane (myLane is updated in processLaneAdvances)
4711 const MSLane* oldLane = myLane;
4712 // Reason for a possible emergency stop
4713 std::string emergencyReason;
4714 processLaneAdvances(passedLanes, emergencyReason);
4715
4716 updateTimeLoss(vNext);
4718
4720 if (myState.myPos > myLane->getLength()) {
4721 if (emergencyReason == "") {
4722 emergencyReason = TL(" for unknown reasons");
4723 }
4724 WRITE_WARNINGF(TL("Vehicle '%' performs emergency stop at the end of lane '%'% (decel=%, offset=%), time=%."),
4725 getID(), myLane->getID(), emergencyReason, myAcceleration - myState.mySpeed,
4730 myState.mySpeed = 0;
4731 myAcceleration = 0;
4732 }
4733 const MSLane* oldBackLane = getBackLane();
4735 passedLanes.clear(); // ignore back occupation
4736 }
4737#ifdef DEBUG_ACTIONSTEPS
4738 if (DEBUG_COND) {
4739 std::cout << SIMTIME << " veh '" << getID() << "' updates further lanes." << std::endl;
4740 }
4741#endif
4743 if (passedLanes.size() > 1 && isRail()) {
4744 for (auto pi = passedLanes.rbegin(); pi != passedLanes.rend(); ++pi) {
4745 MSLane* pLane = *pi;
4746 if (pLane != myLane && std::find(myFurtherLanes.begin(), myFurtherLanes.end(), pLane) == myFurtherLanes.end()) {
4748 }
4749 }
4750 }
4751 // bestLanes need to be updated before lane changing starts. NOTE: This call is also a presumption for updateDriveItems()
4753 if (myLane != oldLane || oldBackLane != getBackLane()) {
4754 if (myLaneChangeModel->getShadowLane() != nullptr || getLateralOverlap() > POSITION_EPS) {
4755 // shadow lane must be updated if the front or back lane changed
4756 // either if we already have a shadowLane or if there is lateral overlap
4758 }
4760 // The vehicles target lane must be also be updated if the front or back lane changed
4762 }
4763 }
4764 setBlinkerInformation(); // needs updated bestLanes
4765 //change the blue light only for emergency vehicles SUMOVehicleClass
4767 setEmergencyBlueLight(MSNet::getInstance()->getCurrentTimeStep());
4768 }
4769 // must be done before angle computation
4770 // State needs to be reset for all vehicles before the next call to MSEdgeControl::changeLanes
4771 if (myActionStep) {
4772 // check (#2681): Can this be skipped?
4774 } else {
4776#ifdef DEBUG_ACTIONSTEPS
4777 if (DEBUG_COND) {
4778 std::cout << SIMTIME << " veh '" << getID() << "' skips LCM->prepareStep()." << std::endl;
4779 }
4780#endif
4781 }
4784 }
4785
4786#ifdef DEBUG_EXEC_MOVE
4787 if (DEBUG_COND) {
4788 std::cout << SIMTIME << " executeMove finished veh=" << getID() << " lane=" << myLane->getID() << " myPos=" << getPositionOnLane() << " myPosLat=" << getLateralPositionOnLane() << "\n";
4789 gDebugFlag1 = false; // See MSLink_DEBUG_OPENED
4790 }
4791#endif
4793 // transform back to the opposite-direction lane
4794 MSLane* newOpposite = nullptr;
4795 const MSEdge* newOppositeEdge = myLane->getEdge().getOppositeEdge();
4796 if (newOppositeEdge != nullptr) {
4797 newOpposite = newOppositeEdge->getLanes()[newOppositeEdge->getNumLanes() - MAX2(1, oldLaneOffset)];
4798#ifdef DEBUG_EXEC_MOVE
4799 if (DEBUG_COND) {
4800 std::cout << SIMTIME << " newOppositeEdge=" << newOppositeEdge->getID() << " oldLaneOffset=" << oldLaneOffset << " leftMost=" << newOppositeEdge->getNumLanes() - 1 << " newOpposite=" << Named::getIDSecure(newOpposite) << "\n";
4801 }
4802#endif
4803 }
4804 if (newOpposite == nullptr) {
4806 // unusual overtaking at junctions is ok for emergency vehicles
4807 WRITE_WARNINGF(TL("Unexpected end of opposite lane for vehicle '%' at lane '%', time=%."),
4809 }
4811 if (myState.myPos < getLength()) {
4812 // further lanes is always cleared during opposite driving
4813 MSLane* oldOpposite = oldLane->getOpposite();
4814 if (oldOpposite != nullptr) {
4815 myFurtherLanes.push_back(oldOpposite);
4816 myFurtherLanesPosLat.push_back(0);
4817 // small value since the lane is going in the other direction
4820 } else {
4821 SOFT_ASSERT(false);
4822 }
4823 }
4824 } else {
4826 myLane = newOpposite;
4827 oldLane = oldLaneMaybeOpposite;
4828 //std::cout << SIMTIME << " updated myLane=" << Named::getIDSecure(myLane) << " oldLane=" << oldLane->getID() << "\n";
4831 }
4832 }
4834 // Return whether the vehicle did move to another lane
4835 return myLane != oldLane;
4836}
4837
4838void
4840 myState.myPos += dist;
4843
4844 const std::vector<const MSLane*> lanes = getUpcomingLanesUntil(dist);
4846 for (int i = 0; i < (int)lanes.size(); i++) {
4847 MSLink* link = nullptr;
4848 if (i + 1 < (int)lanes.size()) {
4849 const MSLane* const to = lanes[i + 1];
4850 const bool internal = to->isInternal();
4851 for (MSLink* const l : lanes[i]->getLinkCont()) {
4852 if ((internal && l->getViaLane() == to) || (!internal && l->getLane() == to)) {
4853 link = l;
4854 break;
4855 }
4856 }
4857 }
4858 myLFLinkLanes.emplace_back(link, getSpeed(), getSpeed(), true, t, getSpeed(), 0, 0, dist);
4859 }
4860 // minimum execute move:
4861 std::vector<MSLane*> passedLanes;
4862 // Reason for a possible emergency stop
4863 if (lanes.size() > 1) {
4865 }
4866 std::string emergencyReason;
4867 processLaneAdvances(passedLanes, emergencyReason);
4868#ifdef DEBUG_EXTRAPOLATE_DEPARTPOS
4869 if (DEBUG_COND) {
4870 std::cout << SIMTIME << " veh=" << getID() << " executeFractionalMove dist=" << dist
4871 << " passedLanes=" << toString(passedLanes) << " lanes=" << toString(lanes)
4872 << " finalPos=" << myState.myPos
4873 << " speed=" << getSpeed()
4874 << " myFurtherLanes=" << toString(myFurtherLanes)
4875 << "\n";
4876 }
4877#endif
4879 if (lanes.size() > 1) {
4880 for (std::vector<MSLane*>::iterator i = myFurtherLanes.begin(); i != myFurtherLanes.end(); ++i) {
4881#ifdef DEBUG_FURTHER
4882 if (DEBUG_COND) {
4883 std::cout << SIMTIME << " leaveLane \n";
4884 }
4885#endif
4886 (*i)->resetPartialOccupation(this);
4887 }
4888 myFurtherLanes.clear();
4889 myFurtherLanesPosLat.clear();
4891 }
4892}
4893
4894
4895void
4896MSVehicle::updateState(double vNext, bool parking) {
4897 // update position and speed
4898 double deltaPos; // positional change
4900 // euler
4901 deltaPos = SPEED2DIST(vNext);
4902 } else {
4903 // ballistic
4904 deltaPos = getDeltaPos(SPEED2ACCEL(vNext - myState.mySpeed));
4905 }
4906
4907 // the *mean* acceleration during the next step (probably most appropriate for emission calculation)
4908 // NOTE: for the ballistic update vNext may be negative, indicating a stop.
4910
4911#ifdef DEBUG_EXEC_MOVE
4912 if (DEBUG_COND) {
4913 std::cout << SIMTIME << " updateState() for veh '" << getID() << "': deltaPos=" << deltaPos
4914 << " pos=" << myState.myPos << " newPos=" << myState.myPos + deltaPos << std::endl;
4915 }
4916#endif
4917 double decelPlus = -myAcceleration - getCarFollowModel().getMaxDecel() - NUMERICAL_EPS;
4918 if (decelPlus > 0) {
4919 const double previousAcceleration = SPEED2ACCEL(myState.mySpeed - myState.myPreviousSpeed);
4920 if (myAcceleration + NUMERICAL_EPS < previousAcceleration) {
4921 // vehicle brakes beyond wished maximum deceleration (only warn at the start of the braking manoeuvre)
4922 decelPlus += 2 * NUMERICAL_EPS;
4923 const double emergencyFraction = decelPlus / MAX2(NUMERICAL_EPS, getCarFollowModel().getEmergencyDecel() - getCarFollowModel().getMaxDecel());
4924 if (emergencyFraction >= MSGlobals::gEmergencyDecelWarningThreshold) {
4925 WRITE_WARNINGF(TL("Vehicle '%' performs emergency braking on lane '%' with decel=%, wished=%, severity=%, time=%."),
4926 //+ " decelPlus=" + toString(decelPlus)
4927 //+ " prevAccel=" + toString(previousAcceleration)
4928 //+ " reserve=" + toString(MAX2(NUMERICAL_EPS, getCarFollowModel().getEmergencyDecel() - getCarFollowModel().getMaxDecel()))
4929 getID(), myLane->getID(), -myAcceleration, getCarFollowModel().getMaxDecel(), emergencyFraction, time2string(SIMSTEP));
4931 }
4932 }
4933 }
4934
4936 myState.mySpeed = MAX2(vNext, 0.);
4937
4938 if (isRemoteControlled()) {
4939 deltaPos = myInfluencer->implicitDeltaPosRemote(this);
4940 }
4941
4942 myState.myPos += deltaPos;
4943 myState.myLastCoveredDist = deltaPos;
4944 myNextTurn.first -= deltaPos;
4945
4946 if (!parking) {
4948 }
4949}
4950
4951void
4953 updateState(0, true);
4954 // deboard while parked
4955 if (myPersonDevice != nullptr) {
4957 }
4958 if (myContainerDevice != nullptr) {
4960 }
4961 for (MSVehicleDevice* const dev : myDevices) {
4962 dev->notifyParking();
4963 }
4964}
4965
4966
4967void
4973
4974
4975const MSLane*
4977 if (myFurtherLanes.size() > 0) {
4978 return myFurtherLanes.back();
4979 } else {
4980 return myLane;
4981 }
4982}
4983
4984
4985double
4986MSVehicle::updateFurtherLanes(std::vector<MSLane*>& furtherLanes, std::vector<double>& furtherLanesPosLat,
4987 const std::vector<MSLane*>& passedLanes) {
4988#ifdef DEBUG_SETFURTHER
4989 if (DEBUG_COND) std::cout << SIMTIME << " veh=" << getID()
4990 << " updateFurtherLanes oldFurther=" << toString(furtherLanes)
4991 << " oldFurtherPosLat=" << toString(furtherLanesPosLat)
4992 << " passed=" << toString(passedLanes)
4993 << "\n";
4994#endif
4995 for (MSLane* further : furtherLanes) {
4996 further->resetPartialOccupation(this);
4997 if (further->getBidiLane() != nullptr
4998 && (!isRailway(getVClass()) || (further->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
4999 further->getBidiLane()->resetPartialOccupation(this);
5000 }
5001 }
5002
5003 std::vector<MSLane*> newFurther;
5004 std::vector<double> newFurtherPosLat;
5005 double backPosOnPreviousLane = myState.myPos - getLength();
5006 bool widthShift = myFurtherLanesPosLat.size() > myFurtherLanes.size();
5007 if (passedLanes.size() > 1) {
5008 // There are candidates for further lanes. (passedLanes[-1] is the current lane, or current shadow lane in context of updateShadowLanes())
5009 std::vector<MSLane*>::const_iterator fi = furtherLanes.begin();
5010 std::vector<double>::const_iterator fpi = furtherLanesPosLat.begin();
5011 for (auto pi = passedLanes.rbegin() + 1; pi != passedLanes.rend() && backPosOnPreviousLane < 0; ++pi) {
5012 // As long as vehicle back reaches into passed lane, add it to the further lanes
5013 MSLane* further = *pi;
5014 newFurther.push_back(further);
5015 backPosOnPreviousLane += further->setPartialOccupation(this);
5016 if (further->getBidiLane() != nullptr
5017 && (!isRailway(getVClass()) || (further->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5018 further->getBidiLane()->setPartialOccupation(this);
5019 }
5020 if (fi != furtherLanes.end() && further == *fi) {
5021 // Lateral position on this lane is already known. Assume constant and use old value.
5022 newFurtherPosLat.push_back(*fpi);
5023 ++fi;
5024 ++fpi;
5025 } else {
5026 // The lane *pi was not in furtherLanes before.
5027 // If it is downstream, we assume as lateral position the current position
5028 // If it is a new lane upstream (can appear as shadow further in case of LC-maneuvering, e.g.)
5029 // we assign the last known lateral position.
5030 if (newFurtherPosLat.size() == 0) {
5031 if (widthShift) {
5032 newFurtherPosLat.push_back(myFurtherLanesPosLat.back());
5033 } else {
5034 newFurtherPosLat.push_back(myState.myPosLat);
5035 }
5036 } else {
5037 newFurtherPosLat.push_back(newFurtherPosLat.back());
5038 }
5039 }
5040#ifdef DEBUG_SETFURTHER
5041 if (DEBUG_COND) {
5042 std::cout << SIMTIME << " updateFurtherLanes \n"
5043 << " further lane '" << further->getID() << "' backPosOnPreviousLane=" << backPosOnPreviousLane
5044 << std::endl;
5045 }
5046#endif
5047 }
5048 furtherLanes = newFurther;
5049 furtherLanesPosLat = newFurtherPosLat;
5050 } else {
5051 furtherLanes.clear();
5052 furtherLanesPosLat.clear();
5053 }
5054#ifdef DEBUG_SETFURTHER
5055 if (DEBUG_COND) std::cout
5056 << " newFurther=" << toString(furtherLanes)
5057 << " newFurtherPosLat=" << toString(furtherLanesPosLat)
5058 << " newBackPos=" << backPosOnPreviousLane
5059 << "\n";
5060#endif
5061 return backPosOnPreviousLane;
5062}
5063
5064
5065double
5066MSVehicle::getBackPositionOnLane(const MSLane* lane, bool calledByGetPosition) const {
5067#ifdef DEBUG_FURTHER
5068 if (DEBUG_COND) {
5069 std::cout << SIMTIME
5070 << " getBackPositionOnLane veh=" << getID()
5071 << " lane=" << Named::getIDSecure(lane)
5072 << " cbgP=" << calledByGetPosition
5073 << " pos=" << myState.myPos
5074 << " backPos=" << myState.myBackPos
5075 << " myLane=" << myLane->getID()
5076 << " myLaneBidi=" << Named::getIDSecure(myLane->getBidiLane())
5077 << " further=" << toString(myFurtherLanes)
5078 << " furtherPosLat=" << toString(myFurtherLanesPosLat)
5079 << "\n shadowLane=" << Named::getIDSecure(myLaneChangeModel->getShadowLane())
5080 << " shadowFurther=" << toString(myLaneChangeModel->getShadowFurtherLanes())
5081 << " shadowFurtherPosLat=" << toString(myLaneChangeModel->getShadowFurtherLanesPosLat())
5082 << "\n targetLane=" << Named::getIDSecure(myLaneChangeModel->getTargetLane())
5083 << " furtherTargets=" << toString(myLaneChangeModel->getFurtherTargetLanes())
5084 << std::endl;
5085 }
5086#endif
5087 if (lane == myLane
5088 || lane == myLaneChangeModel->getShadowLane()
5089 || lane == myLaneChangeModel->getTargetLane()) {
5091 if (lane == myLaneChangeModel->getShadowLane()) {
5092 return lane->getLength() - myState.myPos - myType->getLength();
5093 } else {
5094 return myState.myPos + (calledByGetPosition ? -1 : 1) * myType->getLength();
5095 }
5096 } else if (&lane->getEdge() != &myLane->getEdge()) {
5097 return lane->getLength() - myState.myPos + (calledByGetPosition ? -1 : 1) * myType->getLength();
5098 } else {
5099 // account for parallel lanes of different lengths in the most conservative manner (i.e. while turning)
5100 return myState.myPos - myType->getLength() + MIN2(0.0, lane->getLength() - myLane->getLength());
5101 }
5102 } else if (lane == myLane->getBidiLane()) {
5103 return lane->getLength() - myState.myPos + myType->getLength() * (calledByGetPosition ? -1 : 1);
5104 } else if (myFurtherLanes.size() > 0 && lane == myFurtherLanes.back()) {
5105 return myState.myBackPos;
5106 } else if ((myLaneChangeModel->getShadowFurtherLanes().size() > 0 && lane == myLaneChangeModel->getShadowFurtherLanes().back())
5107 || (myLaneChangeModel->getFurtherTargetLanes().size() > 0 && lane == myLaneChangeModel->getFurtherTargetLanes().back())) {
5108 assert(myFurtherLanes.size() > 0);
5109 if (lane->getLength() == myFurtherLanes.back()->getLength()) {
5110 return myState.myBackPos;
5111 } else {
5112 // interpolate
5113 //if (DEBUG_COND) {
5114 //if (myFurtherLanes.back()->getLength() != lane->getLength()) {
5115 // std::cout << SIMTIME << " veh=" << getID() << " lane=" << lane->getID() << " further=" << myFurtherLanes.back()->getID()
5116 // << " len=" << lane->getLength() << " fLen=" << myFurtherLanes.back()->getLength()
5117 // << " backPos=" << myState.myBackPos << " result=" << myState.myBackPos / myFurtherLanes.back()->getLength() * lane->getLength() << "\n";
5118 //}
5119 return myState.myBackPos / myFurtherLanes.back()->getLength() * lane->getLength();
5120 }
5121 } else {
5122 //if (DEBUG_COND) std::cout << SIMTIME << " veh=" << getID() << " myFurtherLanes=" << toString(myFurtherLanes) << "\n";
5123 double leftLength = myType->getLength() - myState.myPos;
5124
5125 std::vector<MSLane*>::const_iterator i = myFurtherLanes.begin();
5126 while (leftLength > 0 && i != myFurtherLanes.end()) {
5127 leftLength -= (*i)->getLength();
5128 //if (DEBUG_COND) std::cout << " comparing i=" << (*i)->getID() << " lane=" << lane->getID() << "\n";
5129 if (*i == lane) {
5130 return -leftLength;
5131 } else if (*i == lane->getBidiLane()) {
5132 return lane->getLength() + leftLength - (calledByGetPosition ? 2 * myType->getLength() : 0);
5133 }
5134 ++i;
5135 }
5136 //if (DEBUG_COND) std::cout << SIMTIME << " veh=" << getID() << " myShadowFurtherLanes=" << toString(myLaneChangeModel->getShadowFurtherLanes()) << "\n";
5137 leftLength = myType->getLength() - myState.myPos;
5139 while (leftLength > 0 && i != myLaneChangeModel->getShadowFurtherLanes().end()) {
5140 leftLength -= (*i)->getLength();
5141 //if (DEBUG_COND) std::cout << " comparing i=" << (*i)->getID() << " lane=" << lane->getID() << "\n";
5142 if (*i == lane) {
5143 return -leftLength;
5144 }
5145 ++i;
5146 }
5147 //if (DEBUG_COND) std::cout << SIMTIME << " veh=" << getID() << " myFurtherTargetLanes=" << toString(myLaneChangeModel->getFurtherTargetLanes()) << "\n";
5148 leftLength = myType->getLength() - myState.myPos;
5149 i = getFurtherLanes().begin();
5150 const std::vector<MSLane*> furtherTargetLanes = myLaneChangeModel->getFurtherTargetLanes();
5151 auto j = furtherTargetLanes.begin();
5152 while (leftLength > 0 && j != furtherTargetLanes.end()) {
5153 leftLength -= (*i)->getLength();
5154 // if (DEBUG_COND) std::cout << " comparing i=" << (*i)->getID() << " lane=" << lane->getID() << "\n";
5155 if (*j == lane) {
5156 return -leftLength;
5157 }
5158 ++i;
5159 ++j;
5160 }
5161 WRITE_WARNING("Request backPos of vehicle '" + getID() + "' for invalid lane '" + Named::getIDSecure(lane)
5162 + "' time=" + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".")
5163 SOFT_ASSERT(false);
5164 return myState.myBackPos;
5165 }
5166}
5167
5168
5169double
5171 return getBackPositionOnLane(lane, true) + myType->getLength();
5172}
5173
5174
5175bool
5177 return lane == myLane || lane == myLaneChangeModel->getShadowLane() || lane == myLane->getBidiLane();
5178}
5179
5180
5181void
5182MSVehicle::checkRewindLinkLanes(const double lengthsInFront, DriveItemVector& lfLinks) const {
5184 double seenSpace = -lengthsInFront;
5185#ifdef DEBUG_CHECKREWINDLINKLANES
5186 if (DEBUG_COND) {
5187 std::cout << "\nCHECK_REWIND_LINKLANES\n" << " veh=" << getID() << " lengthsInFront=" << lengthsInFront << "\n";
5188 };
5189#endif
5190 bool foundStopped = false;
5191 // compute available space until a stopped vehicle is found
5192 // this is the sum of non-interal lane length minus in-between vehicle lengths
5193 for (int i = 0; i < (int)lfLinks.size(); ++i) {
5194 // skip unset links
5195 DriveProcessItem& item = lfLinks[i];
5196#ifdef DEBUG_CHECKREWINDLINKLANES
5197 if (DEBUG_COND) std::cout << SIMTIME
5198 << " link=" << (item.myLink == 0 ? "NULL" : item.myLink->getViaLaneOrLane()->getID())
5199 << " foundStopped=" << foundStopped;
5200#endif
5201 if (item.myLink == nullptr || foundStopped) {
5202 if (!foundStopped) {
5203 item.availableSpace += seenSpace;
5204 } else {
5205 item.availableSpace = seenSpace;
5206 }
5207#ifdef DEBUG_CHECKREWINDLINKLANES
5208 if (DEBUG_COND) {
5209 std::cout << " avail=" << item.availableSpace << "\n";
5210 }
5211#endif
5212 continue;
5213 }
5214 // get the next lane, determine whether it is an internal lane
5215 const MSLane* approachedLane = item.myLink->getViaLane();
5216 if (approachedLane != nullptr) {
5217 if (keepClear(item.myLink)) {
5218 seenSpace = seenSpace - approachedLane->getBruttoVehLenSum();
5219 if (approachedLane == myLane) {
5220 seenSpace += getVehicleType().getLengthWithGap();
5221 }
5222 } else {
5223 seenSpace = seenSpace + approachedLane->getSpaceTillLastStanding(this, foundStopped);// - approachedLane->getBruttoVehLenSum() + approachedLane->getLength();
5224 }
5225 item.availableSpace = seenSpace;
5226#ifdef DEBUG_CHECKREWINDLINKLANES
5227 if (DEBUG_COND) std::cout
5228 << " approached=" << approachedLane->getID()
5229 << " approachedBrutto=" << approachedLane->getBruttoVehLenSum()
5230 << " avail=" << item.availableSpace
5231 << " seenSpace=" << seenSpace
5232 << " hadStoppedVehicle=" << item.hadStoppedVehicle
5233 << " lengthsInFront=" << lengthsInFront
5234 << "\n";
5235#endif
5236 continue;
5237 }
5238 approachedLane = item.myLink->getLane();
5239 const MSVehicle* last = approachedLane->getLastAnyVehicle();
5240 if (last == nullptr || last == this) {
5241 if (approachedLane->getLength() > getVehicleType().getLength()
5242 || keepClear(item.myLink)) {
5243 seenSpace += approachedLane->getLength();
5244 }
5245 item.availableSpace = seenSpace;
5246#ifdef DEBUG_CHECKREWINDLINKLANES
5247 if (DEBUG_COND) {
5248 std::cout << " last=" << Named::getIDSecure(last) << " laneLength=" << approachedLane->getLength() << " avail=" << item.availableSpace << "\n";
5249 }
5250#endif
5251 } else {
5252 bool foundStopped2 = false;
5253 double spaceTillLastStanding = approachedLane->getSpaceTillLastStanding(this, foundStopped2);
5254 if (approachedLane->getBidiLane() != nullptr) {
5255 const MSVehicle* oncomingVeh = approachedLane->getBidiLane()->getFirstFullVehicle();
5256 if (oncomingVeh) {
5257 const double oncomingGap = approachedLane->getLength() - oncomingVeh->getPositionOnLane();
5258 const double oncomingBGap = oncomingVeh->getBrakeGap(true);
5259 // oncoming movement until ego enters the junction
5260 const double oncomingMove = STEPS2TIME(item.myArrivalTime - SIMSTEP) * oncomingVeh->getSpeed();
5261 const double spaceTillOncoming = oncomingGap - oncomingBGap - oncomingMove;
5262 spaceTillLastStanding = MIN2(spaceTillLastStanding, spaceTillOncoming);
5263 if (spaceTillOncoming <= getVehicleType().getLengthWithGap()) {
5264 foundStopped = true;
5265 }
5266#ifdef DEBUG_CHECKREWINDLINKLANES
5267 if (DEBUG_COND) {
5268 std::cout << " oVeh=" << oncomingVeh->getID()
5269 << " oGap=" << oncomingGap
5270 << " bGap=" << oncomingBGap
5271 << " mGap=" << oncomingMove
5272 << " sto=" << spaceTillOncoming;
5273 }
5274#endif
5275 }
5276 }
5277 seenSpace += spaceTillLastStanding;
5278 if (foundStopped2) {
5279 foundStopped = true;
5280 item.hadStoppedVehicle = true;
5281 }
5282 item.availableSpace = seenSpace;
5283 if (last->myHaveToWaitOnNextLink || last->isStopped()) {
5284 foundStopped = true;
5285 item.hadStoppedVehicle = true;
5286 }
5287#ifdef DEBUG_CHECKREWINDLINKLANES
5288 if (DEBUG_COND) std::cout
5289 << " approached=" << approachedLane->getID()
5290 << " last=" << last->getID()
5291 << " lastHasToWait=" << last->myHaveToWaitOnNextLink
5292 << " lastBrakeLight=" << last->signalSet(VEH_SIGNAL_BRAKELIGHT)
5293 << " lastBrakeGap=" << last->getCarFollowModel().brakeGap(last->getSpeed())
5294 << " lastGap=" << (last->getBackPositionOnLane(approachedLane) + last->getCarFollowModel().brakeGap(last->getSpeed()) - last->getSpeed() * last->getCarFollowModel().getHeadwayTime()
5295 // gap of last up to the next intersection
5296 - last->getVehicleType().getMinGap())
5297 << " stls=" << spaceTillLastStanding
5298 << " avail=" << item.availableSpace
5299 << " seenSpace=" << seenSpace
5300 << " foundStopped=" << foundStopped
5301 << " foundStopped2=" << foundStopped2
5302 << "\n";
5303#endif
5304 }
5305 }
5306
5307 // check which links allow continuation and add pass available to the previous item
5308 for (int i = ((int)lfLinks.size() - 1); i > 0; --i) {
5309 DriveProcessItem& item = lfLinks[i - 1];
5310 DriveProcessItem& nextItem = lfLinks[i];
5311 const bool canLeaveJunction = item.myLink->getViaLane() == nullptr || nextItem.myLink == nullptr || nextItem.mySetRequest;
5312 const bool opened = (item.myLink != nullptr
5313 && (canLeaveJunction || (
5314 // indirect bicycle turn
5315 nextItem.myLink != nullptr && nextItem.myLink->isInternalJunctionLink() && nextItem.myLink->haveRed()))
5316 && (
5317 item.myLink->havePriority()
5318 || i == 1 // the upcoming link (item 0) is checked in executeMove anyway. No need to use outdata approachData here
5320 || item.myLink->opened(item.myArrivalTime, item.myArrivalSpeed,
5323 bool allowsContinuation = (item.myLink == nullptr || item.myLink->isCont() || opened) && !item.hadStoppedVehicle;
5324#ifdef DEBUG_CHECKREWINDLINKLANES
5325 if (DEBUG_COND) std::cout
5326 << " link=" << (item.myLink == 0 ? "NULL" : item.myLink->getViaLaneOrLane()->getID())
5327 << " canLeave=" << canLeaveJunction
5328 << " opened=" << opened
5329 << " allowsContinuation=" << allowsContinuation
5330 << " foundStopped=" << foundStopped
5331 << "\n";
5332#endif
5333 if (!opened && item.myLink != nullptr) {
5334 foundStopped = true;
5335 if (i > 1) {
5336 DriveProcessItem& item2 = lfLinks[i - 2];
5337 if (item2.myLink != nullptr && item2.myLink->isCont()) {
5338 allowsContinuation = true;
5339 }
5340 }
5341 }
5342 if (allowsContinuation) {
5343 item.availableSpace = nextItem.availableSpace;
5344#ifdef DEBUG_CHECKREWINDLINKLANES
5345 if (DEBUG_COND) std::cout
5346 << " link=" << (item.myLink == nullptr ? "NULL" : item.myLink->getViaLaneOrLane()->getID())
5347 << " copy nextAvail=" << nextItem.availableSpace
5348 << "\n";
5349#endif
5350 }
5351 }
5352
5353 // find removalBegin
5354 int removalBegin = -1;
5355 for (int i = 0; foundStopped && i < (int)lfLinks.size() && removalBegin < 0; ++i) {
5356 // skip unset links
5357 const DriveProcessItem& item = lfLinks[i];
5358 if (item.myLink == nullptr) {
5359 continue;
5360 }
5361 /*
5362 double impatienceCorrection = MAX2(0., double(double(myWaitingTime)));
5363 if (seenSpace<getVehicleType().getLengthWithGap()-impatienceCorrection/10.&&nextSeenNonInternal!=0) {
5364 removalBegin = lastLinkToInternal;
5365 }
5366 */
5367
5368 const double leftSpace = item.availableSpace - getVehicleType().getLengthWithGap();
5369#ifdef DEBUG_CHECKREWINDLINKLANES
5370 if (DEBUG_COND) std::cout
5371 << SIMTIME
5372 << " veh=" << getID()
5373 << " link=" << (item.myLink == 0 ? "NULL" : item.myLink->getViaLaneOrLane()->getID())
5374 << " avail=" << item.availableSpace
5375 << " leftSpace=" << leftSpace
5376 << "\n";
5377#endif
5378 if (leftSpace < 0/* && item.myLink->willHaveBlockedFoe()*/) {
5379 double impatienceCorrection = 0;
5380 /*
5381 if(item.myLink->getState()==LINKSTATE_MINOR) {
5382 impatienceCorrection = MAX2(0., STEPS2TIME(myWaitingTime));
5383 }
5384 */
5385 // may ignore keepClear rules
5386 if (leftSpace < -impatienceCorrection / 10. && keepClear(item.myLink)) {
5387 removalBegin = i;
5388 }
5389 //removalBegin = i;
5390 }
5391 }
5392 // abort requests
5393 if (removalBegin != -1 && !(removalBegin == 0 && myLane->getEdge().isInternal())) {
5394 const double brakeGap = getCarFollowModel().brakeGap(myState.mySpeed, getCarFollowModel().getMaxDecel(), 0.);
5395 while (removalBegin < (int)(lfLinks.size())) {
5396 DriveProcessItem& dpi = lfLinks[removalBegin];
5397 if (dpi.myLink == nullptr) {
5398 break;
5399 }
5400 dpi.myVLinkPass = dpi.myVLinkWait;
5401#ifdef DEBUG_CHECKREWINDLINKLANES
5402 if (DEBUG_COND) {
5403 std::cout << " removalBegin=" << removalBegin << " brakeGap=" << brakeGap << " dist=" << dpi.myDistance << " speed=" << myState.mySpeed << " a2s=" << ACCEL2SPEED(getCarFollowModel().getMaxDecel()) << "\n";
5404 }
5405#endif
5406 if (dpi.myDistance >= brakeGap + POSITION_EPS) {
5407 // always leave junctions after requesting to enter
5408 if (!dpi.myLink->isExitLink() || !lfLinks[removalBegin - 1].mySetRequest) {
5409 dpi.mySetRequest = false;
5410 }
5411 }
5412 ++removalBegin;
5413 }
5414 }
5415 }
5416}
5417
5418
5419void
5421 if (!myActionStep) {
5422 return;
5423 }
5425 for (DriveProcessItem& dpi : myLFLinkLanes) {
5426 if (dpi.myLink != nullptr) {
5427 if (dpi.myLink->getState() == LINKSTATE_ALLWAY_STOP) {
5428 dpi.myArrivalTime += (SUMOTime)RandHelper::rand((int)2, getRNG()); // tie braker
5429 }
5430 dpi.myLink->setApproaching(this, dpi.myArrivalTime, dpi.myArrivalSpeed, dpi.getLeaveSpeed(),
5431 dpi.mySetRequest, dpi.myArrivalSpeedBraking, getWaitingTimeFor(dpi.myLink), dpi.myDistance, getLateralPositionOnLane());
5432 }
5433 }
5434 if (isRail()) {
5435 for (DriveProcessItem& dpi : myLFLinkLanes) {
5436 if (dpi.myLink != nullptr && dpi.myLink->getTLLogic() != nullptr && dpi.myLink->getTLLogic()->getLogicType() == TrafficLightType::RAIL_SIGNAL) {
5438 }
5439 }
5440 }
5441 if (myLaneChangeModel->getShadowLane() != nullptr) {
5442 // register on all shadow links
5443 for (const DriveProcessItem& dpi : myLFLinkLanes) {
5444 if (dpi.myLink != nullptr) {
5445 MSLink* parallelLink = dpi.myLink->getParallelLink(myLaneChangeModel->getShadowDirection());
5446 if (parallelLink == nullptr && getLaneChangeModel().isOpposite() && dpi.myLink->isEntryLink()) {
5447 // register on opposite direction entry link to warn foes at minor side road
5448 parallelLink = dpi.myLink->getOppositeDirectionLink();
5449 }
5450 if (parallelLink != nullptr) {
5451 const double latOffset = getLane()->getRightSideOnEdge() - myLaneChangeModel->getShadowLane()->getRightSideOnEdge();
5452 parallelLink->setApproaching(this, dpi.myArrivalTime, dpi.myArrivalSpeed, dpi.getLeaveSpeed(),
5453 dpi.mySetRequest, dpi.myArrivalSpeedBraking, getWaitingTimeFor(dpi.myLink), dpi.myDistance,
5454 latOffset);
5456 }
5457 }
5458 }
5459 }
5460#ifdef DEBUG_PLAN_MOVE
5461 if (DEBUG_COND) {
5462 std::cout << SIMTIME
5463 << " veh=" << getID()
5464 << " after checkRewindLinkLanes\n";
5465 for (DriveProcessItem& dpi : myLFLinkLanes) {
5466 std::cout
5467 << " vPass=" << dpi.myVLinkPass
5468 << " vWait=" << dpi.myVLinkWait
5469 << " linkLane=" << (dpi.myLink == 0 ? "NULL" : dpi.myLink->getViaLaneOrLane()->getID())
5470 << " request=" << dpi.mySetRequest
5471 << " atime=" << dpi.myArrivalTime
5472 << "\n";
5473 }
5474 }
5475#endif
5476}
5477
5478
5479void
5481 DriveProcessItem dpi(0, dist);
5482 dpi.myLink = link;
5483 const double arrivalSpeedBraking = getCarFollowModel().getMinimalArrivalSpeedEuler(dist, getSpeed());
5484 link->setApproaching(this, SUMOTime_MAX, 0, 0, false, arrivalSpeedBraking, 0, dpi.myDistance, 0);
5485 // ensure cleanup in the next step
5486 myLFLinkLanes.push_back(dpi);
5488}
5489
5490
5491void
5492MSVehicle::enterLaneAtMove(MSLane* enteredLane, bool onTeleporting) {
5493 myAmOnNet = !onTeleporting;
5494 // vaporizing edge?
5495 /*
5496 if (enteredLane->getEdge().isVaporizing()) {
5497 // yep, let's do the vaporization...
5498 myLane = enteredLane;
5499 return true;
5500 }
5501 */
5502 // Adjust MoveReminder offset to the next lane
5503 adaptLaneEntering2MoveReminder(*enteredLane);
5504 // set the entered lane as the current lane
5505 MSLane* oldLane = myLane;
5506 myLane = enteredLane;
5507 myLastBestLanesEdge = nullptr;
5508
5509 // internal edges are not a part of the route...
5510 if (!enteredLane->getEdge().isInternal()) {
5511 ++myCurrEdge;
5513 }
5514 if (myInfluencer != nullptr) {
5516 }
5517 if (!onTeleporting) {
5521 // transform lateral position when the lane width changes
5522 assert(oldLane != nullptr);
5523 const MSLink* const link = oldLane->getLinkTo(myLane);
5524 if (link != nullptr) {
5525 myState.myPosLat += link->getLateralShift();
5526 } else {
5528 }
5529 } else if (fabs(myState.myPosLat) > NUMERICAL_EPS) {
5530 const double overlap = MAX2(0.0, getLateralOverlap(myState.myPosLat, oldLane));
5531 const double range = (oldLane->getWidth() - getVehicleType().getWidth()) * 0.5 + overlap;
5532 const double range2 = (myLane->getWidth() - getVehicleType().getWidth()) * 0.5 + overlap;
5533 myState.myPosLat *= range2 / range;
5534 }
5535 if (myLane->getBidiLane() != nullptr && (!isRailway(getVClass()) || (myLane->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5536 // railways don't need to "see" each other when moving in opposite directions on the same track (efficiency)
5537 // (unless the lane is shared with cars)
5539 }
5540 } else {
5541 // normal move() isn't called so reset position here. must be done
5542 // before calling reminders
5543 myState.myPos = 0;
5546 }
5547 // update via
5548 if (myParameter->via.size() > 0 && myLane->getEdge().getID() == myParameter->via.front()) {
5549 myParameter->via.erase(myParameter->via.begin());
5550 }
5551}
5552
5553
5554void
5556 myAmOnNet = true;
5557 myLane = enteredLane;
5559 // need to update myCurrentLaneInBestLanes
5561 // switch to and activate the new lane's reminders
5562 // keep OldLaneReminders
5563 for (std::vector< MSMoveReminder* >::const_iterator rem = enteredLane->getMoveReminders().begin(); rem != enteredLane->getMoveReminders().end(); ++rem) {
5564 addReminder(*rem);
5565 }
5567 MSLane* lane = myLane;
5568 double leftLength = getVehicleType().getLength() - myState.myPos;
5569 int deleteFurther = 0;
5570#ifdef DEBUG_SETFURTHER
5571 if (DEBUG_COND) {
5572 std::cout << SIMTIME << " enterLaneAtLaneChange entered=" << Named::getIDSecure(enteredLane) << " oldFurther=" << toString(myFurtherLanes) << "\n";
5573 }
5574#endif
5575 if (myLane->getBidiLane() != nullptr && (!isRailway(getVClass()) || (myLane->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5576 // railways don't need to "see" each other when moving in opposite directions on the same track (efficiency)
5577 // (unless the lane is shared with cars)
5579 }
5580 for (int i = 0; i < (int)myFurtherLanes.size(); i++) {
5581 if (lane != nullptr) {
5583 }
5584#ifdef DEBUG_SETFURTHER
5585 if (DEBUG_COND) {
5586 std::cout << " enterLaneAtLaneChange i=" << i << " lane=" << Named::getIDSecure(lane) << " leftLength=" << leftLength << "\n";
5587 }
5588#endif
5589 if (leftLength > 0) {
5590 if (lane != nullptr) {
5592 if (myFurtherLanes[i]->getBidiLane() != nullptr
5593 && (!isRailway(getVClass()) || (myFurtherLanes[i]->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5594 myFurtherLanes[i]->getBidiLane()->resetPartialOccupation(this);
5595 }
5596 // lane changing onto longer lanes may reduce the number of
5597 // remaining further lanes
5598 myFurtherLanes[i] = lane;
5600 leftLength -= lane->setPartialOccupation(this);
5601 if (lane->getBidiLane() != nullptr
5602 && (!isRailway(getVClass()) || (lane->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5603 lane->getBidiLane()->setPartialOccupation(this);
5604 }
5605 myState.myBackPos = -leftLength;
5606#ifdef DEBUG_SETFURTHER
5607 if (DEBUG_COND) {
5608 std::cout << SIMTIME << " newBackPos=" << myState.myBackPos << "\n";
5609 }
5610#endif
5611 } else {
5612 // keep the old values, but ensure there is no shadow
5615 }
5616 if (myState.myBackPos < 0) {
5617 myState.myBackPos += myFurtherLanes[i]->getLength();
5618 }
5619#ifdef DEBUG_SETFURTHER
5620 if (DEBUG_COND) {
5621 std::cout << SIMTIME << " i=" << i << " further=" << myFurtherLanes[i]->getID() << " newBackPos=" << myState.myBackPos << "\n";
5622 }
5623#endif
5624 }
5625 } else {
5626 myFurtherLanes[i]->resetPartialOccupation(this);
5627 if (myFurtherLanes[i]->getBidiLane() != nullptr
5628 && (!isRailway(getVClass()) || (myFurtherLanes[i]->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5629 myFurtherLanes[i]->getBidiLane()->resetPartialOccupation(this);
5630 }
5631 deleteFurther++;
5632 }
5633 }
5634 if (deleteFurther > 0) {
5635#ifdef DEBUG_SETFURTHER
5636 if (DEBUG_COND) {
5637 std::cout << SIMTIME << " veh=" << getID() << " shortening myFurtherLanes by " << deleteFurther << "\n";
5638 }
5639#endif
5640 myFurtherLanes.erase(myFurtherLanes.end() - deleteFurther, myFurtherLanes.end());
5641 myFurtherLanesPosLat.erase(myFurtherLanesPosLat.end() - deleteFurther, myFurtherLanesPosLat.end());
5642 }
5643#ifdef DEBUG_SETFURTHER
5644 if (DEBUG_COND) {
5645 std::cout << SIMTIME << " enterLaneAtLaneChange new furtherLanes=" << toString(myFurtherLanes)
5646 << " furterLanesPosLat=" << toString(myFurtherLanesPosLat) << "\n";
5647 }
5648#endif
5650}
5651
5652
5653void
5654MSVehicle::computeFurtherLanes(MSLane* enteredLane, double pos, bool collision) {
5655 // build the list of lanes the vehicle is lapping into
5656 if (!myLaneChangeModel->isOpposite()) {
5657 double leftLength = myType->getLength() - pos;
5658 MSLane* clane = enteredLane;
5659 int routeIndex = getRoutePosition();
5660 while (leftLength > 0) {
5661 if (routeIndex > 0 && clane->getEdge().isNormal()) {
5662 // get predecessor lane that corresponds to prior route
5663 routeIndex--;
5664 const MSEdge* fromRouteEdge = myRoute->getEdges()[routeIndex];
5665 MSLane* target = clane;
5666 clane = nullptr;
5667 for (auto ili : target->getIncomingLanes()) {
5668 if (ili.lane->getEdge().getNormalBefore() == fromRouteEdge) {
5669 clane = ili.lane;
5670 break;
5671 }
5672 }
5673 } else {
5674 clane = clane->getLogicalPredecessorLane();
5675 }
5676 if (clane == nullptr || clane == myLane || clane == myLane->getBidiLane()
5677 || (clane->isInternal() && (
5678 clane->getLinkCont()[0]->getDirection() == LinkDirection::TURN
5679 || clane->getLinkCont()[0]->getDirection() == LinkDirection::TURN_LEFTHAND))) {
5680 break;
5681 }
5682 if (!collision || std::find(myFurtherLanes.begin(), myFurtherLanes.end(), clane) == myFurtherLanes.end()) {
5683 myFurtherLanes.push_back(clane);
5685 clane->setPartialOccupation(this);
5686 if (clane->getBidiLane() != nullptr
5687 && (!isRailway(getVClass()) || (clane->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5688 clane->getBidiLane()->setPartialOccupation(this);
5689 }
5690 }
5691 leftLength -= clane->getLength();
5692 }
5693 myState.myBackPos = -leftLength;
5694#ifdef DEBUG_SETFURTHER
5695 if (DEBUG_COND) {
5696 std::cout << SIMTIME << " computeFurtherLanes veh=" << getID() << " pos=" << pos << " myFurtherLanes=" << toString(myFurtherLanes) << " backPos=" << myState.myBackPos << "\n";
5697 }
5698#endif
5699 } else {
5700 // clear partial occupation
5701 for (MSLane* further : myFurtherLanes) {
5702#ifdef DEBUG_SETFURTHER
5703 if (DEBUG_COND) {
5704 std::cout << SIMTIME << " opposite: resetPartialOccupation " << further->getID() << " \n";
5705 }
5706#endif
5707 further->resetPartialOccupation(this);
5708 if (further->getBidiLane() != nullptr
5709 && (!isRailway(getVClass()) || (further->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5710 further->getBidiLane()->resetPartialOccupation(this);
5711 }
5712 }
5713 myFurtherLanes.clear();
5714 myFurtherLanesPosLat.clear();
5715 }
5716}
5717
5718
5719void
5720MSVehicle::enterLaneAtInsertion(MSLane* enteredLane, double pos, double speed, double posLat, MSMoveReminder::Notification notification) {
5721 myState = State(pos, speed, posLat, pos - getVehicleType().getLength(), hasDeparted() ? myState.myPreviousSpeed : speed);
5723 onDepart();
5724 }
5726 assert(myState.myPos >= 0);
5727 assert(myState.mySpeed >= 0);
5728 myLane = enteredLane;
5729 myAmOnNet = true;
5730 // schedule action for the next timestep
5732 if (notification != MSMoveReminder::NOTIFICATION_TELEPORT) {
5733 if (notification == MSMoveReminder::NOTIFICATION_PARKING && myInfluencer != nullptr) {
5734 drawOutsideNetwork(false);
5735 }
5736 // set and activate the new lane's reminders, teleports already did that at enterLaneAtMove
5737 for (std::vector< MSMoveReminder* >::const_iterator rem = enteredLane->getMoveReminders().begin(); rem != enteredLane->getMoveReminders().end(); ++rem) {
5738 addReminder(*rem);
5739 }
5740 activateReminders(notification, enteredLane);
5741 } else {
5742 myLastBestLanesEdge = nullptr;
5745 while (!myStops.empty() && myStops.front().edge == myCurrEdge && &myStops.front().lane->getEdge() == &myLane->getEdge()
5746 && myStops.front().pars.endPos < pos) {
5747 WRITE_WARNINGF(TL("Vehicle '%' skips stop on lane '%' time=%."), getID(), myStops.front().lane->getID(),
5748 time2string(MSNet::getInstance()->getCurrentTimeStep()));
5750 myStops.pop_front();
5751 }
5752 // avoid startup-effects after teleport
5754 myStopSpeed = std::numeric_limits<double>::max();
5755 }
5756 computeFurtherLanes(enteredLane, pos);
5760 } else if (MSGlobals::gLaneChangeDuration > 0) {
5762 }
5763 if (notification != MSMoveReminder::NOTIFICATION_LOAD_STATE) {
5766 myAngle += M_PI;
5767 }
5768 }
5769 if (MSNet::getInstance()->hasPersons()) {
5770 for (MSLane* further : myFurtherLanes) {
5771 if (further->mustCheckJunctionCollisions()) {
5773 }
5774 }
5775 }
5776}
5777
5778
5779void
5780MSVehicle::leaveLane(const MSMoveReminder::Notification reason, const MSLane* approachedLane) {
5781 for (MoveReminderCont::iterator rem = myMoveReminders.begin(); rem != myMoveReminders.end();) {
5782 if (rem->first->notifyLeave(*this, myState.myPos + rem->second, reason, approachedLane)) {
5783#ifdef _DEBUG
5784 if (myTraceMoveReminders) {
5785 traceMoveReminder("notifyLeave", rem->first, rem->second, true);
5786 }
5787#endif
5788 ++rem;
5789 } else {
5790#ifdef _DEBUG
5791 if (myTraceMoveReminders) {
5792 traceMoveReminder("notifyLeave", rem->first, rem->second, false);
5793 }
5794#endif
5795 rem = myMoveReminders.erase(rem);
5796 }
5797 }
5801 && myLane != nullptr) {
5803 }
5804 if (myLane != nullptr && myLane->getBidiLane() != nullptr && myAmOnNet
5805 && (!isRailway(getVClass()) || (myLane->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5807 }
5809 // @note. In case of lane change, myFurtherLanes and partial occupation
5810 // are handled in enterLaneAtLaneChange()
5811 for (MSLane* further : myFurtherLanes) {
5812#ifdef DEBUG_FURTHER
5813 if (DEBUG_COND) {
5814 std::cout << SIMTIME << " leaveLane \n";
5815 }
5816#endif
5817 further->resetPartialOccupation(this);
5818 if (further->getBidiLane() != nullptr
5819 && (!isRailway(getVClass()) || (further->getPermissions() & ~SVC_RAIL_CLASSES) != 0)) {
5820 further->getBidiLane()->resetPartialOccupation(this);
5821 }
5822 }
5823 myFurtherLanes.clear();
5824 myFurtherLanesPosLat.clear();
5825 }
5827 myAmOnNet = false;
5828 myWaitingTime = 0;
5829 }
5831 myStopDist = std::numeric_limits<double>::max();
5832 if (myPastStops.back().speed <= 0) {
5833 WRITE_WARNINGF(TL("Vehicle '%' aborts stop."), getID());
5834 }
5835 }
5837 while (!myStops.empty() && myStops.front().edge == myCurrEdge && &myStops.front().lane->getEdge() == &myLane->getEdge()) {
5838 if (myStops.front().getSpeed() <= 0) {
5839 WRITE_WARNINGF(TL("Vehicle '%' skips stop on lane '%' time=%."), getID(), myStops.front().lane->getID(),
5840 time2string(MSNet::getInstance()->getCurrentTimeStep()));
5842 if (MSStopOut::active()) {
5843 // clean up if stopBlocked was called
5845 }
5846 myStops.pop_front();
5847 } else {
5848 MSStop& stop = myStops.front();
5849 // passed waypoint at the end of the lane
5850 if (!stop.reached) {
5851 if (MSStopOut::active()) {
5853 }
5854 stop.reached = true;
5855 // enter stopping place so leaveFrom works as expected
5856 if (stop.busstop != nullptr) {
5857 // let the bus stop know the vehicle
5858 stop.busstop->enter(this, stop.pars.parking == ParkingType::OFFROAD);
5859 }
5860 if (stop.containerstop != nullptr) {
5861 // let the container stop know the vehicle
5863 }
5864 // do not enter parkingarea!
5865 if (stop.chargingStation != nullptr) {
5866 // let the container stop know the vehicle
5868 }
5869 }
5871 }
5872 myStopDist = std::numeric_limits<double>::max();
5873 }
5874 }
5875}
5876
5877
5878void
5880 for (MoveReminderCont::iterator rem = myMoveReminders.begin(); rem != myMoveReminders.end();) {
5881 if (rem->first->notifyLeaveBack(*this, reason, leftLane)) {
5882#ifdef _DEBUG
5883 if (myTraceMoveReminders) {
5884 traceMoveReminder("notifyLeaveBack", rem->first, rem->second, true);
5885 }
5886#endif
5887 ++rem;
5888 } else {
5889#ifdef _DEBUG
5890 if (myTraceMoveReminders) {
5891 traceMoveReminder("notifyLeaveBack", rem->first, rem->second, false);
5892 }
5893#endif
5894 rem = myMoveReminders.erase(rem);
5895 }
5896 }
5897#ifdef DEBUG_MOVEREMINDERS
5898 if (DEBUG_COND) {
5899 std::cout << SIMTIME << " veh=" << getID() << " myReminders:";
5900 for (auto rem : myMoveReminders) {
5901 std::cout << rem.first->getDescription() << " ";
5902 }
5903 std::cout << "\n";
5904 }
5905#endif
5906}
5907
5908
5913
5914
5919
5920bool
5922 return (lane->isInternal()
5923 ? & (lane->getLinkCont()[0]->getLane()->getEdge()) != *(myCurrEdge + 1)
5924 : &lane->getEdge() != *myCurrEdge);
5925}
5926
5927const std::vector<MSVehicle::LaneQ>&
5929 return *myBestLanes.begin();
5930}
5931
5932
5933void
5934MSVehicle::updateBestLanes(bool forceRebuild, const MSLane* startLane) {
5935#ifdef DEBUG_BESTLANES
5936 if (DEBUG_COND) {
5937 std::cout << SIMTIME << " updateBestLanes veh=" << getID() << " force=" << forceRebuild << " startLane1=" << Named::getIDSecure(startLane) << " myLane=" << Named::getIDSecure(myLane) << "\n";
5938 }
5939#endif
5940 if (startLane == nullptr) {
5941 startLane = myLane;
5942 }
5943 assert(startLane != 0);
5945 // depending on the calling context, startLane might be the forward lane
5946 // or the reverse-direction lane. In the latter case we need to
5947 // transform it to the forward lane.
5948 if (isOppositeLane(startLane)) {
5949 // use leftmost lane of forward edge
5950 startLane = startLane->getEdge().getOppositeEdge()->getLanes().back();
5951 assert(startLane != 0);
5952#ifdef DEBUG_BESTLANES
5953 if (DEBUG_COND) {
5954 std::cout << " startLaneIsOpposite newStartLane=" << startLane->getID() << "\n";
5955 }
5956#endif
5957 }
5958 }
5959 if (forceRebuild) {
5960 myLastBestLanesEdge = nullptr;
5962 }
5963 if (myBestLanes.size() > 0 && !forceRebuild && myLastBestLanesEdge == &startLane->getEdge()) {
5965#ifdef DEBUG_BESTLANES
5966 if (DEBUG_COND) {
5967 std::cout << " only updateOccupancyAndCurrentBestLane\n";
5968 }
5969#endif
5970 return;
5971 }
5972 if (startLane->getEdge().isInternal()) {
5973 if (myBestLanes.size() == 0 || forceRebuild) {
5974 // rebuilt from previous non-internal lane (may backtrack twice if behind an internal junction)
5975 updateBestLanes(true, startLane->getLogicalPredecessorLane());
5976 }
5977 if (myLastBestLanesInternalLane == startLane && !forceRebuild) {
5978#ifdef DEBUG_BESTLANES
5979 if (DEBUG_COND) {
5980 std::cout << " nothing to do on internal\n";
5981 }
5982#endif
5983 return;
5984 }
5985 // adapt best lanes to fit the current internal edge:
5986 // keep the entries that are reachable from this edge
5987 const MSEdge* nextEdge = startLane->getNextNormal();
5988 assert(!nextEdge->isInternal());
5989 for (std::vector<std::vector<LaneQ> >::iterator it = myBestLanes.begin(); it != myBestLanes.end();) {
5990 std::vector<LaneQ>& lanes = *it;
5991 assert(lanes.size() > 0);
5992 if (&(lanes[0].lane->getEdge()) == nextEdge) {
5993 // keep those lanes which are successors of internal lanes from the edge of startLane
5994 std::vector<LaneQ> oldLanes = lanes;
5995 lanes.clear();
5996 const std::vector<MSLane*>& sourceLanes = startLane->getEdge().getLanes();
5997 for (std::vector<MSLane*>::const_iterator it_source = sourceLanes.begin(); it_source != sourceLanes.end(); ++it_source) {
5998 for (std::vector<LaneQ>::iterator it_lane = oldLanes.begin(); it_lane != oldLanes.end(); ++it_lane) {
5999 if ((*it_source)->getLinkCont()[0]->getLane() == (*it_lane).lane) {
6000 lanes.push_back(*it_lane);
6001 break;
6002 }
6003 }
6004 }
6005 assert(lanes.size() == startLane->getEdge().getLanes().size());
6006 // patch invalid bestLaneOffset and updated myCurrentLaneInBestLanes
6007 for (int i = 0; i < (int)lanes.size(); ++i) {
6008 if (i + lanes[i].bestLaneOffset < 0) {
6009 lanes[i].bestLaneOffset = -i;
6010 }
6011 if (i + lanes[i].bestLaneOffset >= (int)lanes.size()) {
6012 lanes[i].bestLaneOffset = (int)lanes.size() - i - 1;
6013 }
6014 assert(i + lanes[i].bestLaneOffset >= 0);
6015 assert(i + lanes[i].bestLaneOffset < (int)lanes.size());
6016 if (lanes[i].bestContinuations[0] != 0) {
6017 // patch length of bestContinuation to match expectations (only once)
6018 lanes[i].bestContinuations.insert(lanes[i].bestContinuations.begin(), (MSLane*)nullptr);
6019 }
6020 if (startLane->getLinkCont()[0]->getLane() == lanes[i].lane) {
6021 myCurrentLaneInBestLanes = lanes.begin() + i;
6022 }
6023 assert(&(lanes[i].lane->getEdge()) == nextEdge);
6024 }
6025 myLastBestLanesInternalLane = startLane;
6027#ifdef DEBUG_BESTLANES
6028 if (DEBUG_COND) {
6029 std::cout << " updated for internal\n";
6030 }
6031#endif
6032 return;
6033 } else {
6034 // remove passed edges
6035 it = myBestLanes.erase(it);
6036 }
6037 }
6038 assert(false); // should always find the next edge
6039 }
6040 // start rebuilding
6042 myLastBestLanesEdge = &startLane->getEdge();
6044
6045 // get information about the next stop
6046 MSRouteIterator nextStopEdge = myRoute->end();
6047 const MSLane* nextStopLane = nullptr;
6048 double nextStopPos = 0;
6049 bool nextStopIsWaypoint = false;
6050 if (!myStops.empty()) {
6051 const MSStop& nextStop = myStops.front();
6052 nextStopLane = nextStop.lane;
6053 if (nextStop.isOpposite) {
6054 // target leftmost lane in forward direction
6055 nextStopLane = nextStopLane->getEdge().getOppositeEdge()->getLanes().back();
6056 }
6057 nextStopEdge = nextStop.edge;
6058 nextStopPos = nextStop.pars.startPos;
6059 nextStopIsWaypoint = nextStop.getSpeed() > 0;
6060 }
6061 // myArrivalTime = -1 in the context of validating departSpeed with departLane=best
6062 if (myParameter->arrivalLaneProcedure >= ArrivalLaneDefinition::GIVEN && nextStopEdge == myRoute->end() && myArrivalLane >= 0) {
6063 nextStopEdge = (myRoute->end() - 1);
6064 nextStopLane = (*nextStopEdge)->getLanes()[myArrivalLane];
6065 nextStopPos = myArrivalPos;
6066 }
6067 if (nextStopEdge != myRoute->end()) {
6068 // make sure that the "wrong" lanes get a penalty. (penalty needs to be
6069 // large enough to overcome a magic threshold in MSLaneChangeModel::DK2004.cpp:383)
6070 nextStopPos = MAX2(POSITION_EPS, MIN2((double)nextStopPos, (double)(nextStopLane->getLength() - 2 * POSITION_EPS)));
6071 if (nextStopLane->isInternal()) {
6072 // switch to the correct lane before entering the intersection
6073 nextStopPos = (*nextStopEdge)->getLength();
6074 }
6075 }
6076
6077 // go forward along the next lanes;
6078 // trains do not have to deal with lane-changing for stops but their best
6079 // lanes lookahead is needed for rail signal control
6080 const bool continueAfterStop = nextStopIsWaypoint || isRailway(getVClass());
6081 int seen = 0;
6082 double seenLength = 0;
6083 bool progress = true;
6084 // bestLanes must cover the braking distance even when at the very end of the current lane to avoid unecessary slow down
6085 const double maxBrakeDist = startLane->getLength() + getCarFollowModel().getHeadwayTime() * getMaxSpeed() + getCarFollowModel().brakeGap(getMaxSpeed()) + getVehicleType().getMinGap();
6086 const double lookahead = getLaneChangeModel().getStrategicLookahead();
6087 for (MSRouteIterator ce = myCurrEdge; progress;) {
6088 std::vector<LaneQ> currentLanes;
6089 const std::vector<MSLane*>* allowed = nullptr;
6090 const MSEdge* nextEdge = nullptr;
6091 if (ce != myRoute->end() && ce + 1 != myRoute->end()) {
6092 nextEdge = *(ce + 1);
6093 allowed = (*ce)->allowedLanes(*nextEdge, myType->getVehicleClass());
6094 }
6095 const std::vector<MSLane*>& lanes = (*ce)->getLanes();
6096 for (std::vector<MSLane*>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
6097 LaneQ q;
6098 MSLane* cl = *i;
6099 q.lane = cl;
6100 q.bestContinuations.push_back(cl);
6101 q.bestLaneOffset = 0;
6102 q.length = cl->allowsVehicleClass(myType->getVehicleClass()) ? (*ce)->getLength() : 0;
6103 q.currentLength = q.length;
6104 // if all lanes are forbidden (i.e. due to a dynamic closing) we want to express no preference
6105 q.allowsContinuation = allowed == nullptr || std::find(allowed->begin(), allowed->end(), cl) != allowed->end();
6106 q.occupation = 0;
6107 q.nextOccupation = 0;
6108 currentLanes.push_back(q);
6109 }
6110 //
6111 if (nextStopEdge == ce
6112 // already past the stop edge
6113 && !(ce == myCurrEdge && myLane != nullptr && myLane->isInternal())) {
6114 if (!nextStopLane->isInternal() && !continueAfterStop) {
6115 progress = false;
6116 }
6117 const MSLane* normalStopLane = nextStopLane->getNormalPredecessorLane();
6118 for (std::vector<LaneQ>::iterator q = currentLanes.begin(); q != currentLanes.end(); ++q) {
6119 if (nextStopLane != nullptr && normalStopLane != (*q).lane) {
6120 (*q).allowsContinuation = false;
6121 (*q).length = nextStopPos;
6122 (*q).currentLength = (*q).length;
6123 }
6124 }
6125 }
6126
6127 myBestLanes.push_back(currentLanes);
6128 ++seen;
6129 seenLength += currentLanes[0].lane->getLength();
6130 ++ce;
6131 if (lookahead >= 0) {
6132 progress &= (seen <= 2 || seenLength < lookahead); // custom (but we need to look at least one edge ahead)
6133 } else {
6134 progress &= (seen <= 4 || seenLength < MAX2(maxBrakeDist, 3000.0)); // motorway
6135 progress &= (seen <= 8 || seenLength < MAX2(maxBrakeDist, 200.0) || isRailway(getVClass())); // urban
6136 }
6137 progress &= ce != myRoute->end();
6138 /*
6139 if(progress) {
6140 progress &= (currentLanes.size()!=1||(*ce)->getLanes().size()!=1);
6141 }
6142 */
6143 }
6144
6145 // we are examining the last lane explicitly
6146 if (myBestLanes.size() != 0) {
6147 double bestLength = -1;
6148 // minimum and maximum lane index with best length
6149 int bestThisIndex = 0;
6150 int bestThisMaxIndex = 0;
6151 int index = 0;
6152 std::vector<LaneQ>& last = myBestLanes.back();
6153 for (std::vector<LaneQ>::iterator j = last.begin(); j != last.end(); ++j, ++index) {
6154 if ((*j).length > bestLength) {
6155 bestLength = (*j).length;
6156 bestThisIndex = index;
6157 bestThisMaxIndex = index;
6158 } else if ((*j).length == bestLength) {
6159 bestThisMaxIndex = index;
6160 }
6161 }
6162 index = 0;
6163 bool requiredChangeRightForbidden = false;
6164 int requireChangeToLeftForbidden = -1;
6165 for (std::vector<LaneQ>::iterator j = last.begin(); j != last.end(); ++j, ++index) {
6166 if ((*j).length < bestLength) {
6167 if (abs(bestThisIndex - index) < abs(bestThisMaxIndex - index)) {
6168 (*j).bestLaneOffset = bestThisIndex - index;
6169 } else {
6170 (*j).bestLaneOffset = bestThisMaxIndex - index;
6171 }
6172 if ((*j).bestLaneOffset < 0 && (!(*j).lane->allowsChangingRight(getVClass())
6173 || !(*j).lane->getParallelLane(-1, false)->allowsVehicleClass(getVClass())
6174 || requiredChangeRightForbidden)) {
6175 // this lane and all further lanes to the left cannot be used
6176 requiredChangeRightForbidden = true;
6177 (*j).length = 0;
6178 } else if ((*j).bestLaneOffset > 0 && (!(*j).lane->allowsChangingLeft(getVClass())
6179 || !(*j).lane->getParallelLane(1, false)->allowsVehicleClass(getVClass()))) {
6180 // this lane and all previous lanes to the right cannot be used
6181 requireChangeToLeftForbidden = (*j).lane->getIndex();
6182 }
6183 }
6184 }
6185 for (int i = requireChangeToLeftForbidden; i >= 0; i--) {
6186 if (last[i].bestLaneOffset > 0) {
6187 last[i].length = 0;
6188 }
6189 }
6190#ifdef DEBUG_BESTLANES
6191 if (DEBUG_COND) {
6192 std::cout << " last edge=" << last.front().lane->getEdge().getID() << " (bestIndex=" << bestThisIndex << " bestMaxIndex=" << bestThisMaxIndex << "):\n";
6193 std::vector<LaneQ>& laneQs = myBestLanes.back();
6194 for (std::vector<LaneQ>::iterator j = laneQs.begin(); j != laneQs.end(); ++j) {
6195 std::cout << " lane=" << (*j).lane->getID() << " length=" << (*j).length << " bestOffset=" << (*j).bestLaneOffset << "\n";
6196 }
6197 }
6198#endif
6199 }
6200 // go backward through the lanes
6201 // track back best lane and compute the best prior lane(s)
6202 for (std::vector<std::vector<LaneQ> >::reverse_iterator i = myBestLanes.rbegin() + 1; i != myBestLanes.rend(); ++i) {
6203 std::vector<LaneQ>& nextLanes = (*(i - 1));
6204 std::vector<LaneQ>& clanes = (*i);
6205 MSEdge* const cE = &clanes[0].lane->getEdge();
6206 int index = 0;
6207 double bestConnectedLength = -1;
6208 double bestLength = -1;
6209 for (const LaneQ& j : nextLanes) {
6210 if (j.lane->isApproachedFrom(cE) && bestConnectedLength < j.length) {
6211 bestConnectedLength = j.length;
6212 }
6213 if (bestLength < j.length) {
6214 bestLength = j.length;
6215 }
6216 }
6217 // compute index of the best lane (highest length and least offset from the best next lane)
6218 int bestThisIndex = 0;
6219 int bestThisMaxIndex = 0;
6220 if (bestConnectedLength > 0) {
6221 index = 0;
6222 for (LaneQ& j : clanes) {
6223 const LaneQ* bestConnectedNext = nullptr;
6224 if (j.allowsContinuation) {
6225 for (const LaneQ& m : nextLanes) {
6226 if ((m.lane->allowsVehicleClass(getVClass()) || m.lane->hadPermissionChanges())
6227 && m.lane->isApproachedFrom(cE, j.lane)) {
6228 if (betterContinuation(bestConnectedNext, m)) {
6229 bestConnectedNext = &m;
6230 }
6231 }
6232 }
6233 if (bestConnectedNext != nullptr) {
6234 if (bestConnectedNext->length == bestConnectedLength && abs(bestConnectedNext->bestLaneOffset) < 2) {
6235 j.length += bestLength;
6236 } else {
6237 j.length += bestConnectedNext->length;
6238 }
6239 j.bestLaneOffset = bestConnectedNext->bestLaneOffset;
6240 }
6241 }
6242 if (bestConnectedNext != nullptr && (bestConnectedNext->allowsContinuation || bestConnectedNext->length > 0)) {
6243 copy(bestConnectedNext->bestContinuations.begin(), bestConnectedNext->bestContinuations.end(), back_inserter(j.bestContinuations));
6244 } else {
6245 j.allowsContinuation = false;
6246 }
6247 if (clanes[bestThisIndex].length < j.length
6248 || (clanes[bestThisIndex].length == j.length && abs(clanes[bestThisIndex].bestLaneOffset) > abs(j.bestLaneOffset))
6249 || (clanes[bestThisIndex].length == j.length && abs(clanes[bestThisIndex].bestLaneOffset) == abs(j.bestLaneOffset) &&
6250 nextLinkPriority(clanes[bestThisIndex].bestContinuations) < nextLinkPriority(j.bestContinuations))
6251 ) {
6252 bestThisIndex = index;
6253 bestThisMaxIndex = index;
6254 } else if (clanes[bestThisIndex].length == j.length
6255 && abs(clanes[bestThisIndex].bestLaneOffset) == abs(j.bestLaneOffset)
6256 && nextLinkPriority(clanes[bestThisIndex].bestContinuations) == nextLinkPriority(j.bestContinuations)) {
6257 bestThisMaxIndex = index;
6258 }
6259 index++;
6260 }
6261
6262 //vehicle with elecHybrid device prefers running under an overhead wire
6263 if (getDevice(typeid(MSDevice_ElecHybrid)) != nullptr) {
6264 index = 0;
6265 for (const LaneQ& j : clanes) {
6266 std::string overheadWireSegmentID = MSNet::getInstance()->getStoppingPlaceID(j.lane, j.currentLength / 2., SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
6267 if (overheadWireSegmentID != "") {
6268 bestThisIndex = index;
6269 bestThisMaxIndex = index;
6270 }
6271 index++;
6272 }
6273 }
6274
6275 } else {
6276 // only needed in case of disconnected routes
6277 int bestNextIndex = 0;
6278 int bestDistToNeeded = (int) clanes.size();
6279 index = 0;
6280 for (std::vector<LaneQ>::iterator j = clanes.begin(); j != clanes.end(); ++j, ++index) {
6281 if ((*j).allowsContinuation) {
6282 int nextIndex = 0;
6283 for (std::vector<LaneQ>::const_iterator m = nextLanes.begin(); m != nextLanes.end(); ++m, ++nextIndex) {
6284 if ((*m).lane->isApproachedFrom(cE, (*j).lane)) {
6285 if (bestDistToNeeded > abs((*m).bestLaneOffset)) {
6286 bestDistToNeeded = abs((*m).bestLaneOffset);
6287 bestThisIndex = index;
6288 bestThisMaxIndex = index;
6289 bestNextIndex = nextIndex;
6290 }
6291 }
6292 }
6293 }
6294 }
6295 clanes[bestThisIndex].length += nextLanes[bestNextIndex].length;
6296 copy(nextLanes[bestNextIndex].bestContinuations.begin(), nextLanes[bestNextIndex].bestContinuations.end(), back_inserter(clanes[bestThisIndex].bestContinuations));
6297
6298 }
6299 // set bestLaneOffset for all lanes
6300 index = 0;
6301 bool requiredChangeRightForbidden = false;
6302 int requireChangeToLeftForbidden = -1;
6303 for (std::vector<LaneQ>::iterator j = clanes.begin(); j != clanes.end(); ++j, ++index) {
6304 if ((*j).length < clanes[bestThisIndex].length
6305 || ((*j).length == clanes[bestThisIndex].length && abs((*j).bestLaneOffset) > abs(clanes[bestThisIndex].bestLaneOffset))
6306 || (nextLinkPriority((*j).bestContinuations)) < nextLinkPriority(clanes[bestThisIndex].bestContinuations)
6307 ) {
6308 if (abs(bestThisIndex - index) < abs(bestThisMaxIndex - index)) {
6309 (*j).bestLaneOffset = bestThisIndex - index;
6310 } else {
6311 (*j).bestLaneOffset = bestThisMaxIndex - index;
6312 }
6313 if ((nextLinkPriority((*j).bestContinuations)) < nextLinkPriority(clanes[bestThisIndex].bestContinuations)) {
6314 // try to move away from the lower-priority lane before it ends
6315 (*j).length = (*j).currentLength;
6316 }
6317 if ((*j).bestLaneOffset < 0 && (!(*j).lane->allowsChangingRight(getVClass())
6318 || !(*j).lane->getParallelLane(-1, false)->allowsVehicleClass(getVClass())
6319 || requiredChangeRightForbidden)) {
6320 // this lane and all further lanes to the left cannot be used
6321 requiredChangeRightForbidden = true;
6322 if ((*j).length == (*j).currentLength) {
6323 (*j).length = 0;
6324 }
6325 } else if ((*j).bestLaneOffset > 0 && (!(*j).lane->allowsChangingLeft(getVClass())
6326 || !(*j).lane->getParallelLane(1, false)->allowsVehicleClass(getVClass()))) {
6327 // this lane and all previous lanes to the right cannot be used
6328 requireChangeToLeftForbidden = (*j).lane->getIndex();
6329 }
6330 } else {
6331 (*j).bestLaneOffset = 0;
6332 }
6333 }
6334 for (int idx = requireChangeToLeftForbidden; idx >= 0; idx--) {
6335 if (clanes[idx].length == clanes[idx].currentLength) {
6336 clanes[idx].length = 0;
6337 };
6338 }
6339
6340 //vehicle with elecHybrid device prefers running under an overhead wire
6341 if (static_cast<MSDevice_ElecHybrid*>(getDevice(typeid(MSDevice_ElecHybrid))) != 0) {
6342 index = 0;
6343 std::string overheadWireID = MSNet::getInstance()->getStoppingPlaceID(clanes[bestThisIndex].lane, (clanes[bestThisIndex].currentLength) / 2, SUMO_TAG_OVERHEAD_WIRE_SEGMENT);
6344 if (overheadWireID != "") {
6345 for (std::vector<LaneQ>::iterator j = clanes.begin(); j != clanes.end(); ++j, ++index) {
6346 (*j).bestLaneOffset = bestThisIndex - index;
6347 }
6348 }
6349 }
6350
6351#ifdef DEBUG_BESTLANES
6352 if (DEBUG_COND) {
6353 std::cout << " edge=" << cE->getID() << " (bestIndex=" << bestThisIndex << " bestMaxIndex=" << bestThisMaxIndex << "):\n";
6354 std::vector<LaneQ>& laneQs = clanes;
6355 for (std::vector<LaneQ>::iterator j = laneQs.begin(); j != laneQs.end(); ++j) {
6356 std::cout << " lane=" << (*j).lane->getID() << " length=" << (*j).length << " bestOffset=" << (*j).bestLaneOffset << " allowCont=" << (*j).allowsContinuation << "\n";
6357 }
6358 }
6359#endif
6360
6361 }
6362 if (myBestLanes.front().front().lane->isInternal()) {
6363 // route starts on an internal lane
6364 if (myLane != nullptr) {
6365 startLane = myLane;
6366 } else {
6367 // vehicle not yet departed
6368 startLane = myBestLanes.front().front().lane;
6369 }
6370 }
6372#ifdef DEBUG_BESTLANES
6373 if (DEBUG_COND) {
6374 std::cout << SIMTIME << " veh=" << getID() << " bestCont=" << toString(getBestLanesContinuation()) << "\n";
6375 }
6376#endif
6377}
6378
6379void
6381 if (myLane != nullptr) {
6383 }
6384}
6385
6386bool
6387MSVehicle::betterContinuation(const LaneQ* bestConnectedNext, const LaneQ& m) const {
6388 if (bestConnectedNext == nullptr) {
6389 return true;
6390 } else if (m.lane->getBidiLane() != nullptr && bestConnectedNext->lane->getBidiLane() == nullptr) {
6391 return false;
6392 } else if (bestConnectedNext->lane->getBidiLane() != nullptr && m.lane->getBidiLane() == nullptr) {
6393 return true;
6394 } else if (bestConnectedNext->length < m.length) {
6395 return true;
6396 } else if (bestConnectedNext->length == m.length) {
6397 if (abs(bestConnectedNext->bestLaneOffset) > abs(m.bestLaneOffset)) {
6398 return true;
6399 }
6400 const double contRight = getVehicleType().getParameter().getLCParam(SUMO_ATTR_LCA_CONTRIGHT, 1);
6401 if (contRight < 1
6402 // if we don't check for adjacency, the rightmost line will get
6403 // multiple chances to be better which leads to an uninituitve distribution
6404 && (m.lane->getIndex() - bestConnectedNext->lane->getIndex()) == 1
6405 && RandHelper::rand(getRNG()) > contRight) {
6406 return true;
6407 }
6408 }
6409 return false;
6410}
6411
6412
6413int
6414MSVehicle::nextLinkPriority(const std::vector<MSLane*>& conts) {
6415 if (conts.size() < 2) {
6416 return -1;
6417 } else {
6418 const MSLink* const link = conts[0]->getLinkTo(conts[1]);
6419 if (link != nullptr) {
6420 return link->havePriority() ? 1 : 0;
6421 } else {
6422 // disconnected route
6423 return -1;
6424 }
6425 }
6426}
6427
6428
6429void
6431 std::vector<LaneQ>& currLanes = *myBestLanes.begin();
6432 std::vector<LaneQ>::iterator i;
6433#ifdef _DEBUG
6434 bool found = false;
6435#endif
6436 for (i = currLanes.begin(); i != currLanes.end(); ++i) {
6437 double nextOccupation = 0;
6438 for (std::vector<MSLane*>::const_iterator j = (*i).bestContinuations.begin() + 1; j != (*i).bestContinuations.end(); ++j) {
6439 nextOccupation += (*j)->getBruttoVehLenSum();
6440 }
6441 (*i).nextOccupation = nextOccupation;
6442#ifdef DEBUG_BESTLANES
6443 if (DEBUG_COND) {
6444 std::cout << " lane=" << (*i).lane->getID() << " nextOccupation=" << nextOccupation << "\n";
6445 }
6446#endif
6447 if ((*i).lane == startLane) {
6449#ifdef _DEBUG
6450 found = true;
6451#endif
6452 }
6453 }
6454#ifdef _DEBUG
6455 assert(found || startLane->isInternal());
6456#endif
6457}
6458
6459
6460const std::vector<MSLane*>&
6462 if (myBestLanes.empty() || myBestLanes[0].empty()) {
6463 return myEmptyLaneVector;
6464 }
6465 return (*myCurrentLaneInBestLanes).bestContinuations;
6466}
6467
6468
6469const std::vector<MSLane*>&
6471 const MSLane* lane = l;
6472 // XXX: shouldn't this be a "while" to cover more than one internal lane? (Leo) Refs. #2575
6473 if (lane->getEdge().isInternal()) {
6474 // internal edges are not kept inside the bestLanes structure
6475 lane = lane->getLinkCont()[0]->getLane();
6476 }
6477 if (myBestLanes.size() == 0) {
6478 return myEmptyLaneVector;
6479 }
6480 for (std::vector<LaneQ>::const_iterator i = myBestLanes[0].begin(); i != myBestLanes[0].end(); ++i) {
6481 if ((*i).lane == lane) {
6482 return (*i).bestContinuations;
6483 }
6484 }
6485 return myEmptyLaneVector;
6486}
6487
6488const std::vector<const MSLane*>
6489MSVehicle::getUpcomingLanesUntil(double distance) const {
6490 std::vector<const MSLane*> lanes;
6491
6492 if (distance <= 0. || hasArrived()) {
6493 // WRITE_WARNINGF(TL("MSVehicle::getUpcomingLanesUntil(): distance ('%') should be greater than 0."), distance);
6494 return lanes;
6495 }
6496
6497 if (!myLaneChangeModel->isOpposite()) {
6498 distance += getPositionOnLane();
6499 } else {
6500 distance += myLane->getOppositePos(getPositionOnLane());
6501 }
6503 while (lane->isInternal() && (distance > 0.)) { // include initial internal lanes
6504 lanes.insert(lanes.end(), lane);
6505 distance -= lane->getLength();
6506 lane = lane->getLinkCont().front()->getViaLaneOrLane();
6507 }
6508
6509 const std::vector<MSLane*>& contLanes = getBestLanesContinuation();
6510 if (contLanes.empty()) {
6511 return lanes;
6512 }
6513 auto contLanesIt = contLanes.begin();
6514 MSRouteIterator routeIt = myCurrEdge; // keep track of covered edges in myRoute
6515 while (distance > 0.) {
6516 MSLane* l = nullptr;
6517 if (contLanesIt != contLanes.end()) {
6518 l = *contLanesIt;
6519 if (l != nullptr) {
6520 assert(l->getEdge().getID() == (*routeIt)->getLanes().front()->getEdge().getID());
6521 }
6522 ++contLanesIt;
6523 if (l != nullptr || myLane->isInternal()) {
6524 ++routeIt;
6525 }
6526 if (l == nullptr) {
6527 continue;
6528 }
6529 } else if (routeIt != myRoute->end()) { // bestLanes didn't get us far enough
6530 // choose left-most lane as default (avoid sidewalks, bike lanes etc)
6531 l = (*routeIt)->getLanes().back();
6532 ++routeIt;
6533 } else { // the search distance goes beyond our route
6534 break;
6535 }
6536
6537 assert(l != nullptr);
6538
6539 // insert internal lanes if applicable
6540 const MSLane* internalLane = lanes.size() > 0 ? lanes.back()->getInternalFollowingLane(l) : nullptr;
6541 while ((internalLane != nullptr) && internalLane->isInternal() && (distance > 0.)) {
6542 lanes.insert(lanes.end(), internalLane);
6543 distance -= internalLane->getLength();
6544 internalLane = internalLane->getLinkCont().front()->getViaLaneOrLane();
6545 }
6546 if (distance <= 0.) {
6547 break;
6548 }
6549
6550 lanes.insert(lanes.end(), l);
6551 distance -= l->getLength();
6552 }
6553
6554 return lanes;
6555}
6556
6557const std::vector<const MSLane*>
6558MSVehicle::getPastLanesUntil(double distance) const {
6559 std::vector<const MSLane*> lanes;
6560
6561 if (distance <= 0.) {
6562 // WRITE_WARNINGF(TL("MSVehicle::getPastLanesUntil(): distance ('%') should be greater than 0."), distance);
6563 return lanes;
6564 }
6565
6566 MSRouteIterator routeIt = myCurrEdge;
6567 if (!myLaneChangeModel->isOpposite()) {
6568 distance += myLane->getLength() - getPositionOnLane();
6569 } else {
6571 }
6573 while (lane->isInternal() && (distance > 0.)) { // include initial internal lanes
6574 lanes.insert(lanes.end(), lane);
6575 distance -= lane->getLength();
6576 lane = lane->getLogicalPredecessorLane();
6577 }
6578
6579 while (distance > 0.) {
6580 // choose left-most lane as default (avoid sidewalks, bike lanes etc)
6581 MSLane* l = (*routeIt)->getLanes().back();
6582
6583 // insert internal lanes if applicable
6584 const MSEdge* internalEdge = lanes.size() > 0 ? (*routeIt)->getInternalFollowingEdge(&(lanes.back()->getEdge()), getVClass()) : nullptr;
6585 const MSLane* internalLane = internalEdge != nullptr ? internalEdge->getLanes().front() : nullptr;
6586 std::vector<const MSLane*> internalLanes;
6587 while ((internalLane != nullptr) && internalLane->isInternal()) { // collect all internal successor lanes
6588 internalLanes.insert(internalLanes.begin(), internalLane);
6589 internalLane = internalLane->getLinkCont().front()->getViaLaneOrLane();
6590 }
6591 for (auto it = internalLanes.begin(); (it != internalLanes.end()) && (distance > 0.); ++it) { // check remaining distance in correct order
6592 lanes.insert(lanes.end(), *it);
6593 distance -= (*it)->getLength();
6594 }
6595 if (distance <= 0.) {
6596 break;
6597 }
6598
6599 lanes.insert(lanes.end(), l);
6600 distance -= l->getLength();
6601
6602 // NOTE: we're going backwards with the (bi-directional) Iterator
6603 // TODO: consider make reverse_iterator() when moving on to C++14 or later
6604 if (routeIt != myRoute->begin()) {
6605 --routeIt;
6606 } else { // we went backwards to begin() and already processed the first and final element
6607 break;
6608 }
6609 }
6610
6611 return lanes;
6612}
6613
6614
6615const std::vector<MSLane*>
6617 const std::vector<const MSLane*> routeLanes = getPastLanesUntil(myLane->getMaximumBrakeDist());
6618 std::vector<MSLane*> result;
6619 for (const MSLane* lane : routeLanes) {
6620 MSLane* opposite = lane->getOpposite();
6621 if (opposite != nullptr) {
6622 result.push_back(opposite);
6623 } else {
6624 break;
6625 }
6626 }
6627 return result;
6628}
6629
6630
6631int
6633 if (myBestLanes.empty() || myBestLanes[0].empty()) {
6634 return 0;
6635 } else {
6636 return (*myCurrentLaneInBestLanes).bestLaneOffset;
6637 }
6638}
6639
6640double
6642 if (myBestLanes.empty() || myBestLanes[0].empty()) {
6643 return -1;
6644 } else {
6645 return (*myCurrentLaneInBestLanes).length;
6646 }
6647}
6648
6649
6650
6651void
6652MSVehicle::adaptBestLanesOccupation(int laneIndex, double density) {
6653 std::vector<MSVehicle::LaneQ>& preb = myBestLanes.front();
6654 assert(laneIndex < (int)preb.size());
6655 preb[laneIndex].occupation = density + preb[laneIndex].nextOccupation;
6656}
6657
6658
6659void
6665
6666std::pair<const MSLane*, double>
6667MSVehicle::getLanePosAfterDist(double distance) const {
6668 if (distance == 0) {
6669 return std::make_pair(myLane, getPositionOnLane());
6670 }
6671 const std::vector<const MSLane*> lanes = getUpcomingLanesUntil(distance);
6672 distance += getPositionOnLane();
6673 for (const MSLane* lane : lanes) {
6674 if (lane->getLength() > distance) {
6675 return std::make_pair(lane, distance);
6676 }
6677 distance -= lane->getLength();
6678 }
6679 return std::make_pair(nullptr, -1);
6680}
6681
6682
6683double
6684MSVehicle::getDistanceToPosition(double destPos, const MSLane* destLane) const {
6685 if (isOnRoad() && destLane != nullptr) {
6686 return myRoute->getDistanceBetween(getPositionOnLane(), destPos, myLane, destLane);
6687 }
6688 return std::numeric_limits<double>::max();
6689}
6690
6691
6692std::pair<const MSVehicle* const, double>
6693MSVehicle::getLeader(double dist, bool considerCrossingFoes) const {
6694 if (myLane == nullptr) {
6695 return std::make_pair(static_cast<const MSVehicle*>(nullptr), -1);
6696 }
6697 if (dist == 0) {
6699 }
6700 const MSVehicle* lead = nullptr;
6701 const MSLane* lane = myLane; // ensure lane does not change between getVehiclesSecure and releaseVehicles;
6702 const MSLane::VehCont& vehs = lane->getVehiclesSecure();
6703 // vehicle might be outside the road network
6704 MSLane::VehCont::const_iterator it = std::find(vehs.begin(), vehs.end(), this);
6705 if (it != vehs.end() && it + 1 != vehs.end()) {
6706 lead = *(it + 1);
6707 }
6708 if (lead != nullptr) {
6709 std::pair<const MSVehicle* const, double> result(
6710 lead, lead->getBackPositionOnLane(myLane) - getPositionOnLane() - getVehicleType().getMinGap());
6711 lane->releaseVehicles();
6712 return result;
6713 }
6714 const double seen = myLane->getLength() - getPositionOnLane();
6715 const std::vector<MSLane*>& bestLaneConts = getBestLanesContinuation(myLane);
6716 std::pair<const MSVehicle* const, double> result = myLane->getLeaderOnConsecutive(dist, seen, getSpeed(), *this, bestLaneConts, considerCrossingFoes);
6717 lane->releaseVehicles();
6718 return result;
6719}
6720
6721
6722std::pair<const MSVehicle* const, double>
6723MSVehicle::getFollower(double dist) const {
6724 if (myLane == nullptr) {
6725 return std::make_pair(static_cast<const MSVehicle*>(nullptr), -1);
6726 }
6727 if (dist == 0) {
6728 dist = getCarFollowModel().brakeGap(myLane->getEdge().getSpeedLimit() * 2, 4.5, 0);
6729 }
6731}
6732
6733
6734double
6736 // calling getLeader with 0 would induce a dist calculation but we only want to look for the leaders on the current lane
6737 std::pair<const MSVehicle* const, double> leaderInfo = getLeader(-1);
6738 if (leaderInfo.first == nullptr || getSpeed() == 0) {
6739 return -1;
6740 }
6741 return (leaderInfo.second + getVehicleType().getMinGap()) / getSpeed();
6742}
6743
6744
6745void
6747 MSBaseVehicle::addTransportable(transportable);
6748 if (myStops.size() > 0 && myStops.front().reached) {
6749 if (transportable->isPerson()) {
6750 if (myStops.front().triggered && myStops.front().numExpectedPerson > 0) {
6751 myStops.front().numExpectedPerson -= (int)myStops.front().pars.awaitedPersons.count(transportable->getID());
6752 }
6753 } else {
6754 if (myStops.front().pars.containerTriggered && myStops.front().numExpectedContainer > 0) {
6755 myStops.front().numExpectedContainer -= (int)myStops.front().pars.awaitedContainers.count(transportable->getID());
6756 }
6757 }
6758 }
6759}
6760
6761
6762void
6765 int state = myLaneChangeModel->getOwnState();
6766 // do not set blinker for sublane changes or when blocked from changing to the right
6767 const bool blinkerManoeuvre = (((state & LCA_SUBLANE) == 0) && (
6768 (state & LCA_KEEPRIGHT) == 0 || (state & LCA_BLOCKED) == 0));
6772 // lane indices increase from left to right
6773 std::swap(left, right);
6774 }
6775 if ((state & LCA_LEFT) != 0 && blinkerManoeuvre) {
6776 switchOnSignal(left);
6777 } else if ((state & LCA_RIGHT) != 0 && blinkerManoeuvre) {
6778 switchOnSignal(right);
6779 } else if (myLaneChangeModel->isChangingLanes()) {
6781 switchOnSignal(left);
6782 } else {
6783 switchOnSignal(right);
6784 }
6785 } else {
6786 const MSLane* lane = getLane();
6787 std::vector<MSLink*>::const_iterator link = MSLane::succLinkSec(*this, 1, *lane, getBestLanesContinuation());
6788 if (link != lane->getLinkCont().end() && lane->getLength() - getPositionOnLane() < lane->getVehicleMaxSpeed(this) * (double) 7.) {
6789 switch ((*link)->getDirection()) {
6794 break;
6798 break;
6799 default:
6800 break;
6801 }
6802 }
6803 }
6804 // stopping related signals
6805 if (hasStops()
6806 && (myStops.begin()->reached ||
6808 && myStopDist < getCarFollowModel().brakeGap(myLane->getVehicleMaxSpeed(this), getCarFollowModel().getMaxDecel(), 3)))) {
6809 if (myStops.begin()->lane->getIndex() > 0 && myStops.begin()->lane->getParallelLane(-1)->allowsVehicleClass(getVClass())) {
6810 // not stopping on the right. Activate emergency blinkers
6812 } else if (!myStops.begin()->reached && (myStops.begin()->pars.parking == ParkingType::OFFROAD)) {
6813 // signal upcoming parking stop on the current lane when within braking distance (~2 seconds before braking)
6815 }
6816 }
6817 if (myInfluencer != nullptr && myInfluencer->getSignals() >= 0) {
6819 myInfluencer->setSignals(-1); // overwrite computed signals only once
6820 }
6821}
6822
6823void
6825
6826 //TODO look if timestep ist SIMSTEP
6827 if (currentTime % 1000 == 0) {
6830 } else {
6832 }
6833 }
6834}
6835
6836
6837int
6839 return myLane == nullptr ? -1 : myLane->getIndex();
6840}
6841
6842
6843void
6844MSVehicle::setTentativeLaneAndPosition(MSLane* lane, double pos, double posLat) {
6845 myLane = lane;
6846 myState.myPos = pos;
6847 myState.myPosLat = posLat;
6849}
6850
6851
6852double
6854 return myState.myPosLat + 0.5 * myLane->getWidth() - 0.5 * getVehicleType().getWidth();
6855}
6856
6857
6858double
6860 return myState.myPosLat + 0.5 * myLane->getWidth() + 0.5 * getVehicleType().getWidth();
6861}
6862
6863
6864double
6866 return myState.myPosLat + 0.5 * lane->getWidth() - 0.5 * getVehicleType().getWidth();
6867}
6868
6869
6870double
6872 return myState.myPosLat + 0.5 * lane->getWidth() + 0.5 * getVehicleType().getWidth();
6873}
6874
6875
6876double
6878 return getCenterOnEdge(lane) - 0.5 * getVehicleType().getWidth();
6879}
6880
6881
6882double
6884 return getCenterOnEdge(lane) + 0.5 * getVehicleType().getWidth();
6885}
6886
6887
6888double
6890 if (lane == nullptr || &lane->getEdge() == &myLane->getEdge()) {
6892 } else if (lane == myLaneChangeModel->getShadowLane()) {
6893 if (myLaneChangeModel->isOpposite() && &lane->getEdge() != &myLane->getEdge()) {
6894 return lane->getRightSideOnEdge() + lane->getWidth() - myState.myPosLat + 0.5 * myLane->getWidth();
6895 }
6897 return lane->getRightSideOnEdge() + lane->getWidth() + myState.myPosLat + 0.5 * myLane->getWidth();
6898 } else {
6899 return lane->getRightSideOnEdge() - myLane->getWidth() + myState.myPosLat + 0.5 * myLane->getWidth();
6900 }
6901 } else if (lane == myLane->getBidiLane()) {
6902 return lane->getRightSideOnEdge() - myState.myPosLat + 0.5 * lane->getWidth();
6903 } else {
6904 assert(myFurtherLanes.size() == myFurtherLanesPosLat.size());
6905 for (int i = 0; i < (int)myFurtherLanes.size(); ++i) {
6906 if (myFurtherLanes[i] == lane) {
6907#ifdef DEBUG_FURTHER
6908 if (DEBUG_COND) std::cout << " getCenterOnEdge veh=" << getID() << " lane=" << lane->getID() << " i=" << i << " furtherLat=" << myFurtherLanesPosLat[i]
6909 << " result=" << lane->getRightSideOnEdge() + myFurtherLanesPosLat[i] + 0.5 * lane->getWidth()
6910 << "\n";
6911#endif
6912 return lane->getRightSideOnEdge() + myFurtherLanesPosLat[i] + 0.5 * lane->getWidth();
6913 } else if (myFurtherLanes[i]->getBidiLane() == lane) {
6914#ifdef DEBUG_FURTHER
6915 if (DEBUG_COND) std::cout << " getCenterOnEdge veh=" << getID() << " lane=" << lane->getID() << " i=" << i << " furtherLat(bidi)=" << myFurtherLanesPosLat[i]
6916 << " result=" << lane->getRightSideOnEdge() + myFurtherLanesPosLat[i] + 0.5 * lane->getWidth()
6917 << "\n";
6918#endif
6919 return lane->getRightSideOnEdge() - myFurtherLanesPosLat[i] + 0.5 * lane->getWidth();
6920 }
6921 }
6922 //if (DEBUG_COND) std::cout << SIMTIME << " veh=" << getID() << " myShadowFurtherLanes=" << toString(myLaneChangeModel->getShadowFurtherLanes()) << "\n";
6923 const std::vector<MSLane*>& shadowFurther = myLaneChangeModel->getShadowFurtherLanes();
6924 for (int i = 0; i < (int)shadowFurther.size(); ++i) {
6925 //if (DEBUG_COND) std::cout << " comparing i=" << (*i)->getID() << " lane=" << lane->getID() << "\n";
6926 if (shadowFurther[i] == lane) {
6927 assert(myLaneChangeModel->getShadowLane() != 0);
6928 return (lane->getRightSideOnEdge() + myLaneChangeModel->getShadowFurtherLanesPosLat()[i] + 0.5 * lane->getWidth()
6930 }
6931 }
6932 assert(false);
6933 throw ProcessError("Request lateral pos of vehicle '" + getID() + "' for invalid lane '" + Named::getIDSecure(lane) + "'");
6934 }
6935}
6936
6937
6938double
6940 assert(lane != 0);
6941 if (&lane->getEdge() == &myLane->getEdge()) {
6942 return myLane->getRightSideOnEdge() - lane->getRightSideOnEdge();
6943 } else if (myLane->getParallelOpposite() == lane) {
6944 return (myLane->getWidth() + lane->getWidth()) * 0.5 - 2 * getLateralPositionOnLane();
6945 } else if (myLane->getBidiLane() == lane) {
6946 return -2 * getLateralPositionOnLane();
6947 } else {
6948 // Check whether the lane is a further lane for the vehicle
6949 for (int i = 0; i < (int)myFurtherLanes.size(); ++i) {
6950 if (myFurtherLanes[i] == lane) {
6951#ifdef DEBUG_FURTHER
6952 if (DEBUG_COND) {
6953 std::cout << " getLatOffset veh=" << getID() << " lane=" << lane->getID() << " i=" << i << " posLat=" << myState.myPosLat << " furtherLat=" << myFurtherLanesPosLat[i] << "\n";
6954 }
6955#endif
6957 } else if (myFurtherLanes[i]->getBidiLane() == lane) {
6958#ifdef DEBUG_FURTHER
6959 if (DEBUG_COND) {
6960 std::cout << " getLatOffset veh=" << getID() << " lane=" << lane->getID() << " i=" << i << " posLat=" << myState.myPosLat << " furtherBidiLat=" << myFurtherLanesPosLat[i] << "\n";
6961 }
6962#endif
6963 return -2 * (myFurtherLanesPosLat[i] - myState.myPosLat);
6964 }
6965 }
6966#ifdef DEBUG_FURTHER
6967 if (DEBUG_COND) {
6968 std::cout << SIMTIME << " veh=" << getID() << " myShadowFurtherLanes=" << toString(myLaneChangeModel->getShadowFurtherLanes()) << "\n";
6969 }
6970#endif
6971 // Check whether the lane is a "shadow further lane" for the vehicle
6972 const std::vector<MSLane*>& shadowFurther = myLaneChangeModel->getShadowFurtherLanes();
6973 for (int i = 0; i < (int)shadowFurther.size(); ++i) {
6974 if (shadowFurther[i] == lane) {
6975#ifdef DEBUG_FURTHER
6976 if (DEBUG_COND) std::cout << " getLatOffset veh=" << getID()
6977 << " shadowLane=" << Named::getIDSecure(myLaneChangeModel->getShadowLane())
6978 << " lane=" << lane->getID()
6979 << " i=" << i
6980 << " posLat=" << myState.myPosLat
6981 << " shadowPosLat=" << getLatOffset(myLaneChangeModel->getShadowLane())
6982 << " shadowFurtherLat=" << myLaneChangeModel->getShadowFurtherLanesPosLat()[i]
6983 << "\n";
6984#endif
6986 }
6987 }
6988 // Check whether the vehicle issued a maneuverReservation on the lane.
6989 const std::vector<MSLane*>& furtherTargets = myLaneChangeModel->getFurtherTargetLanes();
6990 for (int i = 0; i < (int)myFurtherLanes.size(); ++i) {
6991 // Further target lanes are just neighboring lanes of the vehicle's further lanes, @see MSAbstractLaneChangeModel::updateTargetLane()
6992 MSLane* targetLane = furtherTargets[i];
6993 if (targetLane == lane) {
6994 const double targetDir = myLaneChangeModel->getManeuverDist() < 0 ? -1. : 1.;
6995 const double latOffset = myFurtherLanesPosLat[i] - myState.myPosLat + targetDir * 0.5 * (myFurtherLanes[i]->getWidth() + targetLane->getWidth());
6996#ifdef DEBUG_TARGET_LANE
6997 if (DEBUG_COND) {
6998 std::cout << " getLatOffset veh=" << getID()
6999 << " wrt targetLane=" << Named::getIDSecure(myLaneChangeModel->getTargetLane())
7000 << "\n i=" << i
7001 << " posLat=" << myState.myPosLat
7002 << " furtherPosLat=" << myFurtherLanesPosLat[i]
7003 << " maneuverDist=" << myLaneChangeModel->getManeuverDist()
7004 << " targetDir=" << targetDir
7005 << " latOffset=" << latOffset
7006 << std::endl;
7007 }
7008#endif
7009 return latOffset;
7010 }
7011 }
7012 assert(false);
7013 throw ProcessError("Request lateral offset of vehicle '" + getID() + "' for invalid lane '" + Named::getIDSecure(lane) + "'");
7014 }
7015}
7016
7017
7018double
7019MSVehicle::lateralDistanceToLane(const int offset) const {
7020 // compute the distance when changing to the neighboring lane
7021 // (ensure we do not lap into the line behind neighLane since there might be unseen blockers)
7022 assert(offset == 0 || offset == 1 || offset == -1);
7023 assert(myLane != nullptr);
7024 assert(myLane->getParallelLane(offset) != nullptr || myLane->getParallelOpposite() != nullptr);
7025 const double halfCurrentLaneWidth = 0.5 * myLane->getWidth();
7026 const double halfVehWidth = 0.5 * (getWidth() + NUMERICAL_EPS);
7027 const double latPos = getLateralPositionOnLane();
7028 const double oppositeSign = getLaneChangeModel().isOpposite() ? -1 : 1;
7029 double leftLimit = halfCurrentLaneWidth - halfVehWidth - oppositeSign * latPos;
7030 double rightLimit = -halfCurrentLaneWidth + halfVehWidth - oppositeSign * latPos;
7031 double latLaneDist = 0; // minimum distance to move the vehicle fully onto the new lane
7032 if (offset == 0) {
7033 if (latPos + halfVehWidth > halfCurrentLaneWidth) {
7034 // correct overlapping left
7035 latLaneDist = halfCurrentLaneWidth - latPos - halfVehWidth;
7036 } else if (latPos - halfVehWidth < -halfCurrentLaneWidth) {
7037 // correct overlapping right
7038 latLaneDist = -halfCurrentLaneWidth - latPos + halfVehWidth;
7039 }
7040 latLaneDist *= oppositeSign;
7041 } else if (offset == -1) {
7042 latLaneDist = rightLimit - (getWidth() + NUMERICAL_EPS);
7043 } else if (offset == 1) {
7044 latLaneDist = leftLimit + (getWidth() + NUMERICAL_EPS);
7045 }
7046#ifdef DEBUG_ACTIONSTEPS
7047 if (DEBUG_COND) {
7048 std::cout << SIMTIME
7049 << " veh=" << getID()
7050 << " halfCurrentLaneWidth=" << halfCurrentLaneWidth
7051 << " halfVehWidth=" << halfVehWidth
7052 << " latPos=" << latPos
7053 << " latLaneDist=" << latLaneDist
7054 << " leftLimit=" << leftLimit
7055 << " rightLimit=" << rightLimit
7056 << "\n";
7057 }
7058#endif
7059 return latLaneDist;
7060}
7061
7062
7063double
7064MSVehicle::getLateralOverlap(double posLat, const MSLane* lane) const {
7065 return (fabs(posLat) + 0.5 * getVehicleType().getWidth()
7066 - 0.5 * lane->getWidth());
7067}
7068
7069double
7073
7074double
7078
7079
7080void
7082 for (const DriveProcessItem& dpi : lfLinks) {
7083 if (dpi.myLink != nullptr) {
7084 dpi.myLink->removeApproaching(this);
7085 }
7086 }
7087 // unregister on all shadow links
7089}
7090
7091
7092bool
7093MSVehicle::unsafeLinkAhead(const MSLane* lane, double zipperDist) const {
7094 // the following links are unsafe:
7095 // - zipper links if they are close enough and have approaching vehicles in the relevant time range
7096 // - unprioritized links if the vehicle is currently approaching a prioritzed link and unable to stop in time
7097 double seen = myLane->getLength() - getPositionOnLane();
7098 const double dist = MAX2(zipperDist, getCarFollowModel().brakeGap(getSpeed(), getCarFollowModel().getMaxDecel(), 0));
7099 if (seen < dist) {
7100 const std::vector<MSLane*>& bestLaneConts = getBestLanesContinuation(lane);
7101 int view = 1;
7102 std::vector<MSLink*>::const_iterator link = MSLane::succLinkSec(*this, view, *lane, bestLaneConts);
7103 DriveItemVector::const_iterator di = myLFLinkLanes.begin();
7104 while (!lane->isLinkEnd(link) && seen <= dist) {
7105 if ((!lane->isInternal()
7106 && (((*link)->getState() == LINKSTATE_ZIPPER && seen < (*link)->getFoeVisibilityDistance())
7107 || !(*link)->havePriority()))
7108 || (lane->isInternal() && zipperDist > 0)) {
7109 // find the drive item corresponding to this link
7110 bool found = false;
7111 while (di != myLFLinkLanes.end() && !found) {
7112 if ((*di).myLink != nullptr) {
7113 const MSLane* diPredLane = (*di).myLink->getLaneBefore();
7114 if (diPredLane != nullptr) {
7115 if (&diPredLane->getEdge() == &lane->getEdge()) {
7116 found = true;
7117 }
7118 }
7119 }
7120 if (!found) {
7121 di++;
7122 }
7123 }
7124 if (found) {
7125 const SUMOTime leaveTime = (*link)->getLeaveTime((*di).myArrivalTime, (*di).myArrivalSpeed,
7126 (*di).getLeaveSpeed(), getVehicleType().getLength());
7127 const MSLink* entry = (*link)->getCorrespondingEntryLink();
7128 //if (DEBUG_COND) {
7129 // 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";
7130 //}
7131 if (entry->hasApproachingFoe((*di).myArrivalTime, leaveTime, (*di).myArrivalSpeed, getCarFollowModel().getMaxDecel())) {
7132 //std::cout << SIMTIME << " veh=" << getID() << " aborting changeTo=" << Named::getIDSecure(bestLaneConts.front()) << " linkState=" << toString((*link)->getState()) << " seen=" << seen << " dist=" << dist << "\n";
7133 return true;
7134 }
7135 }
7136 // no drive item is found if the vehicle aborts its request within dist
7137 }
7138 lane = (*link)->getViaLaneOrLane();
7139 if (!lane->getEdge().isInternal()) {
7140 view++;
7141 }
7142 seen += lane->getLength();
7143 link = MSLane::succLinkSec(*this, view, *lane, bestLaneConts);
7144 }
7145 }
7146 return false;
7147}
7148
7149
7151MSVehicle::getBoundingBox(double offset) const {
7152 PositionVector centerLine;
7153 Position pos = getPosition();
7154 centerLine.push_back(pos);
7155 switch (myType->getGuiShape()) {
7162 for (MSLane* lane : myFurtherLanes) {
7163 centerLine.push_back(lane->getShape().back());
7164 }
7165 break;
7166 }
7167 default:
7168 break;
7169 }
7170 double l = getLength();
7171 Position backPos = getBackPosition();
7172 if (pos.distanceTo2D(backPos) > l + NUMERICAL_EPS) {
7173 // getBackPosition may not match the visual back in networks without internal lanes
7174 double a = getAngle() + M_PI; // angle pointing backwards
7175 backPos = pos + Position(l * cos(a), l * sin(a));
7176 }
7177 centerLine.push_back(backPos);
7178 if (offset != 0) {
7179 centerLine.extrapolate2D(offset);
7180 }
7181 PositionVector result = centerLine;
7182 result.move2side(MAX2(0.0, 0.5 * myType->getWidth() + offset));
7183 centerLine.move2side(MIN2(0.0, -0.5 * myType->getWidth() - offset));
7184 result.append(centerLine.reverse(), POSITION_EPS);
7185 return result;
7186}
7187
7188
7190MSVehicle::getBoundingPoly(double offset) const {
7191 switch (myType->getGuiShape()) {
7197 // box with corners cut off
7198 PositionVector result;
7199 PositionVector centerLine;
7200 centerLine.push_back(getPosition());
7201 centerLine.push_back(getBackPosition());
7202 if (offset != 0) {
7203 centerLine.extrapolate2D(offset);
7204 }
7205 PositionVector line1 = centerLine;
7206 PositionVector line2 = centerLine;
7207 line1.move2side(MAX2(0.0, 0.3 * myType->getWidth() + offset));
7208 line2.move2side(MAX2(0.0, 0.5 * myType->getWidth() + offset));
7209 line2.scaleRelative(0.8);
7210 result.push_back(line1[0]);
7211 result.push_back(line2[0]);
7212 result.push_back(line2[1]);
7213 result.push_back(line1[1]);
7214 line1.move2side(MIN2(0.0, -0.6 * myType->getWidth() - offset));
7215 line2.move2side(MIN2(0.0, -1.0 * myType->getWidth() - offset));
7216 result.push_back(line1[1]);
7217 result.push_back(line2[1]);
7218 result.push_back(line2[0]);
7219 result.push_back(line1[0]);
7220 return result;
7221 }
7222 default:
7223 return getBoundingBox();
7224 }
7225}
7226
7227
7228bool
7230 for (std::vector<MSLane*>::const_iterator i = myFurtherLanes.begin(); i != myFurtherLanes.end(); ++i) {
7231 if (&(*i)->getEdge() == edge) {
7232 return true;
7233 }
7234 }
7235 return false;
7236}
7237
7238
7239bool
7240MSVehicle::isBidiOn(const MSLane* lane) const {
7241 return lane->getBidiLane() != nullptr && (
7242 myLane == lane->getBidiLane()
7243 || onFurtherEdge(&lane->getBidiLane()->getEdge()));
7244}
7245
7246
7247bool
7248MSVehicle::rerouteParkingArea(const std::string& parkingAreaID, std::string& errorMsg) {
7249 // this function is based on MSTriggeredRerouter::rerouteParkingArea in order to keep
7250 // consistency in the behaviour.
7251
7252 // get vehicle params
7253 MSParkingArea* destParkArea = getNextParkingArea();
7254 const MSRoute& route = getRoute();
7255 const MSEdge* lastEdge = route.getLastEdge();
7256
7257 if (destParkArea == nullptr) {
7258 // not driving towards a parking area
7259 errorMsg = "Vehicle " + getID() + " is not driving to a parking area so it cannot be rerouted.";
7260 return false;
7261 }
7262
7263 // if the current route ends at the parking area, the new route will also and at the new area
7264 bool newDestination = (&destParkArea->getLane().getEdge() == route.getLastEdge()
7265 && getArrivalPos() >= destParkArea->getBeginLanePosition()
7266 && getArrivalPos() <= destParkArea->getEndLanePosition());
7267
7268 // retrieve info on the new parking area
7270 parkingAreaID, SumoXMLTag::SUMO_TAG_PARKING_AREA);
7271
7272 if (newParkingArea == nullptr) {
7273 errorMsg = "Parking area ID " + toString(parkingAreaID) + " not found in the network.";
7274 return false;
7275 }
7276
7277 const MSEdge* newEdge = &(newParkingArea->getLane().getEdge());
7279
7280 // Compute the route from the current edge to the parking area edge
7281 ConstMSEdgeVector edgesToPark;
7282 router.compute(getEdge(), getPositionOnLane(), newEdge, newParkingArea->getEndLanePosition(), this, MSNet::getInstance()->getCurrentTimeStep(), edgesToPark);
7283
7284 // Compute the route from the parking area edge to the end of the route
7285 ConstMSEdgeVector edgesFromPark;
7286 if (!newDestination) {
7287 router.compute(newEdge, lastEdge, this, MSNet::getInstance()->getCurrentTimeStep(), edgesFromPark);
7288 } else {
7289 // adapt plans of any riders
7290 for (MSTransportable* p : getPersons()) {
7291 p->rerouteParkingArea(getNextParkingArea(), newParkingArea);
7292 }
7293 }
7294
7295 // we have a new destination, let's replace the vehicle route
7296 ConstMSEdgeVector edges = edgesToPark;
7297 if (edgesFromPark.size() > 0) {
7298 edges.insert(edges.end(), edgesFromPark.begin() + 1, edgesFromPark.end());
7299 }
7300
7301 if (newDestination) {
7302 SUMOVehicleParameter* newParameter = new SUMOVehicleParameter();
7303 *newParameter = getParameter();
7305 newParameter->arrivalPos = newParkingArea->getEndLanePosition();
7306 replaceParameter(newParameter);
7307 }
7308 const double routeCost = router.recomputeCosts(edges, this, MSNet::getInstance()->getCurrentTimeStep());
7309 ConstMSEdgeVector prevEdges(myCurrEdge, myRoute->end());
7310 const double savings = router.recomputeCosts(prevEdges, this, MSNet::getInstance()->getCurrentTimeStep());
7311 if (replaceParkingArea(newParkingArea, errorMsg)) {
7312 const bool onInit = myLane == nullptr;
7313 replaceRouteEdges(edges, routeCost, savings, "TraCI:" + toString(SUMO_TAG_PARKING_AREA_REROUTE), onInit, false, false);
7314 } else {
7315 WRITE_WARNING("Vehicle '" + getID() + "' could not reroute to new parkingArea '" + newParkingArea->getID()
7316 + "' reason=" + errorMsg + ", time=" + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
7317 return false;
7318 }
7319 return true;
7320}
7321
7322
7323bool
7325 const int numStops = (int)myStops.size();
7326 const bool result = MSBaseVehicle::addTraciStop(stop, errorMsg);
7327 if (myLane != nullptr && numStops != (int)myStops.size()) {
7328 updateBestLanes(true);
7329 }
7330 return result;
7331}
7332
7333
7334bool
7335MSVehicle::handleCollisionStop(MSStop& stop, const double distToStop) {
7336 if (myCurrEdge == stop.edge && distToStop + POSITION_EPS < getCarFollowModel().brakeGap(myState.mySpeed, getCarFollowModel().getMaxDecel(), 0)) {
7337 if (distToStop < getCarFollowModel().brakeGap(myState.mySpeed, getCarFollowModel().getEmergencyDecel(), 0)) {
7338 double vNew = getCarFollowModel().maximumSafeStopSpeed(distToStop, getCarFollowModel().getMaxDecel(), getSpeed(), false, 0);
7339 //std::cout << SIMTIME << " veh=" << getID() << " v=" << myState.mySpeed << " distToStop=" << distToStop
7340 // << " vMinNex=" << getCarFollowModel().minNextSpeed(getSpeed(), this)
7341 // << " bg1=" << getCarFollowModel().brakeGap(myState.mySpeed)
7342 // << " bg2=" << getCarFollowModel().brakeGap(myState.mySpeed, getCarFollowModel().getEmergencyDecel(), 0)
7343 // << " vNew=" << vNew
7344 // << "\n";
7345 myState.mySpeed = MIN2(myState.mySpeed, vNew + ACCEL2SPEED(getCarFollowModel().getEmergencyDecel()));
7348 if (myState.myPos < myType->getLength()) {
7352 myAngle += M_PI;
7353 }
7354 }
7355 }
7356 }
7357 return true;
7358}
7359
7360
7361bool
7363 if (isStopped()) {
7367 }
7368 MSStop& stop = myStops.front();
7369 // we have waited long enough and fulfilled any passenger-requirements
7370 if (stop.busstop != nullptr) {
7371 // inform bus stop about leaving it
7372 stop.busstop->leaveFrom(this);
7373 }
7374 // we have waited long enough and fulfilled any container-requirements
7375 if (stop.containerstop != nullptr) {
7376 // inform container stop about leaving it
7377 stop.containerstop->leaveFrom(this);
7378 }
7379 if (stop.parkingarea != nullptr && stop.getSpeed() <= 0) {
7380 // inform parking area about leaving it
7381 stop.parkingarea->leaveFrom(this);
7382 }
7383 if (stop.chargingStation != nullptr) {
7384 // inform charging station about leaving it
7385 stop.chargingStation->leaveFrom(this);
7386 }
7387 // the current stop is no longer valid
7388 myLane->getEdge().removeWaiting(this);
7389 // MSStopOut needs to know whether the stop had a loaded 'ended' value so we call this before replacing the value
7390 if (stop.pars.started == -1) {
7391 // waypoint edge was passed in a single step
7393 }
7394 if (MSStopOut::active()) {
7395 MSStopOut::getInstance()->stopEnded(this, stop.pars, stop.lane->getID());
7396 }
7398 for (const auto& rem : myMoveReminders) {
7399 rem.first->notifyStopEnded();
7400 }
7402 myCollisionImmunity = TIME2STEPS(5); // leave the conflict area
7403 }
7405 // reset lateral position to default
7406 myState.myPosLat = 0;
7407 }
7408 const bool wasWaypoint = stop.getSpeed() > 0;
7409 myPastStops.push_back(stop.pars);
7410 myPastStops.back().routeIndex = (int)(stop.edge - myRoute->begin());
7411 myStops.pop_front();
7412 myStopDist = std::numeric_limits<double>::max();
7413 // do not count the stopping time towards gridlock time.
7414 // Other outputs use an independent counter and are not affected.
7415 myWaitingTime = 0;
7417 // maybe the next stop is on the same edge; let's rebuild best lanes
7418 updateBestLanes(true);
7419 // continue as wished...
7422 return !wasWaypoint;
7423 }
7424 return false;
7425}
7426
7427
7430 if (myInfluencer == nullptr) {
7431 myInfluencer = new Influencer();
7432 }
7433 return *myInfluencer;
7434}
7435
7440
7441
7444 return myInfluencer;
7445}
7446
7449 return myInfluencer;
7450}
7451
7452
7453double
7455 if (myInfluencer != nullptr && myInfluencer->getOriginalSpeed() >= 0) {
7456 // influencer original speed is -1 on initialization
7458 }
7459 return myState.mySpeed;
7460}
7461
7462
7463int
7465 if (hasInfluencer()) {
7467 MSNet::getInstance()->getCurrentTimeStep(),
7468 myLane->getEdge(),
7469 getLaneIndex(),
7470 state);
7471 }
7472 return state;
7473}
7474
7475
7476void
7480
7481
7482bool
7486
7487
7488bool
7492
7493
7494bool
7495MSVehicle::keepClear(const MSLink* link) const {
7496 if (link->hasFoes() && link->keepClear() /* && item.myLink->willHaveBlockedFoe()*/) {
7497 const double keepClearTime = getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_IGNORE_KEEPCLEAR_TIME, -1);
7498 //std::cout << SIMTIME << " veh=" << getID() << " keepClearTime=" << keepClearTime << " accWait=" << getAccumulatedWaitingSeconds() << " keepClear=" << (keepClearTime < 0 || getAccumulatedWaitingSeconds() < keepClearTime) << "\n";
7499 return keepClearTime < 0 || getAccumulatedWaitingSeconds() < keepClearTime;
7500 } else {
7501 return false;
7502 }
7503}
7504
7505
7506bool
7507MSVehicle::ignoreRed(const MSLink* link, bool canBrake) const {
7508 if ((myInfluencer != nullptr && !myInfluencer->getEmergencyBrakeRedLight())) {
7509 return true;
7510 }
7511 const double ignoreRedTime = getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_DRIVE_AFTER_RED_TIME, -1);
7512#ifdef DEBUG_IGNORE_RED
7513 if (DEBUG_COND) {
7514 std::cout << SIMTIME << " veh=" << getID() << " link=" << link->getViaLaneOrLane()->getID() << " state=" << toString(link->getState()) << "\n";
7515 }
7516#endif
7517 if (ignoreRedTime < 0) {
7518 const double ignoreYellowTime = getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_DRIVE_AFTER_YELLOW_TIME, 0);
7519 if (ignoreYellowTime > 0 && link->haveYellow()) {
7520 assert(link->getTLLogic() != 0);
7521 const double yellowDuration = STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep() - link->getLastStateChange());
7522 // when activating ignoreYellow behavior, vehicles will drive if they cannot brake
7523 return !canBrake || ignoreYellowTime > yellowDuration;
7524 } else {
7525 return false;
7526 }
7527 } else if (link->haveYellow()) {
7528 // always drive at yellow when ignoring red
7529 return true;
7530 } else if (link->haveRed()) {
7531 assert(link->getTLLogic() != 0);
7532 const double redDuration = STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep() - link->getLastStateChange());
7533#ifdef DEBUG_IGNORE_RED
7534 if (DEBUG_COND) {
7535 std::cout
7536 // << SIMTIME << " veh=" << getID() << " link=" << link->getViaLaneOrLane()->getID()
7537 << " ignoreRedTime=" << ignoreRedTime
7538 << " spentRed=" << redDuration
7539 << " canBrake=" << canBrake << "\n";
7540 }
7541#endif
7542 // when activating ignoreRed behavior, vehicles will always drive if they cannot brake
7543 return !canBrake || ignoreRedTime > redDuration;
7544 } else {
7545 return false;
7546 }
7547}
7548
7549bool
7552 return false;
7553 }
7554 for (const std::string& typeID : StringTokenizer(getParameter().getParameter(toString(SUMO_ATTR_CF_IGNORE_TYPES), "")).getVector()) {
7555 if (typeID == foe->getVehicleType().getID()) {
7556 return true;
7557 }
7558 }
7559 for (const std::string& id : StringTokenizer(getParameter().getParameter(toString(SUMO_ATTR_CF_IGNORE_IDS), "")).getVector()) {
7560 if (id == foe->getID()) {
7561 return true;
7562 }
7563 }
7564 return false;
7565}
7566
7567bool
7569 // either on an internal lane that was entered via minor link
7570 // or on approach to minor link below visibility distance
7571 if (myLane == nullptr) {
7572 return false;
7573 }
7574 if (myLane->getEdge().isInternal()) {
7575 return !myLane->getIncomingLanes().front().viaLink->havePriority();
7576 } else if (myLFLinkLanes.size() > 0 && myLFLinkLanes.front().myLink != nullptr) {
7577 MSLink* link = myLFLinkLanes.front().myLink;
7578 return !link->havePriority() && myLFLinkLanes.front().myDistance <= link->getFoeVisibilityDistance();
7579 }
7580 return false;
7581}
7582
7583bool
7584MSVehicle::isLeader(const MSLink* link, const MSVehicle* veh, const double gap) const {
7585 assert(link->fromInternalLane());
7586 if (veh == nullptr) {
7587 return false;
7588 }
7589 if (!myLane->isInternal() || myLane->getEdge().getToJunction() != link->getJunction()) {
7590 // if this vehicle is not yet on the junction, every vehicle is a leader
7591 return true;
7592 }
7593 if (veh->getLaneChangeModel().hasBlueLight()) {
7594 // blue light device automatically gets right of way
7595 return true;
7596 }
7597 const MSLane* foeLane = veh->getLane();
7598 if (foeLane->isInternal()) {
7599 if (foeLane->getEdge().getFromJunction() == link->getJunction()) {
7601 SUMOTime foeET = veh->myJunctionEntryTime;
7602 // check relationship between link and foeLane
7604 // we are entering the junction from the same lane
7606 foeET = veh->myJunctionEntryTimeNeverYield;
7609 }
7610 } else {
7611 const MSLink* foeLink = foeLane->getIncomingLanes()[0].viaLink;
7612 const MSJunctionLogic* logic = link->getJunction()->getLogic();
7613 assert(logic != nullptr);
7614 // determine who has right of way
7615 bool response; // ego response to foe
7616 bool response2; // foe response to ego
7617 // attempt 1: tlLinkState
7618 const MSLink* entry = link->getCorrespondingEntryLink();
7619 const MSLink* foeEntry = foeLink->getCorrespondingEntryLink();
7620 if (entry->haveRed() || foeEntry->haveRed()) {
7621 // ensure that vehicles which are stuck on the intersection may exit
7622 if (!foeEntry->haveRed() && veh->getSpeed() > SUMO_const_haltingSpeed && gap < 0) {
7623 // foe might be oncoming, don't drive unless foe can still brake safely
7624 const double foeNextSpeed = veh->getSpeed() + ACCEL2SPEED(veh->getCarFollowModel().getMaxAccel());
7625 const double foeBrakeGap = veh->getCarFollowModel().brakeGap(
7626 foeNextSpeed, veh->getCarFollowModel().getMaxDecel(), veh->getCarFollowModel().getHeadwayTime());
7627 // the minGap was subtracted from gap in MSLink::getLeaderInfo (enlarging the negative gap)
7628 // so the -2* makes it point in the right direction
7629 const double foeGap = -gap - veh->getLength() - 2 * getVehicleType().getMinGap();
7630#ifdef DEBUG_PLAN_MOVE_LEADERINFO
7631 if (DEBUG_COND) {
7632 std::cout << " foeGap=" << foeGap << " foeBGap=" << foeBrakeGap << "\n";
7633
7634 }
7635#endif
7636 if (foeGap < foeBrakeGap) {
7637 response = true;
7638 response2 = false;
7639 } else {
7640 response = false;
7641 response2 = true;
7642 }
7643 } else {
7644 // let conflict entry time decide
7645 response = true;
7646 response2 = true;
7647 }
7648 } else if (entry->havePriority() != foeEntry->havePriority()) {
7649 response = !entry->havePriority();
7650 response2 = !foeEntry->havePriority();
7651 } else if (entry->haveYellow() && foeEntry->haveYellow()) {
7652 // let the faster vehicle keep moving
7653 response = veh->getSpeed() >= getSpeed();
7654 response2 = getSpeed() >= veh->getSpeed();
7655 } else {
7656 // fallback if pedestrian crossings are involved
7657 response = logic->getResponseFor(link->getIndex()).test(foeLink->getIndex());
7658 response2 = logic->getResponseFor(foeLink->getIndex()).test(link->getIndex());
7659 }
7660#ifdef DEBUG_PLAN_MOVE_LEADERINFO
7661 if (DEBUG_COND) {
7662 std::cout << SIMTIME
7663 << " foeLane=" << foeLane->getID()
7664 << " foeLink=" << foeLink->getViaLaneOrLane()->getID()
7665 << " linkIndex=" << link->getIndex()
7666 << " foeLinkIndex=" << foeLink->getIndex()
7667 << " entryState=" << toString(entry->getState())
7668 << " entryState2=" << toString(foeEntry->getState())
7669 << " response=" << response
7670 << " response2=" << response2
7671 << "\n";
7672 }
7673#endif
7674 if (!response) {
7675 // if we have right of way over the foe, entryTime does not matter
7676 foeET = veh->myJunctionConflictEntryTime;
7677 egoET = myJunctionEntryTime;
7678 } else if (response && response2) {
7679 // in a mutual conflict scenario, use entry time to avoid deadlock
7680 foeET = veh->myJunctionConflictEntryTime;
7682 }
7683 }
7684 if (egoET == foeET) {
7685 // try to use speed as tie braker
7686 if (getSpeed() == veh->getSpeed()) {
7687 // use ID as tie braker
7688#ifdef DEBUG_PLAN_MOVE_LEADERINFO
7689 if (DEBUG_COND) {
7690 std::cout << SIMTIME << " veh=" << getID() << " equal ET " << egoET << " with foe " << veh->getID()
7691 << " foeIsLeaderByID=" << (getID() < veh->getID()) << "\n";
7692 }
7693#endif
7694 return getID() < veh->getID();
7695 } else {
7696#ifdef DEBUG_PLAN_MOVE_LEADERINFO
7697 if (DEBUG_COND) {
7698 std::cout << SIMTIME << " veh=" << getID() << " equal ET " << egoET << " with foe " << veh->getID()
7699 << " foeIsLeaderBySpeed=" << (getSpeed() < veh->getSpeed())
7700 << " v=" << getSpeed() << " foeV=" << veh->getSpeed()
7701 << "\n";
7702 }
7703#endif
7704 return getSpeed() < veh->getSpeed();
7705 }
7706 } else {
7707 // leader was on the junction first
7708#ifdef DEBUG_PLAN_MOVE_LEADERINFO
7709 if (DEBUG_COND) {
7710 std::cout << SIMTIME << " veh=" << getID() << " egoET " << egoET << " with foe " << veh->getID()
7711 << " foeET=" << foeET << " isLeader=" << (egoET > foeET) << "\n";
7712 }
7713#endif
7714 return egoET > foeET;
7715 }
7716 } else {
7717 // vehicle can only be partially on the junction. Must be a leader
7718 return true;
7719 }
7720 } else {
7721 // vehicle can only be partially on the junction. Must be a leader
7722 return true;
7723 }
7724}
7725
7726void
7729 // here starts the vehicle internal part (see loading)
7730 std::vector<std::string> internals;
7731 internals.push_back(toString(myParameter->parametersSet));
7732 internals.push_back(toString(myDeparture));
7733 internals.push_back(toString(distance(myRoute->begin(), myCurrEdge)));
7734 internals.push_back(toString(myDepartPos));
7735 internals.push_back(toString(myWaitingTime));
7736 internals.push_back(toString(myTimeLoss));
7737 internals.push_back(toString(myLastActionTime));
7738 internals.push_back(toString(isStopped()));
7739 internals.push_back(toString(myPastStops.size()));
7740 out.writeAttr(SUMO_ATTR_STATE, internals);
7742 out.writeAttr(SUMO_ATTR_SPEED, std::vector<double> { myState.mySpeed, myState.myPreviousSpeed });
7747 // save past stops
7749 stop.write(out, false);
7750 // do not write started and ended twice
7751 if ((stop.parametersSet & STOP_STARTED_SET) == 0) {
7752 out.writeAttr(SUMO_ATTR_STARTED, time2string(stop.started));
7753 }
7754 if ((stop.parametersSet & STOP_ENDED_SET) == 0) {
7755 out.writeAttr(SUMO_ATTR_ENDED, time2string(stop.ended));
7756 }
7757 stop.writeParams(out);
7758 out.closeTag();
7759 }
7760 // save upcoming stops
7761 for (MSStop& stop : myStops) {
7762 stop.write(out);
7763 }
7764 // save parameters and device states
7766 for (MSVehicleDevice* const dev : myDevices) {
7767 dev->saveState(out);
7768 }
7769 out.closeTag();
7770}
7771
7772void
7774 if (!attrs.hasAttribute(SUMO_ATTR_POSITION)) {
7775 throw ProcessError(TL("Error: Invalid vehicles in state (may be a meso state)!"));
7776 }
7777 int routeOffset;
7778 bool stopped;
7779 int pastStops;
7780
7781 std::istringstream bis(attrs.getString(SUMO_ATTR_STATE));
7782 bis >> myParameter->parametersSet;
7783 bis >> myDeparture;
7784 bis >> routeOffset;
7785 bis >> myDepartPos;
7786 bis >> myWaitingTime;
7787 bis >> myTimeLoss;
7788 bis >> myLastActionTime;
7789 bis >> stopped;
7790 bis >> pastStops;
7791
7793 bool ok;
7794 myArrivalPos = attrs.get<double>(SUMO_ATTR_ARRIVALPOS_RANDOMIZED, getID().c_str(), ok);
7795 }
7796 // load stops
7797 myStops.clear();
7799
7800 if (hasDeparted()) {
7801 myCurrEdge = myRoute->begin() + routeOffset;
7802 myDeparture -= offset;
7803 // fix stops
7804 while (pastStops > 0) {
7805 myPastStops.push_back(myStops.front().pars);
7806 myPastStops.back().routeIndex = (int)(myStops.front().edge - myRoute->begin());
7807 myStops.pop_front();
7808 pastStops--;
7809 }
7810 // see MSBaseVehicle constructor
7813 }
7814 // a (tentative lane is needed for calling hasArrivedInternal
7815 myLane = (*myCurrEdge)->getLanes()[0];
7816 }
7819 WRITE_WARNINGF(TL("Action steps are out of sync for loaded vehicle '%'."), getID());
7820 }
7821 std::istringstream pis(attrs.getString(SUMO_ATTR_POSITION));
7823 std::istringstream sis(attrs.getString(SUMO_ATTR_SPEED));
7828 std::istringstream dis(attrs.getString(SUMO_ATTR_DISTANCE));
7829 dis >> myOdometer >> myNumberReroutes;
7831 if (stopped) {
7832 myStops.front().startedFromState = true;
7833 myStopDist = 0;
7834 }
7836 // no need to reset myCachedPosition here since state loading happens directly after creation
7837}
7838
7839void
7841 SUMOTime arrivalTime, double arrivalSpeed,
7842 double arrivalSpeedBraking,
7843 double dist, double leaveSpeed) {
7844 // ensure that approach information is reset on the next call to setApproachingForAllLinks
7845 myLFLinkLanes.push_back(DriveProcessItem(link, 0, 0, setRequest,
7846 arrivalTime, arrivalSpeed, arrivalSpeedBraking, dist, leaveSpeed));
7847
7848}
7849
7850
7851std::shared_ptr<MSSimpleDriverState>
7855
7856
7857double
7859 return myFrictionDevice == nullptr ? 1. : myFrictionDevice->getMeasuredFriction();
7860}
7861
7862
7863void
7864MSVehicle::setPreviousSpeed(double prevSpeed, double prevAcceleration) {
7865 myState.mySpeed = MAX2(0., prevSpeed);
7866 // also retcon acceleration
7867 if (prevAcceleration != std::numeric_limits<double>::min()) {
7868 myAcceleration = prevAcceleration;
7869 } else {
7871 }
7872}
7873
7874
7875double
7877 //return MAX2(-myAcceleration, getCarFollowModel().getApparentDecel());
7879}
7880
7881/****************************************************************************/
7882bool
7886
7887/* -------------------------------------------------------------------------
7888 * methods of MSVehicle::manoeuvre
7889 * ----------------------------------------------------------------------- */
7890
7891MSVehicle::Manoeuvre::Manoeuvre() : myManoeuvreStop(""), myManoeuvreStartTime(0), myManoeuvreCompleteTime(0), myManoeuvreType(MSVehicle::MANOEUVRE_NONE), myGUIIncrement(0) {}
7892
7893
7895 myManoeuvreStop = manoeuvre.myManoeuvreStop;
7896 myManoeuvreStartTime = manoeuvre.myManoeuvreStartTime;
7897 myManoeuvreCompleteTime = manoeuvre.myManoeuvreCompleteTime;
7898 myManoeuvreType = manoeuvre.myManoeuvreType;
7899 myGUIIncrement = manoeuvre.myGUIIncrement;
7900}
7901
7902
7905 myManoeuvreStop = manoeuvre.myManoeuvreStop;
7906 myManoeuvreStartTime = manoeuvre.myManoeuvreStartTime;
7907 myManoeuvreCompleteTime = manoeuvre.myManoeuvreCompleteTime;
7908 myManoeuvreType = manoeuvre.myManoeuvreType;
7909 myGUIIncrement = manoeuvre.myGUIIncrement;
7910 return *this;
7911}
7912
7913
7914bool
7916 return (myManoeuvreStop != manoeuvre.myManoeuvreStop ||
7917 myManoeuvreStartTime != manoeuvre.myManoeuvreStartTime ||
7918 myManoeuvreCompleteTime != manoeuvre.myManoeuvreCompleteTime ||
7919 myManoeuvreType != manoeuvre.myManoeuvreType ||
7920 myGUIIncrement != manoeuvre.myGUIIncrement
7921 );
7922}
7923
7924
7925double
7927 return (myGUIIncrement);
7928}
7929
7930
7933 return (myManoeuvreType);
7934}
7935
7936
7941
7942
7943void
7947
7948
7949void
7951 myManoeuvreType = mType;
7952}
7953
7954
7955bool
7957 if (!veh->hasStops()) {
7958 return false; // should never happen - checked before call
7959 }
7960
7961 const SUMOTime currentTime = MSNet::getInstance()->getCurrentTimeStep();
7962 const MSStop& stop = veh->getNextStop();
7963
7964 int manoeuverAngle = stop.parkingarea->getLastFreeLotAngle();
7965 double GUIAngle = stop.parkingarea->getLastFreeLotGUIAngle();
7966 if (abs(GUIAngle) < 0.1) {
7967 GUIAngle = -0.1; // Wiggle vehicle on parallel entry
7968 }
7969 myManoeuvreVehicleID = veh->getID();
7970 myManoeuvreStop = stop.parkingarea->getID();
7971 myManoeuvreType = MSVehicle::MANOEUVRE_ENTRY;
7972 myManoeuvreStartTime = currentTime;
7973 myManoeuvreCompleteTime = currentTime + veh->myType->getEntryManoeuvreTime(manoeuverAngle);
7974 myGUIIncrement = GUIAngle / (STEPS2TIME(myManoeuvreCompleteTime - myManoeuvreStartTime) / TS);
7975
7976#ifdef DEBUG_STOPS
7977 if (veh->isSelected()) {
7978 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 <<
7979 " endTime=" << myManoeuvreCompleteTime << " manoeuvre time=" << myManoeuvreCompleteTime - currentTime << " parkArea=" << myManoeuvreStop << std::endl;
7980 }
7981#endif
7982
7983 return (true);
7984}
7985
7986
7987bool
7989 // At the moment we only want to set for parking areas
7990 if (!veh->hasStops()) {
7991 return true;
7992 }
7993 if (veh->getNextStop().parkingarea == nullptr) {
7994 return true;
7995 }
7996
7997 if (myManoeuvreType != MSVehicle::MANOEUVRE_NONE) {
7998 return (false);
7999 }
8000
8001 const SUMOTime currentTime = MSNet::getInstance()->getCurrentTimeStep();
8002
8003 int manoeuverAngle = veh->getCurrentParkingArea()->getManoeuverAngle(*veh);
8004 double GUIAngle = veh->getCurrentParkingArea()->getGUIAngle(*veh);
8005 if (abs(GUIAngle) < 0.1) {
8006 GUIAngle = 0.1; // Wiggle vehicle on parallel exit
8007 }
8008
8009 myManoeuvreVehicleID = veh->getID();
8010 myManoeuvreStop = veh->getCurrentParkingArea()->getID();
8011 myManoeuvreType = MSVehicle::MANOEUVRE_EXIT;
8012 myManoeuvreStartTime = currentTime;
8013 myManoeuvreCompleteTime = currentTime + veh->myType->getExitManoeuvreTime(manoeuverAngle);
8014 myGUIIncrement = -GUIAngle / (STEPS2TIME(myManoeuvreCompleteTime - myManoeuvreStartTime) / TS);
8015 if (veh->remainingStopDuration() > 0) {
8016 myManoeuvreCompleteTime += veh->remainingStopDuration();
8017 }
8018
8019#ifdef DEBUG_STOPS
8020 if (veh->isSelected()) {
8021 std::cout << "EXIT manoeuvre start: vehicle=" << veh->getID() << " Manoeuvre Angle=" << manoeuverAngle << " increment=" << RAD2DEG(myGUIIncrement) << " currentTime=" << currentTime
8022 << " endTime=" << myManoeuvreCompleteTime << " manoeuvre time=" << myManoeuvreCompleteTime - currentTime << " parkArea=" << myManoeuvreStop << std::endl;
8023 }
8024#endif
8025
8026 return (true);
8027}
8028
8029
8030bool
8032 // At the moment we only want to consider parking areas - need to check because we could be setting up a manoeuvre
8033 if (!veh->hasStops()) {
8034 return (true);
8035 }
8036 MSStop* currentStop = &veh->myStops.front();
8037 if (currentStop->parkingarea == nullptr) {
8038 return true;
8039 } else if (currentStop->parkingarea->getID() != myManoeuvreStop || MSVehicle::MANOEUVRE_ENTRY != myManoeuvreType) {
8040 if (configureEntryManoeuvre(veh)) {
8042 return (false);
8043 } else { // cannot configure entry so stop trying
8044 return true;
8045 }
8046 } else if (MSNet::getInstance()->getCurrentTimeStep() < myManoeuvreCompleteTime) {
8047 return false;
8048 } else { // manoeuvre complete
8049 myManoeuvreType = MSVehicle::MANOEUVRE_NONE;
8050 return true;
8051 }
8052}
8053
8054
8055bool
8057 if (checkType != myManoeuvreType) {
8058 return true; // we're not maneuvering / wrong manoeuvre
8059 }
8060
8061 if (MSNet::getInstance()->getCurrentTimeStep() < myManoeuvreCompleteTime) {
8062 return false;
8063 } else {
8064 return true;
8065 }
8066}
8067
8068
8069bool
8071 return (MSNet::getInstance()->getCurrentTimeStep() >= myManoeuvreCompleteTime);
8072}
8073
8074
8075bool
8079
8080
8081std::pair<double, double>
8083 if (hasStops()) {
8084 MSLane* lane = myLane;
8085 if (lane == nullptr) {
8086 // not in network
8087 lane = getEdge()->getLanes()[0];
8088 }
8089 const MSStop& stop = myStops.front();
8090 auto it = myCurrEdge + 1;
8091 // drive to end of current edge
8092 double dist = (lane->getLength() - getPositionOnLane());
8093 double travelTime = lane->getEdge().getMinimumTravelTime(this) * dist / lane->getLength();
8094 // drive until stop edge
8095 while (it != myRoute->end() && it < stop.edge) {
8096 travelTime += (*it)->getMinimumTravelTime(this);
8097 dist += (*it)->getLength();
8098 it++;
8099 }
8100 // drive up to the stop position
8101 const double stopEdgeDist = stop.pars.endPos - (lane == stop.lane ? lane->getLength() : 0);
8102 dist += stopEdgeDist;
8103 travelTime += stop.lane->getEdge().getMinimumTravelTime(this) * (stopEdgeDist / stop.lane->getLength());
8104 // estimate time loss due to acceleration and deceleration
8105 // maximum speed is limited by available distance:
8106 const double a = getCarFollowModel().getMaxAccel();
8107 const double b = getCarFollowModel().getMaxDecel();
8108 const double c = getSpeed();
8109 const double d = dist;
8110 const double len = getVehicleType().getLength();
8111 const double vs = MIN2(MAX2(stop.getSpeed(), 0.0), stop.lane->getVehicleMaxSpeed(this));
8112 // distAccel = (v - c)^2 / (2a)
8113 // distDecel = (v + vs)*(v - vs) / 2b = (v^2 - vs^2) / (2b)
8114 // distAccel + distDecel < d
8115 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))))
8116 + pow((a * vs), 2))))) * 0.5) + (c * b)) / (b + a));
8117 it = myCurrEdge;
8118 double v0 = c;
8119 bool v0Stable = getAcceleration() == 0 && v0 > 0;
8120 double timeLossAccel = 0;
8121 double timeLossDecel = 0;
8122 double timeLossLength = 0;
8123 while (it != myRoute->end() && it <= stop.edge) {
8124 double v = MIN2(maxVD, (*it)->getVehicleMaxSpeed(this));
8125 double edgeLength = (it == stop.edge ? stop.pars.endPos : (*it)->getLength()) - (it == myCurrEdge ? getPositionOnLane() : 0);
8126 if (edgeLength <= len && v0Stable && v0 < v) {
8127 const double lengthDist = MIN2(len, edgeLength);
8128 const double dTL = lengthDist / v0 - lengthDist / v;
8129 //std::cout << " e=" << (*it)->getID() << " v0=" << v0 << " v=" << v << " el=" << edgeLength << " lDist=" << lengthDist << " newTLL=" << dTL<< "\n";
8130 timeLossLength += dTL;
8131 }
8132 if (edgeLength > len) {
8133 const double dv = v - v0;
8134 if (dv > 0) {
8135 // timeLossAccel = timeAccel - timeMaxspeed = dv / a - distAccel / v
8136 const double dTA = dv / a - dv * (v + v0) / (2 * a * v);
8137 //std::cout << " e=" << (*it)->getID() << " v0=" << v0 << " v=" << v << " newTLA=" << dTA << "\n";
8138 timeLossAccel += dTA;
8139 // time loss from vehicle length
8140 } else if (dv < 0) {
8141 // timeLossDecel = timeDecel - timeMaxspeed = dv / b - distDecel / v
8142 const double dTD = -dv / b + dv * (v + v0) / (2 * b * v0);
8143 //std::cout << " e=" << (*it)->getID() << " v0=" << v0 << " v=" << v << " newTLD=" << dTD << "\n";
8144 timeLossDecel += dTD;
8145 }
8146 v0 = v;
8147 v0Stable = true;
8148 }
8149 it++;
8150 }
8151 // final deceleration to stop (may also be acceleration or deceleration to waypoint speed)
8152 double v = vs;
8153 const double dv = v - v0;
8154 if (dv > 0) {
8155 // timeLossAccel = timeAccel - timeMaxspeed = dv / a - distAccel / v
8156 const double dTA = dv / a - dv * (v + v0) / (2 * a * v);
8157 //std::cout << " final e=" << (*it)->getID() << " v0=" << v0 << " v=" << v << " newTLA=" << dTA << "\n";
8158 timeLossAccel += dTA;
8159 // time loss from vehicle length
8160 } else if (dv < 0) {
8161 // timeLossDecel = timeDecel - timeMaxspeed = dv / b - distDecel / v
8162 const double dTD = -dv / b + dv * (v + v0) / (2 * b * v0);
8163 //std::cout << " final e=" << (*it)->getID() << " v0=" << v0 << " v=" << v << " newTLD=" << dTD << "\n";
8164 timeLossDecel += dTD;
8165 }
8166 const double result = travelTime + timeLossAccel + timeLossDecel + timeLossLength;
8167 //std::cout << SIMTIME << " v=" << c << " a=" << a << " b=" << b << " maxVD=" << maxVD << " tt=" << travelTime
8168 // << " ta=" << timeLossAccel << " td=" << timeLossDecel << " tl=" << timeLossLength << " res=" << result << "\n";
8169 return {MAX2(0.0, result), dist};
8170 } else {
8172 }
8173}
8174
8175
8176double
8178 if (hasStops() && myStops.front().pars.until >= 0) {
8179 const MSStop& stop = myStops.front();
8180 SUMOTime estimatedDepart = MSNet::getInstance()->getCurrentTimeStep() - DELTA_T;
8181 if (stop.reached) {
8182 return STEPS2TIME(estimatedDepart + stop.duration - stop.pars.until);
8183 }
8184 if (stop.pars.duration > 0) {
8185 estimatedDepart += stop.pars.duration;
8186 }
8187 estimatedDepart += TIME2STEPS(estimateTimeToNextStop().first);
8188 const double result = MAX2(0.0, STEPS2TIME(estimatedDepart - stop.pars.until));
8189 return result;
8190 } else {
8191 // vehicles cannot drive before 'until' so stop delay can never be
8192 // negative and we can use -1 to signal "undefined"
8193 return -1;
8194 }
8195}
8196
8197
8198double
8200 if (hasStops() && myStops.front().pars.arrival >= 0) {
8201 const MSStop& stop = myStops.front();
8202 if (stop.reached) {
8203 return STEPS2TIME(stop.pars.started - stop.pars.arrival);
8204 } else {
8205 return STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep()) + estimateTimeToNextStop().first - STEPS2TIME(stop.pars.arrival);
8206 }
8207 } else {
8208 // vehicles can arrival earlier than planned so arrival delay can be negative
8209 return INVALID_DOUBLE;
8210 }
8211}
8212
8213
8214const MSEdge*
8216 return myLane != nullptr ? &myLane->getEdge() : getEdge();
8217}
8218
8219
8220const MSEdge*
8222 if (myLane == nullptr || (myCurrEdge + 1) == myRoute->end()) {
8223 return nullptr;
8224 }
8225 if (myLane->isInternal()) {
8227 } else {
8228 const MSEdge* nextNormal = succEdge(1);
8229 const MSEdge* nextInternal = myLane->getEdge().getInternalFollowingEdge(nextNormal, getVClass());
8230 return nextInternal ? nextInternal : nextNormal;
8231 }
8232}
8233
8234
8235const MSLane*
8236MSVehicle::getPreviousLane(const MSLane* current, int& furtherIndex) const {
8237 if (furtherIndex < (int)myFurtherLanes.size()) {
8238 return myFurtherLanes[furtherIndex++];
8239 } else {
8240 // try to use route information
8241 int routeIndex = getRoutePosition();
8242 bool resultInternal;
8243 if (MSGlobals::gUsingInternalLanes && MSNet::getInstance()->hasInternalLinks()) {
8244 if (myLane->isInternal()) {
8245 if (furtherIndex % 2 == 0) {
8246 routeIndex -= (furtherIndex + 0) / 2;
8247 resultInternal = false;
8248 } else {
8249 routeIndex -= (furtherIndex + 1) / 2;
8250 resultInternal = false;
8251 }
8252 } else {
8253 if (furtherIndex % 2 != 0) {
8254 routeIndex -= (furtherIndex + 1) / 2;
8255 resultInternal = false;
8256 } else {
8257 routeIndex -= (furtherIndex + 2) / 2;
8258 resultInternal = true;
8259 }
8260 }
8261 } else {
8262 routeIndex -= furtherIndex;
8263 resultInternal = false;
8264 }
8265 furtherIndex++;
8266 if (routeIndex >= 0) {
8267 if (resultInternal) {
8268 const MSEdge* prevNormal = myRoute->getEdges()[routeIndex];
8269 for (MSLane* cand : prevNormal->getLanes()) {
8270 for (MSLink* link : cand->getLinkCont()) {
8271 if (link->getLane() == current) {
8272 if (link->getViaLane() != nullptr) {
8273 return link->getViaLane();
8274 } else {
8275 return const_cast<MSLane*>(link->getLaneBefore());
8276 }
8277 }
8278 }
8279 }
8280 } else {
8281 return myRoute->getEdges()[routeIndex]->getLanes()[0];
8282 }
8283 }
8284 }
8285 return current;
8286}
8287
8290 // this vehicle currently has the highest priority on the allway_stop
8291 return link == myHaveStoppedFor ? SUMOTime_MAX : getWaitingTime();
8292}
8293
8294
8295void
8297 bool diverged = false;
8298 const ConstMSEdgeVector& route = myRoute->getEdges();
8299 int ri = getRoutePosition();
8300 for (const DriveProcessItem& dpi : myLFLinkLanes) {
8301 if (dpi.myLink != nullptr) {
8302 if (!diverged) {
8303 const MSEdge* next = route[ri + 1];
8304 if (&dpi.myLink->getLane()->getEdge() != next) {
8305 diverged = true;
8306 } else {
8307 if (dpi.myLink->getViaLane() == nullptr) {
8308 ri++;
8309 }
8310 }
8311 }
8312 if (diverged) {
8313 dpi.myLink->removeApproaching(this);
8314 }
8315 }
8316 }
8317}
8318
8319
8320bool
8324
8325/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define RAD2DEG(x)
Definition GeomHelper.h:36
#define DEBUG_COND2(obj)
Definition MESegment.cpp:54
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 WRITE_WARNING(msg)
Definition MsgHandler.h:286
#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.
@ 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.
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_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:43
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:46
#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 angle)
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)
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.
The car-following model abstraction.
Definition MSCFModel.h:57
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:252
double getEmergencyDecel() const
Get the vehicle type's maximal physically possible deceleration [m/s^2].
Definition MSCFModel.h:277
SUMOTime getStartupDelay() const
Get the vehicle type's startupDelay.
Definition MSCFModel.h:293
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:619
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...
@ FUTURE
the return value is used for calculating future speeds
Definition MSCFModel.h:83
@ CURRENT_WAIT
the return value is used for calculating junction stop speeds
Definition MSCFModel.h:85
double getApparentDecel() const
Get the vehicle type's apparent deceleration [m/s^2] (the one regarded by its followers.
Definition MSCFModel.h:285
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
Definition MSCFModel.h:261
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
Definition MSCFModel.h:408
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:229
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:269
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:173
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
Definition MSCFModel.h:339
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:1120
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:1368
bool isFringe() const
return whether this edge is at the fringe of the network
Definition MSEdge.h:773
const MSEdge * getNormalSuccessor() const
if this edge is an internal edge, return its first normal successor, otherwise the edge itself
Definition MSEdge.cpp:975
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:1186
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:1390
bool hasLaneChanger() const
Definition MSEdge.h:747
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:730
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:1479
const MSEdge * getInternalFollowingEdge(const MSEdge *followerAfterInternal, SUMOVehicleClass vClass) const
Definition MSEdge.cpp:928
void removeWaiting(const SUMOVehicle *vehicle) const
Removes a vehicle from the list of waiting vehicles.
Definition MSEdge.cpp:1488
const MSEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
Definition MSEdge.cpp:1286
static bool gModelParkingManoeuver
whether parking simulation includes manoeuver time and any associated lane blocking
Definition MSGlobals.h:162
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:180
static double gTLSYellowMinDecel
The minimum deceleration at a yellow traffic light (only overruled by emergencyDecel)
Definition MSGlobals.h:171
static double gLateralResolution
Definition MSGlobals.h:100
static bool gSemiImplicitEulerUpdate
Definition MSGlobals.h:53
static bool gLefthand
Whether lefthand-drive is being simulated.
Definition MSGlobals.h:174
static bool gSublane
whether sublane simulation is enabled (sublane model or continuous lanechanging)
Definition MSGlobals.h:165
static SUMOTime gLaneChangeDuration
Definition MSGlobals.h:97
static double gEmergencyDecelWarningThreshold
threshold for warning about strong deceleration
Definition MSGlobals.h:152
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:1297
const std::vector< MSMoveReminder * > & getMoveReminders() const
Return the list of this lane's move reminders.
Definition MSLane.h:324
std::pair< MSVehicle *const, double > getFollower(const MSVehicle *ego, double egoPos, double dist, MinorLinkMode mLinkMode) const
Find follower vehicle for the given ego vehicle (which may be on the opposite direction lane)
Definition MSLane.cpp:4414
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:4588
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:2864
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
Definition MSLane.cpp:2846
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:2694
const MSLink * getEntryLink() const
Returns the entry link if this is an internal lane, else nullptr.
Definition MSLane.cpp:2782
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:1170
static std::vector< MSLink * >::const_iterator succLinkSec(const SUMOVehicle &veh, int nRouteSuccs, const MSLane &succLinkSource, const std::vector< MSLane * > &conts)
Definition MSLane.cpp:2708
void markRecalculateBruttoSum()
Set a flag to recalculate the brutto (including minGaps) occupancy of this lane (used if mingap is ch...
Definition MSLane.cpp:2440
const MSLink * getLinkTo(const MSLane *const) const
returns the link to the given lane or nullptr, if it is not connected
Definition MSLane.cpp:2759
void forceVehicleInsertion(MSVehicle *veh, double pos, MSMoveReminder::Notification notification, double posLat=0)
Inserts the given vehicle at the given position.
Definition MSLane.cpp:1399
double getVehicleStopOffset(const MSVehicle *veh) const
Returns vehicle class specific stopOffset for the vehicle.
Definition MSLane.cpp:3792
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
Definition MSLane.h:598
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:2472
SVCPermissions getPermissions() const
Returns the vehicle class permissions for this lane.
Definition MSLane.h:620
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
Definition MSLane.h:961
MSLane * getCanonicalPredecessorLane() const
Definition MSLane.cpp:3286
double getLength() const
Returns the lane's length.
Definition MSLane.h:612
double getMaximumBrakeDist() const
compute maximum braking distance on this lane
Definition MSLane.cpp:2921
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:2771
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:1452
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:3005
bool isLinkEnd(std::vector< MSLink * >::const_iterator &i) const
Definition MSLane.h:861
bool allowsVehicleClass(SUMOVehicleClass vclass) const
Definition MSLane.h:936
virtual double setPartialOccupation(MSVehicle *v)
Sets the information about a vehicle lapping into this lane.
Definition MSLane.cpp:384
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:1206
bool hasPedestrians() const
whether the lane has pedestrians on it
Definition MSLane.cpp:4581
int getIndex() const
Returns the lane's index.
Definition MSLane.h:648
MSLane * getCanonicalSuccessorLane() const
Definition MSLane.cpp:3310
double getOppositePos(double pos) const
return the corresponding position on the opposite lane
Definition MSLane.cpp:4409
MSLane * getLogicalPredecessorLane() const
get the most likely precedecessor lane (sorted using by_connections_to_sorter). The result is cached ...
Definition MSLane.cpp:3230
double getCenterOnEdge() const
Definition MSLane.h:1214
bool isNormal() const
Definition MSLane.cpp:2633
MSVehicle * getLastAnyVehicle() const
returns the last vehicle that is fully or partially on this lane
Definition MSLane.cpp:2675
bool isInternal() const
Definition MSLane.cpp:2627
@ FOLLOW_NEVER
Definition MSLane.h:985
virtual void resetPartialOccupation(MSVehicle *v)
Removes the information about a vehicle lapping into this lane.
Definition MSLane.cpp:403
MSLane * getOpposite() const
return the neighboring opposite direction lane for lane changing or nullptr
Definition MSLane.cpp:4397
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:4699
double interpolateLanePosToGeometryPos(double lanePos) const
Definition MSLane.h:555
MSLane * getBidiLane() const
retrieve bidirectional lane or nullptr
Definition MSLane.cpp:4693
@ 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:4403
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:770
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:4708
const MSLane * getNormalPredecessorLane() const
get normal lane leading to this internal lane, for normal lanes, the lane itself is returned
Definition MSLane.cpp:3255
MSLeaderDistanceInfo getFollowersOnConsecutive(const MSVehicle *ego, double backOffset, bool allSublanes, double searchDist=-1, MinorLinkMode mLinkMode=FOLLOW_ALWAYS) const
return the sublane followers with the largest missing rear gap among all predecessor lanes (within di...
Definition MSLane.cpp:3817
double getWidth() const
Returns the lane's width.
Definition MSLane.h:641
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
Definition MSLane.h:730
MSVehicle * getFirstFullVehicle() const
returns the first vehicle for which this lane is responsible or 0
Definition MSLane.cpp:2666
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition MSLane.h:561
static CollisionAction getCollisionAction()
Definition MSLane.h:1368
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:1334
VehicleState
Definition of a vehicle state.
Definition MSNet.h:626
@ 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:187
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition MSNet.cpp:1267
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:1489
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:1468
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition MSNet.cpp:1326
bool hasContainers() const
Returns whether containers are simulated.
Definition MSNet.h:425
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:1343
bool hasPersons() const
Returns whether persons are simulated.
Definition MSNet.h:409
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition MSNet.h:445
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:392
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1258
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition MSNet.h:435
bool hasElevation() const
return whether the network contains elevation data
Definition MSNet.h:808
static const double SAFETY_GAP
Definition MSPModel.h:59
A lane area vehicles can halt at.
int getOccupancyIncludingReservations(const SUMOVehicle *forVehicle) const
void leaveFrom(SUMOVehicle *what)
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.
void enter(SUMOVehicle *veh, const bool parking)
Called if a vehicle enters this stop.
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:212
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:170
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 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:187
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:66
static bool active()
Definition MSStopOut.h:54
void stopNotStarted(const SUMOVehicle *veh)
Definition MSStopOut.cpp:75
void stopStarted(const SUMOVehicle *veh, int numPersons, int numContainers, SUMOTime time)
Definition MSStopOut.cpp:82
void stopEnded(const SUMOVehicle *veh, const SUMOVehicleParameter::Stop &stop, const std::string &laneOrEdgeID, bool simEnd=false)
static MSStopOut * getInstance()
Definition MSStopOut.h:60
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:1357
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:1352
void setLaneChangeMode(int value)
Sets lane changing behavior.
TraciLaneChangePriority myTraciLaneChangePriority
flags for determining the priority of traci lane change requests
Definition MSVehicle.h:1683
bool getEmergencyBrakeRedLight() const
Returns whether red lights shall be a reason to brake.
Definition MSVehicle.h:1526
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:1628
int getSignals() const
Definition MSVehicle.h:1599
bool myConsiderMaxDeceleration
Whether the maximum deceleration shall be regarded.
Definition MSVehicle.h:1649
void setLaneTimeLine(const std::vector< std::pair< SUMOTime, int > > &laneTimeLine)
Sets a new lane timeline.
bool hasSpeedTimeLine(SUMOTime t) const
Definition MSVehicle.h:1433
bool myRespectJunctionLeaderPriority
Whether the junction priority rules are respected (within)
Definition MSVehicle.h:1658
void setOriginalSpeed(double speed)
Stores the originally longitudinal speed.
double myOriginalSpeed
The velocity before influence.
Definition MSVehicle.h:1631
bool myConsiderSpeedLimit
Whether the speed limit shall be regarded.
Definition MSVehicle.h:1643
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:1667
bool getRespectJunctionLeaderPriority() const
Returns whether junction priority rules within the junction shall be respected (concerns vehicles wit...
Definition MSVehicle.h:1534
LaneChangeMode myStrategicLC
lane changing which is necessary to follow the current route
Definition MSVehicle.h:1672
LaneChangeMode mySpeedGainLC
lane changing to travel with higher speed
Definition MSVehicle.h:1676
void init()
Static initalization.
LaneChangeMode mySublaneLC
changing to the prefered lateral alignment
Definition MSVehicle.h:1680
bool getRespectJunctionPriority() const
Returns whether junction priority rules shall be respected (concerns approaching vehicles outside the...
Definition MSVehicle.h:1518
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:1640
bool mySpeedAdaptationStarted
Whether influencing the speed has already started.
Definition MSVehicle.h:1637
~Influencer()
Destructor.
void setSignals(int signals)
Definition MSVehicle.h:1595
double myLatDist
The requested lateral change.
Definition MSVehicle.h:1634
bool considerSpeedLimit() const
Returns whether speed limits shall be considered.
Definition MSVehicle.h:1545
bool myEmergencyBrakeRedLight
Whether red lights are a reason to brake.
Definition MSVehicle.h:1655
LaneChangeMode myRightDriveLC
changing to the rightmost lane
Definition MSVehicle.h:1678
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:1551
SUMOTime getLastAccessTimeStep() const
Definition MSVehicle.h:1575
bool myConsiderMaxAcceleration
Whether the maximum acceleration shall be regarded.
Definition MSVehicle.h:1646
LaneChangeMode myCooperativeLC
lane changing with the intent to help other vehicles
Definition MSVehicle.h:1674
bool isRemoteControlled() const
bool myRespectJunctionPriority
Whether the junction priority rules are respected (approaching)
Definition MSVehicle.h:1652
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:1276
SUMOTime myManoeuvreCompleteTime
Time at which this manoeuvre should complete.
Definition MSVehicle.h:1328
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:1322
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:1331
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:1325
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:1154
@ LCP_OPPORTUNISTIC
Definition MSVehicle.h:1158
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:996
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:1942
SUMOTime myWaitingTime
The time the vehicle waits (is not faster than 0.1m/s) in seconds.
Definition MSVehicle.h:1878
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:1882
SUMOTime myLastActionTime
Action offset (actions are taken at time myActionOffset + N*getActionStepLength()) Initialized to 0,...
Definition MSVehicle.h:1897
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...
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:1963
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:1924
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:1953
void setPreviousSpeed(double prevSpeed, double prevAcceleration)
Sets the influenced previous speed.
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:1904
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:1931
bool signalSet(int which) const
Returns whether the given signal is on.
Definition MSVehicle.h:1190
MSCFModel::VehicleVariables * myCFVariables
The per vehicle variables of the car following model.
Definition MSVehicle.h:2175
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:1928
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:1939
void enterLaneAtMove(MSLane *enteredLane, bool onTeleporting=false)
Update when the vehicle enters a new lane in the move step.
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:2089
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:1919
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:1907
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:1879
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:1249
@ MANOEUVRE_ENTRY
Manoeuvre into stopping place.
Definition MSVehicle.h:1251
@ MANOEUVRE_NONE
not manouevring
Definition MSVehicle.h:1255
@ MANOEUVRE_EXIT
Manoeuvre out of stopping place.
Definition MSVehicle.h:1253
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:1906
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:2178
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:2032
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:2045
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:1967
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
SUMOTime myJunctionEntryTimeNeverYield
Definition MSVehicle.h:1962
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:1173
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:1936
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:1950
Signalling
Some boolean values which describe the state of some vehicle parts.
Definition MSVehicle.h:1108
@ VEH_SIGNAL_BLINKER_RIGHT
Right blinker lights are switched on.
Definition MSVehicle.h:1112
@ VEH_SIGNAL_BRAKELIGHT
The brake lights are on.
Definition MSVehicle.h:1118
@ VEH_SIGNAL_EMERGENCY_BLUE
A blue emergency light is on.
Definition MSVehicle.h:1134
@ VEH_SIGNAL_BLINKER_LEFT
Left blinker lights are switched on.
Definition MSVehicle.h:1114
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:1944
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:1956
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:2038
std::vector< std::vector< LaneQ > > myBestLanes
Definition MSVehicle.h:1914
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:1894
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:1966
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:1921
Position myCachedPosition
Definition MSVehicle.h:1958
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:835
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:1933
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:969
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:1947
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:1888
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:1902
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:1338
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:1702
MSDevice_Friction * myFrictionDevice
This vehicle's friction perception.
Definition MSVehicle.h:1891
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:1146
virtual void drawOutsideNetwork(bool)
register vehicle for drawing while outside the network
Definition MSVehicle.h:1853
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:1885
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:1165
static bool overlap(const MSVehicle *veh1, const MSVehicle *veh2)
Definition MSVehicle.h:763
int getLaneIndex() const
void updateParkingState()
update state while parking
DriveItemVector myLFLinkLanes
container for the planned speeds in the current step
Definition MSVehicle.h:2035
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:1961
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:67
const std::string & getID() const
Returns the id.
Definition Named.h:74
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
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 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
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:1974
void adaptStopSpeed(const double v)
Definition MSVehicle.h:2021
double getLeaveSpeed() const
Definition MSVehicle.h:2025
void adaptLeaveSpeed(const double v)
Definition MSVehicle.h:2013
static std::map< const MSVehicle *, GapControlState * > refVehMap
stores reference vehicles currently in use by a gapController
Definition MSVehicle.h:1411
static GapControlVehStateListener * myVehStateListener
Definition MSVehicle.h:1414
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:857
double length
The overall length which may be driven when using this lane without a lane change.
Definition MSVehicle.h:861
bool allowsContinuation
Whether this lane allows to continue the drive.
Definition MSVehicle.h:871
double nextOccupation
As occupation, but without the first lane.
Definition MSVehicle.h:867
std::vector< MSLane * > bestContinuations
Definition MSVehicle.h:877
MSLane * lane
The described lane.
Definition MSVehicle.h:859
double currentLength
The length which may be driven on this lane.
Definition MSVehicle.h:863
int bestLaneOffset
The (signed) number of lanes to be crossed to get to the lane which allows to continue the drive.
Definition MSVehicle.h:869
double occupation
The overall vehicle sum on consecutive lanes which can be passed without a lane change.
Definition MSVehicle.h:865