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  // 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  SUMOReal getPreviousSpeed() const;
66 
67  friend class GUIBaseVehicle;
68 
76  MSBaseVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
77  const MSVehicleType* type, const SUMOReal speedFactor);
78 
79 
81  virtual ~MSBaseVehicle();
82 
83 
85  const std::string& getID() const;
86 
91  const SUMOVehicleParameter& getParameter() const;
92 
93 
97  inline const MSRoute& getRoute() const {
98  return *myRoute;
99  }
100 
101 
105  inline const MSVehicleType& getVehicleType() const {
106  return *myType;
107  }
108 
109 
113  inline SUMOVehicleClass getVClass() const {
114  return myType->getParameter().vehicleClass;
115  }
116 
120  SUMOReal getMaxSpeed() const;
121 
122 
130  const MSEdge* succEdge(int nSuccs) const;
131 
136  const MSEdge* getEdge() const;
137 
138 
142  virtual bool isOnRoad() const {
143  return true;
144  }
145 
150  virtual bool isRemoteControlled() const {
151  return false;
152  }
153 
157  virtual bool isFrontOnLane(const MSLane*) const {
158  return true;
159  }
160 
166  return 0;
167  }
168 
174  virtual const MSEdge* getRerouteOrigin() const {
175  return *myCurrEdge;
176  }
177 
178 
183  return myCurrEdge;
184  }
185 
186 
196  void reroute(SUMOTime t, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit = false, const bool withTaz = false);
197 
198 
210  bool replaceRouteEdges(ConstMSEdgeVector& edges, bool onInit = false, bool check = false);
211 
212 
218  virtual SUMOReal getAcceleration() const;
219 
225  virtual SUMOReal getSlope() const;
226 
232  void onDepart();
233 
237  inline SUMOTime getDeparture() const {
238  return myDeparture;
239  }
240 
243  return getDeparture() - getParameter().depart;
244  }
245 
246 
250  inline SUMOReal getDepartPos() const {
251  return myDepartPos;
252  }
253 
258  virtual SUMOReal getArrivalPos() const {
259  return myArrivalPos;
260  }
261 
264  virtual void setArrivalPos(SUMOReal arrivalPos) {
265  myArrivalPos = arrivalPos;
266  }
267 
270  bool hasDeparted() const;
271 
275  virtual bool hasArrived() const;
276 
280  inline int getNumberReroutes() const {
281  return myNumberReroutes;
282  }
283 
285  SUMOReal getImpatience() const;
286 
287 
291  inline const std::vector<MSDevice*>& getDevices() const {
292  return myDevices;
293  }
294 
301  virtual void addPerson(MSTransportable* person);
302 
303 
310  virtual void addContainer(MSTransportable* container);
311 
317  bool hasValidRoute(std::string& msg, const MSRoute* route = 0) const;
318 
324  void addReminder(MSMoveReminder* rem);
325 
331  void removeReminder(MSMoveReminder* rem);
332 
343  virtual void activateReminders(const MSMoveReminder::Notification reason);
344 
349  return myChosenSpeedFactor;
350  }
351 
355  inline void setChosenSpeedFactor(const SUMOReal factor) {
356  myChosenSpeedFactor = factor;
357  }
358 
360  MSDevice* getDevice(const std::type_info& type) const;
361 
362 
364 
365 
367  virtual void saveState(OutputDevice& out);
368 
370 
378  void addStops(const bool ignoreStopErrors);
379 
380 protected:
383  void calculateArrivalParams();
384 
387  virtual const ConstMSEdgeVector getStopEdges() const = 0;
388 
389 protected:
392 
394  const MSRoute* myRoute;
395 
398 
401 
404 
405 
408 
410  // The SUMOReal value holds the relative position offset, i.e.,
411  // offset + vehicle-position - moveReminder-position = distance,
412  // i.e. the offset is counted up when the vehicle continues to a
413  // succeeding lane.
414  typedef std::vector< std::pair<MSMoveReminder*, SUMOReal> > MoveReminderCont;
415 
417  MoveReminderCont myMoveReminders;
419 
421  std::vector<MSDevice*> myDevices;
422 
425 
428 
431 
434 
437 
438  /* @brief magic value for undeparted vehicles
439  * @note: in previous versions this was -1
440  */
442 
443 private:
446 
447 
448 #ifdef _DEBUG
449 public:
450  static void initMoveReminderOutput(const OptionsCont& oc);
451 
452 protected:
454  void traceMoveReminder(const std::string& type, MSMoveReminder* rem, SUMOReal pos, bool keep) const;
455 
457  const bool myTraceMoveReminders;
458 private:
460  static std::set<std::string> myShallTraceMoveReminders;
461 #endif
462 
463 
464 };
465 
466 #endif
467 
468 /****************************************************************************/
void removeReminder(MSMoveReminder *rem)
Removes a MoveReminder dynamically.
const MSVehicleType * myType
This Vehicle&#39;s type.
long long int SUMOTime
Definition: SUMOTime.h:43
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.
SUMOReal myArrivalPos
The position on the destination lane where the vehicle stops.
virtual SUMOReal getAcceleration() const
Returns the vehicle&#39;s acceleration.
bool hasDeparted() const
Returns whether this vehicle has already departed.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
const SUMOVehicleParameter & getParameter() const
Returns the vehicle&#39;s parameter (including departure definition)
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.
Definition: MSBaseVehicle.h:97
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
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
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
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)
virtual bool isFrontOnLane(const MSLane *) const
Returns the information whether the front of the vehhicle is on the given lane.
virtual SUMOReal getArrivalPos() const
Returns this vehicle&#39;s desired arrivalPos for its current route (may change on reroute) ...
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...
SUMOReal getDepartPos() const
Returns this vehicle&#39;s real departure position.
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.
SUMOReal getMaxSpeed() const
Returns the maximum speed.
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.
const std::vector< MSDevice * > & getDevices() const
Returns this vehicle&#39;s devices.
const SUMOVTypeParameter & getParameter() const
SUMOReal getPreviousSpeed() const
Returns the vehicle&#39;s previous speed.
Abstract in-vehicle device.
Definition: MSDevice.h:69
SUMOReal myChosenSpeedFactor
A precomputed factor by which the driver wants to be faster than the speed limit. ...
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 SUMOReal getSlope() const
Returns the slope of the road at vehicle&#39;s position.
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 void activateReminders(const MSMoveReminder::Notification reason)
"Activates" all current move reminder
SUMOReal getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
virtual SUMOReal getLateralPositionOnLane() const
Get the vehicle&#39;s lateral position on the lane.
void onDepart()
Called when the vehicle is inserted into the network.
A storage for options typed value containers)
Definition: OptionsCont.h:99
bool replaceRouteEdges(ConstMSEdgeVector &edges, bool onInit=false, bool check=false)
Replaces the current route by the given edges.
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
#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.
SUMOReal getImpatience() const
Returns this vehicles impatience.
const MSRouteIterator & getCurrentRouteEdge() const
Returns an iterator pointing to the current edge in this vehicles route.
SUMOReal myDepartPos
The real depart position.
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.
SUMOTime myDeparture
The real departure time.
static const SUMOTime NOT_YET_DEPARTED