SUMO - Simulation of Urban MObility
MSPModel_Striping.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // The pedestrian following model (prototype)
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2014-2015 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 #ifndef MSPModel_Striping_h
22 #define MSPModel_Striping_h
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <limits>
35 #include <utils/common/SUMOTime.h>
36 #include <utils/common/Command.h>
38 #include <microsim/MSLane.h>
39 #include "MSPerson.h"
40 #include "MSPModel.h"
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class MSNet;
46 class MSLink;
47 class MSJunction;
48 
49 
50 // ===========================================================================
51 // class definitions
52 // ===========================================================================
58 class MSPModel_Striping : public MSPModel {
59 
60  friend class GUIPerson; // for debugging
61 
62 public:
63 
65  MSPModel_Striping(const OptionsCont& oc, MSNet* net);
66 
68 
71 
73  bool blockedAtDist(const MSLane* lane, SUMOReal distToCrossing, std::vector<const MSPerson*>* collectBlockers);
74 
76  void cleanupHelper();
77 
80 
81  // @brief the width of a pedstrian stripe
83 
84  // @brief the factor for random slow-down
86 
87  // @brief the time threshold before becoming jammed
88  static SUMOTime jamTime;
89 
90  // @brief the distance (in seconds) to look ahead for changing stripes
92  // @brief the distance (in seconds) to look ahead for changing stripes (regarding oncoming pedestrians)
94 
95  // @brief the utility penalty for moving sideways (corresponds to meters)
96  static const SUMOReal LATERAL_PENALTY;
97 
98  // @brief the utility penalty for obstructed (physically blocking me) stripes (corresponds to meters)
100 
101  // @brief the utility penalty for inappropriate (reserved for oncoming traffic or may violate my min gap) stripes (corresponds to meters)
103 
104  // @brief the utility penalty for oncoming conflicts on stripes (corresponds to meters)
106 
107  // @brief the factor by which pedestrian width is reduced when sqeezing past each other
108  static const SUMOReal SQUEEZE;
109 
110  // @brief the maximum distance (in meters) at which oncoming pedestrians block right turning traffic
112 
113  // @brief fraction of the leftmost lanes to reserve for oncoming traffic
115 
116  // @brief the time pedestrians take to reach maximum impatience
118 
119  // @brief the fraction of forward speed to be used for lateral movemenk
121 
122  // @brief the minimum distance to the next obstacle in order to start walking after stopped
124 
126 
127 
128 protected:
130  public:
132  bool operator()(const MSLane* l1, const MSLane* l2) const {
133  return l1->getNumericalID() < l2->getNumericalID();
134  }
135  };
136 
137  struct Obstacle;
138  struct WalkingAreaPath;
139  class PState;
140  typedef std::vector<PState*> Pedestrians;
141  typedef std::map<const MSLane*, Pedestrians, lane_by_numid_sorter> ActiveLanes;
142  typedef std::vector<Obstacle> Obstacles;
143  typedef std::map<const MSLane*, Obstacles, lane_by_numid_sorter> NextLanesObstacles;
144  typedef std::map<std::pair<const MSLane*, const MSLane*>, WalkingAreaPath> WalkingAreaPaths;
145 
146  struct NextLaneInfo {
147  NextLaneInfo(const MSLane* _lane, const MSLink* _link, int _dir) :
148  lane(_lane),
149  link(_link),
150  dir(_dir)
151  { }
152 
154  lane(0),
155  link(0),
157  { }
158 
159  // @brief the next lane to be used
160  const MSLane* lane;
161  // @brief the link from the current lane to the next lane
162  const MSLink* link;
163  // @brief the direction on the next lane
164  int dir;
165  };
166 
168  struct Obstacle {
170  Obstacle(int dir);
172  Obstacle(const PState& ped);
174  Obstacle(SUMOReal _x, SUMOReal _speed, const std::string& _description, const SUMOReal width = 0.)
175  : xFwd(_x + width / 2.), xBack(_x - width / 2.), speed(_speed), description(_description) {};
176 
178  SUMOReal xFwd;
184  std::string description;
185  };
186 
188  WalkingAreaPath(const MSLane* _from, const MSLane* _walkingArea, const MSLane* _to, const PositionVector& _shape) :
189  from(_from),
190  to(_to),
191  lane(_walkingArea),
192  shape(_shape),
193  length(_shape.length())
194  {}
195 
196  WalkingAreaPath(): from(0), to(0), lane(0) {};
197 
198  const MSLane* from;
199  const MSLane* to;
200  const MSLane* lane; // the walkingArea;
201  PositionVector shape; // actually const but needs to be copyable by some stl code
203 
204  };
205 
207  public:
209  bool operator()(const WalkingAreaPath* p1, const WalkingAreaPath* p2) const {
210  if (p1->from->getNumericalID() < p2->from->getNumericalID()) {
211  return true;
212  }
213  if (p1->from->getNumericalID() == p2->from->getNumericalID()) {
214  if (p1->to->getNumericalID() < p2->to->getNumericalID()) {
215  return true;
216  }
217  }
218  return false;
219  }
220  };
221 
222 
227  class PState : public PedestrianState {
228  public:
229 
232  SUMOReal getEdgePos(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
233  Position getPosition(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
234  SUMOReal getAngle(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
235  SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
236  SUMOReal getSpeed(const MSPerson::MSPersonStage_Walking& stage) const;
237  const MSEdge* getNextEdge(const MSPerson::MSPersonStage_Walking& stage) const;
239 
240  PState(MSPerson* person, MSPerson::MSPersonStage_Walking* stage, const MSLane* lane);
241 
242  ~PState() {};
243  MSPerson* myPerson;
246  const MSLane* myLane;
252  int myDir;
265 
267  SUMOReal getMinX(const bool includeMinGap = true) const;
268 
270  SUMOReal getMaxX(const bool includeMinGap = true) const;
271 
273  SUMOReal getLength() const;
274 
276  SUMOReal getMinGap() const;
277 
279  SUMOReal distToLaneEnd() const;
280 
282  bool moveToNextLane(SUMOTime currentTime);
283 
285  void walk(const Obstacles& obs, SUMOTime currentTime);
286 
288  SUMOReal getImpatience(SUMOTime now) const;
289 
290  int stripe() const;
291  int otherStripe() const;
292 
293  int stripe(const SUMOReal relY) const;
294  int otherStripe(const SUMOReal relY) const;
295 
297  SUMOReal distanceTo(const Obstacle& obs, const bool includeMinGap = true) const;
298 
300  void mergeObstacles(Obstacles& into, const Obstacles& obs2);
301 
302  };
303 
304  class MovePedestrians : public Command {
305  public:
308  SUMOTime execute(SUMOTime currentTime);
309  private:
311  private:
313  MovePedestrians& operator=(const MovePedestrians&);
314  };
315 
318  public:
320  by_xpos_sorter(int dir): myDir(dir) {}
321 
322  public:
324  bool operator()(const PState* p1, const PState* p2) const {
325  if (p1->myRelX != p2->myRelX) {
326  return myDir * p1->myRelX > myDir * p2->myRelX;
327  }
328  return p1->myPerson->getID() < p2->myPerson->getID();
329  }
330 
331  private:
332  const int myDir;
333 
334  private:
336  by_xpos_sorter& operator=(const by_xpos_sorter&);
337  };
338 
339 
341  void moveInDirection(SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
342 
344  void moveInDirectionOnLane(Pedestrians& pedestrians, const MSLane* lane, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
345 
346  const ActiveLanes& getActiveLanes() {
347  return myActiveLanes;
348  }
349 
350 private:
351  static void DEBUG_PRINT(const Obstacles& obs);
352 
354  static int connectedDirection(const MSLane* from, const MSLane* to);
355 
361  static NextLaneInfo getNextLane(const PState& ped, const MSLane* currentLane, const MSLane* prevLane);
362 
364  static const MSLane* getNextWalkingArea(const MSLane* currentLane, const int dir, MSLink*& link);
365 
366  static void initWalkingAreaPaths(const MSNet* net);
367 
369  static int numStripes(const MSLane* lane);
370 
371  static Obstacles getNeighboringObstacles(const Pedestrians& pedestrians, int egoIndex, int stripes);
372 
373  const Obstacles& getNextLaneObstacles(NextLanesObstacles& nextLanesObs, const MSLane* lane, const MSLane* nextLane, int stripes,
374  SUMOReal nextLength, int nextDir, SUMOReal currentLength, int currentDir);
375 
376  static void addCloserObstacle(Obstacles& obs, SUMOReal x, int stripe, int numStripes, const std::string& id, SUMOReal width, int dir);
377 
379  Pedestrians& getPedestrians(const MSLane* lane);
380 
381 
382 private:
385 
388 
390  ActiveLanes myActiveLanes;
391 
393  static WalkingAreaPaths myWalkingAreaPaths;
394 
396  static Pedestrians noPedestrians;
397 
398 };
399 
400 
401 #endif /* MSPModel_Striping_h */
402 
const Obstacles & getNextLaneObstacles(NextLanesObstacles &nextLanesObs, const MSLane *lane, const MSLane *nextLane, int stripes, SUMOReal nextLength, int nextDir, SUMOReal currentLength, int currentDir)
bool operator()(const PState *p1, const PState *p2) const
comparing operation
static NextLaneInfo getNextLane(const PState &ped, const MSLane *currentLane, const MSLane *prevLane)
computes the successor lane for the given pedestrian and sets the link as well as the direction to us...
bool blockedAtDist(const MSLane *lane, SUMOReal distToCrossing, std::vector< const MSPerson * > *collectBlockers)
whether a pedestrian is blocking the crossing of lane at offset distToCrossing
bool operator()(const WalkingAreaPath *p1, const WalkingAreaPath *p2) const
comparing operation
static const SUMOReal OBSTRUCTED_PENALTY
long long int SUMOTime
Definition: SUMOTime.h:43
MSPerson::MSPersonStage_Walking * myStage
Obstacle(SUMOReal _x, SUMOReal _speed, const std::string &_description, const SUMOReal width=0.)
create an obstacle from explict values
static SUMOReal stripeWidth
model parameters
static int numStripes(const MSLane *lane)
return the maximum number of pedestrians walking side by side
static Obstacles getNeighboringObstacles(const Pedestrians &pedestrians, int egoIndex, int stripes)
sorts the persons by position on the lane. If dir is forward, higher x positions come first...
SUMOReal mySpeed
the current walking speed
static const MSLane * getNextWalkingArea(const MSLane *currentLane, const int dir, MSLink *&link)
return the next walkingArea in the given direction
static int connectedDirection(const MSLane *from, const MSLane *to)
returns the direction in which these lanes are connectioned or 0 if they are not
WalkingAreaPath * myWalkingAreaPath
the current walkingAreaPath or 0
WalkingAreaPath(const MSLane *_from, const MSLane *_walkingArea, const MSLane *_to, const PositionVector &_shape)
The pedestrian following model.
information regarding surround Pedestrians (and potentially other things)
The base class for an intersection.
Definition: MSJunction.h:61
size_t getNumericalID() const
Returns this lane&#39;s numerical id.
Definition: MSLane.h:315
MSPModel_Striping *const myModel
static const SUMOReal ONCOMING_CONFLICT_PENALTY
const std::string & getID() const
returns the id of the transportable
std::map< std::pair< const MSLane *, const MSLane * >, WalkingAreaPath > WalkingAreaPaths
static void addCloserObstacle(Obstacles &obs, SUMOReal x, int stripe, int numStripes, const std::string &id, SUMOReal width, int dir)
Base (microsim) event class.
Definition: Command.h:61
static MSPModel * myModel
Definition: MSPModel.h:90
static WalkingAreaPaths myWalkingAreaPaths
store for walkinArea elements
The simulated network and simulation perfomer.
Definition: MSNet.h:94
bool myAmJammed
whether the person is jammed
static Pedestrians noPedestrians
empty pedestrian vector
static const SUMOReal RESERVE_FOR_ONCOMING_FACTOR
void moveInDirection(SUMOTime currentTime, std::set< MSPerson * > &changedLane, int dir)
move all pedestrians forward and advance to the next lane if applicable
NextLaneInfo myNLI
information about the upcoming lane
The pedestrian following model.
Definition: MSPModel.h:54
static const SUMOReal SQUEEZE
A road/street connecting two junctions.
Definition: MSEdge.h:81
Pedestrians & getPedestrians(const MSLane *lane)
retrieves the pedestian vector for the given lane (may be empty)
static const SUMOReal LOOKAHEAD_SAMEDIR
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:78
static const SUMOReal LATERAL_SPEED_FACTOR
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
static const SUMOReal LOOKAHEAD_ONCOMING
static const SUMOReal INAPPROPRIATE_PENALTY
SUMOReal xFwd
maximal position on the current lane in forward direction
A list of positions.
std::map< const MSLane *, Pedestrians, lane_by_numid_sorter > ActiveLanes
std::map< const MSLane *, Obstacles, lane_by_numid_sorter > NextLanesObstacles
SUMOTime myWaitingTime
the consecutive time spent at speed 0
int myDir
the walking direction on the current lane (1 forward, -1 backward)
void cleanupHelper()
remove state at simulation end
PedestrianState * add(MSPerson *person, MSPerson::MSPersonStage_Walking *stage, SUMOTime now)
register the given person as a pedestrian
static const SUMOReal MIN_STARTUP_DIST
MovePedestrians(MSPModel_Striping *model)
abstract base class for managing callbacks to retrieve various state information from the model ...
Definition: MSPModel.h:96
std::vector< PState * > Pedestrians
bool myWaitingToEnter
whether the pedestrian is waiting to start its walk
A storage for options typed value containers)
Definition: OptionsCont.h:108
Container for pedestrian state and individual position update function.
NextLaneInfo(const MSLane *_lane, const MSLink *_link, int _dir)
std::vector< Obstacle > Obstacles
static const SUMOReal BLOCKER_LOOKAHEAD
SUMOReal xBack
maximal position on the current lane in backward direction
#define SUMOReal
Definition: config.h:214
SUMOReal myRelY
the orthogonal shift on the current lane
static const SUMOReal MAX_WAIT_TOLERANCE
SUMOReal myRelX
the advancement along the current lane
MovePedestrians * myCommand
the MovePedestrians command that is registered
static void DEBUG_PRINT(const Obstacles &obs)
static SUMOReal dawdling
const ActiveLanes & getActiveLanes()
static SUMOTime jamTime
int myNumActivePedestrians
the total number of active pedestrians
SUMOReal speed
speed relative to lane direction (positive means in the same direction)
std::string description
the id / description of the obstacle
static void initWalkingAreaPaths(const MSNet *net)
MSPModel_Striping(const OptionsCont &oc, MSNet *net)
Constructor (it should not be necessary to construct more than one instance)
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
ActiveLanes myActiveLanes
store of all lanes which have pedestrians on them
const MSLane * myLane
the current lane of this pedestrian
bool operator()(const MSLane *l1, const MSLane *l2) const
comparing operation
static const SUMOReal LATERAL_PENALTY
void moveInDirectionOnLane(Pedestrians &pedestrians, const MSLane *lane, SUMOTime currentTime, std::set< MSPerson * > &changedLane, int dir)
move pedestrians forward on one lane