Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSPModel_Striping.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2014-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
19// The pedestrian movement model using stripes on sidewalks
20/****************************************************************************/
21#pragma once
22#include <config.h>
23
24#include <string>
25#include <limits>
29#include <microsim/MSLane.h>
30#include "MSPerson.h"
32
33// ===========================================================================
34// class declarations
35// ===========================================================================
36class MSNet;
37class MSLink;
38class MSJunction;
39
40
41// ===========================================================================
42// class definitions
43// ===========================================================================
50
51 friend class GUIPerson; // for debugging
52
53public:
54
56 WalkingAreaPath(const MSLane* _from, const MSLane* _walkingArea, const MSLane* _to, const PositionVector& _shape, int _dir, double _angleOverride) :
57 from(_from),
58 to(_to),
59 lane(_walkingArea),
60 shape(_shape),
61 dir(_dir),
62 angleOverride(_angleOverride),
63 length(_shape.length()) {
64 }
65
66 const MSLane* const from;
67 const MSLane* const to;
68 const MSLane* const lane; // the walkingArea;
70 const int dir; // the direction when entering this path
71 const double angleOverride;
72 const double length;
73
74 };
75
76 typedef std::map<std::pair<const MSLane*, const MSLane*>, const WalkingAreaPath> WalkingAreaPaths;
77
79 MSPModel_Striping(const OptionsCont& oc, MSNet* net);
80
82
85
87 MSTransportableStateAdapter* loadState(MSTransportable* transportable, MSStageMoving* stage, std::istringstream& in);
88
91
93 static double stripeWidth;
94
96 static double dawdling;
97
99 static double minGapToVehicle;
100
103
109 static double jamFactor;
110
112 static bool myLegacyPosLat;
113
115 static const double LOOKAHEAD_SAMEDIR;
117 static const double LOOKAHEAD_ONCOMING;
119 static const double LOOKAROUND_VEHICLES;
121 static const double LOOKAHEAD_ONCOMING_DIST;
122
124 static const double LATERAL_PENALTY;
125
127 static const double OBSTRUCTED_PENALTY;
128
130 static const double INAPPROPRIATE_PENALTY;
131
133 static const double ONCOMING_CONFLICT_PENALTY;
134
136 static const double OBSTRUCTION_THRESHOLD;
137
139 static const double SQUEEZE;
140
145
147 static bool USE_NET_SPEEDS;
148
150 static const double MAX_WAIT_TOLERANCE;
151
153 static const double LATERAL_SPEED_FACTOR;
154
156 static const double MIN_STARTUP_DIST;
157
159
161 // The striping model uses as lateral position the distance of the center of the pedestrian
162 // to the left boundary of the lane minus a half stripe width, where right is positive.
163 // The vehicle uses the distance to the center of the lane (and left is positive).
164 // The function happens to be self inverse so it can be used to convert in both directions.
165 inline static double posLatConversion(const double posLat, const double laneWidth) {
166 return .5 * (laneWidth - stripeWidth) - posLat;
167 }
168
169
170protected:
171 static const double DIST_FAR_AWAY;
172 static const double DIST_BEHIND;
173 static const double DIST_OVERLAP;
174
175 struct Obstacle;
176 class PState;
177 typedef std::vector<Obstacle> Obstacles;
178 typedef std::map<const MSLane*, Obstacles, ComparatorNumericalIdLess> NextLanesObstacles;
179 typedef std::map<const MSLane*, double> MinNextLengths;
180
182 NextLaneInfo(const MSLane* _lane, const MSLink* _link, int _dir) :
183 lane(_lane),
184 link(_link),
185 dir(_dir) {
186 }
187
189 lane(0),
190 link(0),
192 }
193
195 const MSLane* lane;
197 const MSLink* link;
199 int dir;
200 };
201
211
213 struct Obstacle {
215 Obstacle(int dir, double dist = DIST_FAR_AWAY);
217 Obstacle(const PState& ped);
219 Obstacle(double _x, double _speed, ObstacleType _type, const std::string& _description, const double width = 0., const SUMOVehicle* veh = nullptr)
220 : xFwd(_x + width / 2.), xBack(_x - width / 2.), speed(_speed), type(_type), description(_description), vehicle(veh) {};
221
223 double xFwd;
225 double xBack;
227 double speed;
231 std::string description;
233 const SUMOVehicle* vehicle = nullptr;
234
235 bool closer(const Obstacle& o, int dir);
236 };
237
239 public:
241 bool operator()(const WalkingAreaPath* p1, const WalkingAreaPath* p2) const {
242 if (p1->from->getNumericalID() < p2->from->getNumericalID()) {
243 return true;
244 }
245 if (p1->from->getNumericalID() == p2->from->getNumericalID()) {
246 if (p1->to->getNumericalID() < p2->to->getNumericalID()) {
247 return true;
248 }
249 }
250 return false;
251 }
252 };
253
254
260 public:
261 PState(MSPerson* person, MSStageMoving* stage, const MSLane* lane);
262
264 PState(MSPerson* person, MSStageMoving* stage, std::istringstream* in = nullptr);
265
267 Position getPosition(const MSStageMoving& stage, SUMOTime now) const;
268 double getAngle(const MSStageMoving& stage, SUMOTime now) const;
269 const MSEdge* getNextEdge(const MSStageMoving& stage) const;
270 void moveTo(MSPerson* p, MSLane* lane, double lanePos, double lanePosLat, SUMOTime t);
271 void moveToXY(MSPerson* p, Position pos, MSLane* lane, double lanePos,
272 double lanePosLat, double angle, int routeOffset,
273 const ConstMSEdgeVector& edges, SUMOTime t);
274
279
281 virtual double getMinX(const bool includeMinGap = true) const;
282
284 virtual double getMaxX(const bool includeMinGap = true) const;
285
287 double getLength() const;
288
290 double getMinGap() const;
291
293 double distToLaneEnd() const;
294
296 bool moveToNextLane(SUMOTime currentTime);
297
299 void walk(const Obstacles& obs, SUMOTime currentTime);
300
302 double getImpatience(SUMOTime now) const;
303
304 int stripe() const;
305 int otherStripe() const;
306
307 static int stripe(const double relY);
308 int otherStripe(const double relY) const;
309
310 /* @brief calculate distance to the given obstacle,
311 * - non-negative values signify an obstacle in front of ego
312 * the special values DIST_OVERLAP and DIST_BEHIND are used to signify
313 * obstacles that overlap and obstacles behind ego respectively
314 * the result is the same regardless of walking direction
315 */
316 double distanceTo(const Obstacle& obs, const bool includeMinGap = true) const;
317
319 void mergeObstacles(Obstacles& into, const Obstacles& obs2);
320
322 static void mergeObstacles(Obstacles& into, const Obstacles& obs2, int dir, int offset);
323
325 bool ignoreRed(const MSLink* link) const;
326
328 bool stopForYellow(const MSLink* link) const;
329
331 virtual double getWidth() const;
332
333 virtual ObstacleType getOType() const {
334 return OBSTACLE_PED;
335 }
336
338 bool isRemoteControlled() const;
339
342 void saveState(std::ostringstream& out);
343
344 const MSLane* getNextCrossing() const;
345
347 double getLatOffset() const {
349 }
350
351 inline double getPosLat() const {
352 return myPosLat;
353 }
354
355 double getPathLength() const;
356 void reverse(const double pathLength, const double usableWidth);
357 void reset(const double edgePos, const double latPos);
358
359 protected:
361 PState();
362 private:
364 PState& operator=(const PState&) = delete;
365 };
366
367 class PStateVehicle : public PState {
368 public:
369 PStateVehicle(const MSVehicle* veh, const MSLane* walkingarea, double relX, double relY, double xWidth, double yWidth);
370 const std::string& getID() const;
371 double getMinX(const bool includeMinGap = true) const;
372 double getMaxX(const bool includeMinGap = true) const;
373 double getWidth() const;
374
376 return OBSTACLE_VEHICLE;
377 }
378
379 const MSVehicle* getVehicle() const {
380 return myVehicle;
381 }
382 private:
384 const double myXWidth;
385 const double myYWidth;
386 };
387
388
389 class MovePedestrians : public Command {
390 public:
393 SUMOTime execute(SUMOTime currentTime);
394 private:
396 private:
399 };
400
403 public:
405 by_xpos_sorter(int dir): myDir(dir) {}
406
407 public:
410 if (p1->getEdgePos(0) != p2->getEdgePos(0)) {
411 return myDir * p1->getEdgePos(0) > myDir * p2->getEdgePos(0);
412 }
413 return p1->getID() < p2->getID();
414 }
415
416 private:
417 const int myDir;
418 };
419
420
422 void moveInDirection(SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
423
425 void moveInDirectionOnLane(Pedestrians& pedestrians, const MSLane* lane, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir, bool debug);
426
428 void arriveAndAdvance(Pedestrians& pedestrians, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
429
431 return myActiveLanes;
432 }
433
434private:
435 static void DEBUG_PRINT(const Obstacles& obs);
436
438 static int connectedDirection(const MSLane* from, const MSLane* to);
439
445 static NextLaneInfo getNextLane(const PState& ped, const MSLane* currentLane, const MSLane* prevLane);
446
448 static const MSLane* getNextWalkingArea(const MSLane* currentLane, const int dir, const MSLink*& link);
449
450 static void initWalkingAreaPaths(const MSNet* net);
451
453 static void insertWalkArePaths(const MSEdge* edge, WalkingAreaPaths& into);
454
455 static const WalkingAreaPath* getWalkingAreaPath(const MSEdge* walkingArea, const MSLane* before, const MSLane* after);
456
458 static const WalkingAreaPath* getArbitraryPath(const MSEdge* walkingArea);
459
460 static const WalkingAreaPath* guessPath(const MSEdge* walkingArea, const MSEdge* before, const MSEdge* after);
461
463 static int numStripes(const MSLane* lane);
464
465 static Obstacles getNeighboringObstacles(const Pedestrians& pedestrians, int egoIndex, int stripes);
466
467 const Obstacles& getNextLaneObstacles(NextLanesObstacles& nextLanesObs, const MSLane* lane, const MSLane* nextLane, int stripes,
468 int nextDir, double currentLength, int currentDir);
469
470 static void transformToCurrentLanePositions(Obstacles& o, int currentDir, int nextDir, double currentLength, double nextLength);
471
472 static void addCloserObstacle(Obstacles& obs, double x, int stripe, int numStripes, const std::string& id, double width, int dir, ObstacleType type);
473
474 /* @brief compute stripe-offset to transform relY values from a lane with origStripes into a lane wit destStrips
475 * @note this is called once for transforming nextLane peds to into the current system as obstacles and another time
476 * (in reverse) to transform the pedestrian coordinates into the nextLane-coordinates when changing lanes
477 */
478 static int getStripeOffset(int origStripes, int destStripes, bool addRemainder);
479
481 static bool addCrossingVehs(const MSLane* crossing, int stripes, double lateral_offset, int dir, Obstacles& crossingVehs, bool prio);
482
484 static Obstacles getVehicleObstacles(const MSLane* lane, int dir, PState* ped = 0);
485
486 static bool addVehicleFoe(const MSVehicle* veh, const MSLane* walkingarea, const Position& relPos, double xWidth, double yWidth, double lateral_offset,
487 double minY, double maxY, Pedestrians& toDelete, Pedestrians& transformedPeds);
488
489 static int getReserved(int stripes, double factor);
490
492 static void registerCrossingApproach(const PState& ped, const MSLane* crossing, const MSLane* beforeWA);
493
494private:
497 static std::map<const MSEdge*, std::vector<const MSLane*> > myWalkingAreaFoes;
499};
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:74
Base (microsim) event class.
Definition Command.h:50
A road/street connecting two junctions.
Definition MSEdge.h:77
The base class for an intersection.
Definition MSJunction.h:58
Representation of a lane in the micro simulation.
Definition MSLane.h:84
int getNumericalID() const
Returns this lane's numerical id.
Definition MSLane.h:525
double getWidth() const
Returns the lane's width.
Definition MSLane.h:635
The simulated network and simulation perfomer.
Definition MSNet.h:89
The abstract superclass for pedestrian models which actually interact with vehicles.
std::map< const MSLane *, Pedestrians, ComparatorNumericalIdLess > ActiveLanes
std::vector< MSPModel_InteractingState * > Pedestrians
ActiveLanes myActiveLanes
store of all lanes which have pedestrians on them
Container for pedestrian state and individual position update function.
double getEdgePos(SUMOTime) const
abstract methods inherited from MSTransportableStateAdapter
virtual const std::string & getID() const
return ID of the person (or sometimes vehicle) being represented
const MSLane * myLane
the current lane of this pedestrian
double myPosLat
the orthogonal shift on the current lane
MovePedestrians(MSPModel_Striping *model)
SUMOTime execute(SUMOTime currentTime)
Executes the command.
MovePedestrians & operator=(const MovePedestrians &)=delete
Invalidated assignment operator.
Container for pedestrian state and individual position update function.
virtual double getMaxX(const bool includeMinGap=true) const
return the maximum position on the lane
const WalkingAreaPath * myWalkingAreaPath
the current walkingAreaPath or 0
PState()
constructor for PStateVehicle
double distToLaneEnd() const
the absolute distance to the end of the lane in walking direction (or to the arrivalPos)
void mergeObstacles(Obstacles &into, const Obstacles &obs2)
replace obstacles in the first vector with obstacles from the second if they are closer to me
bool isRemoteControlled() const
whether the person is currently being controlled via TraCI
const MSEdge * getNextEdge(const MSStageMoving &stage) const
return the list of internal edges if the transportable is on an intersection
const MSLane * getNextCrossing() const
placeholder function for the accessing the next crossing
void walk(const Obstacles &obs, SUMOTime currentTime)
perform position update
virtual double getWidth() const
return the person width
void saveState(std::ostringstream &out)
Saves the current state into the given stream.
bool ignoreRed(const MSLink *link) const
whether the pedestrian may ignore a red light
virtual double getMinX(const bool includeMinGap=true) const
return the minimum position on the lane
bool moveToNextLane(SUMOTime currentTime)
return whether this pedestrian has passed the end of the current lane and update myRelX if so
void reverse(const double pathLength, const double usableWidth)
double getMinGap() const
return the minimum gap of the pedestrian
void moveToXY(MSPerson *p, Position pos, MSLane *lane, double lanePos, double lanePosLat, double angle, int routeOffset, const ConstMSEdgeVector &edges, SUMOTime t)
try to move transportable to the given position
void moveTo(MSPerson *p, MSLane *lane, double lanePos, double lanePosLat, SUMOTime t)
try to move transportable to the given position
PState & operator=(const PState &)=delete
Invalidated assignment operator.
Position getPosition(const MSStageMoving &stage, SUMOTime now) const
return the network coordinate of the transportable
NextLaneInfo myNLI
information about the upcoming lane
virtual ObstacleType getOType() const
double getAngle(const MSStageMoving &stage, SUMOTime now) const
return the current orientation in degrees
double getImpatience(SUMOTime now) const
returns the impatience
void reset(const double edgePos, const double latPos)
double distanceTo(const Obstacle &obs, const bool includeMinGap=true) const
bool stopForYellow(const MSLink *link) const
whether the pedestrian should stop at a yellow light
double getLength() const
return the length of the pedestrian
double getPathLength() const
return the total length of the current lane (in particular for on a walkingarea)
double getLatOffset() const
return the lateral offset to the lane center
double getWidth() const
return the person width
const MSVehicle * getVehicle() const
double getMaxX(const bool includeMinGap=true) const
return the maximum position on the lane
double getMinX(const bool includeMinGap=true) const
return the minimum position on the lane
const std::string & getID() const
return ID of the person (or sometimes vehicle) being represented
sorts the persons by position on the lane. If dir is forward, higher x positions come first.
bool operator()(const MSPModel_InteractingState *p1, const MSPModel_InteractingState *p2) const
comparing operation
bool operator()(const WalkingAreaPath *p1, const WalkingAreaPath *p2) const
comparing operation
The pedestrian movement model using stripes on sidewalks.
static const double MIN_STARTUP_DIST
the minimum distance to the next obstacle in order to start walking after stopped
static void registerCrossingApproach(const PState &ped, const MSLane *crossing, const MSLane *beforeWA)
register pedestrian approach with the junction model
static double RESERVE_FOR_ONCOMING_FACTOR
fraction of the leftmost lanes to reserve for oncoming traffic
static MinNextLengths myMinNextLengths
static bool addVehicleFoe(const MSVehicle *veh, const MSLane *walkingarea, const Position &relPos, double xWidth, double yWidth, double lateral_offset, double minY, double maxY, Pedestrians &toDelete, Pedestrians &transformedPeds)
MSTransportableStateAdapter * loadState(MSTransportable *transportable, MSStageMoving *stage, std::istringstream &in)
load the state of the given transportable
static double posLatConversion(const double posLat, const double laneWidth)
Convert the striping to the vehicle lateral position and vice versa.
static SUMOTime jamTimeCrossing
const ActiveLanes & getActiveLanes()
void moveInDirection(SUMOTime currentTime, std::set< MSPerson * > &changedLane, int dir)
move all pedestrians forward and advance to the next lane if applicable
static bool USE_NET_SPEEDS
whether to use speed limits embedded in the network
static void transformToCurrentLanePositions(Obstacles &o, int currentDir, int nextDir, double currentLength, double nextLength)
static int myWalkingAreaDetail
intermediate points to smooth out lanes within the walkingarea
static const double LOOKAHEAD_SAMEDIR
the distance (in seconds) to look ahead for changing stripes
static double RESERVE_FOR_ONCOMING_MAX
std::map< const MSLane *, Obstacles, ComparatorNumericalIdLess > NextLanesObstacles
static double minGapToVehicle
the safety buffer to vehicles
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...
static const double LOOKAHEAD_ONCOMING_DIST
the distance (in m) to look ahead for obstacles on a subsequent edge
static void initWalkingAreaPaths(const MSNet *net)
static const double LOOKAROUND_VEHICLES
the distance (in m) to look around for vehicles
static const double SQUEEZE
the factor by which pedestrian width is reduced when sqeezing past each other
static SUMOTime jamTimeNarrow
static const WalkingAreaPath * getWalkingAreaPath(const MSEdge *walkingArea, const MSLane *before, const MSLane *after)
void arriveAndAdvance(Pedestrians &pedestrians, SUMOTime currentTime, std::set< MSPerson * > &changedLane, int dir)
handle arrivals and lane advancement
std::map< const MSLane *, double > MinNextLengths
static double RESERVE_FOR_ONCOMING_FACTOR_JUNCTIONS
static int getStripeOffset(int origStripes, int destStripes, bool addRemainder)
static const WalkingAreaPath * guessPath(const MSEdge *walkingArea, const MSEdge *before, const MSEdge *after)
static int getReserved(int stripes, double factor)
static SUMOTime jamTime
the time threshold before becoming jammed
static void insertWalkArePaths(const MSEdge *edge, WalkingAreaPaths &into)
creates and inserts all paths into the given map
void moveInDirectionOnLane(Pedestrians &pedestrians, const MSLane *lane, SUMOTime currentTime, std::set< MSPerson * > &changedLane, int dir, bool debug)
move pedestrians forward on one lane
static double jamFactor
the factor on speed when jammed
static double stripeWidth
model parameters
static const double MAX_WAIT_TOLERANCE
the time pedestrians take to reach maximum impatience
static Obstacles getVehicleObstacles(const MSLane *lane, int dir, PState *ped=0)
retrieve vehicle obstacles on the given lane
static const double OBSTRUCTED_PENALTY
the utility penalty for obstructed (physically blocking me) stripes (corresponds to meters)
static const MSLane * getNextWalkingArea(const MSLane *currentLane, const int dir, const MSLink *&link)
return the next walkingArea in the given direction
MSTransportableStateAdapter * add(MSTransportable *transportable, MSStageMoving *stage, SUMOTime now)
register the given person as a pedestrian
static const double DIST_OVERLAP
static const WalkingAreaPath * getArbitraryPath(const MSEdge *walkingArea)
return an arbitrary path across the given walkingArea
static const double LATERAL_PENALTY
the utility penalty for moving sideways (corresponds to meters)
std::vector< Obstacle > Obstacles
static const double DIST_BEHIND
static Obstacles getNeighboringObstacles(const Pedestrians &pedestrians, int egoIndex, int stripes)
static bool myLegacyPosLat
use old style departPosLat interpretation
static void addCloserObstacle(Obstacles &obs, double x, int stripe, int numStripes, const std::string &id, double width, int dir, ObstacleType type)
static double dawdling
the factor for random slow-down
static int numStripes(const MSLane *lane)
return the maximum number of pedestrians walking side by side
static const double OBSTRUCTION_THRESHOLD
the minimum utility that indicates obstruction
static bool addCrossingVehs(const MSLane *crossing, int stripes, double lateral_offset, int dir, Obstacles &crossingVehs, bool prio)
add vehicles driving across
static int connectedDirection(const MSLane *from, const MSLane *to)
returns the direction in which these lanes are connectioned or 0 if they are not
static void DEBUG_PRINT(const Obstacles &obs)
static const double LATERAL_SPEED_FACTOR
the fraction of forward speed to be used for lateral movemenk
static const double INAPPROPRIATE_PENALTY
the utility penalty for inappropriate (reserved for oncoming traffic or may violate my min gap) strip...
static const double ONCOMING_CONFLICT_PENALTY
the utility penalty for oncoming conflicts on stripes (corresponds to meters)
static const double LOOKAHEAD_ONCOMING
the distance (in seconds) to look ahead for changing stripes (regarding oncoming pedestrians)
static std::map< const MSEdge *, std::vector< const MSLane * > > myWalkingAreaFoes
const Obstacles & getNextLaneObstacles(NextLanesObstacles &nextLanesObs, const MSLane *lane, const MSLane *nextLane, int stripes, int nextDir, double currentLength, int currentDir)
static const double DIST_FAR_AWAY
std::map< std::pair< const MSLane *, const MSLane * >, const WalkingAreaPath > WalkingAreaPaths
static WalkingAreaPaths myWalkingAreaPaths
store for walkinArea elements
static const int UNDEFINED_DIRECTION
Definition MSPModel.h:56
abstract base class for managing callbacks to retrieve various state information from the model
Definition MSPModel.h:154
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
A storage for options typed value containers)
Definition OptionsCont.h:89
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
Representation of a vehicle.
Definition SUMOVehicle.h:62
int dir
the direction on the next lane
NextLaneInfo(const MSLane *_lane, const MSLink *_link, int _dir)
const MSLink * link
the link from the current lane to the next lane
const MSLane * lane
the next lane to be used
information regarding surround Pedestrians (and potentially other things)
Obstacle(double _x, double _speed, ObstacleType _type, const std::string &_description, const double width=0., const SUMOVehicle *veh=nullptr)
create an obstacle from explicit values
double speed
speed relative to lane direction (positive means in the same direction)
double xFwd
maximal position on the current lane in forward direction
bool closer(const Obstacle &o, int dir)
std::string description
the id / description of the obstacle
const SUMOVehicle * vehicle
a pointer to the vehicle if this obstacle is one
ObstacleType type
whether this obstacle denotes a border, a vehicle or a pedestrian
double xBack
maximal position on the current lane in backward direction
WalkingAreaPath(const MSLane *_from, const MSLane *_walkingArea, const MSLane *_to, const PositionVector &_shape, int _dir, double _angleOverride)