1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2005-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    MSStoppingPlace.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Michael Behrisch
13 /// @date    Mon, 13.12.2005
14 /// @version $Id$
15 ///
16 // A lane area vehicles can halt at
17 /****************************************************************************/
18 #ifndef MSStoppingPlace_h
19 #define MSStoppingPlace_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <vector>
28 #include <algorithm>
29 #include <map>
30 #include <string>
31 #include <utils/common/Named.h>
32 #include <utils/common/Parameterised.h>
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class MSLane;
39 class MSEdge;
40 class SUMOVehicle;
41 class MSTransportable;
42 class Position;
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
48 /**
49  * @class MSStoppingPlace
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 MSStoppingPlace : public Named, public Parameterised {
61 public:
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      */
71     MSStoppingPlace(const std::string& id,
72                     const std::vector<std::string>& lines, MSLane& lane,
73                     double begPos, double endPos, const std::string name = "",
74                     int capacity = 0);
75 
76 
77 
78     /// @brief Destructor
79     virtual ~MSStoppingPlace();
80 
81 
82     /** @brief Returns the lane this stop is located at
83      *
84      * @return Reference to the lane the stop is located at
85      */
86     const MSLane& getLane() const;
87 
88 
89     /** @brief Returns the begin position of this stop
90      *
91      * @return The position the stop begins at
92      */
93     double getBeginLanePosition() const;
94 
95 
96     /** @brief Returns the end position of this stop
97      *
98      * @return The position the stop ends at
99      */
100     double getEndLanePosition() const;
101 
102 
103     /** @brief Called if a vehicle enters this stop
104      *
105      * Stores the position of the entering vehicle in myEndPositions.
106      *
107      * Recomputes the free space using "computeLastFreePos" then.
108      *
109      * @param[in] what The vehicle that enters the bus stop
110      * @param[in] beg The begin halting position of the vehicle
111      * @param[in] what The end halting position of the vehicle
112      * @see computeLastFreePos
113      */
114     void enter(SUMOVehicle* what, double beg, double end);
115 
116 
117     /** @brief Called if a vehicle leaves this stop
118      *
119      * Removes the position of the vehicle from myEndPositions.
120      *
121      * Recomputes the free space using "computeLastFreePos" then.
122      *
123      * @param[in] what The vehicle that leaves the bus stop
124      * @see computeLastFreePos
125      */
126     void leaveFrom(SUMOVehicle* what);
127 
128 
129     /** @brief Returns the last free position on this stop
130      *
131      * @return The last free position of this bus stop
132      */
133     double getLastFreePos(const SUMOVehicle& forVehicle) const;
134 
135     /// @brief return whether the given vehicle fits at the given position
136     bool fits(double pos, const SUMOVehicle& veh) const;
137 
138     /** @brief Returns the next free waiting place for pedestrians / containers
139      *
140      * @return The next free waiting place for pedestrians / containers
141      */
142     virtual Position getWaitPosition(MSTransportable* person) const;
143 
144     /** @brief Returns the lane position corresponding to getWaitPosition()
145      *
146      * @return The waiting position along the stop lane
147      */
148     double getWaitingPositionOnLane(MSTransportable* t) const;
149 
150 
151     /** @brief For vehicles at the stop this gives the the actual stopping
152      *         position of the vehicle. For all others the last free stopping position
153      *
154      */
155     double getStoppingPosition(const SUMOVehicle* veh) const;
156 
157     /** @brief Returns the number of transportables waiting on this stop
158     */
getTransportableNumber()159     int getTransportableNumber() const {
160         return (int)myWaitingTransportables.size();
161     }
162 
163     /** @brief Returns the number of stopped vehicles waiting on this stop
164     */
getStoppedVehicleNumber()165     int getStoppedVehicleNumber() const {
166         return (int)myEndPositions.size();
167     }
168 
getLastFreePos()169     double getLastFreePos() const {
170         return myLastFreePos;
171     }
172 
173     /// @brief whether there is still capacity for more transportables
174     bool hasSpaceForTransportable() const;
175 
176     /// @brief adds a transportable to this stop
177     bool addTransportable(MSTransportable* p);
178 
179     /// @brief Removes a transportable from this stop
180     void removeTransportable(MSTransportable* p);
181 
182     /// @brief adds an access point to this stop
183     virtual bool addAccess(MSLane* lane, const double pos, const double length);
184 
185     /// @brief lanes and positions connected to this stop
getAllAccessPos()186     const std::vector<std::tuple<MSLane*, double, double> >& getAllAccessPos() const {
187         return myAccessPos;
188     }
189 
190     /// @brief the position on the given edge which is connected to this stop, -1 on failure
191     double getAccessPos(const MSEdge* edge) const;
192 
193     /// @brief the distance from the access on the given edge to the stop, -1 on failure
194     double getAccessDistance(const MSEdge* edge) const;
195 
196     const std::string& getMyName() const;
197 
198     static int getPersonsAbreast(double length);
199 
200 protected:
201     /** @brief Computes the last free position on this stop
202      *
203      * The last free position is the one, the last vehicle ends at.
204      * It is stored in myLastFreePos. If no vehicle halts, the last free
205      *  position gets the value of myEndPos.
206      */
207     void computeLastFreePos();
208 
209     int getPersonsAbreast() const;
210 
211 protected:
212     /// @brief The list of lines that are assigned to this stop
213     std::vector<std::string> myLines;
214 
215     /// @brief A map from objects (vehicles) to the areas they acquire after entering the stop
216     std::map<const SUMOVehicle*, std::pair<double, double> > myEndPositions;
217 
218     /// @brief The lane this bus stop is located at
219     const MSLane& myLane;
220 
221     /// @brief The begin position this bus stop is located at
222     const double myBegPos;
223 
224     /// @brief The end position this bus stop is located at
225     const double myEndPos;
226 
227     /// @brief The last free position at this stop (variable)
228     double myLastFreePos;
229 
230     /// @brief The name of the stopping place
231     const std::string myName;
232 
233     /// @brief The number of transportables that can wait here
234     const int myTransportableCapacity;
235 
236 protected:
237 
238     /// @brief Persons waiting at this stop (mapped to waiting position)
239     std::map<MSTransportable*, int> myWaitingTransportables;
240     std::set<int> myWaitingSpots;
241 
242     /// @brief lanes and positions connected to this stop
243     std::vector<std::tuple<MSLane*, double, double> > myAccessPos;
244 
245 private:
246     /// @brief Invalidated copy constructor.
247     MSStoppingPlace(const MSStoppingPlace&);
248 
249     /// @brief Invalidated assignment operator.
250     MSStoppingPlace& operator=(const MSStoppingPlace&);
251 
252 
253 };
254 
255 
256 #endif
257 
258 /****************************************************************************/
259 
260