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-sim.org/
12 // Copyright (C) 2010-2014 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 
43 
44 // ===========================================================================
45 // class declarations
46 // ===========================================================================
48 class MSVehicleType;
49 
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
58 class MSBaseVehicle : public SUMOVehicle {
59 public:
67  MSBaseVehicle(SUMOVehicleParameter* pars, const MSRoute* route, const MSVehicleType* type, const SUMOReal speedFactor);
68 
69 
71  virtual ~MSBaseVehicle();
72 
73 
75  const std::string& getID() const;
76 
81  const SUMOVehicleParameter& getParameter() const;
82 
83 
87  inline const MSRoute& getRoute() const {
88  return *myRoute;
89  }
90 
91 
95  inline const MSVehicleType& getVehicleType() const {
96  return *myType;
97  }
98 
99 
103  SUMOReal getMaxSpeed() const;
104 
105 
113  const MSEdge* succEdge(unsigned int nSuccs) const;
114 
119  const MSEdge* getEdge() const;
120 
121 
125  virtual bool isOnRoad() const {
126  return true;
127  }
128 
129 
135  virtual const MSEdge* getRerouteOrigin() const {
136  return *myCurrEdge;
137  }
138 
139 
149  void reroute(SUMOTime t, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, bool withTaz = false);
150 
151 
162  bool replaceRouteEdges(MSEdgeVector& edges, bool onInit = false);
163 
164 
170  virtual SUMOReal getAcceleration() const;
171 
177  virtual SUMOReal getSlope() const;
178 
184  void onDepart();
185 
189  inline SUMOTime getDeparture() const {
190  return myDeparture;
191  }
192 
197  virtual SUMOReal getArrivalPos() const {
198  return myArrivalPos;
199  }
200 
203  bool hasDeparted() const;
204 
208  virtual bool hasArrived() const;
209 
213  inline unsigned int getNumberReroutes() const {
214  return myNumberReroutes;
215  }
216 
218  SUMOReal getImpatience() const;
219 
220 
224  inline const std::vector<MSDevice*>& getDevices() const {
225  return myDevices;
226  }
227 
234  virtual void addPerson(MSPerson* person);
235 
240  bool hasValidRoute(std::string& msg) const;
241 
247  void addReminder(MSMoveReminder* rem);
248 
254  void removeReminder(MSMoveReminder* rem);
255 
266  virtual void activateReminders(const MSMoveReminder::Notification reason);
267 
272  return myChosenSpeedFactor;
273  }
274 
278  inline void setChosenSpeedFactor(SUMOReal factor) {
279  myChosenSpeedFactor = factor;
280  }
281 
283  MSDevice* getDevice(const std::type_info& type) const;
284 
285 
287 
288 
290  virtual void saveState(OutputDevice& out);
291 
293 
294 protected:
297  void calculateArrivalPos();
298 
299 protected:
302 
304  const MSRoute* myRoute;
305 
308 
311 
314 
315 
318 
320  typedef std::vector< std::pair<MSMoveReminder*, SUMOReal> > MoveReminderCont;
321 
323  MoveReminderCont myMoveReminders;
325 
327  std::vector<MSDevice*> myDevices;
328 
331 
334 
336  unsigned int myNumberReroutes;
337 
338 private:
339  /* @brief magic value for undeparted vehicles
340  * @note: in previous versions this was -1
341  */
343 
346 
347 
348 #ifdef _DEBUG
349 public:
350  static void initMoveReminderOutput(const OptionsCont& oc);
351 
352 protected:
354  void traceMoveReminder(const std::string& type, MSMoveReminder* rem, SUMOReal pos, bool keep) const;
355 
357  const bool myTraceMoveReminders;
358 private:
360  static std::set<std::string> myShallTraceMoveReminders;
361 #endif
362 
363 
364 };
365 
366 #endif
367 
368 /****************************************************************************/
void removeReminder(MSMoveReminder *rem)
Removes a MoveReminder dynamically.
void setChosenSpeedFactor(SUMOReal factor)
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
const MSVehicleType * myType
This Vehicle's type.
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
void reroute(SUMOTime t, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, bool withTaz=false)
Performs a rerouting using the given router.
unsigned int getNumberReroutes() const
Returns the number of new routes this vehicle got.
MoveReminderCont myMoveReminders
Current lane's move reminder.
SUMOReal myArrivalPos
the position on the destination lane where the vehicle stops
SUMOReal getMaxSpeed() const
Returns the maximum speed.
virtual void addPerson(MSPerson *person)
Adds a person to this vehicle.
SUMOReal getImpatience() const
Returns this vehicles impatience.
MSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:60
Notification
Definition of a vehicle state.
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
const MSRoute & getRoute() const
Returns the current route.
Definition: MSBaseVehicle.h:87
virtual ~MSBaseVehicle()
Destructor.
const MSRoute * myRoute
This Vehicle's route.
unsigned int myNumberReroutes
The number of reroutings.
bool hasDeparted() const
Returns whether this vehicle has already departed.
const SUMOVehicleParameter * myParameter
This Vehicle's parameter.
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:58
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.
A road/street connecting two junctions.
Definition: MSEdge.h:74
Representation of a vehicle.
Definition: SUMOVehicle.h:64
virtual SUMOReal getAcceleration() const
Returns the vehicle's acceleration.
std::vector< const MSEdge * > MSEdgeVector
Definition: MSPerson.h:57
MSBaseVehicle & operator=(const MSBaseVehicle &s)
invalidated assignment operator
const MSEdge * succEdge(unsigned int nSuccs) const
Returns the nSuccs'th successor of edge the vehicle is currently at.
Something on a lane to be noticed about vehicle movement.
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. ...
bool replaceRouteEdges(MSEdgeVector &edges, bool onInit=false)
Replaces the current route by the given edges.
Structure representing possible vehicle parameter.
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:108
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:95
virtual bool hasArrived() const
Returns whether this vehicle has already arived (by default this is true if the vehicle has reached i...
void calculateArrivalPos()
(Re-)Calculates the arrival position from the vehicle parameters
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 SUMOTime
Definition: SUMOTime.h:43
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
bool hasValidRoute(std::string &msg) const
Validates the current route.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:215
MSRouteIterator myCurrEdge
Iterator to current route-edge.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
SUMOTime getDeparture() const
Returns this vehicle's real departure time.
virtual SUMOReal getArrivalPos() const
Returns this vehicle's desired arrivalPos for its current route (may change on reroute) ...
virtual SUMOReal getSlope() const
Returns the slope of the road at vehicle's position.
void addReminder(MSMoveReminder *rem)
Adds a MoveReminder dynamically.
std::vector< MSDevice * > myDevices
The devices this vehicle has.
const std::vector< MSDevice * > & getDevices() const
Returns this vehicle'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.