SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSBaseVehicle.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // A base class for vehicle implementations
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 #ifndef MSBaseVehicle_h
22 #define MSBaseVehicle_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <iostream>
35 #include <vector>
36 #include <set>
38 #include <utils/common/StdDefs.h>
39 #include "MSRoute.h"
40 #include "MSMoveReminder.h"
41 
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
47 class MSVehicleType;
48 
49 
50 // ===========================================================================
51 // class definitions
52 // ===========================================================================
57 class MSBaseVehicle : public SUMOVehicle {
58 public:
66  MSBaseVehicle(SUMOVehicleParameter* pars, const MSRoute* route, const MSVehicleType* type, const SUMOReal speedFactor);
67 
68 
70  virtual ~MSBaseVehicle();
71 
72 
74  const std::string& getID() const;
75 
80  const SUMOVehicleParameter& getParameter() const;
81 
82 
86  inline const MSRoute& getRoute() const {
87  return *myRoute;
88  }
89 
90 
94  inline const MSVehicleType& getVehicleType() const {
95  return *myType;
96  }
97 
98 
102  SUMOReal getMaxSpeed() const;
103 
104 
112  const MSEdge* succEdge(unsigned int nSuccs) const;
113 
118  const MSEdge* getEdge() const;
119 
120 
124  virtual bool isOnRoad() const {
125  return true;
126  }
127 
128 
134  virtual const MSEdge* getRerouteOrigin() const {
135  return *myCurrEdge;
136  }
137 
138 
148  void reroute(SUMOTime t, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, bool withTaz = false);
149 
150 
161  bool replaceRouteEdges(MSEdgeVector& edges, bool onInit = false);
162 
163 
169  virtual SUMOReal getAcceleration() const;
170 
176  virtual SUMOReal getSlope() const;
177 
183  void onDepart();
184 
188  inline SUMOTime getDeparture() const {
189  return myDeparture;
190  }
191 
196  virtual SUMOReal getArrivalPos() const {
197  return myArrivalPos;
198  }
199 
202  bool hasDeparted() const;
203 
207  virtual bool hasArrived() const;
208 
212  inline unsigned int getNumberReroutes() const {
213  return myNumberReroutes;
214  }
215 
217  SUMOReal getImpatience() const;
218 
219 
223  inline const std::vector<MSDevice*>& getDevices() const {
224  return myDevices;
225  }
226 
233  virtual void addPerson(MSPerson* person);
234 
239  bool hasValidRoute(std::string& msg) const;
240 
246  void addReminder(MSMoveReminder* rem);
247 
253  void removeReminder(MSMoveReminder* rem);
254 
265  virtual void activateReminders(const MSMoveReminder::Notification reason);
266 
271  return myChosenSpeedFactor;
272  }
273 
277  inline void setChosenSpeedFactor(SUMOReal factor) {
278  myChosenSpeedFactor = factor;
279  }
280 
282  MSDevice* getDevice(const std::type_info& type) const;
283 
284 
286 
287 
289  virtual void saveState(OutputDevice& out);
290 
292 
293 protected:
296  void calculateArrivalPos();
297 
298 protected:
301 
303  const MSRoute* myRoute;
304 
307 
310 
313 
314 
317 
319  typedef std::vector< std::pair<MSMoveReminder*, SUMOReal> > MoveReminderCont;
320 
324 
326  std::vector<MSDevice*> myDevices;
327 
330 
333 
335  unsigned int myNumberReroutes;
336 
337 private:
338  /* @brief magic value for undeparted vehicles
339  * @note: in previous versions this was -1
340  */
342 
345 
346 
347 #ifdef _DEBUG
348 public:
349  static void initMoveReminderOutput(const OptionsCont& oc);
350 
351 protected:
353  void traceMoveReminder(const std::string& type, MSMoveReminder* rem, SUMOReal pos, bool keep) const;
354 
356  const bool myTraceMoveReminders;
357 private:
359  static std::set<std::string> myShallTraceMoveReminders;
360 #endif
361 
362 
363 };
364 
365 #endif
366 
367 /****************************************************************************/
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:59
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:86
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:57
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:73
Representation of a vehicle.
Definition: SUMOVehicle.h:63
virtual SUMOReal getAcceleration() const
Returns the vehicle's acceleration.
std::vector< const MSEdge * > MSEdgeVector
Definition: MSPerson.h:53
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:68
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:94
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:70
#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.