SUMO - Simulation of Urban MObility
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-2017 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 
165  constVehIt loadedVehBegin() const {
166  return myVehicleDict.begin();
167  }
168 
169 
173  constVehIt loadedVehEnd() const {
174  return myVehicleDict.end();
175  }
177 
178 
179 
182 
190  void vehicleDeparted(const SUMOVehicle& v);
192 
193 
194 
197 
201  int getLoadedVehicleNo() const {
202  return myLoadedVehNo;
203  }
204 
205 
209  int getEndedVehicleNo() const {
210  return myEndedVehNo;
211  }
212 
213 
217  int getRunningVehicleNo() const {
218  return myRunningVehNo;
219  }
220 
221 
225  int getDepartedVehicleNo() const {
227  }
228 
229 
236  int getQuota(double frac = -1) const;
237 
238 
243  int getActiveVehicleCount() const {
245  }
246 
247 
249  int getCollisionCount() const {
250  return myCollisions;
251  }
252 
254  int getTeleportsJam() const {
255  return myTeleportsJam;
256  }
257 
259  int getTeleportsYield() const {
260  return myTeleportsYield;
261  }
262 
264  int getTeleportsWrongLane() const {
265  return myTeleportsWrongLane;
266  }
267 
269  int getTeleportCount() const;
270 
272  int getEmergencyStops() const {
273  return myEmergencyStops;
274  }
275 
276 
280  double getTotalDepartureDelay() const {
281  return myTotalDepartureDelay;
282  }
283 
284 
288  double getTotalTravelTime() const {
289  return myTotalTravelTime;
290  }
292 
293 
294 
297 
310  bool addVType(MSVehicleType* vehType);
311 
312  /*
313  * @param[in] vehType The vehicle type to remove
314  * @return Whether the vehicle type could be removed
315  */
316  void removeVType(const MSVehicleType* vehType);
317 
318 
332  bool addVTypeDistribution(const std::string& id, RandomDistributor<MSVehicleType*>* vehTypeDistribution);
333 
334 
342  bool hasVTypeDistribution(const std::string& id) const;
343 
344 
349  MSVehicleType* getVType(const std::string& id = DEFAULT_VTYPE_ID, MTRand* rng = 0);
350 
351 
355  void insertVTypeIDs(std::vector<std::string>& into) const;
357 
359  void addWaiting(const MSEdge* const edge, SUMOVehicle* vehicle);
360 
362  void removeWaiting(const MSEdge* const edge, SUMOVehicle* vehicle);
363 
364  /* @brief returns a vehicle of the given lines that is waiting for a for a person or a container at this edge at the given positions
365  * @param[in] edge The edge at which the vehicle is positioned.
366  * @param[in] lines The set of lines from which at least one must correspond to the line of the vehicle
367  * @param[in] position The vehicle shall be positioned in the interval [position - t, position + t], where t is some tolerance
368  * @param[in] ridingID The id of the person or container that wants to ride
369  */
370  SUMOVehicle* getWaitingVehicle(const MSEdge* const edge, const std::set<std::string>& lines, const double position, const std::string ridingID);
371 
376  }
377 
382  }
383 
388  }
389 
394  }
395 
398  myCollisions++;
399  }
400 
403  myTeleportsJam++;
404  }
405 
409  }
410 
414  }
415 
419  }
420 
423 
426  void setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime);
427 
430  void saveState(OutputDevice& out);
432 
434  void discountStateLoaded(bool removed = false) {
435  if (removed) {
436  myRunningVehNo--;
437  myDiscarded++;
438  myEndedVehNo++;
439  } else {
440  myLoadedVehNo--;
441  }
442  }
443 
444 
447  void abortWaiting();
448 
451 
453  double getMaxSpeedFactor() const {
454  return myMaxSpeedFactor;
455  }
456 
458  double getMinDeceleration() const {
459  return myMinDeceleration;
460  }
461 
462 private:
469  bool checkVType(const std::string& id);
470 
471 protected:
474 
477 
480 
483 
486 
489 
492 
495 
498 
501 
503 
504 
507 
510 
514 
515 
518 
520  typedef std::map< std::string, SUMOVehicle* > VehicleDictType;
522  VehicleDictType myVehicleDict;
524 
525 
528 
530  typedef std::map< std::string, MSVehicleType* > VTypeDictType;
532  VTypeDictType myVTypeDict;
533 
535  typedef std::map< std::string, RandomDistributor<MSVehicleType*>* > VTypeDistDictType;
537  VTypeDistDictType myVTypeDistDict;
538 
541 
544 
546  std::map<const MSEdge* const, std::vector<SUMOVehicle*> > myWaiting;
547 
550 
553 
555  double myScale;
556 
559 
562 
565 
566 private:
569 
572 
573 
574 };
575 
576 
577 #endif
578 
579 /****************************************************************************/
580 
bool myDefaultPedTypeMayBeDeleted
Whether no pedestrian type was loaded.
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
void discountStateLoaded(bool removed=false)
avoid counting a vehicle twice if it was loaded from state and route input
void addWaiting(const MSEdge *const edge, SUMOVehicle *vehicle)
Adds a vehicle to the list of waiting vehiclse to a given edge.
int getEndedVehicleNo() const
Returns the number of removed vehicles.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
SUMOTime computeRandomDepartOffset() const
compute (optional) random offset to the departure time
int myTeleportsWrongLane
The number of teleports due to vehicles stuck on the wrong lane.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
int myEndedVehNo
The number of removed vehicles.
int getRunningVehicleNo() const
Returns the number of build and inserted, but not yet deleted vehicles.
double getMaxSpeedFactor() const
return the maximum speed factor for all vehicles that ever entered the network
int getLoadedVehicleNo() const
Returns the number of build vehicles.
Represents a generic random distribution.
int myDiscarded
The number of vehicles which were discarded while loading.
void registerTeleportYield()
register one non-collision-related teleport
std::map< const MSEdge *const, std::vector< SUMOVehicle * > > myWaiting
the lists of waiting vehicles to a given edge
bool hasVTypeDistribution(const std::string &id) const
Asks for a vehicle type distribution.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
int getQuota(double frac=-1) const
Returns the number of instances of the current vehicle that shall be emitted considering that "frac" ...
MSVehicleControl()
Constructor.
void registerEmergencyStop()
register emergency stop
VehicleDictType myVehicleDict
Dictionary of vehicles.
int getActiveVehicleCount() const
Returns the number of build vehicles that have not been removed or need to wait for a passenger or a ...
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.
int myTeleportsJam
The number of teleports due to jam.
void removeWaiting(const MSEdge *const edge, SUMOVehicle *vehicle)
Removes a vehicle from the list of waiting vehicles to a given edge.
bool myDefaultVTypeMayBeDeleted
Whether no vehicle type was loaded.
double myMaxSpeedFactor
The maximum speed factor for all vehicles in the network.
const std::string DEFAULT_VTYPE_ID
void setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime)
Sets the current state variables as loaded from the stream.
The car-following model and parameter.
Definition: MSVehicleType.h:74
void unregisterOneWaitingForContainer()
decreases the count of vehicles waiting for a container to allow recogniztion of container related de...
A road/street connecting two junctions.
Definition: MSEdge.h:80
std::map< std::string, MSVehicleType *> VTypeDictType
Vehicle type dictionary type.
double getTotalDepartureDelay() const
Returns the total departure delay.
Representation of a vehicle.
Definition: SUMOVehicle.h:67
int getTeleportsYield() const
return the number of teleports due to vehicles stuck on a minor road
double getMinDeceleration() const
return the minimum deceleration capability for all vehicles that ever entered the network ...
std::map< std::string, RandomDistributor< MSVehicleType * > *> VTypeDistDictType
Vehicle type distribution dictionary type.
void removeVType(const MSVehicleType *vehType)
double myTotalTravelTime
The aggregated time vehicles needed to aacomplish their route (in seconds)
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.
int getEmergencyStops() const
return the number of emergency stops
int myLoadedVehNo
The number of build vehicles.
SUMOVehicle * getWaitingVehicle(const MSEdge *const edge, const std::set< std::string > &lines, const double position, const std::string ridingID)
int myEmergencyStops
The number of emergency stops.
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.
int getTeleportsJam() const
return the number of teleports due to jamming
double getTotalTravelTime() const
Returns the total travel time.
int myRunningVehNo
The number of vehicles within the network (build and inserted but not removed)
void registerTeleportJam()
register one non-collision-related teleport
int myWaitingForContainer
the number of vehicles wainting for containers contained in myWaiting which can only continue by bein...
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...
void insertVTypeIDs(std::vector< std::string > &into) const
Inserts ids of all known vehicle types and vehicle type distributions to the given vector...
int getTeleportsWrongLane() const
return the number of teleports due to vehicles stuck on the wrong lane
void abortWaiting()
informes about all waiting vehicles (deletion in destructor)
int myWaitingForPerson
the number of vehicles wainting for persons contained in myWaiting which can only continue by being t...
MSVehicleControl & operator=(const MSVehicleControl &s)
invalidated assignment operator
bool addVType(MSVehicleType *vehType)
Adds a vehicle type.
double myTotalDepartureDelay
The aggregated time vehicles had to wait for departure (in seconds)
void registerOneWaitingForContainer()
increases the count of vehicles waiting for a container to allow recogniztion of container related de...
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)
int myCollisions
The number of collisions.
virtual ~MSVehicleControl()
Destructor.
bool addVTypeDistribution(const std::string &id, RandomDistributor< MSVehicleType *> *vehTypeDistribution)
Adds a vehicle type distribution.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
std::map< std::string, SUMOVehicle *> VehicleDictType
Vehicle dictionary type.
void registerCollision()
registers one collision-related teleport
long long int SUMOTime
Definition: TraCIDefs.h:52
void vehicleDeparted(const SUMOVehicle &v)
Informs this control about a vehicle&#39;s departure.
The class responsible for building and deletion of vehicles.
double myScale
The scaling factor (especially for inc-dua)
double myMinDeceleration
The minimum deceleration capability for all vehicles in the network.
int getDepartedVehicleNo() const
Returns the number of inserted vehicles.
int myTeleportsYield
The number of teleports due to vehicles stuck on a minor road.
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
int getCollisionCount() const
return the number of collisions
int getTeleportCount() const
return the number of teleports (including collisions)
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.