Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2025 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 30 : return (int)myTransportables.size();
167 : }
168 :
169 : /// @brief register a jammed transportable
170 : void registerJammed() {
171 87888 : 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 38 : myTeleportsWrongDest++;
182 38 : }
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 519923 : 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 4010031 : 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 7262 : 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 Returns the number of discarded transportables
248 : */
249 : int getDiscardedNumber() const {
250 4752 : return myDiscardedNumber;
251 : }
252 :
253 : /// @brief return the number of teleports due to excessive waiting for a ride
254 : int getTeleportsAbortWait() const {
255 11 : return myTeleportsAbortWait;
256 : }
257 :
258 : /// @brief return the number of teleports of transportables riding to the wrong destination
259 : int getTeleportsWrongDest() const {
260 18 : return myTeleportsWrongDest;
261 : }
262 :
263 : /// @brief Returns the number of teleports transportables did
264 : int getTeleportCount() const {
265 7215 : return myTeleportsAbortWait + myTeleportsWrongDest;
266 : }
267 :
268 : /// @}
269 :
270 : /** @brief Returns the default movement model for this kind of transportables
271 : * @return The movement model
272 : */
273 : inline MSPModel* getMovementModel() {
274 11860891 : return myMovementModel;
275 : }
276 :
277 : /** @brief Returns the non interacting movement model (for tranship and "beaming")
278 : * @return The non interacting movement model
279 : */
280 : inline MSPModel* getNonInteractingModel() {
281 130790 : return myNonInteractingModel;
282 : }
283 :
284 : void addArrived() {
285 393322 : myArrivedNumber++;
286 : }
287 :
288 : void addDiscarded() {
289 56 : myLoadedNumber++;
290 56 : myDiscardedNumber++;
291 56 : }
292 :
293 : void startedAccess() {
294 4225 : myAccessNumber++;
295 : }
296 :
297 : void endedAccess() {
298 4193 : myAccessNumber--;
299 : }
300 :
301 : /** @brief Saves the current state into the given stream
302 : */
303 : void saveState(OutputDevice& out);
304 :
305 : /** @brief Reconstruct the current state
306 : */
307 : void loadState(const std::string& state);
308 :
309 : /// @brief Resets transportables when quick-loading state
310 : void clearState();
311 :
312 : const MSDevice_Vehroutes::SortedRouteInfo& getRouteInfo() {
313 : return myRouteInfos;
314 : }
315 :
316 : protected:
317 : /// all currently created transportables by id
318 : std::map<std::string, MSTransportable*> myTransportables;
319 :
320 : /// @brief Transportables waiting for departure
321 : std::map<SUMOTime, TransportableVector> myWaiting4Departure;
322 :
323 : /// the lists of walking / stopping transportables
324 : std::map<SUMOTime, TransportableVector> myWaitingUntil;
325 :
326 : /// the lists of waiting transportables
327 : std::map<const MSEdge*, TransportableVector, ComparatorNumericalIdLess> myWaiting4Vehicle;
328 :
329 : /// @brief The number of build transportables
330 : int myLoadedNumber;
331 :
332 : /// @brief The number of discarded transportables
333 : int myDiscardedNumber;
334 :
335 : /// @brief The number of transportables within the network (build and inserted but not removed)
336 : int myRunningNumber;
337 :
338 : /// @brief The number of jammed transportables
339 : int myJammedNumber;
340 :
341 : /// @brief The number of transportables waiting for departure
342 : int myWaitingForDepartureNumber;
343 :
344 : /// @brief The number of transportables waiting for vehicles
345 : int myWaitingForVehicleNumber;
346 :
347 : /// @brief The number of transportables waiting for a specified time
348 : int myWaitingUntilNumber;
349 :
350 : /// @brief The number of transportables currently in an access stage
351 : int myAccessNumber;
352 :
353 : /// @brief The number of transportables that exited the simulation
354 : int myEndedNumber;
355 :
356 : /// @brief The number of transportables that arrived at their destination
357 : int myArrivedNumber;
358 :
359 : /// @brief The number of teleports due to long waits for a ride
360 : int myTeleportsAbortWait;
361 :
362 : /// @brief The number of teleports due to wrong destination
363 : int myTeleportsWrongDest;
364 :
365 : /// @brief whether a new transportable waiting for a vehicle has been added in the last step
366 : bool myHaveNewWaiting;
367 :
368 : /// @brief maximum transportable count
369 : int myMaxTransportableNumber;
370 :
371 : private:
372 : MSPModel* myMovementModel;
373 :
374 : MSPModel* myNonInteractingModel;
375 :
376 : /// @brief Information needed to sort transportable output by departure time
377 : MSDevice_Vehroutes::SortedRouteInfo myRouteInfos;
378 :
379 : /// @brief The time until waiting for a ride is aborted
380 : SUMOTime myAbortWaitingTimeout;
381 :
382 : private:
383 : /// @brief invalidated assignment operator
384 : MSTransportableControl& operator=(const MSTransportableControl& src) = delete;
385 : };
|