Line data Source code
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 : /****************************************************************************/
14 : /// @file MSPModel_Interacting.h
15 : /// @author Jakob Erdmann
16 : /// @author Michael Behrisch
17 : /// @date Mon, 13 Jan 2014
18 : ///
19 : // The abstract superclass for pedestrian models which actually interact with vehicles
20 : /****************************************************************************/
21 : #pragma once
22 : #include <config.h>
23 :
24 : #include "MSPModel.h"
25 :
26 :
27 : // ===========================================================================
28 : // class declarations
29 : // ===========================================================================
30 : class MSPModel_InteractingState;
31 :
32 :
33 : // ===========================================================================
34 : // class definitions
35 : // ===========================================================================
36 : /**
37 : * @class MSPModel_Interacting
38 : * @brief The abstract superclass for pedestrian models which actually interact with vehicles
39 : *
40 : */
41 5408 : class MSPModel_Interacting : public MSPModel {
42 : public:
43 : ~MSPModel_Interacting();
44 :
45 : /// @brief Resets pedestrians when quick-loading state
46 : virtual void clearState();
47 :
48 : /// @brief remove the specified person from the pedestrian simulation
49 : virtual void remove(MSTransportableStateAdapter* state);
50 :
51 : /** @brief whether a pedestrian is blocking the crossing of lane for the given vehicle bondaries
52 : * @param[in] ego The object that inquires about blockage (and may electively ignore foes)
53 : * @param[in] lane The crossing to check
54 : * @param[in] vehside The offset to the vehicle side near the start of the crossing
55 : * @param[in] vehWidth The width of the vehicle
56 : * @param[in] oncomingGap The distance which the vehicle wants to keep from oncoming pedestrians
57 : * @param[in] collectBlockers The list of persons blocking the crossing
58 : * @return Whether the vehicle must wait
59 : */
60 : bool blockedAtDist(const SUMOTrafficObject* ego, const MSLane* lane, double vehCenter, double vehWidth,
61 : double oncomingGap, std::vector<const MSPerson*>* collectBlockers);
62 :
63 : /** @brief returns the next pedestrian beyond minPos that is laterally between minRight and maxLeft or nullptr
64 : * @param[in] lane the lane to check
65 : * @param[in] minPos The minimum offset along the lane after which to check
66 : * @param[in] minRight The rightmost border of the vehicle (0 indicates driving on the right border)
67 : * @param[in] maxLeft The leftmost border of the vehicle
68 : * @param[in] stopTime The time it would take the vehicle to come to a stop
69 : * @param[in] bidi Whether the vehicle is driving against the flow
70 : * @return The closest person (or nullptr) and the distance to it
71 : */
72 : PersonDist nextBlocking(const MSLane* lane, double minPos, double minRight, double maxLeft, double stopTime = 0, bool bidi = false);
73 :
74 : /// @brief whether the given lane has pedestrians on it
75 : bool hasPedestrians(const MSLane* lane);
76 :
77 : /// @brief whether movements on intersections are modelled
78 : //// @note function declared as member for sake of inheritance (delegates to static function)
79 : bool usingInternalLanes();
80 :
81 : static bool usingInternalLanesStatic();
82 :
83 : /// @brief return the number of active pedestrians
84 524678 : int getActiveNumber() {
85 524678 : return myNumActivePedestrians;
86 : }
87 :
88 : /// @brief increase the number of active pedestrians
89 : void registerActive() {
90 355 : myNumActivePedestrians++;
91 355 : }
92 :
93 : /// @brief unregister pedestrian approach with the junction model
94 : static void unregisterCrossingApproach(const MSPModel_InteractingState& ped, const MSLane* crossing);
95 :
96 : protected:
97 : typedef std::vector<MSPModel_InteractingState*> Pedestrians;
98 : typedef std::map<const MSLane*, Pedestrians, ComparatorNumericalIdLess> ActiveLanes;
99 :
100 : /// @brief retrieves the pedestrian vector for the given lane (may be empty)
101 : Pedestrians& getPedestrians(const MSLane* lane);
102 :
103 : /// @brief the total number of active pedestrians
104 : int myNumActivePedestrians = 0;
105 :
106 : /// @brief store of all lanes which have pedestrians on them
107 : ActiveLanes myActiveLanes;
108 :
109 : /// @brief whether an event for pedestrian processing was added
110 : bool myAmActive = false;
111 :
112 : /// @brief all crossings being approached by pedestrians
113 : std::set<MSLink*> myApproachedCrossings;
114 :
115 : /// @brief empty pedestrian vector
116 : static Pedestrians noPedestrians;
117 :
118 : };
119 :
120 :
121 : /**
122 : * @class MSPModel_InteractingState
123 : * This contains trivial implementations and members for the most used access methods
124 : * @brief Container for pedestrian state and individual position update function
125 : */
126 : class MSPModel_InteractingState : public MSTransportableStateAdapter {
127 : public:
128 : /// @brief constructor
129 738428 : MSPModel_InteractingState(MSPerson* person, MSStageMoving* stage, const MSLane* lane) :
130 738428 : myPerson(person),
131 738428 : myStage(stage),
132 738428 : myLane(lane),
133 243030 : myEdgePos(stage != nullptr ? stage->getDepartPos() : 0.),
134 243030 : myPosLat(stage != nullptr ? stage->getDepartPosLat() : 0.),
135 738428 : myDir(MSPModel::UNDEFINED_DIRECTION),
136 243030 : myWaitingToEnter(person != nullptr) {}
137 :
138 : ~MSPModel_InteractingState() {};
139 :
140 : /// @brief abstract methods inherited from MSTransportableStateAdapter
141 : /// @{
142 : /// @brief return the offset from the start of the current edge measured in its natural direction
143 8218588728 : inline double getEdgePos(SUMOTime /* now */) const {
144 8218588728 : return myEdgePos;
145 : }
146 :
147 : /// @brief return the walking direction (FORWARD, BACKWARD, UNDEFINED_DIRECTION)
148 1109462515 : inline int getDirection() const {
149 1109462515 : return myDir;
150 : }
151 :
152 : /// @brief return the time the transportable spent standing
153 11461571 : inline SUMOTime getWaitingTime() const {
154 11461571 : return myWaitingTime;
155 : }
156 :
157 73154 : virtual SUMOTime getTotalWaitingTime() const {
158 73154 : return myTotalWaitingTime;
159 : }
160 :
161 : /// @brief return the current speed of the transportable
162 679430139 : inline double getSpeed(const MSStageMoving& /* stage */) const {
163 679430139 : return mySpeed;
164 : }
165 :
166 : /// @brief whether the transportable is jammed
167 2383136003 : inline bool isJammed() const {
168 2383136003 : return myAmJammed;
169 : }
170 :
171 : /// @brief the current lane of the transportable
172 3671836 : inline const MSLane* getLane() const {
173 3671836 : return myLane;
174 : }
175 : /// @}
176 :
177 : /// @brief placeholder function for the accessing the next crossing
178 0 : virtual const MSLane* getNextCrossing() const {
179 0 : return nullptr;
180 : }
181 :
182 : /// @brief return the lateral offset to the lane center
183 0 : virtual double getLatOffset() const {
184 0 : return myPosLat;
185 : }
186 :
187 : /// @brief return the represented person
188 : inline MSPerson* getPerson() const {
189 10782186531 : return myPerson;
190 : }
191 :
192 : /// @brief return the current stage
193 : inline MSStageMoving* getStage() const {
194 846248581 : return myStage;
195 : }
196 :
197 : /// @brief whether the person still waits to entere the network
198 : inline bool isWaitingToEnter() const {
199 12660347332 : return myWaitingToEnter;
200 : }
201 :
202 : /// @brief return the remote position if being controlled by TraCI or JuPedSim
203 : inline const Position& getRemotePosition() const {
204 : return myRemoteXYPos;
205 : }
206 :
207 : /// @brief return ID of the person (or sometimes vehicle) being represented
208 3582849303 : virtual const std::string& getID() const {
209 3582849303 : return myPerson->getID();
210 : }
211 :
212 : /// @brief return the current orientation in degrees
213 : virtual double getAngle(const MSStageMoving&, SUMOTime) const {
214 : return myAngle;
215 : }
216 :
217 : protected:
218 : /// @brief the person who is being represented
219 : MSPerson* myPerson = nullptr;
220 : /// @brief the current stage of this pedestrian
221 : MSStageMoving* myStage = nullptr;
222 : /// @brief the current lane of this pedestrian
223 : const MSLane* myLane = nullptr;
224 : /// @brief the advancement along the current lane
225 : double myEdgePos = 0.;
226 : /// @brief the orthogonal shift on the current lane
227 : double myPosLat = 0.;
228 : /// @brief the walking direction on the current lane (1 forward, -1 backward)
229 : int myDir = MSPModel::UNDEFINED_DIRECTION;
230 : /// @brief the current walking speed
231 : double mySpeed = 0.;
232 : /// @brief the current lateral walking speed
233 : double mySpeedLat = 0.;
234 : /// @brief whether the pedestrian is waiting to start its walk
235 : bool myWaitingToEnter = false;
236 : /// @brief the consecutive time spent at speed 0
237 : SUMOTime myWaitingTime = 0;
238 : /// @brief the total time spent at speed 0
239 : SUMOTime myTotalWaitingTime = 0;
240 : /// @brief whether the person is jammed
241 : bool myAmJammed = false;
242 : /// @brief remote-controlled position
243 : Position myRemoteXYPos = Position::INVALID;
244 : /// @brief cached angle
245 : mutable double myAngle = std::numeric_limits<double>::max();
246 :
247 : private:
248 : /// @brief Invalidated assignment operator.
249 : MSPModel_InteractingState& operator=(const MSPModel_InteractingState&) = delete;
250 : };
|