Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2026 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 : /// @removes all transportables
87 : void eraseAll();
88 :
89 : /// sets the arrival time for a waiting transportable
90 : void setWaitEnd(SUMOTime time, MSTransportable* transportable);
91 :
92 : /// checks whether any transportables waiting time is over
93 : void checkWaiting(MSNet* net, const SUMOTime time);
94 :
95 : /// adds a transportable to the list of transportables waiting for a vehicle on the specified edge
96 : void addWaiting(const MSEdge* edge, MSTransportable* person);
97 :
98 : /// register forced (traci) departure
99 : void forceDeparture();
100 :
101 : /// @brief check whether any transportables are waiting for the given vehicle
102 : bool hasAnyWaiting(const MSEdge* edge, SUMOVehicle* vehicle) const;
103 :
104 : /** @brief load any applicable transportables
105 : * Loads any person / container that is waiting on that edge for the given vehicle and removes them from myWaiting
106 : * @param[in] edge the edge on which the loading should take place
107 : * @param[in] vehicle the vehicle which is taking on containers
108 : * @param[in,out] timeToLoadNext earliest time for the next loading process (gets updated)
109 : * @param[in,out] stopDuration the duration of the stop where the loading takes place (might be extended)
110 : * @param[in] force load the specified transportable even if the vehicle is not on a stop (needed for replay)
111 : * @return Whether any transportables have been loaded
112 : */
113 : bool loadAnyWaiting(const MSEdge* edge, SUMOVehicle* vehicle, SUMOTime& timeToLoadNext, SUMOTime& stopDuration, MSTransportable* const force = nullptr);
114 :
115 : /// checks whether any transportable waits to finish her plan
116 : bool hasTransportables() const;
117 :
118 : /// checks whether any transportable is still engaged in walking / stopping
119 : bool hasNonWaiting() const;
120 :
121 : /// @brief return the number of active transportable objects
122 : int getActiveCount();
123 :
124 : /// aborts the plan for any transportable that is still waiting for a ride
125 : void abortAnyWaitingForVehicle();
126 :
127 : /// let the given transportable abort waiting for a vehicle (when removing stage via TraCI)
128 : void abortWaitingForVehicle(MSTransportable* t);
129 :
130 : /// aborts waiting stage of transportable
131 : void abortWaiting(MSTransportable* t);
132 :
133 : /** @brief Builds a new person
134 : * @param[in] pars The parameter
135 : * @param[in] vtype The type (reusing vehicle type container here)
136 : * @param[in] plan This person's plan
137 : * @param[in] rng The RNG to compute the optional speed deviation
138 : */
139 : virtual MSTransportable* buildPerson(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportable::MSTransportablePlan* plan,
140 : SumoRNG* rng) const;
141 :
142 : /** @brief Builds a new container
143 : * @param[in] pars The parameter
144 : * @param[in] vtype The type (reusing vehicle type container here)
145 : * @param[in] plan This container's plan
146 : */
147 : virtual MSTransportable* buildContainer(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportable::MSTransportablePlan* plan) const;
148 :
149 : /** @brief Returns the begin of the internal transportables map
150 : * @return The begin of the internal transportables map
151 : */
152 : constVehIt loadedBegin() const {
153 : return myTransportables.begin();
154 : }
155 :
156 :
157 : /** @brief Returns the end of the internal transportables map
158 : * @return The end of the internal transportables map
159 : */
160 : constVehIt loadedEnd() const {
161 : return myTransportables.end();
162 : }
163 :
164 :
165 : /** @brief Returns the number of known transportables
166 : * @return The number of stored transportables
167 : */
168 : int size() const {
169 26 : return (int)myTransportables.size();
170 : }
171 :
172 : /// @brief register a jammed transportable
173 : void registerJammed() {
174 97858 : myJammedNumber++;
175 : }
176 :
177 : /// @brief register a teleport after aborting a long wait
178 : void registerTeleportAbortWait() {
179 16 : myTeleportsAbortWait++;
180 : }
181 :
182 : /// @brief register a teleport to the final destination
183 : void registerTeleportWrongDest() {
184 38 : myTeleportsWrongDest++;
185 38 : }
186 :
187 : /// @brief decrement counter to avoid double counting transportables loaded from state
188 : void fixLoadCount(const MSTransportable* transportable);
189 :
190 : /// @name Retrieval of transportable statistics (always accessible)
191 : /// @{
192 :
193 : /** @brief Returns the number of build transportables
194 : * @return The number of loaded (build) transportables
195 : */
196 0 : int getLoadedNumber() const {
197 515582 : return myLoadedNumber;
198 : }
199 :
200 : int getDepartedNumber() const;
201 :
202 : /** @brief Returns the number of build and inserted, but not yet deleted transportables
203 : * @return The number of simulated transportables
204 : */
205 0 : int getRunningNumber() const {
206 4058114 : return myRunningNumber;
207 : }
208 :
209 : /** @brief Returns the number of times a transportables was jammed
210 : * @return The number of times transportables were jammed
211 : */
212 0 : int getJammedNumber() const {
213 7287 : return myJammedNumber;
214 : }
215 :
216 : /** @brief Returns the number of transportables waiting for a ride
217 : */
218 : int getWaitingForVehicleNumber() const {
219 4752 : return myWaitingForVehicleNumber;
220 : }
221 :
222 : /** @brief Returns the number of transportables waiting for a specified
223 : * amount of time
224 : */
225 : int getWaitingUntilNumber() const {
226 4752 : return myWaitingUntilNumber;
227 : }
228 :
229 : /** @brief Returns the number of transportables moving by themselvs (i.e. walking)
230 : */
231 : int getMovingNumber() const;
232 :
233 : /** @brief Returns the number of transportables riding a vehicle
234 : */
235 : int getRidingNumber() const;
236 :
237 : /** @brief Returns the number of transportables that exited the simulation
238 : */
239 : int getEndedNumber() const {
240 4752 : return myEndedNumber;
241 : }
242 :
243 : /** @brief Returns the number of transportables that arrived at their
244 : * destination
245 : */
246 : int getArrivedNumber() const {
247 4752 : return myArrivedNumber;
248 : }
249 :
250 : /** @brief Returns the number of discarded transportables
251 : */
252 : int getDiscardedNumber() const {
253 4752 : return myDiscardedNumber;
254 : }
255 :
256 : /// @brief return the number of teleports due to excessive waiting for a ride
257 : int getTeleportsAbortWait() const {
258 11 : return myTeleportsAbortWait;
259 : }
260 :
261 : /// @brief return the number of teleports of transportables riding to the wrong destination
262 : int getTeleportsWrongDest() const {
263 18 : return myTeleportsWrongDest;
264 : }
265 :
266 : /// @brief Returns the number of teleports transportables did
267 : int getTeleportCount() const {
268 7240 : return myTeleportsAbortWait + myTeleportsWrongDest;
269 : }
270 :
271 : /// @}
272 :
273 : /** @brief Returns the default movement model for this kind of transportables
274 : * @return The movement model
275 : */
276 : inline MSPModel* getMovementModel() {
277 12349165 : return myMovementModel;
278 : }
279 :
280 : /** @brief Returns the non interacting movement model (for tranship and "beaming")
281 : * @return The non interacting movement model
282 : */
283 : inline MSPModel* getNonInteractingModel() {
284 135324 : return myNonInteractingModel;
285 : }
286 :
287 : void addArrived() {
288 410278 : myArrivedNumber++;
289 : }
290 :
291 : void addDiscarded() {
292 56 : myLoadedNumber++;
293 56 : myDiscardedNumber++;
294 56 : }
295 :
296 : void startedAccess() {
297 4243 : myAccessNumber++;
298 : }
299 :
300 : void endedAccess() {
301 4211 : myAccessNumber--;
302 : }
303 :
304 : /** @brief Saves the current state into the given stream
305 : */
306 : void saveState(OutputDevice& out);
307 :
308 : /** @brief Reconstruct the current state
309 : */
310 : void loadState(const std::string& state);
311 :
312 : /// @brief Resets transportables when quick-loading state
313 : void clearState();
314 :
315 : const MSDevice_Vehroutes::SortedRouteInfo& getRouteInfo() {
316 : return myRouteInfos;
317 : }
318 :
319 : protected:
320 : /// all currently created transportables by id
321 : std::map<std::string, MSTransportable*> myTransportables;
322 :
323 : /// @brief Transportables waiting for departure
324 : std::map<SUMOTime, TransportableVector> myWaiting4Departure;
325 :
326 : /// the lists of walking / stopping transportables
327 : std::map<SUMOTime, TransportableVector> myWaitingUntil;
328 :
329 : /// the lists of waiting transportables
330 : std::map<const MSEdge*, TransportableVector, ComparatorNumericalIdLess> myWaiting4Vehicle;
331 :
332 : /// @brief The number of build transportables
333 : int myLoadedNumber;
334 :
335 : /// @brief The number of discarded transportables
336 : int myDiscardedNumber;
337 :
338 : /// @brief The number of transportables within the network (build and inserted but not removed)
339 : int myRunningNumber;
340 :
341 : /// @brief The number of jammed transportables
342 : int myJammedNumber;
343 :
344 : /// @brief The number of transportables waiting for departure
345 : int myWaitingForDepartureNumber;
346 :
347 : /// @brief The number of transportables waiting for vehicles
348 : int myWaitingForVehicleNumber;
349 :
350 : /// @brief The number of transportables waiting for a specified time
351 : int myWaitingUntilNumber;
352 :
353 : /// @brief The number of transportables currently in an access stage
354 : int myAccessNumber;
355 :
356 : /// @brief The number of transportables that exited the simulation
357 : int myEndedNumber;
358 :
359 : /// @brief The number of transportables that arrived at their destination
360 : int myArrivedNumber;
361 :
362 : /// @brief The number of teleports due to long waits for a ride
363 : int myTeleportsAbortWait;
364 :
365 : /// @brief The number of teleports due to wrong destination
366 : int myTeleportsWrongDest;
367 :
368 : /// @brief whether a new transportable waiting for a vehicle has been added in the last step
369 : bool myHaveNewWaiting;
370 :
371 : /// @brief maximum transportable count
372 : int myMaxTransportableNumber;
373 :
374 : private:
375 : MSPModel* myMovementModel;
376 :
377 : MSPModel* myNonInteractingModel;
378 :
379 : /// @brief Information needed to sort transportable output by departure time
380 : MSDevice_Vehroutes::SortedRouteInfo myRouteInfos;
381 :
382 : /// @brief The time until waiting for a ride is aborted
383 : SUMOTime myAbortWaitingTimeout;
384 :
385 : private:
386 : /// @brief invalidated assignment operator
387 : MSTransportableControl& operator=(const MSTransportableControl& src) = delete;
388 : };
|