Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2005-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 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 :
93 :
94 :
95 : /// @brief Destructor
96 : virtual ~MSStoppingPlace();
97 :
98 :
99 : /** @brief Returns the lane this stop is located at
100 : *
101 : * @return Reference to the lane the stop is located at
102 : */
103 : const MSLane& getLane() const;
104 :
105 :
106 : /** @brief Returns the begin position of this stop
107 : *
108 : * @return The position the stop begins at
109 : */
110 : double getBeginLanePosition() const;
111 :
112 :
113 : /** @brief Returns the end position of this stop
114 : *
115 : * @return The position the stop ends at
116 : */
117 : double getEndLanePosition() const;
118 :
119 : /// @brief the position in the middle of the stop shape
120 : Position getCenterPos() const;
121 :
122 : /** @brief Called if a vehicle enters this stop
123 : *
124 : * Stores the position of the entering vehicle in myEndPositions.
125 : *
126 : * Recomputes the free space using "computeLastFreePos" then.
127 : *
128 : * @param[in] what The vehicle that enters the bus stop
129 : * @param[in] beg The begin halting position of the vehicle
130 : * @param[in] what The end halting position of the vehicle
131 : * @see computeLastFreePos
132 : */
133 : void enter(SUMOVehicle* veh, bool parking);
134 :
135 :
136 : /** @brief Called if a vehicle leaves this stop
137 : *
138 : * Removes the position of the vehicle from myEndPositions.
139 : *
140 : * Recomputes the free space using "computeLastFreePos" then.
141 : *
142 : * @param[in] what The vehicle that leaves the bus stop
143 : * @see computeLastFreePos
144 : */
145 : void leaveFrom(SUMOVehicle* what);
146 :
147 :
148 : /** @brief Returns the last free position on this stop
149 : *
150 : * @param[in] forVehicle The vehicle that wants to stop here
151 : * @param[in] brakePos the first position on the stop lane that the vehicle can stop at
152 : * @return The last free position of this bus stop
153 : */
154 : double getLastFreePos(const SUMOVehicle& forVehicle, double brakePos = 0) const;
155 :
156 : /// @brief return whether the given vehicle fits at the given position
157 : bool fits(double pos, const SUMOVehicle& veh) const;
158 :
159 : /** @brief Returns the next free waiting place for pedestrians / containers
160 : *
161 : * @return The next free waiting place for pedestrians / containers
162 : */
163 : Position getWaitPosition(MSTransportable* person) const;
164 :
165 : /** @brief Returns the lane position corresponding to getWaitPosition()
166 : *
167 : * @return The waiting position along the stop lane
168 : */
169 : double getWaitingPositionOnLane(MSTransportable* t) const;
170 :
171 :
172 : /** @brief For vehicles at the stop this gives the actual stopping
173 : * position of the vehicle. For all others the last free stopping position
174 : *
175 : */
176 : double getStoppingPosition(const SUMOVehicle* veh) const;
177 :
178 : /** @brief Returns the number of transportables waiting on this stop
179 : */
180 0 : int getTransportableNumber() const {
181 6 : return (int)myWaitingTransportables.size();
182 : }
183 :
184 : /** @brief Returns the transportables waiting on this stop
185 : */
186 : std::vector<const MSTransportable*> getTransportables() const;
187 :
188 : /** @brief Returns the number of stopped vehicles waiting on this stop
189 : */
190 0 : int getStoppedVehicleNumber() const {
191 1385963 : return (int)myEndPositions.size();
192 : }
193 :
194 0 : double getLastFreePos() const {
195 832 : return myLastFreePos;
196 : }
197 :
198 : /// @brief whether there is still capacity for more transportables
199 : bool hasSpaceForTransportable() const;
200 :
201 : /// @brief adds a transportable to this stop
202 : bool addTransportable(const MSTransportable* p);
203 :
204 : /// @brief Removes a transportable from this stop
205 : void removeTransportable(const MSTransportable* p);
206 :
207 : /// @brief adds an access point to this stop
208 : virtual bool addAccess(MSLane* const lane, const double startPos, const double endPos, double length, const MSStoppingPlace::AccessExit exit);
209 :
210 : /// @brief lanes and positions connected to this stop
211 : const std::vector<Access>& getAllAccessPos() const {
212 : return myAccessPos;
213 : }
214 :
215 : /// @brief the position on the given edge which is connected to this stop, -1 on failure
216 : double getAccessPos(const MSEdge* edge, SumoRNG* rng = nullptr) const;
217 :
218 : /// @brief the access on the given edge to the stop, nullptr if there is none
219 : const Access* getAccess(const MSEdge* edge) const;
220 :
221 : const std::string& getMyName() const;
222 :
223 : /// @brief return the type of this stopping place
224 : SumoXMLTag getElement() const {
225 1264 : return myElement;
226 : }
227 :
228 : const RGBColor& getColor() const;
229 :
230 : static int getTransportablesAbreast(double length, SumoXMLTag element);
231 :
232 : /// @brief get list of vehicles waiting at this stop
233 : std::vector<const SUMOVehicle*> getStoppedVehicles() const;
234 :
235 : /// @brief get number of persons waiting at this stop
236 : inline int getNumWaitingPersons() const {
237 1535235 : return (int)myWaitingTransportables.size();
238 : }
239 :
240 : /// @brief get number of persons that can wait at this stop
241 : inline int getWaitingCapacity() const {
242 1535134 : return myTransportableCapacity;
243 : }
244 :
245 : /// @brief get IDs of persons waiting at this stop
246 : void getWaitingPersonIDs(std::vector<std::string>& into) const;
247 :
248 : /** @brief Remove all vehicles before quick-loading state */
249 : void clearState();
250 :
251 : protected:
252 : /** @brief Computes the last free position on this stop
253 : *
254 : * The last free position is the one, the last vehicle ends at.
255 : * It is stored in myLastFreePos. If no vehicle halts, the last free
256 : * position gets the value of myEndPos.
257 : */
258 : void computeLastFreePos();
259 :
260 : int getTransportablesAbreast() const;
261 :
262 : protected:
263 : /// @brief the type of stopping place
264 : const SumoXMLTag myElement;
265 :
266 : /// @brief The list of lines that are assigned to this stop
267 : std::vector<std::string> myLines;
268 :
269 : /// @brief A map from objects (vehicles) to the areas they acquire after entering the stop
270 : std::map<const SUMOVehicle*, std::pair<double, double>, ComparatorNumericalIdLess> myEndPositions;
271 :
272 : /// @brief The lane this bus stop is located at
273 : const MSLane& myLane;
274 :
275 : /// @brief The begin position this bus stop is located at
276 : const double myBegPos;
277 :
278 : /// @brief The end position this bus stop is located at
279 : const double myEndPos;
280 :
281 : /// @brief The last free position at this stop (variable)
282 : double myLastFreePos;
283 : /// @brief The length of the last parking vehicle (or 0 if there is none)
284 : const SUMOVehicle* myLastParking;
285 :
286 : /// @brief The name of the stopping place
287 : const std::string myName;
288 :
289 : /// @brief The number of transportables that can wait here
290 : const int myTransportableCapacity;
291 :
292 : /// @brief the scaled space capacity for parking vehicles
293 : const double myParkingFactor;
294 :
295 : /// @brief The color of the stopping place
296 : const RGBColor myColor;
297 :
298 : /// @brief row depth of waiting transportables
299 : const double myTransportableDepth;
300 :
301 : /// @brief Persons waiting at this stop (mapped to waiting position)
302 : std::map<const MSTransportable*, int> myWaitingTransportables;
303 : std::set<int> myWaitingSpots;
304 :
305 : /// @brief lanes and positions connected to this stop
306 : std::vector<Access> myAccessPos;
307 :
308 : private:
309 : /// @brief Invalidated copy constructor.
310 : MSStoppingPlace(const MSStoppingPlace&);
311 :
312 : /// @brief Invalidated assignment operator.
313 : MSStoppingPlace& operator=(const MSStoppingPlace&);
314 :
315 :
316 : };
|