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