Eclipse SUMO - Simulation of Urban MObility
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-2024 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>
25 #include <utils/common/SUMOTime.h>
28 #include <utils/geom/Position.h>
30 #include <utils/geom/Boundary.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;
47 class SUMOVehicle;
49 
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
60 public:
63  inline bool isPerson() const {
64  return myAmPerson;
65  }
66 
67  inline bool isContainer() const {
68  return !myAmPerson;
69  }
70 
71  inline std::string getObjectType() {
72  return myAmPerson ? "Person" : "Container";
73  }
74 
75  inline NumericalID getNumericalID() const {
76  return myNumericalID;
77  }
78 
79  inline bool isStopped() const {
81  }
82 
83  double getSlope() const;
84 
86 
88  virtual bool isJammed() const {
89  return false;
90  }
91 
95  double getMaxSpeed() const;
96 
97  SUMOTime getWaitingTime(const bool accumulated = false) const;
98 
99  double getPreviousSpeed() const {
100  return getSpeed();
101  }
102 
103  double getAcceleration() const {
104  return 0.0;
105  }
106 
107  double getPositionOnLane() const {
108  return getEdgePos();
109  }
110 
111  double getBackPositionOnLane(const MSLane* lane) const;
112 
113  Position getPosition(const double /*offset*/) const {
114  return getPosition();
115  }
117 
119  typedef std::vector<MSStage*> MSTransportablePlan;
120 
122  MSTransportable(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportablePlan* plan, const bool isPerson);
123 
125  virtual ~MSTransportable();
126 
127  /* @brief proceeds to the next step of the route,
128  * @return Whether the transportables plan continues */
129  virtual bool proceed(MSNet* net, SUMOTime time, const bool vehicleArrived = false);
130 
131  virtual bool checkAccess(const MSStage* const prior, const bool waitAtStop = true) {
132  UNUSED_PARAMETER(prior);
133  UNUSED_PARAMETER(waitAtStop);
134  return false;
135  }
136 
138  void setID(const std::string& newID);
139 
140  inline const SUMOVehicleParameter& getParameter() const {
141  return *myParameter;
142  }
143 
144  inline const MSVehicleType& getVehicleType() const {
145  return *myVType;
146  }
147 
151  inline const SUMOVTypeParameter& getVTypeParameter() const {
152  return myVType->getParameter();
153  }
154 
156  SumoRNG* getRNG() const;
157 
159  int getRNGIndex() const;
160 
162  SUMOTime getDesiredDepart() const;
163 
165  void setDeparted(SUMOTime now);
166 
168  SUMOTime getDeparture() const;
169 
171  const MSEdge* getDestination() const {
172  return (*myStep)->getDestination();
173  }
174 
176  const MSEdge* getNextDestination() const {
177  return (*(myStep + 1))->getDestination();
178  }
179 
181  const MSEdge* getEdge() const {
182  return (*myStep)->getEdge();
183  }
184 
186  const MSLane* getLane() const {
187  return (*myStep)->getLane();
188  }
189 
191  const MSEdge* getFromEdge() const {
192  return (*myStep)->getFromEdge();
193  }
194 
196  virtual double getEdgePos() const;
197 
199  virtual int getDirection() const;
200 
202  virtual Position getPosition() const;
203 
205  virtual double getAngle() const;
206 
208  virtual double getWaitingSeconds() const;
209 
211  virtual double getSpeed() const;
212 
214  virtual double getChosenSpeedFactor() const {
215  return 1;
216  }
217 
220  return (*myStep)->getStageType();
221  }
222 
224  MSStageType getStageType(int next) const {
225  assert(myStep + next < myPlan->end());
226  assert(myStep + next >= myPlan->begin());
227  return (*(myStep + next))->getStageType();
228  }
229 
231  std::string getStageSummary(int stageIndex) const;
232 
234  std::string getCurrentStageDescription() const {
235  return (*myStep)->getStageDescription(myAmPerson);
236  }
237 
240  return *myStep;
241  }
242 
244  inline MSStage* getNextStage(int offset) const {
245  assert(myStep + offset >= myPlan->begin());
246  assert(myStep + offset < myPlan->end());
247  return *(myStep + offset);
248  }
249 
251  const std::set<NumericalID> getUpcomingEdgeIDs() const;
252 
254  inline int getNumStages() const {
255  return (int)myPlan->size();
256  }
257 
259  inline int getNumRemainingStages() const {
260  return (int)(myPlan->end() - myStep);
261  }
262 
264  inline int getCurrentStageIndex() const {
265  return (int)(myStep - myPlan->begin());
266  }
267 
269  inline int getRoutePosition() const {
270  return (*myStep)->getRoutePosition();
271  }
272 
274  virtual const MSEdge* getNextEdgePtr() const {
275  return nullptr;
276  }
277 
283  void tripInfoOutput(OutputDevice& os) const;
284 
290  void routeOutput(OutputDevice& os, const bool withRouteLength) const;
291 
293  bool isWaitingFor(const SUMOVehicle* vehicle) const {
294  return (*myStep)->isWaitingFor(vehicle);
295  }
296 
298  bool isWaiting4Vehicle() const {
299  return (*myStep)->isWaiting4Vehicle();
300  }
301 
302  void setAbortWaiting(const SUMOTime timeout);
303 
306 
309  return (*myStep)->getVehicle();
310  }
311 
313  void appendStage(MSStage* stage, int next = -1);
314 
316  void removeStage(int next, bool stayInSim = true);
317 
319  void setSpeed(double speed);
320 
322  double getArrivalPos() const {
323  return myPlan->back()->getArrivalPos();
324  }
325 
327  const MSEdge* getArrivalEdge() const {
328  return myPlan->back()->getEdges().back();
329  }
330 
335  const MSEdge* getRerouteDestination() const {
336  return getArrivalEdge();
337  }
338 
339  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);
340 
342  bool replaceRoute(ConstMSRoutePtr route, const std::string& info, bool onInit = false, int offset = 0, bool addStops = true, bool removeStops = true, std::string* msgReturn = nullptr);
343 
352  void replaceVehicleType(MSVehicleType* type);
353 
362 
365 
367  bool hasArrived() const;
368 
370  bool hasDeparted() const;
371 
373  void rerouteParkingArea(MSStoppingPlace* orig, MSStoppingPlace* replacement);
374 
376  MSDevice* getDevice(const std::type_info& type) const;
377 
379  void setJunctionModelParameter(const std::string& key, const std::string& value);
380 
384  inline const std::vector<MSTransportableDevice*>& getDevices() const {
385  return myDevices;
386  }
387 
388  virtual bool hasInfluencer() const {
389  return false;
390  }
391 
393  virtual bool isSelected() const {
394  return false;
395  }
396 
398  virtual int getRoutingMode() const;
399 
402  void saveState(OutputDevice& out);
403 
406  void loadState(const std::string& state);
407 
408 protected:
411 
415 
418 
421 
423  MSTransportablePlan::iterator myStep;
424 
426  std::vector<MSTransportableDevice*> myDevices;
427 
428 private:
429  const bool myAmPerson;
430 
432 
434 
436 
437 private:
440 
443 
444 };
long long int SUMOTime
Definition: GUI.h:35
MSStageType
Definition: MSStage.h:55
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition: Route.h:31
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:30
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.
virtual double getChosenSpeedFactor() const
the current speed factor of the transportable (where applicable)
virtual double getEdgePos() const
Return the position on the edge.
bool hasDeparted() const
return whether the transportable has started its plan
int getRNGIndex() const
returns the index of the associated RNG
SUMOVehicleClass getVClass() const
Returns the object's access class.
static NumericalID myCurrentNumericalIndex
const MSEdge * getArrivalEdge() const
returns the final arrival edge
double getAcceleration() const
Returns the object's acceleration.
SUMOTime getDeparture() const
logs depart time of the current stage
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
MSTransportable & operator=(const MSTransportable &)
Invalidated assignment operator.
double getBackPositionOnLane(const MSLane *lane) const
Get the object's back position along the given lane.
virtual double getAngle() const
return the current angle of the transportable
void setAbortWaiting(const SUMOTime timeout)
MSStageType getStageType(int next) const
the stage type for the nth next stage
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.
void setJunctionModelParameter(const std::string &key, const std::string &value)
set individual junction model paramete (not type related)
MSStage * getNextStage(int offset) const
Return the next (or previous) stage denoted by the offset.
int getNumRemainingStages() const
Return the number of remaining stages (including the current)
virtual double getSpeed() const
the current speed of the transportable
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 SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
void setDeparted(SUMOTime now)
logs depart time of the current stage
const std::set< NumericalID > getUpcomingEdgeIDs() const
returns the numerical IDs of edges to be used (possibly of future stages)
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)
virtual bool isSelected() const
whether this transportable is selected in the GUI
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
bool isStopped() const
Returns whether the object is at a stop.
MSVehicleType * myVType
This transportable's type. (mainly used for drawing related information Note sure if it is really nec...
SUMOTime getWaitingTime(const bool accumulated=false) const
const MSVehicleType & getVehicleType() const
Returns the object's "vehicle" type.
int getRoutePosition() const
return the index of the edge within the route
bool isPerson() const
Whether it is a person.
virtual Position getPosition() const
Return the Network coordinate of the transportable.
const SUMOVehicleParameter * myParameter
the plan of the transportable
double getPreviousSpeed() const
Returns the object's previous speed.
Position getPosition(const double) const
Return current position (x/y, cartesian)
double getArrivalPos() const
returns the final arrival pos
double getPositionOnLane() const
Get the object's position along the lane.
const MSEdge * getNextDestination() const
Returns the destination after the current destination.
void saveState(OutputDevice &out)
Saves the current state into the given stream.
const MSEdge * getFromEdge() const
Returns the departure edge.
bool isContainer() const
Whether it is a container.
virtual ~MSTransportable()
destructor
int getNumStages() const
Return the total number stages in this person's plan.
int getCurrentStageIndex() const
Return the index of the current stage.
MSStageType getCurrentStageType() const
the current stage type of the transportable
NumericalID getNumericalID() const
return the numerical ID which is only for internal usage
void rerouteParkingArea(MSStoppingPlace *orig, MSStoppingPlace *replacement)
adapt plan when the vehicle reroutes and now stops at replacement instead of orig
const SUMOVTypeParameter & getVTypeParameter() const
Returns the object's "vehicle" type parameter.
std::string getObjectType()
const MSEdge * getRerouteDestination() const
Returns the end point for reroutes (usually the last edge of the route)
const MSEdge * getEdge() const
Returns the current edge.
void loadState(const std::string &state)
Reconstructs the current state.
MSStage * getCurrentStage() const
Return the current stage.
std::vector< MSTransportableDevice * > myDevices
The devices this transportable has.
virtual double getWaitingSeconds() const
the time this transportable spent waiting in seconds
MSTransportable(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportablePlan *plan, const bool isPerson)
constructor
bool hasArrived() const
return whether the person has reached the end of its plan
double getSlope() const
Returns the slope of the road at object's position in degrees.
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.
const NumericalID myNumericalID
virtual bool hasInfluencer() const
whether the vehicle is individually influenced (via TraCI or special parameters)
void appendStage(MSStage *stage, int next=-1)
Appends the given stage to the current plan.
SumoRNG * getRNG() const
returns the associated RNG
const MSLane * getLane() const
Returns the current lane (may be nullptr)
virtual bool isJammed() const
whether the transportable (persons) is jammed as defined by the current pedestrian model
virtual int getRoutingMode() const
return routing mode (configures router choice but also handling of transient permission changes)
MSTransportable(const MSTransportable &)
Invalidated copy constructor.
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
const std::vector< MSTransportableDevice * > & getDevices() const
Returns this vehicle's devices.
bool replaceRoute(ConstMSRoutePtr route, const std::string &info, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true, std::string *msgReturn=nullptr)
Replaces the current route by the given one.
virtual int getDirection() const
Return the movement directon on the edge.
SUMOVehicle * getVehicle() const
The vehicle associated with this transportable.
std::vector< MSStage * > MSTransportablePlan
the structure holding the plan of a transportable
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or nullptr if not.
const MSEdge * getDestination() const
Returns the current destination.
void setID(const std::string &newID)
set the id (inherited from Named but forbidden for transportables)
WrappingCommand< MSTransportable > * myAbortCommand
void replaceVehicleType(MSVehicleType *type)
Replaces the current vehicle type by the one given.
bool isWaitingFor(const SUMOVehicle *vehicle) const
Whether the transportable waits for the given vehicle in the current step.
SUMOTime getDesiredDepart() const
Returns the desired departure time.
virtual const MSEdge * getNextEdgePtr() const
returns the next edge ptr (used by walking persons)
double getMaxSpeed() const
Returns the maximum speed (the minimum of desired and physical maximum speed)
The car-following model and parameter.
Definition: MSVehicleType.h:63
const SUMOVTypeParameter & getParameter() const
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
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:62
Structure representing possible vehicle parameter.