Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-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/****************************************************************************/
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>
46#include "MSPModel_Striping.h"
47#include "MSStageTrip.h"
48#include "MSStageWalking.h"
49#include "MSPerson.h"
50
51
52// ===========================================================================
53// method definitions
54// ===========================================================================
55/* -------------------------------------------------------------------------
56* MSPerson::MSPersonStage_Access - methods
57* ----------------------------------------------------------------------- */
59 const double arrivalPos, const double arrivalPosLat, const double dist, const bool isExit,
60 const Position& startPos, const Position& endPos) :
61 MSStage(MSStageType::ACCESS, destination, toStop, arrivalPos, arrivalPosLat),
62 myDist(dist), myAmExit(isExit) {
63 myPath.push_back(startPos);
64 myPath.push_back(endPos);
65}
66
67
69
72 return new MSPersonStage_Access(myDestination, myDestinationStop, myArrivalPos, myArrivalPosLat, myDist, myAmExit, myPath.front(), myPath.back());
73}
74
75void
77 myDeparted = now;
78 myEstimatedArrival = now + TIME2STEPS(myDist / person->getMaxSpeed());
79 // TODO myEstimatedArrival is not a multiple of DELTA_T here. This might give a problem because the destination position will not be reached precisely
80 net->getBeginOfTimestepEvents()->addEvent(new ProceedCmd(person, &myDestinationStop->getLane().getEdge()), myEstimatedArrival);
82 myDestinationStop->getLane().getEdge().addTransportable(person);
83}
84
85
86std::string
88 return "access";
89}
90
91
92std::string
93MSPerson::MSPersonStage_Access::getStageSummary(const bool /* isPerson */) const {
94 return (myAmExit ? "access from stop '" : "access to stop '") + getDestinationStop()->getID() + "'";
95}
96
97
100 return myPath.positionAtOffset(myPath.length() * (double)(now - myDeparted) / (double)(myEstimatedArrival - myDeparted));
101}
102
103
104double
106 return myPath.angleAt2D(0);
107}
108
109
110double
112 return myDist / STEPS2TIME(MAX2((SUMOTime)1, myEstimatedArrival - myDeparted));
113}
114
115void
117 os.openTag("access");
118 os.writeAttr("stop", getDestinationStop()->getID());
119 os.writeAttr("depart", time2string(myDeparted));
120 os.writeAttr("arrival", myArrived >= 0 ? time2string(myArrived) : "-1");
121 os.writeAttr("duration", myArrived > 0 ? time2string(getDuration()) : "-1");
122 os.writeAttr("routeLength", myDist);
123 os.closeTag();
124}
125
126
130 myStopEdge->removeTransportable(myPerson);
131 if (!myPerson->proceed(MSNet::getInstance(), currentTime)) {
133 }
134 return 0;
135}
136
137
138/* -------------------------------------------------------------------------
139 * MSPerson - methods
140 * ----------------------------------------------------------------------- */
142 MSTransportable(pars, vtype, plan, true),
143 myInfluencer(nullptr),
144 myChosenSpeedFactor(pars->speedFactor < 0 ? speedFactor : pars->speedFactor),
145 myTimegapCrossing(getFloatParam("pedestrian.timegap-crossing"))
146{ }
147
148
152
153
154bool
155MSPerson::checkAccess(const MSStage* const prior, const bool waitAtStop) {
156 MSStoppingPlace* prevStop = prior->getDestinationStop();
157 if (!waitAtStop && prior->getStageType() == MSStageType::TRIP) {
158 prevStop = prior->getOriginStop();
159 }
160 if (prevStop != nullptr) {
161 const MSEdge* const accessEdge = waitAtStop ? prior->getDestination() : (*myStep)->getFromEdge();
162 const MSStoppingPlace::Access* const access = prevStop->getAccess(accessEdge);
163 if (access != nullptr) {
164 const MSLane* const lane = accessEdge->getLanes()[0];
165 MSStage* newStage = nullptr;
166 if (waitAtStop) {
167 const MSEdge* const stopEdge = &prevStop->getLane().getEdge();
168 const double arrivalAtBs = (prevStop->getBeginLanePosition() + prevStop->getEndLanePosition()) / 2;
169 newStage = new MSPersonStage_Access(stopEdge, prevStop, arrivalAtBs, 0.0, access->length, false,
170 lane->geometryPositionAtOffset(access->endPos),
171 prevStop->getLane().geometryPositionAtOffset(arrivalAtBs));
172 } else {
173 const bool useDoors = access->exit == MSStoppingPlace::AccessExit::DOORS ||
174 (OptionsCont::getOptions().getString("pedestrian.model") != "jupedsim" && access->exit == MSStoppingPlace::AccessExit::CARRIAGE);
176 const double startPos = prior->getStageType() == MSStageType::TRIP ? prior->getEdgePos(0) : prior->getArrivalPos();
177 const double startPosLat = prior->getStageType() == MSStageType::TRIP ? prior->getEdgePosLat(0) : prior->getArrivalPosLat();
178 // The start and end attributes of the access stage are equal in this case, but we need to compute the arrival position relatively
179 // to the current lane and not the lane of the previous stage.
180 const Position start = prevStop->getLane().geometryPositionAtOffset(startPos, startPosLat);
181 const Position end = lane->getShape().transformToVectorCoordinates(start);
182 newStage = new MSPersonStage_Access(accessEdge, prevStop, end.x(), -end.y(), access->length, true, start, start);
183 } else {
184 const double startPos = prior->getStageType() == MSStageType::TRIP ? prior->getEdgePos(0) : prior->getArrivalPos();
185 const Position& trainExit = prevStop->getLane().geometryPositionAtOffset(startPos);
186 const double arrivalPos = useDoors ? lane->getShape().nearest_offset_to_point2D(trainExit) : access->endPos;
187 Position platformEntry = lane->geometryPositionAtOffset(arrivalPos);
188 if (useDoors) {
189 // find the closer side of the platform to enter
190 const double halfWidth = lane->getWidth() / 2. - MAX2(getVehicleType().getLength(), getVehicleType().getWidth()) / 2. - POSITION_EPS;
191 platformEntry = lane->geometryPositionAtOffset(arrivalPos, halfWidth);
192 const Position& plat2 = lane->geometryPositionAtOffset(arrivalPos, -halfWidth);
193 if (trainExit.distanceSquaredTo2D(plat2) < trainExit.distanceSquaredTo2D(platformEntry)) {
194 platformEntry = plat2;
195 }
196 }
197 newStage = new MSPersonStage_Access(accessEdge, prevStop, arrivalPos, 0.0, access->length, true,
198 trainExit, platformEntry);
199 }
200 }
201 newStage->setTrip(prior->getTrip());
202 myStep = myPlan->insert(myStep, newStage);
203 return true;
204 }
205 }
206 return false;
207}
208
209
210double
212 return MAX2(0., MIN2(1., getVehicleType().getImpatience()
213 + STEPS2TIME((*myStep)->getWaitingTime(SIMSTEP)) / MSPModel_Striping::MAX_WAIT_TOLERANCE));
214}
215
216const std::string&
218// if (getCurrentStageType() == WALKING) {
219// MSStageWalking* walkingStage = dynamic_cast<MSStageWalking*>(*myStep);
220// assert(walkingStage != 0);
221// const MSEdge* nextEdge = walkingStage->getPedestrianState()->getNextEdge(*walkingStage);
222// if (nextEdge != 0) {
223// return nextEdge->getID();
224// }
225// }
226// return StringUtils::emptyString;
227 const MSEdge* nextEdge = getNextEdgePtr();
228 if (nextEdge != nullptr) {
229 return nextEdge->getID();
230 }
232}
233
234
235const MSEdge*
238 MSStageWalking* walkingStage = dynamic_cast<MSStageWalking*>(*myStep);
239 assert(walkingStage != nullptr);
240 return walkingStage->getPState()->getNextEdge(*walkingStage);
241 }
242 return nullptr;
243}
244
245
246
247void
248MSPerson::replaceWalk(const ConstMSEdgeVector& newEdges, double departPos, int firstIndex, int nextIndex) {
249 assert(nextIndex > firstIndex);
250 //std::cout << SIMTIME << " reroute person " << getID()
251 // << " newEdges=" << toString(newEdges)
252 // << " firstIndex=" << firstIndex
253 // << " nextIndex=" << nextIndex
254 // << " departPos=" << getEdgePos()
255 // << " arrivalPos=" << getNextStage(nextIndex - 1)->getArrivalPos()
256 // << "\n";
257 MSStage* const toBeReplaced = getNextStage(nextIndex - 1);
258 MSStageWalking* newStage = new MSStageWalking(getID(), newEdges,
259 toBeReplaced->getDestinationStop(), -1,
260 -1,
261 departPos,
262 toBeReplaced->getArrivalPos(),
264 appendStage(newStage, nextIndex);
265 // remove stages in reverse order so that proceed will only be called at the last removal
266 for (int i = nextIndex - 1; i >= firstIndex; i--) {
267 //std::cout << " removeStage=" << i << "\n";
268 removeStage(i);
269 }
270}
271
272
275 if (myInfluencer == nullptr) {
276 myInfluencer = new Influencer();
277 }
278 return *myInfluencer;
279}
280
281
284 return myInfluencer;
285}
286
287
288
289/* -------------------------------------------------------------------------
290 * methods of MSPerson::Influencer
291 * ----------------------------------------------------------------------- */
293
294
296
297
298void
299MSPerson::Influencer::setRemoteControlled(Position xyPos, MSLane* l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector& route, SUMOTime t) {
300 myRemoteXYPos = xyPos;
301 myRemoteLane = l;
302 myRemotePos = pos;
303 myRemotePosLat = posLat;
304 myRemoteAngle = angle;
305 myRemoteEdgeOffset = edgeOffset;
306 myRemoteRoute = route;
307 myLastRemoteAccess = t;
308}
309
310
311bool
313 return myLastRemoteAccess == MSNet::getInstance()->getCurrentTimeStep();
314}
315
316
317bool
319 return myLastRemoteAccess >= t - TIME2STEPS(10);
320}
321
322
323void
325 /*
326 std::cout << SIMTIME << " moveToXY person=" << p->getID()
327 << " xyPos=" << myRemoteXYPos
328 << " lane=" << Named::getIDSecure(myRemoteLane)
329 << " pos=" << myRemotePos
330 << " posLat=" << myRemotePosLat
331 << " angle=" << myRemoteAngle
332 << " eOf=" << myRemoteEdgeOffset
333 << " route=" << toString(myRemoteRoute)
334 << " aTime=" << time2string(myLastRemoteAccess)
335 << "\n";
336 */
337 switch (p->getStageType(0)) {
339 MSStageWalking* s = dynamic_cast<MSStageWalking*>(p->getCurrentStage());
340 assert(s != nullptr);
341 s->getPState()->moveToXY(p, myRemoteXYPos, myRemoteLane, myRemotePos, myRemotePosLat,
342 myRemoteAngle, myRemoteEdgeOffset, myRemoteRoute,
343 MSNet::getInstance()->getCurrentTimeStep());
344 }
345 break;
346 default:
347 break;
348 }
349}
350
351
352/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSPerson.h:51
MSStageType
Definition MSStage.h:55
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
T MIN2(T a, T b)
Definition StdDefs.h:76
T MAX2(T a, T b)
Definition StdDefs.h:82
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 addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
Representation of a lane in the micro simulation.
Definition MSLane.h:84
virtual const PositionVector & getShape(bool) const
Definition MSLane.h:294
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:764
double getWidth() const
Returns the lane's width.
Definition MSLane.h:635
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition MSLane.h:560
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:186
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition MSNet.h:471
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:320
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1190
static const double MAX_WAIT_TOLERANCE
the time pedestrians take to reach maximum impatience
static const double UNSPECIFIED_POS_LAT
the default lateral offset for persons when starting a walk
Definition MSPModel.h:65
Changes the wished person speed and position.
Definition MSPerson.h:179
void postProcessRemoteControl(MSPerson *p)
Definition MSPerson.cpp:324
Influencer()
Constructor.
Definition MSPerson.cpp:292
void setRemoteControlled(Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector &route, SUMOTime t)
Definition MSPerson.cpp:299
~Influencer()
Destructor.
Definition MSPerson.cpp:295
bool isRemoteAffected(SUMOTime t) const
Definition MSPerson.cpp:318
bool isRemoteControlled() const
Definition MSPerson.cpp:312
SUMOTime execute(SUMOTime currentTime)
Executes the command.
Definition MSPerson.cpp:128
Position getPosition(SUMOTime now) const
returns the position of the transportable
Definition MSPerson.cpp:99
MSPersonStage_Access(const MSEdge *destination, MSStoppingPlace *toStop, const double arrivalPos, const double arrivalPosLat, const double dist, const bool isExit, const Position &startPos, const Position &endPos)
constructor
Definition MSPerson.cpp:58
double getSpeed() const
the speed of the person in this stage
Definition MSPerson.cpp:111
void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const
Called on writing tripinfo output.
Definition MSPerson.cpp:116
virtual void proceed(MSNet *net, MSTransportable *person, SUMOTime now, MSStage *previous)
proceeds to the next step
Definition MSPerson.cpp:76
double getAngle(SUMOTime now) const
returns the angle of the transportable
Definition MSPerson.cpp:105
std::string getStageDescription(const bool isPerson) const
returns the stage description as a string
Definition MSPerson.cpp:87
std::string getStageSummary(const bool isPerson) const
return string summary of the current stage
Definition MSPerson.cpp:93
bool checkAccess(const MSStage *const prior, const bool waitAtStop=true)
Definition MSPerson.cpp:155
Influencer * myInfluencer
An instance of a speed/position influencing instance; built in "getInfluencer".
Definition MSPerson.h:231
const MSEdge * getNextEdgePtr() const
returns the next edge ptr if this person is walking and the pedestrian model allows it
Definition MSPerson.cpp:236
double getImpatience() const
Definition MSPerson.cpp:211
double myChosenSpeedFactor
Definition MSPerson.h:233
double myTimegapCrossing
value may be sampled from distribution and therefore must be cached
Definition MSPerson.h:236
void replaceWalk(const 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:248
virtual ~MSPerson()
destructor
Definition MSPerson.cpp:149
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition MSPerson.cpp:274
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:217
MSPerson(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan, const double speedFactor)
constructor
Definition MSPerson.cpp:141
const MSEdge * getDestination() const
returns the destination edge
Definition MSStage.cpp:65
virtual double getEdgePos(SUMOTime now) const
Definition MSStage.cpp:83
virtual double getEdgePosLat(SUMOTime now) const
Definition MSStage.cpp:89
MSStageTrip * getTrip() const
Definition MSStage.h:268
virtual double getArrivalPos() const
Definition MSStage.h:94
void setTrip(MSStageTrip *trip)
Definition MSStage.h:272
virtual MSStoppingPlace * getOriginStop() const
returns the origin stop (if any). only needed for MSStageTrip
Definition MSStage.h:90
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
Definition MSStage.h:85
MSStageType getStageType() const
Definition MSStage.h:127
virtual double getArrivalPosLat() const
Definition MSStage.h:98
MSTransportableStateAdapter * getPState() const
A lane area vehicles can halt at.
const Access * getAccess(const MSEdge *edge) const
the access on the given edge to the stop, nullptr if there is none
double getBeginLanePosition() const
Returns the begin position of this stop.
double getEndLanePosition() const
Returns the end position of this stop.
const MSLane & getLane() const
Returns the lane this stop is located at.
virtual void erase(MSTransportable *transportable)
removes a single transportable
const MSLane * getLane() const
Returns the current lane (may be nullptr)
MSStageType getStageType(int next) const
the stage type for the nth next stage
MSStage * getNextStage(int offset) const
Return the next (or previous) stage denoted by the offset.
MSStage * getCurrentStage() const
Return the current stage.
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
const MSVehicleType & getVehicleType() const
Returns the object's "vehicle" type.
MSStageType getCurrentStageType() const
the current stage type of the transportable
void appendStage(MSStage *stage, int next=-1)
Appends the given stage to the current plan.
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:190
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.
const std::string & getID() const
Returns the id.
Definition Named.h:74
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double distanceSquaredTo2D(const Position &p2) const
returns the square of the distance to another position (Only using x and y positions)
Definition Position.h:281
double x() const
Returns the x-position.
Definition Position.h:55
double y() const
Returns the y-position.
Definition Position.h:60
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
Position transformToVectorCoordinates(const Position &p, bool extend=false) const
return position p within the length-wise coordinate system defined by this position vector....
double getFloatParam(const std::string &paramName, const bool required=false, const double deflt=INVALID_DOUBLE) const
Retrieve a floating point parameter for the traffic object.
Structure representing possible vehicle parameter.
static std::string emptyString
An empty string.
Definition StringUtils.h:91