Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MEVehicle.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/****************************************************************************/
19// A vehicle from the mesoscopic point of view
20/****************************************************************************/
21#include <config.h>
22
23#include <iostream>
24#include <cassert>
25#include <cmath>
26#include <limits>
38#include <microsim/MSGlobals.h>
39#include <microsim/MSEdge.h>
40#include <microsim/MSLane.h>
41#include <microsim/MSNet.h>
43#include <microsim/MSLink.h>
44#include <microsim/MSStop.h>
48#include "MELoop.h"
49#include "MEVehicle.h"
50#include "MESegment.h"
51
52
53// ===========================================================================
54// method definitions
55// ===========================================================================
57 MSVehicleType* type, const double speedFactor) :
58 MSBaseVehicle(pars, route, type, speedFactor),
59 mySegment(nullptr),
60 myQueIndex(0),
61 myEventTime(SUMOTime_MIN),
62 myEventIndex(-1),
63 myLastEntryTime(SUMOTime_MIN),
64 myBlockTime(SUMOTime_MAX),
65 myUnqueuedEventTime(SUMOTime_MIN),
66 myWasJammed(false),
67 myInfluencer(nullptr) {
68}
69
70
71double
72MEVehicle::getBackPositionOnLane(const MSLane* /* lane */) const {
74}
75
76
77double
80 && !MESegment::isInvalid(mySegment) && myQueIndex >= 0 && myQueIndex < mySegment->numQueues()) {
82 if (myMesoPosition != -std::numeric_limits<double>::max()) {
83 return myMesoPosition;
84 }
85 }
86 return mySegment == nullptr ? 0. : (double)mySegment->getIndex() * mySegment->getLength();
87}
88
89
90double
92 const MSLane* const lane = getEdge()->getLanes()[MAX2(0, getQueIndex())];
94}
95
96
97double
99 const MSLane* const lane = getEdge()->getLanes()[MAX2(0, getQueIndex())];
101 - (MSGlobals::gSlopeCentered ? getLength() / 2 : 0)));
102}
103
104
105const MSEdge*
107 return mySegment != nullptr ? &mySegment->getEdge() : getEdge();
108}
109
110
112MEVehicle::getPosition(const double offset) const {
113 const MSLane* const lane = getEdge()->getLanes()[MAX2(0, getQueIndex())];
114 return lane->geometryPositionAtOffset(getPositionOnLane() + offset);
115}
116
117
119MEVehicle::getBoundingBox(double offset) const {
120 double a = getAngle() + M_PI; // angle pointing backwards
121 double l = getLength();
122 Position pos = getPosition();
123 Position backPos = pos + Position(l * cos(a), l * sin(a));
124 PositionVector centerLine;
125 centerLine.push_back(pos);
126 centerLine.push_back(backPos);
127 if (offset != 0) {
128 centerLine.extrapolate2D(offset);
129 }
130 PositionVector result = centerLine;
131 result.move2side(MAX2(0.0, 0.5 * myType->getWidth() + offset));
132 centerLine.move2side(MIN2(0.0, -0.5 * myType->getWidth() - offset));
133 result.append(centerLine.reverse(), POSITION_EPS);
134 return result;
135}
136
137
138double
140 if (getWaitingTime() > 0 || isStopped()) {
141 return 0;
142 } else {
143 return getAverageSpeed();
144 }
145}
146
147
148double
150 // cache for thread safety
151 MESegment* s = mySegment;
152 if (s == nullptr || myQueIndex == MESegment::PARKING_QUEUE) {
153 return 0;
154 } else {
156 s->getVehicleMaxSpeed(*this, myQueIndex));
157 }
158}
159
160
161double
164 const double v = getSpeed();
165 return MIN2(link->getViaLaneOrLane()->getVehicleMaxSpeed(this),
166 (double)sqrt(2 * link->getLength() * getVehicleType().getCarFollowModel().getMaxAccel() + v * v));
167}
168
169
170double
172 earliestArrival = MAX2(myEventTime, earliestArrival - DELTA_T); // event times have subsecond resolution
173 return mySegment->getLength() / STEPS2TIME(earliestArrival - myLastEntryTime);
174}
175
176
177bool
179 // vehicle has just entered a new edge. Position is 0
180 if (myCurrEdge == myRoute->end() - 1 || (myParameter->arrivalEdge >= 0 && getRoutePosition() >= myParameter->arrivalEdge)) { // may happen during teleport
181 return true;
182 }
183 ++myCurrEdge;
184 if ((*myCurrEdge)->isVaporizing()) {
185 return true;
186 }
187 // update via
188 if (myParameter->via.size() > 0 && (*myCurrEdge)->getID() == myParameter->via.front()) {
189 myParameter->via.erase(myParameter->via.begin());
190 }
191 return hasArrived();
192}
193
194
195bool
197 // mySegment may be 0 due to teleporting or arrival
198 return (myCurrEdge == myRoute->end() - 1 || (myParameter->arrivalEdge >= 0 && getRoutePosition() >= myParameter->arrivalEdge)) && (
199 (mySegment == nullptr)
201 || getPositionOnLane() > myArrivalPos - POSITION_EPS);
202}
203
204
205bool
207 return getSegment() != nullptr;
208}
209
210
211bool
213 return false;
214}
215
216
217void
219 if (link != nullptr) {
220 const double speed = getSpeed();
221 link->setApproaching(this, getEventTime() + (link->getState() == LINKSTATE_ALLWAY_STOP ?
222 (SUMOTime)RandHelper::rand((int)2) : 0), // tie braker
223 speed, link->getViaLaneOrLane()->getVehicleMaxSpeed(this), true,
224 speed, getWaitingTime(),
225 // @note: dist is not used by meso (getZipperSpeed is never called)
226 getSegment()->getLength(), 0);
227 }
228}
229
230
231bool
232MEVehicle::replaceRoute(ConstMSRoutePtr newRoute, const std::string& info, bool onInit, int offset, bool addRouteStops, bool removeStops, std::string* msgReturn) {
233 MSLink* const oldLink = mySegment != nullptr ? mySegment->getLink(this) : nullptr;
234 if (MSBaseVehicle::replaceRoute(newRoute, info, onInit, offset, addRouteStops, removeStops, msgReturn)) {
235 if (mySegment != nullptr) {
236 MSLink* const newLink = mySegment->getLink(this);
237 // update approaching vehicle information
238 if (oldLink != newLink) {
239 if (oldLink != nullptr) {
240 oldLink->removeApproaching(this);
241 }
242 setApproaching(newLink);
243 }
244 }
245 return true;
246 }
247 return false;
248}
249
250
253 const SUMOTime initialTime = time;
254 bool hadStop = false;
255 bool reachedStop = false;
256 for (MSStop& stop : myStops) {
257 if (stop.joinTriggered) {
258 WRITE_WARNINGF(TL("Join stops are not available in meso yet (vehicle '%', segment '%')."),
259 getID(), mySegment->getID());
260 continue;
261 }
262 if (stop.edge != myCurrEdge || stop.segment != mySegment) {
263 break;
264 }
265 const SUMOTime cur = time;
266 if (stop.duration > 0) { // it might be a triggered stop with duration -1
267 if (stop.duration >= SUMOTime_MAX / 2) {
268 // avoid overflow!
269 time = SUMOTime_MAX / 2;
270 } else {
271 time += stop.duration;
272 }
273 }
274 if (stop.pars.until > time) {
275 // @note: this assumes the stop is reached at time. With the way this is called in MESegment (time == entryTime),
276 // travel time is overestimated of the stop is not at the start of the segment
277 time = stop.pars.until;
278 }
279 if (MSGlobals::gUseStopEnded && stop.pars.ended >= 0) {
280 time = MAX2(cur, stop.pars.ended);
281 }
282 if (!stop.reached) {
283 reachedStop = true;
284 stop.reached = true;
285 stop.pars.started = myLastEntryTime;
286 stop.endBoarding = stop.pars.extension >= 0 ? time + stop.pars.extension : SUMOTime_MAX;
287 if (MSStopOut::active()) {
288 if (!hadStop) {
290 } else {
291 WRITE_WARNINGF(TL("Vehicle '%' has multiple stops on segment '%', time=% (stop-output will be merged)."),
292 getID(), mySegment->getID(), time2string(time));
293 }
294 }
295 }
296 if (stop.triggered || stop.containerTriggered || stop.joinTriggered) {
297 time = MAX2(time, cur + DELTA_T);
298 }
299 hadStop = true;
300 }
301 if (reachedStop) {
302 MSDevice_Taxi* taxi = static_cast<MSDevice_Taxi*>(getDevice(typeid(MSDevice_Taxi)));
303 if (taxi != nullptr) {
304 taxi->notifyMove(*this, 0, 0, 0);
305 }
306 }
307 MSDevice_Tripinfo* tripinfo = static_cast<MSDevice_Tripinfo*>(getDevice(typeid(MSDevice_Tripinfo)));
308 if (tripinfo != nullptr) {
309 tripinfo->updateStopTime(time - initialTime);
310 }
311 return time;
312}
313
314
315bool
317 if (isStopped()) {
318 const SUMOTime now = SIMSTEP;
319 MSStop& stop = myStops.front();
320 stop.pars.ended = now;
321 for (const auto& rem : myMoveReminders) {
322 rem.first->notifyStopEnded();
323 }
324 if (MSStopOut::active()) {
325 MSStopOut::getInstance()->stopEnded(this, stop);
326 }
327 myPastStops.push_back(stop.pars);
328 myPastStops.back().routeIndex = (int)(stop.edge - myRoute->begin());
332 }
333 myStops.pop_front();
334 if (myEventTime > now) {
335 // if this is an aborted stop we need to change the event time of the vehicle
336 const bool isLeader = myQueIndex != MESegment::PARKING_QUEUE && mySegment->getQueue(myQueIndex).back() == this;
337 if (isLeader) {
339 myEventTime = now + 1;
340 MSGlobals::gMesoNet->addLeaderCar(this, nullptr);
341 }
342 }
343 return true;
344 }
345 return false;
346}
347
348
349double
352 for (const MSStop& stop : myStops) {
353 if (stop.reached) {
354 time += stop.duration;
355 if (stop.pars.until > time) {
356 // @note: this assumes the stop is reached at time. With the way this is called in MESegment (time == entryTime),
357 // travel time is overestimated of the stop is not at the start of the segment
358 time = stop.pars.until;
359 }
360 } else {
361 break;
362 }
363 }
364 return STEPS2TIME(time - myLastEntryTime);
365}
366
367
368void
370 assert(isStopped());
371 double lastPos = -1;
372 bool hadStop = false;
373 while (!myStops.empty()) {
374 MSStop& stop = myStops.front();
375 if (stop.edge != myCurrEdge || stop.segment != mySegment || stop.pars.endPos <= lastPos) {
376 break;
377 }
378 lastPos = stop.pars.endPos;
379 MSNet* const net = MSNet::getInstance();
380 SUMOTime dummy = -1; // boarding- and loading-time are not considered
381 if (hadStop && MSStopOut::active()) {
382 stop.reached = true;
384 }
385 if (net->hasPersons()) {
386 net->getPersonControl().loadAnyWaiting(&mySegment->getEdge(), this, dummy, dummy);
387 }
388 if (net->hasContainers()) {
389 net->getContainerControl().loadAnyWaiting(&mySegment->getEdge(), this, dummy, dummy);
390 }
392 hadStop = true;
393 }
394 if (getWaitingTime() > 0) {
395 // entry back onto the road was blocked for some time
396 MSDevice_Tripinfo* tripinfoDevice = static_cast<MSDevice_Tripinfo*>(getDevice(typeid(MSDevice_Tripinfo)));
397 if (tripinfoDevice != nullptr) {
398 tripinfoDevice->recordMesoParkingTimeLoss(getWaitingTime());
399 }
400 }
402}
403
404
405bool
407 MSNet* const net = MSNet::getInstance();
408 SUMOTime dummy = -1; // boarding- and loading-time are not considered
409 for (MSStop& stop : myStops) {
410 if (!stop.reached) {
411 break;
412 }
413 if (net->getCurrentTimeStep() > stop.endBoarding) {
414 if (stop.triggered || stop.containerTriggered) {
415 MSDevice_Taxi* taxiDevice = static_cast<MSDevice_Taxi*>(getDevice(typeid(MSDevice_Taxi)));
416 if (taxiDevice != nullptr) {
417 taxiDevice->cancelCurrentCustomers();
418 }
419 stop.triggered = false;
420 stop.containerTriggered = false;
421 }
425 }
426 }
427 if (stop.triggered) {
429 // we could not check this on entering the segment because there may be persons who still want to leave
430 WRITE_WARNINGF(TL("Vehicle '%' ignores triggered stop on lane '%' due to capacity constraints."), getID(), stop.lane->getID());
431 stop.triggered = false;
435 }
436 } else if (!net->hasPersons() || !net->getPersonControl().loadAnyWaiting(&mySegment->getEdge(), this, dummy, dummy)) {
440 }
441 return false;
442 }
443 }
444 if (stop.containerTriggered) {
445 if (getVehicleType().getContainerCapacity() == getContainerNumber()) {
446 // we could not check this on entering the segment because there may be containers who still want to leave
447 WRITE_WARNINGF(TL("Vehicle '%' ignores container triggered stop on lane '%' due to capacity constraints."), getID(), stop.lane->getID());
448 stop.containerTriggered = false;
452 }
453 } else if (!net->hasContainers() || !net->getContainerControl().loadAnyWaiting(&mySegment->getEdge(), this, dummy, dummy)) {
457 }
458 return false;
459 }
460 }
461 if (stop.joinTriggered) {
462 // TODO do something useful here
463 return false;
464 }
465 }
466 return true;
467}
468
469
470int
472 if (mySegment == nullptr) {
474 }
475 if (!endTriggeredStop()) {
477 }
478 return mySegment->isOpen(this);
479}
480
481
482double
484 if (mySegment == nullptr) {
485 return 0;
486 } else {
487 return STEPS2TIME(mySegment->getLinkPenalty(this));
488 }
489}
490
491
492void
494 for (MoveReminderCont::iterator i = myMoveReminders.begin(); i != myMoveReminders.end(); ++i) {
495 if (i->first == rem) {
498 getLastEntryTime(), currentTime, exitTime, false);
499#ifdef _DEBUG
500 if (myTraceMoveReminders) {
501 traceMoveReminder("notifyMove", i->first, i->second, true);
502 }
503#endif
504 return;
505 }
506 }
507}
508
509
510void
511MEVehicle::updateDetectors(const SUMOTime currentTime, const SUMOTime exitTime, const bool isLeave, const MSMoveReminder::Notification reason) {
512 // segments of the same edge have the same reminder so no cleaning up must take place
513 const bool cleanUp = isLeave && (reason != MSMoveReminder::NOTIFICATION_SEGMENT);
514 for (MoveReminderCont::iterator rem = myMoveReminders.begin(); rem != myMoveReminders.end();) {
516 rem->first->updateDetector(*this, mySegment->getIndex() * mySegment->getLength(),
518 getLastEntryTime(), currentTime, exitTime, cleanUp);
519#ifdef _DEBUG
520 if (myTraceMoveReminders) {
521 traceMoveReminder("notifyMove", rem->first, rem->second, true);
522 }
523#endif
524 }
525 if (!isLeave || rem->first->notifyLeave(*this, mySegment == nullptr ? 0 : mySegment->getLength(), reason)) {
526#ifdef _DEBUG
527 if (isLeave && myTraceMoveReminders) {
528 traceMoveReminder("notifyLeave", rem->first, rem->second, true);
529 }
530#endif
531
532 if (isLeave) {
533 rem->second += getEdge()->getLength();
534#ifdef _DEBUG
535 if (myTraceMoveReminders) {
536 traceMoveReminder("adaptedPos", rem->first, rem->second, true);
537 }
538#endif
539 }
540 ++rem;
541 } else {
542#ifdef _DEBUG
543 if (myTraceMoveReminders) {
544 traceMoveReminder("remove", rem->first, rem->second, false);
545 }
546#endif
547 rem = myMoveReminders.erase(rem);
548 }
549 }
552 }
553}
554
555
558 if (myInfluencer == nullptr) {
560 }
561 return *myInfluencer;
562}
563
564
569
570
571void
576
577
578int
580 return getSegment() != nullptr ? getSegment()->getIndex() : -1;
581}
582
583
584double
585MEVehicle::getRightSideOnEdge(const MSLane* /*lane*/) const {
586 if (mySegment == nullptr || mySegment->getIndex() >= getEdge()->getNumLanes()) {
587 return 0;
588 }
589 const MSLane* lane = getEdge()->getLanes()[mySegment->getIndex()];
590 return lane->getRightSideOnEdge() + lane->getWidth() * 0.5 - 0.5 * getVehicleType().getWidth();
591
592}
593
594
595void
597 if (mySegment != nullptr && MESegment::isInvalid(mySegment)) {
598 // segment is vaporization target, do not write this vehicle
599 return;
600 }
602 assert(mySegment == nullptr || *myCurrEdge == &mySegment->getEdge() || mySegment->getEdge().isInternal());
603 std::vector<SUMOTime> internals;
604 internals.push_back(myParameter->parametersSet);
605 internals.push_back(myDeparture);
606 internals.push_back((SUMOTime)distance(myRoute->begin(), myCurrEdge));
607 internals.push_back((SUMOTime)myDepartPos * 1000); // store as mm
608 internals.push_back(mySegment == nullptr ? (SUMOTime) - 1 : (SUMOTime)mySegment->getIndex());
609 internals.push_back((SUMOTime)getQueIndex());
610 internals.push_back(myEventTime);
611 internals.push_back(myLastEntryTime);
612 internals.push_back(myBlockTime);
613 internals.push_back(isStopped());
614 internals.push_back(myPastStops.size());
615 internals.push_back(myWasJammed);
616 internals.push_back(myEventIndex);
617 internals.push_back(myUnqueuedEventTime);
618 out.writeAttr(SUMO_ATTR_STATE, toString(internals));
619 // save past stops
621 stop.write(out, false);
622 // do not write started and ended twice
623 if ((stop.parametersSet & STOP_STARTED_SET) == 0) {
624 out.writeAttr(SUMO_ATTR_STARTED, time2string(stop.started));
625 }
626 if ((stop.parametersSet & STOP_ENDED_SET) == 0) {
627 out.writeAttr(SUMO_ATTR_ENDED, time2string(stop.ended));
628 }
629 out.closeTag();
630 }
631 // save upcoming stops
632 for (const MSStop& stop : myStops) {
633 stop.write(out);
634 }
635 // save parameters
637 for (MSDevice* dev : myDevices) {
638 dev->saveState(out);
639 }
640 for (const auto& item : myMoveReminders) {
641 item.first->saveReminderState(out, *this);
642 }
643 out.closeTag();
644}
645
646
647void
649 if (attrs.hasAttribute(SUMO_ATTR_POSITION)) {
650 throw ProcessError(TL("Error: Invalid vehicles in state (may be a micro state)!"));
651 }
652 int routeOffset;
653 bool stopped;
654 int pastStops;
655 int segIndex;
656 int queIndex;
657 std::istringstream bis(attrs.getString(SUMO_ATTR_STATE));
659 bis >> myDeparture;
660 bis >> routeOffset;
661 bis >> myDepartPos;
662 bis >> segIndex;
663 bis >> queIndex;
664 bis >> myEventTime;
665 bis >> myLastEntryTime;
666 bis >> myBlockTime;
667 bis >> stopped;
668 bis >> pastStops;
669 bis >> myWasJammed;
670 bis >> myEventIndex;
671 bis >> myUnqueuedEventTime;
672 myDepartPos /= 1000.; // was stored as mm
673
675 bool ok;
676 myArrivalPos = attrs.get<double>(SUMO_ATTR_ARRIVALPOS_RANDOMIZED, getID().c_str(), ok);
677 }
678
679 // load stops
680 myStops.clear();
682
683 if (hasDeparted()) {
684 myDeparture -= offset;
685 myEventTime -= offset;
686 myLastEntryTime -= offset;
687 myCurrEdge = myRoute->begin() + routeOffset;
688 // fix stops
689 while (pastStops > 0) {
690 for (const auto& rem : myMoveReminders) {
691 rem.first->notifyStopEnded();
692 }
693 myPastStops.push_back(myStops.front().pars);
694 myPastStops.back().routeIndex = (int)(myStops.front().edge - myRoute->begin());
695 myStops.pop_front();
696 pastStops--;
697 }
698 if (segIndex >= 0) {
700 while (seg->getIndex() != (int)segIndex) {
701 seg = seg->getNextSegment();
702 if (seg == nullptr) {
703 throw ProcessError(TLF("Unknown segment '%:%' for vehicle '%' in loaded state.", (*myCurrEdge)->getID(), segIndex, getID()));
704 }
705 }
706 setSegment(seg, queIndex);
707 if (queIndex == MESegment::PARKING_QUEUE) {
708 MSGlobals::gMesoNet->addLeaderCar(this, nullptr, true);
709 getCurrentEdge()->getLanes()[0]->addParking(this);
710 }
711 } else {
712 // on teleport
713 setSegment(nullptr, 0);
714 assert(myEventTime != SUMOTime_MIN);
715 MSGlobals::gMesoNet->addLeaderCar(this, nullptr, true);
716 }
717 // see MSBaseVehicle constructor
720 }
721 }
722 if (myBlockTime != SUMOTime_MAX) {
723 myBlockTime -= offset;
724 }
726 myUnqueuedEventTime -= offset;
727 }
728 std::istringstream dis(attrs.getString(SUMO_ATTR_DISTANCE));
730 if (stopped) {
731 myStops.front().startedFromState = true;
732 myStops.front().reached = true;
733 }
734}
735
736
737/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:299
#define TL(string)
Definition MsgHandler.h:316
#define TLF(string,...)
Definition MsgHandler.h:318
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
SUMOTime DELTA_T
Definition SUMOTime.cpp:39
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:107
#define STEPS2TIME(x)
Definition SUMOTime.h:58
#define SIMSTEP
Definition SUMOTime.h:69
#define SUMOTime_MAX
Definition SUMOTime.h:34
#define SUMOTime_MIN
Definition SUMOTime.h:35
const long long int VEHPARS_FORCE_REROUTE
const int STOP_ENDED_SET
const int STOP_STARTED_SET
@ LINKSTATE_ALLWAY_STOP
This is an uncontrolled, all-way stop link.
@ SUMO_ATTR_STARTED
@ SUMO_ATTR_ENDED
@ SUMO_ATTR_DISTANCE
@ SUMO_ATTR_ARRIVALPOS_RANDOMIZED
@ SUMO_ATTR_POSITION
@ SUMO_ATTR_STATE
The state of a link.
T MIN2(T a, T b)
Definition StdDefs.h:80
T MAX2(T a, T b)
Definition StdDefs.h:86
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
void addLeaderCar(MEVehicle *veh, MSLink *link, const bool fromState=false)
Adds the given car to the leading vehicles.
Definition MELoop.cpp:331
SUMOTime changeSegment(MEVehicle *veh, SUMOTime leaveTime, MESegment *const toSegment, MSMoveReminder::Notification reason, const bool ignoreLink=false) const
change to the next segment this handles combinations of the following cases: (ending / continuing rou...
Definition MELoop.cpp:130
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition MELoop.cpp:435
void removeLeaderCar(MEVehicle *v)
Removes the given car from the leading vehicles.
Definition MELoop.cpp:348
A single mesoscopic segment (cell)
Definition MESegment.h:50
double getVehicleMaxSpeed(const MEVehicle &veh, int queueIndex) const
Maximum vehicle speed for the given queue, accounting for internal junction segments.
int isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
static const int PARKING_QUEUE
Definition MESegment.h:53
SUMOTime getLinkPenalty(const MEVehicle *veh) const
Returns the penalty time for passing a link (if using gMesoTLSPenalty > 0 or gMesoMinorPenalty > 0)
MSLink * getLink(const MEVehicle *veh, bool tlsPenalty=false) const
Returns the link the given car will use when passing the next junction.
double getLength() const
Returns the length of the segment in meters.
Definition MESegment.h:282
const std::vector< MEVehicle * > & getQueue(int index) const
Returns the cars in the queue with the given index for visualization.
Definition MESegment.h:244
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition MESegment.h:405
void updateMesoPositions() const
Update interpolated positions for all vehicles on this segment.
@ PROCEED_NO
the vehicle must stay on the current segment
Definition MESegment.h:79
@ PROCEED_NO_STOP
vehicle want's to change to right lane
Definition MESegment.h:83
@ PROCEED_YES
the vehicle may proceed to the next segment
Definition MESegment.h:77
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
Definition MESegment.h:266
static bool isInvalid(const MESegment *segment)
whether the given segment is 0 or encodes vaporization
Definition MESegment.h:498
MESegment * getNextSegment() const
Returns the following segment on the same edge (0 if it is the last).
Definition MESegment.h:274
double getConservativeSpeed(SUMOTime &earliestArrival) const
Returns the vehicle's estimated speed taking into account delays.
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
double getAverageSpeed() const
Returns the vehicle's estimated average speed on the segment assuming no further delays.
double getAngle() const
Returns the vehicle's direction in degrees.
Definition MEVehicle.cpp:91
double getBackPositionOnLane(const MSLane *lane) const
Get the vehicle's position relative to the given lane.
Definition MEVehicle.cpp:72
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.
SUMOTime myEventTime
The (planned) time of leaving the segment (cell)
Definition MEVehicle.h:441
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
void updateDetectorForWriting(MSMoveReminder *rem, SUMOTime currentTime, SUMOTime exitTime)
Updates a single vehicle detector if present.
MEVehicle(SUMOVehicleParameter *pars, ConstMSRoutePtr route, MSVehicleType *type, const double speedFactor)
Constructor.
Definition MEVehicle.cpp:56
BaseInfluencer & getBaseInfluencer()
Returns the velocity/lane influencer.
double getCurrentStoppingTimeSeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
long long int myEventIndex
The index of the vehicle's event (orders events with the same time)
Definition MEVehicle.h:444
double estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle's estimated speed after driving across the link.
void processStop()
ends the current stop and performs loading/unloading
SUMOTime getWaitingTime(const bool accumulated=false) const
Returns the duration for which the vehicle was blocked.
Definition MEVehicle.h:347
bool hasArrived() const
Returns whether this vehicle has already arrived (reached the arrivalPosition on its final edge)
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
int myQueIndex
Index of the que the vehicle is in (important for multiqueue extension)
Definition MEVehicle.h:438
void updateDetectors(const SUMOTime currentTime, const SUMOTime exitTime, const bool isLeave, const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_JUNCTION)
Updates all vehicle detectors.
SUMOTime checkStop(SUMOTime time)
Returns until when to stop at the current segment and sets the information that the stop has been rea...
virtual bool isIdling() const
Returns whether the vehicle is trying to re-enter the net.
double myMesoPosition
The interpolated mesoscopic position on the current edge (-maxdouble when invalid)
Definition MEVehicle.h:459
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
Definition MEVehicle.h:318
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition MEVehicle.cpp:78
SUMOTime myLastEntryTime
The time the vehicle entered its current segment.
Definition MEVehicle.h:447
BaseInfluencer * myInfluencer
An instance of a velocity/lane influencing instance; built in "getInfluencer".
Definition MEVehicle.h:465
void setApproaching(MSLink *link)
registers vehicle with the given link
bool endTriggeredStop()
process triggered stops and return true if all stops on the current segment are completed
void saveState(OutputDevice &out)
Saves the states of a vehicle.
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition MEVehicle.h:266
const MSEdge * getCurrentEdge() const
Returns the edge the vehicle is currently at (possibly an internal edge)
MESegment * mySegment
The segment the vehicle is at.
Definition MEVehicle.h:435
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition MEVehicle.h:275
int getSegmentIndex() const
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset)
Loads the state of this vehicle from the given description.
virtual void setSegment(MESegment *s, int idx=0)
Sets the current segment the vehicle is at together with its que.
Definition MEVehicle.h:250
bool myWasJammed
Whether this vehicle was jammed on it's previous normal segment.
Definition MEVehicle.h:456
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
int mayProceed()
Returns whether the vehicle is allowed to pass the next junction, checks also for triggered stops.
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves its current segment.
Definition MEVehicle.h:218
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
SUMOTime myUnqueuedEventTime
The expected time of leaving the segment when following the leader at free-flow headway.
Definition MEVehicle.h:453
bool resumeFromStopping()
double getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
PositionVector getBoundingBox(double offset=0) const
get bounding rectangle
double getSlope() const
Returns the slope of the road at vehicle's position in degrees.
Definition MEVehicle.cpp:98
SUMOTime myBlockTime
The time at which the vehicle was blocked on its current segment.
Definition MEVehicle.h:450
double getRightSideOnEdge(const MSLane *) const
Get the vehicle's lateral position on the edge of the given lane (or its current edge if lane == 0)
The base class for microscopic and mesoscopic vehicles.
std::list< MSStop > myStops
The vehicle's list of stops.
void calculateArrivalParams(bool onInit)
(Re-)Calculates the arrival position and lane from the vehicle parameters
MoveReminderCont myMoveReminders
Currently relevant move reminders.
double myDepartPos
The real depart position.
std::vector< MSVehicleDevice * > myDevices
The devices this vehicle has.
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.
const MSVehicleType * myType
This vehicle's type.
double getLength() const
Returns the vehicle's length.
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.
ConstMSRoutePtr myRoute
This vehicle's route.
void addStops(const bool ignoreStopErrors, MSRouteIterator *searchStart=nullptr, bool addRouteStops=true)
Adds stops to the built vehicle.
SUMOTime myDeparture
The real departure time.
int getRoutePosition() const
return index of edge within route
bool myAmRegisteredAsWaiting
Whether this vehicle is registered as waiting for a person or container (for deadlock-recognition)
const SUMOVehicleParameter * myParameter
This vehicle's parameter.
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.
double myOdometer
A simple odometer to keep track of the length of the route already driven.
int getContainerNumber() const
Returns the number of containers.
A device which collects info on the vehicle trip (mainly on departure and arrival)
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks for waiting steps when the vehicle moves.
void cancelCurrentCustomers()
remove the persons the taxi is currently waiting for from reservations
A device which collects info on the vehicle trip (mainly on departure and arrival)
void updateStopTime(const SUMOTime time)
update stopping time for meso
void recordMesoParkingTimeLoss(SUMOTime waitingTime)
Abstract in-vehicle / in-person device.
Definition MSDevice.h:62
A road/street connecting two junctions.
Definition MSEdge.h:78
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:169
double getLength() const
return the length of the edge
Definition MSEdge.h:695
bool isInternal() const
return whether this edge is an internal edge
Definition MSEdge.h:270
void removeWaiting(const SUMOVehicle *vehicle) const
Removes a vehicle from the list of waiting vehicles.
Definition MSEdge.cpp:1543
static bool gMesoInterpolatePos
Definition MSGlobals.h:112
static bool gCheckRoutes
Definition MSGlobals.h:91
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition MSGlobals.h:115
static bool gSlopeCentered
whether to use a simplified slope computation (for compatibility with other simulations)
Definition MSGlobals.h:137
static bool gUseStopEnded
whether the simulation should replay previous stop times
Definition MSGlobals.h:133
Representation of a lane in the micro simulation.
Definition MSLane.h:84
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:1229
double interpolateLanePosToGeometryPos(double lanePos) const
Definition MSLane.h:555
virtual const PositionVector & getShape(bool) const
Definition MSLane.h:294
double getWidth() const
Returns the lane's width.
Definition MSLane.h:661
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition MSLane.h:561
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
@ NOTIFICATION_VAPORIZED_CALIBRATOR
The vehicle got removed by a calibrator.
@ NOTIFICATION_SEGMENT
The vehicle changes the segment (meso only)
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
@ NOTIFICATION_TELEPORT
The vehicle is being teleported.
void updateDetector(SUMOTrafficObject &veh, double entryPos, double leavePos, SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime, bool cleanUp)
The simulated network and simulation perfomer.
Definition MSNet.h:90
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:201
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition MSNet.cpp:1326
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:335
bool hasContainers() const
Returns whether containers are simulated.
Definition MSNet.h:436
bool hasPersons() const
Returns whether persons are simulated.
Definition MSNet.h:420
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:403
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1317
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
bool joinTriggered
whether coupling another vehicle (train) the vehicle continue
Definition MSStop.h:73
const MESegment * segment
The segment to stop at (mesosim only)
Definition MSStop.h:52
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
const SUMOVehicleParameter::Stop pars
The stop parameter.
Definition MSStop.h:65
static bool active()
Definition MSStopOut.h:55
void stopStarted(const SUMOVehicle *veh, int numPersons, int numContainers, SUMOTime time)
Definition MSStopOut.cpp:83
static MSStopOut * getInstance()
Definition MSStopOut.h:61
void stopEnded(const SUMOVehicle *veh, const MSStop &stop, bool simEnd=false)
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 ...
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...
The car-following model and parameter.
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
int getPersonCapacity() const
Get this vehicle type's person capacity.
double getLength() const
Get vehicle's length [m].
const std::string & getID() const
Returns the id.
Definition Named.h:73
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
void append(const PositionVector &v, double sameThreshold=2.0)
double rotationAtOffset(double pos) const
Returns the rotation 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)
PositionVector reverse() const
reverse position vector
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Encapsulated SAX-Attributes.
virtual std::string getString(int id, bool *isPresent=nullptr) const =0
Returns the string-value of the named (by its enum-value) attribute.
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.
Definition of vehicle stop (position and duration)
SUMOTime ended
the time at which this stop was ended
double endPos
The stopping position end.
Structure representing possible vehicle parameter.
std::vector< std::string > via
List of the via-edges the vehicle must visit.
long long int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
bool wasSet(long long int what) const
Returns whether the given parameter was set.
int arrivalEdge
(optional) The final edge within the route of the vehicle
static OutputDevice & writeParams(OutputDevice &device, const Parameterised &params)
write the parameters of the given object as param tags
#define M_PI
Definition odrSpiral.cpp:45