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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // The common superclass for modelling transportable objects like persons and containers
16 /****************************************************************************/
17 #ifndef MSTransportable_h
18 #define MSTransportable_h
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <set>
26 #include <cassert>
27 #include <utils/common/SUMOTime.h>
29 #include <utils/geom/Position.h>
31 #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;
45 
46 typedef std::vector<const MSEdge*> ConstMSEdgeVector;
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
57 public:
58  enum StageType {
60  WAITING = 1,
61  MOVING_WITHOUT_VEHICLE = 2, // walking for persons, tranship for containers
62  DRIVING = 3,
63  ACCESS = 4
64  };
65 
70  class Stage {
71  public:
73  Stage(const MSEdge* destination, MSStoppingPlace* toStop, const double arrivalPos, StageType type);
74 
76  virtual ~Stage();
77 
79  const MSEdge* getDestination() const;
80 
83  return myDestinationStop;
84  }
85 
86  double getArrivalPos() const {
87  return myArrivalPos;
88  }
89 
91  virtual const MSEdge* getEdge() const;
92  virtual const MSEdge* getFromEdge() const;
93  virtual double getEdgePos(SUMOTime now) const;
94 
96  virtual Position getPosition(SUMOTime now) const = 0;
97 
99  virtual double getAngle(SUMOTime now) const = 0;
100 
103  return myType;
104  }
105 
107  virtual std::string getStageDescription() const = 0;
108 
110  virtual std::string getStageSummary() const = 0;
111 
113  virtual void proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, Stage* previous) = 0;
114 
116  virtual void abort(MSTransportable*) {};
117 
119  virtual void setSpeed(double) {};
120 
122  void setDeparted(SUMOTime now);
123 
125  virtual void setArrived(SUMOTime now);
126 
128  virtual bool isWaitingFor(const std::string& line) const;
129 
131  virtual bool isWaiting4Vehicle() const {
132  return false;
133  }
134 
136  virtual SUMOVehicle* getVehicle() const {
137  return nullptr;
138  }
139 
141  virtual SUMOTime getWaitingTime(SUMOTime now) const;
142 
144  virtual double getSpeed() const;
145 
147  virtual ConstMSEdgeVector getEdges() const;
148 
150  Position getEdgePosition(const MSEdge* e, double at, double offset) const;
151 
153  Position getLanePosition(const MSLane* lane, double at, double offset) const;
154 
156  double getEdgeAngle(const MSEdge* e, double at) const;
157 
162  virtual void tripInfoOutput(OutputDevice& os, MSTransportable* transportable) const = 0;
163 
168  virtual void routeOutput(OutputDevice& os) const = 0;
169 
174  virtual void beginEventOutput(const MSTransportable& transportable, SUMOTime t, OutputDevice& os) const = 0;
175 
180  virtual void endEventOutput(const MSTransportable& transportable, SUMOTime t, OutputDevice& os) const = 0;
181 
182  protected:
185 
188 
190  double myArrivalPos;
191 
194 
197 
200 
201  private:
203  Stage(const Stage&);
204 
206  Stage& operator=(const Stage&);
207 
208  };
209 
213  class Stage_Waiting : public Stage {
214  public:
216  Stage_Waiting(const MSEdge* destination, SUMOTime duration, SUMOTime until,
217  double pos, const std::string& actType, const bool initial);
218 
220  virtual ~Stage_Waiting();
221 
223  void abort(MSTransportable*);
224 
225  SUMOTime getUntil() const;
226 
228  Position getPosition(SUMOTime now) const;
229 
230  double getAngle(SUMOTime now) const;
231 
232  SUMOTime getWaitingTime(SUMOTime now) const;
233 
234  std::string getStageDescription() const {
235  return "waiting (" + myActType + ")";
236  }
237 
238  std::string getStageSummary() const;
239 
241  virtual void proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, Stage* previous);
242 
248  virtual void tripInfoOutput(OutputDevice& os, MSTransportable* transportable) const;
249 
255  virtual void routeOutput(OutputDevice& os) const;
256 
261  virtual void beginEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const;
262 
267  virtual void endEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const;
268 
269  private:
272 
275 
277  std::string myActType;
278 
279  private:
282 
285 
286  };
287 
292  class Stage_Driving : public Stage {
293  public:
295  Stage_Driving(const MSEdge* destination, MSStoppingPlace* toStop,
296  const double arrivalPos, const std::vector<std::string>& lines,
297  const std::string& intendedVeh = "", SUMOTime intendedDepart = -1);
298 
300  virtual ~Stage_Driving();
301 
303  void abort(MSTransportable*);
304 
306  const MSEdge* getEdge() const;
307  const MSEdge* getFromEdge() const;
308  double getEdgePos(SUMOTime now) const;
309 
311  Position getPosition(SUMOTime now) const;
312 
313  double getAngle(SUMOTime now) const;
314 
316  bool isWaitingFor(const std::string& line) const;
317 
319  bool isWaiting4Vehicle() const;
320 
322  std::string getWaitingDescription() const;
323 
325  return myVehicle;
326  }
327 
329  SUMOTime getWaitingTime(SUMOTime now) const;
330 
331  double getSpeed() const;
332 
333  ConstMSEdgeVector getEdges() const;
334 
335  void setDestination(const MSEdge* newDestination, MSStoppingPlace* newDestStop);
336 
337  void setVehicle(SUMOVehicle* v);
338 
340  void setArrived(SUMOTime now);
341 
346  virtual void beginEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const;
347 
352  virtual void endEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const;
353 
354  protected:
356  const std::set<std::string> myLines;
357 
361  std::string myVehicleID;
362  std::string myVehicleLine;
363 
366 
367  double myWaitingPos;
372 
373  std::string myIntendedVehicleID;
375 
376  private:
379 
382 
383  };
384 
386  typedef std::vector<MSTransportable::Stage*> MSTransportablePlan;
387 
389  MSTransportable(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportablePlan* plan);
390 
392  virtual ~MSTransportable();
393 
394  /* @brief proceeds to the next step of the route,
395  * @return Whether the transportables plan continues */
396  virtual bool proceed(MSNet* net, SUMOTime time) = 0;
397 
399  const std::string& getID() const;
400 
401  inline const SUMOVehicleParameter& getParameter() const {
402  return *myParameter;
403  }
404 
405  inline const MSVehicleType& getVehicleType() const {
406  return *myVType;
407  }
408 
410  SUMOTime getDesiredDepart() const;
411 
413  void setDeparted(SUMOTime now);
414 
416  const MSEdge* getDestination() const {
417  return (*myStep)->getDestination();
418  }
419 
421  const MSEdge* getNextDestination() const {
422  return (*(myStep + 1))->getDestination();
423  }
424 
426  const MSEdge* getEdge() const {
427  return (*myStep)->getEdge();
428  }
429 
431  const MSEdge* getFromEdge() const {
432  return (*myStep)->getFromEdge();
433  }
434 
436  virtual double getEdgePos() const;
437 
439  virtual Position getPosition() const;
440 
442  virtual double getAngle() const;
443 
445  virtual double getWaitingSeconds() const;
446 
448  virtual double getSpeed() const;
449 
451  virtual double getSpeedFactor() const {
452  return 1;
453  }
454 
457  return (*myStep)->getStageType();
458  }
459 
461  StageType getStageType(int next) const {
462  assert(myStep + next < myPlan->end());
463  assert(myStep + next >= myPlan->begin());
464  return (*(myStep + next))->getStageType();
465  }
466 
468  std::string getStageSummary(int stageIndex) const;
469 
471  std::string getCurrentStageDescription() const {
472  return (*myStep)->getStageDescription();
473  }
474 
477  return *myStep;
478  }
479 
482  assert(myStep + next >= myPlan->begin());
483  assert(myStep + next < myPlan->end());
484  return *(myStep + next);
485  }
486 
488  ConstMSEdgeVector getEdges(int next) const {
489  assert(myStep + next < myPlan->end());
490  assert(myStep + next >= myPlan->begin());
491  return (*(myStep + next))->getEdges();
492  }
493 
495  int getNumRemainingStages() const;
496 
498  int getNumStages() const;
499 
505  virtual void tripInfoOutput(OutputDevice& os, MSTransportable* transportable) const = 0;
506 
512  virtual void routeOutput(OutputDevice& os) const = 0;
513 
515  bool isWaitingFor(const std::string& line) const {
516  return (*myStep)->isWaitingFor(line);
517  }
518 
520  bool isWaiting4Vehicle() const {
521  return (*myStep)->isWaiting4Vehicle();
522  }
523 
526  return (*myStep)->getVehicle();
527  }
528 
530  void appendStage(Stage* stage, int next = -1);
531 
533  void removeStage(int next);
534 
536  void setSpeed(double speed);
537 
539  double getArrivalPos() const {
540  return myPlan->back()->getArrivalPos();
541  }
542 
544  const MSEdge* getArrivalEdge() const {
545  return myPlan->back()->getEdges().back();
546  }
547 
556  void replaceVehicleType(MSVehicleType* type);
557 
558 
567 
568 
571 
573  bool hasArrived() const;
574 
576  void rerouteParkingArea(MSStoppingPlace* orig, MSStoppingPlace* replacement);
577 
578 protected:
580  static const double ROADSIDE_OFFSET;
581 
584 
588 
591 
593  MSTransportablePlan* myPlan;
594 
596  MSTransportablePlan::iterator myStep;
597 
598 private:
601 
604 
605 };
606 
607 
608 #endif
609 
610 /****************************************************************************/
SUMOVehicle * getVehicle() const
The vehicle associated with this transportable.
virtual void setArrived(SUMOTime now)
logs end of the step
Stage(const MSEdge *destination, MSStoppingPlace *toStop, const double arrivalPos, StageType type)
constructor
long long int SUMOTime
Definition: SUMOTime.h:36
std::string myActType
The type of activity.
virtual const MSEdge * getFromEdge() const
double getArrivalPos() const
returns the final arrival pos
virtual void beginEventOutput(const MSTransportable &transportable, SUMOTime t, OutputDevice &os) const =0
Called for writing the events output (begin of an action)
virtual double getAngle(SUMOTime now) const =0
returns the angle of the transportable
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
const MSEdge * getEdge() const
Returns the current edge.
A lane area vehicles can halt at.
std::vector< const MSEdge * > ConstMSEdgeVector
bool hasArrived() const
return whether the person has reached the end of its plan
PositionVector getBoundingBox() const
return the bounding box of the person
virtual bool isWaitingFor(const std::string &line) const
Whether the transportable waits for a vehicle of the line specified.
const MSEdge * getDestination() const
returns the destination edge
virtual const MSEdge * getEdge() const
Returns the current edge.
virtual double getEdgePos(SUMOTime now) const
virtual void abort(MSTransportable *)
abort this stage (TraCI)
Stage & operator=(const Stage &)
Invalidated assignment operator.
virtual void setSpeed(double)
sets the walking speed (ignored in other stages)
const std::set< std::string > myLines
the lines to choose from
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:72
Position getLanePosition(const MSLane *lane, double at, double offset) const
get position on lane at length at with orthogonal offset
const MSEdge * myDestination
the next edge to reach by getting transported
MSStoppingPlace * myDestinationStop
the stop to reach by getting transported (if any)
ConstMSEdgeVector getEdges(int next) const
Return the edges of the nth next stage.
const SUMOVehicleParameter & getParameter() const
MSTransportablePlan::iterator myStep
the iterator over the route
int getNumRemainingStages() const
Return the number of remaining stages (including the current)
The simulated network and simulation perfomer.
Definition: MSNet.h:85
The car-following model and parameter.
Definition: MSVehicleType.h:66
const SUMOVehicleParameter * myParameter
the plan of the transportable
void removeStage(int next)
removes the nth next stage
bool myWriteEvents
Whether events shall be written.
const MSEdge * getFromEdge() const
Returns the departure edge.
SUMOTime myWaitingSince
The time since which this person is waiting for a ride.
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
A road/street connecting two junctions.
Definition: MSEdge.h:75
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
virtual ConstMSEdgeVector getEdges() const
the edges of the current stage
MSTransportable::Stage * getCurrentStage() const
Return the current stage.
virtual Position getPosition(SUMOTime now) const =0
returns the position of the transportable
MSTransportable::Stage * getNextStage(int next) const
Return the current stage.
virtual SUMOTime getWaitingTime(SUMOTime now) const
the time this transportable spent waiting
MSVehicleType * myVType
This transportable&#39;s type. (mainly used for drawing related information Note sure if it is really nec...
SUMOTime myArrived
the time at which this stage ended
SUMOTime myDeparted
the time at which this stage started
Representation of a vehicle.
Definition: SUMOVehicle.h:60
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
SUMOTime getDesiredDepart() const
Returns the desired departure time.
A list of positions.
virtual SUMOVehicle * getVehicle() const
Whether the transportable waits for a vehicle.
virtual void proceed(MSNet *net, MSTransportable *transportable, SUMOTime now, Stage *previous)=0
proceeds to this stage
virtual ~MSTransportable()
destructor
bool isWaiting4Vehicle() const
Whether the transportable waits for a vehicle.
double getArrivalPos() const
std::string myVehicleID
cached vehicle data for output after the vehicle has been removed
const std::string & getID() const
returns the id of the transportable
SUMOTime myWaitingUntil
the time until the person is waiting
SUMOVehicle * myVehicle
The taken vehicle.
virtual std::string getStageDescription() const =0
return (brief) string representation of the current stage
const MSEdge * getNextDestination() const
Returns the destination after the current destination.
bool isWaitingFor(const std::string &line) const
Whether the transportable waits for a vehicle of the line specified.
Position getEdgePosition(const MSEdge *e, double at, double offset) const
get position on edge e at length at with orthogonal offset
virtual double getSpeed() const
the speed of the transportable
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
virtual double getSpeedFactor() const
the current speed factor of the transportable (where applicable)
void appendStage(Stage *stage, int next=-1)
Appends the given stage to the current plan.
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
void rerouteParkingArea(MSStoppingPlace *orig, MSStoppingPlace *replacement)
adapt plan when the vehicle reroutes and now stops at replacement instead of orig ...
std::string getStageDescription() const
return (brief) string representation of the current stage
StageType myType
The type of this stage.
Structure representing possible vehicle parameter.
MSTransportable(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportablePlan *plan)
constructor
virtual void endEventOutput(const MSTransportable &transportable, SUMOTime t, OutputDevice &os) const =0
Called for writing the events output (end of an action)
SUMOVehicle * getVehicle() const
Whether the transportable waits for a vehicle.
StageType getStageType() const
static const double ROADSIDE_OFFSET
the offset for computing positions when standing at an edge
StageType getStageType(int next) const
the stage type for the nth next stage
void replaceVehicleType(MSVehicleType *type)
Replaces the current vehicle type by the one given.
virtual std::string getStageSummary() const =0
return string summary of the current stage
double getEdgeAngle(const MSEdge *e, double at) const
get angle of the edge at a certain position
const MSEdge * getArrivalEdge() const
returns the final arrival edge
const MSVehicleType & getVehicleType() const
virtual double getWaitingSeconds() const
the time this transportable spent waiting in seconds
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
void setDeparted(SUMOTime now)
logs end of the step
virtual bool isWaiting4Vehicle() const
Whether the transportable waits for a vehicle.
const MSEdge * getDestination() const
Returns the current destination.
MSTransportablePlan * myPlan
the plan of the transportable
virtual ~Stage()
destructor
virtual void routeOutput(OutputDevice &os) const =0
Called on writing vehroute output.
Representation of a lane in the micro simulation.
Definition: MSLane.h:71
virtual void tripInfoOutput(OutputDevice &os, MSTransportable *transportable) const =0
Called on writing tripinfo output.
SUMOTime myWaitingDuration
the time the person is waiting
int getNumStages() const
Return the total number stages in this persons plan.
double myArrivalPos
the position at which we want to arrive
StageType getCurrentStageType() const
the current stage type of the transportable