Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSPModel_Interacting.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2014-2025 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 following model (prototype)
20/****************************************************************************/
21#include <config.h>
22
23#include <microsim/MSGlobals.h>
24#include <microsim/MSLane.h>
25#include <microsim/MSLink.h>
26#include <microsim/MSNet.h>
28
29//#define DEBUG_INTERACTING
30//#define DEBUG_CROSSING_APPROACH
31
32#define DEBUGCOND(PED) ((PED)->getPerson()->isSelected())
33
34// ===========================================================================
35// static members
36// ===========================================================================
38
39
40// ===========================================================================
41// MSPModel_Interacting method definitions
42// ===========================================================================
46
47
48void
54
55
56void
58 Pedestrians& pedestrians = myActiveLanes[state->getLane()];
59 MSPModel_InteractingState* const p = static_cast<MSPModel_InteractingState*>(state);
60 const auto& it = std::find(pedestrians.begin(), pedestrians.end(), p);
61 if (it != pedestrians.end()) {
62 if (p->getNextCrossing() != nullptr) {
64 }
65 pedestrians.erase(it);
67 }
68}
69
70
71bool
72MSPModel_Interacting::blockedAtDist(const SUMOTrafficObject* ego, const MSLane* lane, double vehCenter, double vehWidth,
73 double oncomingGap, std::vector<const MSPerson*>* collectBlockers) {
74 for (const MSPModel_InteractingState* ped : getPedestrians(lane)) {
75 const double leaderFrontDist = (ped->getDirection() == FORWARD ? vehCenter - ped->getEdgePos(0) : ped->getEdgePos(0) - vehCenter) - vehWidth * 0.5;
76 const double leaderBackDist = leaderFrontDist + ped->getPerson()->getVehicleType().getLength();
77#ifdef DEBUG_INTERACTING
78 if DEBUGCOND(ped) {
79 std::cout << SIMTIME << " lane=" << lane->getID() << " dir=" << ped->getDirection() << " pX=" << ped->getEdgePos(0) << " pL=" << ped->getPerson()->getVehicleType().getLength()
80 << " vehCenter=" << vehCenter
81 << " vehWidth=" << vehWidth
82 << " lBD=" << leaderBackDist
83 << " lFD=" << leaderFrontDist
84 << "\n";
85 }
86#endif
87 if (leaderBackDist >= -vehWidth
88 && (leaderFrontDist < 0
89 // give right of way to (close) approaching pedestrians unless they are standing
90 || (leaderFrontDist <= oncomingGap && ped->getWaitingTime() < TIME2STEPS(2.0)))) {
91 if (MSLink::ignoreFoe(ego, ped->getPerson())) {
92 continue;
93 }
94 // found one pedestrian that is not completely past the crossing point
95 //std::cout << SIMTIME << " blocking pedestrian foeLane=" << lane->getID() << " ped=" << ped->getPerson()->getID() << " dir=" << ped->getDirection() << " pX=" << ped->getEdgePos(0) << " pL=" << ped.getLength() << " fDTC=" << distToCrossing << " lBD=" << leaderBackDist << "\n";
96 if (collectBlockers == nullptr) {
97 return true;
98 }
99 collectBlockers->push_back(ped->getPerson());
100 }
101 }
102 if (collectBlockers == nullptr) {
103 return false;
104 }
105 return collectBlockers->size() > 0;
106}
107
108
109bool
111 return getPedestrians(lane).size() > 0;
112}
113
114
115bool
119
120
121bool
125
126
128MSPModel_Interacting::nextBlocking(const MSLane* lane, double minPos, double minRight, double maxLeft, double stopTime, bool bidi) {
129 PersonDist result((const MSPerson*)nullptr, std::numeric_limits<double>::max());
130 for (const MSPModel_InteractingState* ped : getPedestrians(lane)) {
131 // account for distance covered by oncoming pedestrians
132 double relX2 = ped->getEdgePos(0) - (ped->getDirection() == FORWARD ? 0 : stopTime * ped->getPerson()->getMaxSpeed());
133 double dist = ((relX2 - minPos) * (bidi ? -1 : 1)
134 - (ped->getDirection() == FORWARD ? ped->getPerson()->getVehicleType().getLength() : 0));
135 const bool aheadOfVehicle = bidi ? ped->getEdgePos(0) < minPos : ped->getEdgePos(0) > minPos;
136 if (aheadOfVehicle && dist < result.second) {
137 const double center = ped->getLatOffset() + 0.5 * lane->getWidth();
138 const double halfWidth = 0.5 * ped->getPerson()->getVehicleType().getWidth();
139 const bool overlap = (center + halfWidth > minRight && center - halfWidth < maxLeft);
140#ifdef DEBUG_INTERACTING
141 if DEBUGCOND(ped) {
142 std::cout << " nextBlocking lane=" << lane->getID() << " bidi=" << bidi
143 << " minPos=" << minPos << " minRight=" << minRight << " maxLeft=" << maxLeft
144 << " stopTime=" << stopTime
145 << " ped=" << ped->getID()
146 << " pedX=" << ped->getEdgePos(0)
147 << " relX2=" << relX2
148 << " center=" << center
149 << " pedLeft=" << center + halfWidth
150 << " pedRight=" << center - halfWidth
151 << " overlap=" << overlap
152 << "\n";
153 }
154#endif
155 if (overlap) {
156 result.first = ped->getPerson();
157 result.second = dist;
158 }
159 }
160 }
161 return result;
162}
163
164
167 ActiveLanes::iterator it = myActiveLanes.find(lane);
168 if (it != myActiveLanes.end()) {
169 //std::cout << " found lane=" << lane->getID() << " n=" << it->second.size() << "\n";
170 return (it->second);
171 }
172 return noPedestrians;
173}
174
175
176void
178 // person has entered the crossing
179 crossing->getIncomingLanes()[0].viaLink->removeApproachingPerson(ped.getPerson());
180#ifdef DEBUG_CROSSING_APPROACH
181 if DEBUGCOND(&ped) {
182 std::cout << SIMTIME << " unregister " << ped.getPerson()->getID() << " at crossing " << crossing->getID() << "\n";
183 }
184#endif
185}
186
187
188/****************************************************************************/
std::pair< const MSPerson *, double > PersonDist
Definition MSPModel.h:41
#define DEBUGCOND(PED)
#define SIMTIME
Definition SUMOTime.h:62
#define TIME2STEPS(x)
Definition SUMOTime.h:57
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition MSGlobals.h:81
Representation of a lane in the micro simulation.
Definition MSLane.h:84
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
Definition MSLane.h:960
double getWidth() const
Returns the lane's width.
Definition MSLane.h:640
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:187
bool hasPedestrianNetwork() const
return whether the network contains walkingareas and crossings
Definition MSNet.h:813
bool hasInternalLinks() const
return whether the network contains internal links
Definition MSNet.h:798
std::vector< MSPModel_InteractingState * > Pedestrians
bool usingInternalLanes()
whether movements on intersections are modelled /
Pedestrians & getPedestrians(const MSLane *lane)
retrieves the pedestrian vector for the given lane (may be empty)
PersonDist nextBlocking(const MSLane *lane, double minPos, double minRight, double maxLeft, double stopTime=0, bool bidi=false)
returns the next pedestrian beyond minPos that is laterally between minRight and maxLeft or nullptr
ActiveLanes myActiveLanes
store of all lanes which have pedestrians on them
bool myAmActive
whether an event for pedestrian processing was added
static Pedestrians noPedestrians
empty pedestrian vector
int myNumActivePedestrians
the total number of active pedestrians
virtual void remove(MSTransportableStateAdapter *state)
remove the specified person from the pedestrian simulation
bool blockedAtDist(const SUMOTrafficObject *ego, const MSLane *lane, double vehCenter, double vehWidth, double oncomingGap, std::vector< const MSPerson * > *collectBlockers)
whether a pedestrian is blocking the crossing of lane for the given vehicle bondaries
bool hasPedestrians(const MSLane *lane)
whether the given lane has pedestrians on it
virtual void clearState()
Resets pedestrians when quick-loading state.
static void unregisterCrossingApproach(const MSPModel_InteractingState &ped, const MSLane *crossing)
unregister pedestrian approach with the junction model
Container for pedestrian state and individual position update function.
virtual const MSLane * getNextCrossing() const
placeholder function for the accessing the next crossing
MSPerson * getPerson() const
return the represented person
static const int FORWARD
Definition MSPModel.h:54
abstract base class for managing callbacks to retrieve various state information from the model
Definition MSPModel.h:154
virtual const MSLane * getLane() const
the current lane of the transportable
Definition MSPModel.h:220
const std::string & getID() const
Returns the id.
Definition Named.h:74
Representation of a vehicle, person, or container.