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 /****************************************************************************/
9 // A base class for vehicle implementations
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
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 #include "MSVehicleType.h"
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
52 class MSBaseVehicle : public SUMOVehicle {
53 public:
61  MSBaseVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
62  const MSVehicleType* type, const SUMOReal speedFactor);
63 
64 
66  virtual ~MSBaseVehicle();
67 
68 
70  const std::string& getID() const;
71 
76  const SUMOVehicleParameter& getParameter() const;
77 
78 
82  inline const MSRoute& getRoute() const {
83  return *myRoute;
84  }
85 
86 
90  inline const MSVehicleType& getVehicleType() const {
91  return *myType;
92  }
93 
94 
98  inline SUMOVehicleClass getVClass() const {
100  }
101 
105  SUMOReal getMaxSpeed() const;
106 
107 
115  const MSEdge* succEdge(unsigned int nSuccs) const;
116 
121  const MSEdge* getEdge() const;
122 
123 
127  virtual bool isOnRoad() const {
128  return true;
129  }
130 
131 
137  virtual const MSEdge* getRerouteOrigin() const {
138  return *myCurrEdge;
139  }
140 
141 
151  void reroute(SUMOTime t, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, bool withTaz = false);
152 
153 
164  bool replaceRouteEdges(MSEdgeVector& edges, bool onInit = false);
165 
166 
172  virtual SUMOReal getAcceleration() const;
173 
179  virtual SUMOReal getSlope() const;
180 
186  void onDepart();
187 
191  inline SUMOTime getDeparture() const {
192  return myDeparture;
193  }
194 
199  virtual SUMOReal getArrivalPos() const {
200  return myArrivalPos;
201  }
202 
205  bool hasDeparted() const;
206 
210  virtual bool hasArrived() const;
211 
215  inline unsigned int getNumberReroutes() const {
216  return myNumberReroutes;
217  }
218 
220  SUMOReal getImpatience() const;
221 
222 
226  inline const std::vector<MSDevice*>& getDevices() const {
227  return myDevices;
228  }
229 
236  virtual void addPerson(MSPerson* person);
237 
242  bool hasValidRoute(std::string& msg) const;
243 
249  void addReminder(MSMoveReminder* rem);
250 
256  void removeReminder(MSMoveReminder* rem);
257 
268  virtual void activateReminders(const MSMoveReminder::Notification reason);
269 
274  return myChosenSpeedFactor;
275  }
276 
280  inline void setChosenSpeedFactor(const SUMOReal factor) {
281  myChosenSpeedFactor = factor;
282  }
283 
285  MSDevice* getDevice(const std::type_info& type) const;
286 
287 
289 
290 
292  virtual void saveState(OutputDevice& out);
293 
295 
303  void addStops(const bool ignoreStopErrors);
304 
305 
306 protected:
309  void calculateArrivalPos();
310 
311 protected:
314 
316  const MSRoute* myRoute;
317 
320 
323 
326 
327 
330 
332  typedef std::vector< std::pair<MSMoveReminder*, SUMOReal> > MoveReminderCont;
333 
337 
339  std::vector<MSDevice*> myDevices;
340 
343 
346 
348  unsigned int myNumberReroutes;
349 
350 private:
351  /* @brief magic value for undeparted vehicles
352  * @note: in previous versions this was -1
353  */
355 
358 
359 
360 #ifdef _DEBUG
361 public:
362  static void initMoveReminderOutput(const OptionsCont& oc);
363 
364 protected:
366  void traceMoveReminder(const std::string& type, MSMoveReminder* rem, SUMOReal pos, bool keep) const;
367 
369  const bool myTraceMoveReminders;
370 private:
372  static std::set<std::string> myShallTraceMoveReminders;
373 #endif
374 
375 
376 };
377 
378 #endif
379 
380 /****************************************************************************/
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
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
SUMOReal getMaxSpeed() const
Returns the maximum speed.
virtual void addPerson(MSPerson *person)
Adds a person to this vehicle.
SUMOVehicleClass getVClass() const
Returns the vehicle&#39;s access class.
Definition: MSBaseVehicle.h:98
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)
SUMOVehicleClass vehicleClass
The vehicle&#39;s class.
const MSRoute & getRoute() const
Returns the current route.
Definition: MSBaseVehicle.h:82
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:52
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:75
const SUMOVTypeParameter & getParameter() const
Representation of a vehicle.
Definition: SUMOVehicle.h:64
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.
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&#39;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.
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
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:90
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&#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:71
#define SUMOReal
Definition: config.h:218
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) ...
virtual SUMOReal getSlope() const
Returns the slope of the road at vehicle&#39;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&#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.