Eclipse SUMO - Simulation of Urban MObility
MSPModel.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2014-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
14 // The pedestrian following model (prototype)
15 /****************************************************************************/
16 #ifndef MSPModel_h
17 #define MSPModel_h
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <string>
25 #include <limits>
26 #include <utils/common/SUMOTime.h>
27 #include <utils/common/Command.h>
29 #include <utils/geom/GeomHelper.h>
31 #ifdef HAVE_FOX
32 #include <fx.h>
33 #endif
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class MSNet;
39 class MSLane;
40 class MSJunction;
41 
42 typedef std::pair<const MSPerson*, double> PersonDist;
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
52 class MSPModel {
53 public:
54 
55  static MSPModel* getModel();
56 
58  static void cleanup();
59 
60  virtual ~MSPModel() {};
61 
63  virtual PedestrianState* add(MSPerson* person, MSPerson::MSPersonStage_Walking* stage, SUMOTime now) = 0;
64 
66  virtual void remove(PedestrianState* state) = 0;
67 
76  virtual bool blockedAtDist(const MSLane* lane, double vehSide, double vehWidth,
77  double oncomingGap, std::vector<const MSPerson*>* collectBlockers) {
78  UNUSED_PARAMETER(lane);
79  UNUSED_PARAMETER(vehSide);
80  UNUSED_PARAMETER(vehWidth);
81  UNUSED_PARAMETER(oncomingGap);
82  UNUSED_PARAMETER(collectBlockers);
83  return false;
84  }
85 
87  virtual bool hasPedestrians(const MSLane* lane) {
88  UNUSED_PARAMETER(lane);
89  return false;
90  }
91 
93  virtual PersonDist nextBlocking(const MSLane* lane, double minPos, double minRight, double maxLeft, double stopTime = 0) {
94  UNUSED_PARAMETER(lane);
95  UNUSED_PARAMETER(minPos);
96  UNUSED_PARAMETER(minRight);
97  UNUSED_PARAMETER(maxLeft);
98  UNUSED_PARAMETER(stopTime);
99  return PersonDist((const MSPerson*)0, -1);
100  }
101 
102  virtual void cleanupHelper() {};
103 
104  // @brief walking directions
105  static const int FORWARD;
106  static const int BACKWARD;
107  static const int UNDEFINED_DIRECTION;
108 
109  // @brief the safety gap to keep between the car and the pedestrian in all directions
110  static const double SAFETY_GAP;
111 
113  static const double SIDEWALK_OFFSET;
114 
115  /* @brief return the arrival direction if the route may be traversed with the given starting direction.
116  * returns UNDEFINED_DIRECTION if the route cannot be traversed
117  */
118  static int canTraverse(int dir, const ConstMSEdgeVector& route);
119 
121  virtual bool usingInternalLanes() = 0;
122 
123 protected:
124 #ifdef HAVE_FOX
125  static FXMutex myInitializationMutex;
127 #endif
128 
129 
130 private:
131  static MSPModel* myModel;
132 
133 };
134 
135 
138 public:
139  virtual ~PedestrianState() {};
140 
142  virtual double getEdgePos(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const = 0;
143 
145  virtual Position getPosition(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const = 0;
146 
148  virtual double getAngle(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const = 0;
149 
151  virtual SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const = 0;
152 
154  virtual double getSpeed(const MSPerson::MSPersonStage_Walking& stage) const = 0;
155 
157  virtual const MSEdge* getNextEdge(const MSPerson::MSPersonStage_Walking& stage) const = 0;
158 
160  virtual void moveToXY(MSPerson* p, Position pos, MSLane* lane, double lanePos,
161  double lanePosLat, double angle, int routeOffset,
162  const ConstMSEdgeVector& edges, SUMOTime t) {
163  UNUSED_PARAMETER(p);
164  UNUSED_PARAMETER(pos);
165  UNUSED_PARAMETER(lane);
166  UNUSED_PARAMETER(lanePos);
167  UNUSED_PARAMETER(lanePosLat);
168  UNUSED_PARAMETER(angle);
169  UNUSED_PARAMETER(routeOffset);
170  UNUSED_PARAMETER(edges);
171  UNUSED_PARAMETER(t);
172  WRITE_WARNING("moveToXY is ignored by the current pedestrian model");
173  }
174 
175 };
176 
177 
178 class DummyState : public PedestrianState {
179 
180 public:
182  return 0.;
183  }
185  return Position::INVALID;
186  }
188  return 0.;
189  }
191  return 0;
192  }
194  return 0.;
195  }
197  return nullptr;
198  }
199 };
200 
201 
202 #endif /* MSPModel_h */
203 
DummyState::getNextEdge
const MSEdge * getNextEdge(const MSPerson::MSPersonStage_Walking &) const
return the list of internal edges if the pedestrian is on an intersection
Definition: MSPModel.h:196
UNUSED_PARAMETER
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:31
PedestrianState::~PedestrianState
virtual ~PedestrianState()
Definition: MSPModel.h:139
MSPModel
The pedestrian following model.
Definition: MSPModel.h:52
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:275
MSPModel::canTraverse
static int canTraverse(int dir, const ConstMSEdgeVector &route)
Definition: MSPModel.cpp:99
SUMOTime.h
MSPModel::BACKWARD
static const int BACKWARD
Definition: MSPModel.h:106
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSJunction
The base class for an intersection.
Definition: MSJunction.h:60
PedestrianState::getAngle
virtual double getAngle(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const =0
return the direction in which the person faces in degrees
Position::INVALID
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:284
MsgHandler.h
MSNet
The simulated network and simulation perfomer.
Definition: MSNet.h:91
PedestrianState::getWaitingTime
virtual SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const =0
return the time the person spent standing
MSPerson
Definition: MSPerson.h:63
MSPModel::SAFETY_GAP
static const double SAFETY_GAP
Definition: MSPModel.h:110
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
ConstMSEdgeVector
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:75
MSPModel::blockedAtDist
virtual bool blockedAtDist(const MSLane *lane, double vehSide, double vehWidth, double oncomingGap, std::vector< const MSPerson * > *collectBlockers)
whether a pedestrian is blocking the crossing of lane for the given vehicle bondaries
Definition: MSPModel.h:76
DummyState::getEdgePos
double getEdgePos(const MSPerson::MSPersonStage_Walking &, SUMOTime) const
return the offset from the start of the current edge measured in its natural direction
Definition: MSPModel.h:181
DummyState::getSpeed
double getSpeed(const MSPerson::MSPersonStage_Walking &) const
return the current speed of the person
Definition: MSPModel.h:193
PedestrianState
abstract base class for managing callbacks to retrieve various state information from the model
Definition: MSPModel.h:137
PedestrianState::getSpeed
virtual double getSpeed(const MSPerson::MSPersonStage_Walking &stage) const =0
return the current speed of the person
PedestrianState::getPosition
virtual Position getPosition(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const =0
return the network coordinate of the person
PersonDist
std::pair< const MSPerson *, double > PersonDist
Definition: MSPModel.h:40
DummyState::getPosition
Position getPosition(const MSPerson::MSPersonStage_Walking &, SUMOTime) const
return the network coordinate of the person
Definition: MSPModel.h:184
MSPModel::~MSPModel
virtual ~MSPModel()
Definition: MSPModel.h:60
MSPModel::add
virtual PedestrianState * add(MSPerson *person, MSPerson::MSPersonStage_Walking *stage, SUMOTime now)=0
register the given person as a pedestrian
DummyState::getWaitingTime
SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking &, SUMOTime) const
return the time the person spent standing
Definition: MSPModel.h:190
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
PedestrianState::getEdgePos
virtual double getEdgePos(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const =0
return the offset from the start of the current edge measured in its natural direction
DummyState::getAngle
double getAngle(const MSPerson::MSPersonStage_Walking &, SUMOTime) const
return the direction in which the person faces in degrees
Definition: MSPModel.h:187
MSPerson.h
MSPModel::nextBlocking
virtual PersonDist nextBlocking(const MSLane *lane, double minPos, double minRight, double maxLeft, double stopTime=0)
returns the next pedestrian beyond minPos that is laterally between minRight and maxLeft or 0
Definition: MSPModel.h:93
MSPModel::myModel
static MSPModel * myModel
Definition: MSPModel.h:131
MSPModel::remove
virtual void remove(PedestrianState *state)=0
remove the specified person from the pedestrian simulation
MSPModel::FORWARD
static const int FORWARD
Definition: MSPModel.h:102
MSPModel::hasPedestrians
virtual bool hasPedestrians(const MSLane *lane)
whether the given lane has pedestrians on it
Definition: MSPModel.h:87
MSPModel::cleanup
static void cleanup()
remove state at simulation end
Definition: MSPModel.cpp:89
MSPModel::SIDEWALK_OFFSET
static const double SIDEWALK_OFFSET
the offset for computing person positions when walking on edges without a sidewalk
Definition: MSPModel.h:113
MSPModel::cleanupHelper
virtual void cleanupHelper()
Definition: MSPModel.h:102
DummyState
Definition: MSPModel.h:178
MSPModel::UNDEFINED_DIRECTION
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:107
MSPerson::MSPersonStage_Walking
Definition: MSPerson.h:70
MSPModel::getModel
static MSPModel * getModel()
Definition: MSPModel.cpp:63
config.h
GeomHelper.h
PedestrianState::moveToXY
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 person to the given position
Definition: MSPModel.h:160
Command.h
MSPModel::usingInternalLanes
virtual bool usingInternalLanes()=0
whether movements on intersections are modelled
PedestrianState::getNextEdge
virtual const MSEdge * getNextEdge(const MSPerson::MSPersonStage_Walking &stage) const =0
return the list of internal edges if the pedestrian is on an intersection