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-sim.org/
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>
39 #include "MSGlobals.h"
41 #include <utils/common/SUMOTime.h>
44 
45 
46 // ===========================================================================
47 // class declarations
48 // ===========================================================================
49 class SUMOVehicle;
50 class MSVehicle;
51 class MSRoute;
52 class MSVehicleType;
53 class BinaryInputDevice;
54 class MSEdge;
55 
56 
57 // ===========================================================================
58 // class definitions
59 // ===========================================================================
76 public:
78  typedef std::map<std::string, SUMOVehicle*>::const_iterator constVehIt;
79 
80 public:
83 
84 
86  virtual ~MSVehicleControl();
87 
88 
91 
102  virtual SUMOVehicle* buildVehicle(SUMOVehicleParameter* defs, const MSRoute* route,
103  const MSVehicleType* type);
105 
106 
107 
110 
123  virtual bool addVehicle(const std::string& id, SUMOVehicle* v);
124 
125 
134  SUMOVehicle* getVehicle(const std::string& id) const;
135 
136 
143  virtual void deleteVehicle(SUMOVehicle* v, bool discard = false);
144 
145 
158 
159 
164  constVehIt loadedVehBegin() const;
165 
166 
171  constVehIt loadedVehEnd() const;
173 
174 
175 
178 
186  void vehicleDeparted(const SUMOVehicle& v);
188 
189 
190 
193 
197  unsigned int getLoadedVehicleNo() const {
198  return myLoadedVehNo;
199  }
200 
201 
205  unsigned int getEndedVehicleNo() const {
206  return myEndedVehNo;
207  }
208 
209 
213  unsigned int getRunningVehicleNo() const {
214  return myRunningVehNo;
215  }
216 
217 
221  unsigned int getDepartedVehicleNo() const {
223  }
224 
225 
232  bool isInQuota(SUMOReal frac = -1) const;
233 
234 
239  int getActiveVehicleCount() const {
241  }
242 
243 
245  unsigned int getCollisionCount() const {
246  return myCollisions;
247  }
248 
250  unsigned int getTeleportsJam() const {
251  return myTeleportsJam;
252  }
253 
255  unsigned int getTeleportsYield() const {
256  return myTeleportsYield;
257  }
258 
260  unsigned int getTeleportsWrongLane() const {
261  return myTeleportsWrongLane;
262  }
263 
265  unsigned int getTeleportCount() const {
267  }
268 
269 
274  return myTotalDepartureDelay;
275  }
276 
277 
282  return myTotalTravelTime;
283  }
285 
286 
287 
290 
303  bool addVType(MSVehicleType* vehType);
304 
305 
319  bool addVTypeDistribution(const std::string& id, RandomDistributor<MSVehicleType*>* vehTypeDistribution);
320 
321 
329  bool hasVTypeDistribution(const std::string& id) const;
330 
331 
336  MSVehicleType* getVType(const std::string& id = DEFAULT_VTYPE_ID);
337 
338 
342  void insertVTypeIDs(std::vector<std::string>& into) const;
344 
345  void addWaiting(const MSEdge* const edge, SUMOVehicle* vehicle);
346 
347  void removeWaiting(const MSEdge* const edge, SUMOVehicle* vehicle);
348 
349  SUMOVehicle* getWaitingVehicle(const MSEdge* const edge, const std::set<std::string>& lines);
350 
355  }
356 
361  }
362 
365  myCollisions++;
366  }
367 
370  myTeleportsJam++;
371  }
372 
376  }
377 
381  }
382 
385 
388  void setState(int runningVehNo, int endedVehNo, SUMOReal totalDepartureDelay, SUMOReal totalTravelTime);
389 
392  void saveState(OutputDevice& out);
394 
395 
398  void abortWaiting();
399 
400 
401 public:
404 
405 
406 private:
413  bool checkVType(const std::string& id);
414 
415 protected:
418 
420  unsigned int myLoadedVehNo;
421 
423  unsigned int myRunningVehNo;
424 
426  unsigned int myEndedVehNo;
427 
429  unsigned int myDiscarded;
430 
432  unsigned int myCollisions;
433 
435  unsigned int myTeleportsJam;
436 
438  unsigned int myTeleportsYield;
439 
441  unsigned int myTeleportsWrongLane;
442 
444 
445 
448 
451 
455 
456 
459 
461  typedef std::map< std::string, SUMOVehicle* > VehicleDictType;
465 
466 
469 
471  typedef std::map< std::string, MSVehicleType* > VTypeDictType;
474 
476  typedef std::map< std::string, RandomDistributor<MSVehicleType*>* > VTypeDistDictType;
479 
482 
484  std::map<const MSEdge* const, std::vector<SUMOVehicle*> > myWaiting;
485 
487  unsigned int myWaitingForPerson;
488 
491 
492 private:
495 
498 
499 
500 };
501 
502 
503 #endif
504 
505 /****************************************************************************/
506 
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:77
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
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID)
Returns the named vehicle type or a sample from the named distribution.
MSVehicleControl()
Constructor.
int getActiveVehicleCount() const
Returns the number of build vehicles that have not been removed or need to wait for a passenger...
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
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, const MSVehicleType *type)
Builds a vehicle, increases the number of built vehicles.
SUMOVehicle * getWaitingVehicle(const MSEdge *const edge, const std::set< std::string > &lines)
A road/street connecting two junctions.
Definition: MSEdge.h:73
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.
Representation of a vehicle.
Definition: SUMOVehicle.h:63
SUMOReal myScale
The scaling factor (especially for inc-dua)
std::map< std::string, RandomDistributor< MSVehicleType * > * > VTypeDistDictType
Vehicle type distribution dictionary type.
void saveState(OutputDevice &out)
Saves the current state into the given stream.
unsigned int myCollisions
The number of collisions.
static MTRand myVehicleParamsRNG
A random number generator used to choose from vtype/route distributions and computing the speed facto...
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->vehicle type)
unsigned int myWaitingForPerson
the number of vehicles contained in myWaiting which can only continue by being triggered ...
virtual ~MSVehicleControl()
Destructor.
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 isInQuota(SUMOReal frac=-1) const
Returns the information whether the currently vehicle number shall be emitted considering that only f...
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:70
#define SUMOReal
Definition: config.h:215
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's departure.
The class responsible for building and deletion of vehicles.
unsigned int myLoadedVehNo
The number of build vehicles.
void registerTeleportWrongLane()
register one non-collision-related teleport
Encapsulates binary reading operations on a file.
unsigned int myRunningVehNo
The number of vehicles within the network (build and inserted but not removed)