SUMO - Simulation of Urban MObility
MSTransportable.h
Go to the documentation of this file.
1 /****************************************************************************/
7 // The common superclass for modelling transportable objects like persons and containers
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 #ifndef MSTransportable_h
21 #define MSTransportable_h
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <set>
33 #include <cassert>
34 #include <utils/common/SUMOTime.h>
35 #include <utils/geom/Position.h>
37 #include <utils/geom/Boundary.h>
38 
39 
40 // ===========================================================================
41 // class declarations
42 // ===========================================================================
43 class MSEdge;
44 class MSLane;
45 class MSNet;
46 class MSStoppingPlace;
47 class MSVehicleType;
48 class OutputDevice;
51 
52 typedef std::vector<const MSEdge*> ConstMSEdgeVector;
53 
54 // ===========================================================================
55 // class definitions
56 // ===========================================================================
63 public:
64  enum StageType {
66  WAITING = 1,
67  MOVING_WITHOUT_VEHICLE = 2, // walking for persons, tranship for containers
68  DRIVING = 3
69  };
70 
75  class Stage {
76  public:
78  Stage(const MSEdge& destination, MSStoppingPlace* toStop, const double arrivalPos, StageType type);
79 
81  virtual ~Stage();
82 
84  const MSEdge& getDestination() const;
85 
88  return myDestinationStop;
89  }
90 
91  double getArrivalPos() const {
92  return myArrivalPos;
93  }
94 
96  virtual const MSEdge* getEdge() const = 0;
97  virtual const MSEdge* getFromEdge() const = 0;
98  virtual double getEdgePos(SUMOTime now) const = 0;
99 
101  virtual Position getPosition(SUMOTime now) const = 0;
102 
104  virtual double getAngle(SUMOTime now) const = 0;
105 
108  return myType;
109  }
110 
112  virtual std::string getStageDescription() 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  void setArrived(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 0;
140  }
141 
143  virtual SUMOTime getWaitingTime(SUMOTime now) const = 0;
144 
146  virtual double getSpeed() const = 0;
147 
149  virtual ConstMSEdgeVector getEdges() const = 0;
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 = 0;
165 
170  virtual void routeOutput(OutputDevice& os) const = 0;
171 
176  virtual void beginEventOutput(const MSTransportable& transportable, SUMOTime t, OutputDevice& os) const = 0;
177 
182  virtual void endEventOutput(const MSTransportable& transportable, SUMOTime t, OutputDevice& os) const = 0;
183 
184  protected:
187 
190 
192  double myArrivalPos;
193 
196 
199 
202 
203  private:
205  Stage(const Stage&);
206 
208  Stage& operator=(const Stage&);
209 
210  };
211 
215  class Stage_Waiting : public Stage {
216  public:
218  Stage_Waiting(const MSEdge& destination, SUMOTime duration, SUMOTime until,
219  double pos, const std::string& actType, const bool initial);
220 
222  virtual ~Stage_Waiting();
223 
225  void abort(MSTransportable*);
226 
228  const MSEdge* getEdge() const;
229  const MSEdge* getFromEdge() const;
230  double getEdgePos(SUMOTime now) const;
231  SUMOTime getUntil() const;
232 
234  Position getPosition(SUMOTime now) const;
235 
236  double getAngle(SUMOTime now) const;
237 
238  SUMOTime getWaitingTime(SUMOTime now) const;
239 
240  double getSpeed() const;
241 
242  ConstMSEdgeVector getEdges() const;
243 
244  std::string getStageDescription() const {
245  return "waiting (" + myActType + ")";
246  }
247 
249  virtual void proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, Stage* previous);
250 
256  virtual void tripInfoOutput(OutputDevice& os) const;
257 
263  virtual void routeOutput(OutputDevice& os) const;
264 
269  virtual void beginEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const;
270 
275  virtual void endEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const;
276 
277  private:
280 
283 
285  std::string myActType;
286 
287  private:
290 
293 
294  };
295 
300  class Stage_Driving : public Stage {
301  public:
303  Stage_Driving(const MSEdge& destination, MSStoppingPlace* toStop,
304  const double arrivalPos, const std::vector<std::string>& lines);
305 
307  virtual ~Stage_Driving();
308 
310  void abort(MSTransportable*);
311 
313  const MSEdge* getEdge() const;
314  const MSEdge* getFromEdge() const;
315  double getEdgePos(SUMOTime now) const;
316 
318  Position getPosition(SUMOTime now) const;
319 
320  double getAngle(SUMOTime now) const;
321 
323  bool isWaitingFor(const std::string& line) const;
324 
326  bool isWaiting4Vehicle() const;
327 
330  return myVehicle;
331  }
332 
334  SUMOTime getWaitingTime(SUMOTime now) const;
335 
336  double getSpeed() const;
337 
338  ConstMSEdgeVector getEdges() const;
339 
340  void setVehicle(SUMOVehicle* v);
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 
360  std::string myVehicleID;
361 
362  double myWaitingPos;
367 
368  private:
371 
374 
375  };
376 
378  typedef std::vector<MSTransportable::Stage*> MSTransportablePlan;
379 
381  MSTransportable(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportablePlan* plan);
382 
384  virtual ~MSTransportable();
385 
386  /* @brief proceeds to the next step of the route,
387  * @return Whether the transportables plan continues */
388  virtual bool proceed(MSNet* net, SUMOTime time) = 0;
389 
391  const std::string& getID() const;
392 
393  inline const SUMOVehicleParameter& getParameter() const {
394  return *myParameter;
395  }
396 
397  inline const MSVehicleType& getVehicleType() const {
398  return *myVType;
399  }
400 
402  SUMOTime getDesiredDepart() const;
403 
405  void setDeparted(SUMOTime now);
406 
408  const MSEdge& getDestination() const {
409  return (*myStep)->getDestination();
410  }
411 
413  const MSEdge& getNextDestination() const {
414  return (*(myStep + 1))->getDestination();
415  }
416 
418  const MSEdge* getEdge() const {
419  return (*myStep)->getEdge();
420  }
421 
423  const MSEdge* getFromEdge() const {
424  return (*myStep)->getFromEdge();
425  }
426 
428  virtual double getEdgePos() const;
429 
431  virtual Position getPosition() const;
432 
434  virtual double getAngle() const;
435 
437  virtual double getWaitingSeconds() const;
438 
440  virtual double getSpeed() const;
441 
443  virtual double getSpeedFactor() const {
444  return 1;
445  }
446 
449  return (*myStep)->getStageType();
450  }
451 
453  StageType getStageType(int next) const {
454  assert(myStep + next < myPlan->end());
455  assert(myStep + next >= myPlan->begin());
456  return (*(myStep + next))->getStageType();
457  }
458 
460  std::string getCurrentStageDescription() const {
461  return (*myStep)->getStageDescription();
462  }
463 
466  return *myStep;
467  }
468 
470  ConstMSEdgeVector getEdges(int next) const {
471  assert(myStep + next < myPlan->end());
472  assert(myStep + next >= myPlan->begin());
473  return (*(myStep + next))->getEdges();
474  }
475 
477  int getNumRemainingStages() const;
478 
480  int getNumStages() const;
481 
487  virtual void tripInfoOutput(OutputDevice& os) const = 0;
488 
494  virtual void routeOutput(OutputDevice& os) const = 0;
495 
497  bool isWaitingFor(const std::string& line) const {
498  return (*myStep)->isWaitingFor(line);
499  }
500 
502  bool isWaiting4Vehicle() const {
503  return (*myStep)->isWaiting4Vehicle();
504  }
505 
508  return (*myStep)->getVehicle();
509  }
510 
512  void appendStage(Stage* stage, int next = -1);
513 
515  void removeStage(int next);
516 
518  void setSpeed(double speed);
519 
521  double getArrivalPos() const {
522  return myPlan->back()->getArrivalPos();
523  }
524 
526  const MSEdge* getArrivalEdge() const {
527  return myPlan->back()->getEdges().back();
528  }
529 
538  void replaceVehicleType(MSVehicleType* type);
539 
540 
549 
550 
553 
554 protected:
556  static const double ROADSIDE_OFFSET;
557 
560 
564 
567 
569  MSTransportablePlan* myPlan;
570 
572  MSTransportablePlan::iterator myStep;
573 
574 private:
577 
580 
581 };
582 
583 
584 #endif
585 
586 /****************************************************************************/
virtual double getSpeed() const =0
the speed of the transportable
void setArrived(SUMOTime now)
logs end of the step
virtual double getAngle(SUMOTime now) const =0
returns the angle of the transportable
virtual std::string getStageDescription() const =0
return string representation of the current stage
std::string myActType
The type of activity.
StageType getStageType() const
A lane area vehicles can halt at.
double getEdgeAngle(const MSEdge *e, double at) const
get angle of the edge at a certain position
virtual double getWaitingSeconds() const
the time this transportable spent waiting in seconds
bool isWaiting4Vehicle() const
Whether the transportable waits for a vehicle.
std::vector< const MSEdge * > ConstMSEdgeVector
const SUMOVehicleParameter & getParameter() const
const MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
virtual void abort(MSTransportable *)
abort this stage (TraCI)
SUMOVehicle * getVehicle() const
The vehicle associated with this transportable.
int getNumRemainingStages() const
Return the number of remaining stages (including the current)
Stage & operator=(const Stage &)
Invalidated assignment operator.
virtual void setSpeed(double)
sets the walking speed (ignored in other stages)
Position getEdgePosition(const MSEdge *e, double at, double offset) const
get position on edge e at length at with orthogonal offset
double getArrivalPos() const
const std::set< std::string > myLines
the lines to choose from
const std::string & getID() const
returns the id of the transportable
MSTransportable::Stage * getCurrentStage() const
Return the current stage.
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:79
virtual bool isWaiting4Vehicle() const
Whether the transportable waits for a vehicle.
MSTransportablePlan::iterator myStep
the iterator over the route
SUMOVehicle * getVehicle() const
The vehicle the person is riding or 0.
virtual SUMOTime getWaitingTime(SUMOTime now) const =0
the time this transportable spent waiting
The simulated network and simulation perfomer.
Definition: MSNet.h:89
The car-following model and parameter.
Definition: MSVehicleType.h:73
virtual SUMOVehicle * getVehicle() const
Whether the transportable waits for a vehicle.
SUMOTime getDesiredDepart() const
Returns the desired departure time.
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 & getDestination() const
returns the destination edge
SUMOTime myWaitingSince
The time since which this person is waiting for a ride.
virtual void beginEventOutput(const MSTransportable &transportable, SUMOTime t, OutputDevice &os) const =0
Called for writing the events output (begin of an action)
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:81
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
PositionVector getBoundingBox() const
return the bounding box of the person
const MSVehicleType & getVehicleType() const
virtual void routeOutput(OutputDevice &os) const =0
Called on writing vehroute output.
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
const MSEdge * getEdge() const
Returns the current edge.
SUMOTime myDeparted
the time at which this stage started
Representation of a vehicle.
Definition: SUMOVehicle.h:67
virtual bool isWaitingFor(const std::string &line) const
Whether the transportable waits for a vehicle of the line specified.
MSStoppingPlace *const myDestinationStop
the stop to reach by getting transported (if any)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
StageType getCurrentStageType() const
the current stage type of the transportable
virtual void proceed(MSNet *net, MSTransportable *transportable, SUMOTime now, Stage *previous)=0
proceeds to this stage
virtual ~MSTransportable()
destructor
virtual Position getPosition(SUMOTime now) const =0
returns the position of the transportable
SUMOTime myWaitingUntil
the time until the person is waiting
SUMOVehicle * myVehicle
The taken vehicle.
std::string getStageDescription() const
return string representation of the current stage
virtual ConstMSEdgeVector getEdges() const =0
the edges of the current stage
const MSEdge & getDestination() const
Returns the current destination.
void appendStage(Stage *stage, int next=-1)
Appends the given stage to the current plan.
const MSEdge * getFromEdge() const
Returns the departure edge.
StageType myType
The type of this stage.
Structure representing possible vehicle parameter.
virtual const MSEdge * getEdge() const =0
Returns the current edge.
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)
bool isWaitingFor(const std::string &line) const
Whether the transportable waits for a vehicle of the line specified.
StageType getStageType(int next) const
the stage type for the nth next stage
static const double ROADSIDE_OFFSET
the offset for computing positions when standing at an edge
ConstMSEdgeVector getEdges(int next) const
Return the edges of the nth next stage.
void replaceVehicleType(MSVehicleType *type)
Replaces the current vehicle type by the one given.
const MSEdge & getNextDestination() const
Returns the destination after the current destination.
virtual void tripInfoOutput(OutputDevice &os) const =0
Called on writing tripinfo output.
virtual const MSEdge * getFromEdge() const =0
double getArrivalPos() const
returns the final arrival pos
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
void setDeparted(SUMOTime now)
logs end of the step
int getNumStages() const
Return the total number stages in this persons plan.
MSTransportablePlan * myPlan
the plan of the transportable
long long int SUMOTime
Definition: TraCIDefs.h:52
virtual double getSpeedFactor() const
the current speed factor of the transportable (where applicable)
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
virtual ~Stage()
destructor
Stage(const MSEdge &destination, MSStoppingPlace *toStop, const double arrivalPos, StageType type)
constructor
const MSEdge & myDestination
the next edge to reach by getting transported
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
const MSEdge * getArrivalEdge() const
returns the final arrival edge
Position getLanePosition(const MSLane *lane, double at, double offset) const
get position on lane at length at with orthogonal offset
SUMOTime myWaitingDuration
the time the person is waiting
virtual double getEdgePos(SUMOTime now) const =0
double myArrivalPos
the position at which we want to arrive