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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // The common superclass for modelling transportable objects like persons and containers
18 /****************************************************************************/
19 #ifndef MSTransportable_h
20 #define MSTransportable_h
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <set>
32 #include <cassert>
33 #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  virtual 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, MSTransportable* transportable) 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, MSTransportable* transportable) 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 
329  std::string getWaitingDescription() const;
330 
332  return myVehicle;
333  }
334 
336  SUMOTime getWaitingTime(SUMOTime now) const;
337 
338  double getSpeed() const;
339 
340  ConstMSEdgeVector getEdges() const;
341 
342  void setVehicle(SUMOVehicle* v);
343 
345  void setArrived(SUMOTime now);
346 
351  virtual void beginEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const;
352 
357  virtual void endEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const;
358 
359  protected:
361  const std::set<std::string> myLines;
362 
366  std::string myVehicleID;
367  std::string myVehicleLine;
370 
371  double myWaitingPos;
376 
377  private:
380 
383 
384  };
385 
387  typedef std::vector<MSTransportable::Stage*> MSTransportablePlan;
388 
390  MSTransportable(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportablePlan* plan);
391 
393  virtual ~MSTransportable();
394 
395  /* @brief proceeds to the next step of the route,
396  * @return Whether the transportables plan continues */
397  virtual bool proceed(MSNet* net, SUMOTime time) = 0;
398 
400  const std::string& getID() const;
401 
402  inline const SUMOVehicleParameter& getParameter() const {
403  return *myParameter;
404  }
405 
406  inline const MSVehicleType& getVehicleType() const {
407  return *myVType;
408  }
409 
411  SUMOTime getDesiredDepart() const;
412 
414  void setDeparted(SUMOTime now);
415 
417  const MSEdge& getDestination() const {
418  return (*myStep)->getDestination();
419  }
420 
422  const MSEdge& getNextDestination() const {
423  return (*(myStep + 1))->getDestination();
424  }
425 
427  const MSEdge* getEdge() const {
428  return (*myStep)->getEdge();
429  }
430 
432  const MSEdge* getFromEdge() const {
433  return (*myStep)->getFromEdge();
434  }
435 
437  virtual double getEdgePos() const;
438 
440  virtual Position getPosition() const;
441 
443  virtual double getAngle() const;
444 
446  virtual double getWaitingSeconds() const;
447 
449  virtual double getSpeed() const;
450 
452  virtual double getSpeedFactor() const {
453  return 1;
454  }
455 
458  return (*myStep)->getStageType();
459  }
460 
462  StageType getStageType(int next) const {
463  assert(myStep + next < myPlan->end());
464  assert(myStep + next >= myPlan->begin());
465  return (*(myStep + next))->getStageType();
466  }
467 
469  std::string getCurrentStageDescription() const {
470  return (*myStep)->getStageDescription();
471  }
472 
475  return *myStep;
476  }
477 
479  ConstMSEdgeVector getEdges(int next) const {
480  assert(myStep + next < myPlan->end());
481  assert(myStep + next >= myPlan->begin());
482  return (*(myStep + next))->getEdges();
483  }
484 
486  int getNumRemainingStages() const;
487 
489  int getNumStages() const;
490 
496  virtual void tripInfoOutput(OutputDevice& os, MSTransportable* transportable) const = 0;
497 
503  virtual void routeOutput(OutputDevice& os) const = 0;
504 
506  bool isWaitingFor(const std::string& line) const {
507  return (*myStep)->isWaitingFor(line);
508  }
509 
511  bool isWaiting4Vehicle() const {
512  return (*myStep)->isWaiting4Vehicle();
513  }
514 
517  return (*myStep)->getVehicle();
518  }
519 
521  void appendStage(Stage* stage, int next = -1);
522 
524  void removeStage(int next);
525 
527  void setSpeed(double speed);
528 
530  double getArrivalPos() const {
531  return myPlan->back()->getArrivalPos();
532  }
533 
535  const MSEdge* getArrivalEdge() const {
536  return myPlan->back()->getEdges().back();
537  }
538 
547  void replaceVehicleType(MSVehicleType* type);
548 
549 
558 
559 
562 
563 protected:
565  static const double ROADSIDE_OFFSET;
566 
569 
573 
576 
578  MSTransportablePlan* myPlan;
579 
581  MSTransportablePlan::iterator myStep;
582 
583 private:
586 
589 
590 };
591 
592 
593 #endif
594 
595 /****************************************************************************/
SUMOVehicle * getVehicle() const
The vehicle associated with this transportable.
virtual void setArrived(SUMOTime now)
logs end of the step
const MSEdge & getNextDestination() const
Returns the destination after the current destination.
std::string myActType
The type of activity.
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.
const MSEdge & getDestination() const
Returns the current destination.
std::vector< const MSEdge * > ConstMSEdgeVector
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.
virtual const MSEdge * getEdge() const =0
Returns the current edge.
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:78
Position getLanePosition(const MSLane *lane, double at, double offset) const
get position on lane at length at with orthogonal offset
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:90
The car-following model and parameter.
Definition: MSVehicleType.h:72
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:80
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
MSTransportable::Stage * getCurrentStage() const
Return the current stage.
virtual Position getPosition(SUMOTime now) const =0
returns the position of the transportable
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:66
MSStoppingPlace *const myDestinationStop
the stop to reach by getting transported (if any)
virtual double getEdgePos(SUMOTime now) const =0
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
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 string representation of the current stage
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 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.
std::string getStageDescription() const
return string representation of the current stage
StageType myType
The type of this stage.
Structure representing possible vehicle parameter.
const MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
MSTransportable(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportablePlan *plan)
constructor
virtual SUMOTime getWaitingTime(SUMOTime now) const =0
the time this transportable spent waiting
virtual void endEventOutput(const MSTransportable &transportable, SUMOTime t, OutputDevice &os) const =0
Called for writing the events output (end of an action)
virtual double getSpeed() const =0
the speed of the transportable
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.
const MSEdge & getDestination() const
returns the destination edge
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:70
void setDeparted(SUMOTime now)
logs end of the step
virtual bool isWaiting4Vehicle() const
Whether the transportable waits for a vehicle.
MSTransportablePlan * myPlan
the plan of the transportable
long long int SUMOTime
Definition: TraCIDefs.h:51
virtual ConstMSEdgeVector getEdges() const =0
the edges of the current stage
virtual ~Stage()
destructor
Stage(const MSEdge &destination, MSStoppingPlace *toStop, const double arrivalPos, StageType type)
constructor
virtual void routeOutput(OutputDevice &os) const =0
Called on writing vehroute output.
const MSEdge & myDestination
the next edge to reach by getting transported
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
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
virtual const MSEdge * getFromEdge() const =0