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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // The pedestrian following model (prototype)
19 /****************************************************************************/
20 #ifndef MSPModel_Striping_h
21 #define MSPModel_Striping_h
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
33 #include <limits>
34 #include <utils/common/SUMOTime.h>
35 #include <utils/common/Command.h>
37 #include <microsim/MSLane.h>
38 #include "MSPerson.h"
39 #include "MSPModel.h"
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 class MSNet;
45 class MSLink;
46 class MSJunction;
47 
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
57 class MSPModel_Striping : public MSPModel {
58 
59  friend class GUIPerson; // for debugging
60 
61 public:
62 
64  MSPModel_Striping(const OptionsCont& oc, MSNet* net);
65 
67 
70 
72  void remove(PedestrianState* state);
73 
82  bool blockedAtDist(const MSLane* lane, double vehSide, double vehWidth,
83  double oncomingGap, std::vector<const MSPerson*>* collectBlockers);
84 
86  bool hasPedestrians(const MSLane* lane);
87 
89  bool usingInternalLanes();
90 
92  PersonDist nextBlocking(const MSLane* lane, double minPos, double minRight, double maxLeft, double stopTime = 0);
93 
95  void cleanupHelper();
96 
99 
100  // @brief the width of a pedstrian stripe
101  static double stripeWidth;
102 
103  // @brief the factor for random slow-down
104  static double dawdling;
105 
106  // @brief the time threshold before becoming jammed
108 
109  // @brief the distance (in seconds) to look ahead for changing stripes
110  static const double LOOKAHEAD_SAMEDIR;
111  // @brief the distance (in seconds) to look ahead for changing stripes (regarding oncoming pedestrians)
112  static const double LOOKAHEAD_ONCOMING;
113  // @brief the distance (in m) to look around for vehicles
114  static const double LOOKAROUND_VEHICLES;
115 
116  // @brief the utility penalty for moving sideways (corresponds to meters)
117  static const double LATERAL_PENALTY;
118 
119  // @brief the utility penalty for obstructed (physically blocking me) stripes (corresponds to meters)
120  static const double OBSTRUCTED_PENALTY;
121 
122  // @brief the utility penalty for inappropriate (reserved for oncoming traffic or may violate my min gap) stripes (corresponds to meters)
123  static const double INAPPROPRIATE_PENALTY;
124 
125  // @brief the utility penalty for oncoming conflicts on stripes (corresponds to meters)
126  static const double ONCOMING_CONFLICT_PENALTY;
127 
128  // @brief the minimum utility that indicates obstruction
129  static const double OBSTRUCTION_THRESHOLD;
130 
131  // @brief the factor by which pedestrian width is reduced when sqeezing past each other
132  static const double SQUEEZE;
133 
134  // @brief fraction of the leftmost lanes to reserve for oncoming traffic
135  static const double RESERVE_FOR_ONCOMING_FACTOR;
137 
138  // @brief the time pedestrians take to reach maximum impatience
139  static const double MAX_WAIT_TOLERANCE;
140 
141  // @brief the fraction of forward speed to be used for lateral movemenk
142  static const double LATERAL_SPEED_FACTOR;
143 
144  // @brief the minimum distance to the next obstacle in order to start walking after stopped
145  static const double MIN_STARTUP_DIST;
146 
148 
149 
150 protected:
151  static const double DIST_FAR_AWAY;
152  static const double DIST_BEHIND;
153  static const double DIST_OVERLAP;
154 
156  public:
158  bool operator()(const MSLane* l1, const MSLane* l2) const {
159  return l1->getNumericalID() < l2->getNumericalID();
160  }
161  };
162 
163  struct Obstacle;
164  struct WalkingAreaPath;
165  class PState;
166  typedef std::vector<PState*> Pedestrians;
167  typedef std::map<const MSLane*, Pedestrians, lane_by_numid_sorter> ActiveLanes;
168  typedef std::vector<Obstacle> Obstacles;
169  typedef std::map<const MSLane*, Obstacles, lane_by_numid_sorter> NextLanesObstacles;
170  typedef std::map<std::pair<const MSLane*, const MSLane*>, WalkingAreaPath> WalkingAreaPaths;
171  typedef std::map<const MSLane*, double> MinNextLengths;
172 
173  struct NextLaneInfo {
174  NextLaneInfo(const MSLane* _lane, const MSLink* _link, int _dir) :
175  lane(_lane),
176  link(_link),
177  dir(_dir) {
178  }
179 
181  lane(0),
182  link(0),
183  dir(UNDEFINED_DIRECTION) {
184  }
185 
186  // @brief the next lane to be used
187  const MSLane* lane;
188  // @brief the link from the current lane to the next lane
189  const MSLink* link;
190  // @brief the direction on the next lane
191  int dir;
192  };
193 
202  };
203 
205  struct Obstacle {
207  Obstacle(int dir, double dist = DIST_FAR_AWAY);
209  Obstacle(const PState& ped);
211  Obstacle(double _x, double _speed, ObstacleType _type, const std::string& _description, const double width = 0.)
212  : xFwd(_x + width / 2.), xBack(_x - width / 2.), speed(_speed), type(_type), description(_description) {};
213 
215  double xFwd;
217  double xBack;
219  double speed;
223  std::string description;
224  };
225 
227  WalkingAreaPath(const MSLane* _from, const MSLane* _walkingArea, const MSLane* _to, const PositionVector& _shape) :
228  from(_from),
229  to(_to),
230  lane(_walkingArea),
231  shape(_shape),
232  length(_shape.length()) {
233  }
234 
235  WalkingAreaPath(): from(0), to(0), lane(0) {};
236 
237  const MSLane* from;
238  const MSLane* to;
239  const MSLane* lane; // the walkingArea;
240  PositionVector shape; // actually const but needs to be copyable by some stl code
241  double length;
242 
243  };
244 
246  public:
248  bool operator()(const WalkingAreaPath* p1, const WalkingAreaPath* p2) const {
249  if (p1->from->getNumericalID() < p2->from->getNumericalID()) {
250  return true;
251  }
252  if (p1->from->getNumericalID() == p2->from->getNumericalID()) {
253  if (p1->to->getNumericalID() < p2->to->getNumericalID()) {
254  return true;
255  }
256  }
257  return false;
258  }
259  };
260 
261 
266  class PState : public PedestrianState {
267  public:
268 
271  double getEdgePos(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
272  Position getPosition(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
273  double getAngle(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
274  SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking& stage, SUMOTime now) const;
275  double getSpeed(const MSPerson::MSPersonStage_Walking& stage) const;
276  const MSEdge* getNextEdge(const MSPerson::MSPersonStage_Walking& stage) const;
277  void moveToXY(MSPerson* p, Position pos, MSLane* lane, double lanePos,
278  double lanePosLat, double angle, int routeOffset,
279  const ConstMSEdgeVector& edges, SUMOTime t);
280 
282 
283  PState(MSPerson* person, MSPerson::MSPersonStage_Walking* stage, const MSLane* lane);
284 
285  ~PState() {};
286  MSPerson* myPerson;
289  const MSLane* myLane;
291  double myRelX;
293  double myRelY;
295  int myDir;
297  double mySpeed;
308 
310  double getMinX(const bool includeMinGap = true) const;
311 
313  double getMaxX(const bool includeMinGap = true) const;
314 
316  double getLength() const;
317 
319  double getMinGap() const;
320 
322  double distToLaneEnd() const;
323 
325  bool moveToNextLane(SUMOTime currentTime);
326 
328  void walk(const Obstacles& obs, SUMOTime currentTime);
329 
331  double getImpatience(SUMOTime now) const;
332 
333  int stripe() const;
334  int otherStripe() const;
335 
336  static int stripe(const double relY);
337  int otherStripe(const double relY) const;
338 
339  /* @brief calculate distance to the given obstacle,
340  * - non-negative values signify an obstacle in front of ego
341  * the special values DIST_OVERLAP and DIST_BEHIND are used to signify
342  * obstacles that overlap and obstacles behind ego respectively
343  * the result is the same regardless of walking direction
344  */
345  double distanceTo(const Obstacle& obs, const bool includeMinGap = true) const;
346 
348  void mergeObstacles(Obstacles& into, const Obstacles& obs2);
349 
351  bool ignoreRed(const MSLink* link) const;
352  };
353 
354  class MovePedestrians : public Command {
355  public:
358  SUMOTime execute(SUMOTime currentTime);
359  private:
361  private:
363  MovePedestrians& operator=(const MovePedestrians&);
364  };
365 
368  public:
370  by_xpos_sorter(int dir): myDir(dir) {}
371 
372  public:
374  bool operator()(const PState* p1, const PState* p2) const {
375  if (p1->myRelX != p2->myRelX) {
376  return myDir * p1->myRelX > myDir * p2->myRelX;
377  }
378  return p1->myPerson->getID() < p2->myPerson->getID();
379  }
380 
381  private:
382  const int myDir;
383 
384  private:
386  by_xpos_sorter& operator=(const by_xpos_sorter&);
387  };
388 
389 
391  void moveInDirection(SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
392 
394  void moveInDirectionOnLane(Pedestrians& pedestrians, const MSLane* lane, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
395 
397  void arriveAndAdvance(Pedestrians& pedestrians, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
398 
399  const ActiveLanes& getActiveLanes() {
400  return myActiveLanes;
401  }
402 
403 private:
404  static void DEBUG_PRINT(const Obstacles& obs);
405 
407  static int connectedDirection(const MSLane* from, const MSLane* to);
408 
414  static NextLaneInfo getNextLane(const PState& ped, const MSLane* currentLane, const MSLane* prevLane);
415 
417  static const MSLane* getNextWalkingArea(const MSLane* currentLane, const int dir, MSLink*& link);
418 
419  static void initWalkingAreaPaths(const MSNet* net);
420 
422  static WalkingAreaPath* getArbitraryPath(const MSEdge* walkingArea);
423 
425  static int numStripes(const MSLane* lane);
426 
427  static Obstacles getNeighboringObstacles(const Pedestrians& pedestrians, int egoIndex, int stripes);
428 
429  const Obstacles& getNextLaneObstacles(NextLanesObstacles& nextLanesObs, const MSLane* lane, const MSLane* nextLane, int stripes,
430  int nextDir, double currentLength, int currentDir);
431 
432  static void transformToCurrentLanePositions(Obstacles& o, int currentDir, int nextDir, double currentLength, double nextLength);
433 
434  static void addCloserObstacle(Obstacles& obs, double x, int stripe, int numStripes, const std::string& id, double width, int dir, ObstacleType type);
435 
437  Pedestrians& getPedestrians(const MSLane* lane);
438 
439  /* @brief compute stripe-offset to transform relY values from a lane with origStripes into a lane wit destStrips
440  * @note this is called once for transforming nextLane peds to into the current system as obstacles and another time
441  * (in reverse) to transform the pedestrian coordinates into the nextLane-coordinates when changing lanes
442  */
443  static int getStripeOffset(int origStripes, int destStripes, bool addRemainder);
444 
446  static bool addCrossingVehs(const MSLane* crossing, int stripes, double lateral_offset, int dir, Obstacles& crossingVehs);
447 private:
450 
453 
455  ActiveLanes myActiveLanes;
456 
458  static WalkingAreaPaths myWalkingAreaPaths;
459  static MinNextLengths myMinNextLengths;
460 
462  static Pedestrians noPedestrians;
463 
464 };
465 
466 
467 #endif /* MSPModel_Striping_h */
468 
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 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
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:78
bool usingInternalLanes()
whether movements on intersections are modelled
std::map< std::pair< const MSLane *, const MSLane * >, WalkingAreaPath > WalkingAreaPaths
Base (microsim) event class.
Definition: Command.h:60
static MSPModel * myModel
Definition: MSPModel.h:125
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:90
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:431
NextLaneInfo myNLI
information about the upcoming lane
The pedestrian following model.
Definition: MSPModel.h:55
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:110
static const double OBSTRUCTED_PENALTY
static const double DIST_OVERLAP
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
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
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:131
std::pair< const MSPerson *, double > PersonDist
Definition: MSPModel.h:43
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
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:98
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:51
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:77
ActiveLanes myActiveLanes
store of all lanes which have pedestrians on them
const MSLane * myLane
the current lane of this pedestrian
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 bool addCrossingVehs(const MSLane *crossing, int stripes, double lateral_offset, int dir, Obstacles &crossingVehs)
add vehicles driving across
static const double LOOKAROUND_VEHICLES