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.org/sumo
3 // Copyright (C) 2001-2022 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>
27 #include <utils/geom/Position.h>
29 #include <utils/geom/Boundary.h>
32 #include "MSStage.h"
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class MSEdge;
39 class MSLane;
40 class MSNet;
41 class MSStoppingPlace;
42 class MSVehicleType;
43 class OutputDevice;
45 class SUMOVehicle;
47 
48 typedef std::vector<const MSEdge*> ConstMSEdgeVector;
49 
50 // ===========================================================================
51 // class definitions
52 // ===========================================================================
59 public:
62  bool isPerson() const {
63  return myAmPerson;
64  }
65 
66  bool isContainer() const {
67  return !myAmPerson;
68  }
69 
70  bool isStopped() const {
72  }
73 
74  double getSlope() const;
75 
76  double getChosenSpeedFactor() const {
77  return 1.0;
78  }
79 
81 
82  double getMaxSpeed() const;
83 
84  SUMOTime getWaitingTime() const;
85 
86  double getPreviousSpeed() const {
87  return getSpeed();
88  }
89 
90  double getAcceleration() const {
91  return 0.0;
92  }
93 
94  double getPositionOnLane() const {
95  return getEdgePos();
96  }
97 
98  double getBackPositionOnLane(const MSLane* lane) const;
99 
100  Position getPosition(const double /*offset*/) const {
101  return getPosition();
102  }
104 
106  typedef std::vector<MSStage*> MSTransportablePlan;
107 
109  MSTransportable(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportablePlan* plan, const bool isPerson);
110 
112  virtual ~MSTransportable();
113 
114  /* @brief proceeds to the next step of the route,
115  * @return Whether the transportables plan continues */
116  virtual bool proceed(MSNet* net, SUMOTime time, const bool vehicleArrived = false);
117 
118  virtual bool checkAccess(const MSStage* const prior, const bool waitAtStop = true) {
119  UNUSED_PARAMETER(prior);
120  UNUSED_PARAMETER(waitAtStop);
121  return false;
122  }
123 
125  void setID(const std::string& newID);
126 
127  inline const SUMOVehicleParameter& getParameter() const {
128  return *myParameter;
129  }
130 
131  inline const MSVehicleType& getVehicleType() const {
132  return *myVType;
133  }
134 
136  SumoRNG* getRNG() const;
137 
139  SUMOTime getDesiredDepart() const;
140 
142  void setDeparted(SUMOTime now);
143 
145  SUMOTime getDeparture() const;
146 
148  const MSEdge* getDestination() const {
149  return (*myStep)->getDestination();
150  }
151 
153  const MSEdge* getNextDestination() const {
154  return (*(myStep + 1))->getDestination();
155  }
156 
158  const MSEdge* getEdge() const {
159  return (*myStep)->getEdge();
160  }
161 
163  const MSLane* getLane() const {
164  return (*myStep)->getLane();
165  }
166 
168  const MSEdge* getFromEdge() const {
169  return (*myStep)->getFromEdge();
170  }
171 
173  virtual double getEdgePos() const;
174 
176  virtual int getDirection() const;
177 
179  virtual Position getPosition() const;
180 
182  virtual double getAngle() const;
183 
185  virtual double getWaitingSeconds() const;
186 
188  virtual double getSpeed() const;
189 
191  virtual double getSpeedFactor() const {
192  return 1;
193  }
194 
197  return (*myStep)->getStageType();
198  }
199 
201  MSStageType getStageType(int next) const {
202  assert(myStep + next < myPlan->end());
203  assert(myStep + next >= myPlan->begin());
204  return (*(myStep + next))->getStageType();
205  }
206 
208  std::string getStageSummary(int stageIndex) const;
209 
211  std::string getCurrentStageDescription() const {
212  return (*myStep)->getStageDescription(myAmPerson);
213  }
214 
217  return *myStep;
218  }
219 
221  MSStage* getNextStage(int next) const {
222  assert(myStep + next >= myPlan->begin());
223  assert(myStep + next < myPlan->end());
224  return *(myStep + next);
225  }
226 
228  ConstMSEdgeVector getEdges(int next) const {
229  assert(myStep + next < myPlan->end());
230  assert(myStep + next >= myPlan->begin());
231  return (*(myStep + next))->getEdges();
232  }
233 
235  int getNumRemainingStages() const;
236 
238  int getNumStages() const;
239 
245  void tripInfoOutput(OutputDevice& os) const;
246 
252  void routeOutput(OutputDevice& os, const bool withRouteLength) const;
253 
255  bool isWaitingFor(const SUMOVehicle* vehicle) const {
256  return (*myStep)->isWaitingFor(vehicle);
257  }
258 
260  bool isWaiting4Vehicle() const {
261  return (*myStep)->isWaiting4Vehicle();
262  }
263 
266  return (*myStep)->getVehicle();
267  }
268 
270  void appendStage(MSStage* stage, int next = -1);
271 
273  void removeStage(int next, bool stayInSim = true);
274 
276  void setSpeed(double speed);
277 
279  double getArrivalPos() const {
280  return myPlan->back()->getArrivalPos();
281  }
282 
284  const MSEdge* getArrivalEdge() const {
285  return myPlan->back()->getEdges().back();
286  }
287 
296  void replaceVehicleType(MSVehicleType* type);
297 
298 
307 
308 
311 
313  bool hasArrived() const;
314 
316  bool hasDeparted() const;
317 
319  void rerouteParkingArea(MSStoppingPlace* orig, MSStoppingPlace* replacement);
320 
322  MSTransportableDevice* getDevice(const std::type_info& type) const;
323 
327  inline const std::vector<MSTransportableDevice*>& getDevices() const {
328  return myDevices;
329  }
330 
331  virtual bool hasInfluencer() const {
332  return false;
333  }
334 
336  virtual bool isSelected() const {
337  return false;
338  }
339 
342  void saveState(OutputDevice& out);
343 
346  void loadState(const std::string& state);
347 
348 protected:
351 
355 
358 
361 
363  MSTransportablePlan::iterator myStep;
364 
366  std::vector<MSTransportableDevice*> myDevices;
367 
368 private:
369  const bool myAmPerson;
370 
371 private:
374 
377 
378 };
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
MSStageType
Definition: MSStage.h:54
std::vector< const MSEdge * > ConstMSEdgeVector
long long int SUMOTime
Definition: SUMOTime.h:32
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:30
A road/street connecting two junctions.
Definition: MSEdge.h:77
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
The simulated network and simulation perfomer.
Definition: MSNet.h:88
A lane area vehicles can halt at.
Abstract in-person device.
double getChosenSpeedFactor() const
virtual double getEdgePos() const
Return the position on the edge.
bool hasDeparted() const
return whether the transportable has started it's plan
SUMOVehicleClass getVClass() const
Returns the object's access class.
SUMOTime getWaitingTime() const
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
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.
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)
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)
MSTransportableDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
void setDeparted(SUMOTime now)
logs depart time of the current stage
void setSpeed(double speed)
sets the walking speed (ignored in other stages)
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...
const MSVehicleType & getVehicleType() const
Returns the object's "vehicle" type.
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.
ConstMSEdgeVector getEdges(int next) const
Return the edges of the nth next stage.
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 persons plan.
MSStageType getCurrentStageType() const
the current stage type of the transportable
void rerouteParkingArea(MSStoppingPlace *orig, MSStoppingPlace *replacement)
adapt plan when the vehicle reroutes and now stops at replacement instead of orig
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.
MSStage * getNextStage(int next) const
Return the current stage.
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.
void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
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)
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.
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
const MSEdge * getDestination() const
Returns the current destination.
void setID(const std::string &newID)
set the id (inherited from Named but forbidden for transportables)
virtual double getSpeedFactor() const
the current speed factor of the transportable (where applicable)
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.
double getMaxSpeed() const
Returns the object's maximum speed.
The car-following model and parameter.
Definition: MSVehicleType.h:62
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.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
Structure representing possible vehicle parameter.