Line data Source code
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 : /****************************************************************************/
14 : /// @file MSPModel.h
15 : /// @author Jakob Erdmann
16 : /// @date Mon, 13 Jan 2014
17 : ///
18 : // The pedestrian following model (prototype)
19 : /****************************************************************************/
20 : #pragma once
21 : #include <config.h>
22 :
23 : #include <string>
24 : #include <limits>
25 : #include <utils/common/SUMOTime.h>
26 : #include <utils/common/Command.h>
27 : #include <utils/common/MsgHandler.h>
28 : #include <utils/geom/GeomHelper.h>
29 : #include <microsim/transportables/MSPerson.h>
30 : #ifdef HAVE_FOX
31 : #include <utils/foxtools/fxheader.h>
32 : #endif
33 :
34 : // ===========================================================================
35 : // class declarations
36 : // ===========================================================================
37 : class MSNet;
38 : class MSLane;
39 : class MSJunction;
40 :
41 : typedef std::pair<const MSPerson*, double> PersonDist;
42 :
43 : // ===========================================================================
44 : // class definitions
45 : // ===========================================================================
46 : /**
47 : * @class MSPModel
48 : * @brief The pedestrian (and also sometimes container) movement model
49 : *
50 : */
51 : class MSPModel {
52 : public:
53 : // @brief walking directions
54 : static const int FORWARD;
55 : static const int BACKWARD;
56 : static const int UNDEFINED_DIRECTION;
57 :
58 : // @brief the safety gap to keep between the car and the pedestrian in all directions
59 : static const double SAFETY_GAP;
60 :
61 : /// @brief the offset for computing person positions when walking on edges without a sidewalk
62 : static const double SIDEWALK_OFFSET;
63 :
64 : /// @brief the default lateral offset for persons when starting a walk
65 : static const double UNSPECIFIED_POS_LAT;
66 :
67 : /// @brief magic value to encode randomized lateral offset for persons when starting a walk
68 : static const double RANDOM_POS_LAT;
69 :
70 : virtual ~MSPModel() {};
71 :
72 : /// @brief register the given person as a pedestrian
73 : virtual MSTransportableStateAdapter* add(MSTransportable* transportable, MSStageMoving* stage, SUMOTime now) = 0;
74 :
75 : /// @brief load the state of the given transportable
76 0 : virtual MSTransportableStateAdapter* loadState(MSTransportable* transportable, MSStageMoving* stage, std::istringstream& state) {
77 : UNUSED_PARAMETER(transportable);
78 : UNUSED_PARAMETER(stage);
79 : UNUSED_PARAMETER(state);
80 0 : return nullptr;
81 : }
82 :
83 : /// @brief Resets pedestrians when quick-loading state
84 : virtual void clearState() = 0;
85 :
86 : /// @brief remove the specified person from the pedestrian simulation
87 : virtual void remove(MSTransportableStateAdapter* state) = 0;
88 :
89 : /** @brief whether a pedestrian is blocking the crossing of lane for the given vehicle bondaries
90 : * @param[in] ego The object that inquires about blockage (and may electively ignore foes)
91 : * @param[in] lane The crossing to check
92 : * @param[in] vehSide The offset to the vehicle side near the start of the crossing
93 : * @param[in] vehWidth The width of the vehicle
94 : * @param[in] oncomingGap The distance which the vehicle wants to keep from oncoming pedestrians
95 : * @param[in] collectBlockers The list of persons blocking the crossing
96 : * @return Whether the vehicle must wait
97 : */
98 51287 : virtual bool blockedAtDist(const SUMOTrafficObject* ego, const MSLane* lane, double vehCenter, double vehWidth,
99 : double oncomingGap, std::vector<const MSPerson*>* collectBlockers) {
100 : UNUSED_PARAMETER(ego);
101 : UNUSED_PARAMETER(lane);
102 : UNUSED_PARAMETER(vehCenter);
103 : UNUSED_PARAMETER(vehWidth);
104 : UNUSED_PARAMETER(oncomingGap);
105 : UNUSED_PARAMETER(collectBlockers);
106 51287 : return false;
107 : }
108 :
109 : /// @brief whether the given lane has pedestrians on it
110 79846 : virtual bool hasPedestrians(const MSLane* lane) {
111 : UNUSED_PARAMETER(lane);
112 79846 : return false;
113 : }
114 :
115 : /** @brief returns the next pedestrian beyond minPos that is laterally between minRight and maxLeft or nullptr
116 : * @param[in] lane the lane to check
117 : * @param[in] minPos The minimum offset along the lane after which to check
118 : * @param[in] minRight The rightmost border of the vehicle (0 indicates driving on the right border)
119 : * @param[in] maxLeft The leftmost border of the vehicle
120 : * @param[in] stopTime The time it would take the vehicle to come to a stop
121 : * @param[in] bidi Whether the vehicle is driving against the flow
122 : * @return The closest person (or nullptr) and the distance to it
123 : */
124 0 : virtual PersonDist nextBlocking(const MSLane* lane, double minPos, double minRight, double maxLeft, double stopTime = 0, bool bidi = false) {
125 : UNUSED_PARAMETER(lane);
126 : UNUSED_PARAMETER(minPos);
127 : UNUSED_PARAMETER(minRight);
128 : UNUSED_PARAMETER(maxLeft);
129 : UNUSED_PARAMETER(stopTime);
130 : UNUSED_PARAMETER(bidi);
131 0 : return PersonDist(nullptr, -1);
132 : }
133 :
134 : /// @brief whether movements on intersections are modelled
135 : virtual bool usingInternalLanes() = 0;
136 :
137 : /// @brief whether travel times and distances can reliably be calculated from the network alone
138 54483 : virtual bool usingShortcuts() {
139 54483 : return false;
140 : }
141 :
142 : /// @brief return the number of active objects
143 : virtual int getActiveNumber() = 0;
144 :
145 : /* @brief return the arrival direction if the route may be traversed with the given starting direction.
146 : * param[out] passedEdges: the number of edges that were successfully traversed
147 : * returns UNDEFINED_DIRECTION if the route cannot be traversed
148 : */
149 : static int canTraverse(int dir, const ConstMSEdgeVector& route, int& passedEdges);
150 : };
151 :
152 :
153 : /// @brief abstract base class for managing callbacks to retrieve various state information from the model
154 : class MSTransportableStateAdapter {
155 : public:
156 : virtual ~MSTransportableStateAdapter() {};
157 :
158 : /// @brief return the offset from the start of the current edge measured in its natural direction
159 : virtual double getEdgePos(SUMOTime now = 0) const = 0;
160 :
161 : /// @brief return the walking direction (FORWARD, BACKWARD, UNDEFINED_DIRECTION)
162 : virtual int getDirection() const = 0;
163 :
164 : /// @brief return the network coordinate of the transportable
165 : virtual Position getPosition(const MSStageMoving& stage, SUMOTime now) const = 0;
166 :
167 : /// @brief return the direction in which the transportable faces in degrees
168 : virtual double getAngle(const MSStageMoving& stage, SUMOTime now) const = 0;
169 :
170 : /// @brief return the time the transportable spent standing
171 : virtual SUMOTime getWaitingTime() const = 0;
172 :
173 : /// @brief return the current speed of the transportable
174 : virtual double getSpeed(const MSStageMoving& stage) const = 0;
175 :
176 : /// @brief return the list of internal edges if the transportable is on an intersection
177 : virtual const MSEdge* getNextEdge(const MSStageMoving& stage) const = 0;
178 :
179 : /// @brief try to move transportable to the given position
180 0 : virtual void moveTo(MSPerson* p, MSLane* lane, double lanePos, double lanePosLat, SUMOTime t) {
181 : UNUSED_PARAMETER(p);
182 : UNUSED_PARAMETER(lane);
183 : UNUSED_PARAMETER(lanePos);
184 : UNUSED_PARAMETER(lanePosLat);
185 : UNUSED_PARAMETER(t);
186 0 : WRITE_WARNING(TL("moveTo is ignored by the current movement model"));
187 0 : }
188 :
189 : /// @brief try to move transportable to the given position
190 0 : virtual void moveToXY(MSPerson* p, Position pos, MSLane* lane, double lanePos,
191 : double lanePosLat, double angle, int routeOffset,
192 : const ConstMSEdgeVector& edges, SUMOTime t) {
193 : UNUSED_PARAMETER(p);
194 : UNUSED_PARAMETER(pos);
195 : UNUSED_PARAMETER(lane);
196 : UNUSED_PARAMETER(lanePos);
197 : UNUSED_PARAMETER(lanePosLat);
198 : UNUSED_PARAMETER(angle);
199 : UNUSED_PARAMETER(routeOffset);
200 : UNUSED_PARAMETER(edges);
201 : UNUSED_PARAMETER(t);
202 0 : WRITE_WARNING(TL("moveToXY is ignored by the current movement model"));
203 0 : }
204 :
205 : /// @brief whether the transportable is jammed
206 0 : virtual bool isJammed() const {
207 0 : return false;
208 : }
209 :
210 : /// @brief whether the transportable has finished walking
211 398055 : virtual bool isFinished() const {
212 398055 : return true;
213 : }
214 :
215 : /// @brief the current lane of the transportable
216 78012 : virtual const MSLane* getLane() const {
217 78012 : return nullptr;
218 : }
219 :
220 : /// @brief return the total length of the current lane (in particular for on a walkingarea)
221 0 : virtual double getPathLength() const {
222 0 : return 0;
223 : }
224 :
225 : /** @brief Saves the current state into the given stream
226 : */
227 0 : virtual void saveState(std::ostringstream& out) {
228 : UNUSED_PARAMETER(out);
229 0 : }
230 :
231 : };
|