Eclipse SUMO - Simulation of Urban MObility
MSPerson.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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 #pragma once
24 #include <config.h>
25 
26 #include <string>
27 #include <vector>
28 #include <set>
29 #include <utils/common/SUMOTime.h>
30 #include <utils/common/Command.h>
31 #include <utils/geom/Position.h>
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class MSNet;
40 class MSEdge;
41 class MSLane;
42 class OutputDevice;
44 class MSStoppingPlace;
45 class SUMOVehicle;
46 class MSVehicleType;
47 class MSPModel;
48 class MSMoveReminder;
49 
50 typedef std::vector<const MSEdge*> ConstMSEdgeVector;
51 
52 // ===========================================================================
53 // class definitions
54 // ===========================================================================
60 class MSPerson : public MSTransportable {
61 public:
68  public:
70  MSPersonStage_Walking(const std::string& personID, const ConstMSEdgeVector& route, MSStoppingPlace* toStop, SUMOTime walkingTime,
71  double speed, double departPos, double arrivalPos, double departPosLat, int departLane = -1);
72 
75 
76  MSStage* clone() const;
77 
79  virtual void proceed(MSNet* net, MSTransportable* person, SUMOTime now, MSStage* previous);
80 
82  void abort(MSTransportable*);
83 
85  void setSpeed(double speed);
86 
88  double getDistance() const {
89  return walkDistance();
90  }
91 
92  std::string getStageDescription(const bool isPerson) const {
94  return "walking";
95  }
96 
97  std::string getStageSummary(const bool isPerson) const;
98 
101  void saveState(std::ostringstream& out);
102 
105  void loadState(MSTransportable* transportable, std::istringstream& state);
106 
111  virtual void tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const;
112 
118  virtual void routeOutput(const bool isPerson, OutputDevice& os, const bool withRouteLength, const MSStage* const previous) const;
119 
121  bool moveToNextEdge(MSTransportable* person, SUMOTime currentTime, int prevDir, MSEdge* nextInternal = nullptr);
122 
124 
125  double getMaxSpeed(const MSTransportable* const person) const;
126 
127  inline double getArrivalPos() const {
128  return myArrivalPos;
129  }
130 
131  inline const MSEdge* getNextRouteEdge() const {
132  return myRouteStep == myRoute.end() - 1 ? nullptr : *(myRouteStep + 1);
133  }
135 
136 
137  private:
138 
140  double walkDistance() const;
141 
142  /* @brief compute average speed if the total walking duration is given
143  * @note Must be called when the previous stage changes myDepartPos from the default*/
144  double computeAverageSpeed() const;
145 
146 
147  private:
148 
151 
154 
156  std::vector<MSMoveReminder*> myMoveReminders;
157 
159  std::vector<SUMOTime>* myExitTimes;
160 
162  public:
164  explicit arrival_finder(SUMOTime time) : myTime(time) {}
165 
167  bool operator()(double t) const {
168  return myTime > t;
169  }
170 
171  private:
174  };
175 
176  private:
179 
182 
183  };
184 
189  class MSPersonStage_Access : public MSStage {
190  public:
192  MSPersonStage_Access(const MSEdge* destination, MSStoppingPlace* toStop,
193  const double arrivalPos, const double dist, const bool isExit);
194 
197 
198  MSStage* clone() const;
199 
201  virtual void proceed(MSNet* net, MSTransportable* person, SUMOTime now, MSStage* previous);
202 
204  std::string getStageDescription(const bool isPerson) const;
205  std::string getStageSummary(const bool isPerson) const;
206 
207  Position getPosition(SUMOTime now) const;
208 
209  double getAngle(SUMOTime now) const;
210 
212  double getDistance() const {
213  return myDist;
214  }
215 
222  void tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const;
223 
225  void routeOutput(const bool, OutputDevice&, const bool, const MSStage* const) const {};
226 
227  private:
228  class ProceedCmd : public Command {
229  public:
230  ProceedCmd(MSTransportable* person, MSEdge* edge) : myPerson(person), myStopEdge(edge) {}
232  SUMOTime execute(SUMOTime currentTime);
233  private:
236  private:
239  };
240 
241  private:
242  const double myDist;
243  const bool myAmExit;
246  };
247 
248 public:
250  MSPerson(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportable::MSTransportablePlan* plan, const double speedFactor);
251 
253  virtual ~MSPerson();
254 
255  /* @brief check whether an access stage must be added and return whether a
256  * stage was added */
257  bool checkAccess(const MSStage* const prior, const bool isDisembark = true);
258 
260  const std::string& getNextEdge() const;
261 
263  const MSEdge* getNextEdgePtr() const;
264 
266  virtual bool isSelected() const {
267  return false;
268  }
269 
270  inline double getSpeedFactor() const {
271  return myChosenSpeedFactor;
272  }
273 
274  inline void setSpeedFactor(const double factor) {
275  myChosenSpeedFactor = factor;
276  }
277 
279  void reroute(ConstMSEdgeVector& newEdges, double departPos, int firstIndex, int nextIndex);
280 
281 
287  class Influencer {
288  public:
290  Influencer();
291 
292 
294  ~Influencer();
295 
296 
297  void setRemoteControlled(Position xyPos, MSLane* l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector& route, SUMOTime t);
298 
300  return myLastRemoteAccess;
301  }
302 
304 
305  bool isRemoteControlled() const;
306 
307  bool isRemoteAffected(SUMOTime t) const;
308 
309  private:
312  double myRemotePos;
318  };
319 
320 
327 
328  const Influencer* getInfluencer() const;
329 
330  bool hasInfluencer() const {
331  return myInfluencer != 0;
332  }
333 
336 
337 private:
340 
342 
343 private:
346 
349 
350 };
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSPerson.h:48
long long int SUMOTime
Definition: SUMOTime.h:32
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:30
Base (microsim) event class.
Definition: Command.h:50
A road/street connecting two junctions.
Definition: MSEdge.h:77
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
Something on a lane to be noticed about vehicle movement.
The simulated network and simulation perfomer.
Definition: MSNet.h:88
The pedestrian (and also sometimes container) movement model.
Definition: MSPModel.h:51
Changes the wished person speed and position.
Definition: MSPerson.h:287
SUMOTime myLastRemoteAccess
Definition: MSPerson.h:317
void postProcessRemoteControl(MSPerson *p)
Definition: MSPerson.cpp:586
Influencer()
Constructor.
Definition: MSPerson.cpp:554
SUMOTime getLastAccessTimeStep() const
Definition: MSPerson.h:299
ConstMSEdgeVector myRemoteRoute
Definition: MSPerson.h:316
void setRemoteControlled(Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector &route, SUMOTime t)
Definition: MSPerson.cpp:561
~Influencer()
Destructor.
Definition: MSPerson.cpp:557
Position myRemoteXYPos
Definition: MSPerson.h:310
MSLane * myRemoteLane
Definition: MSPerson.h:311
bool isRemoteAffected(SUMOTime t) const
Definition: MSPerson.cpp:580
bool isRemoteControlled() const
Definition: MSPerson.cpp:574
SUMOTime execute(SUMOTime currentTime)
Executes the command.
Definition: MSPerson.cpp:431
ProceedCmd & operator=(const ProceedCmd &)
Invalidated assignment operator.
ProceedCmd(MSTransportable *person, MSEdge *edge)
Definition: MSPerson.h:230
Position getPosition(SUMOTime now) const
returns the position of the transportable
Definition: MSPerson.cpp:407
double getDistance() const
get travel distance in this stage
Definition: MSPerson.h:212
MSPersonStage_Access(const MSEdge *destination, MSStoppingPlace *toStop, const double arrivalPos, const double dist, const bool isExit)
constructor
Definition: MSPerson.cpp:366
void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const
Called on writing tripinfo output.
Definition: MSPerson.cpp:419
void routeOutput(const bool, OutputDevice &, const bool, const MSStage *const) const
Called on writing vehroute output. Currently does nothing.
Definition: MSPerson.h:225
virtual void proceed(MSNet *net, MSTransportable *person, SUMOTime now, MSStage *previous)
proceeds to the next step
Definition: MSPerson.cpp:386
double getAngle(SUMOTime now) const
returns the angle of the transportable
Definition: MSPerson.cpp:413
std::string getStageDescription(const bool isPerson) const
returns the stage description as a string
Definition: MSPerson.cpp:395
std::string getStageSummary(const bool isPerson) const
return string summary of the current stage
Definition: MSPerson.cpp:401
arrival_finder(SUMOTime time)
constructor
Definition: MSPerson.h:164
bool operator()(double t) const
comparison operator
Definition: MSPerson.h:167
SUMOTime myTime
the searched arrival time
Definition: MSPerson.h:173
std::string getStageDescription(const bool isPerson) const
return (brief) string representation of the current stage
Definition: MSPerson.h:92
virtual void routeOutput(const bool isPerson, OutputDevice &os, const bool withRouteLength, const MSStage *const previous) const
Called on writing vehroute output.
Definition: MSPerson.cpp:240
virtual void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const
Called on writing tripinfo output.
Definition: MSPerson.cpp:215
MSPersonStage_Walking(const std::string &personID, const ConstMSEdgeVector &route, MSStoppingPlace *toStop, SUMOTime walkingTime, double speed, double departPos, double arrivalPos, double departPosLat, int departLane=-1)
constructor
Definition: MSPerson.cpp:53
std::vector< MSMoveReminder * > myMoveReminders
the MoveReminders encountered while walking
Definition: MSPerson.h:156
void setSpeed(double speed)
sets the walking speed (ignored in other stages)
Definition: MSPerson.cpp:127
SUMOTime myWalkingTime
the time the person is walking
Definition: MSPerson.h:150
double getArrivalPos() const
Definition: MSPerson.h:127
double computeAverageSpeed() const
Definition: MSPerson.cpp:133
const MSEdge * getNextRouteEdge() const
Definition: MSPerson.h:131
double getDistance() const
get travel distance in this stage
Definition: MSPerson.h:88
bool moveToNextEdge(MSTransportable *person, SUMOTime currentTime, int prevDir, MSEdge *nextInternal=nullptr)
move forward and return whether the person arrived
Definition: MSPerson.cpp:273
double getMaxSpeed(const MSTransportable *const person) const
accessors to be used by MSPModel
Definition: MSPerson.cpp:332
MSPersonStage_Walking & operator=(const MSPersonStage_Walking &)
Invalidated assignment operator.
double walkDistance() const
compute total walking distance
Definition: MSPerson.cpp:139
void loadState(MSTransportable *transportable, std::istringstream &state)
Reconstructs the current state.
Definition: MSPerson.cpp:354
SUMOTime myLastEdgeEntryTime
the time the person entered the edge
Definition: MSPerson.h:153
MSPersonStage_Walking(const MSPersonStage_Walking &)
Invalidated copy constructor.
std::string getStageSummary(const bool isPerson) const
return string summary of the current stage
Definition: MSPerson.cpp:337
std::vector< SUMOTime > * myExitTimes
optional exit time tracking for vehroute output
Definition: MSPerson.h:159
virtual void proceed(MSNet *net, MSTransportable *person, SUMOTime now, MSStage *previous)
proceeds to the next step
Definition: MSPerson.cpp:83
void abort(MSTransportable *)
abort this stage (TraCI)
Definition: MSPerson.cpp:121
void saveState(std::ostringstream &out)
Saves the current state into the given stream.
Definition: MSPerson.cpp:347
Influencer * myInfluencer
An instance of a speed/position influencing instance; built in "getInfluencer".
Definition: MSPerson.h:339
const MSEdge * getNextEdgePtr() const
returns the next edge ptr if this person is walking and the pedestrian model allows it
Definition: MSPerson.cpp:499
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:511
double myChosenSpeedFactor
Definition: MSPerson.h:341
virtual bool isSelected() const
whether this person is selected in the GUI
Definition: MSPerson.h:266
MSPerson(const MSPerson &)
Invalidated copy constructor.
MSPerson & operator=(const MSPerson &)
Invalidated assignment operator.
double getSpeedFactor() const
the current speed factor of the transportable (where applicable)
Definition: MSPerson.h:270
void setSpeedFactor(const double factor)
Definition: MSPerson.h:274
bool checkAccess(const MSStage *const prior, const bool isDisembark=true)
Definition: MSPerson.cpp:454
bool hasInfluencer() const
whether the vehicle is individually influenced (via TraCI or special parameters)
Definition: MSPerson.h:330
virtual ~MSPerson()
destructor
Definition: MSPerson.cpp:449
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition: MSPerson.cpp:536
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:480
MSPerson(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan, const double speedFactor)
constructor
Definition: MSPerson.cpp:443
void setRemoteState(Position xyPos)
sets position outside the road network
double myArrivalPos
the position at which we want to arrive
Definition: MSStage.h:227
std::vector< const MSEdge * > myRoute
The route of the container.
Definition: MSStage.h:548
std::vector< const MSEdge * >::iterator myRouteStep
current step
Definition: MSStage.h:551
A lane area vehicles can halt at.
bool isPerson() const
Whether it is a person.
std::vector< MSStage * > MSTransportablePlan
the structure holding the plan of a transportable
The car-following model and parameter.
Definition: MSVehicleType.h:62
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
A list of positions.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
Structure representing possible vehicle parameter.