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 const double MAX_WAIT_TOLERANCE;
148
150 static const double LATERAL_SPEED_FACTOR;
151
153 static const double MIN_STARTUP_DIST;
154
156
158 // The striping model uses as lateral position the distance of the center of the pedestrian
159 // to the left boundary of the lane minus a half stripe width, where right is positive.
160 // The vehicle uses the distance to the center of the lane (and left is positive).
161 // The function happens to be self inverse so it can be used to convert in both directions.
162 inline static double posLatConversion(const double posLat, const double laneWidth) {
163 return .5 * (laneWidth - stripeWidth) - posLat;
164 }
165
166
167protected:
168 static const double DIST_FAR_AWAY;
169 static const double DIST_BEHIND;
170 static const double DIST_OVERLAP;
171
172 struct Obstacle;
173 class PState;
174 typedef std::vector<Obstacle> Obstacles;
175 typedef std::map<const MSLane*, Obstacles, ComparatorNumericalIdLess> NextLanesObstacles;
176 typedef std::map<const MSLane*, double> MinNextLengths;
177
179 NextLaneInfo(const MSLane* _lane, const MSLink* _link, int _dir) :
180 lane(_lane),
181 link(_link),
182 dir(_dir) {
183 }
184
186 lane(0),
187 link(0),
189 }
190
192 const MSLane* lane;
194 const MSLink* link;
196 int dir;
197 };
198
208
210 struct Obstacle {
212 Obstacle(int dir, double dist = DIST_FAR_AWAY);
214 Obstacle(const PState& ped);
216 Obstacle(double _x, double _speed, ObstacleType _type, const std::string& _description, const double width = 0., const SUMOVehicle* veh = nullptr)
217 : xFwd(_x + width / 2.), xBack(_x - width / 2.), speed(_speed), type(_type), description(_description), vehicle(veh) {};
218
220 double xFwd;
222 double xBack;
224 double speed;
228 std::string description;
230 const SUMOVehicle* vehicle = nullptr;
231
232 bool closer(const Obstacle& o, int dir);
233 };
234
236 public:
238 bool operator()(const WalkingAreaPath* p1, const WalkingAreaPath* p2) const {
239 if (p1->from->getNumericalID() < p2->from->getNumericalID()) {
240 return true;
241 }
242 if (p1->from->getNumericalID() == p2->from->getNumericalID()) {
243 if (p1->to->getNumericalID() < p2->to->getNumericalID()) {
244 return true;
245 }
246 }
247 return false;
248 }
249 };
250
251
257 public:
258 PState(MSPerson* person, MSStageMoving* stage, const MSLane* lane);
259
261 PState(MSPerson* person, MSStageMoving* stage, std::istringstream* in = nullptr);
262
264 Position getPosition(const MSStageMoving& stage, SUMOTime now) const;
265 double getAngle(const MSStageMoving& stage, SUMOTime now) const;
266 const MSEdge* getNextEdge(const MSStageMoving& stage) const;
267 void moveTo(MSPerson* p, MSLane* lane, double lanePos, double lanePosLat, SUMOTime t);
268 void moveToXY(MSPerson* p, Position pos, MSLane* lane, double lanePos,
269 double lanePosLat, double angle, int routeOffset,
270 const ConstMSEdgeVector& edges, SUMOTime t);
271
276
278 virtual double getMinX(const bool includeMinGap = true) const;
279
281 virtual double getMaxX(const bool includeMinGap = true) const;
282
284 double getLength() const;
285
287 double getMinGap() const;
288
290 double distToLaneEnd() const;
291
293 bool moveToNextLane(SUMOTime currentTime);
294
296 void walk(const Obstacles& obs, SUMOTime currentTime);
297
299 double getImpatience(SUMOTime now) const;
300
301 int stripe() const;
302 int otherStripe() const;
303
304 static int stripe(const double relY);
305 int otherStripe(const double relY) const;
306
307 /* @brief calculate distance to the given obstacle,
308 * - non-negative values signify an obstacle in front of ego
309 * the special values DIST_OVERLAP and DIST_BEHIND are used to signify
310 * obstacles that overlap and obstacles behind ego respectively
311 * the result is the same regardless of walking direction
312 */
313 double distanceTo(const Obstacle& obs, const bool includeMinGap = true) const;
314
316 void mergeObstacles(Obstacles& into, const Obstacles& obs2);
317
319 static void mergeObstacles(Obstacles& into, const Obstacles& obs2, int dir, int offset);
320
322 bool ignoreRed(const MSLink* link) const;
323
325 virtual double getWidth() const;
326
327 virtual ObstacleType getOType() const {
328 return OBSTACLE_PED;
329 }
330
332 bool isRemoteControlled() const;
333
336 void saveState(std::ostringstream& out);
337
338 const MSLane* getNextCrossing() const;
339
341 double getLatOffset() const {
343 }
344
345 inline double getPosLat() const {
346 return myPosLat;
347 }
348
349 double getPathLength() const;
350 void reverse(const double pathLength, const double usableWidth);
351 void reset(const double edgePos, const double latPos);
352
353 protected:
355 PState();
356 private:
358 PState& operator=(const PState&) = delete;
359 };
360
361 class PStateVehicle : public PState {
362 public:
363 PStateVehicle(const MSVehicle* veh, const MSLane* walkingarea, double relX, double relY, double xWidth, double yWidth);
364 const std::string& getID() const;
365 double getMinX(const bool includeMinGap = true) const;
366 double getMaxX(const bool includeMinGap = true) const;
367 double getWidth() const;
368
370 return OBSTACLE_VEHICLE;
371 }
372
373 const MSVehicle* getVehicle() const {
374 return myVehicle;
375 }
376 private:
378 const double myXWidth;
379 const double myYWidth;
380 };
381
382
383 class MovePedestrians : public Command {
384 public:
387 SUMOTime execute(SUMOTime currentTime);
388 private:
390 private:
393 };
394
397 public:
399 by_xpos_sorter(int dir): myDir(dir) {}
400
401 public:
404 if (p1->getEdgePos(0) != p2->getEdgePos(0)) {
405 return myDir * p1->getEdgePos(0) > myDir * p2->getEdgePos(0);
406 }
407 return p1->getID() < p2->getID();
408 }
409
410 private:
411 const int myDir;
412 };
413
414
416 void moveInDirection(SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
417
419 void moveInDirectionOnLane(Pedestrians& pedestrians, const MSLane* lane, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir, bool debug);
420
422 void arriveAndAdvance(Pedestrians& pedestrians, SUMOTime currentTime, std::set<MSPerson*>& changedLane, int dir);
423
425 return myActiveLanes;
426 }
427
428private:
429 static void DEBUG_PRINT(const Obstacles& obs);
430
432 static int connectedDirection(const MSLane* from, const MSLane* to);
433
439 static NextLaneInfo getNextLane(const PState& ped, const MSLane* currentLane, const MSLane* prevLane);
440
442 static const MSLane* getNextWalkingArea(const MSLane* currentLane, const int dir, const MSLink*& link);
443
444 static void initWalkingAreaPaths(const MSNet* net);
445
447 static void insertWalkArePaths(const MSEdge* edge, WalkingAreaPaths& into);
448
449 static const WalkingAreaPath* getWalkingAreaPath(const MSEdge* walkingArea, const MSLane* before, const MSLane* after);
450
452 static const WalkingAreaPath* getArbitraryPath(const MSEdge* walkingArea);
453
454 static const WalkingAreaPath* guessPath(const MSEdge* walkingArea, const MSEdge* before, const MSEdge* after);
455
457 static int numStripes(const MSLane* lane);
458
459 static Obstacles getNeighboringObstacles(const Pedestrians& pedestrians, int egoIndex, int stripes);
460
461 const Obstacles& getNextLaneObstacles(NextLanesObstacles& nextLanesObs, const MSLane* lane, const MSLane* nextLane, int stripes,
462 int nextDir, double currentLength, int currentDir);
463
464 static void transformToCurrentLanePositions(Obstacles& o, int currentDir, int nextDir, double currentLength, double nextLength);
465
466 static void addCloserObstacle(Obstacles& obs, double x, int stripe, int numStripes, const std::string& id, double width, int dir, ObstacleType type);
467
468 /* @brief compute stripe-offset to transform relY values from a lane with origStripes into a lane wit destStrips
469 * @note this is called once for transforming nextLane peds to into the current system as obstacles and another time
470 * (in reverse) to transform the pedestrian coordinates into the nextLane-coordinates when changing lanes
471 */
472 static int getStripeOffset(int origStripes, int destStripes, bool addRemainder);
473
475 static bool addCrossingVehs(const MSLane* crossing, int stripes, double lateral_offset, int dir, Obstacles& crossingVehs, bool prio);
476
478 static Obstacles getVehicleObstacles(const MSLane* lane, int dir, PState* ped = 0);
479
480 static bool addVehicleFoe(const MSVehicle* veh, const MSLane* walkingarea, const Position& relPos, double xWidth, double yWidth, double lateral_offset,
481 double minY, double maxY, Pedestrians& toDelete, Pedestrians& transformedPeds);
482
483 static int getReserved(int stripes, double factor);
484
486 static void registerCrossingApproach(const PState& ped, const MSLane* crossing, const MSLane* beforeWA);
487
488private:
491 static std::map<const MSEdge*, std::vector<const MSLane*> > myWalkingAreaFoes;
493};
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
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 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)