Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2015-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 MSParkingArea.h
15 : /// @author Mirco Sturari
16 : /// @author Mirko Barthauer
17 : /// @date Tue, 19.01.2016
18 : ///
19 : // A area where vehicles can park next to the road
20 : /****************************************************************************/
21 : #pragma once
22 : #include <config.h>
23 :
24 : #include <vector>
25 : #include <algorithm>
26 : #include <map>
27 : #include <string>
28 : #include <utils/geom/PositionVector.h>
29 : #include <utils/common/Named.h>
30 : #include <utils/vehicle/SUMOVehicleParameter.h>
31 : #include "MSStoppingPlace.h"
32 :
33 :
34 : // ===========================================================================
35 : // class declarations
36 : // ===========================================================================
37 : class MSLane;
38 : class SUMOVehicle;
39 : class MSTransportable;
40 : class MSBaseVehicle;
41 : class Position;
42 : class Command;
43 :
44 :
45 : // ===========================================================================
46 : // class definitions
47 : // ===========================================================================
48 : /**
49 : * @class MSParkingArea
50 : * @brief A lane area vehicles can halt at
51 : *
52 : * The stop tracks the last free space a vehicle may halt at by being
53 : * informed about a vehicle's entering and depart. It keeps the information
54 : * about entered vehicles' begin and end position within an internal
55 : * container ("myEndPositions") and is so able to compute the last free space.
56 : *
57 : * Please note that using the last free space disallows vehicles to enter a
58 : * free space in between other vehicles.
59 : */
60 : class MSParkingArea : public MSStoppingPlace {
61 : public:
62 :
63 : /** @brief Constructor
64 : *
65 : * @param[in] id The id of the stop
66 : * @param[in] net The net the stop belongs to
67 : * @param[in] lines Names of the lines that halt on this stop
68 : * @param[in] badges Names which grant access to this parking area
69 : * @param[in] lane The lane the stop is placed on
70 : * @param[in] begPos Begin position of the stop on the lane
71 : * @param[in] endPos End position of the stop on the lane
72 : * @param[in] capacity Capacity of the stop
73 : * @param[in] width Width of the default lot rectangle
74 : * @param[in] length Length of the default lot rectangle
75 : * @param[in] angle Angle of the default lot rectangle
76 : */
77 : MSParkingArea(const std::string& id,
78 : const std::vector<std::string>& lines,
79 : const std::vector<std::string>& badges, MSLane& lane,
80 : double begPos, double endPos, int capacity,
81 : double width, double length, double angle, const std::string& name,
82 : bool onRoad,
83 : const std::string& departPos,
84 : bool lefthand);
85 :
86 : /// @brief Destructor
87 : virtual ~MSParkingArea();
88 :
89 : /// @brief needed for patching its capacity
90 : friend class NLTriggerBuilder;
91 :
92 : /// @brief Returns the area capacity
93 : int getCapacity() const;
94 :
95 : /// @brief whether vehicles park on the road
96 : bool parkOnRoad() const;
97 :
98 : /// @brief compute lot for this vehicle
99 : int getLotIndex(const SUMOVehicle* veh) const;
100 :
101 : /** @brief Returns the area occupancy
102 : *
103 : * @return The occupancy computed as number of vehicles in myEndPositions
104 : * (reduced by 1 if at least one vehicle has finished parking but is blocked
105 : * from entering the road)
106 : */
107 : int getOccupancy() const;
108 :
109 : /// @brief Returns the area occupancy
110 : int getOccupancyIncludingBlocked() const;
111 :
112 : /// @brief Returns the area occupancy at the end of the last simulation step
113 : int getLastStepOccupancy() const;
114 :
115 : /// @brief Add a badge to the accepted set
116 : void accept(std::string badge);
117 :
118 : /// @brief Add badges to the accepted set
119 : void accept(std::vector<std::string> badges);
120 :
121 : /// @brief Remove the access right for the given badge
122 : void refuse(std::string badge);
123 :
124 : /// @brief Return the parking accepts the vehicle (due to its given badges)
125 : bool accepts(MSBaseVehicle* veh) 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 parking area
134 : * @see computeLastFreePos
135 : */
136 : void enter(SUMOVehicle* veh);
137 :
138 : /** @brief Called if a vehicle leaves this stop
139 : *
140 : * Removes the position of the vehicle from myEndPositions.
141 : *
142 : * Recomputes the free space using "computeLastFreePos" then.
143 : *
144 : * @param[in] what The vehicle that leaves the parking area
145 : * @see computeLastFreePos
146 : */
147 : void leaveFrom(SUMOVehicle* what);
148 :
149 : /** @brief Called at the end of the time step
150 : *
151 : * Stores the current occupancy.
152 : *
153 : * @param[in] currentTime The current simulation time (unused)
154 : * @return Always 0 (the event is not rescheduled)
155 : */
156 : SUMOTime updateOccupancy(SUMOTime currentTime);
157 :
158 : /// @brief Returns the last free position on this stop
159 : double getLastFreePos(const SUMOVehicle& forVehicle, double brakePos = 0) const;
160 :
161 : /** @brief Returns the last free position on this stop including
162 : * reservations from the current lane and time step
163 : *
164 : * @return The last free position of this bus stop
165 : */
166 : double getLastFreePosWithReservation(SUMOTime t, const SUMOVehicle& forVehicle, double brakePos);
167 :
168 : /// @brief Returns the position of parked vehicle
169 : Position getVehiclePosition(const SUMOVehicle& forVehicle) const;
170 :
171 : /// @brief Returns the insertion position of a parked vehicle
172 : double getInsertionPosition(const SUMOVehicle& forVehicle) const;
173 :
174 : /// @brief Returns the angle of parked vehicle
175 : double getVehicleAngle(const SUMOVehicle& forVehicle) const;
176 :
177 : /// @brief Returns the slope of parked vehicle
178 : double getVehicleSlope(const SUMOVehicle& forVehicle) const;
179 :
180 : /** @brief Return the angle of myLastFreeLot - the next parking lot
181 : * only expected to be called after we have established there is space in the parking area
182 : *
183 : * @return The angle of the lot in degrees
184 : */
185 : int getLastFreeLotAngle() const;
186 :
187 : /** @brief Return the GUI angle of myLastFreeLot - the angle the GUI uses to rotate into the next parking lot
188 : * as above, only expected to be called after we have established there is space in the parking area
189 : *
190 : * @return The GUI angle, relative to the lane, in radians
191 : */
192 : double getLastFreeLotGUIAngle() const;
193 :
194 : /// @brief Return the manoeuver angle of the lot where the vehicle is parked
195 : int getManoeuverAngle(const SUMOVehicle& forVehicle) const;
196 :
197 : /// @brief Return the GUI angle of the lot where the vehicle is parked
198 : double getGUIAngle(const SUMOVehicle& forVehicle) const;
199 :
200 : /** @brief Add a lot entry to parking area
201 : *
202 : * @param[in] x X position of the lot center
203 : * @param[in] y Y position of the lot center
204 : * @param[in] z Z position of the lot center
205 : * @param[in] width Width of the lot rectangle
206 : * @param[in] length Length of the lot rectangle
207 : * @param[in] angle Angle of the lot rectangle
208 : * @param[in] slope Slope of the lot rectangle
209 : * @return Whether the lot entry could be added
210 : */
211 : virtual void addLotEntry(double x, double y, double z,
212 : double width, double length,
213 : double angle, double slope);
214 :
215 : /// @brief Returns the lot rectangle width
216 : double getWidth() const;
217 :
218 : /// @brief Returns the lot rectangle length
219 : double getLength() const;
220 :
221 : /// @brief Returns the lot rectangle angle
222 : double getAngle() const;
223 :
224 : /// @brief update state so that vehicles wishing to enter cooperate with exiting vehicles
225 : void notifyEgressBlocked();
226 :
227 : /// @brief get number alternatives
228 : int getNumAlternatives() const;
229 :
230 : /// @brief set number alternatives
231 : void setNumAlternatives(int alternatives);
232 :
233 : /// @brief get the accepted badges
234 : std::vector<std::string> getAcceptedBadges() const;
235 :
236 : /// @brief set the accepted badges
237 : void setAcceptedBadges(const std::vector<std::string>& badges);
238 :
239 :
240 : protected:
241 : /// @brief overwrite the capacity (caution: will delete ANY previous parking space definitions)
242 : void setRoadsideCapacity(int capactity);
243 :
244 : protected:
245 : /** @struct LotSpaceDefinition
246 : * @brief Representation of a single lot space
247 : */
248 54559 : struct LotSpaceDefinition {
249 : /// @brief default constructor
250 : LotSpaceDefinition();
251 :
252 : /// @brief parameter constructor
253 : LotSpaceDefinition(int index, SUMOVehicle* vehicle, double x, double y, double z, double rotation, double slope, double width, double length);
254 :
255 : /// @brief the running index
256 : const int index;
257 :
258 : /// @brief The last parked vehicle or 0
259 : const SUMOVehicle* vehicle;
260 :
261 : /// @brief The position of the vehicle when parking in this space
262 : const Position position;
263 :
264 : /// @brief The rotation
265 : const double rotation;
266 :
267 : /// @brief The slope
268 : const double slope;
269 :
270 : /// @brief The width
271 : const double width;
272 :
273 : /// @brief The length
274 : const double length;
275 :
276 : /// @brief The position along the lane that the vehicle needs to reach for entering this lot
277 : double endPos;
278 :
279 : ///@brief The angle between lane and lot through which a vehicle must manoeuver to enter the lot
280 : double manoeuverAngle;
281 :
282 : ///@brief Whether the lot is on the LHS of the lane relative to the lane direction
283 : bool sideIsLHS;
284 : };
285 :
286 : /** @brief Computes the last free position on this stop
287 : *
288 : * The last free position is the one, the last vehicle ends at.
289 : * It is stored in myLastFreePos. If no vehicle halts, the last free
290 : * position gets the value of myEndPos.
291 : */
292 : void computeLastFreePos();
293 :
294 : /// @brief Last free lot number (-1 no free lot)
295 : int myLastFreeLot;
296 :
297 : /// @brief Stop area capacity configured via roadsideCapacity
298 : int myRoadSideCapacity;
299 :
300 : /// @brief Stop area total capacity
301 : int myCapacity;
302 :
303 : /// @brief Whether vehicles stay on the road
304 : bool myOnRoad;
305 :
306 : /// @brief The default width of each parking space
307 : double myWidth;
308 :
309 : /// @brief The default length of each parking space
310 : double myLength;
311 :
312 : /// @brief The default angle of each parking space
313 : double myAngle;
314 :
315 : /// @brief All the spaces in this parking area
316 : std::vector<LotSpaceDefinition> mySpaceOccupancies;
317 :
318 : /// @brief The roadside shape of this parkingArea
319 : PositionVector myShape;
320 :
321 : /// @brief The parking badges to grant access
322 : std::set<std::string> myAcceptedBadges;
323 :
324 : /// @brief whether a vehicle wants to exit but is blocked
325 : bool myEgressBlocked;
326 :
327 : /// @brief track parking reservations from the lane for the current time step
328 : SUMOTime myReservationTime;
329 :
330 : /// @brief number of reservations
331 : int myReservations;
332 :
333 : /// @brief reservation max length
334 : double myReservationMaxLength;
335 :
336 : /// @brief the number of alternative parkingAreas that are assigned to parkingAreaRerouter
337 : int myNumAlternatives;
338 :
339 : /// @brief Changes to the occupancy in the current time step
340 : int myLastStepOccupancy;
341 :
342 : /// @brief custom departPos
343 : double myDepartPos;
344 : DepartPosDefinition myDepartPosDefinition;
345 :
346 : /// @brief Event for updating the occupancy
347 : Command* myUpdateEvent;
348 :
349 : private:
350 : /// @brief Invalidated copy constructor.
351 : MSParkingArea(const MSParkingArea&) = delete;
352 :
353 : /// @brief Invalidated assignment operator.
354 : MSParkingArea& operator=(const MSParkingArea&) = delete;
355 : };
|