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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // The class responsible for building and deletion of vehicles
18 /****************************************************************************/
19 #ifndef MSVehicleControl_h
20 #define MSVehicleControl_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <cmath>
29 #include <string>
30 #include <map>
31 #include <set>
33 #include <utils/common/SUMOTime.h>
35 #include "MSNet.h"
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
41 class SUMOVehicle;
43 class MSVehicle;
44 class MSRoute;
45 class MSVehicleType;
46 class OutputDevice;
47 class MSEdge;
48 
49 
50 // ===========================================================================
51 // class definitions
52 // ===========================================================================
69 public:
71  typedef std::map<std::string, SUMOVehicle*>::const_iterator constVehIt;
72 
73 public:
76 
77 
79  virtual ~MSVehicleControl();
80 
81 
84 
97  virtual SUMOVehicle* buildVehicle(SUMOVehicleParameter* defs, const MSRoute* route,
98  MSVehicleType* type,
99  const bool ignoreStopErrors, const bool fromRouteFile = true);
101 
102 
103 
106 
120  virtual bool addVehicle(const std::string& id, SUMOVehicle* v);
121 
122 
131  SUMOVehicle* getVehicle(const std::string& id) const;
132 
133 
140  virtual void deleteVehicle(SUMOVehicle* v, bool discard = false);
141 
142 
155 
156 
160  constVehIt loadedVehBegin() const {
161  return myVehicleDict.begin();
162  }
163 
164 
168  constVehIt loadedVehEnd() const {
169  return myVehicleDict.end();
170  }
172 
173 
174 
177 
185  void vehicleDeparted(const SUMOVehicle& v);
187 
188 
189 
192 
196  int getLoadedVehicleNo() const {
197  return myLoadedVehNo;
198  }
199 
200 
204  virtual int getHaltingVehicleNo() const;
205 
207  virtual std::pair<double, double> getVehicleMeanSpeeds() const;
208  double getVehicleMeanSpeed() const {
209  return getVehicleMeanSpeeds().first;
210  }
212  return getVehicleMeanSpeeds().second;
213  }
214 
218  int getEndedVehicleNo() const {
219  return myEndedVehNo;
220  }
221 
225  int getArrivedVehicleNo() const {
226  return myEndedVehNo - myDiscarded;
227  }
228 
232  int getDiscardedVehicleNo() const {
233  return myDiscarded;
234  }
235 
236 
240  int getRunningVehicleNo() const {
241  return myRunningVehNo;
242  }
243 
244 
248  int getDepartedVehicleNo() const {
250  }
251 
252 
259  int getQuota(double frac = -1) const;
260 
261 
266  int getActiveVehicleCount() const {
268  }
269 
270 
272  int getCollisionCount() const {
273  return myCollisions;
274  }
275 
277  int getTeleportsJam() const {
278  return myTeleportsJam;
279  }
280 
282  int getTeleportsYield() const {
283  return myTeleportsYield;
284  }
285 
287  int getTeleportsWrongLane() const {
288  return myTeleportsWrongLane;
289  }
290 
292  int getTeleportCount() const;
293 
295  int getEmergencyStops() const {
296  return myEmergencyStops;
297  }
298 
302  double getTotalDepartureDelay() const {
303  return myTotalDepartureDelay;
304  }
305 
306 
310  double getTotalTravelTime() const {
311  return myTotalTravelTime;
312  }
314 
315 
316 
319 
332  bool addVType(MSVehicleType* vehType);
333 
334  /*
335  * @param[in] vehType The vehicle type to remove
336  * @return Whether the vehicle type could be removed
337  */
338  void removeVType(const MSVehicleType* vehType);
339 
340 
354  bool addVTypeDistribution(const std::string& id, RandomDistributor<MSVehicleType*>* vehTypeDistribution);
355 
356 
364  bool hasVType(const std::string& id) const;
365 
366 
374  bool hasVTypeDistribution(const std::string& id) const;
375 
376 
381  MSVehicleType* getVType(const std::string& id = DEFAULT_VTYPE_ID, std::mt19937* rng = 0);
382 
383 
387  void insertVTypeIDs(std::vector<std::string>& into) const;
388 
389 
393  std::set<std::string> getVTypeDistributionMembership(const std::string& id) const;
394 
396 
398  void addWaiting(const MSEdge* const edge, SUMOVehicle* vehicle);
399 
401  void removeWaiting(const MSEdge* const edge, const SUMOVehicle* vehicle);
402 
403  /* @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
404  * @param[in] edge The edge at which the vehicle is positioned.
405  * @param[in] lines The set of lines from which at least one must correspond to the line of the vehicle
406  * @param[in] position The vehicle shall be positioned in the interval [position - t, position + t], where t is some tolerance
407  * @param[in] ridingID The id of the person or container that wants to ride
408  */
409  SUMOVehicle* getWaitingVehicle(const MSEdge* const edge, const std::set<std::string>& lines, const double position, const std::string ridingID);
410 
413  void registerOneWaiting(const bool isPerson) {
414  if (isPerson) {
416  } else {
418  }
419  }
420 
423  void unregisterOneWaiting(const bool isPerson) {
424  if (isPerson) {
426  } else {
428  }
429  }
430 
433  myCollisions++;
434  }
435 
438  myTeleportsJam++;
439  }
440 
444  }
445 
449  }
450 
454  }
455 
458 
461  void setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime);
462 
465  void saveState(OutputDevice& out);
467 
469  void discountStateLoaded(bool removed = false) {
470  if (removed) {
471  myRunningVehNo--;
472  myDiscarded++;
473  myEndedVehNo++;
474  } else {
475  myLoadedVehNo--;
476  }
477  }
478 
479 
482  void abortWaiting();
483 
485  double getMaxSpeedFactor() const {
486  return myMaxSpeedFactor;
487  }
488 
490  double getMinDeceleration() const {
491  return myMinDeceleration;
492  }
493 
495 
497  void setScale(double scale) {
498  myScale = scale;
499  }
500 
501 private:
508  bool checkVType(const std::string& id);
509 
510 protected:
513 
516 
517 private:
520 
523 
526 
529 
532 
535 
538 
541 
543 
544 
547 
550 
554 
555 
556 protected:
559 
561  typedef std::map< std::string, SUMOVehicle* > VehicleDictType;
563  VehicleDictType myVehicleDict;
565 
566 
567 private:
570 
572  typedef std::map< std::string, MSVehicleType* > VTypeDictType;
574  VTypeDictType myVTypeDict;
575 
577  typedef std::map< std::string, RandomDistributor<MSVehicleType*>* > VTypeDistDictType;
579  VTypeDistDictType myVTypeDistDict;
580 
582  std::map<std::string, std::set<std::string>> myVTypeToDist;
583 
586 
589 
592 
594  std::map<const MSEdge* const, std::vector<SUMOVehicle*> > myWaiting;
595 
598 
601 
603  double myScale;
604 
607 
610 
612  std::vector<SUMOVehicle*> myPTVehicles;
613 
614 private:
617 
620 
621 
622 };
623 
624 
625 #endif
626 
627 /****************************************************************************/
628 
bool myDefaultPedTypeMayBeDeleted
Whether the default pedestrian type was already used or can still be replaced.
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:79
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
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 getArrivedVehicleNo() const
Returns the number of arrived vehicles.
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.
bool myDefaultVTypeMayBeDeleted
Whether the default vehicle type was already used or can still be replaced.
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:66
virtual std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
A road/street connecting two junctions.
Definition: MSEdge.h:75
std::set< std::string > getVTypeDistributionMembership(const std::string &id) const
Return the distribution IDs the vehicle type is a member of.
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:60
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.
void saveState(OutputDevice &out)
Saves the current state into the given stream.
int getTeleportsJam() const
return the number of teleports due to jamming
double getVehicleMeanSpeedRelative() const
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.
std::map< std::string, std::set< std::string > > myVTypeToDist
Inverse lookup from vehicle type to distributions it is a member of.
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
virtual int getHaltingVehicleNo() const
Returns the number of halting vehicles.
int myCollisions
The number of collisions.
void setScale(double scale)
sets the demand scaling factor
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:64
std::map< std::string, SUMOVehicle *> VehicleDictType
Vehicle dictionary type.
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.
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.
int getDiscardedVehicleNo() const
Returns the number of discarded vehicles.
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...
bool myDefaultBikeTypeMayBeDeleted
Whether the default bicycle type was already used or can still be replaced.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
void removeWaiting(const MSEdge *const edge, const SUMOVehicle *vehicle)
Removes a vehicle from the list of waiting vehicles to a given edge.
double getVehicleMeanSpeed() const
std::vector< SUMOVehicle * > myPTVehicles
List of vehicles which belong to public transport.