Eclipse SUMO - Simulation of Urban MObility
MSPModel_Striping.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2014-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // The pedestrian following model (prototype)
17 /****************************************************************************/
18 #ifndef MSPModel_Striping_h
19 #define MSPModel_Striping_h
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
27 #include <limits>
28 #include <utils/common/SUMOTime.h>
29 #include <utils/common/Command.h>
31 #include <microsim/MSLane.h>
32 #include "MSPerson.h"
33 #include "MSPModel.h"
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class MSNet;
39 class MSLink;
40 class MSJunction;
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
51 class MSPModel_Striping : public MSPModel {
52 
53  friend class GUIPerson; // for debugging
54 
55 public:
56 
58  MSPModel_Striping(const OptionsCont& oc, MSNet* net);
59 
61 
64 
66  void add(PedestrianState* pState, const MSLane* lane);
67 
69  void remove(PedestrianState* state);
70 
79  bool blockedAtDist(const MSLane* lane, double vehSide, double vehWidth,
80  double oncomingGap, std::vector<const MSPerson*>* collectBlockers);
81 
83  bool hasPedestrians(const MSLane* lane);
84 
87  bool usingInternalLanes();
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
107 
108  // @brief the distance (in seconds) to look ahead for changing stripes
109  static const double LOOKAHEAD_SAMEDIR;
110  // @brief the distance (in seconds) to look ahead for changing stripes (regarding oncoming pedestrians)
111  static const double LOOKAHEAD_ONCOMING;
112  // @brief the distance (in m) to look around for vehicles
113  static const double LOOKAROUND_VEHICLES;
114 
115  // @brief the utility penalty for moving sideways (corresponds to meters)
116  static const double LATERAL_PENALTY;
117 
118  // @brief the utility penalty for obstructed (physically blocking me) stripes (corresponds to meters)
119  static const double OBSTRUCTED_PENALTY;
120 
121  // @brief the utility penalty for inappropriate (reserved for oncoming traffic or may violate my min gap) stripes (corresponds to meters)
122  static const double INAPPROPRIATE_PENALTY;
123 
124  // @brief the utility penalty for oncoming conflicts on stripes (corresponds to meters)
125  static const double ONCOMING_CONFLICT_PENALTY;
126 
127  // @brief the minimum utility that indicates obstruction
128  static const double OBSTRUCTION_THRESHOLD;
129 
130  // @brief the factor by which pedestrian width is reduced when sqeezing past each other
131  static const double SQUEEZE;
132 
133  // @brief fraction of the leftmost lanes to reserve for oncoming traffic
134  static const double RESERVE_FOR_ONCOMING_FACTOR;
136 
137  // @brief the time pedestrians take to reach maximum impatience
138  static const double MAX_WAIT_TOLERANCE;
139 
140  // @brief the fraction of forward speed to be used for lateral movemenk
141  static const double LATERAL_SPEED_FACTOR;
142 
143  // @brief the minimum distance to the next obstacle in order to start walking after stopped
144  static const double MIN_STARTUP_DIST;
145 
147 
148 
149 protected:
150  static const double DIST_FAR_AWAY;
151  static const double DIST_BEHIND;
152  static const double DIST_OVERLAP;
153 
155  public:
157  bool operator()(const MSLane* l1, const MSLane* l2) const {
158  return l1->getNumericalID() < l2->getNumericalID();
159  }
160  };
161 
162  struct Obstacle;
163  struct WalkingAreaPath;
164  class PState;
165  typedef std::vector<PState*> Pedestrians;
166  typedef std::map<const MSLane*, Pedestrians, lane_by_numid_sorter> ActiveLanes;
167  typedef std::vector<Obstacle> Obstacles;
168  typedef std::map<const MSLane*, Obstacles, lane_by_numid_sorter> NextLanesObstacles;
169  typedef std::map<std::pair<const MSLane*, const MSLane*>, WalkingAreaPath> WalkingAreaPaths;
170  typedef std::map<const MSLane*, double> MinNextLengths;
171 
172  struct NextLaneInfo {
173  NextLaneInfo(const MSLane* _lane, const MSLink* _link, int _dir) :
174  lane(_lane),
175  link(_link),
176  dir(_dir) {
177  }
178 
180  lane(0),
181  link(0),
182  dir(UNDEFINED_DIRECTION) {
183  }
184 
185  // @brief the next lane to be used
186  const MSLane* lane;
187  // @brief the link from the current lane to the next lane
188  const MSLink* link;
189  // @brief the direction on the next lane
190  int dir;
191  };
192 
201  };
202 
204  struct Obstacle {
206  Obstacle(int dir, double dist = DIST_FAR_AWAY);
208  Obstacle(const PState& ped);
210  Obstacle(double _x, double _speed, ObstacleType _type, const std::string& _description, const double width = 0.)
211  : xFwd(_x + width / 2.), xBack(_x - width / 2.), speed(_speed), type(_type), description(_description) {};
212 
214  double xFwd;
216  double xBack;
218  double speed;
222  std::string description;
223  };
224 
226  WalkingAreaPath(const MSLane* _from, const MSLane* _walkingArea, const MSLane* _to, const PositionVector& _shape) :
227  from(_from),
228  to(_to),
229  lane(_walkingArea),
230  shape(_shape),
231  length(_shape.length()) {
232  }
233 
234  WalkingAreaPath(): from(0), to(0), lane(0) {};
235 
236  const MSLane* from;
237  const MSLane* to;
238  const MSLane* lane; // the walkingArea;
239  PositionVector shape; // actually const but needs to be copyable by some stl code
240  double length;
241 
242  };
243 
245  public:
247  bool operator()(const WalkingAreaPath* p1, const WalkingAreaPath* p2) const {
248  if (p1->from->getNumericalID() < p2->from->getNumericalID()) {
249  return true;
250  }
251  if (p1->from->getNumericalID() == p2->from->getNumericalID()) {
252  if (p1->to->getNumericalID() < p2->to->getNumericalID()) {
253  return true;
254  }
255  }
256  return false;
257  }
258  };
259 
260 
265  class PState : public PedestrianState {
266  public:
267 
270  double getEdgePos(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
271  Position getPosition(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
272  double getAngle(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
273  SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
274  double getSpeed(const MSPerson::MSPersonStage_Walking& stage) const;
275  const MSEdge* getNextEdge(const MSPerson::MSPersonStage_Walking& stage) const;
276  void moveToXY(MSPerson* p, Position pos, MSLane* lane, double lanePos,
277  double lanePosLat, double angle, int routeOffset,
278  const ConstMSEdgeVector& edges, SUMOTime t);
279 
281 
282  PState(MSPerson* person, MSPerson::MSPersonStage_Walking* stage, const MSLane* lane);
283 
284 
285  ~PState() {};
286  MSPerson* myPerson;
289  const MSLane* myLane;
291  double myRelX;
293  double myRelY;
295  int myDir;
297  double mySpeed;
311  mutable double myAngle;
312 
314  virtual double getMinX(const bool includeMinGap = true) const;
315 
317  virtual double getMaxX(const bool includeMinGap = true) const;
318 
320  double getLength() const;
321 
323  double getMinGap() const;
324 
326  double distToLaneEnd() const;
327 
329  bool moveToNextLane(SUMOTime currentTime);
330 
332  void walk(const Obstacles& obs, SUMOTime currentTime);
333 
335  double getImpatience(SUMOTime now) const;
336 
337  int stripe() const;
338  int otherStripe() const;
339 
340  static int stripe(const double relY);
341  int otherStripe(const double relY) const;
342 
343  /* @brief calculate distance to the given obstacle,
344  * - non-negative values signify an obstacle in front of ego
345  * the special values DIST_OVERLAP and DIST_BEHIND are used to signify
346  * obstacles that overlap and obstacles behind ego respectively
347  * the result is the same regardless of walking direction
348  */
349  double distanceTo(const Obstacle& obs, const bool includeMinGap = true) const;
350 
352  void mergeObstacles(Obstacles& into, const Obstacles& obs2);
353 
355  static void mergeObstacles(Obstacles& into, const Obstacles& obs2, int dir, int offset);
356 
358  bool ignoreRed(const MSLink* link) const;
359 
361  virtual const std::string& getID() const;
362 
364  virtual double getWidth() const;
365 
366  protected:
368  PState();
369  };
370 
371  class PStateVehicle : public PState {
372  public:
373  PStateVehicle(const MSVehicle* veh, const MSLane* walkingarea, double relX, double relY);
374  const std::string& getID() const;
375  double getMinX(const bool includeMinGap = true) const;
376  double getMaxX(const bool includeMinGap = true) const;
377  double getWidth() const;
378  private:
380  };
381 
382 
383  class MovePedestrians : public Command {
384  public:
387  SUMOTime execute(SUMOTime currentTime);
388  private:
390  private:
392  MovePedestrians& operator=(const MovePedestrians&);
393  };
394 
397  public:
399  by_xpos_sorter(int dir): myDir(dir) {}
400 
401  public:
403  bool operator()(const PState* p1, const PState* p2) const {
404  if (p1->myRelX != p2->myRelX) {
405  return myDir * p1->myRelX > myDir * p2->myRelX;
406  }
407  return p1->getID() < p2->getID();
408  }
409 
410  private:
411  const int myDir;
412 
413  private:
415  by_xpos_sorter& operator=(const by_xpos_sorter&);
416  };
417 
418 
420  void moveInDirection(SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
421 
423  void moveInDirectionOnLane(Pedestrians& pedestrians, const MSLane* lane, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
424 
426  void arriveAndAdvance(Pedestrians& pedestrians, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
427 
428  const ActiveLanes& getActiveLanes() {
429  return myActiveLanes;
430  }
431 
432 private:
433  static void DEBUG_PRINT(const Obstacles& obs);
434 
436  static int connectedDirection(const MSLane* from, const MSLane* to);
437 
443  static NextLaneInfo getNextLane(const PState& ped, const MSLane* currentLane, const MSLane* prevLane);
444 
446  static const MSLane* getNextWalkingArea(const MSLane* currentLane, const int dir, MSLink*& link);
447 
448  static void initWalkingAreaPaths(const MSNet* net);
449 
451  static WalkingAreaPath* getArbitraryPath(const MSEdge* walkingArea);
452 
454  static int numStripes(const MSLane* lane);
455 
456  static Obstacles getNeighboringObstacles(const Pedestrians& pedestrians, int egoIndex, int stripes);
457 
458  const Obstacles& getNextLaneObstacles(NextLanesObstacles& nextLanesObs, const MSLane* lane, const MSLane* nextLane, int stripes,
459  int nextDir, double currentLength, int currentDir);
460 
461  static void transformToCurrentLanePositions(Obstacles& o, int currentDir, int nextDir, double currentLength, double nextLength);
462 
463  static void addCloserObstacle(Obstacles& obs, double x, int stripe, int numStripes, const std::string& id, double width, int dir, ObstacleType type);
464 
466  Pedestrians& getPedestrians(const MSLane* lane);
467 
468  /* @brief compute stripe-offset to transform relY values from a lane with origStripes into a lane wit destStrips
469  * @note this is called once for transforming nextLane peds to into the current system as obstacles and another time
470  * (in reverse) to transform the pedestrian coordinates into the nextLane-coordinates when changing lanes
471  */
472  static int getStripeOffset(int origStripes, int destStripes, bool addRemainder);
473 
475  static bool addCrossingVehs(const MSLane* crossing, int stripes, double lateral_offset, int dir, Obstacles& crossingVehs, bool prio);
476 
478  static Obstacles getVehicleObstacles(const MSLane* lane, int dir, PState* ped = 0);
479 
480  static bool usingInternalLanesStatic();
481 
482  static bool addVehicleFoe(const MSVehicle* veh, const MSLane* walkingarea, const Position& relPos, double lateral_offset,
483  double minY, double maxY, Pedestrians& toDelete, Pedestrians& transformedPeds);
484 private:
487 
489  ActiveLanes myActiveLanes;
490 
493 
495  static WalkingAreaPaths myWalkingAreaPaths;
496  static std::map<const MSEdge*, std::vector<const MSLane*> > myWalkingAreaFoes;
497  static MinNextLengths myMinNextLengths;
498 
500  static Pedestrians noPedestrians;
501 
502 };
503 
504 
505 #endif /* MSPModel_Striping_h */
506 
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 myAmActive
whether an event for pedestrian processing was added
bool operator()(const WalkingAreaPath *p1, const WalkingAreaPath *p2) const
comparing operation
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
long long int SUMOTime
Definition: SUMOTime.h:35
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 SUMOTime jamTimeCrossing
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
virtual const std::string & getID() const
return the person id
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:61
MSPModel_Striping *const myModel
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:73
bool usingInternalLanes()
whether movements on intersections are modelled /
std::map< std::pair< const MSLane *, const MSLane * >, WalkingAreaPath > WalkingAreaPaths
static bool usingInternalLanesStatic()
Base (microsim) event class.
Definition: Command.h:53
static MSPModel * myModel
Definition: MSPModel.h:122
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:92
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
int getNumericalID() const
Returns this lane&#39;s numerical id.
Definition: MSLane.h:470
NextLaneInfo myNLI
information about the upcoming lane
The pedestrian following model.
Definition: MSPModel.h:50
static const double RESERVE_FOR_ONCOMING_FACTOR_JUNCTIONS
A road/street connecting two junctions.
Definition: MSEdge.h:76
Pedestrians & getPedestrians(const MSLane *lane)
retrieves the pedestian vector for the given lane (may be empty)
static bool addCrossingVehs(const MSLane *crossing, int stripes, double lateral_offset, int dir, Obstacles &crossingVehs, bool prio)
add vehicles driving across
double xFwd
maximal position on the current lane in forward direction
static const int UNDEFINED_DIRECTION
Definition: MSPModel.h:105
static const double OBSTRUCTED_PENALTY
static const double DIST_OVERLAP
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
static int getStripeOffset(int origStripes, int destStripes, bool addRemainder)
static Obstacles getVehicleObstacles(const MSLane *lane, int dir, PState *ped=0)
retrieve vehicle obstacles on the given lane
A list of positions.
double myRelY
the orthogonal shift on the current lane
Position myRemoteXYPos
remote-controlled position
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
double myAngle
cached angle
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)
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:128
std::pair< const MSPerson *, double > PersonDist
Definition: MSPModel.h:38
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
static std::map< const MSEdge *, std::vector< const MSLane * > > myWalkingAreaFoes
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:90
Container for pedestrian state and individual position update function.
NextLaneInfo(const MSLane *_lane, const MSLink *_link, int _dir)
std::vector< Obstacle > Obstacles
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:83
ActiveLanes myActiveLanes
store of all lanes which have pedestrians on them
const MSLane * myLane
the current lane of this pedestrian
static bool addVehicleFoe(const MSVehicle *veh, const MSLane *walkingarea, const Position &relPos, double lateral_offset, double minY, double maxY, Pedestrians &toDelete, Pedestrians &transformedPeds)
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 ...
bool operator()(const MSLane *l1, const MSLane *l2) const
comparing operation
static const double LOOKAROUND_VEHICLES