Eclipse SUMO - Simulation of Urban MObility
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-2024 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 
25 #include <utils/geom/GeomHelper.h>
29 #include <libsumo/TraCIConstants.h>
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  myStep = myPlan->begin();
57  // init devices
59  for (MSStage* const stage : * myPlan) {
60  stage->init(this);
61  }
62 }
63 
64 
66  if (myStep != myPlan->end() && getCurrentStageType() == MSStageType::DRIVING) {
67  MSStageDriving* const stage = dynamic_cast<MSStageDriving*>(*myStep);
68  if (stage->getVehicle() != nullptr) {
69  stage->getVehicle()->removeTransportable(this);
70  } else if (stage->getOriginStop() != nullptr) {
71  stage->getOriginStop()->removeTransportable(this);
72  }
73  }
74  if (myPlan != nullptr) {
75  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
76  delete *i;
77  }
78  delete myPlan;
79  myPlan = nullptr;
80  }
81  for (MSTransportableDevice* dev : myDevices) {
82  delete dev;
83  }
84  delete myParameter;
85  if (myVType->isVehicleSpecific()) {
87  }
88 }
89 
90 SumoRNG*
92  return getEdge()->getLanes()[0]->getRNG();
93 }
94 
95 int
97  return getEdge()->getLanes()[0]->getRNGIndex();
98 }
99 
100 bool
101 MSTransportable::proceed(MSNet* net, SUMOTime time, const bool vehicleArrived) {
102  MSStage* const prior = *myStep;
103  const std::string& error = prior->setArrived(net, this, time, vehicleArrived);
104  // must be done before increasing myStep to avoid invalid state for rendering
105  prior->getEdge()->removeTransportable(this);
106  myStep++;
107  if (error != "") {
108  throw ProcessError(error);
109  }
110  /* We need to check whether an access stage is needed (or maybe even two).
111  The general scheme is: If the prior stage ended at a stop and the next stage
112  starts at an edge which is not the one the stop is at, but the stop has an access to it
113  we need an access stage. The same is true if prior ends at an edge, the next stage
114  is allowed to start at any stop the edge has access to.
115  If we start at a stop or end at a stop no access is needed.
116  */
117  bool accessToStop = false;
118  if (prior->getStageType() == MSStageType::WALKING || prior->getStageType() == MSStageType::DRIVING) {
119  accessToStop = checkAccess(prior);
120  } else if (prior->getStageType() == MSStageType::WAITING_FOR_DEPART) {
121  for (MSTransportableDevice* const dev : myDevices) {
122  dev->notifyEnter(*this, MSMoveReminder::NOTIFICATION_DEPARTED, nullptr);
123  }
124  }
125  if (!accessToStop && (myStep == myPlan->end()
126  || ((*myStep)->getStageType() != MSStageType::DRIVING
127  && (*myStep)->getStageType() != MSStageType::TRIP))) {
128  MSStoppingPlace* priorStop = prior->getStageType() == MSStageType::TRIP ? prior->getOriginStop() : prior->getDestinationStop();
129  // a trip might resolve to DRIVING so we would have to stay at the stop
130  // if a trip resolves to something else, this step will do stop removal
131  if (priorStop != nullptr) {
132  priorStop->removeTransportable(this);
133  }
134  }
135  if (myStep != myPlan->end()) {
136  if ((*myStep)->getStageType() == MSStageType::WALKING && (prior->getStageType() != MSStageType::ACCESS || prior->getDestination() != (*myStep)->getFromEdge())) {
137  checkAccess(prior, false);
138  }
139  (*myStep)->proceed(net, this, time, prior);
140  return true;
141  } else {
143  return false;
144  }
145 }
146 
147 
148 void
149 MSTransportable::setID(const std::string& /*newID*/) {
150  throw ProcessError(TL("Changing a transportable ID is not permitted"));
151 }
152 
153 SUMOTime
155  return myParameter->depart;
156 }
157 
158 void
160  (*myStep)->setDeparted(now);
161 }
162 
163 SUMOTime
165  for (const MSStage* const stage : *myPlan) {
166  if (stage->getDeparted() >= 0) {
167  return stage->getDeparted();
168  }
169  }
170  return -1;
171 }
172 
173 
174 double
176  return (*myStep)->getEdgePos(MSNet::getInstance()->getCurrentTimeStep());
177 }
178 
179 double
181  return getEdgePos() - getVehicleType().getLength();
182 }
183 
184 int
186  return (*myStep)->getDirection();
187 }
188 
189 Position
191  return (*myStep)->getPosition(MSNet::getInstance()->getCurrentTimeStep());
192 }
193 
194 double
196  return (*myStep)->getAngle(MSNet::getInstance()->getCurrentTimeStep());
197 }
198 
199 double
201  return STEPS2TIME((*myStep)->getWaitingTime(MSNet::getInstance()->getCurrentTimeStep()));
202 }
203 
204 double
206  return (*myStep)->getSpeed();
207 }
208 
209 
210 void
212  SUMOTime departure = myPlan->front()->getDeparted();
213  os.openTag(isPerson() ? "personinfo" : "containerinfo");
215  os.writeAttr(SUMO_ATTR_DEPART, departure >= 0 ? time2string(departure) : "-1");
217  if (isPerson()) {
219  }
220  SUMOTime duration = 0;
221  SUMOTime waitingTime = 0;
222  SUMOTime timeLoss = 0;
223  SUMOTime travelTime = 0;
224  bool durationOK = true;
225  bool waitingTimeOK = true;
226  bool timeLossOK = true;
227  bool travelTimeOK = true;
228  for (MSStage* const i : *myPlan) {
229  SUMOTime t = i->getDuration();
230  if (t != SUMOTime_MAX) {
231  duration += t;
232  } else {
233  durationOK = false;
234  }
235  t = i->getWaitingTime();
236  if (t != SUMOTime_MAX) {
237  waitingTime += t;
238  } else {
239  waitingTimeOK = false;
240  }
241  t = i->getTimeLoss(this);
242  if (t != SUMOTime_MAX) {
243  timeLoss += t;
244  } else {
245  timeLossOK = false;
246  }
247  t = i->getTravelTime();
248  if (t != SUMOTime_MAX) {
249  travelTime += t;
250  } else {
251  travelTimeOK = false;
252  }
253  }
254  os.writeAttr(SUMO_ATTR_DURATION, durationOK ? time2string(duration) : "-1");
255  os.writeAttr(SUMO_ATTR_WAITINGTIME, waitingTimeOK ? time2string(waitingTime) : "-1");
256  os.writeAttr(SUMO_ATTR_TIMELOSS, timeLossOK ? time2string(timeLoss) : "-1");
257  os.writeAttr(SUMO_ATTR_TRAVELTIME, travelTimeOK ? time2string(travelTime) : "-1");
258  for (MSStage* const i : *myPlan) {
259  i->tripInfoOutput(os, this);
260  }
261  os.closeTag();
262 }
263 
264 
265 void
266 MSTransportable::routeOutput(OutputDevice& os, const bool withRouteLength) const {
267  const std::string typeID = (
271  if (hasArrived()) {
272  os.writeAttr("arrival", time2string(MSNet::getInstance()->getCurrentTimeStep()));
273  }
274  const MSStage* previous = nullptr;
275  for (const MSStage* const stage : *myPlan) {
276  stage->routeOutput(myAmPerson, os, withRouteLength, previous);
277  previous = stage;
278  }
280  os.closeTag();
281  os.lf();
282 }
283 
284 
285 void
287  if (timeout < 0 && myAbortCommand != nullptr) {
289  myAbortCommand = nullptr;
290  return;
291  }
294 }
295 
296 
297 SUMOTime
299  WRITE_WARNINGF(TL("Teleporting % '%'; waited too long, from edge '%', time=%."),
300  isPerson() ? "person" : "container", getID(), (*myStep)->getEdge()->getID(), time2string(step));
303  (*myStep)->abort(this);
304  if (!proceed(MSNet::getInstance(), step)) {
305  tc.erase(this);
306  }
307  return 0;
308 }
309 
310 
311 
312 void
314  // myStep is invalidated upon modifying myPlan
315  const int stepIndex = (int)(myStep - myPlan->begin());
316  if (next < 0) {
317  myPlan->push_back(stage);
318  } else {
319  if (stepIndex + next > (int)myPlan->size()) {
320  throw ProcessError("invalid index '" + toString(next) + "' for inserting new stage into plan of '" + getID() + "'");
321  }
322  myPlan->insert(myPlan->begin() + stepIndex + next, stage);
323  }
324  myStep = myPlan->begin() + stepIndex;
325 }
326 
327 
328 void
329 MSTransportable::removeStage(int next, bool stayInSim) {
330  assert(myStep + next < myPlan->end());
331  assert(next >= 0);
332  if (next > 0) {
333  // myStep is invalidated upon modifying myPlan
334  int stepIndex = (int)(myStep - myPlan->begin());
335  delete *(myStep + next);
336  myPlan->erase(myStep + next);
337  myStep = myPlan->begin() + stepIndex;
338  } else {
339  if (myStep + 1 == myPlan->end() && stayInSim) {
340  // stay in the simulation until the start of simStep to allow appending new stages (at the correct position)
341  appendStage(new MSStageWaiting(getEdge(), nullptr, 0, 0, getEdgePos(), "last stage removed", false));
342  }
343  (*myStep)->abort(this);
346  } else if (myPlan->front()->getDeparted() < 0) {
347  myPlan->front()->setDeparted(SIMSTEP);
348  }
349  }
350 }
351 
352 
353 void
355  for (MSTransportablePlan::const_iterator i = myStep; i != myPlan->end(); ++i) {
356  (*i)->setSpeed(speed);
357  }
358  getSingularType().setMaxSpeed(speed);
359 }
360 
361 
362 bool
363 MSTransportable::replaceRoute(ConstMSRoutePtr newRoute, const std::string& /* info */, bool /* onInit */, int /* offset */, bool /* addRouteStops */, bool /* removeStops */, std::string* /* msgReturn */) {
364  if (isPerson()) {
365  static_cast<MSPerson*>(this)->replaceWalk(newRoute->getEdges(), getPositionOnLane(), 0, 1);
366  return true;
367  }
368  return false;
369 }
370 
371 
372 bool
373 MSTransportable::reroute(SUMOTime t, const std::string& /* info */, MSTransportableRouter& router, const bool /* onInit */, const bool /* withTaz */, const bool /* silent */, const MSEdge* /* sink */) {
374  MSStageTrip* trip = getCurrentStage()->getTrip();
375  if (trip == nullptr) {
376  // TODO this should be possible after factoring out MSStageTrip::reroute
377  return false;
378  }
379  if (getCurrentStage()->getVehicle() != nullptr) {
380  // TODO rerouting during a ride still needs to be implemented
381  return false;
382  }
383  // find the final stage of the trip
384  int tripEndOffset = -1;
385  for (int i = getNumRemainingStages() - 1; i >= 0; i--) {
386  if (getNextStage(i)->getTrip() == trip) {
387  tripEndOffset = i;
388  break;
389  }
390  }
391  std::vector<MSStage*> stages;
392  MSStageWaiting start(getEdge(), getCurrentStage()->getOriginStop(), -1, t, getEdgePos(), "start", true);
393  if (trip->reroute(t, router, this, &start, getEdge(), getRerouteDestination(), stages) == "") {
394  // check whether the new plan actually differs
395  while (tripEndOffset >= 0 && !stages.empty() && stages.back()->equals(*getNextStage(tripEndOffset))) {
396  delete stages.back();
397  stages.pop_back();
398  tripEndOffset--;
399  }
400  bool abortCurrent = true;
401  // check whether the future route of the current stage is identical to the route
402  if (!stages.empty() && stages.front()->isWalk() && getCurrentStage()->isWalk()) {
403  // TODO this check should be done for rides as well
404  MSStageMoving* s = static_cast<MSStageMoving*>(getCurrentStage());
405  int routeIndex = (int)(s->getRouteStep() - s->getRoute().begin());
406  ConstMSEdgeVector oldEdges = s->getEdges();
407  oldEdges.erase(oldEdges.begin(), oldEdges.begin() + routeIndex);
408  ConstMSEdgeVector newEdges = stages.front()->getEdges();
409  if (newEdges == oldEdges) {
410  delete stages.front();
411  stages.erase(stages.begin());
412  abortCurrent = false;
413  }
414  }
415  if (stages.empty()) {
416  return false;
417  }
418  // remove future stages of the trip
419  for (int i = tripEndOffset; i >= 1; i--) {
420  removeStage(i);
421  }
422  // insert new stages of the rerouting
423  int idx = 1;
424  for (MSStage* stage : stages) {
425  appendStage(stage, idx++);
426  }
427  if (abortCurrent) {
428  removeStage(0);
429  }
430  return true;
431  }
432  return false;
433 }
434 
435 
436 void
438  const SUMOVehicleClass oldVClass = myVType->getVehicleClass();
439  if (myVType->isVehicleSpecific()) {
441  }
442  if (isPerson()
443  && type->getVehicleClass() != oldVClass
444  && type->getVehicleClass() != SVC_PEDESTRIAN
446  WRITE_WARNINGF(TL("Person '%' receives type '%' which implicitly uses unsuitable vClass '%'."), getID(), type->getID(), toString(type->getVehicleClass()));
447  }
448  myVType = type;
449 }
450 
451 
454  if (myVType->isVehicleSpecific()) {
455  return *myVType;
456  }
457  MSVehicleType* type = myVType->buildSingularType(myVType->getID() + "@" + getID());
458  replaceVehicleType(type);
459  return *type;
460 }
461 
462 
465  PositionVector centerLine;
466  const Position p = getPosition();
467  const double angle = getAngle();
468  const double length = getVehicleType().getLength();
469  const Position back = p + Position(-cos(angle) * length, -sin(angle) * length);
470  centerLine.push_back(p);
471  centerLine.push_back(back);
472  centerLine.move2side(0.5 * getVehicleType().getWidth());
473  PositionVector result = centerLine;
474  centerLine.move2side(-getVehicleType().getWidth());
475  result.append(centerLine.reverse(), POSITION_EPS);
476  //std::cout << " transp=" << getID() << " p=" << p << " angle=" << GeomHelper::naviDegree(angle) << " back=" << back << " result=" << result << "\n";
477  return result;
478 }
479 
480 
481 std::string
482 MSTransportable::getStageSummary(int stageIndex) const {
483  assert(stageIndex < (int)myPlan->size());
484  assert(stageIndex >= 0);
485  return (*myPlan)[stageIndex]->getStageSummary(myAmPerson);
486 }
487 
488 
489 const std::set<SUMOTrafficObject::NumericalID>
491  std::set<SUMOTrafficObject::NumericalID> result;
492  for (auto step = myStep; step != myPlan->end(); ++step) {
493  for (const MSEdge* const e : (*step)->getEdges()) {
494  result.insert(e->getNumericalID());
495  }
496  }
497  return result;
498 }
499 
500 
501 bool
503  return myStep == myPlan->end();
504 }
505 
506 bool
508  return myPlan->size() > 0 && (myPlan->front()->getDeparted() >= 0 || myStep > myPlan->begin());
509 }
510 
511 
512 void
514  // check whether the transportable was riding to the orignal stop
515  // @note: parkingArea can currently not be set as myDestinationStop so we
516  // check for stops on the edge instead
517 #ifdef DEBUG_PARKING
518  std::cout << SIMTIME << " person=" << getID() << " rerouteParkingArea orig=" << orig->getID() << " replacement=" << replacement->getID() << "\n";
519 #endif
521  if (!myAmPerson) {
522  WRITE_WARNING(TL("parkingAreaReroute not supported for containers"));
523  return;
524  }
525  if (getDestination() == &orig->getLane().getEdge()) {
526  MSStageDriving* const stage = dynamic_cast<MSStageDriving*>(*myStep);
527  assert(stage != 0);
528  assert(stage->getVehicle() != 0);
529  // adapt plan
530  stage->setDestination(&replacement->getLane().getEdge(), replacement);
531  stage->setArrivalPos((replacement->getBeginLanePosition() + replacement->getEndLanePosition()) / 2);
532 #ifdef DEBUG_PARKING
533  std::cout << " set ride destination\n";
534 #endif
535  if (myStep + 1 == myPlan->end()) {
536  return;
537  }
538  // if the next step is a walk, adapt the route
539  MSStage* nextStage = *(myStep + 1);
540  if (nextStage->getStageType() == MSStageType::TRIP) {
541  dynamic_cast<MSStageTrip*>(nextStage)->setOrigin(stage->getDestination());
542 #ifdef DEBUG_PARKING
543  std::cout << " set subsequent trip origin\n";
544 #endif
545  } else if (nextStage->getStageType() == MSStageType::WALKING) {
546 #ifdef DEBUG_PARKING
547  std::cout << " replace subsequent walk with a trip\n";
548 #endif
549  MSStageTrip* newStage = new MSStageTrip(stage->getDestination(), nullptr, nextStage->getDestination(),
550  nextStage->getDestinationStop(), -1, 0, "", -1, 1, getID(), 0, true, nextStage->getArrivalPos());
551  removeStage(1);
552  appendStage(newStage, 1);
553  } else if (nextStage->getStageType() == MSStageType::WAITING) {
554 #ifdef DEBUG_PARKING
555  std::cout << " add subsequent walk to reach stop\n";
556  std::cout << " arrivalPos=" << nextStage->getArrivalPos() << "\n";
557 #endif
558  MSStageTrip* newStage = new MSStageTrip(stage->getDestination(), nullptr, nextStage->getDestination(),
559  nextStage->getDestinationStop(), -1, 0, "", -1, 1, getID(), 0, true, nextStage->getArrivalPos());
560  appendStage(newStage, 1);
561  }
562  // if the plan contains another ride with the same vehicle from the same
563  // parking area, adapt the preceeding walk to end at the replacement
564  for (auto it = myStep + 2; it != myPlan->end(); it++) {
565  MSStage* const futureStage = *it;
566  MSStage* const prevStage = *(it - 1);
567  if (futureStage->getStageType() == MSStageType::DRIVING) {
568  MSStageDriving* const ds = static_cast<MSStageDriving*>(futureStage);
569  // ride origin is set implicitly from the walk destination
570  ds->setOrigin(nullptr);
571  if (ds->getLines() == stage->getLines()
572  && prevStage->getDestination() == &orig->getLane().getEdge()) {
573  if (prevStage->getStageType() == MSStageType::TRIP) {
574  dynamic_cast<MSStageTrip*>(prevStage)->setDestination(stage->getDestination(), replacement);
575 #ifdef DEBUG_PARKING
576  std::cout << " replace later trip before ride (" << (it - myPlan->begin()) << ")\n";
577 #endif
578  } else if (prevStage->getStageType() == MSStageType::WALKING) {
579 #ifdef DEBUG_PARKING
580  std::cout << " replace later walk before ride (" << (it - myPlan->begin()) << ")\n";
581 #endif
582  MSStageTrip* newStage = new MSStageTrip(prevStage->getFromEdge(), nullptr, stage->getDestination(),
583  replacement, -1, 0, "", -1, 1, getID(), 0, true, stage->getArrivalPos());
584  int prevStageRelIndex = (int)(it - 1 - myStep);
585  removeStage(prevStageRelIndex);
586  appendStage(newStage, prevStageRelIndex);
587  }
588  break;
589  }
590  }
591  }
592  }
593 }
594 
595 
596 MSDevice*
597 MSTransportable::getDevice(const std::type_info& type) const {
598  for (MSTransportableDevice* const dev : myDevices) {
599  if (typeid(*dev) == type) {
600  return dev;
601  }
602  }
603  return nullptr;
604 }
605 
606 
607 void
608 MSTransportable::setJunctionModelParameter(const std::string& key, const std::string& value) {
611  const_cast<SUMOVehicleParameter&>(getParameter()).setParameter(key, value);
612  // checked in MSLink::ignoreFoe
613  } else {
614  throw InvalidArgument(getObjectType() + " '" + getID() + "' does not support junctionModel parameter '" + key + "'");
615  }
616 }
617 
618 
619 double
621  const MSEdge* edge = getEdge();
622  const double ep = getEdgePos();
623  const double gp = edge->getLanes()[0]->interpolateLanePosToGeometryPos(ep);
624  return edge->getLanes()[0]->getShape().slopeDegreeAtOffset(gp);
625 }
626 
627 
628 SUMOTime
629 MSTransportable::getWaitingTime(const bool /* accumulated */) const {
630  return (*myStep)->getWaitingTime(MSNet::getInstance()->getCurrentTimeStep());
631 }
632 
633 
634 double
636  return MIN2(getVehicleType().getMaxSpeed(), getVehicleType().getDesiredMaxSpeed() * getChosenSpeedFactor());
637 }
638 
639 
642  return getVehicleType().getVehicleClass();
643 }
644 
645 
646 int
650 }
651 
652 void
654  // this saves lots of departParameters which are only needed for transportables that did not yet depart
655  // the parameters may hold the name of a vTypeDistribution but we are interested in the actual type
656  const SUMOTime desiredDepart = myParameter->depart;
657  if (myPlan->front()->getDeparted() >= 0) {
658  // this is only relevant in the context of delayed departure (max-num-persons)
659  const_cast<SUMOVehicleParameter*>(myParameter)->depart = myPlan->front()->getDeparted();
660  }
662  const_cast<SUMOVehicleParameter*>(myParameter)->depart = desiredDepart;
667  }
668  int stepIdx = (int)(myStep - myPlan->begin());
669  for (auto it = myPlan->begin(); it != myStep; ++it) {
670  const MSStageType st = (*it)->getStageType();
671  if (st == MSStageType::TRIP || st == MSStageType::ACCESS) {
672  stepIdx--;
673  }
674  }
675  std::ostringstream state;
676  state << myParameter->parametersSet << " " << stepIdx;
677  (*myStep)->saveState(state);
678  out.writeAttr(SUMO_ATTR_STATE, state.str());
679  const MSStage* previous = nullptr;
680  for (const MSStage* const stage : *myPlan) {
681  stage->routeOutput(myAmPerson, out, false, previous);
682  previous = stage;
683  }
684  out.closeTag();
685 }
686 
687 
688 void
689 MSTransportable::loadState(const std::string& state) {
690  std::istringstream iss(state);
691  int step;
692  iss >> myParameter->parametersSet >> step;
693  myPlan->front()->setDeparted(myParameter->depart);
694  myStep = myPlan->begin() + step;
695  (*myStep)->loadState(this, iss);
696 }
697 
698 
699 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
MSStageType
Definition: MSStage.h:55
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:296
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:295
#define TL(string)
Definition: MsgHandler.h:315
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition: Route.h:31
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
#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 int VEHPARS_JUNCTIONMODEL_PARAMS_SET
const 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:26
int gPrecisionRandom
Definition: StdDefs.cpp:28
T MIN2(T a, T b)
Definition: StdDefs.h:76
T MAX2(T a, T b)
Definition: StdDefs.h:82
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:137
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:1145
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:756
@ 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:184
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:1191
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:378
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:320
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:471
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1182
const std::set< std::string > & getLines() const
MSStoppingPlace * getOriginStop() const
returns the origin stop (if any). only needed for MSStageTrip
SUMOVehicle * getVehicle() const
Current vehicle in which the transportable is driving (or nullptr)
double getArrivalPos() const
return default value for undefined arrivalPos
void setOrigin(const MSEdge *origin)
change origin for parking area rerouting
virtual MSStoppingPlace * getOriginStop() const
returns the origin stop (if any). only needed for MSStageTrip
Definition: MSStage.h:90
const MSEdge * getDestination() const
returns the destination edge
Definition: MSStage.cpp:65
MSStageTrip * getTrip() const
Definition: MSStage.h:268
virtual const MSEdge * getFromEdge() const
Definition: MSStage.cpp:77
virtual double getArrivalPos() const
Definition: MSStage.h:94
virtual const std::string setArrived(MSNet *net, MSTransportable *transportable, SUMOTime now, const bool vehicleArrived)
logs end of the step
Definition: MSStage.cpp:161
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
Definition: MSStage.h:85
MSStageType getStageType() const
Definition: MSStage.h:127
void setArrivalPos(double arrivalPos)
Definition: MSStage.h:102
void setDestination(const MSEdge *newDestination, MSStoppingPlace *newDestStop)
Definition: MSStage.cpp:189
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 * >::iterator getRouteStep() const
const std::vector< const MSEdge * > & getRoute() 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.
virtual double getChosenSpeedFactor() const
the current speed factor of the transportable (where applicable)
virtual double getEdgePos() const
Return the position on the edge.
bool hasDeparted() const
return whether the transportable has started its plan
int getRNGIndex() const
returns the index of the associated RNG
SUMOVehicleClass getVClass() const
Returns the object's access class.
static NumericalID myCurrentNumericalIndex
SUMOTime getDeparture() const
logs depart time of the current stage
double getBackPositionOnLane(const MSLane *lane) const
Get the object's back position along the given lane.
virtual double getAngle() const
return the current angle of the transportable
void setAbortWaiting(const SUMOTime timeout)
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)
MSStage * getNextStage(int offset) const
Return the next (or previous) stage denoted by the offset.
int getNumRemainingStages() const
Return the number of remaining stages (including the current)
virtual double getSpeed() const
the current speed of the transportable
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 SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
void setDeparted(SUMOTime now)
logs depart time of the current stage
const std::set< NumericalID > getUpcomingEdgeIDs() const
returns the numerical IDs of edges to be used (possibly of future stages)
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)
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
MSVehicleType * myVType
This transportable's type. (mainly used for drawing related information Note sure if it is really nec...
SUMOTime getWaitingTime(const bool accumulated=false) const
const MSVehicleType & getVehicleType() const
Returns the object's "vehicle" type.
bool isPerson() const
Whether it is a person.
virtual Position getPosition() const
Return the Network coordinate of the transportable.
const SUMOVehicleParameter * myParameter
the plan of the transportable
double getPositionOnLane() const
Get the object's position along the lane.
void saveState(OutputDevice &out)
Saves the current state into the given stream.
bool isContainer() const
Whether it is a container.
virtual ~MSTransportable()
destructor
MSStageType getCurrentStageType() const
the current stage type of the transportable
void rerouteParkingArea(MSStoppingPlace *orig, MSStoppingPlace *replacement)
adapt plan when the vehicle reroutes and now stops at replacement instead of orig
std::string getObjectType()
const MSEdge * getRerouteDestination() const
Returns the end point for reroutes (usually the last edge of the route)
const MSEdge * getEdge() const
Returns the current edge.
void loadState(const std::string &state)
Reconstructs the current state.
MSStage * getCurrentStage() const
Return the current stage.
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
bool hasArrived() const
return whether the person has reached the end of its plan
double getSlope() const
Returns the slope of the road at object's position in degrees.
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.
void appendStage(MSStage *stage, int next=-1)
Appends the given stage to the current plan.
SumoRNG * getRNG() const
returns the associated RNG
virtual int getRoutingMode() const
return routing mode (configures router choice but also handling of transient permission changes)
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
bool replaceRoute(ConstMSRoutePtr route, const std::string &info, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true, std::string *msgReturn=nullptr)
Replaces the current route by the given one.
virtual int getDirection() const
Return the movement directon on the edge.
SUMOVehicle * getVehicle() const
The vehicle associated with this transportable.
std::vector< MSStage * > MSTransportablePlan
the structure holding the plan of a transportable
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or nullptr if not.
const MSEdge * getDestination() const
Returns the current destination.
void setID(const std::string &newID)
set the id (inherited from Named but forbidden for transportables)
WrappingCommand< MSTransportable > * myAbortCommand
void replaceVehicleType(MSVehicleType *type)
Replaces the current vehicle type by the one given.
SUMOTime getDesiredDepart() const
Returns the desired departure time.
double getMaxSpeed() const
Returns the maximum speed (the minimum of desired and physical maximum speed)
void removeVType(const MSVehicleType *vehType)
The car-following model and parameter.
Definition: MSVehicleType.h:63
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
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)
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:91
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.
Definition: OptionsCont.cpp:60
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
void lf()
writes a line feed if applicable
Definition: OutputDevice.h:242
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
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
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.
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(int what) const
Returns whether the given parameter was set.
void deschedule()
Marks this Command as being descheduled.
TRACI_CONST int ROUTING_MODE_DEFAULT