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>
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;
46 
47 typedef std::vector<const MSEdge*> ConstMSEdgeVector;
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
58 public:
59  enum StageType {
61  WAITING = 1,
62  MOVING_WITHOUT_VEHICLE = 2, // walking for persons, tranship for containers
63  DRIVING = 3,
64  ACCESS = 4,
65  TRIP = 5
66  };
67 
72  class Stage {
73  public:
75  Stage(const MSEdge* destination, MSStoppingPlace* toStop, const double arrivalPos, StageType type);
76 
78  virtual ~Stage();
79 
81  const MSEdge* getDestination() const;
82 
85  return myDestinationStop;
86  }
87 
88  double getArrivalPos() const {
89  return myArrivalPos;
90  }
91 
93  virtual const MSEdge* getEdge() const;
94  virtual const MSEdge* getFromEdge() const;
95  virtual double getEdgePos(SUMOTime now) const;
96 
98  virtual Position getPosition(SUMOTime now) const = 0;
99 
101  virtual double getAngle(SUMOTime now) const = 0;
102 
105  return myType;
106  }
107 
109  virtual std::string getStageDescription() const = 0;
110 
112  virtual std::string getStageSummary() const = 0;
113 
115  virtual void proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, Stage* previous) = 0;
116 
118  virtual void abort(MSTransportable*) {};
119 
121  virtual void setSpeed(double) {};
122 
124  void setDeparted(SUMOTime now);
125 
127  virtual void setArrived(MSNet* net, MSTransportable* transportable, SUMOTime now);
128 
130  virtual bool isWaitingFor(const std::string& line) const;
131 
133  virtual bool isWaiting4Vehicle() const {
134  return false;
135  }
136 
138  virtual SUMOVehicle* getVehicle() const {
139  return nullptr;
140  }
141 
143  virtual SUMOTime getWaitingTime(SUMOTime now) const;
144 
146  virtual double getSpeed() const;
147 
149  virtual ConstMSEdgeVector getEdges() const;
150 
152  Position getEdgePosition(const MSEdge* e, double at, double offset) const;
153 
155  Position getLanePosition(const MSLane* lane, double at, double offset) const;
156 
158  double getEdgeAngle(const MSEdge* e, double at) const;
159 
164  virtual void tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const = 0;
165 
171  virtual void routeOutput(OutputDevice& os, const bool withRouteLength) const = 0;
172 
177  virtual void beginEventOutput(const MSTransportable& transportable, SUMOTime t, OutputDevice& os) const = 0;
178 
183  virtual void endEventOutput(const MSTransportable& transportable, SUMOTime t, OutputDevice& os) const = 0;
184 
185  protected:
188 
191 
193  double myArrivalPos;
194 
197 
200 
203 
204  private:
206  Stage(const Stage&);
207 
209  Stage& operator=(const Stage&);
210 
211  };
212 
216  class Stage_Trip : public Stage {
217  public:
219  Stage_Trip(const MSEdge* origin, const MSEdge* destination, MSStoppingPlace* toStop, const SUMOTime duration, const SVCPermissions modeSet,
220  const std::string& vTypes, const double speed, const double walkFactor, const double departPosLat, const bool hasArrivalPos, const double arrivalPos);
221 
223  virtual ~Stage_Trip();
224 
225  const MSEdge* getEdge() const;
226 
227  double getEdgePos(SUMOTime now) const;
228 
229  Position getPosition(SUMOTime now) const;
230 
231  double getAngle(SUMOTime now) const;
232 
233  std::string getStageDescription() const {
234  return "trip";
235  }
236 
237  std::string getStageSummary() const;
238 
240  virtual void setArrived(MSNet* net, MSTransportable* transportable, SUMOTime now);
241 
243  void setOrigin(const MSEdge* origin) {
244  myOrigin = origin;
245  }
246 
248  virtual void proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, Stage* previous);
249 
255  virtual void tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const;
256 
262  virtual void routeOutput(OutputDevice& os, const bool withRouteLength) const;
263 
268  virtual void beginEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const;
269 
274  virtual void endEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const;
275 
276  private:
278  const MSEdge* myOrigin;
279 
282 
285 
287  const std::string myVTypes;
288 
290  const double mySpeed;
291 
293  const double myWalkFactor;
294 
296  double myDepartPos;
297 
299  const double myDepartPosLat;
300 
302  const bool myHaveArrivalPos;
303 
304  private:
306  Stage_Trip(const Stage_Trip&);
307 
310 
311  };
312 
316  class Stage_Waiting : public Stage {
317  public:
319  Stage_Waiting(const MSEdge* destination, SUMOTime duration, SUMOTime until,
320  double pos, const std::string& actType, const bool initial);
321 
323  virtual ~Stage_Waiting();
324 
326  void abort(MSTransportable*);
327 
328  SUMOTime getUntil() const;
329 
331  Position getPosition(SUMOTime now) const;
332 
333  double getAngle(SUMOTime now) const;
334 
335  SUMOTime getWaitingTime(SUMOTime now) const;
336 
337  std::string getStageDescription() const {
338  return "waiting (" + myActType + ")";
339  }
340 
341  std::string getStageSummary() const;
342 
344  virtual void proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, Stage* previous);
345 
351  virtual void tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const;
352 
358  virtual void routeOutput(OutputDevice& os, const bool withRouteLength) const;
359 
364  virtual void beginEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const;
365 
370  virtual void endEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const;
371 
372  private:
375 
378 
380  std::string myActType;
381 
382  private:
385 
388 
389  };
390 
395  class Stage_Driving : public Stage {
396  public:
398  Stage_Driving(const MSEdge* destination, MSStoppingPlace* toStop,
399  const double arrivalPos, const std::vector<std::string>& lines,
400  const std::string& intendedVeh = "", SUMOTime intendedDepart = -1);
401 
403  virtual ~Stage_Driving();
404 
406  void abort(MSTransportable*);
407 
409  const MSEdge* getEdge() const;
410  const MSEdge* getFromEdge() const;
411  double getEdgePos(SUMOTime now) const;
412 
414  Position getPosition(SUMOTime now) const;
415 
416  double getAngle(SUMOTime now) const;
417 
419  bool isWaitingFor(const std::string& line) const;
420 
422  bool isWaiting4Vehicle() const;
423 
425  std::string getWaitingDescription() const;
426 
428  return myVehicle;
429  }
430 
432  SUMOTime getWaitingTime(SUMOTime now) const;
433 
434  double getSpeed() const;
435 
436  ConstMSEdgeVector getEdges() const;
437 
438  void setDestination(const MSEdge* newDestination, MSStoppingPlace* newDestStop);
439 
440  void setVehicle(SUMOVehicle* v);
441 
443  void setArrived(MSNet* net, MSTransportable* transportable, SUMOTime now);
444 
449  virtual void beginEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const;
450 
455  virtual void endEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const;
456 
457  protected:
459  const std::set<std::string> myLines;
460 
464  std::string myVehicleID;
465  std::string myVehicleLine;
466 
469 
470  double myWaitingPos;
475 
476  std::string myIntendedVehicleID;
478 
479  private:
482 
485 
486  };
487 
489  typedef std::vector<MSTransportable::Stage*> MSTransportablePlan;
490 
492  MSTransportable(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportablePlan* plan);
493 
495  virtual ~MSTransportable();
496 
497  /* @brief proceeds to the next step of the route,
498  * @return Whether the transportables plan continues */
499  virtual bool proceed(MSNet* net, SUMOTime time) = 0;
500 
502  const std::string& getID() const;
503 
504  inline const SUMOVehicleParameter& getParameter() const {
505  return *myParameter;
506  }
507 
508  inline const MSVehicleType& getVehicleType() const {
509  return *myVType;
510  }
511 
513  SUMOTime getDesiredDepart() const;
514 
516  void setDeparted(SUMOTime now);
517 
519  const MSEdge* getDestination() const {
520  return (*myStep)->getDestination();
521  }
522 
524  const MSEdge* getNextDestination() const {
525  return (*(myStep + 1))->getDestination();
526  }
527 
529  const MSEdge* getEdge() const {
530  return (*myStep)->getEdge();
531  }
532 
534  const MSEdge* getFromEdge() const {
535  return (*myStep)->getFromEdge();
536  }
537 
539  virtual double getEdgePos() const;
540 
542  virtual Position getPosition() const;
543 
545  virtual double getAngle() const;
546 
548  virtual double getWaitingSeconds() const;
549 
551  virtual double getSpeed() const;
552 
554  virtual double getSpeedFactor() const {
555  return 1;
556  }
557 
560  return (*myStep)->getStageType();
561  }
562 
564  StageType getStageType(int next) const {
565  assert(myStep + next < myPlan->end());
566  assert(myStep + next >= myPlan->begin());
567  return (*(myStep + next))->getStageType();
568  }
569 
571  std::string getStageSummary(int stageIndex) const;
572 
574  std::string getCurrentStageDescription() const {
575  return (*myStep)->getStageDescription();
576  }
577 
580  return *myStep;
581  }
582 
585  assert(myStep + next >= myPlan->begin());
586  assert(myStep + next < myPlan->end());
587  return *(myStep + next);
588  }
589 
591  ConstMSEdgeVector getEdges(int next) const {
592  assert(myStep + next < myPlan->end());
593  assert(myStep + next >= myPlan->begin());
594  return (*(myStep + next))->getEdges();
595  }
596 
598  int getNumRemainingStages() const;
599 
601  int getNumStages() const;
602 
608  virtual void tripInfoOutput(OutputDevice& os) const = 0;
609 
615  virtual void routeOutput(OutputDevice& os, const bool withRouteLength) const = 0;
616 
618  bool isWaitingFor(const std::string& line) const {
619  return (*myStep)->isWaitingFor(line);
620  }
621 
623  bool isWaiting4Vehicle() const {
624  return (*myStep)->isWaiting4Vehicle();
625  }
626 
629  return (*myStep)->getVehicle();
630  }
631 
633  void appendStage(Stage* stage, int next = -1);
634 
636  void removeStage(int next);
637 
639  void setSpeed(double speed);
640 
642  double getArrivalPos() const {
643  return myPlan->back()->getArrivalPos();
644  }
645 
647  const MSEdge* getArrivalEdge() const {
648  return myPlan->back()->getEdges().back();
649  }
650 
659  void replaceVehicleType(MSVehicleType* type);
660 
661 
670 
671 
674 
676  bool hasArrived() const;
677 
679  void rerouteParkingArea(MSStoppingPlace* orig, MSStoppingPlace* replacement);
680 
681 
682 protected:
684  static const double ROADSIDE_OFFSET;
685 
688 
692 
695 
697  MSTransportablePlan* myPlan;
698 
700  MSTransportablePlan::iterator myStep;
701 
702 private:
705 
708 
709 };
710 
711 
712 #endif
713 
714 /****************************************************************************/
SUMOVehicle * getVehicle() const
The vehicle associated with this transportable.
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 setArrived(MSNet *net, MSTransportable *transportable, SUMOTime now)
logs end of the step
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.
const SVCPermissions myModeSet
The allowed modes of transportation.
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.
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
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
SUMOTime myDuration
the time the trip should take (applies to only walking)
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:84
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
double myDepartPos
The depart position.
const double myWalkFactor
The factor to apply to walking durations.
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
const double mySpeed
The walking speed.
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
std::string getStageDescription() const
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.
virtual void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const =0
Called on writing tripinfo output.
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)
void setOrigin(const MSEdge *origin)
change origin for parking area rerouting
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
const MSEdge * myOrigin
the origin 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 void routeOutput(OutputDevice &os, const bool withRouteLength) const =0
Called on writing vehroute output.
virtual std::string getStageSummary() const =0
return string summary of the current stage
const std::string myVTypes
The possible vehicles to use.
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
const double myDepartPosLat
The lateral depart position.
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
const bool myHaveArrivalPos
whether an arrivalPos was in the input
Representation of a lane in the micro simulation.
Definition: MSLane.h:78
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