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-2017 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  void remove(PedestrianState* state);
74 
76  bool blockedAtDist(const MSLane* lane, double distToCrossing, std::vector<const MSPerson*>* collectBlockers);
77 
79  void cleanupHelper();
80 
83 
84  // @brief the width of a pedstrian stripe
85  static double stripeWidth;
86 
87  // @brief the factor for random slow-down
88  static double dawdling;
89 
90  // @brief the time threshold before becoming jammed
91  static SUMOTime jamTime;
92 
93  // @brief the distance (in seconds) to look ahead for changing stripes
94  static const double LOOKAHEAD_SAMEDIR;
95  // @brief the distance (in seconds) to look ahead for changing stripes (regarding oncoming pedestrians)
96  static const double LOOKAHEAD_ONCOMING;
97 
98  // @brief the utility penalty for moving sideways (corresponds to meters)
99  static const double LATERAL_PENALTY;
100 
101  // @brief the utility penalty for obstructed (physically blocking me) stripes (corresponds to meters)
102  static const double OBSTRUCTED_PENALTY;
103 
104  // @brief the utility penalty for inappropriate (reserved for oncoming traffic or may violate my min gap) stripes (corresponds to meters)
105  static const double INAPPROPRIATE_PENALTY;
106 
107  // @brief the utility penalty for oncoming conflicts on stripes (corresponds to meters)
108  static const double ONCOMING_CONFLICT_PENALTY;
109 
110  // @brief the minimum utility that indicates obstruction
111  static const double OBSTRUCTION_THRESHOLD;
112 
113  // @brief the factor by which pedestrian width is reduced when sqeezing past each other
114  static const double SQUEEZE;
115 
116  // @brief the maximum distance (in meters) at which oncoming pedestrians block right turning traffic
117  static const double BLOCKER_LOOKAHEAD;
118 
119  // @brief fraction of the leftmost lanes to reserve for oncoming traffic
120  static const double RESERVE_FOR_ONCOMING_FACTOR;
122 
123  // @brief the time pedestrians take to reach maximum impatience
124  static const double MAX_WAIT_TOLERANCE;
125 
126  // @brief the fraction of forward speed to be used for lateral movemenk
127  static const double LATERAL_SPEED_FACTOR;
128 
129  // @brief the minimum distance to the next obstacle in order to start walking after stopped
130  static const double MIN_STARTUP_DIST;
131 
133 
134 
135 protected:
136  static const double DIST_FAR_AWAY;
137  static const double DIST_BEHIND;
138  static const double DIST_OVERLAP;
139 
141  public:
143  bool operator()(const MSLane* l1, const MSLane* l2) const {
144  return l1->getNumericalID() < l2->getNumericalID();
145  }
146  };
147 
148  struct Obstacle;
149  struct WalkingAreaPath;
150  class PState;
151  typedef std::vector<PState*> Pedestrians;
152  typedef std::map<const MSLane*, Pedestrians, lane_by_numid_sorter> ActiveLanes;
153  typedef std::vector<Obstacle> Obstacles;
154  typedef std::map<const MSLane*, Obstacles, lane_by_numid_sorter> NextLanesObstacles;
155  typedef std::map<std::pair<const MSLane*, const MSLane*>, WalkingAreaPath> WalkingAreaPaths;
156  typedef std::map<const MSLane*, double> MinNextLengths;
157 
158  struct NextLaneInfo {
159  NextLaneInfo(const MSLane* _lane, const MSLink* _link, int _dir) :
160  lane(_lane),
161  link(_link),
162  dir(_dir) {
163  }
164 
166  lane(0),
167  link(0),
168  dir(UNDEFINED_DIRECTION) {
169  }
170 
171  // @brief the next lane to be used
172  const MSLane* lane;
173  // @brief the link from the current lane to the next lane
174  const MSLink* link;
175  // @brief the direction on the next lane
176  int dir;
177  };
178 
180  struct Obstacle {
182  Obstacle(int dir, double dist = DIST_FAR_AWAY);
184  Obstacle(const PState& ped);
186  Obstacle(double _x, double _speed, const std::string& _description, const double width = 0., bool _border = false)
187  : xFwd(_x + width / 2.), xBack(_x - width / 2.), speed(_speed), description(_description), border(_border) {};
188 
190  double xFwd;
192  double xBack;
194  double speed;
196  std::string description;
198  bool border;
199  };
200 
202  WalkingAreaPath(const MSLane* _from, const MSLane* _walkingArea, const MSLane* _to, const PositionVector& _shape) :
203  from(_from),
204  to(_to),
205  lane(_walkingArea),
206  shape(_shape),
207  length(_shape.length()) {
208  }
209 
210  WalkingAreaPath(): from(0), to(0), lane(0) {};
211 
212  const MSLane* from;
213  const MSLane* to;
214  const MSLane* lane; // the walkingArea;
215  PositionVector shape; // actually const but needs to be copyable by some stl code
216  double length;
217 
218  };
219 
221  public:
223  bool operator()(const WalkingAreaPath* p1, const WalkingAreaPath* p2) const {
224  if (p1->from->getNumericalID() < p2->from->getNumericalID()) {
225  return true;
226  }
227  if (p1->from->getNumericalID() == p2->from->getNumericalID()) {
228  if (p1->to->getNumericalID() < p2->to->getNumericalID()) {
229  return true;
230  }
231  }
232  return false;
233  }
234  };
235 
236 
241  class PState : public PedestrianState {
242  public:
243 
246  double getEdgePos(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
247  Position getPosition(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
248  double getAngle(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
249  SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
250  double getSpeed(const MSPerson::MSPersonStage_Walking& stage) const;
251  const MSEdge* getNextEdge(const MSPerson::MSPersonStage_Walking& stage) const;
253 
254  PState(MSPerson* person, MSPerson::MSPersonStage_Walking* stage, const MSLane* lane);
255 
256  ~PState() {};
257  MSPerson* myPerson;
260  const MSLane* myLane;
262  double myRelX;
264  double myRelY;
266  int myDir;
268  double mySpeed;
279 
281  double getMinX(const bool includeMinGap = true) const;
282 
284  double getMaxX(const bool includeMinGap = true) const;
285 
287  double getLength() const;
288 
290  double getMinGap() const;
291 
293  double distToLaneEnd() const;
294 
296  bool moveToNextLane(SUMOTime currentTime);
297 
299  void walk(const Obstacles& obs, SUMOTime currentTime);
300 
302  double getImpatience(SUMOTime now) const;
303 
304  int stripe() const;
305  int otherStripe() const;
306 
307  int stripe(const double relY) const;
308  int otherStripe(const double relY) const;
309 
310  /* @brief calculate distance to the given obstacle,
311  * - non-negative values signify an obstacle in front of ego
312  * the special values DIST_OVERLAP and DIST_BEHIND are used to signify
313  * obstacles that overlap and obstacles behind ego respectively
314  * the result is the same regardless of walking direction
315  */
316  double distanceTo(const Obstacle& obs, const bool includeMinGap = true) const;
317 
319  void mergeObstacles(Obstacles& into, const Obstacles& obs2);
320 
321  };
322 
323  class MovePedestrians : public Command {
324  public:
327  SUMOTime execute(SUMOTime currentTime);
328  private:
330  private:
332  MovePedestrians& operator=(const MovePedestrians&);
333  };
334 
337  public:
339  by_xpos_sorter(int dir): myDir(dir) {}
340 
341  public:
343  bool operator()(const PState* p1, const PState* p2) const {
344  if (p1->myRelX != p2->myRelX) {
345  return myDir * p1->myRelX > myDir * p2->myRelX;
346  }
347  return p1->myPerson->getID() < p2->myPerson->getID();
348  }
349 
350  private:
351  const int myDir;
352 
353  private:
355  by_xpos_sorter& operator=(const by_xpos_sorter&);
356  };
357 
358 
360  void moveInDirection(SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
361 
363  void moveInDirectionOnLane(Pedestrians& pedestrians, const MSLane* lane, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
364 
366  void arriveAndAdvance(Pedestrians& pedestrians, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
367 
368  const ActiveLanes& getActiveLanes() {
369  return myActiveLanes;
370  }
371 
372 private:
373  static void DEBUG_PRINT(const Obstacles& obs);
374 
376  static int connectedDirection(const MSLane* from, const MSLane* to);
377 
383  static NextLaneInfo getNextLane(const PState& ped, const MSLane* currentLane, const MSLane* prevLane);
384 
386  static const MSLane* getNextWalkingArea(const MSLane* currentLane, const int dir, MSLink*& link);
387 
388  static void initWalkingAreaPaths(const MSNet* net);
389 
391  static int numStripes(const MSLane* lane);
392 
393  static Obstacles getNeighboringObstacles(const Pedestrians& pedestrians, int egoIndex, int stripes);
394 
395  const Obstacles& getNextLaneObstacles(NextLanesObstacles& nextLanesObs, const MSLane* lane, const MSLane* nextLane, int stripes,
396  int nextDir, double currentLength, int currentDir);
397 
398  static void transformToCurrentLanePositions(Obstacles& o, int currentDir, int nextDir, double currentLength, double nextLength);
399 
400  static void addCloserObstacle(Obstacles& obs, double x, int stripe, int numStripes, const std::string& id, double width, int dir);
401 
403  Pedestrians& getPedestrians(const MSLane* lane);
404 
405  /* @brief compute stripe-offset to transform relY values from a lane with origStripes into a lane wit destStrips
406  * @note this is called once for transforming nextLane peds to into the current system as obstacles and another time
407  * (in reverse) to transform the pedestrian coordinates into the nextLane-coordinates when changing lanes
408  */
409  static int getStripeOffset(int origStripes, int destStripes, bool addRemainder);
410 
411 
412 private:
415 
418 
420  ActiveLanes myActiveLanes;
421 
423  static WalkingAreaPaths myWalkingAreaPaths;
424  static MinNextLengths myMinNextLengths;
425 
427  static Pedestrians noPedestrians;
428 
429 };
430 
431 
432 #endif /* MSPModel_Striping_h */
433 
bool blockedAtDist(const MSLane *lane, double distToCrossing, std::vector< const MSPerson *> *collectBlockers)
whether a pedestrian is blocking the crossing of lane at offset distToCrossing
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...
void moveInDirection(SUMOTime currentTime, std::set< MSPerson *> &changedLane, int dir)
move all pedestrians forward and advance to the next lane if applicable
bool operator()(const WalkingAreaPath *p1, const WalkingAreaPath *p2) const
comparing operation
static const double LATERAL_SPEED_FACTOR
static const double SQUEEZE
MSPerson::MSPersonStage_Walking * myStage
static const double DIST_BEHIND
void moveInDirectionOnLane(Pedestrians &pedestrians, const MSLane *lane, SUMOTime currentTime, std::set< MSPerson *> &changedLane, int dir)
move pedestrians forward on one lane
static const double LOOKAHEAD_ONCOMING
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...
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)
static const double MIN_STARTUP_DIST
The pedestrian following model.
information regarding surround Pedestrians (and potentially other things)
The base class for an intersection.
Definition: MSJunction.h:64
MSPModel_Striping *const myModel
static const double BLOCKER_LOOKAHEAD
std::map< std::pair< const MSLane *, const MSLane * >, WalkingAreaPath > WalkingAreaPaths
Base (microsim) event class.
Definition: Command.h:61
static MSPModel * myModel
Definition: MSPModel.h:90
static WalkingAreaPaths myWalkingAreaPaths
store for walkinArea elements
static const double LATERAL_PENALTY
double mySpeed
the current walking speed
static const double OBSTRUCTION_THRESHOLD
The simulated network and simulation perfomer.
Definition: MSNet.h:94
bool myAmJammed
whether the person is jammed
static Pedestrians noPedestrians
empty pedestrian vector
int getNumericalID() const
Returns this lane&#39;s numerical id.
Definition: MSLane.h:418
NextLaneInfo myNLI
information about the upcoming lane
The pedestrian following model.
Definition: MSPModel.h:54
static const double RESERVE_FOR_ONCOMING_FACTOR_JUNCTIONS
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)
double xFwd
maximal position on the current lane in forward direction
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:78
static const double OBSTRUCTED_PENALTY
static const double DIST_OVERLAP
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
static int getStripeOffset(int origStripes, int destStripes, bool addRemainder)
A list of positions.
double myRelY
the orthogonal shift on the current lane
double xBack
maximal position on the current lane in backward direction
double myRelX
the advancement along the current lane
bool operator()(const PState *p1, const PState *p2) const
comparing operation
std::map< const MSLane *, Pedestrians, lane_by_numid_sorter > ActiveLanes
static double dawdling
const std::string & getID() const
returns the id of the transportable
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)
static const double LOOKAHEAD_SAMEDIR
double speed
speed relative to lane direction (positive means in the same direction)
const Obstacles & getNextLaneObstacles(NextLanesObstacles &nextLanesObs, const MSLane *lane, const MSLane *nextLane, int stripes, int nextDir, double currentLength, int currentDir)
void cleanupHelper()
remove state at simulation end
PedestrianState * add(MSPerson *person, MSPerson::MSPersonStage_Walking *stage, SUMOTime now)
register the given person as a pedestrian
bool border
whether this obstacle denotes a border or a pedestrian
static const double RESERVE_FOR_ONCOMING_FACTOR
MovePedestrians(MSPModel_Striping *model)
Obstacle(double _x, double _speed, const std::string &_description, const double width=0., bool _border=false)
create an obstacle from explict values
static void transformToCurrentLanePositions(Obstacles &o, int currentDir, int nextDir, double currentLength, double nextLength)
void arriveAndAdvance(Pedestrians &pedestrians, SUMOTime currentTime, std::set< MSPerson *> &changedLane, int dir)
handle arrivals and lane advancement
abstract base class for managing callbacks to retrieve various state information from the model ...
Definition: MSPModel.h:96
std::map< const MSLane *, double > MinNextLengths
static const double DIST_FAR_AWAY
static const double ONCOMING_CONFLICT_PENALTY
std::vector< PState * > Pedestrians
static double stripeWidth
model parameters
static const double INAPPROPRIATE_PENALTY
bool myWaitingToEnter
whether the pedestrian is waiting to start its walk
A storage for options typed value containers)
Definition: OptionsCont.h:99
Container for pedestrian state and individual position update function.
NextLaneInfo(const MSLane *_lane, const MSLink *_link, int _dir)
static void addCloserObstacle(Obstacles &obs, double x, int stripe, int numStripes, const std::string &id, double width, int dir)
std::vector< Obstacle > Obstacles
MovePedestrians * myCommand
the MovePedestrians command that is registered
long long int SUMOTime
Definition: TraCIDefs.h:52
static void DEBUG_PRINT(const Obstacles &obs)
const ActiveLanes & getActiveLanes()
static SUMOTime jamTime
int myNumActivePedestrians
the total number of active pedestrians
static MinNextLengths myMinNextLengths
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)
static const double MAX_WAIT_TOLERANCE
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
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