Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2014-2026 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 6049 : 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 943528 : int getActiveNumber() {
85 943528 : return myNumActivePedestrians;
86 : }
87 :
88 : /// @brief increase the number of active pedestrians
89 : void registerActive() {
90 317 : myNumActivePedestrians++;
91 317 : }
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 748875 : MSPModel_InteractingState(MSPerson* person, MSStageMoving* stage, const MSLane* lane) :
130 748875 : myPerson(person),
131 748875 : myStage(stage),
132 748875 : myLane(lane),
133 243956 : myEdgePos(stage != nullptr ? stage->getDepartPos() : 0.),
134 243956 : myPosLat(stage != nullptr ? stage->getDepartPosLat() : 0.),
135 748875 : myDir(MSPModel::UNDEFINED_DIRECTION),
136 243956 : 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 9073507393 : inline double getEdgePos(SUMOTime /* now */) const {
144 9073507393 : return myEdgePos;
145 : }
146 :
147 : /// @brief return the walking direction (FORWARD, BACKWARD, UNDEFINED_DIRECTION)
148 1220908528 : inline int getDirection() const {
149 1220908528 : return myDir;
150 : }
151 :
152 : /// @brief return the time the transportable spent standing
153 12574694 : inline SUMOTime getWaitingTime() const {
154 12574694 : return myWaitingTime;
155 : }
156 :
157 73610 : virtual SUMOTime getTotalWaitingTime() const {
158 73610 : return myTotalWaitingTime;
159 : }
160 :
161 : /// @brief return the current speed of the transportable, we need to be able to do this for vehicles as well, so we cannot refer to the stage
162 : inline double getSpeed() const {
163 749299568 : return mySpeed;
164 : }
165 :
166 : /// @brief return the current speed of the transportable
167 562451 : inline double getSpeed(const MSStageMoving& /* stage */) const {
168 562451 : return mySpeed;
169 : }
170 :
171 : /// @brief whether the transportable is jammed
172 2765263903 : inline bool isJammed() const {
173 2765263903 : return myAmJammed;
174 : }
175 :
176 : /// @brief the current lane of the transportable
177 3598759 : inline const MSLane* getLane() const {
178 3598759 : return myLane;
179 : }
180 : /// @}
181 :
182 : /// @brief placeholder function for the accessing the next crossing
183 0 : virtual const MSLane* getNextCrossing() const {
184 0 : return nullptr;
185 : }
186 :
187 : /// @brief return the lateral offset to the lane center
188 0 : virtual double getLatOffset() const {
189 0 : return myPosLat;
190 : }
191 :
192 : /// @brief return the represented person
193 : inline MSPerson* getPerson() const {
194 11698467308 : return myPerson;
195 : }
196 :
197 : /// @brief return the current stage
198 : inline MSStageMoving* getStage() const {
199 179527425 : return myStage;
200 : }
201 :
202 : /// @brief whether the person still waits to entere the network
203 : inline bool isWaitingToEnter() const {
204 13910878260 : return myWaitingToEnter;
205 : }
206 :
207 : /// @brief return the remote position if being controlled by TraCI or JuPedSim
208 : inline const Position& getRemotePosition() const {
209 : return myRemoteXYPos;
210 : }
211 :
212 : /// @brief return ID of the person (or sometimes vehicle) being represented
213 3912113944 : virtual const std::string& getID() const {
214 3912113944 : return myPerson->getID();
215 : }
216 :
217 : /// @brief return the current orientation in degrees
218 : virtual double getAngle(const MSStageMoving&, SUMOTime) const {
219 : return myAngle;
220 : }
221 :
222 : protected:
223 : /// @brief the person who is being represented
224 : MSPerson* myPerson = nullptr;
225 : /// @brief the current stage of this pedestrian
226 : MSStageMoving* myStage = nullptr;
227 : /// @brief the current lane of this pedestrian
228 : const MSLane* myLane = nullptr;
229 : /// @brief the advancement along the current lane
230 : double myEdgePos = 0.;
231 : /// @brief the orthogonal shift on the current lane
232 : double myPosLat = 0.;
233 : /// @brief the walking direction on the current lane (1 forward, -1 backward)
234 : int myDir = MSPModel::UNDEFINED_DIRECTION;
235 : /// @brief the current walking speed
236 : double mySpeed = 0.;
237 : /// @brief the current lateral walking speed
238 : double mySpeedLat = 0.;
239 : /// @brief whether the pedestrian is waiting to start its walk
240 : bool myWaitingToEnter = false;
241 : /// @brief the consecutive time spent at speed 0
242 : SUMOTime myWaitingTime = 0;
243 : /// @brief the total time spent at speed 0
244 : SUMOTime myTotalWaitingTime = 0;
245 : /// @brief whether the person is jammed
246 : bool myAmJammed = false;
247 : /// @brief remote-controlled position
248 : Position myRemoteXYPos = Position::INVALID;
249 : /// @brief cached angle
250 : mutable double myAngle = std::numeric_limits<double>::max();
251 :
252 : private:
253 : /// @brief Invalidated assignment operator.
254 : MSPModel_InteractingState& operator=(const MSPModel_InteractingState&) = delete;
255 : };
|