Eclipse SUMO - Simulation of Urban MObility
MSPerson.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
18 // The class for modelling person-movements
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <string>
28 #include <vector>
31 #include <utils/common/ToString.h>
33 #include <utils/geom/GeomHelper.h>
35 #include <microsim/MSNet.h>
36 #include <microsim/MSEdge.h>
37 #include <microsim/MSLane.h>
38 #include "MSPerson.h"
42 #include <microsim/MSVehicle.h>
46 #include "MSPModel.h"
47 
48 // ===========================================================================
49 // static value definitions
50 // ===========================================================================
52 
53 /* -------------------------------------------------------------------------
54  * MSPerson::MSPersonStage_Walking - methods
55  * ----------------------------------------------------------------------- */
57  const ConstMSEdgeVector& route,
58  MSStoppingPlace* toStop,
59  SUMOTime walkingTime, double speed,
60  double departPos, double arrivalPos, double departPosLat) :
61  MSTransportable::Stage(route.back(), toStop,
62  SUMOVehicleParameter::interpretEdgePos(arrivalPos, route.back()->getLength(), SUMO_ATTR_ARRIVALPOS,
63  "person '" + personID + "' walking to " + route.back()->getID()),
64  MOVING_WITHOUT_VEHICLE),
65  myWalkingTime(walkingTime),
66  myRoute(route),
67  myCurrentInternalEdge(nullptr),
68  myDepartPos(departPos),
69  myDepartPosLat(departPosLat),
70  mySpeed(speed),
71  myPedestrianState(&myDummyState) {
72  myDepartPos = SUMOVehicleParameter::interpretEdgePos(departPos, route.front()->getLength(), SUMO_ATTR_DEPARTPOS,
73  "person '" + personID + "' walking from " + route.front()->getID());
74  if (walkingTime > 0) {
76  }
77 }
78 
79 
82  delete myPedestrianState;
83  }
84 }
85 
89 }
90 
91 const MSEdge*
93  if (myCurrentInternalEdge != nullptr) {
94  return myCurrentInternalEdge;
95  } else {
96  return *myRouteStep;
97  }
98 }
99 
100 
101 const MSEdge*
103  return myRoute.front();
104 }
105 
106 
107 double
109  return myPedestrianState == nullptr ? -1 : myPedestrianState->getEdgePos(*this, now);
110 }
111 
112 
113 Position
115  return myPedestrianState->getPosition(*this, now);
116 }
117 
118 
119 double
121  return myPedestrianState->getAngle(*this, now);
122 }
123 
124 
125 SUMOTime
127  return myPedestrianState->getWaitingTime(*this, now);
128 }
129 
130 
131 double
133  return myPedestrianState->getSpeed(*this);
134 }
135 
136 
139  return myRoute;
140 }
141 
142 
143 void
145  myDeparted = now;
146  myRouteStep = myRoute.begin();
147  myLastEdgeEntryTime = now;
148  if (myWalkingTime == 0) {
149  if (!person->proceed(net, now)) {
151  }
152  return;
153  }
154  if (previous->getEdgePos(now) >= 0 && previous->getEdge() == *myRouteStep) {
155  myDepartPos = previous->getEdgePos(now);
156  if (myWalkingTime > 0) {
158  }
159  }
160  myPedestrianState = MSPModel::getModel()->add(dynamic_cast<MSPerson*>(person), this, now);
161  if (myPedestrianState == nullptr) {
163  return;
164  }
165  const MSEdge* edge = *myRouteStep;
166  const MSLane* lane = getSidewalk<MSEdge, MSLane>(getEdge());
167  if (lane != nullptr) {
168  for (MSMoveReminder* rem : lane->getMoveReminders()) {
169  rem->notifyEnter(*person, MSMoveReminder::NOTIFICATION_DEPARTED, lane);
170  }
171  }
172  edge->addPerson(person);
173 }
174 
175 
176 void
179 }
180 
181 
182 void
184  mySpeed = speed;
185 }
186 
187 
188 double
190  return walkDistance() / STEPS2TIME(myWalkingTime + 1); // avoid systematic rounding errors
191 }
192 
193 
194 double
196  double length = 0;
197  for (const MSEdge* edge : myRoute) {
198  length += edge->getLength();
199  }
200  if (myRoute.size() > 1 && MSPModel::getModel()->usingInternalLanes()) {
201  // use lower bound for distance to pass the intersection
202  for (ConstMSEdgeVector::const_iterator i = myRoute.begin(); i != myRoute.end() - 1; ++i) {
203  const MSEdge* fromEdge = *i;
204  const MSEdge* toEdge = *(i + 1);
205  const MSLane* from = getSidewalk<MSEdge, MSLane>(fromEdge);
206  const MSLane* to = getSidewalk<MSEdge, MSLane>(toEdge);
207  Position fromPos;
208  Position toPos;
209  if (from != nullptr && to != nullptr) {
210  if (fromEdge->getToJunction() == toEdge->getFromJunction()) {
211  fromPos = from->getShape().back();
212  toPos = to->getShape().front();
213  } else if (fromEdge->getToJunction() == toEdge->getToJunction()) {
214  fromPos = from->getShape().back();
215  toPos = to->getShape().back();
216  } else if (fromEdge->getFromJunction() == toEdge->getFromJunction()) {
217  fromPos = from->getShape().front();
218  toPos = to->getShape().front();
219  } else if (fromEdge->getFromJunction() == toEdge->getToJunction()) {
220  fromPos = from->getShape().front();
221  toPos = to->getShape().back();
222  }
223  length += fromPos.distanceTo2D(toPos);
224  }
225  }
226  }
227  // determine walking direction for depart and arrival
228  const int departFwdArrivalDir = MSPModel::canTraverse(MSPModel::FORWARD, myRoute);
229  const int departBwdArrivalDir = MSPModel::canTraverse(MSPModel::BACKWARD, myRoute);
230  const bool mayStartForward = departFwdArrivalDir != MSPModel::UNDEFINED_DIRECTION;
231  const bool mayStartBackward = departBwdArrivalDir != MSPModel::UNDEFINED_DIRECTION;
232  const double lengthFwd = (length - myDepartPos - (
233  departFwdArrivalDir == MSPModel::BACKWARD
234  ? myArrivalPos
235  : myRoute.back()->getLength() - myArrivalPos));
236  const double lengthBwd = (length - (myRoute.front()->getLength() - myDepartPos) - (
237  departBwdArrivalDir == MSPModel::BACKWARD
238  ? myArrivalPos
239  : myRoute.back()->getLength() - myArrivalPos));
240 
241  if (myRoute.size() == 1) {
242  if (myDepartPos > myArrivalPos) {
243  length = lengthBwd;
244  } else {
245  length = lengthFwd;
246  }
247  } else {
248  if (mayStartForward && mayStartBackward) {
249  length = lengthFwd < lengthBwd ? lengthFwd : lengthBwd;
250  } else if (mayStartForward) {
251  length = lengthFwd;
252  } else if (mayStartBackward) {
253  length = lengthBwd;
254  } else {
255  length = lengthFwd;
256  }
257  }
258  //std::cout << SIMTIME << " route=" << toString(myRoute)
259  // << " depPos=" << myDepartPos << " arPos=" << myArrivalPos
260  // << " dFwdADir=" << departFwdArrivalDir
261  // << " dBwdADir=" << departBwdArrivalDir
262  // << " lengthFwd=" << lengthFwd
263  // << " lengthBwd=" << lengthBwd
264  // << "\n";
265 
266  return MAX2(POSITION_EPS, length);
267 }
268 
269 
270 void
272  const double distance = walkDistance();
273  const double maxSpeed = getMaxSpeed(person);
274  const SUMOTime duration = myArrived - myDeparted;
275  const SUMOTime timeLoss = myArrived == -1 ? 0 : duration - TIME2STEPS(distance / maxSpeed);
276  MSDevice_Tripinfo::addPedestrianData(distance, duration, timeLoss);
277  os.openTag("walk");
278  os.writeAttr("depart", time2string(myDeparted));
279  os.writeAttr("departPos", myDepartPos);
280  os.writeAttr("arrival", myArrived >= 0 ? time2string(myArrived) : "-1");
281  os.writeAttr("arrivalPos", myArrivalPos);
282  os.writeAttr("duration", myDeparted < 0 ? "-1" :
283  time2string(myArrived >= 0 ? duration : MSNet::getInstance()->getCurrentTimeStep() - myDeparted));
284  os.writeAttr("routeLength", distance);
285  os.writeAttr("timeLoss", time2string(timeLoss));
286  os.writeAttr("maxSpeed", maxSpeed);
287  os.closeTag();
288 }
289 
290 
291 void
292 MSPerson::MSPersonStage_Walking::routeOutput(OutputDevice& os, const bool withRouteLength) const {
294  std::string comment = "";
295  if (myDestinationStop != nullptr) {
297  if (myDestinationStop->getMyName() != "") {
298  comment = " <!-- " + StringUtils::escapeXML(myDestinationStop->getMyName(), true) + " -->";
299  }
300  }
301  if (myWalkingTime > 0) {
303  } else if (mySpeed > 0) {
305  }
306  if (withRouteLength) {
307  os.writeAttr("routeLength", walkDistance());
308  }
309  os.closeTag(comment);
310 }
311 
312 
313 void
315  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "departure")
316  .writeAttr("agent", p.getID()).writeAttr("link", myRoute.front()->getID()).closeTag();
317 }
318 
319 
320 void
322  os.openTag("event").writeAttr("time", time2string(t)).writeAttr("type", "arrival")
323  .writeAttr("agent", p.getID()).writeAttr("link", myRoute.back()->getID()).closeTag();
324 }
325 
326 
327 bool
329  ((MSEdge*)getEdge())->removePerson(person);
330  const MSLane* lane = getSidewalk<MSEdge, MSLane>(getEdge());
331  const bool arrived = myRouteStep == myRoute.end() - 1;
332  if (lane != nullptr) {
333  for (MSMoveReminder* rem : lane->getMoveReminders()) {
334  rem->updateDetector(*person, 0.0, lane->getLength(), myLastEdgeEntryTime, currentTime, currentTime, true);
335  rem->notifyLeave(*person,
336  arrived ? getArrivalPos() : lane->getLength(),
338  }
339  }
340  myLastEdgeEntryTime = currentTime;
341  //std::cout << SIMTIME << " moveToNextEdge person=" << person->getID() << "\n";
342  if (arrived) {
343  if (myDestinationStop != nullptr) {
345  }
346  if (!person->proceed(MSNet::getInstance(), currentTime)) {
348  }
349  //std::cout << " end walk. myRouteStep=" << (*myRouteStep)->getID() << "\n";
350  return true;
351  } else {
352  if (nextInternal == nullptr) {
353  ++myRouteStep;
354  myCurrentInternalEdge = nullptr;
355  } else {
356  myCurrentInternalEdge = nextInternal;
357  }
358  const MSLane* nextLane = getSidewalk<MSEdge, MSLane>(getEdge());
359  if (nextLane != nullptr) {
360  for (MSMoveReminder* rem : nextLane->getMoveReminders()) {
361  rem->notifyEnter(*person, MSMoveReminder::NOTIFICATION_JUNCTION, nextLane);
362  }
363  }
364  ((MSEdge*) getEdge())->addPerson(person);
365  return false;
366  }
367 }
368 
369 void
371  assert(routeOffset >= 0);
372  assert(routeOffset < (int)myRoute.size());
373  ((MSEdge*)getEdge())->removePerson(person);
374  myRouteStep = myRoute.begin() + routeOffset;
375  ((MSEdge*)getEdge())->addPerson(person);
376 }
377 
378 double
380  return mySpeed > 0 ? mySpeed : person->getVehicleType().getMaxSpeed() * person->getSpeedFactor();
381 }
382 
383 std::string
385  const std::string dest = (getDestinationStop() == nullptr ?
386  " edge '" + getDestination()->getID() + "'" :
387  " stop '" + getDestinationStop()->getID() + "'" + (
388  getDestinationStop()->getMyName() != "" ? " (" + getDestinationStop()->getMyName() + ")" : ""));
389  return "walking to " + dest;
390 }
391 
392 
393 /* -------------------------------------------------------------------------
394 * MSPerson::MSPersonStage_Driving - methods
395 * ----------------------------------------------------------------------- */
397  MSStoppingPlace* toStop, const double arrivalPos, const std::vector<std::string>& lines,
398  const std::string& intendedVeh, SUMOTime intendedDepart) :
399  MSTransportable::Stage_Driving(destination, toStop,
400  SUMOVehicleParameter::interpretEdgePos(
401  arrivalPos, destination->getLength(), SUMO_ATTR_ARRIVALPOS, "person riding to " + destination->getID()),
402  lines,
403  intendedVeh, intendedDepart) {
404 }
405 
406 
408 
411  return new MSPersonStage_Driving(myDestination, myDestinationStop, myArrivalPos, std::vector<std::string>(myLines.begin(), myLines.end()),
413 }
414 
415 void
417  const MSStoppingPlace* start = (previous->getStageType() == TRIP
418  ? previous->getOriginStop()
419  : previous->getDestinationStop());
420  if (start != nullptr) {
421  // the arrival stop may have an access point
422  myWaitingEdge = &start->getLane().getEdge();
423  myStopWaitPos = start->getWaitPosition(person);
424  myWaitingPos = start->getWaitingPositionOnLane(person);
425  } else {
426  myWaitingEdge = previous->getEdge();
428  myWaitingPos = previous->getEdgePos(now);
429  }
430  myWaitingSince = now;
431  SUMOVehicle* availableVehicle = net->getVehicleControl().getWaitingVehicle(person, myWaitingEdge, myWaitingPos);
432  if (availableVehicle != nullptr && availableVehicle->getParameter().departProcedure == DEPART_TRIGGERED && !availableVehicle->hasDeparted()) {
433  setVehicle(availableVehicle);
434  myVehicle->addPerson(person);
438  } else {
439  net->getPersonControl().addWaiting(myWaitingEdge, person);
440  myWaitingEdge->addPerson(person);
441  }
442 }
443 
444 
445 std::string
447  return isWaiting4Vehicle() ? "waiting for " + joinToString(myLines, ",") : "driving";
448 }
449 
450 
451 std::string
453  const std::string dest = (getDestinationStop() == nullptr ?
454  " edge '" + getDestination()->getID() + "'" :
455  " stop '" + getDestinationStop()->getID() + "'" + (
456  getDestinationStop()->getMyName() != "" ? " (" + getDestinationStop()->getMyName() + ")" : ""));
457  const std::string intended = myIntendedVehicleID != "" ?
458  " (vehicle " + myIntendedVehicleID + " at time " + time2string(myIntendedDepart) + ")" :
459  "";
460  return isWaiting4Vehicle() ?
461  "waiting for " + joinToString(myLines, ",") + intended + " then drive to " + dest :
462  "driving to " + dest;
463 }
464 
465 
466 void
469  const SUMOTime departed = myDeparted >= 0 ? myDeparted : now;
470  const SUMOTime waitingTime = myWaitingSince >= 0 && myDeparted >= 0 ? departed - myWaitingSince : -1;
471  const SUMOTime duration = myArrived - myDeparted;
473  os.openTag("ride");
474  os.writeAttr("waitingTime", waitingTime >= 0 ? time2string(waitingTime) : "-1");
475  os.writeAttr("vehicle", myVehicleID);
476  os.writeAttr("depart", myDeparted >= 0 ? time2string(myDeparted) : "-1");
477  os.writeAttr("arrival", myArrived >= 0 ? time2string(myArrived) : "-1");
478  os.writeAttr("arrivalPos", toString(myArrivalPos));
479  os.writeAttr("duration", myArrived >= 0 ? time2string(duration) :
480  (myDeparted >= 0 ? time2string(now - myDeparted) : "-1"));
481  os.writeAttr("routeLength", myVehicleDistance);
482  os.closeTag();
483 }
484 
485 
486 void
487 MSPerson::MSPersonStage_Driving::routeOutput(OutputDevice& os, const bool withRouteLength) const {
488  os.openTag("ride");
489  if (getFromEdge() != nullptr) {
491  }
493  std::string comment = "";
494  if (myDestinationStop != nullptr) {
496  if (myDestinationStop->getMyName() != "") {
497  comment = " <!-- " + StringUtils::escapeXML(myDestinationStop->getMyName()) + " -->";
498  }
499  }
501  if (myIntendedVehicleID != "") {
503  }
504  if (myIntendedDepart >= 0) {
506  }
507  if (withRouteLength) {
508  os.writeAttr("routeLength", myVehicleDistance);
509  }
510  os.closeTag(comment);
511 }
512 
513 
514 /* -------------------------------------------------------------------------
515 * MSPerson::MSPersonStage_Access - methods
516 * ----------------------------------------------------------------------- */
518  const double arrivalPos, const double dist, const bool isExit) :
519  MSTransportable::Stage(destination, toStop, arrivalPos, ACCESS),
520  myDist(dist), myAmExit(isExit) {
521  myPath.push_back(destination->getLanes()[0]->geometryPositionAtOffset(myDestinationStop->getAccessPos(destination)));
522  myPath.push_back(toStop->getLane().geometryPositionAtOffset((toStop->getEndLanePosition() + toStop->getBeginLanePosition()) / 2));
523  if (isExit) {
524  myPath = myPath.reverse();
525  }
526 }
527 
528 
530 
534 }
535 
536 void
538  myDeparted = now;
542 }
543 
544 
545 std::string
547  return "access";
548 }
549 
550 
551 std::string
553  return (myAmExit ? "access from stop '" : "access to stop '") + getDestinationStop()->getID() + "'";
554 }
555 
556 
557 Position
560 }
561 
562 
563 double
565  return myPath.angleAt2D(0);
566 }
567 
568 
569 void
571  os.openTag("access");
572  os.writeAttr("stop", getDestinationStop()->getID());
573  os.writeAttr("duration", myArrived > 0 ? time2string(myArrived - myDeparted) : "-1");
574  os.writeAttr("routeLength", myDist);
575  os.closeTag();
576 }
577 
578 
579 SUMOTime
581  myStopEdge->removePerson(myPerson);
582  if (!myPerson->proceed(MSNet::getInstance(), currentTime)) {
584  }
585  return 0;
586 }
587 
588 
589 /* -------------------------------------------------------------------------
590  * MSPerson - methods
591  * ----------------------------------------------------------------------- */
592 MSPerson::MSPerson(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportable::MSTransportablePlan* plan, const double speedFactor) :
593  MSTransportable(pars, vtype, plan),
594  myInfluencer(nullptr), myChosenSpeedFactor(speedFactor) {
595 }
596 
597 
599 }
600 
601 
602 bool
604  MSTransportable::Stage* prior = *myStep;
605  prior->setArrived(net, this, time);
606  /*
607  if(myWriteEvents) {
608  (*myStep)->endEventOutput(*this, time, OutputDevice::getDeviceByOption("person-event-output"));
609  }
610  */
611  //if (getID() == "ego") {
612  // std::cout << time2string(time) << " person=" << getID() << " proceed priorStep=" << myStep - myPlan->begin() << " planSize=" << myPlan->size() << "\n";
613  //}
614  // must be done before increasing myStep to avoid invalid state for rendering
615  prior->getEdge()->removePerson(this);
616  myStep++;
617  if (prior->getStageType() == MOVING_WITHOUT_VEHICLE) {
618  MSStoppingPlace* const bs = prior->getDestinationStop();
619  if (bs != nullptr) {
620  const double accessDist = bs->getAccessDistance(prior->getDestination());
621  if (accessDist > 0.) {
622  const double arrivalAtBs = (bs->getBeginLanePosition() + bs->getEndLanePosition()) / 2;
623  myStep = myPlan->insert(myStep, new MSPersonStage_Access(prior->getDestination(), bs, arrivalAtBs, accessDist, false));
624  }
625  }
626  }
627  if (myStep != myPlan->end()) {
628  if ((*myStep)->getStageType() == MOVING_WITHOUT_VEHICLE && (prior->getStageType() != ACCESS || prior->getDestination() != (*myStep)->getFromEdge())) {
629  MSStoppingPlace* const prevStop = prior->getDestinationStop();
630  if (prevStop != nullptr && prior->getStageType() != TRIP) {
631  const double accessDist = prevStop->getAccessDistance((*myStep)->getFromEdge());
632  if (accessDist > 0.) {
633  myStep = myPlan->insert(myStep, new MSPersonStage_Access((*myStep)->getFromEdge(), prevStop, prevStop->getAccessPos((*myStep)->getFromEdge()), accessDist, true));
634  }
635  }
636  }
637  (*myStep)->proceed(net, this, time, prior);
638  /*
639  if(myWriteEvents) {
640  (*myStep)->beginEventOutput(*this, time, OutputDevice::getDeviceByOption("person-event-output"));
641  }
642  */
643  return true;
644  } else {
645  // cleanup
646  if (prior->getDestinationStop() != nullptr) {
647  prior->getDestinationStop()->removeTransportable(this);
648  }
649  return false;
650  }
651 }
652 
653 
654 const std::string&
656 // if (getCurrentStageType() == MOVING_WITHOUT_VEHICLE) {
657 // MSPersonStage_Walking* walkingStage = dynamic_cast<MSPersonStage_Walking*>(*myStep);
658 // assert(walkingStage != 0);
659 // const MSEdge* nextEdge = walkingStage->getPedestrianState()->getNextEdge(*walkingStage);
660 // if (nextEdge != 0) {
661 // return nextEdge->getID();
662 // }
663 // }
664 // return StringUtils::emptyString;
665  const MSEdge* nextEdge = getNextEdgePtr();
666  if (nextEdge != nullptr) {
667  return nextEdge->getID();
668  }
670 }
671 
672 
673 const MSEdge*
676  MSPersonStage_Walking* walkingStage = dynamic_cast<MSPersonStage_Walking*>(*myStep);
677  assert(walkingStage != 0);
678  return walkingStage->getPedestrianState()->getNextEdge(*walkingStage);
679 
680  }
681  return nullptr;
682 }
683 
684 
685 
686 void
688  os.openTag("personinfo");
689  os.writeAttr("id", getID());
690  os.writeAttr("depart", time2string(getDesiredDepart()));
691  os.writeAttr("type", getVehicleType().getID());
692  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
693  (*i)->tripInfoOutput(os, this);
694  }
695  os.closeTag();
696 }
697 
698 
699 void
700 MSPerson::routeOutput(OutputDevice& os, const bool withRouteLength) const {
701  const std::string typeID = getVehicleType().getID() != DEFAULT_PEDTYPE_ID ? getVehicleType().getID() : "";
703  if (hasArrived()) {
704  os.writeAttr("arrival", time2string(MSNet::getInstance()->getCurrentTimeStep()));
705  }
706  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
707  (*i)->routeOutput(os, withRouteLength);
708  }
709  os.closeTag();
710  os.lf();
711 }
712 
713 
714 void
715 MSPerson::reroute(ConstMSEdgeVector& newEdges, double departPos, int firstIndex, int nextIndex) {
716  assert(nextIndex > firstIndex);
717  //std::cout << SIMTIME << " reroute person " << getID()
718  // << " newEdges=" << toString(newEdges)
719  // << " firstIndex=" << firstIndex
720  // << " nextIndex=" << nextIndex
721  // << " departPos=" << getEdgePos()
722  // << " arrivalPos=" << getNextStage(nextIndex - 1)->getArrivalPos()
723  // << "\n";
725  getNextStage(nextIndex - 1)->getDestinationStop(), -1,
726  -1,
727  departPos,
728  getNextStage(nextIndex - 1)->getArrivalPos(),
729  0);
730  appendStage(newStage, nextIndex);
731  // remove stages in reverse order so that proceed will only be called at the last removal
732  for (int i = nextIndex - 1; i >= firstIndex; i--) {
733  //std::cout << " removeStage=" << i << "\n";
734  removeStage(i);
735  }
736 }
737 
738 
741  if (myInfluencer == nullptr) {
742  myInfluencer = new Influencer();
743  }
744  return *myInfluencer;
745 }
746 
747 
750  return myInfluencer;
751 }
752 
753 
754 
755 /* -------------------------------------------------------------------------
756  * methods of MSPerson::Influencer
757  * ----------------------------------------------------------------------- */
759 
760 
762 
763 
764 void
765 MSPerson::Influencer::setRemoteControlled(Position xyPos, MSLane* l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector& route, SUMOTime t) {
766  myRemoteXYPos = xyPos;
767  myRemoteLane = l;
768  myRemotePos = pos;
769  myRemotePosLat = posLat;
770  myRemoteAngle = angle;
771  myRemoteEdgeOffset = edgeOffset;
772  myRemoteRoute = route;
773  myLastRemoteAccess = t;
774 }
775 
776 
777 bool
779  return myLastRemoteAccess == MSNet::getInstance()->getCurrentTimeStep();
780 }
781 
782 
783 bool
785  return myLastRemoteAccess >= t - TIME2STEPS(10);
786 }
787 
788 
789 void
791  /*
792  std::cout << SIMTIME << " moveToXY person=" << p->getID()
793  << " xyPos=" << myRemoteXYPos
794  << " lane=" << Named::getIDSecure(myRemoteLane)
795  << " pos=" << myRemotePos
796  << " posLat=" << myRemotePosLat
797  << " angle=" << myRemoteAngle
798  << " eOf=" << myRemoteEdgeOffset
799  << " route=" << toString(myRemoteRoute)
800  << " aTime=" << time2string(myLastRemoteAccess)
801  << "\n";
802  */
803  switch (p->getStageType(0)) {
804  case MOVING_WITHOUT_VEHICLE: {
806  assert(s != 0);
807  s->getPedestrianState()->moveToXY(p, myRemoteXYPos, myRemoteLane, myRemotePos, myRemotePosLat, myRemoteAngle, myRemoteEdgeOffset, myRemoteRoute,
808  MSNet::getInstance()->getCurrentTimeStep());
809  }
810  break;
811  default:
812  break;
813  }
814 }
815 
816 
817 /****************************************************************************/
The departure is person triggered.
virtual const MSEdge * getNextEdge(const MSPerson::MSPersonStage_Walking &stage) const =0
return the list of internal edges if the pedestrian is on an intersection
void addWaiting(const MSEdge *edge, MSTransportable *person)
adds a transportable to the list of transportables waiting for a vehicle on the specified edge ...
double getAccessPos(const MSEdge *edge) const
the position on the given edge which is connected to this stop, -1 on failure
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:670
long long int SUMOTime
Definition: SUMOTime.h:35
static void addPedestrianData(double walkLength, SUMOTime walkDuration, SUMOTime walkTimeLoss)
record tripinfo data for pedestrians
virtual bool hasDeparted() const =0
Returns whether this vehicle has departed.
double getBeginLanePosition() const
Returns the begin position of this stop.
virtual void endEventOutput(const MSTransportable &p, SUMOTime t, OutputDevice &os) const
Called for writing the events output (end of an action)
Definition: MSPerson.cpp:321
~MSPersonStage_Access()
destructor
Definition: MSPerson.cpp:529
virtual ~MSPerson()
destructor
Definition: MSPerson.cpp:598
virtual double getAngle(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const =0
return the direction in which the person faces in degrees
double getArrivalPos() const
returns the final arrival pos
virtual void setArrived(MSNet *net, MSTransportable *transportable, SUMOTime now)
logs end of the step
~Influencer()
Destructor.
Definition: MSPerson.cpp:761
A lane area vehicles can halt at.
virtual SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const =0
return the time the person spent standing
std::string getStageDescription() const
returns the stage description as a string
Definition: MSPerson.cpp:546
virtual void routeOutput(OutputDevice &os, const bool withRouteLength) const
Called on writing vehroute output.
Definition: MSPerson.cpp:700
virtual void proceed(MSNet *net, MSTransportable *person, SUMOTime now, Stage *previous)
proceeds to the next step
Definition: MSPerson.cpp:416
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:244
MSEdge * myCurrentInternalEdge
The current internal edge this person is on or 0.
Definition: MSPerson.h:209
bool hasArrived() const
return whether the person has reached the end of its plan
The vehicle arrived at a junction.
const MSEdge * getDestination() const
returns the destination edge
virtual const MSEdge * getEdge() const
Returns the current edge.
void postProcessRemoteControl(MSPerson *p)
Definition: MSPerson.cpp:790
virtual double getEdgePos(SUMOTime now) const
const MSEdge * getEdge() const
Returns the current edge.
Definition: MSPerson.cpp:92
static const int FORWARD
Definition: MSPModel.h:100
static void addRideData(double rideLength, SUMOTime rideDuration, SUMOVehicleClass vClass, const std::string &line, SUMOTime waitingTime)
record tripinfo data for rides
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
Position getPosition(SUMOTime now) const
returns the position of the transportable
Definition: MSPerson.cpp:114
virtual void remove(PedestrianState *state)=0
remove the specified person from the pedestrian simulation
void setRemoteControlled(Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector &route, SUMOTime t)
Definition: MSPerson.cpp:765
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:165
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
T MAX2(T a, T b)
Definition: StdDefs.h:80
const std::string & getNextEdge() const
return the list of internal edges if this person is walking and the pedestrian model allows it ...
Definition: MSPerson.cpp:655
virtual void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
Definition: MSPerson.cpp:687
MSPersonStage_Driving(const MSEdge *destination, MSStoppingPlace *toStop, const double arrivalPos, const std::vector< std::string > &lines, const std::string &intendedVeh="", SUMOTime intendedDepart=-1)
constructor
Definition: MSPerson.cpp:396
double getLength() const
Returns the lane&#39;s length.
Definition: MSLane.h:541
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:478
const std::set< std::string > myLines
the lines to choose from
virtual bool usingInternalLanes()=0
whether movements on intersections are modelled
PositionVector reverse() const
reverse position vector
void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const
Called on writing tripinfo output.
Definition: MSPerson.cpp:570
double getWaitingPositionOnLane(MSTransportable *t) const
Returns the lane position corresponding to getWaitPosition()
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:73
virtual bool proceed(MSNet *net, SUMOTime time)=0
const std::string & getID() const
Returns the id.
Definition: Named.h:77
#define TIME2STEPS(x)
Definition: SUMOTime.h:59
const MSEdge * myDestination
the next edge to reach by getting transported
const std::vector< MSMoveReminder *> & getMoveReminders() const
Return the list of this lane&#39;s move reminders.
Definition: MSLane.h:268
MSStoppingPlace * myDestinationStop
the stop to reach by getting transported (if any)
MSTransportablePlan::iterator myStep
the iterator over the route
const MSJunction * getToJunction() const
Definition: MSEdge.h:361
const MSEdge * getFromEdge() const
const std::string & getMyName() const
bool isRemoteAffected(SUMOTime t) const
Definition: MSPerson.cpp:784
The simulated network and simulation perfomer.
Definition: MSNet.h:92
The car-following model and parameter.
Definition: MSVehicleType.h:66
virtual void erase(MSTransportable *transportable)
removes a single transportable
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
virtual Position getPosition(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const =0
return the network coordinate of the person
PedestrianState * getPedestrianState() const
Definition: MSPerson.h:179
const SUMOVehicleParameter * myParameter
the plan of the transportable
virtual PedestrianState * add(MSPerson *person, MSPerson::MSPersonStage_Walking *stage, SUMOTime now)=0
register the given person as a pedestrian
void removeStage(int next)
removes the nth next stage
std::string getStageSummary() const
return string summary of the current stage
Definition: MSPerson.cpp:384
virtual void beginEventOutput(const MSTransportable &p, SUMOTime t, OutputDevice &os) const
Called for writing the events output.
Definition: MSPerson.cpp:314
static double interpretEdgePos(double pos, double maximumValue, SumoXMLAttr attr, const std::string &id)
Interprets negative edge positions and fits them onto a given edge.
bool isWaiting4Vehicle() const
Whether the person waits for a vehicle.
SUMOTime myWaitingSince
The time since which this person is waiting for a ride.
std::string getStageSummary() const
return string summary of the current stage
Definition: MSPerson.cpp:552
virtual void proceed(MSNet *net, MSTransportable *person, SUMOTime now, Stage *previous)
proceeds to the next step
Definition: MSPerson.cpp:144
ConstMSEdgeVector myRoute
The route of the person.
Definition: MSPerson.h:203
A road/street connecting two junctions.
Definition: MSEdge.h:76
static int canTraverse(int dir, const ConstMSEdgeVector &route)
Definition: MSPModel.cpp:92
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
MSPersonStage_Access(const MSEdge *destination, MSStoppingPlace *toStop, const double arrivalPos, const double dist, const bool isExit)
constructor
Definition: MSPerson.cpp:517
double getEndLanePosition() const
Returns the end position of this stop.
MSTransportable::Stage * getCurrentStage() const
Return the current stage.
MSTransportable::Stage * getNextStage(int next) const
Return the current stage.
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:105
void abort(MSTransportable *)
abort this stage (TraCI)
Definition: MSPerson.cpp:177
SUMOTime myArrived
the time at which this stage ended
the edges of a route
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition: MSPerson.cpp:740
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
SUMOTime myDeparted
the time at which this stage started
Representation of a vehicle.
Definition: SUMOVehicle.h:61
static MSPModel * getModel()
Definition: MSPModel.cpp:59
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:798
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
SUMOTime getDesiredDepart() const
Returns the desired departure time.
ConstMSEdgeVector getEdges() const
the edges of the current stage
Definition: MSPerson.cpp:138
virtual void addPerson(MSTransportable *p) const
Definition: MSEdge.h:609
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:337
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:430
virtual double getEdgePos(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const =0
return the offset from the start of the current edge measured in its natural direction ...
The vehicle arrived at its destination (is deleted)
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
#define STEPS2TIME(x)
Definition: SUMOTime.h:57
double getAngle(SUMOTime now) const
returns the angle of the transportable
Definition: MSPerson.cpp:120
virtual void routeOutput(OutputDevice &os, const bool withRouteLength) const
Called on writing vehroute output.
Definition: MSPerson.cpp:292
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:284
std::string getStageDescription() const
returns the stage description as a string
Definition: MSPerson.cpp:446
void write(OutputDevice &dev, const OptionsCont &oc, const SumoXMLTag tag=SUMO_TAG_VEHICLE, const std::string &typeID="") const
Writes the parameters as a beginning element.
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
virtual double getSpeed(const MSPerson::MSPersonStage_Walking &stage) const =0
return the current speed of the person
std::string myVehicleID
cached vehicle data for output after the vehicle has been removed
#define POSITION_EPS
Definition: config.h:169
const std::string & getID() const
returns the id of the transportable
double getMaxSpeed(const MSTransportable *const person) const
accessors to be used by MSPModel
Definition: MSPerson.cpp:379
virtual void removePerson(MSTransportable *p) const
Definition: MSEdge.h:613
ConstMSEdgeVector::iterator myRouteStep
Definition: MSPerson.h:206
SUMOVehicle * myVehicle
The taken vehicle.
Something on a lane to be noticed about vehicle movement.
void removeTransportable(MSTransportable *p)
Removes a transportable from this stop.
void setSpeed(double speed)
sets the walking speed (ignored in other stages)
Definition: MSPerson.cpp:183
double getArrivalPos() const
Definition: MSPerson.h:161
virtual Position getWaitPosition(MSTransportable *person) const
Returns the next free waiting place for pedestrians / containers.
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
MSPerson(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan, const double speedFactor)
constructor
Definition: MSPerson.cpp:592
bool addTransportable(MSTransportable *p)
adds a transportable to this stop
virtual const MSStoppingPlace * getOriginStop() const
returns the origin stop (if any). only needed for Stage_Trip
double getAccessDistance(const MSEdge *edge) const
the distance from the access on the given edge to the stop, -1 on failure
static std::string emptyString
An empty string.
Definition: StringUtils.h:79
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
virtual double getSpeedFactor() const
the current speed factor of the transportable (where applicable)
void appendStage(Stage *stage, int next=-1)
Appends the given stage to the current plan.
Position getPosition(SUMOTime now) const
returns the position of the transportable
Definition: MSPerson.cpp:558
Changes the wished person speed and position.
Definition: MSPerson.h:400
double computeAverageSpeed() const
Definition: MSPerson.cpp:189
The vehicle has departed (was inserted into the network)
Structure representing possible vehicle parameter.
SUMOVehicle * getWaitingVehicle(MSTransportable *transportable, const MSEdge *const edge, const double position)
double length() const
Returns the length.
SUMOTime getWaitingTime(SUMOTime now) const
the time this transportable spent waiting
Definition: MSPerson.cpp:126
void reroute(ConstMSEdgeVector &newEdges, double departPos, int firstIndex, int nextIndex)
set new walk and replace the stages with relative indices in the interval [firstIndex, nextIndex[
Definition: MSPerson.cpp:715
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:390
const std::string DEFAULT_PEDTYPE_ID
const double myChosenSpeedFactor
Definition: MSPerson.h:454
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle&#39;s parameter (including departure definition)
const MSJunction * getFromJunction() const
Definition: MSEdge.h:357
SUMOTime myWalkingTime
the time the person is walking
Definition: MSPerson.h:197
double getSpeed() const
the speed of the transportable
Definition: MSPerson.cpp:132
bool moveToNextEdge(MSPerson *person, SUMOTime currentTime, MSEdge *nextInternal=nullptr)
move forward and return whether the person arrived
Definition: MSPerson.cpp:328
StageType getStageType() const
virtual void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const
Called on writing tripinfo output.
Definition: MSPerson.cpp:467
~MSPersonStage_Walking()
destructor
Definition: MSPerson.cpp:80
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
MSPersonStage_Walking(const std::string &personID, const ConstMSEdgeVector &route, MSStoppingPlace *toStop, SUMOTime walkingTime, double speed, double departPos, double arrivalPos, double departPosLat)
constructor
Definition: MSPerson.cpp:56
double angleAt2D(int pos) const
get angle in certain position of position vector
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:505
StageType getStageType(int next) const
the stage type for the nth next stage
PedestrianState * myPedestrianState
state that is to be manipulated by MSPModel
Definition: MSPerson.h:216
bool proceed(MSNet *net, SUMOTime time)
Definition: MSPerson.cpp:603
virtual void addPerson(MSTransportable *person)=0
Adds a person to this vehicle.
static DummyState myDummyState
Definition: MSPerson.h:456
static const int BACKWARD
Definition: MSPModel.h:104
const MSEdge * getNextEdgePtr() const
returns the next edge ptr if this person is walking and the pedestrian model allows it ...
Definition: MSPerson.cpp:674
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
MSTransportablePlan * myPlan
the plan of the transportable
virtual void proceed(MSNet *net, MSTransportable *person, SUMOTime now, Stage *previous)
proceeds to the next step
Definition: MSPerson.cpp:537
SUMOTime myLastEdgeEntryTime
the time the person entered the edge
Definition: MSPerson.h:200
double getAngle(SUMOTime now) const
returns the angle of the transportable
Definition: MSPerson.cpp:564
SUMOTime execute(SUMOTime currentTime)
Executes the command.
Definition: MSPerson.cpp:580
virtual void routeOutput(OutputDevice &os, const bool withRouteLength) const
Called on writing vehroute output.
Definition: MSPerson.cpp:487
const MSLane & getLane() const
Returns the lane this stop is located at.
double walkDistance() const
compute total walking distance
Definition: MSPerson.cpp:195
Influencer * myInfluencer
An instance of a speed/position influencing instance; built in "getInfluencer".
Definition: MSPerson.h:452
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
bool isRemoteControlled() const
Definition: MSPerson.cpp:778
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
const MSEdge * getFromEdge() const
Definition: MSPerson.cpp:102
Influencer()
Constructor.
Definition: MSPerson.cpp:758
void unregisterOneWaiting(const bool isPerson)
decreases the count of vehicles waiting for a transport to allow recognition of person / container re...
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:247
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
double getEdgePos(SUMOTime now) const
Definition: MSPerson.cpp:108
void lf()
writes a line feed if applicable
Definition: OutputDevice.h:234
virtual void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const
Called on writing tripinfo output.
Definition: MSPerson.cpp:271
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:285
void removeWaiting(const MSEdge *const edge, const SUMOVehicle *vehicle)
Removes a vehicle from the list of waiting vehicles for the given edge.
double myArrivalPos
the position at which we want to arrive
StageType getCurrentStageType() const
the current stage type of the transportable
void setRouteIndex(MSPerson *person, int routeOffset)
place person on a previously passed edge
Definition: MSPerson.cpp:370
virtual void moveToXY(MSPerson *p, Position pos, MSLane *lane, double lanePos, double lanePosLat, double angle, int routeOffset, const ConstMSEdgeVector &edges, SUMOTime t)
try to move person to the given position
Definition: MSPModel.h:151
std::string getStageSummary() const
return string summary of the current stage
Definition: MSPerson.cpp:452