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-2016 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 
59  friend class GUIBaseVehicle;
60 
68  MSBaseVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
69  const MSVehicleType* type, const SUMOReal speedFactor);
70 
71 
73  virtual ~MSBaseVehicle();
74 
75 
77  const std::string& getID() const;
78 
83  const SUMOVehicleParameter& getParameter() const;
84 
85 
89  inline const MSRoute& getRoute() const {
90  return *myRoute;
91  }
92 
93 
97  inline const MSVehicleType& getVehicleType() const {
98  return *myType;
99  }
100 
101 
105  inline SUMOVehicleClass getVClass() const {
106  return myType->getParameter().vehicleClass;
107  }
108 
112  SUMOReal getMaxSpeed() const;
113 
114 
122  const MSEdge* succEdge(int nSuccs) const;
123 
128  const MSEdge* getEdge() const;
129 
130 
134  virtual bool isOnRoad() const {
135  return true;
136  }
137 
142  virtual bool isRemoteControlled() const {
143  return false;
144  }
145 
149  virtual bool isFrontOnLane(const MSLane*) const {
150  return true;
151  }
152 
158  return 0;
159  }
160 
166  virtual const MSEdge* getRerouteOrigin() const {
167  return *myCurrEdge;
168  }
169 
170 
175  return myCurrEdge;
176  }
177 
178 
188  void reroute(SUMOTime t, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit = false, const bool withTaz = false);
189 
190 
202  bool replaceRouteEdges(ConstMSEdgeVector& edges, bool onInit = false, bool check = false);
203 
204 
210  virtual SUMOReal getAcceleration() const;
211 
217  virtual SUMOReal getSlope() const;
218 
224  void onDepart();
225 
229  inline SUMOTime getDeparture() const {
230  return myDeparture;
231  }
232 
235  return getDeparture() - getParameter().depart;
236  }
237 
238 
242  inline SUMOReal getDepartPos() const {
243  return myDepartPos;
244  }
245 
250  virtual SUMOReal getArrivalPos() const {
251  return myArrivalPos;
252  }
253 
256  virtual void setArrivalPos(SUMOReal arrivalPos) {
257  myArrivalPos = arrivalPos;
258  }
259 
262  bool hasDeparted() const;
263 
267  virtual bool hasArrived() const;
268 
272  inline int getNumberReroutes() const {
273  return myNumberReroutes;
274  }
275 
277  SUMOReal getImpatience() const;
278 
279 
283  inline const std::vector<MSDevice*>& getDevices() const {
284  return myDevices;
285  }
286 
293  virtual void addPerson(MSTransportable* person);
294 
295 
302  virtual void addContainer(MSTransportable* container);
303 
309  bool hasValidRoute(std::string& msg, const MSRoute* route = 0) const;
310 
316  void addReminder(MSMoveReminder* rem);
317 
323  void removeReminder(MSMoveReminder* rem);
324 
335  virtual void activateReminders(const MSMoveReminder::Notification reason);
336 
341  return myChosenSpeedFactor;
342  }
343 
347  inline void setChosenSpeedFactor(const SUMOReal factor) {
348  myChosenSpeedFactor = factor;
349  }
350 
352  MSDevice* getDevice(const std::type_info& type) const;
353 
354 
356 
357 
359  virtual void saveState(OutputDevice& out);
360 
362 
370  void addStops(const bool ignoreStopErrors);
371 
372 
373 protected:
376  void calculateArrivalParams();
377 
380  virtual const ConstMSEdgeVector getStopEdges() const = 0;
381 
382 protected:
385 
387  const MSRoute* myRoute;
388 
391 
394 
397 
398 
401 
403  typedef std::vector< std::pair<MSMoveReminder*, SUMOReal> > MoveReminderCont;
404 
406  MoveReminderCont myMoveReminders;
408 
410  std::vector<MSDevice*> myDevices;
411 
414 
417 
420 
423 
426 
427  /* @brief magic value for undeparted vehicles
428  * @note: in previous versions this was -1
429  */
431 
432 private:
435 
436 
437 #ifdef _DEBUG
438 public:
439  static void initMoveReminderOutput(const OptionsCont& oc);
440 
441 protected:
443  void traceMoveReminder(const std::string& type, MSMoveReminder* rem, SUMOReal pos, bool keep) const;
444 
446  const bool myTraceMoveReminders;
447 private:
449  static std::set<std::string> myShallTraceMoveReminders;
450 #endif
451 
452 
453 };
454 
455 #endif
456 
457 /****************************************************************************/
void removeReminder(MSMoveReminder *rem)
Removes a MoveReminder dynamically.
const MSVehicleType * myType
This Vehicle&#39;s type.
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
long long int SUMOTime
Definition: SUMOTime.h:43
MoveReminderCont myMoveReminders
Current lane&#39;s move reminder.
SUMOReal myArrivalPos
The position on the destination lane where the vehicle stops.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
SUMOReal getDepartPos() const
Returns this vehicle&#39;s real departure position.
SUMOReal getMaxSpeed() const
Returns the maximum speed.
SUMOVehicleClass getVClass() const
Returns the vehicle&#39;s access class.
SUMOReal getImpatience() const
Returns this vehicles impatience.
const MSRouteIterator & getCurrentRouteEdge() const
Returns an iterator pointing to the current edge in this vehicles route.
Notification
Definition of a vehicle state.
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
SUMOVehicleClass vehicleClass
The vehicle&#39;s class.
const MSRoute & getRoute() const
Returns the current route.
Definition: MSBaseVehicle.h:89
virtual ~MSBaseVehicle()
Destructor.
const MSRoute * myRoute
This Vehicle&#39;s route.
bool hasDeparted() const
Returns whether this vehicle has already departed.
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:78
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
bool hasValidRoute(std::string &msg, const MSRoute *route=0) const
Validates the current or given route.
MSBaseVehicle(SUMOVehicleParameter *pars, const MSRoute *route, const MSVehicleType *type, const SUMOReal speedFactor)
Constructor.
The car-following model and parameter.
Definition: MSVehicleType.h:74
virtual void saveState(OutputDevice &out)
Saves the (common) state of a vehicle.
std::vector< std::pair< MSMoveReminder *, SUMOReal > > MoveReminderCont
Definition of a move reminder container.
void calculateArrivalParams()
(Re-)Calculates the arrival position and lane from the vehicle parameters
virtual bool isFrontOnLane(const MSLane *) const
Returns the information whether the front of the vehhicle is on the given lane.
A road/street connecting two junctions.
Definition: MSEdge.h:80
virtual void addPerson(MSTransportable *person)
Adds a person to this vehicle.
const SUMOVTypeParameter & getParameter() const
Representation of a vehicle.
Definition: SUMOVehicle.h:66
void setChosenSpeedFactor(const SUMOReal factor)
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
virtual SUMOReal getAcceleration() const
Returns the vehicle&#39;s acceleration.
SUMOTime getDepartDelay() const
Returns the depart delay.
MSBaseVehicle & operator=(const MSBaseVehicle &s)
invalidated assignment operator
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:65
SUMOTime depart
The vehicle&#39;s departure time.
A MSVehicle extended by some values for usage within the gui.
virtual void setArrivalPos(SUMOReal arrivalPos)
Sets this vehicle&#39;s desired arrivalPos for its current route.
virtual const ConstMSEdgeVector getStopEdges() const =0
Returns the list of still pending stop edges.
Something on a lane to be noticed about vehicle movement.
Abstract in-vehicle device.
Definition: MSDevice.h:69
virtual SUMOReal getLateralPositionOnLane() const
Get the vehicle&#39;s lateral position on the lane.
SUMOReal myChosenSpeedFactor
A precomputed factor by which the driver wants to be faster than the speed limit. ...
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
Structure representing possible vehicle parameter.
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs&#39;th successor of edge the vehicle is currently at.
virtual void activateReminders(const MSMoveReminder::Notification reason)
"Activates" all current move reminder
void onDepart()
Called when the vehicle is inserted into the network.
A storage for options typed value containers)
Definition: OptionsCont.h:99
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
Definition: MSBaseVehicle.h:97
bool replaceRouteEdges(ConstMSEdgeVector &edges, bool onInit=false, bool check=false)
Replaces the current route by the given edges.
virtual bool hasArrived() const
Returns whether this vehicle has already arived (by default this is true if the vehicle has reached i...
virtual const MSEdge * getRerouteOrigin() const
Returns the starting point for reroutes (usually the current edge)
SUMOReal getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
int myNumberReroutes
The number of reroutings.
const SUMOVehicleParameter & getParameter() const
Returns the vehicle&#39;s parameter (including departure definition)
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:213
MSRouteIterator myCurrEdge
Iterator to current route-edge.
void reroute(SUMOTime t, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false)
Performs a rerouting using the given router.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
SUMOTime getDeparture() const
Returns this vehicle&#39;s real departure time.
virtual SUMOReal getArrivalPos() const
Returns this vehicle&#39;s desired arrivalPos for its current route (may change on reroute) ...
virtual SUMOReal getSlope() const
Returns the slope of the road at vehicle&#39;s position.
SUMOReal myDepartPos
The real depart position.
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.
const std::vector< MSDevice * > & getDevices() const
Returns this vehicle&#39;s devices.
SUMOTime myDeparture
The real departure time.
static const SUMOTime NOT_YET_DEPARTED
const std::string & getID() const
Returns the name of the vehicle.
virtual bool isRemoteControlled() const
Returns the information whether the vehicle is fully controlled via TraCI.