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 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 19659316 : inline bool isPerson() const override {
64 19659316 : return myAmPerson;
65 : }
66 :
67 163 : inline bool isContainer() const override {
68 163 : return !myAmPerson;
69 : }
70 :
71 : inline std::string getObjectType() {
72 117513 : return myAmPerson ? "Person" : "Container";
73 : }
74 :
75 51569989 : inline NumericalID getNumericalID() const override {
76 51569989 : 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 26100 : double getPreviousSpeed() const override {
105 26100 : return getSpeed();
106 : }
107 :
108 9220 : double getAcceleration() const override {
109 9220 : return 0.0;
110 : }
111 :
112 1563980 : double getPositionOnLane() const override {
113 1563980 : return getEdgePos();
114 : }
115 :
116 : double getBackPositionOnLane(const MSLane* lane) const override;
117 :
118 259145 : Position getPosition(const double /*offset*/) const override {
119 259145 : 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 4732790 : inline const SUMOVehicleParameter& getParameter() const override {
146 4732790 : return *myParameter;
147 : }
148 :
149 5731819258 : inline const MSVehicleType& getVehicleType() const override {
150 5731819258 : return *myVType;
151 : }
152 :
153 : /** @brief Returns the object's "vehicle" type parameter
154 : * @return The object's type parameter
155 : */
156 1445709 : inline const SUMOVTypeParameter& getVTypeParameter() const override {
157 1445709 : 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 107732 : 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 4085675 : const MSEdge* getEdge() const override {
187 4085675 : return (*myStep)->getEdge();
188 : }
189 :
190 : const MSEdge* getCurrentEdge() const override;
191 :
192 : /// @brief Returns the current lane (may be nullptr)
193 4384683 : const MSLane* getLane() const override {
194 4384683 : return (*myStep)->getLane();
195 : }
196 :
197 0 : const MSLane* getBackLane() const override {
198 0 : return getLane();
199 : }
200 :
201 : /// @brief Returns the departure edge
202 : const MSEdge* getFromEdge() const {
203 1559 : return (*myStep)->getFromEdge();
204 : }
205 :
206 : /// @brief Return the position on the edge
207 : virtual double getEdgePos() const;
208 :
209 : /// @brief Return the movement directon on the edge
210 : virtual int getDirection() const;
211 :
212 : /// @brief Return the Network coordinate of the transportable
213 : virtual Position getPosition() const;
214 :
215 : /// @brief return the current angle of the transportable
216 : virtual double getAngle() const override;
217 :
218 : /// @brief the time this transportable spent waiting in seconds
219 : virtual double getWaitingSeconds() const;
220 :
221 : /// @brief the current speed of the transportable
222 : virtual double getSpeed() const override;
223 :
224 : /// @brief the current speed factor of the transportable (where applicable)
225 0 : virtual double getChosenSpeedFactor() const override {
226 0 : return 1;
227 : }
228 :
229 : /// @brief the current stage type of the transportable
230 : MSStageType getCurrentStageType() const {
231 3432432 : return (*myStep)->getStageType();
232 : }
233 :
234 : /// @brief the stage type for the nth next stage
235 : MSStageType getStageType(int next) const {
236 : assert(myStep + next < myPlan->end());
237 : assert(myStep + next >= myPlan->begin());
238 5196177 : return (*(myStep + next))->getStageType();
239 : }
240 :
241 : /// @brief return textual summary for the given stage
242 : std::string getStageSummary(int stageIndex) const;
243 :
244 : /// Returns the current stage description as a string
245 0 : std::string getCurrentStageDescription() const {
246 1993091 : return (*myStep)->getStageDescription(myAmPerson);
247 : }
248 :
249 : /// @brief Return the current stage
250 : MSStage* getCurrentStage() const {
251 6815059 : return *myStep;
252 : }
253 :
254 : /// @brief Return the next (or previous) stage denoted by the offset
255 : inline MSStage* getNextStage(int offset) const {
256 : assert(myStep + offset >= myPlan->begin());
257 : assert(myStep + offset < myPlan->end());
258 172528 : return *(myStep + offset);
259 : }
260 :
261 : /// @brief returns the numerical IDs of edges to be used (possibly of future stages)
262 : const std::set<NumericalID> getUpcomingEdgeIDs() const override;
263 :
264 : /// @brief Return the total number stages in this person's plan
265 : inline int getNumStages() const {
266 1943 : return (int)myPlan->size();
267 : }
268 :
269 : /// @brief Return the number of remaining stages (including the current)
270 : inline int getNumRemainingStages() const {
271 71679 : return (int)(myPlan->end() - myStep);
272 : }
273 :
274 : /// @brief Return the index of the current stage
275 : inline int getCurrentStageIndex() const {
276 168737 : return (int)(myStep - myPlan->begin());
277 : }
278 :
279 : /// @brief return the index of the edge within the route
280 456226 : inline int getRoutePosition() const override {
281 456226 : return (*myStep)->getRoutePosition();
282 : }
283 :
284 : /// @brief returns the next edge ptr (used by walking persons)
285 0 : virtual const MSEdge* getNextEdgePtr() const override {
286 0 : return nullptr;
287 : }
288 :
289 : /** @brief Called on writing tripinfo output
290 : *
291 : * @param[in] os The stream to write the information into
292 : * @exception IOError not yet implemented
293 : */
294 : void tripInfoOutput(OutputDevice& os) const;
295 :
296 : /** @brief Called on writing vehroute output
297 : *
298 : * @param[in] os The stream to write the information into
299 : * @exception IOError not yet implemented
300 : */
301 : void routeOutput(OutputDevice& os, const bool withRouteLength) const;
302 :
303 : /// Whether the transportable waits for the given vehicle in the current step
304 : bool isWaitingFor(const SUMOVehicle* vehicle) const {
305 2913339 : return (*myStep)->isWaitingFor(vehicle);
306 : }
307 :
308 : /// @brief Whether the transportable waits for a vehicle
309 : bool isWaiting4Vehicle() const {
310 1838466 : return (*myStep)->isWaiting4Vehicle();
311 : }
312 :
313 : void setAbortWaiting(const SUMOTime timeout);
314 :
315 : /// @brief Abort current stage (used for aborting waiting for a vehicle)
316 : SUMOTime abortStage(SUMOTime step);
317 :
318 : /// @brief The vehicle associated with this transportable
319 : SUMOVehicle* getVehicle() const {
320 373870 : return (*myStep)->getVehicle();
321 : }
322 :
323 : /// @brief Appends the given stage to the current plan
324 : void appendStage(MSStage* stage, int next = -1);
325 :
326 : /// @brief removes the nth next stage
327 : void removeStage(int next, bool stayInSim = true);
328 :
329 : /// @brief set the speed for all present and future (walking) stages and modify the vType so that stages added later are also affected
330 : void setSpeed(double speed);
331 :
332 : /// @brief returns the final arrival pos
333 : double getArrivalPos() const {
334 255 : return myPlan->back()->getArrivalPos();
335 : }
336 :
337 : /// @brief returns the final arrival edge
338 1641 : const MSEdge* getArrivalEdge() const {
339 1641 : return myPlan->back()->getEdges().back();
340 : }
341 :
342 : /** @brief Returns the end point for reroutes (usually the last edge of the route)
343 : *
344 : * @return The rerouting end point
345 : */
346 1615 : const MSEdge* getRerouteDestination() const override {
347 1615 : return getArrivalEdge();
348 : }
349 :
350 : 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);
351 :
352 : /// Replaces the current route by the given one
353 : 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;
354 :
355 : /** @brief Replaces the current vehicle type by the one given
356 : *
357 : * If the currently used vehicle type is marked as being used by this vehicle
358 : * only, it is deleted, first. The new, given type is then assigned to
359 : * "myVType".
360 : * @param[in] type The new vehicle type
361 : * @see MSTransportable::myVType
362 : */
363 : void replaceVehicleType(const MSVehicleType* type) override;
364 :
365 : /** @brief Replaces the current vehicle type with a new one used by this vehicle only
366 : *
367 : * If the currently used vehicle type is already marked as being used by this vehicle
368 : * only, no new type is created.
369 : * @return The new modifiable vehicle type
370 : * @see MSTransportable::myVType
371 : */
372 : MSVehicleType& getSingularType();
373 :
374 : /// @brief return the bounding box of the person
375 : PositionVector getBoundingBox() const;
376 :
377 : /// @brief return whether the person has reached the end of its plan
378 : bool hasArrived() const override;
379 :
380 : /// @brief return whether the transportable has started its plan
381 : bool hasDeparted() const;
382 :
383 : /// @brief adapt plan when the vehicle reroutes and now stops at replacement instead of orig
384 : void rerouteParkingArea(MSStoppingPlace* orig, MSStoppingPlace* replacement);
385 :
386 : /// @brief Returns a device of the given type if it exists or nullptr if not
387 : MSDevice* getDevice(const std::type_info& type) const override;
388 :
389 : /// @brief set individual junction model paramete (not type related)
390 : void setJunctionModelParameter(const std::string& key, const std::string& value);
391 :
392 : /** @brief Returns this vehicle's devices
393 : * @return This vehicle's devices
394 : */
395 : inline const std::vector<MSTransportableDevice*>& getDevices() const {
396 : return myDevices;
397 : }
398 :
399 0 : virtual bool hasInfluencer() const override {
400 0 : return false;
401 : }
402 :
403 : /// @brief whether this transportable is selected in the GUI
404 0 : virtual bool isSelected() const override {
405 0 : return false;
406 : }
407 :
408 : /// @brief return routing mode (configures router choice but also handling of transient permission changes)
409 : virtual int getRoutingMode() const override;
410 :
411 : /** @brief Saves the current state into the given stream
412 : */
413 : void saveState(OutputDevice& out);
414 :
415 : /** @brief Reconstructs the current state
416 : */
417 : void loadState(const std::string& state);
418 :
419 : protected:
420 : /// the plan of the transportable
421 : const SUMOVehicleParameter* myParameter;
422 :
423 : /// @brief This transportable's type. (mainly used for drawing related information
424 : /// Note sure if it is really necessary
425 : const MSVehicleType* myVType;
426 :
427 : /// @brief Whether events shall be written
428 : bool myWriteEvents;
429 :
430 : /// the plan of the transportable
431 : MSTransportablePlan* myPlan;
432 :
433 : /// the iterator over the route
434 : MSTransportablePlan::iterator myStep;
435 :
436 : /// @brief The devices this transportable has
437 : std::vector<MSTransportableDevice*> myDevices;
438 :
439 : private:
440 : const bool myAmPerson;
441 :
442 : const NumericalID myNumericalID;
443 :
444 : const long long int myRandomSeed;
445 :
446 : WrappingCommand<MSTransportable>* myAbortCommand;
447 :
448 : static NumericalID myCurrentNumericalIndex;
449 :
450 : private:
451 : /// @brief Invalidated copy constructor.
452 : MSTransportable(const MSTransportable&);
453 :
454 : /// @brief Invalidated assignment operator.
455 : MSTransportable& operator=(const MSTransportable&);
456 :
457 : };
|