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 
83  bool blockedAtDist(const MSLane* lane, double vehSide, double vehWidth,
84  double oncomingGap, std::vector<const MSPerson*>* collectBlockers);
85 
87  bool hasPedestrians(const MSLane* lane);
88 
90  PersonDist nextBlocking(const MSLane* lane, double minPos, double minRight, double maxLeft, double stopTime = 0);
91 
93  void cleanupHelper();
94 
97 
98  // @brief the width of a pedstrian stripe
99  static double stripeWidth;
100 
101  // @brief the factor for random slow-down
102  static double dawdling;
103 
104  // @brief the time threshold before becoming jammed
106 
107  // @brief the distance (in seconds) to look ahead for changing stripes
108  static const double LOOKAHEAD_SAMEDIR;
109  // @brief the distance (in seconds) to look ahead for changing stripes (regarding oncoming pedestrians)
110  static const double LOOKAHEAD_ONCOMING;
111  // @brief the distance (in m) to look around for vehicles
112  static const double LOOKAROUND_VEHICLES;
113 
114  // @brief the utility penalty for moving sideways (corresponds to meters)
115  static const double LATERAL_PENALTY;
116 
117  // @brief the utility penalty for obstructed (physically blocking me) stripes (corresponds to meters)
118  static const double OBSTRUCTED_PENALTY;
119 
120  // @brief the utility penalty for inappropriate (reserved for oncoming traffic or may violate my min gap) stripes (corresponds to meters)
121  static const double INAPPROPRIATE_PENALTY;
122 
123  // @brief the utility penalty for oncoming conflicts on stripes (corresponds to meters)
124  static const double ONCOMING_CONFLICT_PENALTY;
125 
126  // @brief the minimum utility that indicates obstruction
127  static const double OBSTRUCTION_THRESHOLD;
128 
129  // @brief the factor by which pedestrian width is reduced when sqeezing past each other
130  static const double SQUEEZE;
131 
132  // @brief fraction of the leftmost lanes to reserve for oncoming traffic
133  static const double RESERVE_FOR_ONCOMING_FACTOR;
135 
136  // @brief the time pedestrians take to reach maximum impatience
137  static const double MAX_WAIT_TOLERANCE;
138 
139  // @brief the fraction of forward speed to be used for lateral movemenk
140  static const double LATERAL_SPEED_FACTOR;
141 
142  // @brief the minimum distance to the next obstacle in order to start walking after stopped
143  static const double MIN_STARTUP_DIST;
144 
146 
147 
148 protected:
149  static const double DIST_FAR_AWAY;
150  static const double DIST_BEHIND;
151  static const double DIST_OVERLAP;
152 
154  public:
156  bool operator()(const MSLane* l1, const MSLane* l2) const {
157  return l1->getNumericalID() < l2->getNumericalID();
158  }
159  };
160 
161  struct Obstacle;
162  struct WalkingAreaPath;
163  class PState;
164  typedef std::vector<PState*> Pedestrians;
165  typedef std::map<const MSLane*, Pedestrians, lane_by_numid_sorter> ActiveLanes;
166  typedef std::vector<Obstacle> Obstacles;
167  typedef std::map<const MSLane*, Obstacles, lane_by_numid_sorter> NextLanesObstacles;
168  typedef std::map<std::pair<const MSLane*, const MSLane*>, WalkingAreaPath> WalkingAreaPaths;
169  typedef std::map<const MSLane*, double> MinNextLengths;
170 
171  struct NextLaneInfo {
172  NextLaneInfo(const MSLane* _lane, const MSLink* _link, int _dir) :
173  lane(_lane),
174  link(_link),
175  dir(_dir) {
176  }
177 
179  lane(0),
180  link(0),
181  dir(UNDEFINED_DIRECTION) {
182  }
183 
184  // @brief the next lane to be used
185  const MSLane* lane;
186  // @brief the link from the current lane to the next lane
187  const MSLink* link;
188  // @brief the direction on the next lane
189  int dir;
190  };
191 
200  };
201 
203  struct Obstacle {
205  Obstacle(int dir, double dist = DIST_FAR_AWAY);
207  Obstacle(const PState& ped);
209  Obstacle(double _x, double _speed, ObstacleType _type, const std::string& _description, const double width = 0.)
210  : xFwd(_x + width / 2.), xBack(_x - width / 2.), speed(_speed), type(_type), description(_description) {};
211 
213  double xFwd;
215  double xBack;
217  double speed;
221  std::string description;
222  };
223 
225  WalkingAreaPath(const MSLane* _from, const MSLane* _walkingArea, const MSLane* _to, const PositionVector& _shape) :
226  from(_from),
227  to(_to),
228  lane(_walkingArea),
229  shape(_shape),
230  length(_shape.length()) {
231  }
232 
233  WalkingAreaPath(): from(0), to(0), lane(0) {};
234 
235  const MSLane* from;
236  const MSLane* to;
237  const MSLane* lane; // the walkingArea;
238  PositionVector shape; // actually const but needs to be copyable by some stl code
239  double length;
240 
241  };
242 
244  public:
246  bool operator()(const WalkingAreaPath* p1, const WalkingAreaPath* p2) const {
247  if (p1->from->getNumericalID() < p2->from->getNumericalID()) {
248  return true;
249  }
250  if (p1->from->getNumericalID() == p2->from->getNumericalID()) {
251  if (p1->to->getNumericalID() < p2->to->getNumericalID()) {
252  return true;
253  }
254  }
255  return false;
256  }
257  };
258 
259 
264  class PState : public PedestrianState {
265  public:
266 
269  double getEdgePos(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
270  Position getPosition(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
271  double getAngle(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
272  SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
273  double getSpeed(const MSPerson::MSPersonStage_Walking& stage) const;
274  const MSEdge* getNextEdge(const MSPerson::MSPersonStage_Walking& stage) const;
276 
277  PState(MSPerson* person, MSPerson::MSPersonStage_Walking* stage, const MSLane* lane);
278 
279  ~PState() {};
280  MSPerson* myPerson;
283  const MSLane* myLane;
285  double myRelX;
287  double myRelY;
289  int myDir;
291  double mySpeed;
302 
304  double getMinX(const bool includeMinGap = true) const;
305 
307  double getMaxX(const bool includeMinGap = true) const;
308 
310  double getLength() const;
311 
313  double getMinGap() const;
314 
316  double distToLaneEnd() const;
317 
319  bool moveToNextLane(SUMOTime currentTime);
320 
322  void walk(const Obstacles& obs, SUMOTime currentTime);
323 
325  double getImpatience(SUMOTime now) const;
326 
327  int stripe() const;
328  int otherStripe() const;
329 
330  static int stripe(const double relY);
331  int otherStripe(const double relY) const;
332 
333  /* @brief calculate distance to the given obstacle,
334  * - non-negative values signify an obstacle in front of ego
335  * the special values DIST_OVERLAP and DIST_BEHIND are used to signify
336  * obstacles that overlap and obstacles behind ego respectively
337  * the result is the same regardless of walking direction
338  */
339  double distanceTo(const Obstacle& obs, const bool includeMinGap = true) const;
340 
342  void mergeObstacles(Obstacles& into, const Obstacles& obs2);
343 
345  bool ignoreRed(const MSLink* link) const;
346  };
347 
348  class MovePedestrians : public Command {
349  public:
352  SUMOTime execute(SUMOTime currentTime);
353  private:
355  private:
357  MovePedestrians& operator=(const MovePedestrians&);
358  };
359 
362  public:
364  by_xpos_sorter(int dir): myDir(dir) {}
365 
366  public:
368  bool operator()(const PState* p1, const PState* p2) const {
369  if (p1->myRelX != p2->myRelX) {
370  return myDir * p1->myRelX > myDir * p2->myRelX;
371  }
372  return p1->myPerson->getID() < p2->myPerson->getID();
373  }
374 
375  private:
376  const int myDir;
377 
378  private:
380  by_xpos_sorter& operator=(const by_xpos_sorter&);
381  };
382 
383 
385  void moveInDirection(SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
386 
388  void moveInDirectionOnLane(Pedestrians& pedestrians, const MSLane* lane, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
389 
391  void arriveAndAdvance(Pedestrians& pedestrians, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
392 
393  const ActiveLanes& getActiveLanes() {
394  return myActiveLanes;
395  }
396 
397 private:
398  static void DEBUG_PRINT(const Obstacles& obs);
399 
401  static int connectedDirection(const MSLane* from, const MSLane* to);
402 
408  static NextLaneInfo getNextLane(const PState& ped, const MSLane* currentLane, const MSLane* prevLane);
409 
411  static const MSLane* getNextWalkingArea(const MSLane* currentLane, const int dir, MSLink*& link);
412 
413  static void initWalkingAreaPaths(const MSNet* net);
414 
416  static WalkingAreaPath* getArbitraryPath(const MSEdge* walkingArea);
417 
419  static int numStripes(const MSLane* lane);
420 
421  static Obstacles getNeighboringObstacles(const Pedestrians& pedestrians, int egoIndex, int stripes);
422 
423  const Obstacles& getNextLaneObstacles(NextLanesObstacles& nextLanesObs, const MSLane* lane, const MSLane* nextLane, int stripes,
424  int nextDir, double currentLength, int currentDir);
425 
426  static void transformToCurrentLanePositions(Obstacles& o, int currentDir, int nextDir, double currentLength, double nextLength);
427 
428  static void addCloserObstacle(Obstacles& obs, double x, int stripe, int numStripes, const std::string& id, double width, int dir, ObstacleType type);
429 
431  Pedestrians& getPedestrians(const MSLane* lane);
432 
433  /* @brief compute stripe-offset to transform relY values from a lane with origStripes into a lane wit destStrips
434  * @note this is called once for transforming nextLane peds to into the current system as obstacles and another time
435  * (in reverse) to transform the pedestrian coordinates into the nextLane-coordinates when changing lanes
436  */
437  static int getStripeOffset(int origStripes, int destStripes, bool addRemainder);
438 
440  static bool addCrossingVehs(const MSLane* crossing, int stripes, double lateral_offset, int dir, Obstacles& crossingVehs);
441 private:
444 
447 
449  ActiveLanes myActiveLanes;
450 
452  static WalkingAreaPaths myWalkingAreaPaths;
453  static MinNextLengths myMinNextLengths;
454 
456  static Pedestrians noPedestrians;
457 
458 };
459 
460 
461 #endif /* MSPModel_Striping_h */
462 
int getNumericalID() const
Returns this lane&#39;s numerical id.
Definition: MSLane.h:418
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 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
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 WalkingAreaPath * getArbitraryPath(const MSEdge *walkingArea)
return an arbitrary path across the given walkingArea
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
const std::string & getID() const
returns the id of the transportable
std::map< std::pair< const MSLane *, const MSLane * >, WalkingAreaPath > WalkingAreaPaths
Base (microsim) event class.
Definition: Command.h:61
static MSPModel * myModel
Definition: MSPModel.h:123
static WalkingAreaPaths myWalkingAreaPaths
store for walkinArea elements
static const double LATERAL_PENALTY
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 ...
double mySpeed
the current walking speed
static const double OBSTRUCTION_THRESHOLD
The simulated network and simulation perfomer.
Definition: MSNet.h:89
bool myAmJammed
whether the person is jammed
Obstacle(double _x, double _speed, ObstacleType _type, const std::string &_description, const double width=0.)
create an obstacle from explict values
static Pedestrians noPedestrians
empty pedestrian vector
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:56
static const double RESERVE_FOR_ONCOMING_FACTOR_JUNCTIONS
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)
double xFwd
maximal position on the current lane in forward direction
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:111
void arriveAndAdvance(Pedestrians &pedestrians, SUMOTime currentTime, std::set< MSPerson * > &changedLane, int dir)
handle arrivals and lane advancement
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
std::map< const MSLane *, Pedestrians, lane_by_numid_sorter > ActiveLanes
static double dawdling
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
static const double RESERVE_FOR_ONCOMING_FACTOR
MovePedestrians(MSPModel_Striping *model)
static void transformToCurrentLanePositions(Obstacles &o, int currentDir, int nextDir, double currentLength, double nextLength)
abstract base class for managing callbacks to retrieve various state information from the model ...
Definition: MSPModel.h:129
std::pair< const MSPerson *, double > PersonDist
Definition: MSPModel.h:44
bool hasPedestrians(const MSLane *lane)
whether the given lane has pedestrians on it
std::map< const MSLane *, double > MinNextLengths
ObstacleType type
whether this obstacle denotes a border or a pedestrian
static const double DIST_FAR_AWAY
static const double ONCOMING_CONFLICT_PENALTY
std::vector< PState * > Pedestrians
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 ...
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)
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)
static void addCloserObstacle(Obstacles &obs, double x, int stripe, int numStripes, const std::string &id, double width, int dir, ObstacleType type)
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
void moveInDirectionOnLane(Pedestrians &pedestrians, const MSLane *lane, SUMOTime currentTime, std::set< MSPerson * > &changedLane, int dir)
move pedestrians forward on one lane
static bool addCrossingVehs(const MSLane *crossing, int stripes, double lateral_offset, int dir, Obstacles &crossingVehs)
add vehicles driving across
static const double LOOKAROUND_VEHICLES