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-2016 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 minimum utility that indicates obstruction
109 
110  // @brief the factor by which pedestrian width is reduced when sqeezing past each other
111  static const SUMOReal SQUEEZE;
112 
113  // @brief the maximum distance (in meters) at which oncoming pedestrians block right turning traffic
115 
116  // @brief fraction of the leftmost lanes to reserve for oncoming traffic
118 
119  // @brief the time pedestrians take to reach maximum impatience
121 
122  // @brief the fraction of forward speed to be used for lateral movemenk
124 
125  // @brief the minimum distance to the next obstacle in order to start walking after stopped
127 
129 
130 
131 protected:
133  public:
135  bool operator()(const MSLane* l1, const MSLane* l2) const {
136  return l1->getNumericalID() < l2->getNumericalID();
137  }
138  };
139 
140  struct Obstacle;
141  struct WalkingAreaPath;
142  class PState;
143  typedef std::vector<PState*> Pedestrians;
144  typedef std::map<const MSLane*, Pedestrians, lane_by_numid_sorter> ActiveLanes;
145  typedef std::vector<Obstacle> Obstacles;
146  typedef std::map<const MSLane*, Obstacles, lane_by_numid_sorter> NextLanesObstacles;
147  typedef std::map<std::pair<const MSLane*, const MSLane*>, WalkingAreaPath> WalkingAreaPaths;
148 
149  struct NextLaneInfo {
150  NextLaneInfo(const MSLane* _lane, const MSLink* _link, int _dir) :
151  lane(_lane),
152  link(_link),
153  dir(_dir) {
154  }
155 
157  lane(0),
158  link(0),
159  dir(UNDEFINED_DIRECTION) {
160  }
161 
162  // @brief the next lane to be used
163  const MSLane* lane;
164  // @brief the link from the current lane to the next lane
165  const MSLink* link;
166  // @brief the direction on the next lane
167  int dir;
168  };
169 
171  struct Obstacle {
173  Obstacle(int dir);
175  Obstacle(const PState& ped);
177  Obstacle(SUMOReal _x, SUMOReal _speed, const std::string& _description, const SUMOReal width = 0.)
178  : xFwd(_x + width / 2.), xBack(_x - width / 2.), speed(_speed), description(_description) {};
179 
181  SUMOReal xFwd;
187  std::string description;
188  };
189 
191  WalkingAreaPath(const MSLane* _from, const MSLane* _walkingArea, const MSLane* _to, const PositionVector& _shape) :
192  from(_from),
193  to(_to),
194  lane(_walkingArea),
195  shape(_shape),
196  length(_shape.length()) {
197  }
198 
199  WalkingAreaPath(): from(0), to(0), lane(0) {};
200 
201  const MSLane* from;
202  const MSLane* to;
203  const MSLane* lane; // the walkingArea;
204  PositionVector shape; // actually const but needs to be copyable by some stl code
206 
207  };
208 
210  public:
212  bool operator()(const WalkingAreaPath* p1, const WalkingAreaPath* p2) const {
213  if (p1->from->getNumericalID() < p2->from->getNumericalID()) {
214  return true;
215  }
216  if (p1->from->getNumericalID() == p2->from->getNumericalID()) {
217  if (p1->to->getNumericalID() < p2->to->getNumericalID()) {
218  return true;
219  }
220  }
221  return false;
222  }
223  };
224 
225 
230  class PState : public PedestrianState {
231  public:
232 
235  SUMOReal getEdgePos(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
236  Position getPosition(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
237  SUMOReal getAngle(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
238  SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
239  SUMOReal getSpeed(const MSPerson::MSPersonStage_Walking& stage) const;
240  const MSEdge* getNextEdge(const MSPerson::MSPersonStage_Walking& stage) const;
242 
243  PState(MSPerson* person, MSPerson::MSPersonStage_Walking* stage, const MSLane* lane);
244 
245  ~PState() {};
246  MSPerson* myPerson;
249  const MSLane* myLane;
255  int myDir;
268 
270  SUMOReal getMinX(const bool includeMinGap = true) const;
271 
273  SUMOReal getMaxX(const bool includeMinGap = true) const;
274 
276  SUMOReal getLength() const;
277 
279  SUMOReal getMinGap() const;
280 
282  SUMOReal distToLaneEnd() const;
283 
285  bool moveToNextLane(SUMOTime currentTime);
286 
288  void walk(const Obstacles& obs, SUMOTime currentTime);
289 
291  SUMOReal getImpatience(SUMOTime now) const;
292 
293  int stripe() const;
294  int otherStripe() const;
295 
296  int stripe(const SUMOReal relY) const;
297  int otherStripe(const SUMOReal relY) const;
298 
299  /* @brief calculate distance to the given obstacle,
300  * - non-negative values signify an obstacle in front of ego
301  * the special values DIST_OVERLAP and DIST_BEHIND are used to signify
302  * obstacles that overlap and obstacles behind ego respectively
303  * the result is the same regardless of walking direction
304  */
305  SUMOReal distanceTo(const Obstacle& obs, const bool includeMinGap = true) const;
306 
308  void mergeObstacles(Obstacles& into, const Obstacles& obs2);
309 
310  };
311 
312  class MovePedestrians : public Command {
313  public:
316  SUMOTime execute(SUMOTime currentTime);
317  private:
319  private:
321  MovePedestrians& operator=(const MovePedestrians&);
322  };
323 
326  public:
328  by_xpos_sorter(int dir): myDir(dir) {}
329 
330  public:
332  bool operator()(const PState* p1, const PState* p2) const {
333  if (p1->myRelX != p2->myRelX) {
334  return myDir * p1->myRelX > myDir * p2->myRelX;
335  }
336  return p1->myPerson->getID() < p2->myPerson->getID();
337  }
338 
339  private:
340  const int myDir;
341 
342  private:
344  by_xpos_sorter& operator=(const by_xpos_sorter&);
345  };
346 
347 
349  void moveInDirection(SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
350 
352  void moveInDirectionOnLane(Pedestrians& pedestrians, const MSLane* lane, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
353 
354  const ActiveLanes& getActiveLanes() {
355  return myActiveLanes;
356  }
357 
358 private:
359  static void DEBUG_PRINT(const Obstacles& obs);
360 
362  static int connectedDirection(const MSLane* from, const MSLane* to);
363 
369  static NextLaneInfo getNextLane(const PState& ped, const MSLane* currentLane, const MSLane* prevLane);
370 
372  static const MSLane* getNextWalkingArea(const MSLane* currentLane, const int dir, MSLink*& link);
373 
374  static void initWalkingAreaPaths(const MSNet* net);
375 
377  static int numStripes(const MSLane* lane);
378 
379  static Obstacles getNeighboringObstacles(const Pedestrians& pedestrians, int egoIndex, int stripes);
380 
381  const Obstacles& getNextLaneObstacles(NextLanesObstacles& nextLanesObs, const MSLane* lane, const MSLane* nextLane, int stripes,
382  SUMOReal nextLength, int nextDir, SUMOReal currentLength, int currentDir);
383 
384  static void addCloserObstacle(Obstacles& obs, SUMOReal x, int stripe, int numStripes, const std::string& id, SUMOReal width, int dir);
385 
387  Pedestrians& getPedestrians(const MSLane* lane);
388 
389 
390 private:
393 
396 
398  ActiveLanes myActiveLanes;
399 
401  static WalkingAreaPaths myWalkingAreaPaths;
402 
404  static Pedestrians noPedestrians;
405 
406 };
407 
408 
409 #endif /* MSPModel_Striping_h */
410 
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:64
size_t getNumericalID() const
Returns this lane&#39;s numerical id.
Definition: MSLane.h:314
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:87
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:80
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:75
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
static const SUMOReal OBSTRUCTION_THRESHOLD
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:93
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:213
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