Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSTransportable.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/****************************************************************************/
20// The common superclass for modelling transportable objects like persons and containers
21/****************************************************************************/
22#include <config.h>
23
30#include <microsim/MSEdge.h>
31#include <microsim/MSLane.h>
32#include <microsim/MSNet.h>
43
45
46//#define DEBUG_PARKING
47
48// ===========================================================================
49// method definitions
50// ===========================================================================
52 SUMOTrafficObject(pars->id),
53 myParameter(pars), myVType(vtype), myPlan(plan),
54 myAmPerson(isPerson),
55 myNumericalID(myCurrentNumericalIndex++),
56 myRandomSeed(RandHelper::murmur3_32(pars->id, RandHelper::getSeed())) {
57 myStep = myPlan->begin();
58 // init devices
60 for (MSStage* const stage : * myPlan) {
61 stage->init(this);
62 }
63}
64
65
68 MSStageDriving* const stage = dynamic_cast<MSStageDriving*>(*myStep);
69 if (stage->getVehicle() != nullptr) {
70 stage->getVehicle()->removeTransportable(this);
71 } else if (stage->getOriginStop() != nullptr) {
72 stage->getOriginStop()->removeTransportable(this);
73 }
74 }
75 if (myPlan != nullptr) {
76 for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
77 delete *i;
78 }
79 delete myPlan;
80 myPlan = nullptr;
81 }
82 for (MSTransportableDevice* dev : myDevices) {
83 delete dev;
84 }
85 delete myParameter;
88 }
89}
90
93 return getEdge()->getLanes()[0]->getRNG();
94}
95
96int
98 return getEdge()->getLanes()[0]->getRNGIndex();
99}
100
101bool
102MSTransportable::proceed(MSNet* net, SUMOTime time, const bool vehicleArrived) {
103 MSStage* const prior = *myStep;
104 const std::string& error = prior->setArrived(net, this, time, vehicleArrived);
105 // must be done before increasing myStep to avoid invalid state for rendering
106 prior->getEdge()->removeTransportable(this);
107 myStep++;
108 if (error != "") {
109 throw ProcessError(error);
110 }
111 /* We need to check whether an access stage is needed (or maybe even two).
112 The general scheme is: If the prior stage ended at a stop and the next stage
113 starts at an edge which is not the one the stop is at, but the stop has an access to it
114 we need an access stage. The same is true if prior ends at an edge, the next stage
115 is allowed to start at any stop the edge has access to.
116 If we start at a stop or end at a stop no access is needed.
117 */
118 bool accessToStop = false;
120 accessToStop = checkAccess(prior);
121 } else if (prior->getStageType() == MSStageType::WAITING_FOR_DEPART) {
122 for (MSTransportableDevice* const dev : myDevices) {
123 dev->notifyEnter(*this, MSMoveReminder::NOTIFICATION_DEPARTED, nullptr);
124 }
125 }
126 if (!accessToStop && (myStep == myPlan->end()
127 || ((*myStep)->getStageType() != MSStageType::DRIVING
128 && (*myStep)->getStageType() != MSStageType::TRIP))) {
129 MSStoppingPlace* priorStop = prior->getStageType() == MSStageType::TRIP ? prior->getOriginStop() : prior->getDestinationStop();
130 // a trip might resolve to DRIVING so we would have to stay at the stop
131 // if a trip resolves to something else, this step will do stop removal
132 if (priorStop != nullptr) {
133 priorStop->removeTransportable(this);
134 }
135 }
136 if (myStep != myPlan->end()) {
137 if ((*myStep)->getStageType() == MSStageType::WALKING && (prior->getStageType() != MSStageType::ACCESS || prior->getDestination() != (*myStep)->getFromEdge())) {
138 checkAccess(prior, false);
139 } else if ((*myStep)->getStageType() == MSStageType::WAITING && prior->getStageType() == MSStageType::WAITING && prior->getDestination() != (*myStep)->getFromEdge()) {
140 checkAccess(prior, false);
141 }
142 (*myStep)->proceed(net, this, time, prior);
143 return true;
144 } else {
146 return false;
147 }
148}
149
150
151void
152MSTransportable::setID(const std::string& /*newID*/) {
153 throw ProcessError(TL("Changing a transportable ID is not permitted"));
154}
155
160
161void
163 (*myStep)->setDeparted(now);
164}
165
168 for (const MSStage* const stage : *myPlan) {
169 if (stage->getDeparted() >= 0) {
170 return stage->getDeparted();
171 }
172 }
173 return -1;
174}
175
176
177double
179 return (*myStep)->getEdgePos(MSNet::getInstance()->getCurrentTimeStep());
180}
181
182double
184 return getEdgePos() - getVehicleType().getLength();
185}
186
187int
189 return (*myStep)->getDirection();
190}
191
194 return (*myStep)->getPosition(MSNet::getInstance()->getCurrentTimeStep());
195}
196
197double
199 return (*myStep)->getAngle(MSNet::getInstance()->getCurrentTimeStep());
200}
201
202double
204 return STEPS2TIME((*myStep)->getWaitingTime());
205}
206
207double
209 return (*myStep)->getSpeed();
210}
211
212
213void
215 SUMOTime departure = myPlan->front()->getDeparted();
216 os.openTag(isPerson() ? "personinfo" : "containerinfo");
218 os.writeAttr(SUMO_ATTR_DEPART, departure >= 0 ? time2string(departure) : "-1");
220 if (isPerson()) {
222 }
223 SUMOTime duration = 0;
224 SUMOTime waitingTime = 0;
225 SUMOTime timeLoss = 0;
226 SUMOTime travelTime = 0;
227 bool durationOK = true;
228 bool waitingTimeOK = true;
229 bool timeLossOK = true;
230 bool travelTimeOK = true;
231 for (MSStage* const i : *myPlan) {
232 SUMOTime t = i->getDuration();
233 if (t != SUMOTime_MAX) {
234 duration += t;
235 } else {
236 durationOK = false;
237 }
238 t = i->getTotalWaitingTime();
239 if (t != SUMOTime_MAX) {
240 waitingTime += t;
241 } else {
242 waitingTimeOK = false;
243 }
244 t = i->getTimeLoss(this);
245 if (t != SUMOTime_MAX) {
246 timeLoss += t;
247 } else {
248 timeLossOK = false;
249 }
250 t = i->getTravelTime();
251 if (t != SUMOTime_MAX) {
252 travelTime += t;
253 } else {
254 travelTimeOK = false;
255 }
256 }
257 os.writeAttr(SUMO_ATTR_DURATION, durationOK ? time2string(duration) : "-1");
258 os.writeAttr(SUMO_ATTR_WAITINGTIME, waitingTimeOK ? time2string(waitingTime) : "-1");
259 os.writeAttr(SUMO_ATTR_TIMELOSS, timeLossOK ? time2string(timeLoss) : "-1");
260 os.writeAttr(SUMO_ATTR_TRAVELTIME, travelTimeOK ? time2string(travelTime) : "-1");
261 for (MSStage* const i : *myPlan) {
262 i->tripInfoOutput(os, this);
263 }
264 os.closeTag();
265}
266
267
268void
269MSTransportable::routeOutput(OutputDevice& os, const bool withRouteLength) const {
270 const std::string typeID = (
274 if (hasArrived()) {
275 os.writeAttr("arrival", time2string(MSNet::getInstance()->getCurrentTimeStep()));
276 }
277 const MSStage* previous = nullptr;
278 for (const MSStage* const stage : *myPlan) {
279 stage->routeOutput(myAmPerson, os, withRouteLength, previous);
280 previous = stage;
281 }
283 os.closeTag();
284 os.lf();
285}
286
287
288void
298
299
302 WRITE_WARNINGF(TL("Teleporting % '%'; waited too long, from edge '%', time=%."),
303 isPerson() ? "person" : "container", getID(), (*myStep)->getEdge()->getID(), time2string(step));
306 (*myStep)->abort(this);
307 if (!proceed(MSNet::getInstance(), step)) {
308 tc.erase(this);
309 }
310 return 0;
311}
312
313
314void
316 // myStep is invalidated upon modifying myPlan
317 const int stepIndex = (int)(myStep - myPlan->begin());
318 if (next < 0) {
319 myPlan->push_back(stage);
320 } else {
321 if (stepIndex + next > (int)myPlan->size()) {
322 throw ProcessError("invalid index '" + toString(next) + "' for inserting new stage into plan of '" + getID() + "'");
323 }
324 myPlan->insert(myPlan->begin() + stepIndex + next, stage);
325 }
326 myStep = myPlan->begin() + stepIndex;
327}
328
329
330void
331MSTransportable::removeStage(int next, bool stayInSim) {
332 assert(myStep + next < myPlan->end());
333 assert(next >= 0);
334 if (next > 0) {
335 // myStep is invalidated upon modifying myPlan
336 int stepIndex = (int)(myStep - myPlan->begin());
337 delete *(myStep + next);
338 myPlan->erase(myStep + next);
339 myStep = myPlan->begin() + stepIndex;
340 } else {
341 if (myStep + 1 == myPlan->end() && stayInSim) {
342 // stay in the simulation until the start of simStep to allow appending new stages (at the correct position)
343 appendStage(new MSStageWaiting(getEdge(), nullptr, 0, 0, getEdgePos(), "last stage removed", false));
344 } else if (myStep + 1 != myPlan->end()) {
345 (*(myStep + 1))->setOrigin(getEdge(), getEdge() == getFromEdge() ? (*myStep)->getOriginStop() : nullptr, getEdgePos());
346 }
347 (*myStep)->abort(this);
350 } else if (myPlan->front()->getDeparted() < 0) {
351 myPlan->front()->setDeparted(SIMSTEP);
352 }
353 }
354}
355
356
357void
359 for (MSTransportablePlan::const_iterator i = myStep; i != myPlan->end(); ++i) {
360 (*i)->setSpeed(speed);
361 }
363}
364
365
366bool
367MSTransportable::replaceRoute(ConstMSRoutePtr newRoute, const std::string& /* info */, bool /* onInit */, int /* offset */, bool /* addRouteStops */, bool /* removeStops */, std::string* /* msgReturn */) {
368 if (isPerson()) {
369 static_cast<MSPerson*>(this)->replaceWalk(newRoute->getEdges(), getPositionOnLane(), 0, 1);
370 return true;
371 }
372 return false;
373}
374
375
376bool
377MSTransportable::reroute(SUMOTime t, const std::string& /* info */, MSTransportableRouter& router, const bool /* onInit */, const bool /* withTaz */, const bool /* silent */, const MSEdge* /* sink */) {
379 if (trip == nullptr) {
380 // TODO this should be possible after factoring out MSStageTrip::reroute
381 return false;
382 }
383 if (getCurrentStage()->getVehicle() != nullptr) {
384 // TODO rerouting during a ride still needs to be implemented
385 return false;
386 }
387 // find the final stage of the trip
388 int tripEndOffset = -1;
389 for (int i = getNumRemainingStages() - 1; i >= 0; i--) {
390 if (getNextStage(i)->getTrip() == trip) {
391 tripEndOffset = i;
392 break;
393 }
394 }
395 std::vector<MSStage*> stages;
396 MSStageWaiting start(getEdge(), getCurrentStage()->getOriginStop(), -1, t, getEdgePos(), "start", true);
397 if (trip->reroute(t, router, this, &start, getEdge(), getRerouteDestination(), stages) == "") {
398 // check whether the new plan actually differs
399 while (tripEndOffset >= 0 && !stages.empty() && stages.back()->equals(*getNextStage(tripEndOffset))) {
400 delete stages.back();
401 stages.pop_back();
402 tripEndOffset--;
403 }
404 bool abortCurrent = true;
405 // check whether the future route of the current stage is identical to the route
406 if (!stages.empty() && stages.front()->isWalk() && getCurrentStage()->isWalk()) {
407 // TODO this check should be done for rides as well
408 MSStageMoving* s = static_cast<MSStageMoving*>(getCurrentStage());
409 int routeIndex = (int)(s->getRouteStep() - s->getRoute().begin());
410 ConstMSEdgeVector oldEdges = s->getEdges();
411 oldEdges.erase(oldEdges.begin(), oldEdges.begin() + routeIndex);
412 ConstMSEdgeVector newEdges = stages.front()->getEdges();
413 if (newEdges == oldEdges) {
414 delete stages.front();
415 stages.erase(stages.begin());
416 abortCurrent = false;
417 }
418 }
419 if (stages.empty()) {
420 return false;
421 }
422 // remove future stages of the trip
423 for (int i = tripEndOffset; i >= 1; i--) {
424 removeStage(i);
425 }
426 // insert new stages of the rerouting
427 int idx = 1;
428 for (MSStage* stage : stages) {
429 appendStage(stage, idx++);
430 }
431 if (abortCurrent) {
432 removeStage(0);
433 }
434 return true;
435 }
436 return false;
437}
438
439
440void
442 const SUMOVehicleClass oldVClass = myVType->getVehicleClass();
443 if (myVType->isVehicleSpecific()) {
445 }
446 if (isPerson()
447 && type->getVehicleClass() != oldVClass
448 && type->getVehicleClass() != SVC_PEDESTRIAN
450 WRITE_WARNINGF(TL("Person '%' receives type '%' which implicitly uses unsuitable vClass '%'."), getID(), type->getID(), toString(type->getVehicleClass()));
451 }
452 myVType = type;
453}
454
455
458 if (myVType->isVehicleSpecific()) {
459 return *const_cast<MSVehicleType*>(myVType);
460 }
462 replaceVehicleType(type);
463 return *type;
464}
465
466
469 PositionVector centerLine;
470 const Position p = getPosition();
471 const double angle = getAngle();
472 const double length = getVehicleType().getLength();
473 const Position back = p + Position(-cos(angle) * length, -sin(angle) * length);
474 centerLine.push_back(p);
475 centerLine.push_back(back);
476 centerLine.move2side(0.5 * getVehicleType().getWidth());
477 PositionVector result = centerLine;
478 centerLine.move2side(-getVehicleType().getWidth());
479 result.append(centerLine.reverse(), POSITION_EPS);
480 //std::cout << " transp=" << getID() << " p=" << p << " angle=" << GeomHelper::naviDegree(angle) << " back=" << back << " result=" << result << "\n";
481 return result;
482}
483
484
485std::string
486MSTransportable::getStageSummary(int stageIndex) const {
487 assert(stageIndex < (int)myPlan->size());
488 assert(stageIndex >= 0);
489 return (*myPlan)[stageIndex]->getStageSummary(myAmPerson);
490}
491
492
493const std::set<SUMOTrafficObject::NumericalID>
495 std::set<SUMOTrafficObject::NumericalID> result;
496 for (auto step = myStep; step != myPlan->end(); ++step) {
497 for (const MSEdge* const e : (*step)->getEdges()) {
498 result.insert(e->getNumericalID());
499 }
500 }
501 return result;
502}
503
504
505bool
507 return myStep == myPlan->end();
508}
509
510bool
512 return myPlan->size() > 0 && (myPlan->front()->getDeparted() >= 0 || myStep > myPlan->begin());
513}
514
515
516void
518 // check whether the transportable was riding to the orignal stop
519 // @note: parkingArea can currently not be set as myDestinationStop so we
520 // check for stops on the edge instead
521#ifdef DEBUG_PARKING
522 std::cout << SIMTIME << " person=" << getID() << " rerouteParkingArea orig=" << orig->getID() << " replacement=" << replacement->getID() << "\n";
523#endif
525 if (!myAmPerson) {
526 WRITE_WARNING(TL("parkingAreaReroute not supported for containers"));
527 return;
528 }
529 if (getDestination() == &orig->getLane().getEdge()) {
530 MSStageDriving* const stage = dynamic_cast<MSStageDriving*>(*myStep);
531 assert(stage != 0);
532 assert(stage->getVehicle() != 0);
533 // adapt plan
534 stage->setDestination(&replacement->getLane().getEdge(), replacement);
535 stage->setArrivalPos((replacement->getBeginLanePosition() + replacement->getEndLanePosition()) / 2);
536#ifdef DEBUG_PARKING
537 std::cout << " set ride destination\n";
538#endif
539 if (myStep + 1 == myPlan->end()) {
540 return;
541 }
542 // if the next step is a walk, adapt the route
543 MSStage* nextStage = *(myStep + 1);
544 if (nextStage->getStageType() == MSStageType::TRIP) {
545 dynamic_cast<MSStageTrip*>(nextStage)->setOrigin(stage->getDestination(), stage->getDestinationStop(), stage->getArrivalPos());
546#ifdef DEBUG_PARKING
547 std::cout << " set subsequent trip origin\n";
548#endif
549 } else if (nextStage->getStageType() == MSStageType::WALKING) {
550#ifdef DEBUG_PARKING
551 std::cout << " replace subsequent walk with a trip\n";
552#endif
553 MSStageTrip* newStage = new MSStageTrip(stage->getDestination(), nullptr, nextStage->getDestination(),
554 nextStage->getDestinationStop(), -1, 0, "", -1, 1, getID(), 0, true, nextStage->getArrivalPos());
555 removeStage(1);
556 appendStage(newStage, 1);
557 } else if (nextStage->getStageType() == MSStageType::WAITING) {
558#ifdef DEBUG_PARKING
559 std::cout << " add subsequent walk to reach stop\n";
560 std::cout << " arrivalPos=" << nextStage->getArrivalPos() << "\n";
561#endif
562 MSStageTrip* newStage = new MSStageTrip(stage->getDestination(), nullptr, nextStage->getDestination(),
563 nextStage->getDestinationStop(), -1, 0, "", -1, 1, getID(), 0, true, nextStage->getArrivalPos());
564 appendStage(newStage, 1);
565 }
566 // if the plan contains another ride with the same vehicle from the same
567 // parking area, adapt the preceeding walk to end at the replacement
568 for (auto it = myStep + 2; it != myPlan->end(); it++) {
569 MSStage* const futureStage = *it;
570 MSStage* const prevStage = *(it - 1);
571 if (futureStage->getStageType() == MSStageType::DRIVING) {
572 MSStageDriving* const ds = static_cast<MSStageDriving*>(futureStage);
573 // ride origin is set implicitly from the walk destination
574 ds->setOrigin(nullptr, nullptr, -1);
575 if (ds->getLines() == stage->getLines()
576 && prevStage->getDestination() == &orig->getLane().getEdge()) {
577 if (prevStage->getStageType() == MSStageType::TRIP) {
578 dynamic_cast<MSStageTrip*>(prevStage)->setDestination(stage->getDestination(), replacement);
579#ifdef DEBUG_PARKING
580 std::cout << " replace later trip before ride (" << (it - myPlan->begin()) << ")\n";
581#endif
582 } else if (prevStage->getStageType() == MSStageType::WALKING) {
583#ifdef DEBUG_PARKING
584 std::cout << " replace later walk before ride (" << (it - myPlan->begin()) << ")\n";
585#endif
586 MSStageTrip* newStage = new MSStageTrip(prevStage->getFromEdge(), nullptr, stage->getDestination(),
587 replacement, -1, 0, "", -1, 1, getID(), 0, true, stage->getArrivalPos());
588 int prevStageRelIndex = (int)(it - 1 - myStep);
589 removeStage(prevStageRelIndex);
590 appendStage(newStage, prevStageRelIndex);
591 }
592 break;
593 }
594 }
595 }
596 }
597}
598
599
601MSTransportable::getDevice(const std::type_info& type) const {
602 for (MSTransportableDevice* const dev : myDevices) {
603 if (typeid(*dev) == type) {
604 return dev;
605 }
606 }
607 return nullptr;
608}
609
610
611void
612MSTransportable::setJunctionModelParameter(const std::string& key, const std::string& value) {
615 const_cast<SUMOVehicleParameter&>(getParameter()).setParameter(key, value);
616 // checked in MSLink::ignoreFoe
617 } else {
618 throw InvalidArgument(getObjectType() + " '" + getID() + "' does not support junctionModel parameter '" + key + "'");
619 }
620}
621
622
623double
625 const MSEdge* edge = getEdge();
626 const double ep = getEdgePos();
627 const double gp = edge->getLanes()[0]->interpolateLanePosToGeometryPos(ep);
628 return edge->getLanes()[0]->getShape().slopeDegreeAtOffset(gp);
629}
630
631
633MSTransportable::getWaitingTime(const bool /* accumulated */) const {
634 return (*myStep)->getWaitingTime();
635}
636
637
638double
640 return MIN2(getVehicleType().getMaxSpeed(), getVehicleType().getDesiredMaxSpeed() * getChosenSpeedFactor());
641}
642
643
648
649
650int
655
656void
658 // this saves lots of departParameters which are only needed for transportables that did not yet depart
659 // the parameters may hold the name of a vTypeDistribution but we are interested in the actual type
660 const SUMOTime desiredDepart = myParameter->depart;
661 if (myPlan->front()->getDeparted() >= 0) {
662 // this is only relevant in the context of delayed departure (max-num-persons)
663 const_cast<SUMOVehicleParameter*>(myParameter)->depart = myPlan->front()->getDeparted();
664 }
666 const_cast<SUMOVehicleParameter*>(myParameter)->depart = desiredDepart;
671 }
672 int stepIdx = (int)(myStep - myPlan->begin());
673 for (auto it = myPlan->begin(); it != myStep; ++it) {
674 const MSStageType st = (*it)->getStageType();
675 if (st == MSStageType::TRIP || st == MSStageType::ACCESS) {
676 stepIdx--;
677 }
678 }
679 std::ostringstream state;
680 state << myParameter->parametersSet << " " << stepIdx;
681 (*myStep)->saveState(state);
682 out.writeAttr(SUMO_ATTR_STATE, state.str());
683 const MSStage* previous = nullptr;
684 for (const MSStage* const stage : *myPlan) {
685 stage->routeOutput(myAmPerson, out, false, previous);
686 previous = stage;
687 }
688 out.closeTag();
689}
690
691
692void
693MSTransportable::loadState(const std::string& state) {
694 std::istringstream iss(state);
695 int step;
696 iss >> myParameter->parametersSet >> step;
697 myPlan->front()->setDeparted(myParameter->depart);
698 myStep = myPlan->begin() + step;
699 (*myStep)->loadState(this, iss);
700}
701
702
703/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:74
MSStageType
Definition MSStage.h:55
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:287
#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
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:55
#define SIMSTEP
Definition SUMOTime.h:61
#define SUMOTime_MAX
Definition SUMOTime.h:34
#define SIMTIME
Definition SUMOTime.h:62
const long long int VTYPEPARS_VEHICLECLASS_SET
const std::string DEFAULT_PEDTYPE_ID
const std::string DEFAULT_CONTAINERTYPE_ID
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_PEDESTRIAN
pedestrian
const long long int VEHPARS_JUNCTIONMODEL_PARAMS_SET
const long long int VEHPARS_SPEEDFACTOR_SET
@ SUMO_TAG_CONTAINER
@ SUMO_TAG_PERSON
@ SUMO_ATTR_DEPART
@ SUMO_ATTR_WAITINGTIME
@ SUMO_ATTR_JM_IGNORE_IDS
@ SUMO_ATTR_TRAVELTIME
@ SUMO_ATTR_JM_IGNORE_TYPES
@ SUMO_ATTR_TIMELOSS
@ SUMO_ATTR_SPEEDFACTOR
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ID
@ SUMO_ATTR_DURATION
@ SUMO_ATTR_STATE
The state of a link.
int gPrecision
the precision for floating point outputs
Definition StdDefs.cpp:27
int gPrecisionRandom
Definition StdDefs.cpp:30
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:46
Abstract in-vehicle / in-person device.
Definition MSDevice.h:62
static void buildTransportableDevices(MSTransportable &p, std::vector< MSTransportableDevice * > &into)
Build devices for the given person, if needed.
Definition MSDevice.cpp:139
A road/street connecting two junctions.
Definition MSEdge.h:77
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:168
virtual void removeTransportable(MSTransportable *t) const
Definition MSEdge.cpp:1233
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
Representation of a lane in the micro simulation.
Definition MSLane.h:84
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:769
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
The simulated network and simulation perfomer.
Definition MSNet.h:89
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:187
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition MSNet.h:485
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition MSNet.cpp:1266
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:334
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:392
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1257
SUMOVehicle * getVehicle() const
Current vehicle in which the transportable is driving (or nullptr)
void setOrigin(const MSEdge *origin, MSStoppingPlace *originStop, double departPos)
change origin for parking area rerouting
const std::set< std::string > & getLines() const
MSStoppingPlace * getOriginStop() const
returns the origin stop (if any). only needed for MSStageTrip
double getArrivalPos() const
return default value for undefined arrivalPos
const MSEdge * getDestination() const
returns the destination edge
Definition MSStage.cpp:65
virtual const MSEdge * getFromEdge() const
Definition MSStage.cpp:77
MSStageTrip * getTrip() const
Definition MSStage.h:283
virtual double getArrivalPos() const
Definition MSStage.h:97
virtual MSStoppingPlace * getOriginStop() const
returns the origin stop (if any). only needed for MSStageTrip
Definition MSStage.h:93
virtual const std::string setArrived(MSNet *net, MSTransportable *transportable, SUMOTime now, const bool vehicleArrived)
logs end of the step
Definition MSStage.cpp:160
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
Definition MSStage.h:88
MSStageType getStageType() const
Definition MSStage.h:138
void setArrivalPos(double arrivalPos)
Definition MSStage.h:108
void setDestination(const MSEdge *newDestination, MSStoppingPlace *newDestStop)
Definition MSStage.cpp:188
virtual void routeOutput(const bool isPerson, OutputDevice &os, const bool withRouteLength, const MSStage *const previous) const =0
Called on writing vehroute output.
virtual const MSEdge * getEdge() const
Returns the current edge.
Definition MSStage.cpp:71
ConstMSEdgeVector getEdges() const
the edges of the current stage
const std::vector< const MSEdge * > & getRoute() const
const std::vector< constMSEdge * >::iterator getRouteStep() const
const std::string reroute(const SUMOTime time, MSTransportableRouter &router, MSTransportable *const transportable, MSStage *previous, const MSEdge *origin, const MSEdge *destination, std::vector< MSStage * > &stages)
A lane area vehicles can halt at.
double getBeginLanePosition() const
Returns the begin position of this stop.
double getEndLanePosition() const
Returns the end position of this stop.
void removeTransportable(const MSTransportable *p)
Removes a transportable from this stop.
const MSLane & getLane() const
Returns the lane this stop is located at.
void registerTeleportAbortWait()
register a teleport after aborting a long wait
virtual void erase(MSTransportable *transportable)
removes a single transportable
Abstract in-person device.
const MSEdge * getFromEdge() const
Returns the departure edge.
virtual double getChosenSpeedFactor() const override
the current speed factor of the transportable (where applicable)
bool isContainer() const override
Whether it is a container.
bool replaceRoute(ConstMSRoutePtr route, const std::string &info, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true, std::string *msgReturn=nullptr) override
Replaces the current route by the given one.
virtual double getEdgePos() const
Return the position on the edge.
bool hasDeparted() const
return whether the transportable has started its plan
double getPositionOnLane() const override
Get the object's position along the lane.
static NumericalID myCurrentNumericalIndex
double getBackPositionOnLane(const MSLane *lane) const override
Get the object's back position along the given lane.
const std::set< NumericalID > getUpcomingEdgeIDs() const override
returns the numerical IDs of edges to be used (possibly of future stages)
virtual double getSpeed() const override
the current speed of the transportable
void replaceVehicleType(const MSVehicleType *type) override
Replaces the current vehicle type by the one given.
SUMOTime getDeparture() const
logs depart time of the current stage
const MSEdge * getDestination() const
Returns the current destination.
void setAbortWaiting(const SUMOTime timeout)
MSStage * getNextStage(int offset) const
Return the next (or previous) stage denoted by the offset.
void routeOutput(OutputDevice &os, const bool withRouteLength) const
Called on writing vehroute output.
void setJunctionModelParameter(const std::string &key, const std::string &value)
set individual junction model paramete (not type related)
int getNumRemainingStages() const
Return the number of remaining stages (including the current)
PositionVector getBoundingBox() const
return the bounding box of the person
const bool myAmPerson
virtual bool checkAccess(const MSStage *const prior, const bool waitAtStop=true)
SUMOTime abortStage(SUMOTime step)
Abort current stage (used for aborting waiting for a vehicle)
std::string getStageSummary(int stageIndex) const
return textual summary for the given stage
const MSVehicleType * myVType
This transportable's type. (mainly used for drawing related information Note sure if it is really nec...
MSStage * getCurrentStage() const
Return the current stage.
SumoRNG * getRNG() const override
returns the associated RNG
void setDeparted(SUMOTime now)
logs depart time of the current stage
void setSpeed(double speed)
set the speed for all present and future (walking) stages and modify the vType so that stages added l...
virtual bool proceed(MSNet *net, SUMOTime time, const bool vehicleArrived=false)
SUMOVehicleClass getVClass() const override
Returns the object's access class.
double getMaxSpeed() const override
Returns the maximum speed (the minimum of desired and physical maximum speed)
MSTransportablePlan::iterator myStep
the iterator over the route
MSTransportablePlan * myPlan
the plan of the transportable
void removeStage(int next, bool stayInSim=true)
removes the nth next stage
SUMOVehicle * getVehicle() const
The vehicle associated with this transportable.
bool isPerson() const override
Whether it is a person.
virtual Position getPosition() const
Return the Network coordinate of the transportable.
const SUMOVehicleParameter * myParameter
the plan of the transportable
void saveState(OutputDevice &out)
Saves the current state into the given stream.
const MSEdge * getRerouteDestination() const override
Returns the end point for reroutes (usually the last edge of the route)
MSDevice * getDevice(const std::type_info &type) const override
Returns a device of the given type if it exists or nullptr if not.
virtual ~MSTransportable()
destructor
SUMOTime getWaitingTime(const bool accumulated=false) const override
MSStageType getCurrentStageType() const
the current stage type of the transportable
int getRNGIndex() const override
returns the index of the associated RNG
void rerouteParkingArea(MSStoppingPlace *orig, MSStoppingPlace *replacement)
adapt plan when the vehicle reroutes and now stops at replacement instead of orig
std::string getObjectType()
const SUMOVehicleParameter & getParameter() const override
Returns the vehicle's parameter (including departure definition)
void loadState(const std::string &state)
Reconstructs the current state.
std::vector< MSTransportableDevice * > myDevices
The devices this transportable has.
virtual double getWaitingSeconds() const
the time this transportable spent waiting in seconds
MSTransportable(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportablePlan *plan, const bool isPerson)
constructor
const MSVehicleType & getVehicleType() const override
Returns the object's "vehicle" type.
bool reroute(SUMOTime t, const std::string &info, MSTransportableRouter &router, const bool onInit=false, const bool withTaz=false, const bool silent=false, const MSEdge *sink=nullptr)
void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
virtual int getRoutingMode() const override
return routing mode (configures router choice but also handling of transient permission changes)
virtual double getAngle() const override
return the current angle of the transportable
void appendStage(MSStage *stage, int next=-1)
Appends the given stage to the current plan.
void setID(const std::string &newID) override
set the id (inherited from Named but forbidden for transportables)
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
const MSEdge * getEdge() const override
Returns the current edge.
virtual int getDirection() const
Return the movement directon on the edge.
double getSlope() const override
Returns the slope of the road at object's position in degrees.
std::vector< MSStage * > MSTransportablePlan
the structure holding the plan of a transportable
WrappingCommand< MSTransportable > * myAbortCommand
bool hasArrived() const override
return whether the person has reached the end of its plan
SUMOTime getDesiredDepart() const
Returns the desired departure time.
void removeVType(const MSVehicleType *vehType)
The car-following model and parameter.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
const std::string & getID() const
Returns the name of the vehicle type.
void setMaxSpeed(const double &maxSpeed)
Set a new value for this type's maximum speed.
bool isVehicleSpecific() const
Returns whether this type belongs to a single vehicle only (was modified)
double getLength() const
Get vehicle's length [m].
const SUMOVTypeParameter & getParameter() const
MSVehicleType * buildSingularType(const std::string &id) const
Duplicates the microsim vehicle type giving the newly created type the given id, marking it as vehicl...
const std::string & getID() const
Returns the id.
Definition Named.h:74
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
void lf()
writes a line feed if applicable
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
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
A list of positions.
void append(const PositionVector &v, double sameThreshold=2.0)
void move2side(double amount, double maxExtension=100)
move position vector to side using certain amount
PositionVector reverse() const
reverse position vector
Utility functions for using a global, resetable random number generator.
Definition RandHelper.h:133
Representation of a vehicle, person, or container.
long long int NumericalID
bool wasSet(long long int what) const
Returns whether the given parameter was set.
virtual void removeTransportable(MSTransportable *t)=0
removes a person or container
Structure representing possible vehicle parameter.
long long int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
void write(OutputDevice &dev, const OptionsCont &oc, const SumoXMLTag altTag=SUMO_TAG_VEHICLE, const std::string &typeID="") const
Writes the parameters as a beginning element.
bool wasSet(long long int what) const
Returns whether the given parameter was set.
A wrapper for a Command function.
void deschedule()
Marks this Command as being descheduled.
TRACI_CONST int ROUTING_MODE_DEFAULT