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>
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
41 class MSEdge;
42 class MSLane;
43 class MSNet;
44 class MSStoppingPlace;
45 class MSVehicleType;
46 class OutputDevice;
49 
50 typedef std::vector<const MSEdge*> ConstMSEdgeVector;
51 
52 // ===========================================================================
53 // class definitions
54 // ===========================================================================
61 public:
62  enum StageType {
64  WAITING = 1,
65  MOVING_WITHOUT_VEHICLE = 2, // walking for persons, tranship for containers
66  DRIVING = 3
67  };
68 
73  class Stage {
74  public:
76  Stage(const MSEdge& destination, MSStoppingPlace* toStop, const SUMOReal arrivalPos, StageType type);
77 
79  virtual ~Stage();
80 
82  const MSEdge& getDestination() const;
83 
86  return myDestinationStop;
87  }
88 
90  return myArrivalPos;
91  }
92 
94  virtual const MSEdge* getEdge() const = 0;
95  virtual const MSEdge* getFromEdge() const = 0;
96  virtual SUMOReal getEdgePos(SUMOTime now) const = 0;
97 
99  virtual Position getPosition(SUMOTime now) const = 0;
100 
102  virtual SUMOReal getAngle(SUMOTime now) const = 0;
103 
106  return myType;
107  }
108 
110  virtual std::string getStageDescription() 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(SUMOReal) {};
120 
122  void setDeparted(SUMOTime now);
123 
125  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 0;
138  }
139 
141  virtual SUMOTime getWaitingTime(SUMOTime now) const = 0;
142 
144  virtual SUMOReal getSpeed() const = 0;
145 
147  virtual ConstMSEdgeVector getEdges() const = 0;
148 
150  Position getEdgePosition(const MSEdge* e, SUMOReal at, SUMOReal offset) const;
151 
153  Position getLanePosition(const MSLane* lane, SUMOReal at, SUMOReal offset) const;
154 
156  SUMOReal getEdgeAngle(const MSEdge* e, SUMOReal at) const;
157 
162  virtual void tripInfoOutput(OutputDevice& os) 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 
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  SUMOReal pos, const std::string& actType, const bool initial);
218 
220  virtual ~Stage_Waiting();
221 
223  const MSEdge* getEdge() const;
224  const MSEdge* getFromEdge() const;
225  SUMOReal getEdgePos(SUMOTime now) const;
226  SUMOTime getUntil() const;
227 
229  Position getPosition(SUMOTime now) const;
230 
231  SUMOReal getAngle(SUMOTime now) const;
232 
233  SUMOTime getWaitingTime(SUMOTime now) const;
234 
235  SUMOReal getSpeed() const;
236 
237  ConstMSEdgeVector getEdges() const;
238 
239  std::string getStageDescription() const {
240  return "waiting (" + myActType + ")";
241  }
242 
244  virtual void proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, Stage* previous);
245 
251  virtual void tripInfoOutput(OutputDevice& os) const;
252 
258  virtual void routeOutput(OutputDevice& os) const;
259 
264  virtual void beginEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const;
265 
270  virtual void endEventOutput(const MSTransportable& p, SUMOTime t, OutputDevice& os) const;
271 
272  private:
275 
278 
281 
283  std::string myActType;
284 
285  private:
288 
291 
292  };
293 
298  class Stage_Driving : public Stage {
299  public:
301  Stage_Driving(const MSEdge& destination, MSStoppingPlace* toStop,
302  const SUMOReal arrivalPos, const std::vector<std::string>& lines);
303 
305  virtual ~Stage_Driving();
306 
308  void abort(MSTransportable*);
309 
311  const MSEdge* getEdge() const;
312  const MSEdge* getFromEdge() const;
313  SUMOReal getEdgePos(SUMOTime now) const;
314 
316  Position getPosition(SUMOTime now) const;
317 
318  SUMOReal getAngle(SUMOTime now) const;
319 
321  bool isWaitingFor(const std::string& line) const;
322 
324  bool isWaiting4Vehicle() const;
325 
328  return myVehicle;
329  }
330 
332  SUMOTime getWaitingTime(SUMOTime now) const;
333 
334  SUMOReal getSpeed() const;
335 
336  ConstMSEdgeVector getEdges() const;
337 
339  myVehicle = v;
340  }
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 
366 
367  private:
370 
373 
374  };
375 
377  typedef std::vector<MSTransportable::Stage*> MSTransportablePlan;
378 
380  MSTransportable(const SUMOVehicleParameter* pars, const MSVehicleType* vtype, MSTransportablePlan* plan);
381 
383  virtual ~MSTransportable();
384 
385  /* @brief proceeds to the next step of the route,
386  * @return Whether the transportables plan continues */
387  virtual bool proceed(MSNet* net, SUMOTime time) = 0;
388 
390  const std::string& getID() const;
391 
392  inline const SUMOVehicleParameter& getParameter() const {
393  return *myParameter;
394  }
395 
396  inline const MSVehicleType& getVehicleType() const {
397  return *myVType;
398  }
399 
401  SUMOTime getDesiredDepart() const;
402 
404  void setDeparted(SUMOTime now);
405 
407  const MSEdge& getDestination() const {
408  return (*myStep)->getDestination();
409  }
410 
412  const MSEdge& getNextDestination() const {
413  return (*(myStep + 1))->getDestination();
414  }
415 
417  const MSEdge* getEdge() const {
418  return (*myStep)->getEdge();
419  }
420 
422  const MSEdge* getFromEdge() const {
423  return (*myStep)->getFromEdge();
424  }
425 
427  virtual SUMOReal getEdgePos() const;
428 
430  virtual Position getPosition() const;
431 
433  virtual SUMOReal getAngle() const;
434 
436  virtual SUMOReal getWaitingSeconds() const;
437 
439  virtual SUMOReal getSpeed() const;
440 
443  return (*myStep)->getStageType();
444  }
445 
447  StageType getStageType(int next) const {
448  assert(myStep + next < myPlan->end());
449  assert(myStep + next >= myPlan->begin());
450  return (*(myStep + next))->getStageType();
451  }
452 
454  std::string getCurrentStageDescription() const {
455  return (*myStep)->getStageDescription();
456  }
457 
460  return *myStep;
461  }
462 
464  ConstMSEdgeVector getEdges(int next) const {
465  assert(myStep + next < myPlan->end());
466  assert(myStep + next >= myPlan->begin());
467  return (*(myStep + next))->getEdges();
468  }
469 
471  int getNumRemainingStages() const;
472 
474  int getNumStages() const;
475 
481  virtual void tripInfoOutput(OutputDevice& os) const = 0;
482 
488  virtual void routeOutput(OutputDevice& os) const = 0;
489 
491  bool isWaitingFor(const std::string& line) const {
492  return (*myStep)->isWaitingFor(line);
493  }
494 
496  bool isWaiting4Vehicle() const {
497  return (*myStep)->isWaiting4Vehicle();
498  }
499 
502  return (*myStep)->getVehicle();
503  }
504 
506  void appendStage(Stage* stage);
507 
509  void removeStage(int next);
510 
512  void setSpeed(SUMOReal speed);
513 
516  return myPlan->back()->getArrivalPos();
517  }
518 
520  const MSEdge* getArrivalEdge() const {
521  return myPlan->back()->getEdges().back();
522  }
523 
525  void replaceVehicleType(MSVehicleType* type);
526 
527 protected:
529  static const SUMOReal ROADSIDE_OFFSET;
530 
533 
537 
540 
542  MSTransportablePlan* myPlan;
543 
545  MSTransportablePlan::iterator myStep;
546 
547 private:
550 
553 
554 };
555 
556 
557 #endif
558 
559 /****************************************************************************/
void setArrived(SUMOTime now)
logs end of the step
virtual std::string getStageDescription() const =0
return string representation of the current stage
long long int SUMOTime
Definition: SUMOTime.h:43
std::string myActType
The type of activity.
virtual SUMOReal getEdgePos(SUMOTime now) const =0
StageType getStageType() const
A lane area vehicles can halt at.
bool isWaiting4Vehicle() const
Whether the transportable waits for a vehicle.
std::vector< const MSEdge * > ConstMSEdgeVector
Stage(const MSEdge &destination, MSStoppingPlace *toStop, const SUMOReal arrivalPos, StageType type)
constructor
const SUMOVehicleParameter & getParameter() const
virtual SUMOReal getWaitingSeconds() const
the time this transportable spent waiting in seconds
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.
SUMOReal getArrivalPos() const
returns the final arrival pos
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:78
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.
MSTransportable(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSTransportablePlan *plan)
constructor
virtual SUMOTime getWaitingTime(SUMOTime now) const =0
the time this transportable spent waiting
SUMOReal getEdgeAngle(const MSEdge *e, SUMOReal at) const
get angle of the edge at a certain position
The simulated network and simulation perfomer.
Definition: MSNet.h:94
The car-following model and parameter.
Definition: MSVehicleType.h:74
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.
virtual SUMOReal getAngle(SUMOTime now) const =0
returns the angle of the transportable
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)
A road/street connecting two junctions.
Definition: MSEdge.h:80
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
Position getLanePosition(const MSLane *lane, SUMOReal at, SUMOReal offset) const
get position on lane at length at with orthogonal offset
Position getEdgePosition(const MSEdge *e, SUMOReal at, SUMOReal offset) const
get position on edge e at length at with orthogonal offset
const MSVehicleType & getVehicleType() const
virtual void routeOutput(OutputDevice &os) const =0
Called on writing vehroute output.
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
static const SUMOReal ROADSIDE_OFFSET
the offset for computing positions when standing at an edge
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
void appendStage(Stage *stage)
Appends the given stage to the current plan.
const MSVehicleType * myVType
This transportable&#39;s type. (mainly used for drawing related information Note sure if it is really nec...
void setVehicle(SUMOVehicle *v)
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
SUMOReal myArrivalPos
the position at which we want to arrive
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.
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.
virtual void endEventOutput(const MSTransportable &transportable, SUMOTime t, OutputDevice &os) const =0
Called for writing the events output (end of an action)
SUMOReal getArrivalPos() const
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
ConstMSEdgeVector getEdges(int next) const
Return the edges of the nth next stage.
void replaceVehicleType(MSVehicleType *type)
replace myVType
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
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.
#define SUMOReal
Definition: config.h:208
MSTransportablePlan * myPlan
the plan of the transportable
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
virtual ~Stage()
destructor
virtual SUMOReal getSpeed() const =0
the speed of the transportable
virtual void setSpeed(SUMOReal)
sets the walking speed (ignored in other stages)
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
SUMOTime myWaitingDuration
the time the person is waiting
SUMOTime myWaitingStart
the time the person is waiting