SUMO - Simulation of Urban MObility
MSBaseVehicle.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // A base class for vehicle implementations
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2010-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef MSBaseVehicle_h
23 #define MSBaseVehicle_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <iostream>
36 #include <vector>
37 #include <set>
39 #include <utils/common/StdDefs.h>
40 #include "MSRoute.h"
41 #include "MSMoveReminder.h"
42 #include "MSVehicleType.h"
43 
44 // ===========================================================================
45 // class declarations
46 // ===========================================================================
47 class MSLane;
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
56 class MSBaseVehicle : public SUMOVehicle {
57 public:
58  // XXX: This definition was introduced to make the MSVehicle's previousSpeed
59  // available in the context of MSMoveReminder::notifyMove(). Another solution
60  // would be to modify notifyMove()'s interface to work with MSVehicle instead
61  // of SUMOVehicle (it is only called with MSVehicles!). Refs. #2579
65  double getPreviousSpeed() const;
66 
67  friend class GUIBaseVehicle;
68 
76  MSBaseVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
77  MSVehicleType* type, const double speedFactor);
78 
79 
81  virtual ~MSBaseVehicle();
82 
83 
85  const std::string& getID() const;
86 
91  const SUMOVehicleParameter& getParameter() const;
92 
94  bool hasDevice(const std::string& deviceName) const;
95 
97  void createDevice(const std::string& deviceName);
98 
100  std::string getDeviceParameter(const std::string& deviceName, const std::string& key) const;
101 
103  void setDeviceParameter(const std::string& deviceName, const std::string& key, const std::string& value);
104 
108  inline const MSRoute& getRoute() const {
109  return *myRoute;
110  }
111 
112 
116  inline const MSVehicleType& getVehicleType() const {
117  return *myType;
118  }
119 
120 
124  inline SUMOVehicleClass getVClass() const {
125  return myType->getParameter().vehicleClass;
126  }
127 
131  double getMaxSpeed() const;
132 
133 
141  const MSEdge* succEdge(int nSuccs) const;
142 
147  const MSEdge* getEdge() const;
148 
149 
153  virtual bool isOnRoad() const {
154  return true;
155  }
156 
161  virtual bool isRemoteControlled() const {
162  return false;
163  }
164 
168  virtual bool isFrontOnLane(const MSLane*) const {
169  return true;
170  }
171 
176  virtual double getLateralPositionOnLane() const {
177  return 0;
178  }
179 
185  virtual const MSEdge* getRerouteOrigin() const {
186  return *myCurrEdge;
187  }
188 
189 
194  return myCurrEdge;
195  }
196 
197 
207  void reroute(SUMOTime t, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit = false, const bool withTaz = false);
208 
209 
222  bool replaceRouteEdges(ConstMSEdgeVector& edges, bool onInit = false, bool check = false, bool addStops = true);
223 
224 
230  virtual double getAcceleration() const;
231 
237  virtual double getSlope() const;
238 
244  void onDepart();
245 
249  inline SUMOTime getDeparture() const {
250  return myDeparture;
251  }
252 
255  return getDeparture() - getParameter().depart;
256  }
257 
258 
262  inline double getDepartPos() const {
263  return myDepartPos;
264  }
265 
270  virtual double getArrivalPos() const {
271  return myArrivalPos;
272  }
273 
276  virtual void setArrivalPos(double arrivalPos) {
277  myArrivalPos = arrivalPos;
278  }
279 
282  bool hasDeparted() const;
283 
287  virtual bool hasArrived() const;
288 
292  inline int getNumberReroutes() const {
293  return myNumberReroutes;
294  }
295 
297  double getImpatience() const;
298 
299 
303  inline const std::vector<MSDevice*>& getDevices() const {
304  return myDevices;
305  }
306 
313  virtual void addPerson(MSTransportable* person);
314 
315 
322  virtual void addContainer(MSTransportable* container);
323 
329  bool hasValidRoute(std::string& msg, const MSRoute* route = 0) const;
330 
336  void addReminder(MSMoveReminder* rem);
337 
343  void removeReminder(MSMoveReminder* rem);
344 
356  virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
357 
358 
362  inline double getLength() const {
363  return myType->getLength();
364  }
365 
366 
370  inline double getWidth() const {
371  return myType->getWidth();
372  }
373 
374 
378  inline double getChosenSpeedFactor() const {
379  return myChosenSpeedFactor;
380  }
381 
385  inline void setChosenSpeedFactor(const double factor) {
386  myChosenSpeedFactor = factor;
387  }
388 
390  MSDevice* getDevice(const std::type_info& type) const;
391 
392 
401  void replaceVehicleType(MSVehicleType* type);
402 
403 
412 
414 
415 
417  virtual void saveState(OutputDevice& out);
418 
420 
428  void addStops(const bool ignoreStopErrors);
429 
430 protected:
433  void calculateArrivalParams();
434 
437  virtual const ConstMSEdgeVector getStopEdges() const = 0;
438 
439 protected:
442 
444  const MSRoute* myRoute;
445 
448 
451 
454 
455 
458 
460  // The double value holds the relative position offset, i.e.,
461  // offset + vehicle-position - moveReminder-position = distance,
462  // i.e. the offset is counted up when the vehicle continues to a
463  // succeeding lane.
464  typedef std::vector< std::pair<MSMoveReminder*, double> > MoveReminderCont;
465 
467  MoveReminderCont myMoveReminders;
469 
471  std::vector<MSDevice*> myDevices;
472 
475 
477  double myDepartPos;
478 
480  double myArrivalPos;
481 
484 
487 
488  /* @brief magic value for undeparted vehicles
489  * @note: in previous versions this was -1
490  */
492 
493 private:
496 
497 #ifdef _DEBUG
498 public:
499  static void initMoveReminderOutput(const OptionsCont& oc);
500 
501 protected:
503  void traceMoveReminder(const std::string& type, MSMoveReminder* rem, double pos, bool keep) const;
504 
506  const bool myTraceMoveReminders;
507 private:
509  static std::set<std::string> myShallTraceMoveReminders;
510 #endif
511 
512 
513 };
514 
515 #endif
516 
517 /****************************************************************************/
void removeReminder(MSMoveReminder *rem)
Removes a MoveReminder dynamically.
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
MoveReminderCont myMoveReminders
Currently relevant move reminders.
double getMaxSpeed() const
Returns the maximum speed.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
void setDeviceParameter(const std::string &deviceName, const std::string &key, const std::string &value)
try to set the given parameter from any of the vehicles devices, raise InvalidArgument if no device p...
virtual double getAcceleration() const
Returns the vehicle&#39;s acceleration.
SUMOVehicleClass getVClass() const
Returns the vehicle&#39;s access class.
const MSRouteIterator & getCurrentRouteEdge() const
Returns an iterator pointing to the current edge in this vehicles route.
virtual double getSlope() const
Returns the slope of the road at vehicle&#39;s position.
double getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
double myArrivalPos
The position on the destination lane where the vehicle stops.
Notification
Definition of a vehicle state.
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
SUMOVehicleClass vehicleClass
The vehicle&#39;s class.
const MSRoute & getRoute() const
Returns the current route.
virtual ~MSBaseVehicle()
Destructor.
MSBaseVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
const MSRoute * myRoute
This vehicle&#39;s route.
bool hasDeparted() const
Returns whether this vehicle has already departed.
virtual double getArrivalPos() const
Returns this vehicle&#39;s desired arrivalPos for its current route (may change on reroute) ...
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:79
int myArrivalLane
The destination lane where the vehicle stops.
const SUMOVehicleParameter * myParameter
This vehicle&#39;s parameter.
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:56
double getLength() const
Returns the vehicle&#39;s length.
bool hasValidRoute(std::string &msg, const MSRoute *route=0) const
Validates the current or given route.
bool replaceRouteEdges(ConstMSEdgeVector &edges, bool onInit=false, bool check=false, bool addStops=true)
Replaces the current route by the given edges.
The car-following model and parameter.
Definition: MSVehicleType.h:73
virtual void saveState(OutputDevice &out)
Saves the (common) state of a vehicle.
void calculateArrivalParams()
(Re-)Calculates the arrival position and lane from the vehicle parameters
double getImpatience() const
Returns this vehicles impatience.
std::string getDeviceParameter(const std::string &deviceName, const std::string &key) const
try to retrieve the given parameter from any of the vehicles devices, raise InvalidArgument if no dev...
virtual bool isFrontOnLane(const MSLane *) const
Returns the information whether the front of the vehhicle is on the given lane.
A road/street connecting two junctions.
Definition: MSEdge.h:81
virtual void addPerson(MSTransportable *person)
Adds a person to this vehicle.
double myDepartPos
The real depart position.
const SUMOVTypeParameter & getParameter() const
void createDevice(const std::string &deviceName)
create device of the given type
Representation of a vehicle.
Definition: SUMOVehicle.h:67
SUMOTime getDepartDelay() const
Returns the depart delay.
MSBaseVehicle & operator=(const MSBaseVehicle &s)
invalidated assignment operator
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:65
SUMOTime depart
The vehicle&#39;s departure time.
A MSVehicle extended by some values for usage within the gui.
Something on a lane to be noticed about vehicle movement.
void setChosenSpeedFactor(const double factor)
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
Abstract in-vehicle device.
Definition: MSDevice.h:71
double getLength() const
Get vehicle&#39;s length [m].
std::vector< std::pair< MSMoveReminder *, double > > MoveReminderCont
Definition of a move reminder container.
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
Structure representing possible vehicle parameter.
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs&#39;th successor of edge the vehicle is currently at.
double getPreviousSpeed() const
Returns the vehicle&#39;s previous speed.
MSVehicleType * myType
This vehicle&#39;s type.
void onDepart()
Called when the vehicle is inserted into the network.
A storage for options typed value containers)
Definition: OptionsCont.h:99
bool hasDevice(const std::string &deviceName) const
check whether the vehicle is equiped with a device of the given type
virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
"Activates" all current move reminder
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
virtual bool hasArrived() const
Returns whether this vehicle has already arived (by default this is true if the vehicle has reached i...
virtual const MSEdge * getRerouteOrigin() const
Returns the starting point for reroutes (usually the current edge)
int myNumberReroutes
The number of reroutings.
const SUMOVehicleParameter & getParameter() const
Returns the vehicle&#39;s parameter (including departure definition)
virtual const ConstMSEdgeVector getStopEdges() const =0
Returns the list of still pending stop edges.
virtual double getLateralPositionOnLane() const
Get the vehicle&#39;s lateral position on the lane.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
long long int SUMOTime
Definition: TraCIDefs.h:52
MSRouteIterator myCurrEdge
Iterator to current route-edge.
virtual void setArrivalPos(double arrivalPos)
Sets this vehicle&#39;s desired arrivalPos for its current route.
void reroute(SUMOTime t, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false)
Performs a rerouting using the given router.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
SUMOTime getDeparture() const
Returns this vehicle&#39;s real departure time.
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
void addReminder(MSMoveReminder *rem)
Adds a MoveReminder dynamically.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
std::vector< MSDevice * > myDevices
The devices this vehicle has.
void replaceVehicleType(MSVehicleType *type)
Replaces the current vehicle type by the one given.
virtual void addContainer(MSTransportable *container)
Adds a container to this vehicle.
const std::vector< MSDevice * > & getDevices() const
Returns this vehicle&#39;s devices.
SUMOTime myDeparture
The real departure time.
double getDepartPos() const
Returns this vehicle&#39;s real departure position.
static const SUMOTime NOT_YET_DEPARTED
double getWidth() const
Returns the vehicle&#39;s width.
const std::string & getID() const
Returns the name of the vehicle.
virtual bool isRemoteControlled() const
Returns the information whether the vehicle is fully controlled via TraCI.
double myChosenSpeedFactor
A precomputed factor by which the driver wants to be faster than the speed limit. ...