Eclipse SUMO - Simulation of Urban MObility
MSStage.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>
27 #include <utils/geom/Position.h>
29 #include <utils/geom/Boundary.h>
32 
33 
34 // ===========================================================================
35 // class declarations
36 // ===========================================================================
37 class MSEdge;
38 class MSLane;
39 class MSNet;
40 class MSStoppingPlace;
41 class MSVehicleType;
42 class OutputDevice;
44 class SUMOVehicle;
46 class MSTransportable;
48 
49 typedef std::vector<const MSEdge*> ConstMSEdgeVector;
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
54 enum class MSStageType {
56  WAITING = 1,
57  WALKING = 2, // only for persons
58  DRIVING = 3,
59  ACCESS = 4,
60  TRIP = 5,
61  TRANSHIP = 6
62 };
63 
68 class MSStage : public Parameterised {
69 public:
71  MSStage(const MSStageType type, const MSEdge* destination, MSStoppingPlace* toStop, const double arrivalPos,
72  const double arrivalPosLat = 0.0, const std::string& group = "");
73 
75  virtual ~MSStage();
76 
78  virtual void init(MSTransportable* /*transportable*/) {};
79 
81  const MSEdge* getDestination() const;
82 
85  return myDestinationStop;
86  }
87 
89  virtual MSStoppingPlace* getOriginStop() const {
90  return nullptr;
91  }
92 
93  virtual double getArrivalPos() const {
94  return myArrivalPos;
95  }
96 
97  virtual double getArrivalPosLat() const {
98  return myArrivalPosLat;
99  }
100 
101  void setArrivalPos(double arrivalPos) {
102  myArrivalPos = arrivalPos;
103  }
104 
106  virtual const MSEdge* getEdge() const;
107  virtual const MSEdge* getFromEdge() const;
108  virtual double getEdgePos(SUMOTime now) const;
109  virtual double getEdgePosLat(SUMOTime now) const;
110 
112  virtual int getDirection() const;
113 
115  virtual Position getPosition(SUMOTime now) const = 0;
116 
118  virtual double getAngle(SUMOTime now) const = 0;
119 
121  virtual const MSLane* getLane() const {
122  return nullptr;
123  }
124 
127  return myType;
128  }
129 
131  const std::string& getGroup() const {
132  return myGroup;
133  }
134 
136  virtual std::string getStageDescription(const bool isPerson) const = 0;
137 
139  virtual std::string getStageSummary(const bool isPerson) const = 0;
140 
142  virtual void proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, MSStage* previous) = 0;
143 
145  virtual void abort(MSTransportable*) {};
146 
148  virtual void setSpeed(double) {};
149 
151  SUMOTime getDeparted() const;
152 
154  SUMOTime getArrived() const;
155 
156  virtual SUMOTime getTimeLoss(const MSTransportable* transportable) const;
157  virtual SUMOTime getDuration() const;
158  virtual SUMOTime getTravelTime() const;
159  virtual SUMOTime getWaitingTime() const;
160 
162  void setDeparted(SUMOTime now);
163 
165  virtual const std::string setArrived(MSNet* net, MSTransportable* transportable, SUMOTime now, const bool vehicleArrived);
166 
168  virtual bool isWaitingFor(const SUMOVehicle* vehicle) const;
169 
171  virtual bool isWaiting4Vehicle() const {
172  return false;
173  }
174 
176  virtual bool isWalk() const {
177  return false;
178  }
179 
181  virtual SUMOVehicle* getVehicle() const {
182  return nullptr;
183  }
184 
186  virtual SUMOTime getWaitingTime(SUMOTime now) const;
187 
189  virtual double getSpeed() const;
190 
192  virtual ConstMSEdgeVector getEdges() const;
193 
195  virtual int getRoutePosition() const {
196  return 0;
197  }
198 
200  Position getEdgePosition(const MSEdge* e, double at, double offset) const;
201 
203  Position getLanePosition(const MSLane* lane, double at, double offset) const;
204 
206  double getEdgeAngle(const MSEdge* e, double at) const;
207 
208  void setDestination(const MSEdge* newDestination, MSStoppingPlace* newDestStop);
209 
211  virtual double getDistance() const = 0;
212 
217  virtual void tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const = 0;
218 
226  virtual void routeOutput(const bool isPerson, OutputDevice& os, const bool withRouteLength, const MSStage* const previous) const = 0;
227 
228  virtual MSStage* clone() const = 0;
229 
232  virtual void saveState(std::ostringstream& out) {
233  UNUSED_PARAMETER(out);
234  }
235 
238  virtual void loadState(MSTransportable* transportable, std::istringstream& state) {
239  UNUSED_PARAMETER(transportable);
240  UNUSED_PARAMETER(state);
241  }
242 
243  bool wasSet(int what) const {
244  return (myParametersSet & what) != 0;
245  }
246 
247  void markSet(int what) {
248  myParametersSet |= what;
249  }
250 
255  double getCosts() const {
256  return myCosts;
257  }
258 
263  void setCosts(double costs) {
264  myCosts = costs;
265  }
266 
267 protected:
270 
273 
275  double myArrivalPos;
276 
279 
282 
285 
288 
290  const std::string myGroup;
291 
293  double myCosts;
294 
297 
299  static const double ROADSIDE_OFFSET;
300 
301 private:
303  MSStage(const MSStage&);
304 
306  MSStage& operator=(const MSStage&) = delete;
307 
308 };
long long int SUMOTime
Definition: GUI.h:35
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
MSStageType
Definition: MSStage.h:54
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSStage.h:47
#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:84
The simulated network and simulation perfomer.
Definition: MSNet.h:89
virtual MSStoppingPlace * getOriginStop() const
returns the origin stop (if any). only needed for MSStageTrip
Definition: MSStage.h:89
virtual ~MSStage()
destructor
Definition: MSStage.cpp:61
const MSEdge * getDestination() const
returns the destination edge
Definition: MSStage.cpp:65
double myArrivalPosLat
the lateral position at which we want to arrive
Definition: MSStage.h:278
MSStage(const MSStage &)
Invalidated copy constructor.
virtual ConstMSEdgeVector getEdges() const
the edges of the current stage
Definition: MSStage.cpp:113
virtual bool isWalk() const
Whether the transportable is walking.
Definition: MSStage.h:176
virtual double getEdgePos(SUMOTime now) const
Definition: MSStage.cpp:83
virtual int getDirection() const
Return the movement directon on the edge.
Definition: MSStage.cpp:95
virtual void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const =0
Called on writing tripinfo output.
virtual const MSEdge * getFromEdge() const
Definition: MSStage.cpp:77
virtual double getEdgePosLat(SUMOTime now) const
Definition: MSStage.cpp:89
virtual double getArrivalPos() const
Definition: MSStage.h:93
int myParametersSet
Information on which parameter were set (mainly for vehroute output)
Definition: MSStage.h:296
virtual SUMOTime getTimeLoss(const MSTransportable *transportable) const
Definition: MSStage.cpp:155
virtual MSStage * clone() const =0
virtual void setSpeed(double)
sets the walking speed (ignored in other stages)
Definition: MSStage.h:148
virtual const MSLane * getLane() const
Returns the current lane (if applicable)
Definition: MSStage.h:121
virtual SUMOVehicle * getVehicle() const
Current vehicle in which the transportable is driving (or nullptr)
Definition: MSStage.h:181
virtual void init(MSTransportable *)
initialization, e.g. for param-related events
Definition: MSStage.h:78
virtual void saveState(std::ostringstream &out)
Saves the current state into the given stream, standard implementation does nothing.
Definition: MSStage.h:232
virtual SUMOTime getTravelTime() const
Definition: MSStage.cpp:145
SUMOTime getDeparted() const
get departure time of stage
Definition: MSStage.cpp:128
void setDeparted(SUMOTime now)
logs end of the step
Definition: MSStage.cpp:121
virtual bool isWaitingFor(const SUMOVehicle *vehicle) const
Whether the transportable waits for the given vehicle.
Definition: MSStage.cpp:167
MSStoppingPlace * myDestinationStop
the stop to reach by getting transported (if any)
Definition: MSStage.h:272
virtual std::string getStageDescription(const bool isPerson) const =0
return (brief) string representation of the current stage
const std::string myGroup
The id of the group of transportables traveling together.
Definition: MSStage.h:290
virtual const std::string setArrived(MSNet *net, MSTransportable *transportable, SUMOTime now, const bool vehicleArrived)
logs end of the step
Definition: MSStage.cpp:161
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
Definition: MSStage.h:84
SUMOTime getArrived() const
get arrival time of stage
Definition: MSStage.cpp:133
double getCosts() const
Returns the costs of the stage.
Definition: MSStage.h:255
virtual std::string getStageSummary(const bool isPerson) const =0
return string summary of the current stage
virtual void loadState(MSTransportable *transportable, std::istringstream &state)
Reconstructs the current state, standard implementation does nothing.
Definition: MSStage.h:238
virtual Position getPosition(SUMOTime now) const =0
returns the position of the transportable
bool wasSet(int what) const
Definition: MSStage.h:243
MSStageType getStageType() const
Definition: MSStage.h:126
void setArrivalPos(double arrivalPos)
Definition: MSStage.h:101
virtual double getDistance() const =0
get travel distance in this stage
virtual void proceed(MSNet *net, MSTransportable *transportable, SUMOTime now, MSStage *previous)=0
proceeds to this stage
void setCosts(double costs)
Sets the costs of the stage.
Definition: MSStage.h:263
virtual void abort(MSTransportable *)
abort this stage (TraCI)
Definition: MSStage.h:145
MSStage(const MSStageType type, const MSEdge *destination, MSStoppingPlace *toStop, const double arrivalPos, const double arrivalPosLat=0.0, const std::string &group="")
constructor
Definition: MSStage.cpp:47
virtual double getSpeed() const
the speed of the transportable
Definition: MSStage.cpp:107
double myCosts
The assigned or calculated costs.
Definition: MSStage.h:293
virtual bool isWaiting4Vehicle() const
Whether the transportable waits for a vehicle.
Definition: MSStage.h:171
virtual SUMOTime getWaitingTime() const
Definition: MSStage.cpp:150
virtual SUMOTime getDuration() const
Definition: MSStage.cpp:139
SUMOTime myArrived
the time at which this stage ended
Definition: MSStage.h:284
void setDestination(const MSEdge *newDestination, MSStoppingPlace *newDestStop)
Definition: MSStage.cpp:189
virtual void routeOutput(const bool isPerson, OutputDevice &os, const bool withRouteLength, const MSStage *const previous) const =0
Called on writing vehroute output.
Position getLanePosition(const MSLane *lane, double at, double offset) const
get position on lane at length at with orthogonal offset
Definition: MSStage.cpp:177
virtual double getArrivalPosLat() const
Definition: MSStage.h:97
void markSet(int what)
Definition: MSStage.h:247
MSStageType myType
The type of this stage.
Definition: MSStage.h:287
double getEdgeAngle(const MSEdge *e, double at) const
get angle of the edge at a certain position
Definition: MSStage.cpp:183
virtual const MSEdge * getEdge() const
Returns the current edge.
Definition: MSStage.cpp:71
MSStage & operator=(const MSStage &)=delete
Invalidated assignment operator.
const std::string & getGroup() const
return the id of the group of transportables traveling together
Definition: MSStage.h:131
virtual int getRoutePosition() const
return index of current edge within route
Definition: MSStage.h:195
static const double ROADSIDE_OFFSET
the offset for computing positions when standing at an edge
Definition: MSStage.h:299
double myArrivalPos
the longitudinal position at which we want to arrive
Definition: MSStage.h:275
virtual double getAngle(SUMOTime now) const =0
returns the angle of the transportable
Position getEdgePosition(const MSEdge *e, double at, double offset) const
get position on edge e at length at with orthogonal offset
Definition: MSStage.cpp:172
const MSEdge * myDestination
the next edge to reach by getting transported
Definition: MSStage.h:269
SUMOTime myDeparted
the time at which this stage started
Definition: MSStage.h:281
A lane area vehicles can halt at.
Abstract in-person device.
abstract base class for managing callbacks to retrieve various state information from the model
Definition: MSPModel.h:156
The car-following model and parameter.
Definition: MSVehicleType.h:63
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
An upper class for objects with additional parameters.
Definition: Parameterised.h:41
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
Representation of a vehicle.
Definition: SUMOVehicle.h:60
Structure representing possible vehicle parameter.