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  const 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 
361  inline double getChosenSpeedFactor() const {
362  return myChosenSpeedFactor;
363  }
364 
368  inline void setChosenSpeedFactor(const double factor) {
369  myChosenSpeedFactor = factor;
370  }
371 
373  MSDevice* getDevice(const std::type_info& type) const;
374 
375 
377 
378 
380  virtual void saveState(OutputDevice& out);
381 
383 
391  void addStops(const bool ignoreStopErrors);
392 
393 protected:
396  void calculateArrivalParams();
397 
400  virtual const ConstMSEdgeVector getStopEdges() const = 0;
401 
402 protected:
405 
407  const MSRoute* myRoute;
408 
411 
414 
417 
418 
421 
423  // The double value holds the relative position offset, i.e.,
424  // offset + vehicle-position - moveReminder-position = distance,
425  // i.e. the offset is counted up when the vehicle continues to a
426  // succeeding lane.
427  typedef std::vector< std::pair<MSMoveReminder*, double> > MoveReminderCont;
428 
430  MoveReminderCont myMoveReminders;
432 
434  std::vector<MSDevice*> myDevices;
435 
438 
440  double myDepartPos;
441 
443  double myArrivalPos;
444 
447 
450 
451  /* @brief magic value for undeparted vehicles
452  * @note: in previous versions this was -1
453  */
455 
456 private:
459 
460 
461 #ifdef _DEBUG
462 public:
463  static void initMoveReminderOutput(const OptionsCont& oc);
464 
465 protected:
467  void traceMoveReminder(const std::string& type, MSMoveReminder* rem, double pos, bool keep) const;
468 
470  const bool myTraceMoveReminders;
471 private:
473  static std::set<std::string> myShallTraceMoveReminders;
474 #endif
475 
476 
477 };
478 
479 #endif
480 
481 /****************************************************************************/
void removeReminder(MSMoveReminder *rem)
Removes a MoveReminder dynamically.
const MSVehicleType * myType
This Vehicle&#39;s type.
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.
MSBaseVehicle(SUMOVehicleParameter *pars, const MSRoute *route, const MSVehicleType *type, const double speedFactor)
Constructor.
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.
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:56
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
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:74
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...
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:67
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:65
SUMOTime depart
The vehicle&#39;s departure time.
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:71
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.
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:99
virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
"Activates" all current move reminder
int myNumberReroutes
The number of reroutings.
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:71
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: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.
virtual double getArrivalPos() const
Returns this vehicle&#39;s desired arrivalPos for its current route (may change on reroute) ...
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:79
std::vector< MSDevice * > myDevices
The devices this vehicle has.
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 myChosenSpeedFactor
A precomputed factor by which the driver wants to be faster than the speed limit. ...