SUMO - Simulation of Urban MObility
MSVehicleControl.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // The class responsible for building and deletion of vehicles
20 /****************************************************************************/
21 #ifndef MSVehicleControl_h
22 #define MSVehicleControl_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 <cmath>
35 #include <string>
36 #include <map>
37 #include <set>
39 #include <utils/common/SUMOTime.h>
41 #include "MSNet.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  MSVehicleType* type,
105  const bool ignoreStopErrors, const bool fromRouteFile = true);
107 
108 
109 
112 
126  virtual bool addVehicle(const std::string& id, SUMOVehicle* v);
127 
128 
137  SUMOVehicle* getVehicle(const std::string& id) const;
138 
139 
146  virtual void deleteVehicle(SUMOVehicle* v, bool discard = false);
147 
148 
161 
162 
166  constVehIt loadedVehBegin() const {
167  return myVehicleDict.begin();
168  }
169 
170 
174  constVehIt loadedVehEnd() const {
175  return myVehicleDict.end();
176  }
178 
179 
180 
183 
191  void vehicleDeparted(const SUMOVehicle& v);
193 
194 
195 
198 
202  int getLoadedVehicleNo() const {
203  return myLoadedVehNo;
204  }
205 
206 
210  int getEndedVehicleNo() const {
211  return myEndedVehNo;
212  }
213 
214 
218  int getRunningVehicleNo() const {
219  return myRunningVehNo;
220  }
221 
222 
226  int getDepartedVehicleNo() const {
228  }
229 
230 
237  int getQuota(double frac = -1) const;
238 
239 
244  int getActiveVehicleCount() const {
246  }
247 
248 
250  int getCollisionCount() const {
251  return myCollisions;
252  }
253 
255  int getTeleportsJam() const {
256  return myTeleportsJam;
257  }
258 
260  int getTeleportsYield() const {
261  return myTeleportsYield;
262  }
263 
265  int getTeleportsWrongLane() const {
266  return myTeleportsWrongLane;
267  }
268 
270  int getTeleportCount() const;
271 
273  int getEmergencyStops() const {
274  return myEmergencyStops;
275  }
276 
277 
281  double getTotalDepartureDelay() const {
282  return myTotalDepartureDelay;
283  }
284 
285 
289  double getTotalTravelTime() const {
290  return myTotalTravelTime;
291  }
293 
294 
295 
298 
311  bool addVType(MSVehicleType* vehType);
312 
313  /*
314  * @param[in] vehType The vehicle type to remove
315  * @return Whether the vehicle type could be removed
316  */
317  void removeVType(const MSVehicleType* vehType);
318 
319 
333  bool addVTypeDistribution(const std::string& id, RandomDistributor<MSVehicleType*>* vehTypeDistribution);
334 
335 
343  bool hasVType(const std::string& id) const;
344 
345 
353  bool hasVTypeDistribution(const std::string& id) const;
354 
355 
360  MSVehicleType* getVType(const std::string& id = DEFAULT_VTYPE_ID, std::mt19937* rng = 0);
361 
362 
366  void insertVTypeIDs(std::vector<std::string>& into) const;
368 
370  void addWaiting(const MSEdge* const edge, SUMOVehicle* vehicle);
371 
373  void removeWaiting(const MSEdge* const edge, SUMOVehicle* vehicle);
374 
375  /* @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
376  * @param[in] edge The edge at which the vehicle is positioned.
377  * @param[in] lines The set of lines from which at least one must correspond to the line of the vehicle
378  * @param[in] position The vehicle shall be positioned in the interval [position - t, position + t], where t is some tolerance
379  * @param[in] ridingID The id of the person or container that wants to ride
380  */
381  SUMOVehicle* getWaitingVehicle(const MSEdge* const edge, const std::set<std::string>& lines, const double position, const std::string ridingID);
382 
385  void registerOneWaiting(const bool isPerson) {
386  if (isPerson) {
388  } else {
390  }
391  }
392 
395  void unregisterOneWaiting(const bool isPerson) {
396  if (isPerson) {
398  } else {
400  }
401  }
402 
405  myCollisions++;
406  }
407 
410  myTeleportsJam++;
411  }
412 
416  }
417 
421  }
422 
426  }
427 
430 
433  void setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime);
434 
437  void saveState(OutputDevice& out);
439 
441  void discountStateLoaded(bool removed = false) {
442  if (removed) {
443  myRunningVehNo--;
444  myDiscarded++;
445  myEndedVehNo++;
446  } else {
447  myLoadedVehNo--;
448  }
449  }
450 
451 
454  void abortWaiting();
455 
458 
460  double getMaxSpeedFactor() const {
461  return myMaxSpeedFactor;
462  }
463 
465  double getMinDeceleration() const {
466  return myMinDeceleration;
467  }
468 
470 
471 private:
478  bool checkVType(const std::string& id);
479 
480 protected:
483 
486 
487 private:
490 
493 
496 
499 
502 
505 
508 
511 
513 
514 
517 
520 
524 
525 
526 protected:
529 
531  typedef std::map< std::string, SUMOVehicle* > VehicleDictType;
533  VehicleDictType myVehicleDict;
535 
536 
537 private:
540 
542  typedef std::map< std::string, MSVehicleType* > VTypeDictType;
544  VTypeDictType myVTypeDict;
545 
547  typedef std::map< std::string, RandomDistributor<MSVehicleType*>* > VTypeDistDictType;
549  VTypeDistDictType myVTypeDistDict;
550 
553 
556 
558  std::map<const MSEdge* const, std::vector<SUMOVehicle*> > myWaiting;
559 
562 
565 
567  double myScale;
568 
571 
574 
577 
579  std::vector<SUMOVehicle*> myPTVehicles;
580 
581 private:
584 
587 
588 
589 };
590 
591 
592 #endif
593 
594 /****************************************************************************/
595 
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.
bool hasVType(const std::string &id) const
Asks for existence of a vehicle type.
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:72
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.
void adaptIntermodalRouter(MSNet::MSIntermodalRouter &router) const
Representation of a vehicle.
Definition: SUMOVehicle.h:66
int getTeleportsYield() const
return the number of teleports due to vehicles stuck on a minor road
void registerOneWaiting(const bool isPerson)
increases the count of vehicles waiting for a transport to allow recognition of person / container re...
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)
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 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...
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, std::mt19937 *rng=0)
Returns the named vehicle type or a sample from the named distribution.
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 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:70
std::map< std::string, SUMOVehicle *> VehicleDictType
Vehicle dictionary type.
void registerCollision()
registers one collision-related teleport
long long int SUMOTime
Definition: TraCIDefs.h:51
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.
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, MSVehicleType *type, const bool ignoreStopErrors, const bool fromRouteFile=true)
Builds a vehicle, increases the number of built vehicles.
int getDepartedVehicleNo() const
Returns the number of inserted vehicles.
int myTeleportsYield
The number of teleports due to vehicles stuck on a minor road.
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)
void unregisterOneWaiting(const bool isPerson)
decreases the count of vehicles waiting for a transport to allow recognition of person / container re...
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
std::vector< SUMOVehicle * > myPTVehicles
List of vehicles which belong to public transport.