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-2018 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 
81  const std::string& getID() const;
82 
87  const SUMOVehicleParameter& getParameter() const;
88 
90  void replaceParameter(const SUMOVehicleParameter* newParameter);
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 
164  virtual bool wasRemoteControlled(SUMOTime lookBack = DELTA_T) const {
165  UNUSED_PARAMETER(lookBack);
166  return false;
167  }
168 
172  virtual bool isFrontOnLane(const MSLane*) const {
173  return true;
174  }
175 
180  virtual double getLateralPositionOnLane() const {
181  return 0;
182  }
183 
189  virtual const MSEdge* getRerouteOrigin() const {
190  return *myCurrEdge;
191  }
192 
193 
198  return myCurrEdge;
199  }
200 
201 
211  void reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit = false, const bool withTaz = false);
212 
213 
226  bool replaceRouteEdges(ConstMSEdgeVector& edges, double cost, double savings, const std::string& info, bool onInit = false, bool check = false, bool removeStops = true);
227 
228 
234  virtual double getAcceleration() const;
235 
241  virtual double getSlope() const;
242 
248  void onDepart();
249 
253  inline SUMOTime getDeparture() const {
254  return myDeparture;
255  }
256 
259  return getDeparture() - getParameter().depart;
260  }
261 
262 
266  inline double getDepartPos() const {
267  return myDepartPos;
268  }
269 
274  virtual double getArrivalPos() const {
275  return myArrivalPos;
276  }
277 
280  virtual void setArrivalPos(double arrivalPos) {
281  myArrivalPos = arrivalPos;
282  }
283 
286  bool hasDeparted() const;
287 
291  virtual bool hasArrived() const;
292 
296  inline int getNumberReroutes() const {
297  return myNumberReroutes;
298  }
299 
301  double getImpatience() const;
302 
306  int getPersonNumber() const;
307 
311  std::vector<std::string> getPersonIDList() const;
312 
316  int getContainerNumber() const;
317 
318 
322  inline const std::vector<MSVehicleDevice*>& getDevices() const {
323  return myDevices;
324  }
325 
332  virtual void addPerson(MSTransportable* person);
333 
334 
341  virtual void addContainer(MSTransportable* container);
342 
345 
347  const std::vector<MSTransportable*>& getPersons() const;
348 
350  const std::vector<MSTransportable*>& getContainers() const;
351 
352 
358  bool hasValidRoute(std::string& msg, const MSRoute* route = 0) const;
359 
365  void addReminder(MSMoveReminder* rem);
366 
372  void removeReminder(MSMoveReminder* rem);
373 
385  virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
386 
387 
391  inline double getLength() const {
392  return myType->getLength();
393  }
394 
395 
399  inline double getWidth() const {
400  return myType->getWidth();
401  }
402 
403 
407  inline double getChosenSpeedFactor() const {
408  return myChosenSpeedFactor;
409  }
410 
414  inline void setChosenSpeedFactor(const double factor) {
415  myChosenSpeedFactor = factor;
416  }
417 
419  MSVehicleDevice* getDevice(const std::type_info& type) const;
420 
421 
430  void replaceVehicleType(MSVehicleType* type);
431 
432 
441 
443 
444 
446  virtual void saveState(OutputDevice& out);
447 
449 
457  void addStops(const bool ignoreStopErrors);
458 
460  virtual bool isSelected() const {
461  return false;
462  }
463 
464  inline NumericalID getNumericalID() const {
465  return myNumericalID;
466  }
467 
468 protected:
471  void calculateArrivalParams();
472 
475  virtual const ConstMSEdgeVector getStopEdges() const = 0;
476 
477 protected:
480 
482  const MSRoute* myRoute;
483 
486 
489 
492 
493 
496 
498  // The double value holds the relative position offset, i.e.,
499  // offset + vehicle-position - moveReminder-position = distance,
500  // i.e. the offset is counted up when the vehicle continues to a
501  // succeeding lane.
502  typedef std::vector< std::pair<MSMoveReminder*, double> > MoveReminderCont;
503 
505  MoveReminderCont myMoveReminders;
507 
509  std::vector<MSVehicleDevice*> myDevices;
510 
513 
516 
519 
521  double myDepartPos;
522 
524  double myArrivalPos;
525 
528 
531 
532  /* @brief magic value for undeparted vehicles
533  * @note: in previous versions this was -1
534  */
536 
537  static std::vector<MSTransportable*> myEmptyTransportableVector;
538 
539 private:
541 
543 
544 private:
547 
548 #ifdef _DEBUG
549 public:
550  static void initMoveReminderOutput(const OptionsCont& oc);
551 
552 protected:
554  void traceMoveReminder(const std::string& type, MSMoveReminder* rem, double pos, bool keep) const;
555 
557  const bool myTraceMoveReminders;
558 private:
560  static std::set<std::string> myShallTraceMoveReminders;
561 #endif
562 
563 
564 };
565 
566 #endif
567 
568 /****************************************************************************/
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.
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:36
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...
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.
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:72
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:33
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:75
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:60
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
SUMOTime depart
The vehicle&#39;s departure time.
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.
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 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:92
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
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.
void reroute(SUMOTime t, const std::string &info, 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.
long long int NumericalID
Definition: SUMOVehicle.h:62
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:78
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. ...