Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-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 MSTransportableControl.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Sascha Krieg
18 : /// @author Michael Behrisch
19 : /// @date Mon, 9 Jul 2001
20 : ///
21 : // Stores all persons or containers in the net and handles their waiting for cars.
22 : /****************************************************************************/
23 : #pragma once
24 : #include <config.h>
25 :
26 : #include <vector>
27 : #include <map>
28 : #include <microsim/MSVehicle.h>
29 : #include <microsim/transportables/MSTransportable.h>
30 : #include <microsim/devices/MSDevice_Vehroutes.h>
31 :
32 :
33 : // ===========================================================================
34 : // class declarations
35 : // ===========================================================================
36 : class MSNet;
37 : class MSPModel;
38 :
39 :
40 : // ===========================================================================
41 : // class definitions
42 : // ===========================================================================
43 : /**
44 : *
45 : * @class MSTransportableControl
46 : * The class is used to handle transportables (persons and containers)
47 : * who are not using a transportation
48 : * system but are walking or waiting. This includes waiting
49 : * for the arrival or departure time / the time the waiting is over.
50 : */
51 : class MSTransportableControl {
52 : public:
53 : /// @brief Definition of a list of transportables
54 : typedef std::vector<MSTransportable*> TransportableVector;
55 :
56 : /// @brief Definition of the internal transportables map iterator
57 : typedef std::map<std::string, MSTransportable*>::const_iterator constVehIt;
58 :
59 :
60 : public:
61 : /// @brief Constructor
62 : MSTransportableControl(const bool isPerson);
63 :
64 :
65 : /// @brief Destructor
66 : virtual ~MSTransportableControl();
67 :
68 :
69 : /** @brief Adds a single transportable, returns false if an id clash occurred
70 : * @param[in] transportable The transportable to add
71 : * @return Whether the transportable could be added (none with the same id existed before)
72 : */
73 : bool add(MSTransportable* transportable);
74 :
75 :
76 : /** @brief Returns the named transportable, if existing
77 : * @param[in] id The id of the transportable
78 : * @return The named transportable, if existing, otherwise nullptr
79 : */
80 : MSTransportable* get(const std::string& id) const;
81 :
82 :
83 : /// removes a single transportable
84 : virtual void erase(MSTransportable* transportable);
85 :
86 : /// sets the arrival time for a waiting transportable
87 : void setWaitEnd(SUMOTime time, MSTransportable* transportable);
88 :
89 : /// checks whether any transportables waiting time is over
90 : void checkWaiting(MSNet* net, const SUMOTime time);
91 :
92 : /// adds a transportable to the list of transportables waiting for a vehicle on the specified edge
93 : void addWaiting(const MSEdge* edge, MSTransportable* person);
94 :
95 : /// register forced (traci) departure
96 : void forceDeparture();
97 :
98 : /// @brief check whether any transportables are waiting for the given vehicle
99 : bool hasAnyWaiting(const MSEdge* edge, SUMOVehicle* vehicle) const;
100 :
101 : /** @brief load any applicable transportables
102 : * Loads any person / container that is waiting on that edge for the given vehicle and removes them from myWaiting
103 : * @param[in] edge the edge on which the loading should take place
104 : * @param[in] vehicle the vehicle which is taking on containers
105 : * @param[in,out] timeToLoadNext earliest time for the next loading process (gets updated)
106 : * @param[in,out] stopDuration the duration of the stop where the loading takes place (might be extended)
107 : * @param[in] force load the specified transportable even if the vehicle is not on a stop (needed for replay)
108 : * @return Whether any transportables have been loaded
109 : */
110 : bool loadAnyWaiting(const MSEdge* edge, SUMOVehicle* vehicle, SUMOTime& timeToLoadNext, SUMOTime& stopDuration, MSTransportable* const force = nullptr);
111 :
112 : /// checks whether any transportable waits to finish her plan
113 : bool hasTransportables() const;
114 :
115 : /// checks whether any transportable is still engaged in walking / stopping
116 : bool hasNonWaiting() const;
117 :
118 : /// @brief return the number of active transportable objects
119 : int getActiveCount();
120 :
121 : /// aborts the plan for any transportable that is still waiting for a ride
122 : void abortAnyWaitingForVehicle();
123 :
124 : /// let the given transportable abort waiting for a vehicle (when removing stage via TraCI)
125 : void abortWaitingForVehicle(MSTransportable* t);
126 :
127 : /// aborts waiting stage of transportable
128 : void abortWaiting(MSTransportable* t);
129 :
130 : /** @brief Builds a new person
131 : * @param[in] pars The parameter
132 : * @param[in] vtype The type (reusing vehicle type container here)
133 : * @param[in] plan This person's plan
134 : * @param[in] rng The RNG to compute the optional speed deviation
135 : */
136 : virtual MSTransportable* buildPerson(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportable::MSTransportablePlan* plan,
137 : SumoRNG* rng) const;
138 :
139 : /** @brief Builds a new container
140 : * @param[in] pars The parameter
141 : * @param[in] vtype The type (reusing vehicle type container here)
142 : * @param[in] plan This container's plan
143 : */
144 : virtual MSTransportable* buildContainer(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportable::MSTransportablePlan* plan) const;
145 :
146 : /** @brief Returns the begin of the internal transportables map
147 : * @return The begin of the internal transportables map
148 : */
149 : constVehIt loadedBegin() const {
150 : return myTransportables.begin();
151 : }
152 :
153 :
154 : /** @brief Returns the end of the internal transportables map
155 : * @return The end of the internal transportables map
156 : */
157 : constVehIt loadedEnd() const {
158 : return myTransportables.end();
159 : }
160 :
161 :
162 : /** @brief Returns the number of known transportables
163 : * @return The number of stored transportables
164 : */
165 : int size() const {
166 22 : return (int)myTransportables.size();
167 : }
168 :
169 : /// @brief register a jammed transportable
170 : void registerJammed() {
171 62730 : myJammedNumber++;
172 : }
173 :
174 : /// @brief register a teleport after aborting a long wait
175 : void registerTeleportAbortWait() {
176 16 : myTeleportsAbortWait++;
177 : }
178 :
179 : /// @brief register a teleport to the final destination
180 : void registerTeleportWrongDest() {
181 30 : myTeleportsWrongDest++;
182 30 : }
183 :
184 : /// @brief decrement counter to avoid double counting transportables loaded from state
185 : void fixLoadCount(const MSTransportable* transportable);
186 :
187 : /// @name Retrieval of transportable statistics (always accessible)
188 : /// @{
189 :
190 : /** @brief Returns the number of build transportables
191 : * @return The number of loaded (build) transportables
192 : */
193 0 : int getLoadedNumber() const {
194 510622 : return myLoadedNumber;
195 : }
196 :
197 : int getDepartedNumber() const;
198 :
199 : /** @brief Returns the number of build and inserted, but not yet deleted transportables
200 : * @return The number of simulated transportables
201 : */
202 0 : int getRunningNumber() const {
203 3770599 : return myRunningNumber;
204 : }
205 :
206 : /** @brief Returns the number of times a transportables was jammed
207 : * @return The number of times transportables were jammed
208 : */
209 0 : int getJammedNumber() const {
210 7023 : return myJammedNumber;
211 : }
212 :
213 : /** @brief Returns the number of transportables waiting for a ride
214 : */
215 : int getWaitingForVehicleNumber() const {
216 4752 : return myWaitingForVehicleNumber;
217 : }
218 :
219 : /** @brief Returns the number of transportables waiting for a specified
220 : * amount of time
221 : */
222 : int getWaitingUntilNumber() const {
223 4752 : return myWaitingUntilNumber;
224 : }
225 :
226 : /** @brief Returns the number of transportables moving by themselvs (i.e. walking)
227 : */
228 : int getMovingNumber() const;
229 :
230 : /** @brief Returns the number of transportables riding a vehicle
231 : */
232 : int getRidingNumber() const;
233 :
234 : /** @brief Returns the number of transportables that exited the simulation
235 : */
236 : int getEndedNumber() const {
237 4752 : return myEndedNumber;
238 : }
239 :
240 : /** @brief Returns the number of transportables that arrived at their
241 : * destination
242 : */
243 : int getArrivedNumber() const {
244 4752 : return myArrivedNumber;
245 : }
246 :
247 : /// @brief return the number of teleports due to excessive waiting for a ride
248 : int getTeleportsAbortWait() const {
249 9 : return myTeleportsAbortWait;
250 : }
251 :
252 : /// @brief return the number of teleports of transportables riding to the wrong destination
253 : int getTeleportsWrongDest() const {
254 16 : return myTeleportsWrongDest;
255 : }
256 :
257 : /// @brief Returns the number of teleports transportables did
258 : int getTeleportCount() const {
259 6974 : return myTeleportsAbortWait + myTeleportsWrongDest;
260 : }
261 :
262 : /// @}
263 :
264 : /** @brief Returns the default movement model for this kind of transportables
265 : * @return The movement model
266 : */
267 : inline MSPModel* getMovementModel() {
268 10135388 : return myMovementModel;
269 : }
270 :
271 : /** @brief Returns the non interacting movement model (for tranship and "beaming")
272 : * @return The non interacting movement model
273 : */
274 : inline MSPModel* getNonInteractingModel() {
275 130239 : return myNonInteractingModel;
276 : }
277 :
278 : void addArrived() {
279 364226 : myArrivedNumber++;
280 : }
281 :
282 : void addDiscarded() {
283 56 : myLoadedNumber++;
284 56 : myDiscardedNumber++;
285 56 : }
286 :
287 : void startedAccess() {
288 4120 : myAccessNumber++;
289 : }
290 :
291 : void endedAccess() {
292 4088 : myAccessNumber--;
293 : }
294 :
295 : /** @brief Saves the current state into the given stream
296 : */
297 : void saveState(OutputDevice& out);
298 :
299 : /** @brief Reconstruct the current state
300 : */
301 : void loadState(const std::string& state);
302 :
303 : /// @brief Resets transportables when quick-loading state
304 : void clearState();
305 :
306 : const MSDevice_Vehroutes::SortedRouteInfo& getRouteInfo() {
307 : return myRouteInfos;
308 : }
309 :
310 : protected:
311 : /// all currently created transportables by id
312 : std::map<std::string, MSTransportable*> myTransportables;
313 :
314 : /// @brief Transportables waiting for departure
315 : std::map<SUMOTime, TransportableVector> myWaiting4Departure;
316 :
317 : /// the lists of walking / stopping transportables
318 : std::map<SUMOTime, TransportableVector> myWaitingUntil;
319 :
320 : /// the lists of waiting transportables
321 : std::map<const MSEdge*, TransportableVector, ComparatorNumericalIdLess> myWaiting4Vehicle;
322 :
323 : /// @brief The number of build transportables
324 : int myLoadedNumber;
325 :
326 : /// @brief The number of discarded transportables
327 : int myDiscardedNumber;
328 :
329 : /// @brief The number of transportables within the network (build and inserted but not removed)
330 : int myRunningNumber;
331 :
332 : /// @brief The number of jammed transportables
333 : int myJammedNumber;
334 :
335 : /// @brief The number of transportables waiting for departure
336 : int myWaitingForDepartureNumber;
337 :
338 : /// @brief The number of transportables waiting for vehicles
339 : int myWaitingForVehicleNumber;
340 :
341 : /// @brief The number of transportables waiting for a specified time
342 : int myWaitingUntilNumber;
343 :
344 : /// @brief The number of transportables currently in an access stage
345 : int myAccessNumber;
346 :
347 : /// @brief The number of transportables that exited the simulation
348 : int myEndedNumber;
349 :
350 : /// @brief The number of transportables that arrived at their destination
351 : int myArrivedNumber;
352 :
353 : /// @brief The number of teleports due to long waits for a ride
354 : int myTeleportsAbortWait;
355 :
356 : /// @brief The number of teleports due to wrong destination
357 : int myTeleportsWrongDest;
358 :
359 : /// @brief whether a new transportable waiting for a vehicle has been added in the last step
360 : bool myHaveNewWaiting;
361 :
362 : /// @brief maximum transportable count
363 : int myMaxTransportableNumber;
364 :
365 : private:
366 : MSPModel* myMovementModel;
367 :
368 : MSPModel* myNonInteractingModel;
369 :
370 : /// @brief Information needed to sort transportable output by departure time
371 : MSDevice_Vehroutes::SortedRouteInfo myRouteInfos;
372 :
373 : /// @brief The time until waiting for a ride is aborted
374 : SUMOTime myAbortWaitingTimeout;
375 :
376 : private:
377 : /// @brief invalidated assignment operator
378 : MSTransportableControl& operator=(const MSTransportableControl& src) = delete;
379 : };
|