SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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-sim.org/
10 // Copyright (C) 2014-2014 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/MSPerson.h>
38 #include <microsim/MSPModel.h>
39 
40 // ===========================================================================
41 // class declarations
42 // ===========================================================================
43 class MSNet;
44 class MSLink;
45 class MSLane;
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 distance to look ahead for changing stripes
88  // @brief the distance to look ahead for changing stripes (regarding oncoming pedestrians)
90 
91  // @brief the speed penalty for moving sideways
92  static const SUMOReal LATERAL_PENALTY;
93 
94  // @brief the factor by which pedestrian width is reduced when sqeezing past each other
95  static const SUMOReal SQUEEZE;
96 
97  // @brief the maximum distance at which oncoming pedestrians block right turning traffic
99 
100  // @brief fraction of the leftmost lanes to reserve for oncoming traffic
102 
103  // @brief the time pedestrians take to reach maximum impatience
105 
106  // @brief the fraction of forward speed to be used for lateral movemenk
108 
110 
111 
112 protected:
113  struct Obstacle;
114  struct WalkingAreaPath;
115  class PState;
116  typedef std::vector<PState*> Pedestrians;
117  typedef std::map<const MSLane*, Pedestrians> ActiveLanes;
118  typedef std::vector<Obstacle> Obstacles;
119  typedef std::map<const MSLane*, Obstacles> NextLanesObstacles;
120  typedef std::map<std::pair<const MSLane*, const MSLane*>, WalkingAreaPath> WalkingAreaPaths;
121 
122  struct NextLaneInfo {
123  NextLaneInfo(const MSLane* _lane, const MSLink* _link, int _dir) :
124  lane(_lane),
125  link(_link),
126  dir(_dir)
127  { }
128 
130  lane(0),
131  link(0),
133  { }
134 
135  // @brief the next lane to be used
136  const MSLane* lane;
137  // @brief the link from the current lane to the next lane
138  const MSLink* link;
139  // @brief the direction on the next lane
140  int dir;
141  };
142 
144  struct Obstacle {
146  Obstacle(int dir);
148  Obstacle(const PState& ped, int dir);
150  Obstacle(SUMOReal _x, SUMOReal _speed, const std::string& _description) : x(_x), speed(_speed), description(_description) {};
151 
153  SUMOReal x;
157  std::string description;
158  };
159 
161  WalkingAreaPath(const MSLane* _from, const MSLane* _walkingArea, const MSLane* _to, const PositionVector& _shape) :
162  from(_from),
163  to(_to),
164  lane(_walkingArea),
165  shape(_shape),
166  length(_shape.length())
167  {}
168 
169  WalkingAreaPath(): from(0), to(0), lane(0) {};
170 
171  const MSLane* from;
172  const MSLane* to;
173  const MSLane* lane; // the walkingArea;
174  // actually const but needs to be copyable by some stl code
177 
178  };
179 
184  class PState : public PedestrianState {
185  public:
186 
195 
196  PState(MSPerson* person, MSPerson::MSPersonStage_Walking* stage, const MSLane* lane);
197  ~PState() {};
201  const MSLane* myLane;
207  int myDir;
220 
222  SUMOReal getLength() const;
223 
225  SUMOReal distToLaneEnd() const;
226 
228  bool moveToNextLane(SUMOTime currentTime);
229 
231  void walk(const Obstacles& obs, SUMOTime currentTime);
232 
234  SUMOReal getImpatience(SUMOTime now) const; // XXX
235 
237  SUMOReal getMingap() const;
238 
239  int stripe() const;
240  int otherStripe() const;
241 
242  };
243 
244  class MovePedestrians : public Command {
245  public:
248  SUMOTime execute(SUMOTime currentTime);
249  private:
251  private:
254  };
255 
257  public:
259  by_xpos_sorter(int dir): myDir(dir) {}
260 
261  public:
263  bool operator()(const PState* p1, const PState* p2) const {
264  if (p1->myRelX != p2->myRelX) {
265  return myDir * p1->myRelX > myDir * p2->myRelX;
266  }
267  return p1->myPerson->getID() < p2->myPerson->getID();
268  }
269 
270  private:
271  const int myDir;
272 
273  private:
276  };
277 
278 
280  void moveInDirection(SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
281 
283  return myActiveLanes;
284  }
285 
286 private:
287  static void DEBUG_PRINT(const Obstacles& obs);
288 
290  static int connectedDirection(const MSLane* from, const MSLane* to);
291 
297  static NextLaneInfo getNextLane(const PState& ped, const MSLane* currentLane, const MSLane* prevLane);
298 
300  static const MSLane* getNextWalkingArea(const MSLane* currentLane, const int dir, MSLink*& link);
301 
302  static void initWalkingAreaPaths(const MSNet* net);
303 
305  static int numStripes(const MSLane* lane);
306 
307  static Obstacles mergeObstacles(const Obstacles& obs1, const Obstacles& obs2, int dir);
308 
309  static Obstacles getNeighboringObstacles(const Pedestrians& pedestrians, int egoIndex, int stripes);
310 
311  const Obstacles& getNextLaneObstacles(NextLanesObstacles& nextLanesObs, const MSLane* nextLane, int stripes,
312  SUMOReal nextLength, int nextDir, SUMOReal currentLength, int currentDir);
313 
315  Pedestrians& getPedestrians(const MSLane* lane);
316 
317 
318 private:
321 
324 
327 
330 
333 
334 };
335 
336 
337 #endif /* MSPModel_Striping_h */
338 
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:551
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.
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:58
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:91
std::map< const MSLane *, Pedestrians > ActiveLanes
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
const Obstacles & getNextLaneObstacles(NextLanesObstacles &nextLanesObs, const MSLane *nextLane, int stripes, SUMOReal nextLength, int nextDir, SUMOReal currentLength, int currentDir)
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)
Position getPosition(const MSPerson::MSPersonStage_Walking &stage, SUMOTime now) const
return the network coordinate of the person
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
int myBlockedByOncoming
whether the pedestrian is blocked by an oncoming pedestrian
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
static const SUMOReal BLOCKER_LOOKAHEAD
#define SUMOReal
Definition: config.h:215
SUMOReal myRelY
the orthogonal shift on the current lane
std::map< const MSLane *, Obstacles > NextLanesObstacles
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()
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
const MSLane * myLane
the current lane of this pedestrian
static const SUMOReal LATERAL_PENALTY
Obstacle(int dir)
create No-Obstacle