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, SUMOReal distToCrossing, std::vector<const MSPerson*>* collectBlockers);
77 
79  void cleanupHelper();
80 
83 
84  // @brief the width of a pedstrian stripe
86 
87  // @brief the factor for random slow-down
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
95  // @brief the distance (in seconds) to look ahead for changing stripes (regarding oncoming pedestrians)
97 
98  // @brief the utility penalty for moving sideways (corresponds to meters)
99  static const SUMOReal LATERAL_PENALTY;
100 
101  // @brief the utility penalty for obstructed (physically blocking me) stripes (corresponds to meters)
103 
104  // @brief the utility penalty for inappropriate (reserved for oncoming traffic or may violate my min gap) stripes (corresponds to meters)
106 
107  // @brief the utility penalty for oncoming conflicts on stripes (corresponds to meters)
109 
110  // @brief the minimum utility that indicates obstruction
112 
113  // @brief the factor by which pedestrian width is reduced when sqeezing past each other
114  static const SUMOReal SQUEEZE;
115 
116  // @brief the maximum distance (in meters) at which oncoming pedestrians block right turning traffic
118 
119  // @brief fraction of the leftmost lanes to reserve for oncoming traffic
122 
123  // @brief the time pedestrians take to reach maximum impatience
125 
126  // @brief the fraction of forward speed to be used for lateral movemenk
128 
129  // @brief the minimum distance to the next obstacle in order to start walking after stopped
131 
133 
134 
135 protected:
136  static const SUMOReal DIST_FAR_AWAY;
137  static const SUMOReal DIST_BEHIND;
138  static const SUMOReal 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 
157  struct NextLaneInfo {
158  NextLaneInfo(const MSLane* _lane, const MSLink* _link, int _dir) :
159  lane(_lane),
160  link(_link),
161  dir(_dir) {
162  }
163 
165  lane(0),
166  link(0),
167  dir(UNDEFINED_DIRECTION) {
168  }
169 
170  // @brief the next lane to be used
171  const MSLane* lane;
172  // @brief the link from the current lane to the next lane
173  const MSLink* link;
174  // @brief the direction on the next lane
175  int dir;
176  };
177 
179  struct Obstacle {
181  Obstacle(int dir, SUMOReal dist = DIST_FAR_AWAY);
183  Obstacle(const PState& ped);
185  Obstacle(SUMOReal _x, SUMOReal _speed, const std::string& _description, const SUMOReal width = 0., bool _border = false)
186  : xFwd(_x + width / 2.), xBack(_x - width / 2.), speed(_speed), description(_description), border(_border) {};
187 
189  SUMOReal xFwd;
195  std::string description;
197  bool border;
198  };
199 
201  WalkingAreaPath(const MSLane* _from, const MSLane* _walkingArea, const MSLane* _to, const PositionVector& _shape) :
202  from(_from),
203  to(_to),
204  lane(_walkingArea),
205  shape(_shape),
206  length(_shape.length()) {
207  }
208 
209  WalkingAreaPath(): from(0), to(0), lane(0) {};
210 
211  const MSLane* from;
212  const MSLane* to;
213  const MSLane* lane; // the walkingArea;
214  PositionVector shape; // actually const but needs to be copyable by some stl code
216 
217  };
218 
220  public:
222  bool operator()(const WalkingAreaPath* p1, const WalkingAreaPath* p2) const {
223  if (p1->from->getNumericalID() < p2->from->getNumericalID()) {
224  return true;
225  }
226  if (p1->from->getNumericalID() == p2->from->getNumericalID()) {
227  if (p1->to->getNumericalID() < p2->to->getNumericalID()) {
228  return true;
229  }
230  }
231  return false;
232  }
233  };
234 
235 
240  class PState : public PedestrianState {
241  public:
242 
245  SUMOReal getEdgePos(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
246  Position getPosition(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
247  SUMOReal getAngle(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
248  SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
249  SUMOReal getSpeed(const MSPerson::MSPersonStage_Walking& stage) const;
250  const MSEdge* getNextEdge(const MSPerson::MSPersonStage_Walking& stage) const;
252 
253  PState(MSPerson* person, MSPerson::MSPersonStage_Walking* stage, const MSLane* lane);
254 
255  ~PState() {};
256  MSPerson* myPerson;
259  const MSLane* myLane;
265  int myDir;
278 
280  SUMOReal getMinX(const bool includeMinGap = true) const;
281 
283  SUMOReal getMaxX(const bool includeMinGap = true) const;
284 
286  SUMOReal getLength() const;
287 
289  SUMOReal getMinGap() const;
290 
292  SUMOReal distToLaneEnd() const;
293 
295  bool moveToNextLane(SUMOTime currentTime);
296 
298  void walk(const Obstacles& obs, SUMOTime currentTime);
299 
301  SUMOReal getImpatience(SUMOTime now) const;
302 
303  int stripe() const;
304  int otherStripe() const;
305 
306  int stripe(const SUMOReal relY) const;
307  int otherStripe(const SUMOReal relY) const;
308 
309  /* @brief calculate distance to the given obstacle,
310  * - non-negative values signify an obstacle in front of ego
311  * the special values DIST_OVERLAP and DIST_BEHIND are used to signify
312  * obstacles that overlap and obstacles behind ego respectively
313  * the result is the same regardless of walking direction
314  */
315  SUMOReal distanceTo(const Obstacle& obs, const bool includeMinGap = true) const;
316 
318  void mergeObstacles(Obstacles& into, const Obstacles& obs2);
319 
320  };
321 
322  class MovePedestrians : public Command {
323  public:
326  SUMOTime execute(SUMOTime currentTime);
327  private:
329  private:
331  MovePedestrians& operator=(const MovePedestrians&);
332  };
333 
336  public:
338  by_xpos_sorter(int dir): myDir(dir) {}
339 
340  public:
342  bool operator()(const PState* p1, const PState* p2) const {
343  if (p1->myRelX != p2->myRelX) {
344  return myDir * p1->myRelX > myDir * p2->myRelX;
345  }
346  return p1->myPerson->getID() < p2->myPerson->getID();
347  }
348 
349  private:
350  const int myDir;
351 
352  private:
354  by_xpos_sorter& operator=(const by_xpos_sorter&);
355  };
356 
357 
359  void moveInDirection(SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
360 
362  void moveInDirectionOnLane(Pedestrians& pedestrians, const MSLane* lane, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
363 
365  void arriveAndAdvance(Pedestrians& pedestrians, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
366 
367  const ActiveLanes& getActiveLanes() {
368  return myActiveLanes;
369  }
370 
371 private:
372  static void DEBUG_PRINT(const Obstacles& obs);
373 
375  static int connectedDirection(const MSLane* from, const MSLane* to);
376 
382  static NextLaneInfo getNextLane(const PState& ped, const MSLane* currentLane, const MSLane* prevLane);
383 
385  static const MSLane* getNextWalkingArea(const MSLane* currentLane, const int dir, MSLink*& link);
386 
387  static void initWalkingAreaPaths(const MSNet* net);
388 
390  static int numStripes(const MSLane* lane);
391 
392  static Obstacles getNeighboringObstacles(const Pedestrians& pedestrians, int egoIndex, int stripes);
393 
394  const Obstacles& getNextLaneObstacles(NextLanesObstacles& nextLanesObs, const MSLane* lane, const MSLane* nextLane, int stripes,
395  SUMOReal nextLength, int nextDir, SUMOReal currentLength, int currentDir);
396 
397  static void transformToCurrentLanePositions(Obstacles& o, int currentDir, int nextDir, SUMOReal currentLength, SUMOReal nextLength);
398 
399  static void addCloserObstacle(Obstacles& obs, SUMOReal x, int stripe, int numStripes, const std::string& id, SUMOReal width, int dir);
400 
402  Pedestrians& getPedestrians(const MSLane* lane);
403 
404  /* @brief compute stripe-offset to transform relY values from a lane with origStripes into a lane wit destStrips
405  * @note this is called once for transforming nextLane peds to into the current system as obstacles and another time
406  * (in reverse) to transform the pedestrian coordinates into the nextLane-coordinates when changing lanes
407  */
408  static int getStripeOffset(int origStripes, int destStripes, bool addRemainder);
409 
410 
411 private:
414 
417 
419  ActiveLanes myActiveLanes;
420 
422  static WalkingAreaPaths myWalkingAreaPaths;
423 
425  static Pedestrians noPedestrians;
426 
427 };
428 
429 
430 #endif /* MSPModel_Striping_h */
431 
const Obstacles & getNextLaneObstacles(NextLanesObstacles &nextLanesObs, const MSLane *lane, const MSLane *nextLane, int stripes, SUMOReal nextLength, int nextDir, SUMOReal currentLength, int currentDir)
int getNumericalID() const
Returns this lane&#39;s numerical id.
Definition: MSLane.h:419
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
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
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
static const SUMOReal DIST_OVERLAP
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
static void transformToCurrentLanePositions(Obstacles &o, int currentDir, int nextDir, SUMOReal currentLength, SUMOReal nextLength)
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:78
void arriveAndAdvance(Pedestrians &pedestrians, SUMOTime currentTime, std::set< MSPerson * > &changedLane, int dir)
handle arrivals and lane advancement
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 int getStripeOffset(int origStripes, int destStripes, bool addRemainder)
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.
static const SUMOReal DIST_BEHIND
Obstacle(SUMOReal _x, SUMOReal _speed, const std::string &_description, const SUMOReal width=0., bool _border=false)
create an obstacle from explict values
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)
static const SUMOReal RESERVE_FOR_ONCOMING_FACTOR_JUNCTIONS
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 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:99
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
static const SUMOReal DIST_FAR_AWAY
#define SUMOReal
Definition: config.h:208
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: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
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