Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSTransportable.h
Go to the documentation of this file.
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/****************************************************************************/
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>
28#include <utils/geom/Position.h>
30#include <utils/geom/Boundary.h>
35#include "MSStage.h"
36
37
38// ===========================================================================
39// class declarations
40// ===========================================================================
41class MSEdge;
42class MSLane;
43class MSNet;
44class MSStoppingPlace;
45class OutputDevice;
47class SUMOVehicle;
49
50
51// ===========================================================================
52// class definitions
53// ===========================================================================
60public:
63 inline bool isPerson() const override {
64 return myAmPerson;
65 }
66
67 inline bool isContainer() const override {
68 return !myAmPerson;
69 }
70
71 inline std::string getObjectType() {
72 return myAmPerson ? "Person" : "Container";
73 }
74
75 inline NumericalID getNumericalID() const override {
76 return myNumericalID;
77 }
78
80 long long int getRandomSeed() const override {
81 return myRandomSeed;
82 }
83
84 inline bool isStopped() const override {
86 }
87
88 double getSlope() const override;
89
90 SUMOVehicleClass getVClass() const override;
91
93 virtual bool isJammed() const {
94 return false;
95 }
96
100 double getMaxSpeed() const override;
101
102 SUMOTime getWaitingTime(const bool accumulated = false) const override;
103
104 double getPreviousSpeed() const override {
105 return getSpeed();
106 }
107
108 double getAcceleration() const override {
109 return 0.0;
110 }
111
112 double getPositionOnLane() const override {
113 return getEdgePos();
114 }
115
116 double getBackPositionOnLane(const MSLane* lane) const override;
117
118 Position getPosition(const double /*offset*/) const override {
119 return getPosition();
120 }
122
124 typedef std::vector<MSStage*> MSTransportablePlan;
125
127 MSTransportable(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportablePlan* plan, const bool isPerson);
128
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 virtual bool checkAccess(const MSStage* const prior, const bool waitAtStop = true) {
137 UNUSED_PARAMETER(prior);
138 UNUSED_PARAMETER(waitAtStop);
139 return false;
140 }
141
143 void setID(const std::string& newID) override;
144
145 inline const SUMOVehicleParameter& getParameter() const override {
146 return *myParameter;
147 }
148
149 inline const MSVehicleType& getVehicleType() const override {
150 return *myVType;
151 }
152
156 inline const SUMOVTypeParameter& getVTypeParameter() const override {
157 return myVType->getParameter();
158 }
159
161 SumoRNG* getRNG() const override;
162
164 int getRNGIndex() const override;
165
168
170 void setDeparted(SUMOTime now);
171
173 SUMOTime getDeparture() const;
174
176 const MSEdge* getDestination() const {
177 return (*myStep)->getDestination();
178 }
179
181 const MSEdge* getNextDestination() const {
182 return (*(myStep + 1))->getDestination();
183 }
184
186 const MSEdge* getEdge() const override {
187 return (*myStep)->getEdge();
188 }
189
190 const MSEdge* getCurrentEdge() const override;
191
193 const MSLane* getLane() const override {
194 return (*myStep)->getLane();
195 }
196
197 const MSLane* getBackLane() const override {
198 return getLane();
199 }
200
202 const MSEdge* getFromEdge() const {
203 return (*myStep)->getFromEdge();
204 }
205
207 virtual double getEdgePos() const;
208
210 virtual int getDirection() const;
211
213 virtual Position getPosition() const;
214
216 virtual double getAngle() const override;
217
219 virtual double getWaitingSeconds() const;
220
222 virtual double getSpeed() const override;
223
225 virtual double getChosenSpeedFactor() const override {
226 return 1;
227 }
228
231 return (*myStep)->getStageType();
232 }
233
235 MSStageType getStageType(int next) const {
236 assert(myStep + next < myPlan->end());
237 assert(myStep + next >= myPlan->begin());
238 return (*(myStep + next))->getStageType();
239 }
240
242 std::string getStageSummary(int stageIndex) const;
243
245 std::string getCurrentStageDescription() const {
246 return (*myStep)->getStageDescription(myAmPerson);
247 }
248
251 return *myStep;
252 }
253
255 inline MSStage* getNextStage(int offset) const {
256 assert(myStep + offset >= myPlan->begin());
257 assert(myStep + offset < myPlan->end());
258 return *(myStep + offset);
259 }
260
262 const std::set<NumericalID> getUpcomingEdgeIDs() const override;
263
265 inline int getNumStages() const {
266 return (int)myPlan->size();
267 }
268
270 inline int getNumRemainingStages() const {
271 return (int)(myPlan->end() - myStep);
272 }
273
275 inline int getCurrentStageIndex() const {
276 return (int)(myStep - myPlan->begin());
277 }
278
280 inline int getRoutePosition() const override {
281 return (*myStep)->getRoutePosition();
282 }
283
285 virtual const MSEdge* getNextEdgePtr() const override {
286 return nullptr;
287 }
288
294 void tripInfoOutput(OutputDevice& os) const;
295
301 void routeOutput(OutputDevice& os, const bool withRouteLength) const;
302
304 bool isWaitingFor(const SUMOVehicle* vehicle) const {
305 return (*myStep)->isWaitingFor(vehicle);
306 }
307
309 bool isWaiting4Vehicle() const {
310 return (*myStep)->isWaiting4Vehicle();
311 }
312
313 void setAbortWaiting(const SUMOTime timeout);
314
317
320 return (*myStep)->getVehicle();
321 }
322
324 void appendStage(MSStage* stage, int next = -1);
325
327 void removeStage(int next, bool stayInSim = true);
328
330 void setSpeed(double speed);
331
333 double getArrivalPos() const {
334 return myPlan->back()->getArrivalPos();
335 }
336
338 const MSEdge* getArrivalEdge() const {
339 return myPlan->back()->getEdges().back();
340 }
341
346 const MSEdge* getRerouteDestination() const override {
347 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
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
363 void replaceVehicleType(const MSVehicleType* type) override;
364
373
376
378 bool hasArrived() const override;
379
381 bool hasDeparted() const;
382
384 void rerouteParkingArea(MSStoppingPlace* orig, MSStoppingPlace* replacement);
385
387 MSDevice* getDevice(const std::type_info& type) const override;
388
390 void setJunctionModelParameter(const std::string& key, const std::string& value);
391
395 inline const std::vector<MSTransportableDevice*>& getDevices() const {
396 return myDevices;
397 }
398
399 virtual bool hasInfluencer() const override {
400 return false;
401 }
402
404 virtual bool isSelected() const override {
405 return false;
406 }
407
409 virtual int getRoutingMode() const override;
410
413 void saveState(OutputDevice& out);
414
417 void loadState(const std::string& state);
418
419protected:
422
426
429
432
434 MSTransportablePlan::iterator myStep;
435
437 std::vector<MSTransportableDevice*> myDevices;
438
439private:
440 const bool myAmPerson;
441
443
444 const long long int myRandomSeed;
445
447
449
450private:
453
456
457};
long long int SUMOTime
Definition GUI.h:36
MSStageType
Definition MSStage.h:55
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
Abstract in-vehicle / in-person device.
Definition MSDevice.h:62
A road/street connecting two junctions.
Definition MSEdge.h:77
Representation of a lane in the micro simulation.
Definition MSLane.h:84
The simulated network and simulation perfomer.
Definition MSNet.h:89
A lane area vehicles can halt at.
Abstract in-person device.
const MSEdge * getFromEdge() const
Returns the departure edge.
virtual double getChosenSpeedFactor() const override
the current speed factor of the transportable (where applicable)
Position getPosition(const double) const override
Return current position (x/y, cartesian)
bool isContainer() const override
Whether it is a container.
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
Replaces the current route by the given one.
virtual double getEdgePos() const
Return the position on the edge.
bool hasDeparted() const
return whether the transportable has started its plan
double getPositionOnLane() const override
Get the object's position along the lane.
NumericalID getNumericalID() const override
return the numerical ID which is only for internal usage
static NumericalID myCurrentNumericalIndex
double getBackPositionOnLane(const MSLane *lane) const override
Get the object's back position along the given lane.
const std::set< NumericalID > getUpcomingEdgeIDs() const override
returns the numerical IDs of edges to be used (possibly of future stages)
const MSLane * getLane() const override
Returns the current lane (may be nullptr)
virtual double getSpeed() const override
the current speed of the transportable
const std::vector< MSTransportableDevice * > & getDevices() const
Returns this vehicle's devices.
void replaceVehicleType(const MSVehicleType *type) override
Replaces the current vehicle type by the one given.
SUMOTime getDeparture() const
logs depart time of the current stage
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
const MSEdge * getDestination() const
Returns the current destination.
long long int getRandomSeed() const override
return transportable-specific random number
const MSEdge * getArrivalEdge() const
returns the final arrival edge
void setAbortWaiting(const SUMOTime timeout)
bool isStopped() const override
Returns whether the object is at a stop.
MSStageType getStageType(int next) const
the stage type for the nth next stage
MSStage * getNextStage(int offset) const
Return the next (or previous) stage denoted by the offset.
bool myWriteEvents
Whether events shall be written.
void routeOutput(OutputDevice &os, const bool withRouteLength) const
Called on writing vehroute output.
bool isWaiting4Vehicle() const
Whether the transportable waits for a vehicle.
const long long int myRandomSeed
void setJunctionModelParameter(const std::string &key, const std::string &value)
set individual junction model paramete (not type related)
int getNumRemainingStages() const
Return the number of remaining stages (including the current)
virtual bool hasInfluencer() const override
whether the vehicle is individually influenced (via TraCI or special parameters)
PositionVector getBoundingBox() const
return the bounding box of the person
const bool myAmPerson
virtual bool checkAccess(const MSStage *const prior, const bool waitAtStop=true)
SUMOTime abortStage(SUMOTime step)
Abort current stage (used for aborting waiting for a vehicle)
std::string getStageSummary(int stageIndex) const
return textual summary for the given stage
const MSVehicleType * myVType
This transportable's type. (mainly used for drawing related information Note sure if it is really nec...
MSTransportable & operator=(const MSTransportable &)
Invalidated assignment operator.
MSStage * getCurrentStage() const
Return the current stage.
SumoRNG * getRNG() const override
returns the associated RNG
void setDeparted(SUMOTime now)
logs depart time of the current stage
void setSpeed(double speed)
set the speed for all present and future (walking) stages and modify the vType so that stages added l...
virtual bool proceed(MSNet *net, SUMOTime time, const bool vehicleArrived=false)
SUMOVehicleClass getVClass() const override
Returns the object's access class.
double getMaxSpeed() const override
Returns the maximum speed (the minimum of desired and physical maximum speed)
MSTransportablePlan::iterator myStep
the iterator over the route
MSTransportablePlan * myPlan
the plan of the transportable
void removeStage(int next, bool stayInSim=true)
removes the nth next stage
const MSEdge * getNextDestination() const
Returns the destination after the current destination.
SUMOVehicle * getVehicle() const
The vehicle associated with this transportable.
const SUMOVTypeParameter & getVTypeParameter() const override
Returns the object's "vehicle" type parameter.
bool isPerson() const override
Whether it is a person.
double getAcceleration() const override
Returns the object's acceleration.
virtual Position getPosition() const
Return the Network coordinate of the transportable.
const SUMOVehicleParameter * myParameter
the plan of the transportable
double getArrivalPos() const
returns the final arrival pos
void saveState(OutputDevice &out)
Saves the current state into the given stream.
const MSEdge * getRerouteDestination() const override
Returns the end point for reroutes (usually the last edge of the route)
MSDevice * getDevice(const std::type_info &type) const override
Returns a device of the given type if it exists or nullptr if not.
virtual ~MSTransportable()
destructor
SUMOTime getWaitingTime(const bool accumulated=false) const override
int getNumStages() const
Return the total number stages in this person's plan.
const MSEdge * getCurrentEdge() const override
Returns the edge (normal or internal) the object is currently at.
int getCurrentStageIndex() const
Return the index of the current stage.
MSStageType getCurrentStageType() const
the current stage type of the transportable
int getRNGIndex() const override
returns the index of the associated RNG
void rerouteParkingArea(MSStoppingPlace *orig, MSStoppingPlace *replacement)
adapt plan when the vehicle reroutes and now stops at replacement instead of orig
std::string getObjectType()
const SUMOVehicleParameter & getParameter() const override
Returns the vehicle's parameter (including departure definition)
void loadState(const std::string &state)
Reconstructs the current state.
std::vector< MSTransportableDevice * > myDevices
The devices this transportable has.
virtual double getWaitingSeconds() const
the time this transportable spent waiting in seconds
int getRoutePosition() const override
return the index of the edge within the route
double getPreviousSpeed() const override
Returns the object's previous speed.
const MSVehicleType & getVehicleType() const override
Returns the object's "vehicle" type.
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)
void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
virtual int getRoutingMode() const override
return routing mode (configures router choice but also handling of transient permission changes)
const NumericalID myNumericalID
virtual double getAngle() const override
return the current angle of the transportable
void appendStage(MSStage *stage, int next=-1)
Appends the given stage to the current plan.
virtual bool isJammed() const
whether the transportable (persons) is jammed as defined by the current pedestrian model
void setID(const std::string &newID) override
set the id (inherited from Named but forbidden for transportables)
const MSLane * getBackLane() const override
Returns the lane the where the rear of the object is currently at.
MSTransportable(const MSTransportable &)
Invalidated copy constructor.
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
const MSEdge * getEdge() const override
Returns the current edge.
virtual int getDirection() const
Return the movement directon on the edge.
double getSlope() const override
Returns the slope of the road at object's position in degrees.
std::vector< MSStage * > MSTransportablePlan
the structure holding the plan of a transportable
virtual const MSEdge * getNextEdgePtr() const override
returns the next edge ptr (used by walking persons)
WrappingCommand< MSTransportable > * myAbortCommand
virtual bool isSelected() const override
whether this transportable is selected in the GUI
bool isWaitingFor(const SUMOVehicle *vehicle) const
Whether the transportable waits for the given vehicle in the current step.
bool hasArrived() const override
return whether the person has reached the end of its plan
SUMOTime getDesiredDepart() const
Returns the desired departure time.
The car-following model and parameter.
const SUMOVTypeParameter & getParameter() const
Static storage of an output device and its base (abstract) implementation.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
Representation of a vehicle, person, or container.
long long int NumericalID
Structure representing possible vehicle parameter.
Representation of a vehicle.
Definition SUMOVehicle.h:63
Structure representing possible vehicle parameter.
A wrapper for a Command function.
#define UNUSED_PARAMETER(x)