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.dev/sumo
3// Copyright (C) 2001-2023 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/****************************************************************************/
21// The class for modelling person-movements
22/****************************************************************************/
23#include <config.h>
24
25#include <string>
26#include <vector>
33#include <microsim/MSNet.h>
34#include <microsim/MSEdge.h>
35#include <microsim/MSLane.h>
39#include <microsim/MSVehicle.h>
45#include "MSPModel_Striping.h"
46#include "MSStageTrip.h"
47#include "MSPerson.h"
48#include "MSPModel.h"
49
50// ===========================================================================
51// method definitions
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, int departLane,
61 const std::string& routeID) :
62 MSStageMoving(route, routeID, toStop, speed, departPos, arrivalPos, departPosLat, departLane, MSStageType::WALKING),
63 myWalkingTime(walkingTime),
64 myExitTimes(nullptr),
65 myInternalDistance(0) {
66 myDepartPos = SUMOVehicleParameter::interpretEdgePos(departPos, route.front()->getLength(), SUMO_ATTR_DEPARTPOS,
67 "person '" + personID + "' walking from edge '" + route.front()->getID() + "'");
68 myArrivalPos = SUMOVehicleParameter::interpretEdgePos(arrivalPos, route.back()->getLength(), SUMO_ATTR_ARRIVALPOS,
69 "person '" + personID + "' walking to edge '" + route.back()->getID() + "'");
70 if (walkingTime > 0) {
72 }
73}
74
75
77 delete myExitTimes;
78}
79
80
83 std::vector<const MSEdge*> route = myRoute;
84 double departPos = myDepartPos;
85 double arrivalPos = myArrivalPos;
86 int departLane = myDepartLane;
87 if (myRouteID != "" && MSRoute::distDictionary(myRouteID) != nullptr) {
88 route = MSRoute::dictionary(myRouteID, MSRouteHandler::getParsingRNG())->getEdges();
89 if (departPos > route[0]->getLength()) {
90 WRITE_WARNINGF(TL("Adjusting departPos for cloned walk with routeDistribution '%'"), myRouteID);
91 departPos = route[0]->getLength();
92 }
93 if (arrivalPos > route.back()->getLength()) {
94 WRITE_WARNINGF(TL("Adjusting arrivalPos for cloned walk with routeDistribution '%'"), myRouteID);
95 arrivalPos = route.back()->getLength();
96 }
97 if (departLane >= route[0]->getNumLanes()) {
98 WRITE_WARNINGF(TL("Adjusting departLane for cloned walk with routeDistribution '%'"), myRouteID);
99 departLane = route[0]->getNumLanes() - 1;
100 }
101 }
102 return new MSPersonStage_Walking("dummyID", route, myDestinationStop, myWalkingTime, mySpeed, departPos, arrivalPos, myDepartPosLat, departLane, myRouteID);
103}
104
105
106void
108 myDeparted = now;
109 myRouteStep = myRoute.begin();
110 myLastEdgeEntryTime = now;
111 if (myWalkingTime == 0) {
112 if (!person->proceed(net, now)) {
114 }
115 return;
116 }
117 if (previous->getEdgePos(now) >= 0 && previous->getEdge() == *myRouteStep) {
118 myDepartPos = previous->getEdgePos(now);
119 if (myWalkingTime > 0) {
120 mySpeed = computeAverageSpeed();
121 }
122 }
123 MSTransportableControl& pControl = net->getPersonControl();
124 myState = pControl.getMovementModel()->add(person, this, now);
125 if (myState == nullptr) {
126 pControl.erase(person);
127 return;
128 }
129 const MSLane* const lane = getSidewalk<MSEdge, MSLane>(getEdge());
130 if (lane != nullptr) {
131 for (MSMoveReminder* rem : lane->getMoveReminders()) {
132 if (rem->notifyEnter(*person, MSMoveReminder::NOTIFICATION_DEPARTED, lane)) {
133 myMoveReminders.push_back(rem);
134 }
135 }
136 }
137 if (OptionsCont::getOptions().getBool("vehroute-output.exit-times")) {
138 myExitTimes = new std::vector<SUMOTime>();
139 }
140 (*myRouteStep)->addTransportable(person);
141}
142
143
144void
147}
148
149
150void
152 mySpeed = speed;
153}
154
155
156double
158 return walkDistance() / STEPS2TIME(myWalkingTime + 1); // avoid systematic rounding errors
159}
160
161
162bool
165 if (stage != nullptr) {
166 return stage->getState()->isJammed();
167 }
168 return false;
169}
170
171double
173 double length = 0;
174 auto endIt = partial && myArrived < 0 ? myRouteStep + 1 : myRoute.end();
175 for (ConstMSEdgeVector::const_iterator i = myRoute.begin(); i != endIt; ++i) {
176 length += (*i)->getLength();
177 }
178 if (myRoute.size() > 1 && MSNet::getInstance()->getPersonControl().getMovementModel()->usingInternalLanes()) {
179 if (myInternalDistance > 0) {
180 length += myInternalDistance;
181 } else {
182 // use lower bound for distance to pass the intersection
183 for (ConstMSEdgeVector::const_iterator i = myRoute.begin(); i != endIt - 1; ++i) {
184 const MSEdge* fromEdge = *i;
185 const MSEdge* toEdge = *(i + 1);
186 const MSLane* from = getSidewalk<MSEdge, MSLane>(fromEdge);
187 const MSLane* to = getSidewalk<MSEdge, MSLane>(toEdge);
188 Position fromPos;
189 Position toPos;
190 if (from != nullptr && to != nullptr) {
191 if (fromEdge->getToJunction() == toEdge->getFromJunction()) {
192 fromPos = from->getShape().back();
193 toPos = to->getShape().front();
194 } else if (fromEdge->getToJunction() == toEdge->getToJunction()) {
195 fromPos = from->getShape().back();
196 toPos = to->getShape().back();
197 } else if (fromEdge->getFromJunction() == toEdge->getFromJunction()) {
198 fromPos = from->getShape().front();
199 toPos = to->getShape().front();
200 } else if (fromEdge->getFromJunction() == toEdge->getToJunction()) {
201 fromPos = from->getShape().front();
202 toPos = to->getShape().back();
203 }
204 //std::cout << " from=" << from->getID() << " to=" << to->getID() << " junctionLength=" << fromPos.distanceTo2D(toPos) << "\n";
205 length += fromPos.distanceTo2D(toPos);
206 }
207 }
208 }
209 }
210 // determine walking direction for depart and arrival
211 const int departFwdArrivalDir = MSPModel::canTraverse(MSPModel::FORWARD, myRoute);
212 const int departBwdArrivalDir = MSPModel::canTraverse(MSPModel::BACKWARD, myRoute);
213 const bool mayStartForward = departFwdArrivalDir != MSPModel::UNDEFINED_DIRECTION;
214 const bool mayStartBackward = departBwdArrivalDir != MSPModel::UNDEFINED_DIRECTION;
215 const double arrivalPos = partial && myArrived < 0 ? getEdgePos(SIMSTEP) : myArrivalPos;
216 const double lengthFwd = (length - myDepartPos - (
217 departFwdArrivalDir == MSPModel::BACKWARD
218 ? arrivalPos
219 : myRoute.back()->getLength() - arrivalPos));
220 const double lengthBwd = (length - (myRoute.front()->getLength() - myDepartPos) - (
221 departBwdArrivalDir == MSPModel::BACKWARD
222 ? arrivalPos
223 : myRoute.back()->getLength() - arrivalPos));
224 //std::cout << " length=" << length << " lengthFwd=" << lengthFwd << " lengthBwd=" << lengthBwd << " mayStartForward=" << mayStartForward << " mayStartBackward=" << mayStartBackward << "\n";
225
226 if (myRoute.size() == 1) {
227 if (myDepartPos > myArrivalPos) {
228 length = lengthBwd;
229 } else {
230 length = lengthFwd;
231 }
232 } else {
233 if (mayStartForward && mayStartBackward) {
234 length = lengthFwd < lengthBwd ? lengthFwd : lengthBwd;
235 } else if (mayStartForward) {
236 length = lengthFwd;
237 } else if (mayStartBackward) {
238 length = lengthBwd;
239 } else {
240 length = lengthFwd;
241 }
242 }
243 //std::cout << SIMTIME << " route=" << toString(myRoute)
244 // << " depPos=" << myDepartPos << " arPos=" << myArrivalPos
245 // << " dFwdADir=" << departFwdArrivalDir
246 // << " dBwdADir=" << departBwdArrivalDir
247 // << " lengthFwd=" << lengthFwd
248 // << " lengthBwd=" << lengthBwd
249 // << "\n";
250
251 return MAX2(POSITION_EPS, length);
252}
253
254
255void
257 const double distance = walkDistance(true);
258 const double maxSpeed = getMaxSpeed(person);
259 const SUMOTime duration = myArrived - myDeparted;
260 SUMOTime timeLoss = myArrived == -1 ? 0 : duration - TIME2STEPS(distance / maxSpeed);
261 if (timeLoss < 0 && timeLoss > TIME2STEPS(-0.1)) {
262 // avoid negative timeLoss due to rounding errors
263 timeLoss = 0;
264 }
265 MSDevice_Tripinfo::addPedestrianData(distance, duration, timeLoss);
266 os.openTag("walk");
267 os.writeAttr("depart", myDeparted >= 0 ? time2string(myDeparted) : "-1");
268 os.writeAttr("departPos", myDepartPos);
269 os.writeAttr("arrival", myArrived >= 0 ? time2string(myArrived) : "-1");
270 os.writeAttr("arrivalPos", myArrived >= 0 ? toString(myArrivalPos) : "-1");
271 os.writeAttr("duration", myDeparted < 0 ? "-1" :
272 time2string(myArrived >= 0 ? duration : MSNet::getInstance()->getCurrentTimeStep() - myDeparted));
273 os.writeAttr("routeLength", myArrived >= 0 ? toString(distance) : "-1");
274 os.writeAttr("timeLoss", time2string(timeLoss));
275 os.writeAttr("maxSpeed", maxSpeed);
276 os.closeTag();
277}
278
279
280void
281MSPerson::MSPersonStage_Walking::routeOutput(const bool /* isPerson */, OutputDevice& os, const bool withRouteLength, const MSStage* const /* previous */) const {
282 os.openTag("walk").writeAttr(SUMO_ATTR_EDGES, myRoute);
283 std::string comment = "";
284 if (myDestinationStop != nullptr) {
285 os.writeAttr(toString(myDestinationStop->getElement()), myDestinationStop->getID());
286 if (myDestinationStop->getMyName() != "") {
287 comment = " <!-- " + StringUtils::escapeXML(myDestinationStop->getMyName(), true) + " -->";
288 }
289 } else if (wasSet(VEHPARS_ARRIVALPOS_SET)) {
290 os.writeAttr(SUMO_ATTR_ARRIVALPOS, myArrivalPos);
291 }
292 if (myWalkingTime > 0) {
293 os.writeAttr(SUMO_ATTR_DURATION, time2string(myWalkingTime));
294 } else if (mySpeed > 0) {
295 os.writeAttr(SUMO_ATTR_SPEED, mySpeed);
296 }
297 if (withRouteLength) {
298 if (myDeparted >= 0) {
299 os.writeAttr("routeLength", walkDistance(true));
300 } else {
301 os.writeAttr("routeLength", "-1");
302 }
303 }
304 if (myExitTimes != nullptr) {
305 std::vector<std::string> exits;
306 for (SUMOTime t : *myExitTimes) {
307 exits.push_back(time2string(t));
308 }
309 std::vector<std::string> missing(MAX2(0, (int)myRoute.size() - (int)myExitTimes->size()), "-1");
310 exits.insert(exits.end(), missing.begin(), missing.end());
311 os.writeAttr("exitTimes", exits);
312 os.writeAttr(SUMO_ATTR_STARTED, myDeparted >= 0 ? time2string(myDeparted) : "-1");
313 os.writeAttr(SUMO_ATTR_ENDED, myArrived >= 0 ? time2string(myArrived) : "-1");
314 }
315 os.closeTag(comment);
316}
317
318
319bool
320MSPerson::MSPersonStage_Walking::moveToNextEdge(MSTransportable* person, SUMOTime currentTime, int prevDir, MSEdge* nextInternal) {
321 ((MSEdge*)getEdge())->removeTransportable(person);
322 const MSLane* lane = getSidewalk<MSEdge, MSLane>(getEdge());
323 const bool arrived = myRouteStep == myRoute.end() - 1;
324 if (lane != nullptr) {
325 const double tl = person->getVehicleType().getLength();
326 const double lastPos = (arrived
327 ? (prevDir == MSPModel::FORWARD
328 ? getArrivalPos() + tl
329 : getArrivalPos() - tl)
330 : person->getPositionOnLane());
331 activateLeaveReminders(person, lane, lastPos, currentTime, arrived);
332 }
333 if (myExitTimes != nullptr && nextInternal == nullptr) {
334 myExitTimes->push_back(currentTime);
335 }
336 myMoveReminders.clear();
337 myLastEdgeEntryTime = currentTime;
338 //std::cout << SIMTIME << " moveToNextEdge person=" << person->getID() << "\n";
339 if (myCurrentInternalEdge != nullptr) {
340 myInternalDistance += (myState->getPathLength() == 0 ? myCurrentInternalEdge->getLength() : myState->getPathLength());
341 }
342 if (arrived) {
343 MSPerson* p = dynamic_cast<MSPerson*>(person);
345 myCurrentInternalEdge = nextInternal;
346 ((MSEdge*) getEdge())->addTransportable(person);
347 return false;
348 }
349 if (myDestinationStop != nullptr) {
350 myDestinationStop->addTransportable(person);
351 }
352 if (!person->proceed(MSNet::getInstance(), currentTime)) {
354 }
355 //std::cout << " end walk. myRouteStep=" << (*myRouteStep)->getID() << "\n";
356 return true;
357 } else {
358 if (nextInternal == nullptr) {
359 ++myRouteStep;
360 }
361 myCurrentInternalEdge = nextInternal;
362 ((MSEdge*) getEdge())->addTransportable(person);
363 return false;
364 }
365}
366
367
368void
369MSPerson::MSPersonStage_Walking::activateLeaveReminders(MSTransportable* person, const MSLane* lane, double lastPos, SUMOTime t, bool arrived) {
371 for (MSMoveReminder* rem : myMoveReminders) {
372 rem->updateDetector(*person, 0.0, lane->getLength(), myLastEdgeEntryTime, t, t, true);
373 rem->notifyLeave(*person, lastPos, notification);
374 }
375}
376
377
378void
380 const MSLane* nextLane = getSidewalk<MSEdge, MSLane>(getEdge());
381 if (nextLane != nullptr) {
382 for (MSMoveReminder* rem : nextLane->getMoveReminders()) {
383 if (rem->notifyEnter(*person, MSMoveReminder::NOTIFICATION_JUNCTION, nextLane)) {
384 ;
385 myMoveReminders.push_back(rem);
386 }
387 }
388 }
389}
390
391
392int
394 return (int)(myRouteStep - myRoute.begin());
395}
396
397
398double
400 return mySpeed >= 0 ? mySpeed : person->getMaxSpeed();
401}
402
403std::string
404MSPerson::MSPersonStage_Walking::getStageSummary(const bool /* isPerson */) const {
405 const std::string dest = (getDestinationStop() == nullptr ?
406 " edge '" + getDestination()->getID() + "'" :
407 " stop '" + getDestinationStop()->getID() + "'" + (
408 getDestinationStop()->getMyName() != "" ? " (" + getDestinationStop()->getMyName() + ")" : ""));
409 return "walking to " + dest;
410}
411
412
413void
415 out << " " << myDeparted << " " << (myRouteStep - myRoute.begin()) << " " << myLastEdgeEntryTime;
416 myState->saveState(out);
417}
418
419
420void
421MSPerson::MSPersonStage_Walking::loadState(MSTransportable* transportable, std::istringstream& state) {
422 int stepIdx;
423 state >> myDeparted >> stepIdx >> myLastEdgeEntryTime;
424 myRouteStep = myRoute.begin() + stepIdx;
425 myState = MSNet::getInstance()->getPersonControl().getMovementModel()->loadState(transportable, this, state);
426 if (myState->getLane() && !myState->getLane()->isNormal()) {
427 myCurrentInternalEdge = &myState->getLane()->getEdge();
428 myCurrentInternalEdge->addTransportable(transportable);
429 } else {
430 (*myRouteStep)->addTransportable(transportable);
431 }
432}
433
434
435/* -------------------------------------------------------------------------
436* MSPerson::MSPersonStage_Access - methods
437* ----------------------------------------------------------------------- */
439 const double arrivalPos, const double dist, const bool isExit) :
440 MSStage(destination, toStop, arrivalPos, MSStageType::ACCESS),
441 myOrigin(origin),
442 myDist(dist), myAmExit(isExit) {
443 const MSEdge* accessEdge = myAmExit ? destination : origin;
444 myPath.push_back(accessEdge->getLanes()[0]->geometryPositionAtOffset(myDestinationStop->getAccessPos(accessEdge)));
445 myPath.push_back(toStop->getCenterPos());
446 if (isExit) {
448 }
449}
450
451
453
454MSStage*
456 return new MSPersonStage_Access(myOrigin, myDestination, myDestinationStop, myArrivalPos, myDist, myAmExit);
457}
458
459void
461 myDeparted = now;
462 myEstimatedArrival = now + TIME2STEPS(myDist / person->getMaxSpeed());
463 net->getBeginOfTimestepEvents()->addEvent(new ProceedCmd(person, &myDestinationStop->getLane().getEdge()), myEstimatedArrival);
465 myDestinationStop->getLane().getEdge().addTransportable(person);
466}
467
468
469std::string
471 return "access";
472}
473
474
475std::string
476MSPerson::MSPersonStage_Access::getStageSummary(const bool /* isPerson */) const {
477 return (myAmExit ? "access from stop '" : "access to stop '") + getDestinationStop()->getID() + "'";
478}
479
480
483 return myPath.positionAtOffset(myPath.length() * (double)(now - myDeparted) / (double)(myEstimatedArrival - myDeparted));
484}
485
486
487double
489 return myPath.angleAt2D(0);
490}
491
492
493double
495 return myDist / STEPS2TIME(MAX2((SUMOTime)1, myEstimatedArrival - myDeparted));
496}
497
498void
500 os.openTag("access");
501 os.writeAttr("stop", getDestinationStop()->getID());
502 os.writeAttr("depart", time2string(myDeparted));
503 os.writeAttr("arrival", myArrived >= 0 ? time2string(myArrived) : "-1");
504 os.writeAttr("duration", myArrived > 0 ? time2string(myArrived - myDeparted) : "-1");
505 os.writeAttr("routeLength", myDist);
506 os.closeTag();
507}
508
509
513 myStopEdge->removeTransportable(myPerson);
514 if (!myPerson->proceed(MSNet::getInstance(), currentTime)) {
516 }
517 return 0;
518}
519
520
521/* -------------------------------------------------------------------------
522 * MSPerson - methods
523 * ----------------------------------------------------------------------- */
525 MSTransportable(pars, vtype, plan, true),
526 myInfluencer(nullptr),
527 myChosenSpeedFactor(pars->speedFactor < 0 ? speedFactor : pars->speedFactor)
528{ }
529
530
532 delete myInfluencer;
533}
534
535
536bool
537MSPerson::checkAccess(const MSStage* const prior, const bool waitAtStop) {
538 MSStoppingPlace* prevStop = prior->getDestinationStop();
539 if (!waitAtStop && prior->getStageType() == MSStageType::TRIP) {
540 prevStop = dynamic_cast<const MSStageTrip*>(prior)->getOriginStop();
541 }
542 if (prevStop != nullptr) {
543 const MSEdge* stopEdge = &prevStop->getLane().getEdge();
544 if (waitAtStop) {
545 const double accessDist = prevStop->getAccessDistance(prior->getDestination());
546 if (accessDist > 0.) {
547 const double arrivalAtBs = (prevStop->getBeginLanePosition() + prevStop->getEndLanePosition()) / 2;
548 myStep = myPlan->insert(myStep, new MSPersonStage_Access(prior->getDestination(), stopEdge, prevStop, arrivalAtBs, accessDist, false));
549 return true;
550 }
551 } else {
552 const double accessDist = prevStop->getAccessDistance((*myStep)->getFromEdge());
553 if (accessDist > 0.) {
554 myStep = myPlan->insert(myStep, new MSPersonStage_Access(stopEdge, (*myStep)->getFromEdge(), prevStop, prevStop->getAccessPos((*myStep)->getFromEdge()), accessDist, true));
555 return true;
556 }
557 }
558 }
559 return false;
560}
561
562
563double
565 return MAX2(0., MIN2(1., getVehicleType().getImpatience()
566 + STEPS2TIME((*myStep)->getWaitingTime(SIMSTEP)) / MSPModel_Striping::MAX_WAIT_TOLERANCE));
567}
568
569const std::string&
571// if (getCurrentStageType() == WALKING) {
572// MSPersonStage_Walking* walkingStage = dynamic_cast<MSPersonStage_Walking*>(*myStep);
573// assert(walkingStage != 0);
574// const MSEdge* nextEdge = walkingStage->getPedestrianState()->getNextEdge(*walkingStage);
575// if (nextEdge != 0) {
576// return nextEdge->getID();
577// }
578// }
579// return StringUtils::emptyString;
580 const MSEdge* nextEdge = getNextEdgePtr();
581 if (nextEdge != nullptr) {
582 return nextEdge->getID();
583 }
585}
586
587
588const MSEdge*
591 MSPersonStage_Walking* walkingStage = dynamic_cast<MSPersonStage_Walking*>(*myStep);
592 assert(walkingStage != nullptr);
593 return walkingStage->getState()->getNextEdge(*walkingStage);
594 }
595 return nullptr;
596}
597
598
599
600void
601MSPerson::reroute(ConstMSEdgeVector& newEdges, double departPos, int firstIndex, int nextIndex) {
602 assert(nextIndex > firstIndex);
603 //std::cout << SIMTIME << " reroute person " << getID()
604 // << " newEdges=" << toString(newEdges)
605 // << " firstIndex=" << firstIndex
606 // << " nextIndex=" << nextIndex
607 // << " departPos=" << getEdgePos()
608 // << " arrivalPos=" << getNextStage(nextIndex - 1)->getArrivalPos()
609 // << "\n";
611 getNextStage(nextIndex - 1)->getDestinationStop(), -1,
612 -1,
613 departPos,
614 getNextStage(nextIndex - 1)->getArrivalPos(),
616 appendStage(newStage, nextIndex);
617 // remove stages in reverse order so that proceed will only be called at the last removal
618 for (int i = nextIndex - 1; i >= firstIndex; i--) {
619 //std::cout << " removeStage=" << i << "\n";
620 removeStage(i);
621 }
622}
623
624
627 if (myInfluencer == nullptr) {
628 myInfluencer = new Influencer();
629 }
630 return *myInfluencer;
631}
632
633
636 return myInfluencer;
637}
638
639
640
641/* -------------------------------------------------------------------------
642 * methods of MSPerson::Influencer
643 * ----------------------------------------------------------------------- */
645
646
648
649
650void
651MSPerson::Influencer::setRemoteControlled(Position xyPos, MSLane* l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector& route, SUMOTime t) {
652 myRemoteXYPos = xyPos;
653 myRemoteLane = l;
654 myRemotePos = pos;
655 myRemotePosLat = posLat;
656 myRemoteAngle = angle;
657 myRemoteEdgeOffset = edgeOffset;
658 myRemoteRoute = route;
659 myLastRemoteAccess = t;
660}
661
662
663bool
665 return myLastRemoteAccess == MSNet::getInstance()->getCurrentTimeStep();
666}
667
668
669bool
671 return myLastRemoteAccess >= t - TIME2STEPS(10);
672}
673
674
675void
677 /*
678 std::cout << SIMTIME << " moveToXY person=" << p->getID()
679 << " xyPos=" << myRemoteXYPos
680 << " lane=" << Named::getIDSecure(myRemoteLane)
681 << " pos=" << myRemotePos
682 << " posLat=" << myRemotePosLat
683 << " angle=" << myRemoteAngle
684 << " eOf=" << myRemoteEdgeOffset
685 << " route=" << toString(myRemoteRoute)
686 << " aTime=" << time2string(myLastRemoteAccess)
687 << "\n";
688 */
689 switch (p->getStageType(0)) {
692 assert(s != nullptr);
693 s->getState()->moveToXY(p, myRemoteXYPos, myRemoteLane, myRemotePos, myRemotePosLat, myRemoteAngle, myRemoteEdgeOffset, myRemoteRoute,
694 MSNet::getInstance()->getCurrentTimeStep());
695 }
696 break;
697 default:
698 break;
699 }
700}
701
702
703/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
MSStageType
Definition: MSStage.h:54
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:271
#define TL(string)
Definition: MsgHandler.h:287
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 TIME2STEPS(x)
Definition: SUMOTime.h:57
const int VEHPARS_ARRIVALPOS_SET
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_STARTED
@ SUMO_ATTR_ARRIVALPOS
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_DEPARTPOS
@ SUMO_ATTR_ENDED
@ SUMO_ATTR_DURATION
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
static void addPedestrianData(double walkLength, SUMOTime walkDuration, SUMOTime walkTimeLoss)
record tripinfo data for pedestrians
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
const MSJunction * getToJunction() const
Definition: MSEdge.h:415
const MSJunction * getFromJunction() const
Definition: MSEdge.h:411
virtual void addTransportable(MSTransportable *t) const
Definition: MSEdge.cpp:1086
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
const std::vector< MSMoveReminder * > & getMoveReminders() const
Return the list of this lane's move reminders.
Definition: MSLane.h:314
double getLength() const
Returns the lane's length.
Definition: MSLane.h:593
virtual const PositionVector & getShape(bool) const
Definition: MSLane.h:293
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:745
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
@ NOTIFICATION_ARRIVED
The vehicle arrived at its destination (is deleted)
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
The simulated network and simulation perfomer.
Definition: MSNet.h:88
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:183
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:473
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:322
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1172
static const double MAX_WAIT_TOLERANCE
static const int BACKWARD
Definition: MSPModel.h:120
static int canTraverse(int dir, const ConstMSEdgeVector &route)
Definition: MSPModel.cpp:54
static const int FORWARD
Definition: MSPModel.h:119
virtual MSTransportableStateAdapter * add(MSTransportable *transportable, MSStageMoving *stage, SUMOTime now)=0
register the given person as a pedestrian
virtual MSTransportableStateAdapter * loadState(MSTransportable *transportable, MSStageMoving *stage, std::istringstream &state)
load the state of the given transportable
Definition: MSPModel.h:60
virtual bool usingInternalLanes()=0
whether movements on intersections are modelled
virtual void remove(MSTransportableStateAdapter *state)=0
remove the specified person from the pedestrian simulation
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:121
static const double UNSPECIFIED_POS_LAT
the default lateral offset for persons when starting a walk
Definition: MSPModel.h:130
Changes the wished person speed and position.
Definition: MSPerson.h:289
void postProcessRemoteControl(MSPerson *p)
Definition: MSPerson.cpp:676
Influencer()
Constructor.
Definition: MSPerson.cpp:644
void setRemoteControlled(Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector &route, SUMOTime t)
Definition: MSPerson.cpp:651
~Influencer()
Destructor.
Definition: MSPerson.cpp:647
bool isRemoteAffected(SUMOTime t) const
Definition: MSPerson.cpp:670
bool isRemoteControlled() const
Definition: MSPerson.cpp:664
SUMOTime execute(SUMOTime currentTime)
Executes the command.
Definition: MSPerson.cpp:511
Position getPosition(SUMOTime now) const
returns the position of the transportable
Definition: MSPerson.cpp:482
double getSpeed() const
the speed of the person in this stage
Definition: MSPerson.cpp:494
void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const
Called on writing tripinfo output.
Definition: MSPerson.cpp:499
MSPersonStage_Access(const MSEdge *origin, const MSEdge *destination, MSStoppingPlace *toStop, const double arrivalPos, const double dist, const bool isExit)
constructor
Definition: MSPerson.cpp:438
virtual void proceed(MSNet *net, MSTransportable *person, SUMOTime now, MSStage *previous)
proceeds to the next step
Definition: MSPerson.cpp:460
double getAngle(SUMOTime now) const
returns the angle of the transportable
Definition: MSPerson.cpp:488
std::string getStageDescription(const bool isPerson) const
returns the stage description as a string
Definition: MSPerson.cpp:470
std::string getStageSummary(const bool isPerson) const
return string summary of the current stage
Definition: MSPerson.cpp:476
virtual void routeOutput(const bool isPerson, OutputDevice &os, const bool withRouteLength, const MSStage *const previous) const
Called on writing vehroute output.
Definition: MSPerson.cpp:281
virtual void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const
Called on writing tripinfo output.
Definition: MSPerson.cpp:256
void setSpeed(double speed)
sets the walking speed (ignored in other stages)
Definition: MSPerson.cpp:151
double computeAverageSpeed() const
Definition: MSPerson.cpp:157
double walkDistance(bool partial=false) const
compute total walking distance
Definition: MSPerson.cpp:172
bool moveToNextEdge(MSTransportable *person, SUMOTime currentTime, int prevDir, MSEdge *nextInternal=nullptr)
move forward and return whether the person arrived
Definition: MSPerson.cpp:320
double getMaxSpeed(const MSTransportable *const person) const
accessors to be used by MSPModel
Definition: MSPerson.cpp:399
void loadState(MSTransportable *transportable, std::istringstream &state)
Reconstructs the current state.
Definition: MSPerson.cpp:421
std::string getStageSummary(const bool isPerson) const
return string summary of the current stage
Definition: MSPerson.cpp:404
virtual void proceed(MSNet *net, MSTransportable *person, SUMOTime now, MSStage *previous)
proceeds to the next step
Definition: MSPerson.cpp:107
void activateEntryReminders(MSTransportable *person)
Definition: MSPerson.cpp:379
void activateLeaveReminders(MSTransportable *person, const MSLane *lane, double lastPos, SUMOTime t, bool arrived)
Definition: MSPerson.cpp:369
int getRoutePosition() const
return index of current edge within route
Definition: MSPerson.cpp:393
MSPersonStage_Walking(const std::string &personID, const ConstMSEdgeVector &route, MSStoppingPlace *toStop, SUMOTime walkingTime, double speed, double departPos, double arrivalPos, double departPosLat, int departLane=-1, const std::string &routeID="")
constructor
Definition: MSPerson.cpp:56
void abort(MSTransportable *)
abort this stage (TraCI)
Definition: MSPerson.cpp:145
void saveState(std::ostringstream &out)
Saves the current state into the given stream.
Definition: MSPerson.cpp:414
bool checkAccess(const MSStage *const prior, const bool waitAtStop=true)
Definition: MSPerson.cpp:537
Influencer * myInfluencer
An instance of a speed/position influencing instance; built in "getInfluencer".
Definition: MSPerson.h:341
const MSEdge * getNextEdgePtr() const
returns the next edge ptr if this person is walking and the pedestrian model allows it
Definition: MSPerson.cpp:589
double getImpatience() const
Definition: MSPerson.cpp:564
void reroute(ConstMSEdgeVector &newEdges, double departPos, int firstIndex, int nextIndex)
set new walk and replace the stages with relative indices in the interval [firstIndex,...
Definition: MSPerson.cpp:601
double myChosenSpeedFactor
Definition: MSPerson.h:343
bool isJammed() const
whether the person is jammed as defined by the current pedestrian model
Definition: MSPerson.cpp:163
bool hasInfluencer() const
whether the vehicle is individually influenced (via TraCI or special parameters)
Definition: MSPerson.h:332
virtual ~MSPerson()
destructor
Definition: MSPerson.cpp:531
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition: MSPerson.cpp:626
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:570
MSPerson(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan, const double speedFactor)
constructor
Definition: MSPerson.cpp:524
static SumoRNG * getParsingRNG()
get parsing RNG
static bool dictionary(const std::string &id, ConstMSRoutePtr route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:109
static RandomDistributor< ConstMSRoutePtr > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition: MSRoute.cpp:161
const MSEdge * getDestination() const
returns the destination edge
Definition: MSStage.cpp:61
virtual double getEdgePos(SUMOTime now) const
Definition: MSStage.cpp:79
MSStoppingPlace * myDestinationStop
the stop to reach by getting transported (if any)
Definition: MSStage.h:238
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
Definition: MSStage.h:80
MSStageType getStageType() const
Definition: MSStage.h:117
virtual const MSEdge * getEdge() const
Returns the current edge.
Definition: MSStage.cpp:67
double myArrivalPos
the position at which we want to arrive
Definition: MSStage.h:241
virtual MSTransportableStateAdapter * getState() const
Definition: MSStageMoving.h:49
double mySpeed
the speed of the transportable
double myDepartPos
the depart position
A lane area vehicles can halt at.
double getBeginLanePosition() const
Returns the begin position of this stop.
Position getCenterPos() const
the position in the middle of the stop shape
double getAccessDistance(const MSEdge *edge) const
the distance from the access on the given edge to the stop, -1 on failure
double getEndLanePosition() const
Returns the end position of this stop.
const MSLane & getLane() const
Returns the lane this stop is located at.
double getAccessPos(const MSEdge *edge) const
the position on the given edge which is connected to this stop, -1 on failure
MSPModel * getMovementModel()
Returns the default movement model for this kind of transportables.
virtual void erase(MSTransportable *transportable)
removes a single transportable
virtual double getEdgePos() const
Return the position on the edge.
const MSLane * getLane() const
Returns the current lane (may be nullptr)
const MSEdge * getDestination() const
Returns the current destination.
MSStageType getStageType(int next) const
the stage type for the nth next stage
MSStage * getCurrentStage() const
Return the current stage.
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
double getArrivalPos() const
returns the final arrival pos
double getPositionOnLane() const
Get the object's position along the lane.
const MSVehicleType & getVehicleType() const
Returns the object's "vehicle" type.
MSStageType getCurrentStageType() const
the current stage type of the transportable
MSStage * getNextStage(int next) const
Return the current stage.
void appendStage(MSStage *stage, int next=-1)
Appends the given stage to the current plan.
const MSEdge * getEdge() const
Returns the current edge.
std::vector< MSStage * > MSTransportablePlan
the structure holding the plan of a transportable
double getMaxSpeed() const
Returns the maximum speed (the minimum of desired and physical maximum speed)
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 transportable to the given position
Definition: MSPModel.h:186
virtual const MSLane * getLane() const
whether the transportable is jammed
Definition: MSPModel.h:207
virtual bool isJammed() const
whether the transportable is jammed
Definition: MSPModel.h:202
virtual const MSEdge * getNextEdge(const MSStageMoving &stage) const =0
return the list of internal edges if the transportable is on an intersection
The car-following model and parameter.
Definition: MSVehicleType.h:63
double getLength() const
Get vehicle's length [m].
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
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:254
PositionVector reverse() const
reverse position vector
Structure representing possible vehicle parameter.
static double interpretEdgePos(double pos, double maximumValue, SumoXMLAttr attr, const std::string &id, bool silent=false)
Interprets negative edge positions and fits them onto a given edge.
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
static std::string emptyString
An empty string.
Definition: StringUtils.h:86