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-2018 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
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;
275  void moveToXY(MSPerson* p, Position pos, MSLane* lane, double lanePos,
276  double lanePosLat, double angle, int routeOffset,
277  const ConstMSEdgeVector& edges, SUMOTime t);
278 
280 
281  PState(MSPerson* person, MSPerson::MSPersonStage_Walking* stage, const MSLane* lane);
282 
283  ~PState() {};
284  MSPerson* myPerson;
287  const MSLane* myLane;
289  double myRelX;
291  double myRelY;
293  int myDir;
295  double mySpeed;
309  mutable double myAngle;
310 
312  double getMinX(const bool includeMinGap = true) const;
313 
315  double getMaxX(const bool includeMinGap = true) const;
316 
318  double getLength() const;
319 
321  double getMinGap() const;
322 
324  double distToLaneEnd() const;
325 
327  bool moveToNextLane(SUMOTime currentTime);
328 
330  void walk(const Obstacles& obs, SUMOTime currentTime);
331 
333  double getImpatience(SUMOTime now) const;
334 
335  int stripe() const;
336  int otherStripe() const;
337 
338  static int stripe(const double relY);
339  int otherStripe(const double relY) const;
340 
341  /* @brief calculate distance to the given obstacle,
342  * - non-negative values signify an obstacle in front of ego
343  * the special values DIST_OVERLAP and DIST_BEHIND are used to signify
344  * obstacles that overlap and obstacles behind ego respectively
345  * the result is the same regardless of walking direction
346  */
347  double distanceTo(const Obstacle& obs, const bool includeMinGap = true) const;
348 
350  void mergeObstacles(Obstacles& into, const Obstacles& obs2);
351 
353  static void mergeObstacles(Obstacles& into, const Obstacles& obs2, int dir, int offset);
354 
356  bool ignoreRed(const MSLink* link) const;
357  };
358 
359  class MovePedestrians : public Command {
360  public:
363  SUMOTime execute(SUMOTime currentTime);
364  private:
366  private:
368  MovePedestrians& operator=(const MovePedestrians&);
369  };
370 
373  public:
375  by_xpos_sorter(int dir): myDir(dir) {}
376 
377  public:
379  bool operator()(const PState* p1, const PState* p2) const {
380  if (p1->myRelX != p2->myRelX) {
381  return myDir * p1->myRelX > myDir * p2->myRelX;
382  }
383  return p1->myPerson->getID() < p2->myPerson->getID();
384  }
385 
386  private:
387  const int myDir;
388 
389  private:
391  by_xpos_sorter& operator=(const by_xpos_sorter&);
392  };
393 
394 
396  void moveInDirection(SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
397 
399  void moveInDirectionOnLane(Pedestrians& pedestrians, const MSLane* lane, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
400 
402  void arriveAndAdvance(Pedestrians& pedestrians, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
403 
404  const ActiveLanes& getActiveLanes() {
405  return myActiveLanes;
406  }
407 
408 private:
409  static void DEBUG_PRINT(const Obstacles& obs);
410 
412  static int connectedDirection(const MSLane* from, const MSLane* to);
413 
419  static NextLaneInfo getNextLane(const PState& ped, const MSLane* currentLane, const MSLane* prevLane);
420 
422  static const MSLane* getNextWalkingArea(const MSLane* currentLane, const int dir, MSLink*& link);
423 
424  static void initWalkingAreaPaths(const MSNet* net);
425 
427  static WalkingAreaPath* getArbitraryPath(const MSEdge* walkingArea);
428 
430  static int numStripes(const MSLane* lane);
431 
432  static Obstacles getNeighboringObstacles(const Pedestrians& pedestrians, int egoIndex, int stripes);
433 
434  const Obstacles& getNextLaneObstacles(NextLanesObstacles& nextLanesObs, const MSLane* lane, const MSLane* nextLane, int stripes,
435  int nextDir, double currentLength, int currentDir);
436 
437  static void transformToCurrentLanePositions(Obstacles& o, int currentDir, int nextDir, double currentLength, double nextLength);
438 
439  static void addCloserObstacle(Obstacles& obs, double x, int stripe, int numStripes, const std::string& id, double width, int dir, ObstacleType type);
440 
442  Pedestrians& getPedestrians(const MSLane* lane);
443 
444  /* @brief compute stripe-offset to transform relY values from a lane with origStripes into a lane wit destStrips
445  * @note this is called once for transforming nextLane peds to into the current system as obstacles and another time
446  * (in reverse) to transform the pedestrian coordinates into the nextLane-coordinates when changing lanes
447  */
448  static int getStripeOffset(int origStripes, int destStripes, bool addRemainder);
449 
451  static bool addCrossingVehs(const MSLane* crossing, int stripes, double lateral_offset, int dir, Obstacles& crossingVehs, bool prio);
452 
454  static Obstacles getVehicleObstacles(const MSLane* lane, int dir, PState* ped = 0);
455 
456  static bool usingInternalLanesStatic();
457 private:
460 
462  ActiveLanes myActiveLanes;
463 
465  static WalkingAreaPaths myWalkingAreaPaths;
466  static MinNextLengths myMinNextLengths;
467 
469  static Pedestrians noPedestrians;
470 
471 };
472 
473 
474 #endif /* MSPModel_Striping_h */
475 
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
long long int SUMOTime
Definition: SUMOTime.h:36
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:61
MSPModel_Striping *const myModel
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:72
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:54
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:84
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:448
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:75
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
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: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
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:92
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:78
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 const double LOOKAROUND_VEHICLES