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-2013 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 
138  void reroute(SUMOTime t, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, bool withTaz = false);
139 
140 
151  bool replaceRouteEdges(const MSEdgeVector& edges, bool onInit = false);
152 
153 
159  virtual SUMOReal getAcceleration() const;
160 
166  void onDepart();
167 
171  inline SUMOTime getDeparture() const {
172  return myDeparture;
173  }
174 
179  virtual SUMOReal getArrivalPos() const {
180  return myArrivalPos;
181  }
182 
185  bool hasDeparted() const;
186 
190  virtual bool hasArrived() const;
191 
195  inline unsigned int getNumberReroutes() const {
196  return myNumberReroutes;
197  }
198 
202  inline const std::vector<MSDevice*>& getDevices() const {
203  return myDevices;
204  }
205 
212  virtual void addPerson(MSPerson* person);
213 
218  bool hasValidRoute(std::string& msg) const;
219 
225  void addReminder(MSMoveReminder* rem);
226 
232  void removeReminder(MSMoveReminder* rem);
233 
244  virtual void activateReminders(const MSMoveReminder::Notification reason);
245 
250  return myChosenSpeedFactor;
251  }
252 
254  MSDevice* getDevice(const std::type_info& type) const;
255 
256 
258 
259 
261  virtual void saveState(OutputDevice& out);
262 
264 
265 protected:
268  void calculateArrivalPos();
269 
270 protected:
273 
275  const MSRoute* myRoute;
276 
279 
282 
285 
286 
289 
291  typedef std::vector< std::pair<MSMoveReminder*, SUMOReal> > MoveReminderCont;
292 
296 
298  std::vector<MSDevice*> myDevices;
299 
302 
305 
307  unsigned int myNumberReroutes;
308 
309 private:
310  /* @brief magic value for undeparted vehicles
311  * @note: in previous versions this was -1
312  */
314 
317 
318 
319 #ifdef _DEBUG
320 public:
321  static void initMoveReminderOutput(const OptionsCont& oc);
322 
323 protected:
325  void traceMoveReminder(const std::string& type, MSMoveReminder* rem, SUMOReal pos, bool keep) const;
326 
328  const bool myTraceMoveReminders;
329 private:
331  static std::set<std::string> myShallTraceMoveReminders;
332 #endif
333 
334 
335 };
336 
337 #endif
338 
339 /****************************************************************************/
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.
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&#39;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.
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)
bool replaceRouteEdges(const MSEdgeVector &edges, bool onInit=false)
Replaces the current route by the given edges.
const MSRoute & getRoute() const
Returns the current route.
Definition: MSBaseVehicle.h:86
virtual ~MSBaseVehicle()
Destructor.
const MSRoute * myRoute
This Vehicle&#39;s route.
unsigned int myNumberReroutes
The number of reroutings.
bool hasDeparted() const
Returns whether this vehicle has already departed.
const SUMOVehicleParameter * myParameter
This Vehicle&#39;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&#39;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&#39;th successor of edge the vehicle is currently at.
const SUMOReal myChosenSpeedFactor
A precomputed factor by which the driver wants to be faster than the speed limit. ...
Something on a lane to be noticed about vehicle movement.
Abstract in-vehicle device.
Definition: MSDevice.h:68
Structure representing possible vehicle parameter.
virtual void activateReminders(const MSMoveReminder::Notification reason)
&quot;Activates&quot; 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&#39;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
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&#39;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:221
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&#39;s real departure time.
virtual SUMOReal getArrivalPos() const
Returns this vehicle&#39;s desired arrivalPos for its current route (may change on reroute) ...
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&#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.