Eclipse 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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // The class responsible for building and deletion of vehicles
21 /****************************************************************************/
22 #pragma once
23 #include <config.h>
24 
25 #include <cmath>
26 #include <string>
27 #include <map>
28 #include <set>
29 #ifdef HAVE_FOX
30 #include <fx.h>
32 #endif
34 #include <utils/common/SUMOTime.h>
36 #include "MSNet.h"
37 
38 
39 // ===========================================================================
40 // class declarations
41 // ===========================================================================
42 class SUMOVehicle;
44 class MSBaseVehicle;
45 class MSVehicle;
46 class MSRoute;
47 class MSVehicleType;
48 class OutputDevice;
49 class MSEdge;
50 
51 
52 // ===========================================================================
53 // class definitions
54 // ===========================================================================
71 public:
73  typedef std::map<std::string, SUMOVehicle*>::const_iterator constVehIt;
74 
75 public:
78 
79 
81  virtual ~MSVehicleControl();
82 
83 
86 
99  virtual SUMOVehicle* buildVehicle(SUMOVehicleParameter* defs, const MSRoute* route,
100  MSVehicleType* type,
101  const bool ignoreStopErrors, const bool fromRouteFile = true);
103 
104 
105 
108 
122  virtual bool addVehicle(const std::string& id, SUMOVehicle* v);
123 
124 
133  SUMOVehicle* getVehicle(const std::string& id) const;
134 
135 
142  virtual void deleteVehicle(SUMOVehicle* v, bool discard = false);
143 
145  myLoadedVehNo++;
146  myEndedVehNo++;
147  myDiscarded++;
148  }
149 
161  void scheduleVehicleRemoval(SUMOVehicle* veh, bool checkDuplicate = false);
162 
163 
175  void removePending();
176 
177 
182  return myVehicleDict.begin();
183  }
184 
185 
190  return myVehicleDict.end();
191  }
193 
194 
195 
198 
206  void vehicleDeparted(const SUMOVehicle& v);
208 
209 
210 
213 
217  int getLoadedVehicleNo() const {
218  return myLoadedVehNo;
219  }
220 
221 
225  virtual int getHaltingVehicleNo() const;
226 
228  virtual std::pair<double, double> getVehicleMeanSpeeds() const;
229  double getVehicleMeanSpeed() const {
230  return getVehicleMeanSpeeds().first;
231  }
233  return getVehicleMeanSpeeds().second;
234  }
235 
239  int getEndedVehicleNo() const {
240  return myEndedVehNo;
241  }
242 
246  int getArrivedVehicleNo() const {
247  return myEndedVehNo - myDiscarded;
248  }
249 
253  int getDiscardedVehicleNo() const {
254  return myDiscarded;
255  }
256 
257 
261  int getRunningVehicleNo() const {
262  return myRunningVehNo;
263  }
264 
265 
269  int getDepartedVehicleNo() const {
271  }
272 
273 
281  int getQuota(double frac = -1, int loaded = -1) const;
282 
283 
288  int getActiveVehicleCount() const {
290  }
291 
292 
294  int getCollisionCount() const {
295  return myCollisions;
296  }
297 
299  int getTeleportsJam() const {
300  return myTeleportsJam;
301  }
302 
304  int getTeleportsYield() const {
305  return myTeleportsYield;
306  }
307 
309  int getTeleportsWrongLane() const {
310  return myTeleportsWrongLane;
311  }
312 
314  int getTeleportCount() const;
315 
317  int getEmergencyStops() const {
318  return myEmergencyStops;
319  }
320 
323  return myStoppedVehicles;
324  }
325 
329  double getTotalDepartureDelay() const {
330  return myTotalDepartureDelay;
331  }
332 
333 
337  double getTotalTravelTime() const {
338  return myTotalTravelTime;
339  }
341 
342 
343 
346 
359  bool addVType(MSVehicleType* vehType);
360 
361  /*
362  * @param[in] vehType The vehicle type to remove
363  * @return Whether the vehicle type could be removed
364  */
365  void removeVType(const MSVehicleType* vehType);
366 
367 
381  bool addVTypeDistribution(const std::string& id, RandomDistributor<MSVehicleType*>* vehTypeDistribution);
382 
383 
391  bool hasVType(const std::string& id) const;
392 
393 
401  bool hasVTypeDistribution(const std::string& id) const;
402 
403 
408  MSVehicleType* getVType(const std::string& id = DEFAULT_VTYPE_ID, std::mt19937* rng = nullptr);
409 
410 
414  void insertVTypeIDs(std::vector<std::string>& into) const;
415 
416 
420  const std::set<std::string> getVTypeDistributionMembership(const std::string& id) const;
421 
423  const RandomDistributor<MSVehicleType*>* getVTypeDistribution(const std::string& typeDistID) const;
424 
426 
429  void registerOneWaiting(const bool isPerson) {
430  if (isPerson) {
432  } else {
434  }
435  }
436 
439  void unregisterOneWaiting(const bool isPerson) {
440  if (isPerson) {
442  } else {
444  }
445  }
446 
449  myCollisions++;
450  }
451 
454  myTeleportsJam++;
455  }
456 
460  }
461 
465  }
466 
470  }
471 
475  }
476 
480  }
481 
484 
487  void setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime);
488 
491  void saveState(OutputDevice& out);
492 
494  void clearState();
496 
498  void discountStateRemoved(int n) {
499  myRunningVehNo -= n;
500  myDiscarded += n;
501  myEndedVehNo += n;
502  }
503 
504 
507  void abortWaiting();
508 
510  double getMaxSpeedFactor() const {
511  return myMaxSpeedFactor;
512  }
513 
515  double getMinDeceleration() const {
516  return myMinDeceleration;
517  }
518 
520 
522  void setScale(double scale) {
523  myScale = scale;
524  }
525 
526 private:
533  bool checkVType(const std::string& id);
534 
536  bool isPendingRemoval(SUMOVehicle* veh);
537 
538 protected:
539  void initVehicle(MSBaseVehicle* built, const bool ignoreStopErrors);
540 
541 private:
544 
547 
550 
553 
556 
559 
562 
565 
568 
571 
575 
576 
579 
582 
586 
587 
588 protected:
591 
593  typedef std::map< std::string, SUMOVehicle* > VehicleDictType;
597 
598 
599 private:
602 
604  typedef std::map< std::string, MSVehicleType* > VTypeDictType;
607 
609  typedef std::map< std::string, RandomDistributor<MSVehicleType*>* > VTypeDistDictType;
612 
614  std::map<std::string, std::set<std::string>> myVTypeToDist;
615 
618 
621 
624 
627 
630 
633 
636 
638  double myScale;
639 
642 
645 
647  std::vector<SUMOVehicle*> myPTVehicles;
648 
650 #ifdef HAVE_FOX
652 #else
653  std::vector<SUMOVehicle*> myPendingRemovals;
654 #endif
655 
656 private:
659 
662 
663 
664 };
const std::string DEFAULT_VTYPE_ID
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:51
A road/street connecting two junctions.
Definition: MSEdge.h:77
The class responsible for building and deletion of vehicles.
MSVehicleControl & operator=(const MSVehicleControl &s)
invalidated assignment operator
void registerOneWaiting(const bool isPerson)
increases the count of vehicles waiting for a transport to allow recognition of person / container re...
double myScale
The scaling factor (especially for inc-dua)
bool hasVType(const std::string &id) const
Asks for existence of a vehicle type.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
void clearState()
Remove all vehicles before quick-loading state.
bool myDefaultTaxiTypeMayBeDeleted
Whether the default taxi type was already used or can still be replaced.
std::map< std::string, SUMOVehicle * > VehicleDictType
Vehicle dictionary type.
bool addVType(MSVehicleType *vehType)
Adds a vehicle type.
void setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime)
Sets the current state variables as loaded from the stream.
int getRunningVehicleNo() const
Returns the number of build and inserted, but not yet deleted vehicles.
void registerEmergencyStop()
register emergency stop
void removePending()
Removes a vehicle after it has ended.
double getTotalTravelTime() const
Returns the total travel time.
void adaptIntermodalRouter(MSNet::MSIntermodalRouter &router) const
MSVehicleControl(const MSVehicleControl &s)
invalidated copy constructor
void setScale(double scale)
sets the demand scaling factor
std::vector< SUMOVehicle * > myPendingRemovals
List of vehicles which are going to be removed.
int myLoadedVehNo
The number of build vehicles.
void registerTeleportYield()
register one non-collision-related teleport
void discountStateRemoved(int n)
discount vehicles that were removed during state loading
bool hasVTypeDistribution(const std::string &id) const
Asks for a vehicle type distribution.
void vehicleDeparted(const SUMOVehicle &v)
Informs this control about a vehicle's departure.
int getLoadedVehicleNo() const
Returns the number of build vehicles.
bool myDefaultVTypeMayBeDeleted
Whether the default vehicle type was already used or can still be replaced.
double getMinDeceleration() const
return the minimum deceleration capability for all vehicles that ever entered the network
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
int getCollisionCount() const
return the number of collisions
int getTeleportsWrongLane() const
return the number of teleports due to vehicles stuck on the wrong lane
int myTeleportsYield
The number of teleports due to vehicles stuck on a minor road.
int myTeleportsWrongLane
The number of teleports due to vehicles stuck on the wrong lane.
int getStoppedVehiclesCount() const
return the number of vehicles that are currently stopped
double getVehicleMeanSpeed() const
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
int getTeleportsYield() const
return the number of teleports due to vehicles stuck on a minor road
std::map< std::string, std::set< std::string > > myVTypeToDist
Inverse lookup from vehicle type to distributions it is a member of.
int getEmergencyStops() const
return the number of emergency stops
bool myDefaultBikeTypeMayBeDeleted
Whether the default bicycle type was already used or can still be replaced.
double myMinDeceleration
The minimum deceleration capability for all vehicles in the network.
void registerTeleportJam()
register one non-collision-related teleport
void registerStopEnded()
register emergency stop
double getTotalDepartureDelay() const
Returns the total departure delay.
bool isPendingRemoval(SUMOVehicle *veh)
whether the given vehicle is scheduled for removal
virtual ~MSVehicleControl()
Destructor.
void removeVType(const MSVehicleType *vehType)
int myStoppedVehicles
The number of stopped vehicles.
std::map< std::string, MSVehicleType * > VTypeDictType
Vehicle type dictionary type.
bool myDefaultPedTypeMayBeDeleted
Whether the default pedestrian type was already used or can still be replaced.
virtual std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
void initVehicle(MSBaseVehicle *built, const bool ignoreStopErrors)
int myCollisions
The number of collisions.
int myEmergencyStops
The number of emergency stops.
int getQuota(double frac=-1, int loaded=-1) const
Returns the number of instances of the current vehicle that shall be emitted considering that "frac" ...
MSVehicleControl()
Constructor.
int myWaitingForPerson
the number of vehicles wainting for persons contained in myWaiting which can only continue by being t...
double myMaxSpeedFactor
The maximum speed factor for all vehicles in the network.
void registerCollision()
registers one collision-related teleport
int myDiscarded
The number of vehicles which were discarded while loading.
int getDepartedVehicleNo() const
Returns the number of inserted vehicles.
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, std::mt19937 *rng=nullptr)
Returns the named vehicle type or a sample from the named distribution.
int getArrivedVehicleNo() const
Returns the number of arrived vehicles.
int myWaitingForContainer
the number of vehicles wainting for containers contained in myWaiting which can only continue by bein...
bool myDefaultContainerTypeMayBeDeleted
Whether the default container type was already used or can still be replaced.
int myEndedVehNo
The number of removed vehicles.
void unregisterOneWaiting(const bool isPerson)
decreases the count of vehicles waiting for a transport to allow recognition of person / container re...
bool addVTypeDistribution(const std::string &id, RandomDistributor< MSVehicleType * > *vehTypeDistribution)
Adds a vehicle type distribution.
int myTeleportsJam
The number of teleports due to jam.
int getActiveVehicleCount() const
Returns the number of build vehicles that have not been removed or need to wait for a passenger or a ...
void insertVTypeIDs(std::vector< std::string > &into) const
Inserts ids of all known vehicle types and vehicle type distributions to the given vector.
int getTeleportsJam() const
return the number of teleports due to jamming
double myTotalDepartureDelay
The aggregated time vehicles had to wait for departure (in seconds)
int getEndedVehicleNo() const
Returns the number of removed vehicles.
VTypeDictType myVTypeDict
Dictionary of vehicle types.
double getMaxSpeedFactor() const
return the maximum speed factor for all vehicles that ever entered the network
const RandomDistributor< MSVehicleType * > * getVTypeDistribution(const std::string &typeDistID) const
return the vehicle type distribution with the given id
virtual int getHaltingVehicleNo() const
Returns the number of halting vehicles.
void scheduleVehicleRemoval(SUMOVehicle *veh, bool checkDuplicate=false)
Removes a vehicle after it has ended.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
double myTotalTravelTime
The aggregated time vehicles needed to aacomplish their route (in seconds)
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.
std::vector< SUMOVehicle * > myPTVehicles
List of vehicles which belong to public transport.
int getTeleportCount() const
return the number of teleports (including collisions)
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
std::map< std::string, RandomDistributor< MSVehicleType * > * > VTypeDistDictType
Vehicle type distribution dictionary type.
void abortWaiting()
informes about all waiting vehicles (deletion in destructor)
void saveState(OutputDevice &out)
Saves the current state into the given stream.
double getVehicleMeanSpeedRelative() const
void registerTeleportWrongLane()
register one non-collision-related teleport
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
const std::set< std::string > getVTypeDistributionMembership(const std::string &id) const
Return the distribution IDs the vehicle type is a member of.
int myRunningVehNo
The number of vehicles within the network (build and inserted but not removed)
int getDiscardedVehicleNo() const
Returns the number of discarded vehicles.
void registerStopStarted()
register emergency stop
VehicleDictType myVehicleDict
Dictionary of vehicles.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
The car-following model and parameter.
Definition: MSVehicleType.h:62
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
Representation of a vehicle.
Definition: SUMOVehicle.h:58
Structure representing possible vehicle parameter.