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 /****************************************************************************/
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>
32 #ifdef HAVE_FOX
33 #include <fx.h>
35 #endif
37 #include <utils/common/SUMOTime.h>
39 #include "MSNet.h"
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class SUMOVehicle;
47 class MSVehicle;
48 class MSRoute;
49 class MSVehicleType;
50 class OutputDevice;
51 class MSEdge;
52 
53 
54 // ===========================================================================
55 // class definitions
56 // ===========================================================================
73 public:
75  typedef std::map<std::string, SUMOVehicle*>::const_iterator constVehIt;
76 
77 public:
80 
81 
83  virtual ~MSVehicleControl();
84 
85 
88 
101  virtual SUMOVehicle* buildVehicle(SUMOVehicleParameter* defs, const MSRoute* route,
102  MSVehicleType* type,
103  const bool ignoreStopErrors, const bool fromRouteFile = true);
105 
106 
107 
110 
124  virtual bool addVehicle(const std::string& id, SUMOVehicle* v);
125 
126 
135  SUMOVehicle* getVehicle(const std::string& id) const;
136 
137 
144  virtual void deleteVehicle(SUMOVehicle* v, bool discard = false);
145 
146 
158  void scheduleVehicleRemoval(SUMOVehicle* veh, bool checkDuplicate = false);
159 
160 
172  void removePending();
173 
174 
179  return myVehicleDict.begin();
180  }
181 
182 
187  return myVehicleDict.end();
188  }
190 
191 
192 
195 
203  void vehicleDeparted(const SUMOVehicle& v);
205 
206 
207 
210 
214  int getLoadedVehicleNo() const {
215  return myLoadedVehNo;
216  }
217 
218 
222  virtual int getHaltingVehicleNo() const;
223 
225  virtual std::pair<double, double> getVehicleMeanSpeeds() const;
226  double getVehicleMeanSpeed() const {
227  return getVehicleMeanSpeeds().first;
228  }
230  return getVehicleMeanSpeeds().second;
231  }
232 
236  int getEndedVehicleNo() const {
237  return myEndedVehNo;
238  }
239 
243  int getArrivedVehicleNo() const {
244  return myEndedVehNo - myDiscarded;
245  }
246 
250  int getDiscardedVehicleNo() const {
251  return myDiscarded;
252  }
253 
254 
258  int getRunningVehicleNo() const {
259  return myRunningVehNo;
260  }
261 
262 
266  int getDepartedVehicleNo() const {
268  }
269 
270 
277  int getQuota(double frac = -1) const;
278 
279 
284  int getActiveVehicleCount() const {
286  }
287 
288 
290  int getCollisionCount() const {
291  return myCollisions;
292  }
293 
295  int getTeleportsJam() const {
296  return myTeleportsJam;
297  }
298 
300  int getTeleportsYield() const {
301  return myTeleportsYield;
302  }
303 
305  int getTeleportsWrongLane() const {
306  return myTeleportsWrongLane;
307  }
308 
310  int getTeleportCount() const;
311 
313  int getEmergencyStops() const {
314  return myEmergencyStops;
315  }
316 
320  double getTotalDepartureDelay() const {
321  return myTotalDepartureDelay;
322  }
323 
324 
328  double getTotalTravelTime() const {
329  return myTotalTravelTime;
330  }
332 
333 
334 
337 
350  bool addVType(MSVehicleType* vehType);
351 
352  /*
353  * @param[in] vehType The vehicle type to remove
354  * @return Whether the vehicle type could be removed
355  */
356  void removeVType(const MSVehicleType* vehType);
357 
358 
372  bool addVTypeDistribution(const std::string& id, RandomDistributor<MSVehicleType*>* vehTypeDistribution);
373 
374 
382  bool hasVType(const std::string& id) const;
383 
384 
392  bool hasVTypeDistribution(const std::string& id) const;
393 
394 
399  MSVehicleType* getVType(const std::string& id = DEFAULT_VTYPE_ID, std::mt19937* rng = nullptr);
400 
401 
405  void insertVTypeIDs(std::vector<std::string>& into) const;
406 
407 
411  const std::set<std::string> getVTypeDistributionMembership(const std::string& id) const;
412 
414 
416  void addWaiting(const MSEdge* const edge, SUMOVehicle* vehicle);
417 
419  void removeWaiting(const MSEdge* const edge, const SUMOVehicle* vehicle);
420 
421  /* @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
422  * @param[in] edge The edge at which the vehicle is positioned.
423  * @param[in] lines The set of lines from which at least one must correspond to the line of the vehicle
424  * @param[in] position The vehicle shall be positioned in the interval [position - t, position + t], where t is some tolerance
425  * @param[in] ridingID The id of the person or container that wants to ride
426  */
427  SUMOVehicle* getWaitingVehicle(MSTransportable* transportable, const MSEdge* const edge, const double position);
428 
431  void registerOneWaiting(const bool isPerson) {
432  if (isPerson) {
434  } else {
436  }
437  }
438 
441  void unregisterOneWaiting(const bool isPerson) {
442  if (isPerson) {
444  } else {
446  }
447  }
448 
451  myCollisions++;
452  }
453 
456  myTeleportsJam++;
457  }
458 
462  }
463 
467  }
468 
472  }
473 
476 
479  void setState(int runningVehNo, int loadedVehNo, int endedVehNo, double totalDepartureDelay, double totalTravelTime);
480 
483  void saveState(OutputDevice& out);
485 
487  void discountStateLoaded(bool removed = false) {
488  if (removed) {
489  myRunningVehNo--;
490  myDiscarded++;
491  myEndedVehNo++;
492  } else {
493  myLoadedVehNo--;
494  }
495  }
496 
497 
500  void abortWaiting();
501 
503  double getMaxSpeedFactor() const {
504  return myMaxSpeedFactor;
505  }
506 
508  double getMinDeceleration() const {
509  return myMinDeceleration;
510  }
511 
513 
515  void setScale(double scale) {
516  myScale = scale;
517  }
518 
519 private:
526  bool checkVType(const std::string& id);
527 
528 protected:
531 
534 
535 private:
538 
541 
544 
547 
550 
553 
556 
559 
561 
562 
565 
568 
572 
573 
574 protected:
577 
579  typedef std::map< std::string, SUMOVehicle* > VehicleDictType;
583 
584 
585 private:
588 
590  typedef std::map< std::string, MSVehicleType* > VTypeDictType;
593 
595  typedef std::map< std::string, RandomDistributor<MSVehicleType*>* > VTypeDistDictType;
598 
600  std::map<std::string, std::set<std::string>> myVTypeToDist;
601 
604 
607 
610 
612  std::map<const MSEdge* const, std::vector<SUMOVehicle*> > myWaiting;
613 
616 
619 
621  double myScale;
622 
625 
628 
630  std::vector<SUMOVehicle*> myPTVehicles;
631 
634 
636 #ifdef HAVE_FOX
638 #else
639  std::vector<SUMOVehicle*> myPendingRemovals;
640 #endif
641 
642 private:
645 
648 
649 
650 };
651 
652 
653 #endif
654 
655 /****************************************************************************/
656 
MSVehicleControl::vehicleDeparted
void vehicleDeparted(const SUMOVehicle &v)
Informs this control about a vehicle's departure.
Definition: MSVehicleControl.cpp:163
MSVehicleType
The car-following model and parameter.
Definition: MSVehicleType.h:66
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:431
MSVehicleControl::setScale
void setScale(double scale)
sets the demand scaling factor
Definition: MSVehicleControl.h:515
MSVehicleControl::getDepartedVehicleNo
int getDepartedVehicleNo() const
Returns the number of inserted vehicles.
Definition: MSVehicleControl.h:266
MSVehicleControl::getTeleportsWrongLane
int getTeleportsWrongLane() const
return the number of teleports due to vehicles stuck on the wrong lane
Definition: MSVehicleControl.h:305
SUMOTime.h
MSNet.h
MSVehicleControl::myEmergencyStops
int myEmergencyStops
The number of emergency stops.
Definition: MSVehicleControl.h:558
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:348
MSVehicleControl::removeVType
void removeVType(const MSVehicleType *vehType)
Definition: MSVehicleControl.cpp:306
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
MSVehicleControl::registerTeleportJam
void registerTeleportJam()
register one non-collision-related teleport
Definition: MSVehicleControl.h:455
MSVehicleControl::getVehicleMeanSpeed
double getVehicleMeanSpeed() const
Definition: MSVehicleControl.h:226
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:284
IntermodalRouter
Definition: MSNet.h:80
MSVehicleControl::~MSVehicleControl
virtual ~MSVehicleControl()
Destructor.
Definition: MSVehicleControl.cpp:83
MSVehicleControl::discountStateLoaded
void discountStateLoaded(bool removed=false)
avoid counting a vehicle twice if it was loaded from state and route input
Definition: MSVehicleControl.h:487
MSVehicleControl::saveState
void saveState(OutputDevice &out)
Saves the current state into the given stream.
Definition: MSVehicleControl.cpp:186
MSVehicleControl::getEmergencyStops
int getEmergencyStops() const
return the number of emergency stops
Definition: MSVehicleControl.h:313
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:508
MSVehicleControl::removeWaiting
void removeWaiting(const MSEdge *const edge, const SUMOVehicle *vehicle)
Removes a vehicle from the list of waiting vehicles for the given edge.
Definition: MSVehicleControl.cpp:398
MSVehicleControl::myTotalTravelTime
double myTotalTravelTime
The aggregated time vehicles needed to aacomplish their route (in seconds)
Definition: MSVehicleControl.h:570
MSVehicleControl::abortWaiting
void abortWaiting()
informes about all waiting vehicles (deletion in destructor)
Definition: MSVehicleControl.cpp:430
MSVehicleControl::myDiscarded
int myDiscarded
The number of vehicles which were discarded while loading.
Definition: MSVehicleControl.h:543
MSVehicleControl::VTypeDistDictType
std::map< std::string, RandomDistributor< MSVehicleType * > * > VTypeDistDictType
Vehicle type distribution dictionary type.
Definition: MSVehicleControl.h:595
MSVehicleControl::getTeleportsJam
int getTeleportsJam() const
return the number of teleports due to jamming
Definition: MSVehicleControl.h:295
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:61
MSVehicleControl::getLoadedVehicleNo
int getLoadedVehicleNo() const
Returns the number of build vehicles.
Definition: MSVehicleControl.h:214
MSVehicleControl::addVTypeDistribution
bool addVTypeDistribution(const std::string &id, RandomDistributor< MSVehicleType * > *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: MSVehicleControl.cpp:318
MSVehicleControl::getTeleportsYield
int getTeleportsYield() const
return the number of teleports due to vehicles stuck on a minor road
Definition: MSVehicleControl.h:300
SUMOVehicleParameter
Structure representing possible vehicle parameter.
Definition: SUMOVehicleParameter.h:291
MSTransportable
Definition: MSTransportable.h:59
MSVehicleControl::scheduleVehicleRemoval
void scheduleVehicleRemoval(SUMOVehicle *veh, bool checkDuplicate=false)
Removes a vehicle after it has ended.
Definition: MSVehicleControl.cpp:115
MSRoute
Definition: MSRoute.h:67
FXSynchQue.h
MSVehicleControl::constVehIt
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
Definition: MSVehicleControl.h:75
MSVehicleControl::addWaiting
void addWaiting(const MSEdge *const edge, SUMOVehicle *vehicle)
Adds a vehicle to the list of waiting vehicles for the given edge.
Definition: MSVehicleControl.cpp:389
MSVehicleControl::myVTypeDict
VTypeDictType myVTypeDict
Dictionary of vehicle types.
Definition: MSVehicleControl.h:592
MSVehicleControl::getDiscardedVehicleNo
int getDiscardedVehicleNo() const
Returns the number of discarded vehicles.
Definition: MSVehicleControl.h:250
MSVehicleControl::getEndedVehicleNo
int getEndedVehicleNo() const
Returns the number of removed vehicles.
Definition: MSVehicleControl.h:236
MSVehicleControl::myLoadedVehNo
int myLoadedVehNo
The number of build vehicles.
Definition: MSVehicleControl.h:533
MSVehicleControl::myDefaultPedTypeMayBeDeleted
bool myDefaultPedTypeMayBeDeleted
Whether the default pedestrian type was already used or can still be replaced.
Definition: MSVehicleControl.h:606
MSVehicleControl::getRunningVehicleNo
int getRunningVehicleNo() const
Returns the number of build and inserted, but not yet deleted vehicles.
Definition: MSVehicleControl.h:258
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:600
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:103
MSVehicleControl::registerEmergencyStop
void registerEmergencyStop()
register emergency stop
Definition: MSVehicleControl.h:470
MSVehicleControl::getVehicleMeanSpeedRelative
double getVehicleMeanSpeedRelative() const
Definition: MSVehicleControl.h:229
MSVehicleControl::getArrivedVehicleNo
int getArrivedVehicleNo() const
Returns the number of arrived vehicles.
Definition: MSVehicleControl.h:243
MSVehicleControl::addVehicle
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
Definition: MSVehicleControl.cpp:210
MSVehicleControl::myMaxSpeedFactor
double myMaxSpeedFactor
The maximum speed factor for all vehicles in the network.
Definition: MSVehicleControl.h:624
MSVehicleControl::getVehicle
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
Definition: MSVehicleControl.cpp:235
RandomDistributor.h
MSVehicleControl::VehicleDictType
std::map< std::string, SUMOVehicle * > VehicleDictType
Vehicle dictionary type.
Definition: MSVehicleControl.h:579
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:176
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:379
MSVehicleControl::adaptIntermodalRouter
void adaptIntermodalRouter(MSNet::MSIntermodalRouter &router) const
Definition: MSVehicleControl.cpp:497
MSVehicleControl::hasVTypeDistribution
bool hasVTypeDistribution(const std::string &id) const
Asks for a vehicle type distribution.
Definition: MSVehicleControl.cpp:342
MSVehicleControl::myVTypeDistDict
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition: MSVehicleControl.h:597
MSVehicleControl::myRunningVehNo
int myRunningVehNo
The number of vehicles within the network (build and inserted but not removed)
Definition: MSVehicleControl.h:537
MSVehicleControl::addVType
bool addVType(MSVehicleType *vehType)
Adds a vehicle type.
Definition: MSVehicleControl.cpp:296
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:186
MSVehicleControl::myVehicleDict
VehicleDictType myVehicleDict
Dictionary of vehicles.
Definition: MSVehicleControl.h:581
SUMOVehicleClass.h
MSVehicleControl::myTeleportsJam
int myTeleportsJam
The number of teleports due to jam.
Definition: MSVehicleControl.h:549
MSVehicleControl::myStopTolerance
double myStopTolerance
The tolerance to apply when matching waiting persons and vehicles.
Definition: MSVehicleControl.h:633
MSVehicleControl::deleteVehicle
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
Definition: MSVehicleControl.cpp:245
MSVehicleControl::registerTeleportYield
void registerTeleportYield()
register one non-collision-related teleport
Definition: MSVehicleControl.h:460
MSVehicleControl::myWaitingForPerson
int myWaitingForPerson
the number of vehicles wainting for persons contained in myWaiting which can only continue by being t...
Definition: MSVehicleControl.h:615
MSVehicleControl::myWaiting
std::map< const MSEdge *const, std::vector< SUMOVehicle * > > myWaiting
the lists of waiting vehicles to a given edge
Definition: MSVehicleControl.h:612
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:76
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:473
MSVehicleControl::myTotalDepartureDelay
double myTotalDepartureDelay
The aggregated time vehicles had to wait for departure (in seconds)
Definition: MSVehicleControl.h:567
MSVehicleControl::getCollisionCount
int getCollisionCount() const
return the number of collisions
Definition: MSVehicleControl.h:290
FXSynchQue
Definition: FXSynchQue.h:34
RandomDistributor< MSVehicleType * >
MSVehicleControl::myPTVehicles
std::vector< SUMOVehicle * > myPTVehicles
List of vehicles which belong to public transport.
Definition: MSVehicleControl.h:630
MSVehicleControl::myScale
double myScale
The scaling factor (especially for inc-dua)
Definition: MSVehicleControl.h:621
MSVehicleControl::registerCollision
void registerCollision()
registers one collision-related teleport
Definition: MSVehicleControl.h:450
MSVehicleControl::myTeleportsYield
int myTeleportsYield
The number of teleports due to vehicles stuck on a minor road.
Definition: MSVehicleControl.h:552
MSVehicleControl::myWaitingForContainer
int myWaitingForContainer
the number of vehicles wainting for containers contained in myWaiting which can only continue by bein...
Definition: MSVehicleControl.h:618
MSVehicleControl::getHaltingVehicleNo
virtual int getHaltingVehicleNo() const
Returns the number of halting vehicles.
Definition: MSVehicleControl.cpp:438
MSVehicleControl::registerTeleportWrongLane
void registerTeleportWrongLane()
register one non-collision-related teleport
Definition: MSVehicleControl.h:465
MSVehicleControl::removePending
void removePending()
Removes a vehicle after it has ended.
Definition: MSVehicleControl.cpp:130
MSVehicleControl::myMinDeceleration
double myMinDeceleration
The minimum deceleration capability for all vehicles in the network.
Definition: MSVehicleControl.h:627
MSVehicleControl::MSVehicleControl
MSVehicleControl()
Constructor.
Definition: MSVehicleControl.cpp:49
MSVehicleControl::myCollisions
int myCollisions
The number of collisions.
Definition: MSVehicleControl.h:546
MSVehicleControl::myDefaultVTypeMayBeDeleted
bool myDefaultVTypeMayBeDeleted
Whether the default vehicle type was already used or can still be replaced.
Definition: MSVehicleControl.h:603
MSVehicleControl::VTypeDictType
std::map< std::string, MSVehicleType * > VTypeDictType
Vehicle type dictionary type.
Definition: MSVehicleControl.h:590
MSVehicleControl::getTotalTravelTime
double getTotalTravelTime() const
Returns the total travel time.
Definition: MSVehicleControl.h:328
MSVehicleControl::getVehicleMeanSpeeds
virtual std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
Definition: MSVehicleControl.cpp:452
MSVehicleControl::myTeleportsWrongLane
int myTeleportsWrongLane
The number of teleports due to vehicles stuck on the wrong lane.
Definition: MSVehicleControl.h:555
MSVehicleControl::checkVType
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition: MSVehicleControl.cpp:262
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:367
config.h
MSVehicleControl
The class responsible for building and deletion of vehicles.
Definition: MSVehicleControl.h:72
MSVehicleControl::myPendingRemovals
std::vector< SUMOVehicle * > myPendingRemovals
List of vehicles which are going to be removed.
Definition: MSVehicleControl.h:639
MSVehicleControl::getTotalDepartureDelay
double getTotalDepartureDelay() const
Returns the total departure delay.
Definition: MSVehicleControl.h:320
MSVehicleControl::hasVType
bool hasVType(const std::string &id) const
Asks for existence of a vehicle type.
Definition: MSVehicleControl.cpp:336
MSVehicleControl::getWaitingVehicle
SUMOVehicle * getWaitingVehicle(MSTransportable *transportable, const MSEdge *const edge, const double position)
Definition: MSVehicleControl.cpp:409
MSVehicleControl::loadedVehBegin
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
Definition: MSVehicleControl.h:178
MSVehicleControl::getTeleportCount
int getTeleportCount() const
return the number of teleports (including collisions)
Definition: MSVehicleControl.cpp:491
MSVehicleControl::getMaxSpeedFactor
double getMaxSpeedFactor() const
return the maximum speed factor for all vehicles that ever entered the network
Definition: MSVehicleControl.h:503
MSVehicleControl::myEndedVehNo
int myEndedVehNo
The number of removed vehicles.
Definition: MSVehicleControl.h:540
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:441
MSVehicleControl::myDefaultBikeTypeMayBeDeleted
bool myDefaultBikeTypeMayBeDeleted
Whether the default bicycle type was already used or can still be replaced.
Definition: MSVehicleControl.h:609
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80