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{ }
146
147
151
152
153bool
154MSPerson::checkAccess(const MSStage* const prior, const bool waitAtStop) {
155 MSStoppingPlace* prevStop = prior->getDestinationStop();
156 if (!waitAtStop && prior->getStageType() == MSStageType::TRIP) {
157 prevStop = prior->getOriginStop();
158 }
159 if (prevStop != nullptr) {
160 const MSEdge* const accessEdge = waitAtStop ? prior->getDestination() : (*myStep)->getFromEdge();
161 const MSStoppingPlace::Access* const access = prevStop->getAccess(accessEdge);
162 if (access != nullptr) {
163 const MSLane* const lane = accessEdge->getLanes()[0];
164 MSStage* newStage = nullptr;
165 if (waitAtStop) {
166 const MSEdge* const stopEdge = &prevStop->getLane().getEdge();
167 const double arrivalAtBs = (prevStop->getBeginLanePosition() + prevStop->getEndLanePosition()) / 2;
168 newStage = new MSPersonStage_Access(stopEdge, prevStop, arrivalAtBs, 0.0, access->length, false,
169 lane->geometryPositionAtOffset(access->endPos),
170 prevStop->getLane().geometryPositionAtOffset(arrivalAtBs));
171 } else {
172 const bool useDoors = access->exit == MSStoppingPlace::AccessExit::DOORS ||
173 (OptionsCont::getOptions().getString("pedestrian.model") != "jupedsim" && access->exit == MSStoppingPlace::AccessExit::CARRIAGE);
175 const double startPos = prior->getStageType() == MSStageType::TRIP ? prior->getEdgePos(0) : prior->getArrivalPos();
176 const double startPosLat = prior->getStageType() == MSStageType::TRIP ? prior->getEdgePosLat(0) : prior->getArrivalPosLat();
177 // The start and end attributes of the access stage are equal in this case, but we need to compute the arrival position relatively
178 // to the current lane and not the lane of the previous stage.
179 const Position start = prevStop->getLane().geometryPositionAtOffset(startPos, startPosLat);
180 const Position end = lane->getShape().transformToVectorCoordinates(start);
181 newStage = new MSPersonStage_Access(accessEdge, prevStop, end.x(), -end.y(), access->length, true, start, start);
182 } else {
183 const double startPos = prior->getStageType() == MSStageType::TRIP ? prior->getEdgePos(0) : prior->getArrivalPos();
184 const Position& trainExit = prevStop->getLane().geometryPositionAtOffset(startPos);
185 const double arrivalPos = useDoors ? lane->getShape().nearest_offset_to_point2D(trainExit) : access->endPos;
186 Position platformEntry = lane->geometryPositionAtOffset(arrivalPos);
187 if (useDoors) {
188 // find the closer side of the platform to enter
189 const double halfWidth = lane->getWidth() / 2. - MAX2(getVehicleType().getLength(), getVehicleType().getWidth()) / 2. - POSITION_EPS;
190 platformEntry = lane->geometryPositionAtOffset(arrivalPos, halfWidth);
191 const Position& plat2 = lane->geometryPositionAtOffset(arrivalPos, -halfWidth);
192 if (trainExit.distanceSquaredTo2D(plat2) < trainExit.distanceSquaredTo2D(platformEntry)) {
193 platformEntry = plat2;
194 }
195 }
196 newStage = new MSPersonStage_Access(accessEdge, prevStop, arrivalPos, 0.0, access->length, true,
197 trainExit, platformEntry);
198 }
199 }
200 newStage->setTrip(prior->getTrip());
201 myStep = myPlan->insert(myStep, newStage);
202 return true;
203 }
204 }
205 return false;
206}
207
208
209double
211 return MAX2(0., MIN2(1., getVehicleType().getImpatience()
212 + STEPS2TIME((*myStep)->getWaitingTime(SIMSTEP)) / MSPModel_Striping::MAX_WAIT_TOLERANCE));
213}
214
215const std::string&
217// if (getCurrentStageType() == WALKING) {
218// MSStageWalking* walkingStage = dynamic_cast<MSStageWalking*>(*myStep);
219// assert(walkingStage != 0);
220// const MSEdge* nextEdge = walkingStage->getPedestrianState()->getNextEdge(*walkingStage);
221// if (nextEdge != 0) {
222// return nextEdge->getID();
223// }
224// }
225// return StringUtils::emptyString;
226 const MSEdge* nextEdge = getNextEdgePtr();
227 if (nextEdge != nullptr) {
228 return nextEdge->getID();
229 }
231}
232
233
234const MSEdge*
237 MSStageWalking* walkingStage = dynamic_cast<MSStageWalking*>(*myStep);
238 assert(walkingStage != nullptr);
239 return walkingStage->getPState()->getNextEdge(*walkingStage);
240 }
241 return nullptr;
242}
243
244
245
246void
247MSPerson::replaceWalk(const ConstMSEdgeVector& newEdges, double departPos, int firstIndex, int nextIndex) {
248 assert(nextIndex > firstIndex);
249 //std::cout << SIMTIME << " reroute person " << getID()
250 // << " newEdges=" << toString(newEdges)
251 // << " firstIndex=" << firstIndex
252 // << " nextIndex=" << nextIndex
253 // << " departPos=" << getEdgePos()
254 // << " arrivalPos=" << getNextStage(nextIndex - 1)->getArrivalPos()
255 // << "\n";
256 MSStage* const toBeReplaced = getNextStage(nextIndex - 1);
257 MSStageWalking* newStage = new MSStageWalking(getID(), newEdges,
258 toBeReplaced->getDestinationStop(), -1,
259 -1,
260 departPos,
261 toBeReplaced->getArrivalPos(),
263 appendStage(newStage, nextIndex);
264 // remove stages in reverse order so that proceed will only be called at the last removal
265 for (int i = nextIndex - 1; i >= firstIndex; i--) {
266 //std::cout << " removeStage=" << i << "\n";
267 removeStage(i);
268 }
269}
270
271
274 if (myInfluencer == nullptr) {
275 myInfluencer = new Influencer();
276 }
277 return *myInfluencer;
278}
279
280
283 return myInfluencer;
284}
285
286
287
288/* -------------------------------------------------------------------------
289 * methods of MSPerson::Influencer
290 * ----------------------------------------------------------------------- */
292
293
295
296
297void
298MSPerson::Influencer::setRemoteControlled(Position xyPos, MSLane* l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector& route, SUMOTime t) {
299 myRemoteXYPos = xyPos;
300 myRemoteLane = l;
301 myRemotePos = pos;
302 myRemotePosLat = posLat;
303 myRemoteAngle = angle;
304 myRemoteEdgeOffset = edgeOffset;
305 myRemoteRoute = route;
306 myLastRemoteAccess = t;
307}
308
309
310bool
312 return myLastRemoteAccess == MSNet::getInstance()->getCurrentTimeStep();
313}
314
315
316bool
318 return myLastRemoteAccess >= t - TIME2STEPS(10);
319}
320
321
322void
324 /*
325 std::cout << SIMTIME << " moveToXY person=" << p->getID()
326 << " xyPos=" << myRemoteXYPos
327 << " lane=" << Named::getIDSecure(myRemoteLane)
328 << " pos=" << myRemotePos
329 << " posLat=" << myRemotePosLat
330 << " angle=" << myRemoteAngle
331 << " eOf=" << myRemoteEdgeOffset
332 << " route=" << toString(myRemoteRoute)
333 << " aTime=" << time2string(myLastRemoteAccess)
334 << "\n";
335 */
336 switch (p->getStageType(0)) {
338 MSStageWalking* s = dynamic_cast<MSStageWalking*>(p->getCurrentStage());
339 assert(s != nullptr);
340 s->getPState()->moveToXY(p, myRemoteXYPos, myRemoteLane, myRemotePos, myRemotePosLat,
341 myRemoteAngle, myRemoteEdgeOffset, myRemoteRoute,
342 MSNet::getInstance()->getCurrentTimeStep());
343 }
344 break;
345 default:
346 break;
347 }
348}
349
350
351/****************************************************************************/
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:185
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:1189
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:176
void postProcessRemoteControl(MSPerson *p)
Definition MSPerson.cpp:323
Influencer()
Constructor.
Definition MSPerson.cpp:291
void setRemoteControlled(Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector &route, SUMOTime t)
Definition MSPerson.cpp:298
~Influencer()
Destructor.
Definition MSPerson.cpp:294
bool isRemoteAffected(SUMOTime t) const
Definition MSPerson.cpp:317
bool isRemoteControlled() const
Definition MSPerson.cpp:311
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:154
Influencer * myInfluencer
An instance of a speed/position influencing instance; built in "getInfluencer".
Definition MSPerson.h:228
const MSEdge * getNextEdgePtr() const
returns the next edge ptr if this person is walking and the pedestrian model allows it
Definition MSPerson.cpp:235
double getImpatience() const
Definition MSPerson.cpp:210
double myChosenSpeedFactor
Definition MSPerson.h:230
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:247
virtual ~MSPerson()
destructor
Definition MSPerson.cpp:148
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition MSPerson.cpp:273
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:216
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....
Structure representing possible vehicle parameter.
static std::string emptyString
An empty string.
Definition StringUtils.h:86