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 : protected:
234 : /// @brief overwrite the capacity (caution: will delete ANY previous parking space definitions)
235 : void setRoadsideCapacity(int capactity);
236 :
237 : protected:
238 : /** @struct LotSpaceDefinition
239 : * @brief Representation of a single lot space
240 : */
241 54548 : struct LotSpaceDefinition {
242 : /// @brief default constructor
243 : LotSpaceDefinition();
244 :
245 : /// @brief parameter constructor
246 : LotSpaceDefinition(int index, SUMOVehicle* vehicle, double x, double y, double z, double rotation, double slope, double width, double length);
247 :
248 : /// @brief the running index
249 : const int index;
250 :
251 : /// @brief The last parked vehicle or 0
252 : const SUMOVehicle* vehicle;
253 :
254 : /// @brief The position of the vehicle when parking in this space
255 : const Position position;
256 :
257 : /// @brief The rotation
258 : const double rotation;
259 :
260 : /// @brief The slope
261 : const double slope;
262 :
263 : /// @brief The width
264 : const double width;
265 :
266 : /// @brief The length
267 : const double length;
268 :
269 : /// @brief The position along the lane that the vehicle needs to reach for entering this lot
270 : double endPos;
271 :
272 : ///@brief The angle between lane and lot through which a vehicle must manoeuver to enter the lot
273 : double manoeuverAngle;
274 :
275 : ///@brief Whether the lot is on the LHS of the lane relative to the lane direction
276 : bool sideIsLHS;
277 : };
278 :
279 : /** @brief Computes the last free position on this stop
280 : *
281 : * The last free position is the one, the last vehicle ends at.
282 : * It is stored in myLastFreePos. If no vehicle halts, the last free
283 : * position gets the value of myEndPos.
284 : */
285 : void computeLastFreePos();
286 :
287 : /// @brief Last free lot number (-1 no free lot)
288 : int myLastFreeLot;
289 :
290 : /// @brief Stop area capacity configured via roadsideCapacity
291 : int myRoadSideCapacity;
292 :
293 : /// @brief Stop area total capacity
294 : int myCapacity;
295 :
296 : /// @brief Whether vehicles stay on the road
297 : bool myOnRoad;
298 :
299 : /// @brief The default width of each parking space
300 : double myWidth;
301 :
302 : /// @brief The default length of each parking space
303 : double myLength;
304 :
305 : /// @brief The default angle of each parking space
306 : double myAngle;
307 :
308 : /// @brief All the spaces in this parking area
309 : std::vector<LotSpaceDefinition> mySpaceOccupancies;
310 :
311 : /// @brief The roadside shape of this parkingArea
312 : PositionVector myShape;
313 :
314 : /// @brief The parking badges to grant access
315 : std::set<std::string> myAcceptedBadges;
316 :
317 : /// @brief whether a vehicle wants to exit but is blocked
318 : bool myEgressBlocked;
319 :
320 : /// @brief track parking reservations from the lane for the current time step
321 : SUMOTime myReservationTime;
322 :
323 : /// @brief number of reservations
324 : int myReservations;
325 :
326 : /// @brief reservation max length
327 : double myReservationMaxLength;
328 :
329 : /// @brief the number of alternative parkingAreas that are assigned to parkingAreaRerouter
330 : int myNumAlternatives;
331 :
332 : /// @brief Changes to the occupancy in the current time step
333 : int myLastStepOccupancy;
334 :
335 : /// @brief custom departPos
336 : double myDepartPos;
337 : DepartPosDefinition myDepartPosDefinition;
338 :
339 : /// @brief Event for updating the occupancy
340 : Command* myUpdateEvent;
341 :
342 : private:
343 : /// @brief Invalidated copy constructor.
344 : MSParkingArea(const MSParkingArea&) = delete;
345 :
346 : /// @brief Invalidated assignment operator.
347 : MSParkingArea& operator=(const MSParkingArea&) = delete;
348 : };
|