SUMO - Simulation of Urban MObility
MSBaseVehicle.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2010-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 /****************************************************************************/
19 // A base class for vehicle implementations
20 /****************************************************************************/
21 #ifndef MSBaseVehicle_h
22 #define MSBaseVehicle_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <iostream>
35 #include <vector>
36 #include <set>
38 #include <utils/common/StdDefs.h>
39 #include "MSRoute.h"
40 #include "MSMoveReminder.h"
41 #include "MSVehicleType.h"
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
46 class MSLane;
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
55 class MSBaseVehicle : public SUMOVehicle {
56 public:
57  // XXX: This definition was introduced to make the MSVehicle's previousSpeed
58  // available in the context of MSMoveReminder::notifyMove(). Another solution
59  // would be to modify notifyMove()'s interface to work with MSVehicle instead
60  // of SUMOVehicle (it is only called with MSVehicles!). Refs. #2579
64  double getPreviousSpeed() const;
65 
66  friend class GUIBaseVehicle;
67 
75  MSBaseVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
76  MSVehicleType* type, const double speedFactor);
77 
78 
80  virtual ~MSBaseVehicle();
81 
82 
84  const std::string& getID() const;
85 
90  const SUMOVehicleParameter& getParameter() const;
91 
93  bool hasDevice(const std::string& deviceName) const;
94 
96  void createDevice(const std::string& deviceName);
97 
99  std::string getDeviceParameter(const std::string& deviceName, const std::string& key) const;
100 
102  void setDeviceParameter(const std::string& deviceName, const std::string& key, const std::string& value);
103 
107  inline const MSRoute& getRoute() const {
108  return *myRoute;
109  }
110 
111 
115  inline const MSVehicleType& getVehicleType() const {
116  return *myType;
117  }
118 
119 
123  inline SUMOVehicleClass getVClass() const {
124  return myType->getParameter().vehicleClass;
125  }
126 
130  double getMaxSpeed() const;
131 
132 
140  const MSEdge* succEdge(int nSuccs) const;
141 
146  const MSEdge* getEdge() const;
147 
148 
152  virtual bool isOnRoad() const {
153  return true;
154  }
155 
160  virtual bool isRemoteControlled() const {
161  return false;
162  }
163 
167  virtual bool isFrontOnLane(const MSLane*) const {
168  return true;
169  }
170 
175  virtual double getLateralPositionOnLane() const {
176  return 0;
177  }
178 
184  virtual const MSEdge* getRerouteOrigin() const {
185  return *myCurrEdge;
186  }
187 
188 
193  return myCurrEdge;
194  }
195 
196 
206  void reroute(SUMOTime t, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit = false, const bool withTaz = false);
207 
208 
221  bool replaceRouteEdges(ConstMSEdgeVector& edges, bool onInit = false, bool check = false, bool removeStops = true);
222 
223 
229  virtual double getAcceleration() const;
230 
236  virtual double getSlope() const;
237 
243  void onDepart();
244 
248  inline SUMOTime getDeparture() const {
249  return myDeparture;
250  }
251 
254  return getDeparture() - getParameter().depart;
255  }
256 
257 
261  inline double getDepartPos() const {
262  return myDepartPos;
263  }
264 
269  virtual double getArrivalPos() const {
270  return myArrivalPos;
271  }
272 
275  virtual void setArrivalPos(double arrivalPos) {
276  myArrivalPos = arrivalPos;
277  }
278 
281  bool hasDeparted() const;
282 
286  virtual bool hasArrived() const;
287 
291  inline int getNumberReroutes() const {
292  return myNumberReroutes;
293  }
294 
296  double getImpatience() const;
297 
298 
302  inline const std::vector<MSDevice*>& getDevices() const {
303  return myDevices;
304  }
305 
312  virtual void addPerson(MSTransportable* person);
313 
314 
321  virtual void addContainer(MSTransportable* container);
322 
328  bool hasValidRoute(std::string& msg, const MSRoute* route = 0) const;
329 
335  void addReminder(MSMoveReminder* rem);
336 
342  void removeReminder(MSMoveReminder* rem);
343 
355  virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
356 
357 
361  inline double getLength() const {
362  return myType->getLength();
363  }
364 
365 
369  inline double getWidth() const {
370  return myType->getWidth();
371  }
372 
373 
377  inline double getChosenSpeedFactor() const {
378  return myChosenSpeedFactor;
379  }
380 
384  inline void setChosenSpeedFactor(const double factor) {
385  myChosenSpeedFactor = factor;
386  }
387 
389  MSDevice* getDevice(const std::type_info& type) const;
390 
391 
400  void replaceVehicleType(MSVehicleType* type);
401 
402 
411 
413 
414 
416  virtual void saveState(OutputDevice& out);
417 
419 
427  void addStops(const bool ignoreStopErrors);
428 
430  virtual bool isSelected() const {
431  return false;
432  }
433 
434 protected:
437  void calculateArrivalParams();
438 
441  virtual const ConstMSEdgeVector getStopEdges() const = 0;
442 
443 protected:
446 
448  const MSRoute* myRoute;
449 
452 
455 
458 
459 
462 
464  // The double value holds the relative position offset, i.e.,
465  // offset + vehicle-position - moveReminder-position = distance,
466  // i.e. the offset is counted up when the vehicle continues to a
467  // succeeding lane.
468  typedef std::vector< std::pair<MSMoveReminder*, double> > MoveReminderCont;
469 
471  MoveReminderCont myMoveReminders;
473 
475  std::vector<MSDevice*> myDevices;
476 
479 
481  double myDepartPos;
482 
484  double myArrivalPos;
485 
488 
491 
492  /* @brief magic value for undeparted vehicles
493  * @note: in previous versions this was -1
494  */
496 
497 private:
500 
501 #ifdef _DEBUG
502 public:
503  static void initMoveReminderOutput(const OptionsCont& oc);
504 
505 protected:
507  void traceMoveReminder(const std::string& type, MSMoveReminder* rem, double pos, bool keep) const;
508 
510  const bool myTraceMoveReminders;
511 private:
513  static std::set<std::string> myShallTraceMoveReminders;
514 #endif
515 
516 
517 };
518 
519 #endif
520 
521 /****************************************************************************/
void removeReminder(MSMoveReminder *rem)
Removes a MoveReminder dynamically.
double getLength() const
Returns the vehicle&#39;s length.
SUMOTime getDeparture() const
Returns this vehicle&#39;s real departure time.
bool hasValidRoute(std::string &msg, const MSRoute *route=0) const
Validates the current or given route.
MoveReminderCont myMoveReminders
Currently relevant move reminders.
bool hasDeparted() const
Returns whether this vehicle has already departed.
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...
const SUMOVehicleParameter & getParameter() const
Returns the vehicle&#39;s parameter (including departure definition)
double myArrivalPos
The position on the destination lane where the vehicle stops.
Notification
Definition of a vehicle state.
SUMOVehicleClass vehicleClass
The vehicle&#39;s class.
virtual bool isRemoteControlled() const
Returns the information whether the vehicle is fully controlled via TraCI.
SUMOTime getDepartDelay() const
Returns the depart delay.
virtual ~MSBaseVehicle()
Destructor.
MSBaseVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
const MSRoute * myRoute
This vehicle&#39;s route.
const MSRoute & getRoute() const
Returns the current route.
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:78
virtual double getLateralPositionOnLane() const
Get the vehicle&#39;s lateral position on the lane.
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:55
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
The car-following model and parameter.
Definition: MSVehicleType.h:72
virtual void saveState(OutputDevice &out)
Saves the (common) state of a vehicle.
double getDepartPos() const
Returns this vehicle&#39;s real departure position.
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 isSelected() const
whether this vehicle is selected in the GUI
double getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
double getMaxSpeed() const
Returns the maximum speed.
void calculateArrivalParams()
(Re-)Calculates the arrival position and lane from the vehicle parameters
A road/street connecting two junctions.
Definition: MSEdge.h:80
virtual void addPerson(MSTransportable *person)
Adds a person to this vehicle.
virtual const MSEdge * getRerouteOrigin() const
Returns the starting point for reroutes (usually the current edge)
double myDepartPos
The real depart position.
virtual bool isFrontOnLane(const MSLane *) const
Returns the information whether the front of the vehhicle is on the given lane.
void createDevice(const std::string &deviceName)
create device of the given type
Representation of a vehicle.
Definition: SUMOVehicle.h:66
MSBaseVehicle & operator=(const MSBaseVehicle &s)
invalidated assignment operator
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:64
SUMOTime depart
The vehicle&#39;s departure time.
bool replaceRouteEdges(ConstMSEdgeVector &edges, bool onInit=false, bool check=false, bool removeStops=true)
Replaces the current route by the given edges.
double getImpatience() const
Returns this vehicles impatience.
A MSVehicle extended by some values for usage within the gui.
virtual const ConstMSEdgeVector getStopEdges() const =0
Returns the list of still pending stop edges.
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...
const std::vector< MSDevice * > & getDevices() const
Returns this vehicle&#39;s devices.
const SUMOVTypeParameter & getParameter() const
Abstract in-vehicle device.
Definition: MSDevice.h:70
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
std::vector< std::pair< MSMoveReminder *, double > > MoveReminderCont
Definition of a move reminder container.
SUMOVehicleClass getVClass() const
Returns the vehicle&#39;s access class.
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
Structure representing possible vehicle parameter.
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
virtual bool hasArrived() const
Returns whether this vehicle has already arived (by default this is true if the vehicle has reached i...
virtual double getAcceleration() const
Returns the vehicle&#39;s acceleration.
MSVehicleType * myType
This vehicle&#39;s type.
void onDepart()
Called when the vehicle is inserted into the network.
virtual double getSlope() const
Returns the slope of the road at vehicle&#39;s position.
A storage for options typed value containers)
Definition: OptionsCont.h:98
virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
"Activates" all current move reminder
int myNumberReroutes
The number of reroutings.
double getLength() const
Get vehicle&#39;s length [m].
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs&#39;th successor of edge the vehicle is currently at.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool hasDevice(const std::string &deviceName) const
check whether the vehicle is equiped with a device of the given type
long long int SUMOTime
Definition: TraCIDefs.h:51
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.
virtual double getArrivalPos() const
Returns this vehicle&#39;s desired arrivalPos for its current route (may change on reroute) ...
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
const MSRouteIterator & getCurrentRouteEdge() const
Returns an iterator pointing to the current edge in this vehicles route.
const std::string & getID() const
Returns the name of the vehicle.
void addReminder(MSMoveReminder *rem)
Adds a MoveReminder dynamically.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
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.
double getPreviousSpeed() const
Returns the vehicle&#39;s previous speed.
SUMOTime myDeparture
The real departure time.
static const SUMOTime NOT_YET_DEPARTED
double getWidth() const
Returns the vehicle&#39;s width.
double myChosenSpeedFactor
A precomputed factor by which the driver wants to be faster than the speed limit. ...