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-2020 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  return getEdgePos();
100  }
101 
102  Position getPosition(const double /*offset*/) const {
103  return getPosition();
104  }
106 
108  typedef std::vector<MSStage*> MSTransportablePlan;
109 
111  MSTransportable(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportablePlan* plan, const bool isPerson);
112 
114  virtual ~MSTransportable();
115 
116  /* @brief proceeds to the next step of the route,
117  * @return Whether the transportables plan continues */
118  virtual bool proceed(MSNet* net, SUMOTime time, const bool vehicleArrived = false);
119 
120  virtual void checkAccess(const MSStage* const prior, const bool isDisembark = true) {
121  UNUSED_PARAMETER(prior);
122  UNUSED_PARAMETER(isDisembark);
123  }
124 
126  void setID(const std::string& newID);
127 
128  inline const SUMOVehicleParameter& getParameter() const {
129  return *myParameter;
130  }
131 
132  inline const MSVehicleType& getVehicleType() const {
133  return *myVType;
134  }
135 
137  std::mt19937* getRNG() const;
138 
140  SUMOTime getDesiredDepart() const;
141 
143  void setDeparted(SUMOTime now);
144 
146  const MSEdge* getDestination() const {
147  return (*myStep)->getDestination();
148  }
149 
151  const MSEdge* getNextDestination() const {
152  return (*(myStep + 1))->getDestination();
153  }
154 
156  const MSEdge* getEdge() const {
157  return (*myStep)->getEdge();
158  }
159 
161  const MSLane* getLane() const {
162  return (*myStep)->getLane();
163  }
164 
166  const MSEdge* getFromEdge() const {
167  return (*myStep)->getFromEdge();
168  }
169 
171  virtual double getEdgePos() const;
172 
174  virtual Position getPosition() const;
175 
177  virtual double getAngle() const;
178 
180  virtual double getWaitingSeconds() const;
181 
183  virtual double getSpeed() const;
184 
186  virtual double getSpeedFactor() const {
187  return 1;
188  }
189 
192  return (*myStep)->getStageType();
193  }
194 
196  MSStageType getStageType(int next) const {
197  assert(myStep + next < myPlan->end());
198  assert(myStep + next >= myPlan->begin());
199  return (*(myStep + next))->getStageType();
200  }
201 
203  std::string getStageSummary(int stageIndex) const;
204 
206  std::string getCurrentStageDescription() const {
207  return (*myStep)->getStageDescription(myAmPerson);
208  }
209 
212  return *myStep;
213  }
214 
216  MSStage* getNextStage(int next) const {
217  assert(myStep + next >= myPlan->begin());
218  assert(myStep + next < myPlan->end());
219  return *(myStep + next);
220  }
221 
223  ConstMSEdgeVector getEdges(int next) const {
224  assert(myStep + next < myPlan->end());
225  assert(myStep + next >= myPlan->begin());
226  return (*(myStep + next))->getEdges();
227  }
228 
230  int getNumRemainingStages() const;
231 
233  int getNumStages() const;
234 
240  void tripInfoOutput(OutputDevice& os) const;
241 
247  void routeOutput(OutputDevice& os, const bool withRouteLength) const;
248 
250  bool isWaitingFor(const SUMOVehicle* vehicle) const {
251  return (*myStep)->isWaitingFor(vehicle);
252  }
253 
255  bool isWaiting4Vehicle() const {
256  return (*myStep)->isWaiting4Vehicle();
257  }
258 
261  return (*myStep)->getVehicle();
262  }
263 
265  void appendStage(MSStage* stage, int next = -1);
266 
268  void removeStage(int next);
269 
271  void setSpeed(double speed);
272 
274  double getArrivalPos() const {
275  return myPlan->back()->getArrivalPos();
276  }
277 
279  const MSEdge* getArrivalEdge() const {
280  return myPlan->back()->getEdges().back();
281  }
282 
291  void replaceVehicleType(MSVehicleType* type);
292 
293 
302 
303 
306 
308  bool hasArrived() const;
309 
311  bool hasDeparted() const;
312 
314  void rerouteParkingArea(MSStoppingPlace* orig, MSStoppingPlace* replacement);
315 
317  MSTransportableDevice* getDevice(const std::type_info& type) const;
318 
322  inline const std::vector<MSTransportableDevice*>& getDevices() const {
323  return myDevices;
324  }
325 
328  void saveState(OutputDevice& out);
329 
332  void loadState(const std::string& state);
333 
334 protected:
337 
341 
344 
347 
349  MSTransportablePlan::iterator myStep;
350 
352  std::vector<MSTransportableDevice*> myDevices;
353 
354 private:
355  const bool myAmPerson;
356 
357 private:
360 
363 
364 };
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:31
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:29
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:89
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.
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
MSTransportable & operator=(const MSTransportable &)
Invalidated assignment operator.
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
std::string getStageSummary(int stageIndex) const
return textual summary for the given stage
double getBackPositionOnLane(const MSLane *) const
Get the object's back position along the given lane.
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)
MSTransportablePlan::iterator myStep
the iterator over the route
MSTransportablePlan * myPlan
the plan of the transportable
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.
std::mt19937 * getRNG() const
returns the associated RNG
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.
void removeStage(int next)
removes the nth next stage
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.
void appendStage(MSStage *stage, int next=-1)
Appends the given stage to the current plan.
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.
SUMOVehicle * getVehicle() const
The vehicle associated with this transportable.
virtual void checkAccess(const MSStage *const prior, const bool isDisembark=true)
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:60
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
A list of positions.
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition: SUMOVehicle.h:58
Structure representing possible vehicle parameter.