1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2015-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    MSParkingArea.h
11 /// @author  Mirco Sturari
12 /// @date    Tue, 19.01.2016
13 /// @version $Id$
14 ///
15 // A area where vehicles can park next to the road
16 /****************************************************************************/
17 #ifndef MSParkingArea_h
18 #define MSParkingArea_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <vector>
27 #include <algorithm>
28 #include <map>
29 #include <string>
30 #include <utils/geom/PositionVector.h>
31 #include <utils/common/Named.h>
32 #include "MSStoppingPlace.h"
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class MSLane;
39 class SUMOVehicle;
40 class MSTransportable;
41 class Position;
42 
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
47 /**
48  * @class MSParkingArea
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 MSParkingArea : public MSStoppingPlace {
60 public:
61 
62     /** @brief Constructor
63      *
64      * @param[in] id The id of the stop
65      * @param[in] net The net the stop belongs to
66      * @param[in] lines Names of the lines that halt on this stop
67      * @param[in] lane The lane the stop is placed on
68      * @param[in] begPos Begin position of the stop on the lane
69      * @param[in] endPos End position of the stop on the lane
70      * @param[in] capacity Capacity of the stop
71      * @param[in] width Width of the default lot rectangle
72      * @param[in] length Length of the default lot rectangle
73      * @param[in] angle Angle of the default lot rectangle
74      */
75     MSParkingArea(const std::string& id,
76                   const std::vector<std::string>& lines, MSLane& lane,
77                   double begPos, double endPos, int capacity,
78                   double width, double length, double angle, const std::string& name,
79                   bool onRoad);
80 
81     /// @brief Destructor
82     virtual ~MSParkingArea();
83 
84 
85     /** @brief Returns the area capacity
86      *
87      * @return The capacity
88      */
89     int getCapacity() const;
90 
91     /// @brief whether vehicles park on the road
parkOnRoad()92     bool parkOnRoad() const {
93         return myOnRoad;
94     }
95 
96 
97     /** @brief Returns the area occupancy
98      *
99      * @return The occupancy computed as number of vehicles in myEndPositions
100      */
101     int getOccupancy() const;
102 
103 
104     /** @brief Called if a vehicle enters this stop
105      *
106      * Stores the position of the entering vehicle in myEndPositions.
107      *
108      * Recomputes the free space using "computeLastFreePos" then.
109      *
110      * @param[in] what The vehicle that enters the bus stop
111      * @param[in] beg The begin halting position of the vehicle
112      * @param[in] what The end halting position of the vehicle
113      * @see computeLastFreePos
114      */
115     void enter(SUMOVehicle* what, double beg, double end);
116 
117 
118     /** @brief Called if a vehicle leaves this stop
119      *
120      * Removes the position of the vehicle from myEndPositions.
121      *
122      * Recomputes the free space using "computeLastFreePos" then.
123      *
124      * @param[in] what The vehicle that leaves the bus stop
125      * @see computeLastFreePos
126      */
127     void leaveFrom(SUMOVehicle* what);
128 
129 
130     /** @brief Returns the last free position on this stop
131      *
132      * @return The last free position of this bus stop
133      */
134     double getLastFreePos(const SUMOVehicle& forVehicle) const;
135 
136 
137     /** @brief Returns the last free position on this stop including
138      * reservatiosn from the current lane and time step
139      *
140      * @return The last free position of this bus stop
141      */
142     double getLastFreePosWithReservation(SUMOTime t, const SUMOVehicle& forVehicle);
143 
144 
145     /** @brief Returns the position of parked vehicle
146      *
147      * @return The position of parked vehicle
148      */
149     Position getVehiclePosition(const SUMOVehicle& forVehicle) const;
150 
151 
152     /** @brief Returns the angle of parked vehicle
153      *
154      * @return The angle of parked vehicle
155      */
156     double getVehicleAngle(const SUMOVehicle& forVehicle) const;
157 
158 
159     /** @brief Add a lot entry to parking area
160      *
161      * @param[in] x X position of the lot center
162      * @param[in] y Y position of the lot center
163      * @param[in] z Z position of the lot center
164      * @param[in] width Width of the lot rectangle
165      * @param[in] length Length of the lot rectangle
166      * @param[in] angle Angle of the lot rectangle
167      * @return Whether the lot entry could be added
168      */
169     virtual void addLotEntry(double x, double y, double z,
170                              double width, double length, double angle);
171 
172 
173     /** @brief Returns the lot rectangle width
174      *
175      * @return The width
176      */
177     double getWidth() const;
178 
179 
180     /** @brief Returns the lot rectangle length
181      *
182      * @return The length
183      */
184     double getLength() const;
185 
186 
187     /** @brief Returns the lot rectangle angle
188      *
189      * @return The angle
190      */
191     double getAngle() const;
192 
193 
194     /// @brief update state so that vehicles wishing to enter cooperate with exiting vehicles
195     void notifyEgressBlocked();
196 
197 protected:
198 
199     /** @struct LotSpaceDefinition
200     * @brief Representation of a single lot space
201     */
202     struct LotSpaceDefinition {
203         /// @brief the running index
204         int index;
205         /// @brief The last parked vehicle or 0
206         SUMOVehicle* vehicle;
207         /// @brief The position of the vehicle when parking in this space
208         Position myPosition;
209         /// @brief The rotation
210         double myRotation;
211         /// @brief The width
212         double myWidth;
213         /// @brief The length
214         double myLength;
215         /// @brief The position along the lane that the vehicle needs to reach for entering this lot
216         double myEndPos;
217     };
218 
219 
220     /** @brief Computes the last free position on this stop
221      *
222      * The last free position is the one, the last vehicle ends at.
223      * It is stored in myLastFreePos. If no vehicle halts, the last free
224      *  position gets the value of myEndPos.
225      */
226     void computeLastFreePos();
227 
228     /// @brief Last free lot number (-1 no free lot)
229     int myLastFreeLot;
230 
231     /// @brief Stop area capacity
232     int myCapacity;
233 
234     /// @brief Whether vehicles stay on the road
235     bool myOnRoad;
236 
237     /// @brief The default width of each parking space
238     double myWidth;
239 
240     /// @brief The default length of each parking space
241     double myLength;
242 
243     /// @brief The default angle of each parking space
244     double myAngle;
245 
246 
247     /// @brief All the spaces in this parking area
248     std::vector<LotSpaceDefinition> mySpaceOccupancies;
249 
250     /// @brief The roadside shape of this parkingArea
251     PositionVector myShape;
252 
253     /// @brief whether a vehicle wants to exit but is blocked
254     bool myEgressBlocked;
255 
256     /// @brief track parking reservations from the lane for the current time step
257     SUMOTime myReservationTime;
258     int myReservations;
259     double myReservationMaxLength;
260 
261 private:
262 
263     /// @brief Invalidated copy constructor.
264     MSParkingArea(const MSParkingArea&);
265 
266     /// @brief Invalidated assignment operator.
267     MSParkingArea& operator=(const MSParkingArea&);
268 
269 };
270 
271 
272 #endif
273 
274 /****************************************************************************/
275