Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2005-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 MSStoppingPlace.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Michael Behrisch
17 : /// @author Johannes Rummel
18 : /// @date Mon, 13.12.2005
19 : ///
20 : // A lane area vehicles can halt at
21 : /****************************************************************************/
22 : #pragma once
23 : #include <config.h>
24 :
25 : #include <vector>
26 : #include <algorithm>
27 : #include <map>
28 : #include <string>
29 : #include <utils/common/Named.h>
30 : #include <utils/common/Parameterised.h>
31 : #include <utils/common/RGBColor.h>
32 :
33 :
34 : // ===========================================================================
35 : // class declarations
36 : // ===========================================================================
37 : class MSLane;
38 : class MSEdge;
39 : class SUMOVehicle;
40 : class MSTransportable;
41 : class Position;
42 :
43 :
44 : // ===========================================================================
45 : // class definitions
46 : // ===========================================================================
47 : /**
48 : * @class MSStoppingPlace
49 : * @brief A lane area vehicles can halt at
50 : *
51 : * The stop tracks the last free space a vehicle may halt at by being
52 : * informed about a vehicle's entering and depart. It keeps the information
53 : * about entered vehicles' begin and end position within an internal
54 : * container ("myEndPositions") and is so able to compute the last free space.
55 : *
56 : * Please note that using the last free space disallows vehicles to enter a
57 : * free space in between other vehicles.
58 : */
59 : class MSStoppingPlace : public Named, public Parameterised {
60 : public:
61 : enum class AccessExit {
62 : PLATFORM,
63 : DOORS,
64 : CARRIAGE
65 : };
66 :
67 : struct Access {
68 : MSLane* const lane;
69 : const double startPos;
70 : const double endPos;
71 : const double length;
72 : const AccessExit exit;
73 : };
74 :
75 : /** @brief Constructor
76 : *
77 : * @param[in] id The id of the stop
78 : * @param[in] net The net the stop belongs to
79 : * @param[in] lines Names of the lines that halt on this stop
80 : * @param[in] lane The lane the stop is placed on
81 : * @param[in] begPos Begin position of the stop on the lane
82 : * @param[in] endPos End position of the stop on the lane
83 : */
84 : MSStoppingPlace(const std::string& id,
85 : SumoXMLTag element,
86 : const std::vector<std::string>& lines, MSLane& lane,
87 : double begPos, double endPos,
88 : const std::string name = "",
89 : int capacity = 0,
90 : double parkingLength = 0,
91 : const RGBColor& color = RGBColor::INVISIBLE,
92 : double angle = 90);
93 :
94 :
95 :
96 : /// @brief Destructor
97 : virtual ~MSStoppingPlace();
98 :
99 :
100 : /** @brief Returns the lane this stop is located at
101 : *
102 : * @return Reference to the lane the stop is located at
103 : */
104 : const MSLane& getLane() const;
105 :
106 :
107 : /** @brief Returns the begin position of this stop
108 : *
109 : * @return The position the stop begins at
110 : */
111 : double getBeginLanePosition() const;
112 :
113 :
114 : /** @brief Returns the end position of this stop
115 : *
116 : * @return The position the stop ends at
117 : */
118 : double getEndLanePosition() const;
119 :
120 : double getAngle() const {
121 144624 : return myAngle;
122 : }
123 :
124 : /// @brief the position in the middle of the stop shape
125 : Position getCenterPos() const;
126 :
127 : /** @brief Called if a vehicle enters this stop
128 : *
129 : * Stores the position of the entering vehicle in myEndPositions.
130 : *
131 : * Recomputes the free space using "computeLastFreePos" then.
132 : *
133 : * @param[in] what The vehicle that enters the bus stop
134 : * @param[in] beg The begin halting position of the vehicle
135 : * @param[in] what The end halting position of the vehicle
136 : * @see computeLastFreePos
137 : */
138 : void enter(SUMOVehicle* veh, bool parking);
139 :
140 :
141 : /** @brief Called if a vehicle leaves this stop
142 : *
143 : * Removes the position of the vehicle from myEndPositions.
144 : *
145 : * Recomputes the free space using "computeLastFreePos" then.
146 : *
147 : * @param[in] what The vehicle that leaves the bus stop
148 : * @see computeLastFreePos
149 : */
150 : void leaveFrom(SUMOVehicle* what);
151 :
152 :
153 : /** @brief Returns the last free position on this stop
154 : *
155 : * @param[in] forVehicle The vehicle that wants to stop here
156 : * @param[in] brakePos the first position on the stop lane that the vehicle can stop at
157 : * @return The last free position of this bus stop
158 : */
159 : virtual double getLastFreePos(const SUMOVehicle& forVehicle, double brakePos = 0) const;
160 :
161 0 : virtual bool accepts(SUMOVehicle* /*veh*/) const {
162 0 : return true;
163 : }
164 :
165 : /// @brief return whether the given vehicle fits at the given position
166 : bool fits(double pos, const SUMOVehicle& veh) const;
167 :
168 : /** @brief Returns the next free waiting place for pedestrians / containers
169 : *
170 : * @return The next free waiting place for pedestrians / containers
171 : */
172 : Position getWaitPosition(MSTransportable* person) const;
173 :
174 : /** @brief Returns the lane position corresponding to getWaitPosition()
175 : *
176 : * @return The waiting position along the stop lane
177 : */
178 : double getWaitingPositionOnLane(MSTransportable* t) const;
179 :
180 :
181 : /** @brief For vehicles at the stop this gives the actual stopping
182 : * position of the vehicle. For all others the last free stopping position
183 : *
184 : */
185 : double getStoppingPosition(const SUMOVehicle* veh) const;
186 :
187 : /** @brief Returns the number of transportables waiting on this stop
188 : */
189 0 : int getTransportableNumber() const {
190 6 : return (int)myWaitingTransportables.size();
191 : }
192 :
193 : /** @brief Returns the transportables waiting on this stop
194 : */
195 : std::vector<const MSTransportable*> getTransportables() const;
196 :
197 : /** @brief Returns the number of stopped vehicles waiting on this stop
198 : */
199 0 : int getStoppedVehicleNumber() const {
200 3759643 : return (int)myEndPositions.size();
201 : }
202 :
203 0 : double getLastFreePos() const {
204 1221 : return myLastFreePos;
205 : }
206 :
207 : /// @brief whether there is still capacity for more transportables
208 : bool hasSpaceForTransportable() const;
209 :
210 : /// @brief adds a transportable to this stop
211 : bool addTransportable(const MSTransportable* p);
212 :
213 : /// @brief Removes a transportable from this stop
214 : void removeTransportable(const MSTransportable* p);
215 :
216 : /// @brief adds an access point to this stop
217 : virtual bool addAccess(MSLane* const lane, const double startPos, const double endPos, double length, const MSStoppingPlace::AccessExit exit);
218 :
219 : /// @brief lanes and positions connected to this stop
220 : const std::vector<Access>& getAllAccessPos() const {
221 : return myAccessPos;
222 : }
223 :
224 : /// @brief the position on the given edge which is connected to this stop, -1 on failure
225 : double getAccessPos(const MSEdge* edge, SumoRNG* rng = nullptr) const;
226 :
227 : /// @brief the access on the given edge to the stop, nullptr if there is none
228 : const Access* getAccess(const MSEdge* edge) const;
229 :
230 : const std::string& getMyName() const;
231 :
232 : /// @brief return the type of this stopping place
233 : SumoXMLTag getElement() const {
234 442756 : return myElement;
235 : }
236 :
237 : const RGBColor& getColor() const;
238 :
239 : static int getDefaultTransportablesAbreast(double length, SumoXMLTag element);
240 :
241 : /// @brief get list of vehicles waiting at this stop
242 : std::vector<const SUMOVehicle*> getStoppedVehicles() const;
243 :
244 : /// @brief get number of persons waiting at this stop
245 : inline int getNumWaitingPersons() const {
246 1547293 : return (int)myWaitingTransportables.size();
247 : }
248 :
249 : /// @brief get number of persons that can wait at this stop
250 : inline int getWaitingCapacity() const {
251 1547184 : return myTransportableCapacity;
252 : }
253 :
254 : inline double getParkingLength() const {
255 46431 : return (myEndPos - myBegPos) / myParkingFactor;
256 : }
257 :
258 : /// @brief get IDs of persons waiting at this stop
259 : void getWaitingPersonIDs(std::vector<std::string>& into) const;
260 :
261 : bool checkPersonCapacity() const {
262 118560 : return myElement == SUMO_TAG_BUS_STOP || myElement == SUMO_TAG_TRAIN_STOP;;
263 : }
264 :
265 : /// @brief perform extra processing after element has been loaded
266 : virtual void finishedLoading();
267 :
268 : /** @brief Remove all vehicles before quick-loading state */
269 : void clearState();
270 :
271 : protected:
272 : /** @brief Computes the last free position on this stop
273 : *
274 : * The last free position is the one, the last vehicle ends at.
275 : * It is stored in myLastFreePos. If no vehicle halts, the last free
276 : * position gets the value of myEndPos.
277 : */
278 : void computeLastFreePos();
279 :
280 : int getTransportablesAbreast() const;
281 :
282 : static double getDefaultTransportableWidth(SumoXMLTag element);
283 :
284 : protected:
285 : /// @brief the type of stopping place
286 : const SumoXMLTag myElement;
287 :
288 : /// @brief The list of lines that are assigned to this stop
289 : std::vector<std::string> myLines;
290 :
291 : /// @brief A map from objects (vehicles) to the areas they acquire after entering the stop
292 : std::map<const SUMOVehicle*, std::pair<double, double>, ComparatorNumericalIdLess> myEndPositions;
293 :
294 : /// @brief The lane this bus stop is located at
295 : const MSLane& myLane;
296 :
297 : /// @brief The begin position this bus stop is located at
298 : const double myBegPos;
299 :
300 : /// @brief The end position this bus stop is located at
301 : const double myEndPos;
302 :
303 : /// @brief The last free position at this stop (variable)
304 : double myLastFreePos;
305 : /// @brief The length of the last parking vehicle (or 0 if there is none)
306 : const SUMOVehicle* myLastParking;
307 :
308 : /// @brief The name of the stopping place
309 : const std::string myName;
310 :
311 : /// @brief The number of transportables that can wait here
312 : const int myTransportableCapacity;
313 :
314 : /// @brief the scaled space capacity for parking vehicles
315 : const double myParkingFactor;
316 :
317 : /// @brief The color of the stopping place
318 : const RGBColor myColor;
319 :
320 : /// @brief The angle offset for waiting transportables
321 : double myAngle;
322 :
323 : /// @brief row depth of waiting transportables
324 : double myTransportableDepth;
325 : /// @brief the with of waiting transportables
326 : double myTransportableWidth;
327 :
328 : /// @brief Persons waiting at this stop (mapped to waiting position)
329 : std::map<const MSTransportable*, int> myWaitingTransportables;
330 : std::set<int> myWaitingSpots;
331 :
332 : /// @brief lanes and positions connected to this stop
333 : std::vector<Access> myAccessPos;
334 :
335 : private:
336 : /// @brief Invalidated copy constructor.
337 : MSStoppingPlace(const MSStoppingPlace&);
338 :
339 : /// @brief Invalidated assignment operator.
340 : MSStoppingPlace& operator=(const MSStoppingPlace&);
341 :
342 :
343 : };
|