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
31#include <microsim/MSEdge.h>
32#include <microsim/MSLane.h>
33#include <microsim/MSNet.h>
44
46
47//#define DEBUG_PARKING
48
49// ===========================================================================
50// method definitions
51// ===========================================================================
53 SUMOTrafficObject(pars->id),
54 myParameter(pars), myVType(vtype), myPlan(plan),
55 myAmPerson(isPerson),
56 myNumericalID(myCurrentNumericalIndex++),
57 myRandomSeed(RandHelper::murmur3_32(pars->id, RandHelper::getSeed())) {
58 myStep = myPlan->begin();
59 // init devices
61 for (MSStage* const stage : * myPlan) {
62 stage->init(this);
63 }
64}
65
66
69 MSStageDriving* const stage = dynamic_cast<MSStageDriving*>(*myStep);
70 if (stage->getVehicle() != nullptr) {
71 stage->getVehicle()->removeTransportable(this);
72 } else if (stage->getOriginStop() != nullptr) {
73 stage->getOriginStop()->removeTransportable(this);
74 }
75 }
76 if (myPlan != nullptr) {
77 for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
78 delete *i;
79 }
80 delete myPlan;
81 myPlan = nullptr;
82 }
83 for (MSTransportableDevice* dev : myDevices) {
84 delete dev;
85 }
86 delete myParameter;
89 }
90}
91
94 return getEdge()->getLanes()[0]->getRNG();
95}
96
97int
99 const std::vector<MSLane*>& lanes = getEdge()->getLanes();
100 return lanes.empty() ? 0 : lanes[0]->getRNGIndex();
101}
102
103bool
104MSTransportable::proceed(MSNet* net, SUMOTime time, const bool vehicleArrived) {
105 MSStage* const prior = *myStep;
106 const std::string& error = prior->setArrived(net, this, time, vehicleArrived);
107 // must be done before increasing myStep to avoid invalid state for rendering
108 prior->getEdge()->removeTransportable(this);
109 myStep++;
110 if (error != "") {
111 throw ProcessError(error);
112 }
113 /* We need to check whether an access stage is needed (or maybe even two).
114 The general scheme is: If the prior stage ended at a stop and the next stage
115 starts at an edge which is not the one the stop is at, but the stop has an access to it
116 we need an access stage. The same is true if prior ends at an edge, the next stage
117 is allowed to start at any stop the edge has access to.
118 If we start at a stop or end at a stop no access is needed.
119 */
120 bool accessToStop = false;
122 accessToStop = checkAccess(prior);
123 } else if (prior->getStageType() == MSStageType::WAITING_FOR_DEPART) {
124 for (MSTransportableDevice* const dev : myDevices) {
125 dev->notifyEnter(*this, MSMoveReminder::NOTIFICATION_DEPARTED, nullptr);
126 }
127 }
128 if (!accessToStop && (myStep == myPlan->end()
129 || ((*myStep)->getStageType() != MSStageType::DRIVING
130 && (*myStep)->getStageType() != MSStageType::TRIP))) {
131 MSStoppingPlace* priorStop = prior->getStageType() == MSStageType::TRIP ? prior->getOriginStop() : prior->getDestinationStop();
132 // a trip might resolve to DRIVING so we would have to stay at the stop
133 // if a trip resolves to something else, this step will do stop removal
134 if (priorStop != nullptr) {
135 priorStop->removeTransportable(this);
136 }
137 }
139 if (myStep != myPlan->end()) {
140 if ((*myStep)->getStageType() == MSStageType::WALKING && (prior->getStageType() != MSStageType::ACCESS || prior->getDestination() != (*myStep)->getFromEdge())) {
141 checkAccess(prior, false);
142 } else if ((*myStep)->getStageType() == MSStageType::WAITING && prior->getStageType() == MSStageType::WAITING && prior->getDestination() != (*myStep)->getFromEdge()) {
143 checkAccess(prior, false);
144 }
145 if ((*myStep)->proceed(net, this, time, prior)) {
146 return true;
147 } else {
148 // some problem was encountered
149 tc.addArrived();
150 return false;
151 }
152 } else {
153 tc.addArrived();
154 return false;
155 }
156}
157
158
159void
160MSTransportable::setID(const std::string& /*newID*/) {
161 throw ProcessError(TL("Changing a transportable ID is not permitted"));
162}
163
168
169void
171 (*myStep)->setDeparted(now);
172}
173
176 for (const MSStage* const stage : *myPlan) {
177 if (stage->getDeparted() >= 0) {
178 return stage->getDeparted();
179 }
180 }
181 return -1;
182}
183
184const MSEdge*
186 const MSLane* lane = getLane();
187 return lane == nullptr ? getEdge() : &lane->getEdge();
188}
189
190double
192 return (*myStep)->getEdgePos(MSNet::getInstance()->getCurrentTimeStep());
193}
194
195double
197 return getEdgePos() - getVehicleType().getLength();
198}
199
200int
202 return (*myStep)->getDirection();
203}
204
207 return (*myStep)->getPosition(MSNet::getInstance()->getCurrentTimeStep());
208}
209
210double
212 return (*myStep)->getAngle(MSNet::getInstance()->getCurrentTimeStep());
213}
214
215double
217 return STEPS2TIME((*myStep)->getWaitingTime());
218}
219
220double
222 return (*myStep)->getSpeed();
223}
224
225
226void
228 SUMOTime departure = myPlan->front()->getDeparted();
229 os.openTag(isPerson() ? "personinfo" : "containerinfo");
231 os.writeAttr(SUMO_ATTR_DEPART, departure >= 0 ? time2string(departure) : "-1");
233 if (isPerson()) {
235 }
236 SUMOTime duration = 0;
237 SUMOTime waitingTime = 0;
238 SUMOTime timeLoss = 0;
239 SUMOTime travelTime = 0;
240 bool durationOK = true;
241 bool waitingTimeOK = true;
242 bool timeLossOK = true;
243 bool travelTimeOK = true;
244 for (MSStage* const i : *myPlan) {
245 SUMOTime t = i->getDuration();
246 if (t != SUMOTime_MAX) {
247 duration += t;
248 } else {
249 durationOK = false;
250 }
251 t = i->getTotalWaitingTime();
252 if (t != SUMOTime_MAX) {
253 waitingTime += t;
254 } else {
255 waitingTimeOK = false;
256 }
257 t = i->getTimeLoss(this);
258 if (t != SUMOTime_MAX) {
259 timeLoss += t;
260 } else {
261 timeLossOK = false;
262 }
263 t = i->getTravelTime();
264 if (t != SUMOTime_MAX) {
265 travelTime += t;
266 } else {
267 travelTimeOK = false;
268 }
269 }
270 os.writeAttr(SUMO_ATTR_DURATION, durationOK ? time2string(duration) : "-1");
271 os.writeAttr(SUMO_ATTR_WAITINGTIME, waitingTimeOK ? time2string(waitingTime) : "-1");
272 os.writeAttr(SUMO_ATTR_TIMELOSS, timeLossOK ? time2string(timeLoss) : "-1");
273 os.writeAttr(SUMO_ATTR_TRAVELTIME, travelTimeOK ? time2string(travelTime) : "-1");
274 for (MSStage* const i : *myPlan) {
275 i->tripInfoOutput(os, this);
276 }
277 os.closeTag();
278}
279
280
281void
282MSTransportable::routeOutput(OutputDevice& os, const bool withRouteLength) const {
283 const std::string typeID = (
287 if (hasArrived()) {
288 os.writeAttr("arrival", time2string(MSNet::getInstance()->getCurrentTimeStep()));
289 }
290 const MSStage* previous = nullptr;
291 const bool withTiming = OptionsCont::getOptions().getBool("vehroute-output.exit-times");
292 for (const MSStage* const stage : *myPlan) {
293 stage->routeOutput(myAmPerson, os, withRouteLength, previous, withTiming);
294 previous = stage;
295 }
297 os.closeTag();
298 os.lf();
299}
300
301
302void
312
313
316 WRITE_WARNINGF(TL("Teleporting % '%'; waited too long, from edge '%', time=%."),
317 isPerson() ? "person" : "container", getID(), (*myStep)->getEdge()->getID(), time2string(step));
320 (*myStep)->abort(this);
321 if (!proceed(MSNet::getInstance(), step)) {
322 tc.erase(this);
323 }
324 return 0;
325}
326
327
328void
330 // myStep is invalidated upon modifying myPlan
331 const int stepIndex = (int)(myStep - myPlan->begin());
332 if (next < 0) {
333 myPlan->push_back(stage);
334 } else {
335 if (stepIndex + next > (int)myPlan->size()) {
336 throw ProcessError("invalid index '" + toString(next) + "' for inserting new stage into plan of '" + getID() + "'");
337 }
338 myPlan->insert(myPlan->begin() + stepIndex + next, stage);
339 }
340 myStep = myPlan->begin() + stepIndex;
341}
342
343
344void
345MSTransportable::removeStage(int next, bool stayInSim) {
346 assert(myStep + next < myPlan->end());
347 assert(next >= 0);
348 if (next > 0) {
349 // myStep is invalidated upon modifying myPlan
350 int stepIndex = (int)(myStep - myPlan->begin());
351 delete *(myStep + next);
352 myPlan->erase(myStep + next);
353 myStep = myPlan->begin() + stepIndex;
354 } else {
355 if (myStep + 1 == myPlan->end() && stayInSim) {
356 // stay in the simulation until the start of simStep to allow appending new stages (at the correct position)
357 appendStage(new MSStageWaiting(getEdge(), nullptr, 0, 0, getEdgePos(), "last stage removed", false));
358 } else if (myStep + 1 != myPlan->end()) {
359 (*(myStep + 1))->setOrigin(getEdge(), getEdge() == getFromEdge() ? (*myStep)->getOriginStop() : nullptr, getEdgePos());
360 }
361 (*myStep)->abort(this);
364 } else if (myPlan->front()->getDeparted() < 0) {
365 myPlan->front()->setDeparted(SIMSTEP);
366 }
367 }
368}
369
370
371void
373 for (MSTransportablePlan::const_iterator i = myStep; i != myPlan->end(); ++i) {
374 (*i)->setSpeed(speed);
375 }
377}
378
379
380bool
381MSTransportable::replaceRoute(ConstMSRoutePtr newRoute, const std::string& /* info */, bool /* onInit */, int /* offset */, bool /* addRouteStops */, bool /* removeStops */, std::string* /* msgReturn */) {
382 if (isPerson()) {
383 static_cast<MSPerson*>(this)->replaceWalk(newRoute->getEdges(), getPositionOnLane(), 0, 1);
384 return true;
385 }
386 return false;
387}
388
389
390bool
391MSTransportable::reroute(SUMOTime t, const std::string& /* info */, MSTransportableRouter& router, const bool /* onInit */, const bool /* withTaz */, const bool /* silent */, const MSEdge* /* sink */) {
393 if (trip == nullptr) {
394 // TODO this should be possible after factoring out MSStageTrip::reroute
395 return false;
396 }
397 if (getCurrentStage()->getVehicle() != nullptr) {
398 // TODO rerouting during a ride still needs to be implemented
399 return false;
400 }
401 // find the final stage of the trip
402 int tripEndOffset = -1;
403 for (int i = getNumRemainingStages() - 1; i >= 0; i--) {
404 if (getNextStage(i)->getTrip() == trip) {
405 tripEndOffset = i;
406 break;
407 }
408 }
409 std::vector<MSStage*> stages;
410 MSStageWaiting start(getEdge(), getCurrentStage()->getOriginStop(), -1, t, getEdgePos(), "start", true);
411 if (trip->reroute(t, router, this, &start, getEdge(), getRerouteDestination(), stages) == "") {
412 // check whether the new plan actually differs
413 while (tripEndOffset >= 0 && !stages.empty() && stages.back()->equals(*getNextStage(tripEndOffset))) {
414 delete stages.back();
415 stages.pop_back();
416 tripEndOffset--;
417 }
418 bool abortCurrent = true;
419 // check whether the future route of the current stage is identical to the route
420 if (!stages.empty() && stages.front()->isWalk() && getCurrentStage()->isWalk()) {
421 // TODO this check should be done for rides as well
422 MSStageMoving* s = static_cast<MSStageMoving*>(getCurrentStage());
423 int routeIndex = (int)(s->getRouteStep() - s->getRoute().begin());
424 ConstMSEdgeVector oldEdges = s->getEdges();
425 oldEdges.erase(oldEdges.begin(), oldEdges.begin() + routeIndex);
426 ConstMSEdgeVector newEdges = stages.front()->getEdges();
427 if (newEdges == oldEdges) {
428 delete stages.front();
429 stages.erase(stages.begin());
430 abortCurrent = false;
431 }
432 }
433 if (stages.empty()) {
434 return false;
435 }
436 // remove future stages of the trip
437 for (int i = tripEndOffset; i >= 1; i--) {
438 removeStage(i);
439 }
440 // insert new stages of the rerouting
441 int idx = 1;
442 for (MSStage* stage : stages) {
443 appendStage(stage, idx++);
444 }
445 if (abortCurrent) {
446 removeStage(0);
447 }
448 return true;
449 }
450 return false;
451}
452
453
454void
456 const SUMOVehicleClass oldVClass = myVType->getVehicleClass();
457 if (myVType->isVehicleSpecific()) {
459 }
460 if (isPerson()
461 && type->getVehicleClass() != oldVClass
462 && type->getVehicleClass() != SVC_PEDESTRIAN
464 WRITE_WARNINGF(TL("Person '%' receives type '%' which implicitly uses unsuitable vClass '%'."), getID(), type->getID(), toString(type->getVehicleClass()));
465 }
466 myVType = type;
467}
468
469
472 if (myVType->isVehicleSpecific()) {
473 return *const_cast<MSVehicleType*>(myVType);
474 }
476 replaceVehicleType(type);
477 return *type;
478}
479
480
483 PositionVector centerLine;
484 const Position p = getPosition();
485 const double angle = getAngle();
486 const double length = getVehicleType().getLength();
487 const Position back = p + Position(-cos(angle) * length, -sin(angle) * length);
488 centerLine.push_back(p);
489 centerLine.push_back(back);
490 centerLine.move2side(0.5 * getVehicleType().getWidth());
491 PositionVector result = centerLine;
492 centerLine.move2side(-getVehicleType().getWidth());
493 result.append(centerLine.reverse(), POSITION_EPS);
494 //std::cout << " transp=" << getID() << " p=" << p << " angle=" << GeomHelper::naviDegree(angle) << " back=" << back << " result=" << result << "\n";
495 return result;
496}
497
498
499std::string
500MSTransportable::getStageSummary(int stageIndex) const {
501 assert(stageIndex < (int)myPlan->size());
502 assert(stageIndex >= 0);
503 return (*myPlan)[stageIndex]->getStageSummary(myAmPerson);
504}
505
506
507const std::set<SUMOTrafficObject::NumericalID>
509 std::set<SUMOTrafficObject::NumericalID> result;
510 for (auto step = myStep; step != myPlan->end(); ++step) {
511 for (const MSEdge* const e : (*step)->getEdges()) {
512 if (e != nullptr) {
513 // catch incomplete rides
514 result.insert(e->getNumericalID());
515 }
516 }
517 }
518 return result;
519}
520
521
522bool
524 return myStep == myPlan->end();
525}
526
527bool
529 return myPlan->size() > 0 && (myPlan->front()->getDeparted() >= 0 || myStep > myPlan->begin());
530}
531
532
533void
535 // check whether the transportable was riding to the orignal stop
536 // @note: parkingArea can currently not be set as myDestinationStop so we
537 // check for stops on the edge instead
538#ifdef DEBUG_PARKING
539 std::cout << SIMTIME << " person=" << getID() << " rerouteParkingArea orig=" << orig->getID() << " replacement=" << replacement->getID() << "\n";
540#endif
542 if (!myAmPerson) {
543 WRITE_WARNING(TL("parkingAreaReroute not supported for containers"));
544 return;
545 }
546 if (getDestination() == &orig->getLane().getEdge()) {
547 MSStageDriving* const stage = dynamic_cast<MSStageDriving*>(*myStep);
548 assert(stage != 0);
549 assert(stage->getVehicle() != 0);
550 // adapt plan
551 stage->setDestination(&replacement->getLane().getEdge(), replacement);
552 stage->setArrivalPos((replacement->getBeginLanePosition() + replacement->getEndLanePosition()) / 2);
553#ifdef DEBUG_PARKING
554 std::cout << " set ride destination\n";
555#endif
556 if (myStep + 1 == myPlan->end()) {
557 return;
558 }
559 // if the next step is a walk, adapt the route
560 MSStage* nextStage = *(myStep + 1);
561 if (nextStage->getStageType() == MSStageType::TRIP) {
562 dynamic_cast<MSStageTrip*>(nextStage)->setOrigin(stage->getDestination(), stage->getDestinationStop(), stage->getArrivalPos());
563#ifdef DEBUG_PARKING
564 std::cout << " set subsequent trip origin\n";
565#endif
566 } else if (nextStage->getStageType() == MSStageType::WALKING) {
567#ifdef DEBUG_PARKING
568 std::cout << " replace subsequent walk with a trip\n";
569#endif
570 MSStageTrip* newStage = new MSStageTrip(stage->getDestination(), nullptr, nextStage->getDestination(),
571 nextStage->getDestinationStop(), -1, 0, "", -1, 1, getID(), 0, true, nextStage->getArrivalPos());
572 removeStage(1);
573 appendStage(newStage, 1);
574 } else if (nextStage->getStageType() == MSStageType::WAITING) {
575#ifdef DEBUG_PARKING
576 std::cout << " add subsequent walk to reach stop\n";
577 std::cout << " arrivalPos=" << nextStage->getArrivalPos() << "\n";
578#endif
579 MSStageTrip* newStage = new MSStageTrip(stage->getDestination(), nullptr, nextStage->getDestination(),
580 nextStage->getDestinationStop(), -1, 0, "", -1, 1, getID(), 0, true, nextStage->getArrivalPos());
581 appendStage(newStage, 1);
582 }
583 // if the plan contains another ride with the same vehicle from the same
584 // parking area, adapt the preceeding walk to end at the replacement
585 for (auto it = myStep + 2; it != myPlan->end(); it++) {
586 MSStage* const futureStage = *it;
587 MSStage* const prevStage = *(it - 1);
588 if (futureStage->getStageType() == MSStageType::DRIVING) {
589 MSStageDriving* const ds = static_cast<MSStageDriving*>(futureStage);
590 // ride origin is set implicitly from the walk destination
591 ds->setOrigin(nullptr, nullptr, -1);
592 if (ds->getLines() == stage->getLines()
593 && prevStage->getDestination() == &orig->getLane().getEdge()) {
594 if (prevStage->getStageType() == MSStageType::TRIP) {
595 dynamic_cast<MSStageTrip*>(prevStage)->setDestination(stage->getDestination(), replacement);
596#ifdef DEBUG_PARKING
597 std::cout << " replace later trip before ride (" << (it - myPlan->begin()) << ")\n";
598#endif
599 } else if (prevStage->getStageType() == MSStageType::WALKING) {
600#ifdef DEBUG_PARKING
601 std::cout << " replace later walk before ride (" << (it - myPlan->begin()) << ")\n";
602#endif
603 MSStageTrip* newStage = new MSStageTrip(prevStage->getFromEdge(), nullptr, stage->getDestination(),
604 replacement, -1, 0, "", -1, 1, getID(), 0, true, stage->getArrivalPos());
605 int prevStageRelIndex = (int)(it - 1 - myStep);
606 removeStage(prevStageRelIndex);
607 appendStage(newStage, prevStageRelIndex);
608 }
609 break;
610 }
611 }
612 }
613 }
614}
615
616
618MSTransportable::getDevice(const std::type_info& type) const {
619 for (MSTransportableDevice* const dev : myDevices) {
620 if (typeid(*dev) == type) {
621 return dev;
622 }
623 }
624 return nullptr;
625}
626
627
628void
629MSTransportable::setJunctionModelParameter(const std::string& key, const std::string& value) {
632 const_cast<SUMOVehicleParameter&>(getParameter()).setParameter(key, value);
633 // checked in MSLink::ignoreFoe
634 } else {
635 throw InvalidArgument(getObjectType() + " '" + getID() + "' does not support junctionModel parameter '" + key + "'");
636 }
637}
638
639
640double
642 const MSEdge* edge = getEdge();
643 const double ep = getEdgePos();
644 const double gp = edge->getLanes()[0]->interpolateLanePosToGeometryPos(ep);
645 return edge->getLanes()[0]->getShape().slopeDegreeAtOffset(gp);
646}
647
648
650MSTransportable::getWaitingTime(const bool /* accumulated */) const {
651 return (*myStep)->getWaitingTime();
652}
653
654
655double
657 return MIN2(getVehicleType().getMaxSpeed(), getVehicleType().getDesiredMaxSpeed() * getChosenSpeedFactor());
658}
659
660
665
666
667int
672
673
674void
679
680void
682 // this saves lots of departParameters which are only needed for transportables that did not yet depart
683 // the parameters may hold the name of a vTypeDistribution but we are interested in the actual type
684 const SUMOTime desiredDepart = myParameter->depart;
685 if (myPlan->front()->getDeparted() >= 0) {
686 // this is only relevant in the context of delayed departure (max-num-persons)
687 const_cast<SUMOVehicleParameter*>(myParameter)->depart = myPlan->front()->getDeparted();
688 }
690 const_cast<SUMOVehicleParameter*>(myParameter)->depart = desiredDepart;
695 }
696 int stepIdx = (int)(myStep - myPlan->begin());
697 for (auto it = myPlan->begin(); it != myStep; ++it) {
698 const MSStageType st = (*it)->getStageType();
699 if (st == MSStageType::TRIP || st == MSStageType::ACCESS) {
700 stepIdx--;
701 }
702 }
703 const bool isAccess = (*myStep)->getStageType() == MSStageType::ACCESS;
704 std::ostringstream state;
705 state << myParameter->parametersSet << " " << (isAccess ? toString(stepIdx - 0.5, 1) : toString(stepIdx));
706 (*myStep)->saveState(state, this);
707 out.writeAttr(SUMO_ATTR_STATE, state.str());
708 const MSStage* previous = nullptr;
709 for (const MSStage* const stage : *myPlan) {
710 const bool routeLength = stage->getDeparted() >= 0 && stage->getStageType() == MSStageType::DRIVING;
711 const bool withTiming = stage->getDeparted() >= 0;
712 stage->routeOutput(myAmPerson, out, routeLength, previous, withTiming, true);
713 previous = stage;
714 }
715 out.closeTag();
716}
717
718
719void
720MSTransportable::loadState(const std::string& state) {
721 std::istringstream iss(state);
722 double step;
723 iss >> myParameter->parametersSet >> step;
724 myPlan->front()->setDeparted(myParameter->depart);
725 if (step != floor(step)) {
726 // we are in an access stage
727 int priorIndex = (int)(step - 0.5);
728 MSStage* prior = *(myPlan->begin() + priorIndex);
729 myStep = myPlan->begin() + priorIndex + 1;
730 bool waitAtStop = prior->getDestinationStop() != nullptr
731 && &prior->getDestinationStop()->getLane().getEdge() != prior->getDestination();
732 checkAccess(prior, waitAtStop);
733 //std::cout << " step=" << step << " i=" << getCurrentStageIndex() << " stage=" << getStageSummary(true) << "\n";
734 } else {
735 myStep = myPlan->begin() + (int)step;
736 }
737 (*myStep)->loadState(this, iss);
738 for (int i = 1; i < step; i++) {
739 if ((*myPlan)[i]->getStageType() == MSStageType::DRIVING) {
740 dynamic_cast<MSStageDriving*>((*myPlan)[i])->setWaitingSince((*myPlan)[i - 1]->getArrived());
741 }
742 }
743}
744
745
746/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:75
MSStageType
Definition MSStage.h:55
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:299
#define WRITE_WARNING(msg)
Definition MsgHandler.h:298
#define TL(string)
Definition MsgHandler.h:316
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:107
#define STEPS2TIME(x)
Definition SUMOTime.h:58
#define SIMSTEP
Definition SUMOTime.h:69
#define SUMOTime_MAX
Definition SUMOTime.h:34
#define SIMTIME
Definition SUMOTime.h:70
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:57
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:140
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
virtual void removeTransportable(MSTransportable *t) const
Definition MSEdge.cpp:1281
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:790
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
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
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition MSNet.h:496
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition MSNet.cpp:1326
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:335
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:403
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1317
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:287
virtual double getArrivalPos() const
Definition MSStage.h:97
SUMOTime getDeparted() const
get departure time of stage
Definition MSStage.cpp:129
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:167
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:195
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)
const MSLane * getLane() const override
Returns the current lane (may be nullptr)
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.
virtual void setRoutingMode(int value) override
Sets routing behavior.
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
const MSEdge * getCurrentEdge() const override
Returns the edge (normal or internal) the object is currently at.
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:73
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
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:127
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.
static OutputDevice & writeParams(OutputDevice &device, const Parameterised &params)
write the parameters of the given object as param tags
#define UNUSED_PARAMETER(x)
TRACI_CONST int ROUTING_MODE_DEFAULT