SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSVehicleControl.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // The class responsible for building and deletion of vehicles
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-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 MSVehicleControl_h
23 #define MSVehicleControl_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 <math.h>
36 #include <string>
37 #include <map>
38 #include <set>
40 #include <utils/common/SUMOTime.h>
42 
43 
44 // ===========================================================================
45 // class declarations
46 // ===========================================================================
47 class SUMOVehicle;
49 class MSVehicle;
50 class MSRoute;
51 class MSVehicleType;
52 class OutputDevice;
53 class MSEdge;
54 
55 
56 // ===========================================================================
57 // class definitions
58 // ===========================================================================
75 public:
77  typedef std::map<std::string, SUMOVehicle*>::const_iterator constVehIt;
78 
79 public:
82 
83 
85  virtual ~MSVehicleControl();
86 
87 
90 
103  virtual SUMOVehicle* buildVehicle(SUMOVehicleParameter* defs, const MSRoute* route,
104  const MSVehicleType* type,
105  const bool ignoreStopErrors, const bool fromRouteFile = true);
107 
108 
109 
112 
125  virtual bool addVehicle(const std::string& id, SUMOVehicle* v);
126 
127 
136  SUMOVehicle* getVehicle(const std::string& id) const;
137 
138 
145  virtual void deleteVehicle(SUMOVehicle* v, bool discard = false);
146 
147 
160 
161 
166  constVehIt loadedVehBegin() const;
167 
168 
173  constVehIt loadedVehEnd() const;
175 
176 
177 
180 
188  void vehicleDeparted(const SUMOVehicle& v);
190 
191 
192 
195 
199  unsigned int getLoadedVehicleNo() const {
200  return myLoadedVehNo;
201  }
202 
203 
207  unsigned int getEndedVehicleNo() const {
208  return myEndedVehNo;
209  }
210 
211 
215  unsigned int getRunningVehicleNo() const {
216  return myRunningVehNo;
217  }
218 
219 
223  unsigned int getDepartedVehicleNo() const {
225  }
226 
227 
234  unsigned int getQuota(SUMOReal frac = -1) const;
235 
236 
241  int getActiveVehicleCount() const {
243  }
244 
245 
247  unsigned int getCollisionCount() const {
248  return myCollisions;
249  }
250 
252  unsigned int getTeleportsJam() const {
253  return myTeleportsJam;
254  }
255 
257  unsigned int getTeleportsYield() const {
258  return myTeleportsYield;
259  }
260 
262  unsigned int getTeleportsWrongLane() const {
263  return myTeleportsWrongLane;
264  }
265 
267  unsigned int getTeleportCount() const {
269  }
270 
272  unsigned int getEmergencyStops() const {
273  return myEmergencyStops;
274  }
275 
276 
281  return myTotalDepartureDelay;
282  }
283 
284 
289  return myTotalTravelTime;
290  }
292 
293 
294 
297 
310  bool addVType(MSVehicleType* vehType);
311 
312 
326  bool addVTypeDistribution(const std::string& id, RandomDistributor<MSVehicleType*>* vehTypeDistribution);
327 
328 
336  bool hasVTypeDistribution(const std::string& id) const;
337 
338 
343  MSVehicleType* getVType(const std::string& id = DEFAULT_VTYPE_ID, MTRand* rng = 0);
344 
345 
349  void insertVTypeIDs(std::vector<std::string>& into) const;
351 
352  void addWaiting(const MSEdge* const edge, SUMOVehicle* vehicle);
353 
354  void removeWaiting(const MSEdge* const edge, SUMOVehicle* vehicle);
355 
356  SUMOVehicle* getWaitingVehicle(const MSEdge* const edge, const std::set<std::string>& lines);
357 
362  }
363 
368  }
369 
372  myCollisions++;
373  }
374 
377  myTeleportsJam++;
378  }
379 
383  }
384 
388  }
389 
393  }
394 
397 
400  void setState(int runningVehNo, int endedVehNo, SUMOReal totalDepartureDelay, SUMOReal totalTravelTime);
401 
404  void saveState(OutputDevice& out);
406 
407 
410  void abortWaiting();
411 
414 
415 private:
422  bool checkVType(const std::string& id);
423 
424 protected:
427 
429  unsigned int myLoadedVehNo;
430 
432  unsigned int myRunningVehNo;
433 
435  unsigned int myEndedVehNo;
436 
438  unsigned int myDiscarded;
439 
441  unsigned int myCollisions;
442 
444  unsigned int myTeleportsJam;
445 
447  unsigned int myTeleportsYield;
448 
450  unsigned int myTeleportsWrongLane;
451 
453  unsigned int myEmergencyStops;
454 
456 
457 
460 
463 
467 
468 
471 
473  typedef std::map< std::string, SUMOVehicle* > VehicleDictType;
477 
478 
481 
483  typedef std::map< std::string, MSVehicleType* > VTypeDictType;
486 
488  typedef std::map< std::string, RandomDistributor<MSVehicleType*>* > VTypeDistDictType;
491 
494 
496  std::map<const MSEdge* const, std::vector<SUMOVehicle*> > myWaiting;
497 
499  unsigned int myWaitingForPerson;
500 
503 
506 
507 
508 private:
511 
514 
515 
516 };
517 
518 
519 #endif
520 
521 /****************************************************************************/
522 
unsigned int getTeleportsYield() const
return the number of teleports due to vehicles stuck on a minor road
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
bool addVTypeDistribution(const std::string &id, RandomDistributor< MSVehicleType * > *vehTypeDistribution)
Adds a vehicle type distribution.
void addWaiting(const MSEdge *const edge, SUMOVehicle *vehicle)
unsigned int getTeleportsWrongLane() const
return the number of teleports due to vehicles stuck on the wrong lane
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:78
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
SUMOReal myTotalDepartureDelay
The aggregated time vehicles had to wait for departure (in seconds)
unsigned int getRunningVehicleNo() const
Returns the number of build and inserted, but not yet deleted vehicles.
SUMOReal getTotalDepartureDelay() const
Returns the total departure delay.
unsigned int getDepartedVehicleNo() const
Returns the number of inserted vehicles.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
unsigned int myDiscarded
The number of vehicles which were discarded while loading.
SUMOReal myTotalTravelTime
The aggregated time vehicles needed to aacomplish their route (in seconds)
void registerTeleportYield()
register one non-collision-related teleport
std::map< const MSEdge *const, std::vector< SUMOVehicle * > > myWaiting
the lists of waiting vehicles
MSVehicleControl()
Constructor.
int getActiveVehicleCount() const
Returns the number of build vehicles that have not been removed or need to wait for a passenger...
void registerEmergencyStop()
register emergency stop
VehicleDictType myVehicleDict
Dictionary of vehicles.
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
VTypeDictType myVTypeDict
Dictionary of vehicle types.
void removeWaiting(const MSEdge *const edge, SUMOVehicle *vehicle)
void insertVTypeIDs(std::vector< std::string > &into) const
Inserts ids of all known vehicle types and vehicle type distributions to the given vector...
bool myDefaultVTypeMayBeDeleted
Whether no vehicle type was loaded.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
const std::string DEFAULT_VTYPE_ID
The car-following model and parameter.
Definition: MSVehicleType.h:74
SUMOReal getTotalTravelTime() const
Returns the total travel time.
unsigned int getCollisionCount() const
return the number of collisions
SUMOVehicle * getWaitingVehicle(const MSEdge *const edge, const std::set< std::string > &lines)
A road/street connecting two junctions.
Definition: MSEdge.h:75
unsigned int getLoadedVehicleNo() const
Returns the number of build vehicles.
std::map< std::string, MSVehicleType * > VTypeDictType
Vehicle type dictionary type.
unsigned int getTeleportCount() const
return the number of teleports (including collisions)
void setState(int runningVehNo, int endedVehNo, SUMOReal totalDepartureDelay, SUMOReal totalTravelTime)
Sets the current state variables as loaded from the stream.
SUMOTime computeRandomDepartOffset() const
compute (optional) random offset to the departure time
Representation of a vehicle.
Definition: SUMOVehicle.h:64
SUMOReal myScale
The scaling factor (especially for inc-dua)
std::map< std::string, RandomDistributor< MSVehicleType * > * > VTypeDistDictType
Vehicle type distribution dictionary type.
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, const MSVehicleType *type, const bool ignoreStopErrors, const bool fromRouteFile=true)
Builds a vehicle, increases the number of built vehicles.
SUMOTime myMaxRandomDepartOffset
The maximum random offset to be added to vehicles departure times (non-negative)
void saveState(OutputDevice &out)
Saves the current state into the given stream.
unsigned int myCollisions
The number of collisions.
unsigned int myEndedVehNo
The number of removed vehicles.
void registerTeleportJam()
register one non-collision-related teleport
void unregisterOneWaitingForPerson()
decreases the count of vehicles waiting for a person to allow recogniztion of person related deadlock...
void registerOneWaitingForPerson()
increases the count of vehicles waiting for a person to allow recogniztion of person related deadlock...
unsigned int myTeleportsJam
The number of teleports due to jam.
unsigned int myTeleportsWrongLane
The number of teleports due to vehicles stuck on the wrong lane.
void abortWaiting()
removes any vehicles that are still waiting
MSVehicleControl & operator=(const MSVehicleControl &s)
invalidated assignment operator
bool addVType(MSVehicleType *vehType)
Adds a vehicle type.
unsigned int getTeleportsJam() const
return the number of teleports due to jamming
void scheduleVehicleRemoval(SUMOVehicle *veh)
Removes a vehicle after it has ended.
Structure representing possible vehicle parameter.
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability-&gt;vehicle type)
unsigned int myWaitingForPerson
the number of vehicles contained in myWaiting which can only continue by being triggered ...
virtual ~MSVehicleControl()
Destructor.
unsigned int myEmergencyStops
The number of emergency stops.
int SUMOTime
Definition: SUMOTime.h:43
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
unsigned int getEndedVehicleNo() const
Returns the number of removed vehicles.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
bool hasVTypeDistribution(const std::string &id) const
Asks for a vehicle type distribution.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:218
std::map< std::string, SUMOVehicle * > VehicleDictType
Vehicle dictionary type.
unsigned int myTeleportsYield
The number of teleports due to vehicles stuck on a minor road.
void registerCollision()
registers one collision-related teleport
void vehicleDeparted(const SUMOVehicle &v)
Informs this control about a vehicle&#39;s departure.
The class responsible for building and deletion of vehicles.
unsigned int myLoadedVehNo
The number of build vehicles.
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, MTRand *rng=0)
Returns the named vehicle type or a sample from the named distribution.
void registerTeleportWrongLane()
register one non-collision-related teleport
unsigned int getEmergencyStops() const
return the number of emergency stops
unsigned int getQuota(SUMOReal frac=-1) const
Returns the number of instances of the current vehicle that shall be emitted considering that &quot;frac&quot; ...
unsigned int myRunningVehNo
The number of vehicles within the network (build and inserted but not removed)