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.dlr.de/
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 #include <microsim/MSLane.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 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:
114  public:
116  bool operator()(const MSLane* l1, const MSLane* l2) const {
117  return l1->getNumericalID() < l2->getNumericalID();
118  }
119  };
120 
121  struct Obstacle;
122  struct WalkingAreaPath;
123  class PState;
124  typedef std::vector<PState*> Pedestrians;
125  typedef std::map<const MSLane*, Pedestrians, lane_by_numid_sorter> ActiveLanes;
126  typedef std::vector<Obstacle> Obstacles;
127  typedef std::map<const MSLane*, Obstacles, lane_by_numid_sorter> NextLanesObstacles;
128  typedef std::map<std::pair<const MSLane*, const MSLane*>, WalkingAreaPath> WalkingAreaPaths;
129 
130  struct NextLaneInfo {
131  NextLaneInfo(const MSLane* _lane, const MSLink* _link, int _dir) :
132  lane(_lane),
133  link(_link),
134  dir(_dir)
135  { }
136 
138  lane(0),
139  link(0),
141  { }
142 
143  // @brief the next lane to be used
144  const MSLane* lane;
145  // @brief the link from the current lane to the next lane
146  const MSLink* link;
147  // @brief the direction on the next lane
148  int dir;
149  };
150 
152  struct Obstacle {
154  Obstacle(int dir);
156  Obstacle(const PState& ped, int dir);
158  Obstacle(SUMOReal _x, SUMOReal _speed, const std::string& _description) : x(_x), speed(_speed), description(_description) {};
159 
161  SUMOReal x;
165  std::string description;
166  };
167 
169  WalkingAreaPath(const MSLane* _from, const MSLane* _walkingArea, const MSLane* _to, const PositionVector& _shape) :
170  from(_from),
171  to(_to),
172  lane(_walkingArea),
173  shape(_shape),
174  length(_shape.length())
175  {}
176 
177  WalkingAreaPath(): from(0), to(0), lane(0) {};
178 
179  const MSLane* from;
180  const MSLane* to;
181  const MSLane* lane; // the walkingArea;
182  // actually const but needs to be copyable by some stl code
185 
186  };
187 
192  class PState : public PedestrianState {
193  public:
194 
203 
204  PState(MSPerson* person, MSPerson::MSPersonStage_Walking* stage, const MSLane* lane);
205  ~PState() {};
209  const MSLane* myLane;
215  int myDir;
228 
230  SUMOReal getLength() const;
231 
233  SUMOReal distToLaneEnd() const;
234 
236  bool moveToNextLane(SUMOTime currentTime);
237 
239  void walk(const Obstacles& obs, SUMOTime currentTime);
240 
242  SUMOReal getImpatience(SUMOTime now) const; // XXX
243 
245  SUMOReal getMingap() const;
246 
247  int stripe() const;
248  int otherStripe() const;
249 
250  };
251 
252  class MovePedestrians : public Command {
253  public:
256  SUMOTime execute(SUMOTime currentTime);
257  private:
259  private:
262  };
263 
265  public:
267  by_xpos_sorter(int dir): myDir(dir) {}
268 
269  public:
271  bool operator()(const PState* p1, const PState* p2) const {
272  if (p1->myRelX != p2->myRelX) {
273  return myDir * p1->myRelX > myDir * p2->myRelX;
274  }
275  return p1->myPerson->getID() < p2->myPerson->getID();
276  }
277 
278  private:
279  const int myDir;
280 
281  private:
284  };
285 
286 
288  void moveInDirection(SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
289 
291  return myActiveLanes;
292  }
293 
294 private:
295  static void DEBUG_PRINT(const Obstacles& obs);
296 
298  static int connectedDirection(const MSLane* from, const MSLane* to);
299 
305  static NextLaneInfo getNextLane(const PState& ped, const MSLane* currentLane, const MSLane* prevLane);
306 
308  static const MSLane* getNextWalkingArea(const MSLane* currentLane, const int dir, MSLink*& link);
309 
310  static void initWalkingAreaPaths(const MSNet* net);
311 
313  static int numStripes(const MSLane* lane);
314 
315  static Obstacles mergeObstacles(const Obstacles& obs1, const Obstacles& obs2, int dir);
316 
317  static Obstacles getNeighboringObstacles(const Pedestrians& pedestrians, int egoIndex, int stripes);
318 
319  const Obstacles& getNextLaneObstacles(NextLanesObstacles& nextLanesObs, const MSLane* nextLane, int stripes,
320  SUMOReal nextLength, int nextDir, SUMOReal currentLength, int currentDir);
321 
323  Pedestrians& getPedestrians(const MSLane* lane);
324 
325 
326 private:
329 
332 
335 
338 
341 
342 };
343 
344 
345 #endif /* MSPModel_Striping_h */
346 
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:59
size_t getNumericalID() const
Returns this lane&#39;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:91
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)
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
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
int SUMOTime
Definition: SUMOTime.h:43
static const SUMOReal BLOCKER_LOOKAHEAD
#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()
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
bool operator()(const MSLane *l1, const MSLane *l2) const
comparing operation
static const SUMOReal LATERAL_PENALTY
Obstacle(int dir)
create No-Obstacle