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-2020 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;
49 class MSMoveReminder;
50 
51 typedef std::vector<const MSEdge*> ConstMSEdgeVector;
52 
53 // ===========================================================================
54 // class definitions
55 // ===========================================================================
61 class MSPerson : public MSTransportable {
62 public:
69  public:
71  MSPersonStage_Walking(const std::string& personID, const ConstMSEdgeVector& route, MSStoppingPlace* toStop, SUMOTime walkingTime,
72  double speed, double departPos, double arrivalPos, double departPosLat);
73 
76 
77  MSStage* clone() const;
78 
80  virtual void proceed(MSNet* net, MSTransportable* person, SUMOTime now, MSStage* previous);
81 
83  void abort(MSTransportable*);
84 
86  void setSpeed(double speed);
87 
89  double getDistance() const {
90  return walkDistance();
91  }
92 
93  std::string getStageDescription(const bool isPerson) const {
95  return "walking";
96  }
97 
98  std::string getStageSummary(const bool isPerson) const;
99 
102  void saveState(std::ostringstream& out);
103 
106  void loadState(MSTransportable* transportable, std::istringstream& state);
107 
112  virtual void tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const;
113 
119  virtual void routeOutput(const bool isPerson, OutputDevice& os, const bool withRouteLength, const MSStage* const previous) const;
120 
122  bool moveToNextEdge(MSTransportable* person, SUMOTime currentTime, MSEdge* nextInternal = nullptr);
123 
125 
126  double getMaxSpeed(const MSTransportable* const person) const;
127 
128  inline double getArrivalPos() const {
129  return myArrivalPos;
130  }
131 
132  inline const MSEdge* getNextRouteEdge() const {
133  return myRouteStep == myRoute.end() - 1 ? nullptr : *(myRouteStep + 1);
134  }
136 
137 
138  private:
139 
141  double walkDistance() const;
142 
143  /* @brief compute average speed if the total walking duration is given
144  * @note Must be called when the previous stage changes myDepartPos from the default*/
145  double computeAverageSpeed() const;
146 
147 
148  private:
151 
154 
156  std::vector<MSMoveReminder*> myMoveReminders;
157 
159  public:
161  explicit arrival_finder(SUMOTime time) : myTime(time) {}
162 
164  bool operator()(double t) const {
165  return myTime > t;
166  }
167 
168  private:
171  };
172 
173  private:
176 
179 
180  };
181 
186  class MSPersonStage_Access : public MSStage {
187  public:
189  MSPersonStage_Access(const MSEdge* destination, MSStoppingPlace* toStop,
190  const double arrivalPos, const double dist, const bool isExit);
191 
194 
195  MSStage* clone() const;
196 
198  virtual void proceed(MSNet* net, MSTransportable* person, SUMOTime now, MSStage* previous);
199 
201  std::string getStageDescription(const bool isPerson) const;
202  std::string getStageSummary(const bool isPerson) const;
203 
204  Position getPosition(SUMOTime now) const;
205 
206  double getAngle(SUMOTime now) const;
207 
209  double getDistance() const {
210  return myDist;
211  }
212 
219  void tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const;
220 
222  void routeOutput(const bool, OutputDevice&, const bool, const MSStage* const) const {};
223 
224  private:
225  class ProceedCmd : public Command {
226  public:
227  ProceedCmd(MSTransportable* person, MSEdge* edge) : myPerson(person), myStopEdge(edge) {}
229  SUMOTime execute(SUMOTime currentTime);
230  private:
233  private:
236  };
237 
238  private:
239  const double myDist;
240  const bool myAmExit;
243  };
244 
245 public:
247  MSPerson(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportable::MSTransportablePlan* plan, const double speedFactor);
248 
250  virtual ~MSPerson();
251 
252  void checkAccess(const MSStage* const prior, const bool isDisembark = true);
253 
255  const std::string& getNextEdge() const;
256 
258  const MSEdge* getNextEdgePtr() const;
259 
261  virtual bool isSelected() const {
262  return false;
263  }
264 
265  inline double getSpeedFactor() const {
266  return myChosenSpeedFactor;
267  }
268 
270  void reroute(ConstMSEdgeVector& newEdges, double departPos, int firstIndex, int nextIndex);
271 
272 
278  class Influencer {
279  public:
281  Influencer();
282 
283 
285  ~Influencer();
286 
287 
288  void setRemoteControlled(Position xyPos, MSLane* l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector& route, SUMOTime t);
289 
291  return myLastRemoteAccess;
292  }
293 
295 
296  bool isRemoteControlled() const;
297 
298  bool isRemoteAffected(SUMOTime t) const;
299 
300  private:
303  double myRemotePos;
309  };
310 
311 
318 
319  const Influencer* getInfluencer() const;
320 
321  bool hasInfluencer() const {
322  return myInfluencer != 0;
323  }
324 
327 
328 private:
331 
332  const double myChosenSpeedFactor;
333 
334 private:
337 
340 
341 };
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSPerson.h:49
long long int SUMOTime
Definition: SUMOTime.h:31
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:29
Base (microsim) event class.
Definition: Command.h:49
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:89
The pedestrian (and also sometimes container) movement model.
Definition: MSPModel.h:51
Changes the wished person speed and position.
Definition: MSPerson.h:278
SUMOTime myLastRemoteAccess
Definition: MSPerson.h:308
void postProcessRemoteControl(MSPerson *p)
Definition: MSPerson.cpp:555
Influencer()
Constructor.
Definition: MSPerson.cpp:523
SUMOTime getLastAccessTimeStep() const
Definition: MSPerson.h:290
ConstMSEdgeVector myRemoteRoute
Definition: MSPerson.h:307
void setRemoteControlled(Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector &route, SUMOTime t)
Definition: MSPerson.cpp:530
~Influencer()
Destructor.
Definition: MSPerson.cpp:526
Position myRemoteXYPos
Definition: MSPerson.h:301
MSLane * myRemoteLane
Definition: MSPerson.h:302
bool isRemoteAffected(SUMOTime t) const
Definition: MSPerson.cpp:549
bool isRemoteControlled() const
Definition: MSPerson.cpp:543
SUMOTime execute(SUMOTime currentTime)
Executes the command.
Definition: MSPerson.cpp:404
ProceedCmd & operator=(const ProceedCmd &)
Invalidated assignment operator.
ProceedCmd(MSTransportable *person, MSEdge *edge)
Definition: MSPerson.h:227
Position getPosition(SUMOTime now) const
returns the position of the transportable
Definition: MSPerson.cpp:382
double getDistance() const
get travel distance in this stage
Definition: MSPerson.h:209
MSPersonStage_Access(const MSEdge *destination, MSStoppingPlace *toStop, const double arrivalPos, const double dist, const bool isExit)
constructor
Definition: MSPerson.cpp:341
void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const
Called on writing tripinfo output.
Definition: MSPerson.cpp:394
void routeOutput(const bool, OutputDevice &, const bool, const MSStage *const) const
Called on writing vehroute output. Currently does nothing.
Definition: MSPerson.h:222
virtual void proceed(MSNet *net, MSTransportable *person, SUMOTime now, MSStage *previous)
proceeds to the next step
Definition: MSPerson.cpp:361
double getAngle(SUMOTime now) const
returns the angle of the transportable
Definition: MSPerson.cpp:388
std::string getStageDescription(const bool isPerson) const
returns the stage description as a string
Definition: MSPerson.cpp:370
std::string getStageSummary(const bool isPerson) const
return string summary of the current stage
Definition: MSPerson.cpp:376
arrival_finder(SUMOTime time)
constructor
Definition: MSPerson.h:161
bool operator()(double t) const
comparison operator
Definition: MSPerson.h:164
SUMOTime myTime
the searched arrival time
Definition: MSPerson.h:170
std::string getStageDescription(const bool isPerson) const
return (brief) string representation of the current stage
Definition: MSPerson.h:93
virtual void routeOutput(const bool isPerson, OutputDevice &os, const bool withRouteLength, const MSStage *const previous) const
Called on writing vehroute output.
Definition: MSPerson.cpp:235
virtual void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const
Called on writing tripinfo output.
Definition: MSPerson.cpp:210
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:122
SUMOTime myWalkingTime
the time the person is walking
Definition: MSPerson.h:150
double getArrivalPos() const
Definition: MSPerson.h:128
double computeAverageSpeed() const
Definition: MSPerson.cpp:128
const MSEdge * getNextRouteEdge() const
Definition: MSPerson.h:132
double getDistance() const
get travel distance in this stage
Definition: MSPerson.h:89
double getMaxSpeed(const MSTransportable *const person) const
accessors to be used by MSPModel
Definition: MSPerson.cpp:307
MSPersonStage_Walking & operator=(const MSPersonStage_Walking &)
Invalidated assignment operator.
double walkDistance() const
compute total walking distance
Definition: MSPerson.cpp:134
void loadState(MSTransportable *transportable, std::istringstream &state)
Reconstructs the current state.
Definition: MSPerson.cpp:329
SUMOTime myLastEdgeEntryTime
the time the person entered the edge
Definition: MSPerson.h:153
bool moveToNextEdge(MSTransportable *person, SUMOTime currentTime, MSEdge *nextInternal=nullptr)
move forward and return whether the person arrived
Definition: MSPerson.cpp:257
MSPersonStage_Walking(const MSPersonStage_Walking &)
Invalidated copy constructor.
MSPersonStage_Walking(const std::string &personID, const ConstMSEdgeVector &route, MSStoppingPlace *toStop, SUMOTime walkingTime, double speed, double departPos, double arrivalPos, double departPosLat)
constructor
Definition: MSPerson.cpp:53
std::string getStageSummary(const bool isPerson) const
return string summary of the current stage
Definition: MSPerson.cpp:312
virtual void proceed(MSNet *net, MSTransportable *person, SUMOTime now, MSStage *previous)
proceeds to the next step
Definition: MSPerson.cpp:81
void abort(MSTransportable *)
abort this stage (TraCI)
Definition: MSPerson.cpp:116
void saveState(std::ostringstream &out)
Saves the current state into the given stream.
Definition: MSPerson.cpp:322
void checkAccess(const MSStage *const prior, const bool isDisembark=true)
Definition: MSPerson.cpp:427
Influencer * myInfluencer
An instance of a speed/position influencing instance; built in "getInfluencer".
Definition: MSPerson.h:330
const MSEdge * getNextEdgePtr() const
returns the next edge ptr if this person is walking and the pedestrian model allows it
Definition: MSPerson.cpp:468
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:480
virtual bool isSelected() const
whether this person is selected in the GUI
Definition: MSPerson.h:261
MSPerson(const MSPerson &)
Invalidated copy constructor.
MSPerson & operator=(const MSPerson &)
Invalidated assignment operator.
const double myChosenSpeedFactor
Definition: MSPerson.h:332
double getSpeedFactor() const
the current speed factor of the transportable (where applicable)
Definition: MSPerson.h:265
bool hasInfluencer() const
Definition: MSPerson.h:321
virtual ~MSPerson()
destructor
Definition: MSPerson.cpp:422
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition: MSPerson.cpp:505
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:449
MSPerson(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan, const double speedFactor)
constructor
Definition: MSPerson.cpp:416
void setRemoteState(Position xyPos)
sets position outside the road network
double myArrivalPos
the position at which we want to arrive
Definition: MSStage.h:224
std::vector< const MSEdge * > myRoute
The route of the container.
Definition: MSStage.h:526
std::vector< const MSEdge * >::iterator myRouteStep
current step
Definition: MSStage.h:529
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
abstract base class for managing callbacks to retrieve various state information from the model
Definition: MSPModel.h:130
The car-following model and parameter.
Definition: MSVehicleType.h:62
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
A list of positions.
Representation of a vehicle.
Definition: SUMOVehicle.h:58
Structure representing possible vehicle parameter.