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 MSTransportable.h
15 : /// @author Michael Behrisch
16 : /// @date Tue, 21 Apr 2015
17 : ///
18 : // The common superclass for modelling transportable objects like persons and containers
19 : /****************************************************************************/
20 : #pragma once
21 : #include <config.h>
22 :
23 : #include <set>
24 : #include <cassert>
25 : #include <utils/common/SUMOTime.h>
26 : #include <utils/common/SUMOVehicleClass.h>
27 : #include <utils/common/WrappingCommand.h>
28 : #include <utils/geom/Position.h>
29 : #include <utils/geom/PositionVector.h>
30 : #include <utils/geom/Boundary.h>
31 : #include <utils/router/SUMOAbstractRouter.h>
32 : #include <utils/vehicle/SUMOTrafficObject.h>
33 : #include <microsim/MSRouterDefs.h>
34 : #include <microsim/MSVehicleType.h>
35 : #include "MSStage.h"
36 :
37 :
38 : // ===========================================================================
39 : // class declarations
40 : // ===========================================================================
41 : class MSEdge;
42 : class MSLane;
43 : class MSNet;
44 : class MSStoppingPlace;
45 : class OutputDevice;
46 : class SUMOVehicleParameter;
47 : class SUMOVehicle;
48 : class MSTransportableDevice;
49 :
50 :
51 : // ===========================================================================
52 : // class definitions
53 : // ===========================================================================
54 : /**
55 : * @class MSTransportable
56 : *
57 : * The class holds a simulated moveable object
58 : */
59 : class MSTransportable : public SUMOTrafficObject {
60 : public:
61 : /// @name inherited from SUMOTrafficObject
62 : /// @{
63 23387379 : inline bool isPerson() const override {
64 23387379 : return myAmPerson;
65 : }
66 :
67 164 : inline bool isContainer() const override {
68 164 : return !myAmPerson;
69 : }
70 :
71 : inline std::string getObjectType() {
72 739 : return myAmPerson ? "Person" : "Container";
73 : }
74 :
75 49645112 : inline NumericalID getNumericalID() const override {
76 49645112 : return myNumericalID;
77 : }
78 :
79 : /// @brief return transportable-specific random number
80 0 : long long int getRandomSeed() const override {
81 0 : return myRandomSeed;
82 : }
83 :
84 4282 : inline bool isStopped() const override {
85 4282 : return getCurrentStageType() == MSStageType::WAITING;
86 : }
87 :
88 : double getSlope() const override;
89 :
90 : SUMOVehicleClass getVClass() const override;
91 :
92 : /// @brief whether the transportable (persons) is jammed as defined by the current pedestrian model
93 0 : virtual bool isJammed() const {
94 0 : return false;
95 : }
96 :
97 : /** @brief Returns the maximum speed (the minimum of desired and physical maximum speed)
98 : * @return The objects's maximum speed
99 : */
100 : double getMaxSpeed() const override;
101 :
102 : SUMOTime getWaitingTime(const bool accumulated = false) const override;
103 :
104 26102 : double getPreviousSpeed() const override {
105 26102 : return getSpeed();
106 : }
107 :
108 9220 : double getAcceleration() const override {
109 9220 : return 0.0;
110 : }
111 :
112 1619265 : double getPositionOnLane() const override {
113 1619265 : return getEdgePos();
114 : }
115 :
116 : double getBackPositionOnLane(const MSLane* lane) const override;
117 :
118 259146 : Position getPosition(const double /*offset*/) const override {
119 259146 : return getPosition();
120 : }
121 : /// @}
122 :
123 : /// the structure holding the plan of a transportable
124 : typedef std::vector<MSStage*> MSTransportablePlan;
125 :
126 : /// constructor
127 : MSTransportable(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportablePlan* plan, const bool isPerson);
128 :
129 : /// destructor
130 : virtual ~MSTransportable();
131 :
132 : /* @brief proceeds to the next step of the route,
133 : * @return Whether the transportables plan continues */
134 : virtual bool proceed(MSNet* net, SUMOTime time, const bool vehicleArrived = false);
135 :
136 838 : virtual bool checkAccess(const MSStage* const prior, const bool waitAtStop = true) {
137 : UNUSED_PARAMETER(prior);
138 : UNUSED_PARAMETER(waitAtStop);
139 838 : return false;
140 : }
141 :
142 : /// @brief set the id (inherited from Named but forbidden for transportables)
143 : void setID(const std::string& newID) override;
144 :
145 5033102 : inline const SUMOVehicleParameter& getParameter() const override {
146 5033102 : return *myParameter;
147 : }
148 :
149 7155391403 : inline const MSVehicleType& getVehicleType() const override {
150 7155391403 : return *myVType;
151 : }
152 :
153 : /** @brief Returns the object's "vehicle" type parameter
154 : * @return The object's type parameter
155 : */
156 1636471 : inline const SUMOVTypeParameter& getVTypeParameter() const override {
157 1636471 : return myVType->getParameter();
158 : }
159 :
160 : /// @brief returns the associated RNG
161 : SumoRNG* getRNG() const override;
162 :
163 : /// @brief returns the index of the associated RNG
164 : int getRNGIndex() const override;
165 :
166 : /// Returns the desired departure time.
167 : SUMOTime getDesiredDepart() const;
168 :
169 : /// logs depart time of the current stage
170 : void setDeparted(SUMOTime now);
171 :
172 : /// logs depart time of the current stage
173 : SUMOTime getDeparture() const;
174 :
175 : /// Returns the current destination.
176 : const MSEdge* getDestination() const {
177 90112 : return (*myStep)->getDestination();
178 : }
179 :
180 : /// Returns the destination after the current destination.
181 : const MSEdge* getNextDestination() const {
182 : return (*(myStep + 1))->getDestination();
183 : }
184 :
185 : /// @brief Returns the current edge
186 688247 : const MSEdge* getEdge() const override {
187 688247 : return (*myStep)->getEdge();
188 : }
189 :
190 : /// @brief Returns the current lane (may be nullptr)
191 948729 : const MSLane* getLane() const override {
192 948729 : return (*myStep)->getLane();
193 : }
194 :
195 0 : const MSLane* getBackLane() const override {
196 0 : return getLane();
197 : }
198 :
199 : /// @brief Returns the departure edge
200 : const MSEdge* getFromEdge() const {
201 1558 : return (*myStep)->getFromEdge();
202 : }
203 :
204 : /// @brief Return the position on the edge
205 : virtual double getEdgePos() const;
206 :
207 : /// @brief Return the movement directon on the edge
208 : virtual int getDirection() const;
209 :
210 : /// @brief Return the Network coordinate of the transportable
211 : virtual Position getPosition() const;
212 :
213 : /// @brief return the current angle of the transportable
214 : virtual double getAngle() const override;
215 :
216 : /// @brief the time this transportable spent waiting in seconds
217 : virtual double getWaitingSeconds() const;
218 :
219 : /// @brief the current speed of the transportable
220 : virtual double getSpeed() const override;
221 :
222 : /// @brief the current speed factor of the transportable (where applicable)
223 0 : virtual double getChosenSpeedFactor() const override {
224 0 : return 1;
225 : }
226 :
227 : /// @brief the current stage type of the transportable
228 : MSStageType getCurrentStageType() const {
229 3390424 : return (*myStep)->getStageType();
230 : }
231 :
232 : /// @brief the stage type for the nth next stage
233 : MSStageType getStageType(int next) const {
234 : assert(myStep + next < myPlan->end());
235 : assert(myStep + next >= myPlan->begin());
236 42170 : return (*(myStep + next))->getStageType();
237 : }
238 :
239 : /// @brief return textual summary for the given stage
240 : std::string getStageSummary(int stageIndex) const;
241 :
242 : /// Returns the current stage description as a string
243 0 : std::string getCurrentStageDescription() const {
244 21010 : return (*myStep)->getStageDescription(myAmPerson);
245 : }
246 :
247 : /// @brief Return the current stage
248 : MSStage* getCurrentStage() const {
249 6530120 : return *myStep;
250 : }
251 :
252 : /// @brief Return the next (or previous) stage denoted by the offset
253 : inline MSStage* getNextStage(int offset) const {
254 : assert(myStep + offset >= myPlan->begin());
255 : assert(myStep + offset < myPlan->end());
256 211920 : return *(myStep + offset);
257 : }
258 :
259 : /// @brief returns the numerical IDs of edges to be used (possibly of future stages)
260 : const std::set<NumericalID> getUpcomingEdgeIDs() const override;
261 :
262 : /// @brief Return the total number stages in this person's plan
263 : inline int getNumStages() const {
264 1939 : return (int)myPlan->size();
265 : }
266 :
267 : /// @brief Return the number of remaining stages (including the current)
268 : inline int getNumRemainingStages() const {
269 59786 : return (int)(myPlan->end() - myStep);
270 : }
271 :
272 : /// @brief Return the index of the current stage
273 : inline int getCurrentStageIndex() const {
274 208217 : return (int)(myStep - myPlan->begin());
275 : }
276 :
277 : /// @brief return the index of the edge within the route
278 455828 : inline int getRoutePosition() const override {
279 455828 : return (*myStep)->getRoutePosition();
280 : }
281 :
282 : /// @brief returns the next edge ptr (used by walking persons)
283 0 : virtual const MSEdge* getNextEdgePtr() const override {
284 0 : return nullptr;
285 : }
286 :
287 : /** @brief Called on writing tripinfo output
288 : *
289 : * @param[in] os The stream to write the information into
290 : * @exception IOError not yet implemented
291 : */
292 : void tripInfoOutput(OutputDevice& os) const;
293 :
294 : /** @brief Called on writing vehroute output
295 : *
296 : * @param[in] os The stream to write the information into
297 : * @exception IOError not yet implemented
298 : */
299 : void routeOutput(OutputDevice& os, const bool withRouteLength) const;
300 :
301 : /// Whether the transportable waits for the given vehicle in the current step
302 : bool isWaitingFor(const SUMOVehicle* vehicle) const {
303 4651494 : return (*myStep)->isWaitingFor(vehicle);
304 : }
305 :
306 : /// @brief Whether the transportable waits for a vehicle
307 : bool isWaiting4Vehicle() const {
308 1841304 : return (*myStep)->isWaiting4Vehicle();
309 : }
310 :
311 : void setAbortWaiting(const SUMOTime timeout);
312 :
313 : /// @brief Abort current stage (used for aborting waiting for a vehicle)
314 : SUMOTime abortStage(SUMOTime step);
315 :
316 : /// @brief The vehicle associated with this transportable
317 : SUMOVehicle* getVehicle() const {
318 373915 : return (*myStep)->getVehicle();
319 : }
320 :
321 : /// @brief Appends the given stage to the current plan
322 : void appendStage(MSStage* stage, int next = -1);
323 :
324 : /// @brief removes the nth next stage
325 : void removeStage(int next, bool stayInSim = true);
326 :
327 : /// @brief set the speed for all present and future (walking) stages and modify the vType so that stages added later are also affected
328 : void setSpeed(double speed);
329 :
330 : /// @brief returns the final arrival pos
331 : double getArrivalPos() const {
332 255 : return myPlan->back()->getArrivalPos();
333 : }
334 :
335 : /// @brief returns the final arrival edge
336 1641 : const MSEdge* getArrivalEdge() const {
337 1641 : return myPlan->back()->getEdges().back();
338 : }
339 :
340 : /** @brief Returns the end point for reroutes (usually the last edge of the route)
341 : *
342 : * @return The rerouting end point
343 : */
344 1615 : const MSEdge* getRerouteDestination() const override {
345 1615 : return getArrivalEdge();
346 : }
347 :
348 : bool reroute(SUMOTime t, const std::string& info, MSTransportableRouter& router, const bool onInit = false, const bool withTaz = false, const bool silent = false, const MSEdge* sink = nullptr);
349 :
350 : /// Replaces the current route by the given one
351 : bool replaceRoute(ConstMSRoutePtr route, const std::string& info, bool onInit = false, int offset = 0, bool addStops = true, bool removeStops = true, std::string* msgReturn = nullptr) override;
352 :
353 : /** @brief Replaces the current vehicle type by the one given
354 : *
355 : * If the currently used vehicle type is marked as being used by this vehicle
356 : * only, it is deleted, first. The new, given type is then assigned to
357 : * "myVType".
358 : * @param[in] type The new vehicle type
359 : * @see MSTransportable::myVType
360 : */
361 : void replaceVehicleType(const MSVehicleType* type) override;
362 :
363 : /** @brief Replaces the current vehicle type with a new one used by this vehicle only
364 : *
365 : * If the currently used vehicle type is already marked as being used by this vehicle
366 : * only, no new type is created.
367 : * @return The new modifiable vehicle type
368 : * @see MSTransportable::myVType
369 : */
370 : MSVehicleType& getSingularType();
371 :
372 : /// @brief return the bounding box of the person
373 : PositionVector getBoundingBox() const;
374 :
375 : /// @brief return whether the person has reached the end of its plan
376 : bool hasArrived() const override;
377 :
378 : /// @brief return whether the transportable has started its plan
379 : bool hasDeparted() const;
380 :
381 : /// @brief adapt plan when the vehicle reroutes and now stops at replacement instead of orig
382 : void rerouteParkingArea(MSStoppingPlace* orig, MSStoppingPlace* replacement);
383 :
384 : /// @brief Returns a device of the given type if it exists or nullptr if not
385 : MSDevice* getDevice(const std::type_info& type) const override;
386 :
387 : /// @brief set individual junction model paramete (not type related)
388 : void setJunctionModelParameter(const std::string& key, const std::string& value);
389 :
390 : /** @brief Returns this vehicle's devices
391 : * @return This vehicle's devices
392 : */
393 : inline const std::vector<MSTransportableDevice*>& getDevices() const {
394 : return myDevices;
395 : }
396 :
397 0 : virtual bool hasInfluencer() const override {
398 0 : return false;
399 : }
400 :
401 : /// @brief whether this transportable is selected in the GUI
402 0 : virtual bool isSelected() const override {
403 0 : return false;
404 : }
405 :
406 : /// @brief return routing mode (configures router choice but also handling of transient permission changes)
407 : virtual int getRoutingMode() const override;
408 :
409 : /** @brief Saves the current state into the given stream
410 : */
411 : void saveState(OutputDevice& out);
412 :
413 : /** @brief Reconstructs the current state
414 : */
415 : void loadState(const std::string& state);
416 :
417 : protected:
418 : /// the plan of the transportable
419 : const SUMOVehicleParameter* myParameter;
420 :
421 : /// @brief This transportable's type. (mainly used for drawing related information
422 : /// Note sure if it is really necessary
423 : const MSVehicleType* myVType;
424 :
425 : /// @brief Whether events shall be written
426 : bool myWriteEvents;
427 :
428 : /// the plan of the transportable
429 : MSTransportablePlan* myPlan;
430 :
431 : /// the iterator over the route
432 : MSTransportablePlan::iterator myStep;
433 :
434 : /// @brief The devices this transportable has
435 : std::vector<MSTransportableDevice*> myDevices;
436 :
437 : private:
438 : const bool myAmPerson;
439 :
440 : const NumericalID myNumericalID;
441 :
442 : const long long int myRandomSeed;
443 :
444 : WrappingCommand<MSTransportable>* myAbortCommand;
445 :
446 : static NumericalID myCurrentNumericalIndex;
447 :
448 : private:
449 : /// @brief Invalidated copy constructor.
450 : MSTransportable(const MSTransportable&);
451 :
452 : /// @brief Invalidated assignment operator.
453 : MSTransportable& operator=(const MSTransportable&);
454 :
455 : };
|