Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // A base class for vehicle implementations
18 /****************************************************************************/
19 #ifndef MSBaseVehicle_h
20 #define MSBaseVehicle_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <iostream>
29 #include <vector>
30 #include <set>
32 #include <utils/common/StdDefs.h>
33 #include "MSRoute.h"
34 #include "MSMoveReminder.h"
35 #include "MSVehicleType.h"
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 class MSLane;
42 class MSVehicleDevice;
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
52 class MSBaseVehicle : public SUMOVehicle {
53 public:
54  // XXX: This definition was introduced to make the MSVehicle's previousSpeed
55  // available in the context of MSMoveReminder::notifyMove(). Another solution
56  // would be to modify notifyMove()'s interface to work with MSVehicle instead
57  // of SUMOVehicle (it is only called with MSVehicles!). Refs. #2579
61  double getPreviousSpeed() const;
62 
63  friend class GUIBaseVehicle;
64 
72  MSBaseVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
73  MSVehicleType* type, const double speedFactor);
74 
75 
77  virtual ~MSBaseVehicle();
78 
79  bool isVehicle() const {
80  return true;
81  }
82 
84  const std::string& getID() const;
85 
90  const SUMOVehicleParameter& getParameter() const;
91 
93  void replaceParameter(const SUMOVehicleParameter* newParameter);
94 
96  bool hasDevice(const std::string& deviceName) const;
97 
99  void createDevice(const std::string& deviceName);
100 
102  std::string getDeviceParameter(const std::string& deviceName, const std::string& key) const;
103 
105  void setDeviceParameter(const std::string& deviceName, const std::string& key, const std::string& value);
106 
110  inline const MSRoute& getRoute() const {
111  return *myRoute;
112  }
113 
114 
118  inline const MSVehicleType& getVehicleType() const {
119  return *myType;
120  }
121 
122 
126  inline SUMOVehicleClass getVClass() const {
127  return myType->getParameter().vehicleClass;
128  }
129 
133  double getMaxSpeed() const;
134 
135 
143  const MSEdge* succEdge(int nSuccs) const;
144 
149  const MSEdge* getEdge() const;
150 
151 
155  virtual bool isOnRoad() const {
156  return true;
157  }
158 
163  virtual bool isRemoteControlled() const {
164  return false;
165  }
166 
167  virtual bool wasRemoteControlled(SUMOTime lookBack = DELTA_T) const {
168  UNUSED_PARAMETER(lookBack);
169  return false;
170  }
171 
175  virtual bool isFrontOnLane(const MSLane*) const {
176  return true;
177  }
178 
183  virtual double getLateralPositionOnLane() const {
184  return 0;
185  }
186 
192  virtual const MSEdge* getRerouteOrigin() const {
193  return *myCurrEdge;
194  }
195 
196 
201  return myCurrEdge;
202  }
203 
204 
214  void reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit = false, const bool withTaz = false, const bool silent = false);
215 
216 
229  bool replaceRouteEdges(ConstMSEdgeVector& edges, double cost, double savings, const std::string& info, bool onInit = false, bool check = false, bool removeStops = true);
230 
231 
237  virtual double getAcceleration() const;
238 
244  virtual double getSlope() const;
245 
251  void onDepart();
252 
256  inline SUMOTime getDeparture() const {
257  return myDeparture;
258  }
259 
262  return getDeparture() - getParameter().depart;
263  }
264 
265 
269  inline double getDepartPos() const {
270  return myDepartPos;
271  }
272 
277  virtual double getArrivalPos() const {
278  return myArrivalPos;
279  }
280 
283  virtual void setArrivalPos(double arrivalPos) {
284  myArrivalPos = arrivalPos;
285  }
286 
289  bool hasDeparted() const;
290 
294  virtual bool hasArrived() const;
295 
299  inline int getNumberReroutes() const {
300  return myNumberReroutes;
301  }
302 
304  double getImpatience() const;
305 
309  int getPersonNumber() const;
310 
314  std::vector<std::string> getPersonIDList() const;
315 
319  int getContainerNumber() const;
320 
321 
325  inline const std::vector<MSVehicleDevice*>& getDevices() const {
326  return myDevices;
327  }
328 
335  virtual void addPerson(MSTransportable* person);
336 
337 
344  virtual void addContainer(MSTransportable* container);
345 
348 
350  const std::vector<MSTransportable*>& getPersons() const;
351 
353  const std::vector<MSTransportable*>& getContainers() const;
354 
355 
361  bool hasValidRoute(std::string& msg, const MSRoute* route = 0) const;
362 
368  void addReminder(MSMoveReminder* rem);
369 
375  void removeReminder(MSMoveReminder* rem);
376 
388  virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
389 
390 
394  inline double getLength() const {
395  return myType->getLength();
396  }
397 
398 
402  inline double getWidth() const {
403  return myType->getWidth();
404  }
405 
406 
410  inline double getChosenSpeedFactor() const {
411  return myChosenSpeedFactor;
412  }
413 
417  inline void setChosenSpeedFactor(const double factor) {
418  myChosenSpeedFactor = factor;
419  }
420 
422  MSVehicleDevice* getDevice(const std::type_info& type) const;
423 
424 
433  void replaceVehicleType(MSVehicleType* type);
434 
435 
444 
446 
447 
449  virtual void saveState(OutputDevice& out);
450 
452 
460  void addStops(const bool ignoreStopErrors);
461 
463  virtual bool isSelected() const {
464  return false;
465  }
466 
468  std::mt19937* getRNG() const;
469 
470  inline NumericalID getNumericalID() const {
471  return myNumericalID;
472  }
473 
475  return myPersonDevice;
476  }
477 
479  return myContainerDevice;
480  }
481 
482 protected:
485  void calculateArrivalParams();
486 
489  virtual const ConstMSEdgeVector getStopEdges(double& firstPos, double& lastPos) const = 0;
490 
491 protected:
494 
496  const MSRoute* myRoute;
497 
500 
503 
506 
507 
510 
512  // The double value holds the relative position offset, i.e.,
513  // offset + vehicle-position - moveReminder-position = distance,
514  // i.e. the offset is counted up when the vehicle continues to a
515  // succeeding lane.
516  typedef std::vector< std::pair<MSMoveReminder*, double> > MoveReminderCont;
517 
519  MoveReminderCont myMoveReminders;
521 
523  std::vector<MSVehicleDevice*> myDevices;
524 
527 
530 
533 
535  double myDepartPos;
536 
538  double myArrivalPos;
539 
542 
545 
546  /* @brief magic value for undeparted vehicles
547  * @note: in previous versions this was -1
548  */
550 
551  static std::vector<MSTransportable*> myEmptyTransportableVector;
552 
553 private:
555 
557 
558 private:
561 
562 #ifdef _DEBUG
563 public:
564  static void initMoveReminderOutput(const OptionsCont& oc);
565 
566 protected:
568  void traceMoveReminder(const std::string& type, MSMoveReminder* rem, double pos, bool keep) const;
569 
571  const bool myTraceMoveReminders;
572 private:
574  static std::set<std::string> myShallTraceMoveReminders;
575 #endif
576 
577 
578 };
579 
580 #endif
581 
582 /****************************************************************************/
std::vector< MSVehicleDevice * > myDevices
The devices this vehicle has.
void removeReminder(MSMoveReminder *rem)
Removes a MoveReminder dynamically.
int getContainerNumber() const
Returns the number of containers.
bool isVehicle() const
Get the vehicle&#39;s ID.
Definition: MSBaseVehicle.h:79
void reroute(SUMOTime t, const std::string &info, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false, const bool silent=false)
Performs a rerouting using the given router.
double getLength() const
Returns the vehicle&#39;s length.
virtual bool wasRemoteControlled(SUMOTime lookBack=DELTA_T) const
Returns the information whether the vehicle is fully controlled via TraCI.
long long int SUMOTime
Definition: SUMOTime.h:35
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.
void replaceParameter(const SUMOVehicleParameter *newParameter)
replace the vehicle parameter (deleting the old one)
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...
std::mt19937 * getRNG() const
const MSDevice_Transportable * getPersonDevice() const
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.
SUMOTime DELTA_T
Definition: SUMOTime.cpp:35
MSBaseVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
const MSRoute * myRoute
This vehicle&#39;s route.
const std::vector< MSVehicleDevice * > & getDevices() const
Returns this vehicle&#39;s devices.
const MSRoute & getRoute() const
Returns the current route.
virtual const ConstMSEdgeVector getStopEdges(double &firstPos, double &lastPos) const =0
Returns the list of still pending stop edges.
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:73
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:52
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:32
The car-following model and parameter.
Definition: MSVehicleType.h:66
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:76
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
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
Representation of a vehicle.
Definition: SUMOVehicle.h:61
bool replaceRouteEdges(ConstMSEdgeVector &edges, double cost, double savings, const std::string &info, bool onInit=false, bool check=false, bool removeStops=true)
Replaces the current route by the given edges.
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:58
MSDevice_Transportable * myPersonDevice
The passengers this vehicle may have.
double getImpatience() const
Returns this vehicles impatience.
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...
const SUMOVTypeParameter & getParameter() const
std::vector< std::string > getPersonIDList() const
Returns the list of persons.
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.
int getPersonNumber() const
Returns the number of persons.
Structure representing possible vehicle parameter.
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 removeTransportable(MSTransportable *t)
removes a person or container
MSVehicleType * myType
This vehicle&#39;s type.
static std::vector< MSTransportable * > myEmptyTransportableVector
MSVehicleDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
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:90
virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
"Activates" all current move reminder
Abstract in-vehicle device.
int myNumberReroutes
The number of reroutings.
double getLength() const
Get vehicle&#39;s length [m].
NumericalID getNumericalID() const
return the numerical ID which is only for internal usage
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs&#39;th successor of edge the vehicle is currently at.
const NumericalID myNumericalID
const MSDevice_Transportable * getContainerDevice() const
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool hasDevice(const std::string &deviceName) const
check whether the vehicle is equiped with a device of the given type
MSRouteIterator myCurrEdge
Iterator to current route-edge.
MSDevice_Transportable * myContainerDevice
The containers this vehicle may have.
virtual void setArrivalPos(double arrivalPos)
Sets this vehicle&#39;s desired arrivalPos for its current route.
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.
long long int NumericalID
Definition: SUMOVehicle.h:63
const MSRouteIterator & getCurrentRouteEdge() const
Returns an iterator pointing to the current edge in this vehicles route.
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
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:83
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.
static NumericalID myCurrentNumericalIndex
double myChosenSpeedFactor
A precomputed factor by which the driver wants to be faster than the speed limit. ...