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-2019 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 /****************************************************************************/
16 // The class responsible for building and deletion of vehicles
17 /****************************************************************************/
18 #ifndef MSVehicleControl_h
19 #define MSVehicleControl_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <cmath>
28 #include <string>
29 #include <map>
30 #include <set>
31 #ifdef HAVE_FOX
32 #include <fx.h>
34 #endif
36 #include <utils/common/SUMOTime.h>
38 #include "MSNet.h"
39 
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 class SUMOVehicle;
46 class MSVehicle;
47 class MSRoute;
48 class MSVehicleType;
49 class OutputDevice;
50 class MSEdge;
51 
52 
53 // ===========================================================================
54 // class definitions
55 // ===========================================================================
72 public:
74  typedef std::map<std::string, SUMOVehicle*>::const_iterator constVehIt;
75 
76 public:
79 
80 
82  virtual ~MSVehicleControl();
83 
84 
87 
100  virtual SUMOVehicle* buildVehicle(SUMOVehicleParameter* defs, const MSRoute* route,
101  MSVehicleType* type,
102  const bool ignoreStopErrors, const bool fromRouteFile = true);
104 
105 
106 
109 
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 
157  void scheduleVehicleRemoval(SUMOVehicle* veh, bool checkDuplicate = false);
158 
159 
171  void removePending();
172 
173 
178  return myVehicleDict.begin();
179  }
180 
181 
186  return myVehicleDict.end();
187  }
189 
190 
191 
194 
202  void vehicleDeparted(const SUMOVehicle& v);
204 
205 
206 
209 
213  int getLoadedVehicleNo() const {
214  return myLoadedVehNo;
215  }
216 
217 
221  virtual int getHaltingVehicleNo() const;
222 
224  virtual std::pair<double, double> getVehicleMeanSpeeds() const;
225  double getVehicleMeanSpeed() const {
226  return getVehicleMeanSpeeds().first;
227  }
229  return getVehicleMeanSpeeds().second;
230  }
231 
235  int getEndedVehicleNo() const {
236  return myEndedVehNo;
237  }
238 
242  int getArrivedVehicleNo() const {
243  return myEndedVehNo - myDiscarded;
244  }
245 
249  int getDiscardedVehicleNo() const {
250  return myDiscarded;
251  }
252 
253 
257  int getRunningVehicleNo() const {
258  return myRunningVehNo;
259  }
260 
261 
265  int getDepartedVehicleNo() const {
267  }
268 
269 
276  int getQuota(double frac = -1) const;
277 
278 
283  int getActiveVehicleCount() const {
285  }
286 
287 
289  int getCollisionCount() const {
290  return myCollisions;
291  }
292 
294  int getTeleportsJam() const {
295  return myTeleportsJam;
296  }
297 
299  int getTeleportsYield() const {
300  return myTeleportsYield;
301  }
302 
304  int getTeleportsWrongLane() const {
305  return myTeleportsWrongLane;
306  }
307 
309  int getTeleportCount() const;
310 
312  int getEmergencyStops() const {
313  return myEmergencyStops;
314  }
315 
319  double getTotalDepartureDelay() const {
320  return myTotalDepartureDelay;
321  }
322 
323 
327  double getTotalTravelTime() const {
328  return myTotalTravelTime;
329  }
331 
332 
333 
336 
349  bool addVType(MSVehicleType* vehType);
350 
351  /*
352  * @param[in] vehType The vehicle type to remove
353  * @return Whether the vehicle type could be removed
354  */
355  void removeVType(const MSVehicleType* vehType);
356 
357 
371  bool addVTypeDistribution(const std::string& id, RandomDistributor<MSVehicleType*>* vehTypeDistribution);
372 
373 
381  bool hasVType(const std::string& id) const;
382 
383 
391  bool hasVTypeDistribution(const std::string& id) const;
392 
393 
398  MSVehicleType* getVType(const std::string& id = DEFAULT_VTYPE_ID, std::mt19937* rng = nullptr);
399 
400 
404  void insertVTypeIDs(std::vector<std::string>& into) const;
405 
406 
410  const std::set<std::string> getVTypeDistributionMembership(const std::string& id) const;
411 
413 
416  void registerOneWaiting(const bool isPerson) {
417  if (isPerson) {
419  } else {
421  }
422  }
423 
426  void unregisterOneWaiting(const bool isPerson) {
427  if (isPerson) {
429  } else {
431  }
432  }
433 
436  myCollisions++;
437  }
438 
441  myTeleportsJam++;
442  }
443 
447  }
448 
452  }
453 
457  }
458 
461 
464  void setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime);
465 
468  void saveState(OutputDevice& out);
470 
472  void discountStateLoaded(bool removed = false) {
473  if (removed) {
474  myRunningVehNo--;
475  myDiscarded++;
476  myEndedVehNo++;
477  } else {
478  myLoadedVehNo--;
479  }
480  }
481 
482 
485  void abortWaiting();
486 
488  double getMaxSpeedFactor() const {
489  return myMaxSpeedFactor;
490  }
491 
493  double getMinDeceleration() const {
494  return myMinDeceleration;
495  }
496 
498 
500  void setScale(double scale) {
501  myScale = scale;
502  }
503 
504 private:
511  bool checkVType(const std::string& id);
512 
514  bool isPendingRemoval(SUMOVehicle* veh);
515 
516 protected:
519 
522 
523 private:
526 
529 
532 
535 
538 
541 
544 
547 
549 
550 
553 
556 
560 
561 
562 protected:
565 
567  typedef std::map< std::string, SUMOVehicle* > VehicleDictType;
571 
572 
573 private:
576 
578  typedef std::map< std::string, MSVehicleType* > VTypeDictType;
581 
583  typedef std::map< std::string, RandomDistributor<MSVehicleType*>* > VTypeDistDictType;
586 
588  std::map<std::string, std::set<std::string>> myVTypeToDist;
589 
592 
595 
598 
601 
604 
606  double myScale;
607 
610 
613 
615  std::vector<SUMOVehicle*> myPTVehicles;
616 
618 #ifdef HAVE_FOX
620 #else
621  std::vector<SUMOVehicle*> myPendingRemovals;
622 #endif
623 
624 private:
627 
630 
631 
632 };
633 
634 
635 #endif
636 
637 /****************************************************************************/
638 
MSVehicleControl::vehicleDeparted
void vehicleDeparted(const SUMOVehicle &v)
Informs this control about a vehicle's departure.
Definition: MSVehicleControl.cpp:168
MSVehicleType
The car-following model and parameter.
Definition: MSVehicleType.h:65
MSVehicleControl::registerOneWaiting
void registerOneWaiting(const bool isPerson)
increases the count of vehicles waiting for a transport to allow recognition of person / container re...
Definition: MSVehicleControl.h:416
MSVehicleControl::setScale
void setScale(double scale)
sets the demand scaling factor
Definition: MSVehicleControl.h:500
MSVehicleControl::MSVehicleControl
MSVehicleControl(const MSVehicleControl &s)
invalidated copy constructor
MSVehicleControl::getDepartedVehicleNo
int getDepartedVehicleNo() const
Returns the number of inserted vehicles.
Definition: MSVehicleControl.h:265
MSVehicleControl::getTeleportsWrongLane
int getTeleportsWrongLane() const
return the number of teleports due to vehicles stuck on the wrong lane
Definition: MSVehicleControl.h:304
SUMOTime.h
MSNet.h
MSVehicleControl::myEmergencyStops
int myEmergencyStops
The number of emergency stops.
Definition: MSVehicleControl.h:546
MSVehicleControl::getVType
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.
Definition: MSVehicleControl.cpp:353
MSVehicleControl::removeVType
void removeVType(const MSVehicleType *vehType)
Definition: MSVehicleControl.cpp:311
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
MSVehicleControl::registerTeleportJam
void registerTeleportJam()
register one non-collision-related teleport
Definition: MSVehicleControl.h:440
MSVehicleControl::getVehicleMeanSpeed
double getVehicleMeanSpeed() const
Definition: MSVehicleControl.h:225
MSVehicleControl::getActiveVehicleCount
int getActiveVehicleCount() const
Returns the number of build vehicles that have not been removed or need to wait for a passenger or a ...
Definition: MSVehicleControl.h:283
IntermodalRouter
Definition: IntermodalRouter.h:54
MSVehicleControl::~MSVehicleControl
virtual ~MSVehicleControl()
Destructor.
Definition: MSVehicleControl.cpp:80
MSVehicleControl::discountStateLoaded
void discountStateLoaded(bool removed=false)
avoid counting a vehicle twice if it was loaded from state and route input
Definition: MSVehicleControl.h:472
MSVehicleControl::saveState
void saveState(OutputDevice &out)
Saves the current state into the given stream.
Definition: MSVehicleControl.cpp:191
MSVehicleControl::getEmergencyStops
int getEmergencyStops() const
return the number of emergency stops
Definition: MSVehicleControl.h:312
MSVehicleControl::operator=
MSVehicleControl & operator=(const MSVehicleControl &s)
invalidated assignment operator
MSVehicleControl::getMinDeceleration
double getMinDeceleration() const
return the minimum deceleration capability for all vehicles that ever entered the network
Definition: MSVehicleControl.h:493
MSVehicleControl::myTotalTravelTime
double myTotalTravelTime
The aggregated time vehicles needed to aacomplish their route (in seconds)
Definition: MSVehicleControl.h:558
MSVehicleControl::abortWaiting
void abortWaiting()
informes about all waiting vehicles (deletion in destructor)
Definition: MSVehicleControl.cpp:394
MSVehicleControl::myDiscarded
int myDiscarded
The number of vehicles which were discarded while loading.
Definition: MSVehicleControl.h:531
MSVehicleControl::VTypeDistDictType
std::map< std::string, RandomDistributor< MSVehicleType * > * > VTypeDistDictType
Vehicle type distribution dictionary type.
Definition: MSVehicleControl.h:583
MSVehicleControl::getTeleportsJam
int getTeleportsJam() const
return the number of teleports due to jamming
Definition: MSVehicleControl.h:294
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:60
MSVehicleControl::getLoadedVehicleNo
int getLoadedVehicleNo() const
Returns the number of build vehicles.
Definition: MSVehicleControl.h:213
MSVehicleControl::addVTypeDistribution
bool addVTypeDistribution(const std::string &id, RandomDistributor< MSVehicleType * > *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: MSVehicleControl.cpp:323
MSVehicleControl::getTeleportsYield
int getTeleportsYield() const
return the number of teleports due to vehicles stuck on a minor road
Definition: MSVehicleControl.h:299
SUMOVehicleParameter
Structure representing possible vehicle parameter.
Definition: SUMOVehicleParameter.h:297
MSVehicleControl::scheduleVehicleRemoval
void scheduleVehicleRemoval(SUMOVehicle *veh, bool checkDuplicate=false)
Removes a vehicle after it has ended.
Definition: MSVehicleControl.cpp:117
MSRoute
Definition: MSRoute.h:66
FXSynchQue.h
MSVehicleControl::constVehIt
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
Definition: MSVehicleControl.h:74
MSVehicleControl::myVTypeDict
VTypeDictType myVTypeDict
Dictionary of vehicle types.
Definition: MSVehicleControl.h:580
MSVehicleControl::getDiscardedVehicleNo
int getDiscardedVehicleNo() const
Returns the number of discarded vehicles.
Definition: MSVehicleControl.h:249
MSVehicleControl::getEndedVehicleNo
int getEndedVehicleNo() const
Returns the number of removed vehicles.
Definition: MSVehicleControl.h:235
MSVehicleControl::myLoadedVehNo
int myLoadedVehNo
The number of build vehicles.
Definition: MSVehicleControl.h:521
MSVehicleControl::myDefaultPedTypeMayBeDeleted
bool myDefaultPedTypeMayBeDeleted
Whether the default pedestrian type was already used or can still be replaced.
Definition: MSVehicleControl.h:594
MSVehicleControl::getRunningVehicleNo
int getRunningVehicleNo() const
Returns the number of build and inserted, but not yet deleted vehicles.
Definition: MSVehicleControl.h:257
MSVehicleControl::myVTypeToDist
std::map< std::string, std::set< std::string > > myVTypeToDist
Inverse lookup from vehicle type to distributions it is a member of.
Definition: MSVehicleControl.h:588
MSVehicleControl::buildVehicle
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.
Definition: MSVehicleControl.cpp:100
MSVehicleControl::registerEmergencyStop
void registerEmergencyStop()
register emergency stop
Definition: MSVehicleControl.h:455
MSVehicleControl::getVehicleMeanSpeedRelative
double getVehicleMeanSpeedRelative() const
Definition: MSVehicleControl.h:228
MSVehicleControl::getArrivedVehicleNo
int getArrivedVehicleNo() const
Returns the number of arrived vehicles.
Definition: MSVehicleControl.h:242
MSVehicleControl::addVehicle
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
Definition: MSVehicleControl.cpp:215
MSVehicleControl::myMaxSpeedFactor
double myMaxSpeedFactor
The maximum speed factor for all vehicles in the network.
Definition: MSVehicleControl.h:609
MSVehicleControl::getVehicle
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
Definition: MSVehicleControl.cpp:240
RandomDistributor.h
MSVehicleControl::VehicleDictType
std::map< std::string, SUMOVehicle * > VehicleDictType
Vehicle dictionary type.
Definition: MSVehicleControl.h:567
MSVehicleControl::setState
void setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime)
Sets the current state variables as loaded from the stream.
Definition: MSVehicleControl.cpp:181
MSVehicleControl::getVTypeDistributionMembership
const std::set< std::string > getVTypeDistributionMembership(const std::string &id) const
Return the distribution IDs the vehicle type is a member of.
Definition: MSVehicleControl.cpp:384
MSVehicleControl::adaptIntermodalRouter
void adaptIntermodalRouter(MSNet::MSIntermodalRouter &router) const
Definition: MSVehicleControl.cpp:461
MSVehicleControl::hasVTypeDistribution
bool hasVTypeDistribution(const std::string &id) const
Asks for a vehicle type distribution.
Definition: MSVehicleControl.cpp:347
MSVehicleControl::myVTypeDistDict
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition: MSVehicleControl.h:585
MSVehicleControl::myRunningVehNo
int myRunningVehNo
The number of vehicles within the network (build and inserted but not removed)
Definition: MSVehicleControl.h:525
MSVehicleControl::addVType
bool addVType(MSVehicleType *vehType)
Adds a vehicle type.
Definition: MSVehicleControl.cpp:301
DEFAULT_VTYPE_ID
const std::string DEFAULT_VTYPE_ID
MSVehicleControl::loadedVehEnd
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Definition: MSVehicleControl.h:185
MSVehicleControl::myVehicleDict
VehicleDictType myVehicleDict
Dictionary of vehicles.
Definition: MSVehicleControl.h:569
SUMOVehicleClass.h
MSVehicleControl::myTeleportsJam
int myTeleportsJam
The number of teleports due to jam.
Definition: MSVehicleControl.h:537
MSVehicleControl::deleteVehicle
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
Definition: MSVehicleControl.cpp:250
MSVehicleControl::registerTeleportYield
void registerTeleportYield()
register one non-collision-related teleport
Definition: MSVehicleControl.h:445
MSVehicleControl::myWaitingForPerson
int myWaitingForPerson
the number of vehicles wainting for persons contained in myWaiting which can only continue by being t...
Definition: MSVehicleControl.h:600
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
MSVehicleControl::getQuota
int getQuota(double frac=-1) const
Returns the number of instances of the current vehicle that shall be emitted considering that "frac" ...
Definition: MSVehicleControl.cpp:437
MSVehicleControl::myTotalDepartureDelay
double myTotalDepartureDelay
The aggregated time vehicles had to wait for departure (in seconds)
Definition: MSVehicleControl.h:555
MSVehicleControl::getCollisionCount
int getCollisionCount() const
return the number of collisions
Definition: MSVehicleControl.h:289
FXSynchQue
Definition: FXSynchQue.h:41
RandomDistributor< MSVehicleType * >
MSVehicleControl::myPTVehicles
std::vector< SUMOVehicle * > myPTVehicles
List of vehicles which belong to public transport.
Definition: MSVehicleControl.h:615
MSVehicleControl::myScale
double myScale
The scaling factor (especially for inc-dua)
Definition: MSVehicleControl.h:606
MSVehicleControl::registerCollision
void registerCollision()
registers one collision-related teleport
Definition: MSVehicleControl.h:435
MSVehicleControl::myTeleportsYield
int myTeleportsYield
The number of teleports due to vehicles stuck on a minor road.
Definition: MSVehicleControl.h:540
MSVehicleControl::isPendingRemoval
bool isPendingRemoval(SUMOVehicle *veh)
whether the given vehicle is scheduled for removal
Definition: MSVehicleControl.cpp:126
MSVehicleControl::myWaitingForContainer
int myWaitingForContainer
the number of vehicles wainting for containers contained in myWaiting which can only continue by bein...
Definition: MSVehicleControl.h:603
MSVehicleControl::getHaltingVehicleNo
virtual int getHaltingVehicleNo() const
Returns the number of halting vehicles.
Definition: MSVehicleControl.cpp:402
MSVehicleControl::registerTeleportWrongLane
void registerTeleportWrongLane()
register one non-collision-related teleport
Definition: MSVehicleControl.h:450
MSVehicleControl::removePending
void removePending()
Removes a vehicle after it has ended.
Definition: MSVehicleControl.cpp:135
MSVehicleControl::myMinDeceleration
double myMinDeceleration
The minimum deceleration capability for all vehicles in the network.
Definition: MSVehicleControl.h:612
MSVehicleControl::MSVehicleControl
MSVehicleControl()
Constructor.
Definition: MSVehicleControl.cpp:48
MSVehicleControl::myCollisions
int myCollisions
The number of collisions.
Definition: MSVehicleControl.h:534
MSVehicleControl::myDefaultVTypeMayBeDeleted
bool myDefaultVTypeMayBeDeleted
Whether the default vehicle type was already used or can still be replaced.
Definition: MSVehicleControl.h:591
MSVehicleControl::VTypeDictType
std::map< std::string, MSVehicleType * > VTypeDictType
Vehicle type dictionary type.
Definition: MSVehicleControl.h:578
MSVehicleControl::getTotalTravelTime
double getTotalTravelTime() const
Returns the total travel time.
Definition: MSVehicleControl.h:327
MSVehicleControl::getVehicleMeanSpeeds
virtual std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
Definition: MSVehicleControl.cpp:416
MSVehicleControl::myTeleportsWrongLane
int myTeleportsWrongLane
The number of teleports due to vehicles stuck on the wrong lane.
Definition: MSVehicleControl.h:543
MSVehicleControl::checkVType
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition: MSVehicleControl.cpp:267
MSVehicleControl::insertVTypeIDs
void insertVTypeIDs(std::vector< std::string > &into) const
Inserts ids of all known vehicle types and vehicle type distributions to the given vector.
Definition: MSVehicleControl.cpp:372
config.h
MSVehicleControl
The class responsible for building and deletion of vehicles.
Definition: MSVehicleControl.h:71
MSVehicleControl::myPendingRemovals
std::vector< SUMOVehicle * > myPendingRemovals
List of vehicles which are going to be removed.
Definition: MSVehicleControl.h:621
MSVehicleControl::getTotalDepartureDelay
double getTotalDepartureDelay() const
Returns the total departure delay.
Definition: MSVehicleControl.h:319
MSVehicleControl::hasVType
bool hasVType(const std::string &id) const
Asks for existence of a vehicle type.
Definition: MSVehicleControl.cpp:341
MSVehicleControl::loadedVehBegin
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
Definition: MSVehicleControl.h:177
MSVehicleControl::getTeleportCount
int getTeleportCount() const
return the number of teleports (including collisions)
Definition: MSVehicleControl.cpp:455
MSVehicleControl::getMaxSpeedFactor
double getMaxSpeedFactor() const
return the maximum speed factor for all vehicles that ever entered the network
Definition: MSVehicleControl.h:488
MSVehicleControl::myEndedVehNo
int myEndedVehNo
The number of removed vehicles.
Definition: MSVehicleControl.h:528
MSVehicleControl::unregisterOneWaiting
void unregisterOneWaiting(const bool isPerson)
decreases the count of vehicles waiting for a transport to allow recognition of person / container re...
Definition: MSVehicleControl.h:426
MSVehicleControl::myDefaultBikeTypeMayBeDeleted
bool myDefaultBikeTypeMayBeDeleted
Whether the default bicycle type was already used or can still be replaced.
Definition: MSVehicleControl.h:597
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79