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 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
50 class MSBaseVehicle : public SUMOVehicle {
51 public:
52  // XXX: This definition was introduced to make the MSVehicle's previousSpeed
53  // available in the context of MSMoveReminder::notifyMove(). Another solution
54  // would be to modify notifyMove()'s interface to work with MSVehicle instead
55  // of SUMOVehicle (it is only called with MSVehicles!). Refs. #2579
59  double getPreviousSpeed() const;
60 
61  friend class GUIBaseVehicle;
62 
70  MSBaseVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
71  MSVehicleType* type, const double speedFactor);
72 
73 
75  virtual ~MSBaseVehicle();
76 
77 
79  const std::string& getID() const;
80 
85  const SUMOVehicleParameter& getParameter() const;
86 
88  void replaceParameter(const SUMOVehicleParameter* newParameter);
89 
91  bool hasDevice(const std::string& deviceName) const;
92 
94  void createDevice(const std::string& deviceName);
95 
97  std::string getDeviceParameter(const std::string& deviceName, const std::string& key) const;
98 
100  void setDeviceParameter(const std::string& deviceName, const std::string& key, const std::string& value);
101 
105  inline const MSRoute& getRoute() const {
106  return *myRoute;
107  }
108 
109 
113  inline const MSVehicleType& getVehicleType() const {
114  return *myType;
115  }
116 
117 
121  inline SUMOVehicleClass getVClass() const {
122  return myType->getParameter().vehicleClass;
123  }
124 
128  double getMaxSpeed() const;
129 
130 
138  const MSEdge* succEdge(int nSuccs) const;
139 
144  const MSEdge* getEdge() const;
145 
146 
150  virtual bool isOnRoad() const {
151  return true;
152  }
153 
158  virtual bool isRemoteControlled() const {
159  return false;
160  }
161 
162  virtual bool wasRemoteControlled(SUMOTime lookBack = DELTA_T) const {
163  UNUSED_PARAMETER(lookBack);
164  return false;
165  }
166 
170  virtual bool isFrontOnLane(const MSLane*) const {
171  return true;
172  }
173 
178  virtual double getLateralPositionOnLane() const {
179  return 0;
180  }
181 
187  virtual const MSEdge* getRerouteOrigin() const {
188  return *myCurrEdge;
189  }
190 
191 
196  return myCurrEdge;
197  }
198 
199 
209  void reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit = false, const bool withTaz = false);
210 
211 
224  bool replaceRouteEdges(ConstMSEdgeVector& edges, const std::string& info, bool onInit = false, bool check = false, bool removeStops = true);
225 
226 
232  virtual double getAcceleration() const;
233 
239  virtual double getSlope() const;
240 
246  void onDepart();
247 
251  inline SUMOTime getDeparture() const {
252  return myDeparture;
253  }
254 
257  return getDeparture() - getParameter().depart;
258  }
259 
260 
264  inline double getDepartPos() const {
265  return myDepartPos;
266  }
267 
272  virtual double getArrivalPos() const {
273  return myArrivalPos;
274  }
275 
278  virtual void setArrivalPos(double arrivalPos) {
279  myArrivalPos = arrivalPos;
280  }
281 
284  bool hasDeparted() const;
285 
289  virtual bool hasArrived() const;
290 
294  inline int getNumberReroutes() const {
295  return myNumberReroutes;
296  }
297 
299  double getImpatience() const;
300 
304  int getPersonNumber() const;
305 
309  std::vector<std::string> getPersonIDList() const;
310 
314  int getContainerNumber() const;
315 
316 
320  inline const std::vector<MSDevice*>& getDevices() const {
321  return myDevices;
322  }
323 
330  virtual void addPerson(MSTransportable* person);
331 
332 
339  virtual void addContainer(MSTransportable* container);
340 
343 
345  const std::vector<MSTransportable*>& getPersons() const;
346 
348  const std::vector<MSTransportable*>& getContainers() const;
349 
350 
356  bool hasValidRoute(std::string& msg, const MSRoute* route = 0) const;
357 
363  void addReminder(MSMoveReminder* rem);
364 
370  void removeReminder(MSMoveReminder* rem);
371 
383  virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
384 
385 
389  inline double getLength() const {
390  return myType->getLength();
391  }
392 
393 
397  inline double getWidth() const {
398  return myType->getWidth();
399  }
400 
401 
405  inline double getChosenSpeedFactor() const {
406  return myChosenSpeedFactor;
407  }
408 
412  inline void setChosenSpeedFactor(const double factor) {
413  myChosenSpeedFactor = factor;
414  }
415 
417  MSDevice* getDevice(const std::type_info& type) const;
418 
419 
428  void replaceVehicleType(MSVehicleType* type);
429 
430 
439 
441 
442 
444  virtual void saveState(OutputDevice& out);
445 
447 
455  void addStops(const bool ignoreStopErrors);
456 
458  virtual bool isSelected() const {
459  return false;
460  }
461 
462 protected:
465  void calculateArrivalParams();
466 
469  virtual const ConstMSEdgeVector getStopEdges() const = 0;
470 
471 protected:
474 
476  const MSRoute* myRoute;
477 
480 
483 
486 
487 
490 
492  // The double value holds the relative position offset, i.e.,
493  // offset + vehicle-position - moveReminder-position = distance,
494  // i.e. the offset is counted up when the vehicle continues to a
495  // succeeding lane.
496  typedef std::vector< std::pair<MSMoveReminder*, double> > MoveReminderCont;
497 
499  MoveReminderCont myMoveReminders;
501 
503  std::vector<MSDevice*> myDevices;
504 
507 
510 
513 
515  double myDepartPos;
516 
518  double myArrivalPos;
519 
522 
525 
526  /* @brief magic value for undeparted vehicles
527  * @note: in previous versions this was -1
528  */
530 
531  static std::vector<MSTransportable*> myEmptyTransportableVector;
532 
533 private:
536 
537 #ifdef _DEBUG
538 public:
539  static void initMoveReminderOutput(const OptionsCont& oc);
540 
541 protected:
543  void traceMoveReminder(const std::string& type, MSMoveReminder* rem, double pos, bool keep) const;
544 
546  const bool myTraceMoveReminders;
547 private:
549  static std::set<std::string> myShallTraceMoveReminders;
550 #endif
551 
552 
553 };
554 
555 #endif
556 
557 /****************************************************************************/
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 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:50
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
bool replaceRouteEdges(ConstMSEdgeVector &edges, const std::string &info, bool onInit=false, bool check=false, bool removeStops=true)
Replaces the current route by the given edges.
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
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 std::vector< MSDevice * > & getDevices() const
Returns this vehicle&#39;s devices.
const SUMOVTypeParameter & getParameter() const
std::vector< std::string > getPersonIDList() const
Returns the list of persons.
Abstract in-vehicle device.
Definition: MSDevice.h:65
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.
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 removeTransportable(MSTransportable *t)
removes a person or container
MSVehicleType * myType
This vehicle&#39;s type.
static std::vector< MSTransportable * > myEmptyTransportableVector
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
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: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.
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:71
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. ...