SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MSPModel_Striping.h
Go to the documentation of this file.
1 /****************************************************************************/
7 // The pedestrian following model (prototype)
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2014-2015 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
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  bool blockedAtDist(const MSLane* lane, SUMOReal distToCrossing, std::vector<const MSPerson*>* collectBlockers);
73 
75  void cleanupHelper();
76 
79 
80  // @brief the width of a pedstrian stripe
82 
83  // @brief the factor for random slow-down
85 
86  // @brief the time threshold before becoming jammed
87  static SUMOTime jamTime;
88 
89  // @brief the distance to look ahead for changing stripes
91  // @brief the distance to look ahead for changing stripes (regarding oncoming pedestrians)
93 
94  // @brief the speed penalty for moving sideways
95  static const SUMOReal LATERAL_PENALTY;
96 
97  // @brief the factor by which pedestrian width is reduced when sqeezing past each other
98  static const SUMOReal SQUEEZE;
99 
100  // @brief the maximum distance at which oncoming pedestrians block right turning traffic
102 
103  // @brief fraction of the leftmost lanes to reserve for oncoming traffic
105 
106  // @brief the time pedestrians take to reach maximum impatience
108 
109  // @brief the fraction of forward speed to be used for lateral movemenk
111 
112  // @brief the minimum fraction of maxSpeed in order to start walking after stopped
114 
116 
117 
118 protected:
120  public:
122  bool operator()(const MSLane* l1, const MSLane* l2) const {
123  return l1->getNumericalID() < l2->getNumericalID();
124  }
125  };
126 
127  struct Obstacle;
128  struct WalkingAreaPath;
129  class PState;
130  typedef std::vector<PState*> Pedestrians;
131  typedef std::map<const MSLane*, Pedestrians, lane_by_numid_sorter> ActiveLanes;
132  typedef std::vector<Obstacle> Obstacles;
133  typedef std::map<const MSLane*, Obstacles, lane_by_numid_sorter> NextLanesObstacles;
134  typedef std::map<std::pair<const MSLane*, const MSLane*>, WalkingAreaPath> WalkingAreaPaths;
135 
136  struct NextLaneInfo {
137  NextLaneInfo(const MSLane* _lane, const MSLink* _link, int _dir) :
138  lane(_lane),
139  link(_link),
140  dir(_dir)
141  { }
142 
144  lane(0),
145  link(0),
147  { }
148 
149  // @brief the next lane to be used
150  const MSLane* lane;
151  // @brief the link from the current lane to the next lane
152  const MSLink* link;
153  // @brief the direction on the next lane
154  int dir;
155  };
156 
158  struct Obstacle {
160  Obstacle(int dir);
162  Obstacle(const PState& ped, int dir);
164  Obstacle(SUMOReal _x, SUMOReal _speed, const std::string& _description) : x(_x), speed(_speed), description(_description) {};
165 
167  SUMOReal x;
171  std::string description;
172  };
173 
175  WalkingAreaPath(const MSLane* _from, const MSLane* _walkingArea, const MSLane* _to, const PositionVector& _shape) :
176  from(_from),
177  to(_to),
178  lane(_walkingArea),
179  shape(_shape),
180  length(_shape.length())
181  {}
182 
183  WalkingAreaPath(): from(0), to(0), lane(0) {};
184 
185  const MSLane* from;
186  const MSLane* to;
187  const MSLane* lane; // the walkingArea;
188  PositionVector shape; // actually const but needs to be copyable by some stl code
190 
191  };
192 
194  public:
196  bool operator()(const WalkingAreaPath* p1, const WalkingAreaPath* p2) const {
197  if (p1->from->getNumericalID() < p2->from->getNumericalID()) {
198  return true;
199  }
200  return p1->to->getNumericalID() < p2->to->getNumericalID();
201  }
202  };
203 
204 
209  class PState : public PedestrianState {
210  public:
211 
220 
221  PState(MSPerson* person, MSPerson::MSPersonStage_Walking* stage, const MSLane* lane);
222 
223  ~PState() {};
227  const MSLane* myLane;
233  int myDir;
246 
248  SUMOReal getLength() const;
249 
251  SUMOReal distToLaneEnd() const;
252 
254  bool moveToNextLane(SUMOTime currentTime);
255 
257  void walk(const Obstacles& obs, SUMOTime currentTime);
258 
260  SUMOReal getImpatience(SUMOTime now) const;
261 
263  SUMOReal getMingap() const;
264 
265  int stripe() const;
266  int otherStripe() const;
267 
268  int stripe(SUMOReal relY) const;
269  int otherStripe(SUMOReal relY) const;
270 
271  };
272 
273  class MovePedestrians : public Command {
274  public:
277  SUMOTime execute(SUMOTime currentTime);
278  private:
280  private:
283  };
284 
286  public:
288  by_xpos_sorter(int dir): myDir(dir) {}
289 
290  public:
292  bool operator()(const PState* p1, const PState* p2) const {
293  if (p1->myRelX != p2->myRelX) {
294  return myDir * p1->myRelX > myDir * p2->myRelX;
295  }
296  return p1->myPerson->getID() < p2->myPerson->getID();
297  }
298 
299  private:
300  const int myDir;
301 
302  private:
305  };
306 
307 
309  void moveInDirection(SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
310 
312  void moveInDirectionOnLane(Pedestrians& pedestrians, const MSLane* lane, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
313 
314  const ActiveLanes& getActiveLanes() {
315  return myActiveLanes;
316  }
317 
318 private:
319  static void DEBUG_PRINT(const Obstacles& obs);
320 
322  static int connectedDirection(const MSLane* from, const MSLane* to);
323 
329  static NextLaneInfo getNextLane(const PState& ped, const MSLane* currentLane, const MSLane* prevLane);
330 
332  static const MSLane* getNextWalkingArea(const MSLane* currentLane, const int dir, MSLink*& link);
333 
334  static void initWalkingAreaPaths(const MSNet* net);
335 
337  static int numStripes(const MSLane* lane);
338 
339  static Obstacles mergeObstacles(const Obstacles& obs1, const Obstacles& obs2, int dir);
340 
341  static Obstacles getNeighboringObstacles(const Pedestrians& pedestrians, int egoIndex, int stripes);
342 
343  const Obstacles& getNextLaneObstacles(NextLanesObstacles& nextLanesObs, const MSLane* lane, const MSLane* nextLane, int stripes,
344  SUMOReal nextLength, int nextDir, SUMOReal currentLength, int currentDir);
345 
346  static void addMappedObstacle(Obstacles& obs, const PState& p, int stripe, int currentDir, int nextDir, int offset, int stripes, int nextStripes);
347 
348  static void addCloserObstacle(Obstacles& obs, SUMOReal x, int stripe, const std::string& id, int stripes, int dir);
349 
351  Pedestrians& getPedestrians(const MSLane* lane);
352 
353 
354 private:
357 
360 
362  ActiveLanes myActiveLanes;
363 
365  static WalkingAreaPaths myWalkingAreaPaths;
366 
368  static Pedestrians noPedestrians;
369 
370 };
371 
372 
373 #endif /* MSPModel_Striping_h */
374 
const Obstacles & getNextLaneObstacles(NextLanesObstacles &nextLanesObs, const MSLane *lane, const MSLane *nextLane, int stripes, SUMOReal nextLength, int nextDir, SUMOReal currentLength, int currentDir)
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...
const std::string & getID() const
returns the person id
Definition: MSPerson.cpp:552
bool blockedAtDist(const MSLane *lane, SUMOReal distToCrossing, std::vector< const MSPerson * > *collectBlockers)
whether a pedestrian is blocking the crossing of lane at offset distToCrossing
MovePedestrians & operator=(const MovePedestrians &)
Invalidated assignment operator.
bool operator()(const WalkingAreaPath *p1, const WalkingAreaPath *p2) const
comparing operation
SUMOReal distToLaneEnd() const
the absolute distance to the end of the lane in walking direction (or to the arrivalPos) ...
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)
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:61
size_t getNumericalID() const
Returns this lane's numerical id.
Definition: MSLane.h:315
SUMOReal getMingap() const
return the speed-dependent minGap of the pedestrian
MSPModel_Striping *const myModel
PState(MSPerson *person, MSPerson::MSPersonStage_Walking *stage, const MSLane *lane)
std::map< std::pair< const MSLane *, const MSLane * >, WalkingAreaPath > WalkingAreaPaths
bool moveToNextLane(SUMOTime currentTime)
return whether this pedestrian has passed the end of the current lane and update myRelX if so ...
Base (microsim) event class.
Definition: Command.h:61
static WalkingAreaPaths myWalkingAreaPaths
store for walkinArea elements
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
NextLaneInfo myNLI
information about the upcoming lane
The pedestrian following model.
Definition: MSPModel.h:54
static const SUMOReal SQUEEZE
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
static const SUMOReal LATERAL_SPEED_FACTOR
SUMOTime execute(SUMOTime currentTime)
Executes the command.
void walk(const Obstacles &obs, SUMOTime currentTime)
perform position update
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
static const SUMOReal LOOKAHEAD_ONCOMING
A list of positions.
SUMOReal getLength() const
return the length of the pedestrian
SUMOTime getWaitingTime(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
return the time the person spent standing
static Obstacles mergeObstacles(const Obstacles &obs1, const Obstacles &obs2, int dir)
std::map< const MSLane *, Pedestrians, lane_by_numid_sorter > ActiveLanes
Position getPosition(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
return the network coordinate of the person
std::map< const MSLane *, Obstacles, lane_by_numid_sorter > NextLanesObstacles
SUMOReal getAngle(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
return the direction in which the person faces in degrees
SUMOReal x
position on the current lane
SUMOTime myWaitingTime
the consecutive time spent at speed 0
int myDir
the walking direction on the current lane (1 forward, -1 backward)
SUMOReal getEdgePos(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
abstract methods inherited from PedestrianState
SUMOReal getSpeed(const MSPerson::MSPersonStage_Walking &stage) const
return the current speed of the person
void cleanupHelper()
remove state at simulation end
PedestrianState * add(MSPerson *person, MSPerson::MSPersonStage_Walking *stage, SUMOTime now)
register the given person as a pedestrian
MovePedestrians(MSPModel_Striping *model)
abstract base class for managing callbacks to retrieve various state information from the model ...
Definition: MSPModel.h:96
SUMOReal getImpatience(SUMOTime now) const
returns the impatience
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:108
Container for pedestrian state and individual position update function.
NextLaneInfo(const MSLane *_lane, const MSLink *_link, int _dir)
std::vector< Obstacle > Obstacles
int SUMOTime
Definition: SUMOTime.h:43
static const SUMOReal BLOCKER_LOOKAHEAD
static void addMappedObstacle(Obstacles &obs, const PState &p, int stripe, int currentDir, int nextDir, int offset, int stripes, int nextStripes)
#define SUMOReal
Definition: config.h:218
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)
by_xpos_sorter & operator=(const by_xpos_sorter &)
Invalidated assignment operator.
static SUMOReal dawdling
const ActiveLanes & getActiveLanes()
static SUMOTime jamTime
int myNumActivePedestrians
the total number of active pedestrians
SUMOReal speed
speed relative to ego 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:77
ActiveLanes myActiveLanes
store of all lanes which have pedestrians on them
static const SUMOReal MIN_STARTUP_SPEED
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
static void addCloserObstacle(Obstacles &obs, SUMOReal x, int stripe, const std::string &id, int stripes, int dir)
Obstacle(int dir)
create No-Obstacle
void moveInDirectionOnLane(Pedestrians &pedestrians, const MSLane *lane, SUMOTime currentTime, std::set< MSPerson * > &changedLane, int dir)
move pedestrians forward on one lane