SUMO - Simulation of Urban MObility
MSE2Collector.h
Go to the documentation of this file.
1 /****************************************************************************/
13 // An areal detector covering to a sequence of consecutive lanes
14 /****************************************************************************/
15 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
16 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
17 /****************************************************************************/
18 //
19 // This file is part of SUMO.
20 // SUMO is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 /****************************************************************************/
26 #ifndef MSE2Collector_h
27 #define MSE2Collector_h
28 
29 
30 // ===========================================================================
31 // included modules
32 // ===========================================================================
33 #ifdef _MSC_VER
34 #include <windows_config.h>
35 #else
36 #include <config.h>
37 #endif
38 
39 #include <vector>
40 #include <list>
41 #include <microsim/MSLane.h>
42 #include <microsim/MSNet.h>
47 #include <cassert>
48 
49 // ===========================================================================
50 // class declarations
51 // ===========================================================================
52 class OutputDevice;
53 
54 
55 // ===========================================================================
56 // class definitions
57 // ===========================================================================
88 public:
93  struct VehicleInfo {
96  VehicleInfo(std::string id, std::string type, double length, double minGap, const MSLane* entryLane, double entryOffset,
97  std::size_t currentOffsetIndex, double exitOffset, double distToDetectorEnd, bool onDetector) :
98  id(id),
99  type(type),
100  length(length),
101  minGap(minGap),
102  entryLaneID(entryLane->getID()),
103  entryOffset(entryOffset),
104  currentLane(entryLane),
105  currentOffsetIndex(currentOffsetIndex),
106  exitOffset(exitOffset),
107  distToDetectorEnd(distToDetectorEnd),
110  onDetector(onDetector),
111  hasEntered(false),
112  lastAccel(0),
113  lastSpeed(0),
114  lastPos(0) {
115  }
116  virtual ~VehicleInfo() {};
118  std::string id;
120  std::string type;
122  double length;
124  double minGap;
126  std::string entryLaneID;
130  double entryOffset;
134  std::size_t currentOffsetIndex;
137  double exitOffset;
144 
150  double lastAccel;
152  double lastSpeed;
155  double lastPos;
156  };
157 
158  typedef std::map<std::string, VehicleInfo*> VehicleInfoMap;
159 
160 
161 private:
167  MoveNotificationInfo(std::string _vehID, double _oldPos, double _newPos, double _speed, double _accel, double _distToDetectorEnd, double _timeOnDetector, double _lengthOnDetector, double _timeLoss, bool _onDetector) :
168  id(_vehID),
169  oldPos(_oldPos),
170  newPos(_newPos),
171  speed(_speed),
172  accel(_accel),
173  distToDetectorEnd(_distToDetectorEnd),
174  timeOnDetector(_timeOnDetector),
175  lengthOnDetector(_lengthOnDetector),
176  timeLoss(_timeLoss),
177  onDetector(_onDetector) {}
178 
179  virtual ~MoveNotificationInfo() {};
180 
182  std::string id;
184  double oldPos;
186  double newPos;
188  double speed;
190  double accel;
198  double timeLoss;
201  };
202 
203 
204 
210  struct JamInfo {
212  std::vector<MoveNotificationInfo*>::const_iterator firstStandingVehicle;
213 
215  std::vector<MoveNotificationInfo*>::const_iterator lastStandingVehicle;
216  };
217 
218 
219 public:
220 
239  MSE2Collector(const std::string& id,
240  DetectorUsage usage, MSLane* lane, double startPos, double endPos, double length,
241  SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold,
242  const std::string& vTypes);
243 
244 
257  MSE2Collector(const std::string& id,
258  DetectorUsage usage, std::vector<MSLane*> lanes, double startPos, double endPos,
259  SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold,
260  const std::string& vTypes);
261 
262 
264  virtual ~MSE2Collector();
265 
271  virtual DetectorUsage getUsageType() const {
272  return myUsage;
273  }
274 
275 
276 
279 
297  virtual bool notifyMove(SUMOVehicle& veh, double oldPos, double newPos,
298  double newSpeed);
299 
300 
312  virtual bool notifyLeave(SUMOVehicle& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
313 
314 
327  virtual bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane);
329 
330 
331 
332 
333 
336 
345  virtual void detectorUpdate(const SUMOTime step);
346 
347 
354  virtual void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
355 
356 
365  virtual void writeXMLDetectorProlog(OutputDevice& dev) const;
366 
368 
369 
374  double getStartPos() const {
375  return myStartPos;
376  }
377 
378 
383  double getEndPos() const {
384  return myEndPos;
385  }
386 
391  double getLength() const {
392  return myDetectorLength;
393  }
394 
395 
400  MSLane* getLastLane() const {
401  return myLastLane;
402  }
403 
404 
407  std::vector<MSLane*> getLanes();
408 
415  virtual void reset();
416 
417 
420 
422  int getCurrentVehicleNumber() const;
423 
425  double getCurrentOccupancy() const {
426  return myCurrentOccupancy;
427  }
428 
430  double getCurrentMeanSpeed() const {
431  return myCurrentMeanSpeed;
432  }
433 
435  double getCurrentMeanLength() const {
436  return myCurrentMeanLength;
437  }
438 
440  int getCurrentJamNumber() const {
441  return myCurrentJamNo;
442  }
443 
447  }
448 
452  }
453 
457  }
458 
462  }
463 
466  return myCurrentStartedHalts;
467  }
468 
477  }
478 
483  std::vector<std::string> getCurrentVehicleIDs() const;
484 
487  std::vector<VehicleInfo*> getCurrentVehicles() const;
488 
493  int getPassedVeh() {
495  }
496 
501  void subtractPassedVeh(int passed) {
502  myNumberOfEnteredVehicles -= passed;
503  }
504 
506 
507 
508 
509 
510 
514 
515  int getEstimatedCurrentVehicleNumber(double speedThreshold) const;
516 
518  double getEstimateQueueLength() const;
520 
521 
522 
523 private:
524 
532  bool checkJam(std::vector<MoveNotificationInfo*>::const_iterator mni, std::map<std::string, SUMOTime>& haltingVehicles, std::map<std::string, SUMOTime>& intervalHaltingVehicles);
533 
534 
542  void buildJam(bool isInJam, std::vector<MoveNotificationInfo*>::const_iterator mni, JamInfo*& currentJam, std::vector<JamInfo*>& jams);
543 
544 
549  void processJams(std::vector<JamInfo*>& jams, JamInfo* currentJam);
550 
560  void calculateTimeLossAndTimeOnDetector(const SUMOVehicle& veh, double oldPos, double newPos, const VehicleInfo& vi, double& timeOnDetector, double& timeLoss) const;
561 
566  void initAuxiliaries(std::vector<MSLane*>& lanes);
567 
570  void checkPositioning(bool posGiven = false, double desiredLength = 0.);
571 
574  static double snap(double value, double snapPoint, double snapDist);
575 
579 
580 
581 
592  std::vector<MSLane*> selectLanes(MSLane* endLane, double length, std::string dir);
593 
594 
597  void addDetectorToLanes(std::vector<MSLane*>& lanes);
598 
599 
602  void aggregateOutputValues();
603 
604 
612 
622  MoveNotificationInfo* makeMoveNotification(const SUMOVehicle& veh, double oldPos, double newPos, double newSpeed, const VehicleInfo& vehInfo) const;
623 
630  VehicleInfo* makeVehicleInfo(const SUMOVehicle& veh, const MSLane* enteredLane) const;
631 
640  static double calculateSegmentTimeLoss(double timespan, double initialSpeed, double accel, double vmax);
641 
645  return mni1->distToDetectorEnd < mni2->distToDetectorEnd;
646  }
647 
648 
649 private:
650 
653 
657  std::vector<std::string> myLanes;
659  std::vector<double> myOffsets;
665  double myStartPos;
667  double myEndPos;
670 
678 
679 
683  VehicleInfoMap myVehicleInfos;
684 
687  std::vector<MoveNotificationInfo*> myMoveNotifications;
688 
692  std::set<std::string> myLeftVehicles;
693 
695  std::map<std::string, SUMOTime> myHaltingVehicleDurations;
696 
698  std::map<std::string, SUMOTime> myIntervalHaltingVehicleDurations;
699 
701  std::vector<SUMOTime> myPastStandingDurations;
702 
704  std::vector<SUMOTime> myPastIntervalStandingDurations;
706 
707 
708 
718  double mySpeedSum;
742 
743 
750 
772 
773 
774 private:
777 
780 };
781 
782 
783 #endif
784 
785 /****************************************************************************/
786 
std::vector< double > myOffsets
The distances of the lane-beginnings from the detector start-point.
int myMaxVehicleNumber
The maximal number of vehicles located on the detector simultaneously since the last reset...
int myMeanMaxJamInVehicles
The mean jam length [#veh].
double lastAccel
Last value of the acceleration.
std::vector< SUMOTime > myPastIntervalStandingDurations
Halting durations of ended halts for the current interval [s].
std::vector< MoveNotificationInfo * >::const_iterator firstStandingVehicle
The first standing vehicle.
double myMeanMaxJamInMeters
The mean jam length [m].
void addDetectorToLanes(std::vector< MSLane *> &lanes)
This adds the detector as a MoveReminder to the associated lanes.
std::vector< std::string > getCurrentVehicleIDs() const
Returns the IDs of the vehicles within the area.
bool onDetector
whether the vehicle is on the detector at the end of the current timestep
static bool compareMoveNotification(MoveNotificationInfo *mni1, MoveNotificationInfo *mni2)
double myMaxOccupancy
The maximum occupancy [%].
double lastSpeed
Last value of the speed.
int getCurrentJamLengthInVehicles() const
Returns the length of all jams in vehicles.
virtual ~MSE2Collector()
Destructor.
An areal detector corresponding to a sequence of consecutive lanes.
Definition: MSE2Collector.h:87
MSE2Collector(const std::string &id, DetectorUsage usage, MSLane *lane, double startPos, double endPos, double length, SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold, const std::string &vTypes)
Constructor with given end position and detector length.
Internal representation of a jam.
int myCurrentMaxJamLengthInVehicles
The current maximum jam length in vehicles.
bool onDetector
whether the vehicle is on the detector at the end of the current timestep
double getEndPos() const
Returns the end position of the detector.
Values collected in notifyMove and needed in detectorUpdate() to calculate the accumulated quantities...
double lengthOnDetector
The length of the part of the vehicle on the detector at the end of the last time step...
double myTotalTimeLoss
The total amount of all time losses [time x vehicle] since the last reset.
Notification
Definition of a vehicle state.
double myVehicleSamples
double timeOnDetector
Time spent on the detector during the last integration step.
double newPos
Position after the last integration step (relative to the vehicle&#39;s entry lane on the detector) ...
double getLength() const
Returns the length of the detector.
std::vector< SUMOTime > myPastStandingDurations
Halting durations of ended halts [s].
double accel
Acceleration in the last integration step.
double getStartPos() const
Returns the begin position of the detector.
int myMeanVehicleNumber
The mean number of vehicles [#veh].
virtual bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane)
Adds the vehicle to known vehicles if not beyond the dector.
const std::string & getID() const
Returns the id.
Definition: Named.h:66
double totalTimeOnDetector
Accumulated time that this vehicle has spent on the detector since its last entry.
int myCurrentStartedHalts
The number of started halts in the last step.
std::size_t currentOffsetIndex
Index of currentLane in the detector&#39;s myLanes vector.
std::vector< VehicleInfo * > getCurrentVehicles() const
Returns the VehicleInfos for the vehicles currently on the detector.
std::vector< MoveNotificationInfo * > myMoveNotifications
Temporal storage for notifications from vehicles that did call the detector&#39;s notifyMove() in the las...
void initAuxiliaries(std::vector< MSLane *> &lanes)
Checks integrity of myLanes, adds internal-lane information, inits myLength, myFirstLane, myLastLane, myOffsets Called once at construction. myLanes should form a continuous sequence.
void aggregateOutputValues()
Aggregates and normalize some values for the detector output during detectorUpdate() ...
double myJamHaltingSpeedThreshold
A vehicle must driver slower than this to be counted as a part of a jam.
VehicleInfo * makeVehicleInfo(const SUMOVehicle &veh, const MSLane *enteredLane) const
Creates and returns a VehicleInfo (called at the vehicle&#39;s entry)
std::vector< std::string > myLanes
double mySpeedSum
The sum of collected vehicle speeds [m/s].
double minGap
vehicle&#39;s minGap
std::vector< MoveNotificationInfo * >::const_iterator lastStandingVehicle
The last standing vehicle.
void checkPositioning(bool posGiven=false, double desiredLength=0.)
Adjusts positioning if the detector length is less than POSITION_EPS and tests some assertions...
void recalculateDetectorLength()
Updates the detector length after myStartPos and myEndPos have been modified.
double myJamDistanceThreshold
Two standing vehicles must be closer than this to be counted into the same jam.
int myTimeSamples
The current aggregation duration [#steps].
int getCurrentMaxJamLengthInVehicles() const
Returns the length in vehicles of the currently largest jam.
A VehicleInfo stores values that are tracked for the individual vehicles on the detector, e.g., accumulated timeloss. These infos are stored in myVehicles. If a vehicle leaves the detector (may it be temporarily), the entry in myVehicles is discarded, i.e. all information on the vehicle is reset.
Definition: MSE2Collector.h:93
double getCurrentMeanSpeed() const
Returns the mean vehicle speed of vehicles currently on the detector.
double myCurrentMeanLength
The current mean length.
static double snap(double value, double snapPoint, double snapDist)
Snaps value to snpPoint if they are closer than snapDist.
MSE2Collector & operator=(const MSE2Collector &)
Invalidated assignment operator.
VehicleInfo(std::string id, std::string type, double length, double minGap, const MSLane *entryLane, double entryOffset, std::size_t currentOffsetIndex, double exitOffset, double distToDetectorEnd, bool onDetector)
Definition: MSE2Collector.h:96
int myCurrentJamLengthInVehicles
The overall jam length in vehicles.
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Open the XML-output.
Representation of a vehicle.
Definition: SUMOVehicle.h:67
double oldPos
Position before the last integration step (relative to the vehicle&#39;s entry lane on the detector) ...
int myJamLengthInVehiclesSum
The sum of jam lengths [#veh].
double myStartedHalts
The number of started halts [#].
double distToDetectorEnd
Distance left till the detector end after the last integration step (may become negative if the vehic...
std::vector< MSLane * > selectLanes(MSLane *endLane, double length, std::string dir)
This is called if no lane sequence is given to the constructor. Builds myLanes from the given informa...
double myJamLengthInMetersSum
The sum of jam lengths [m].
double myMaxJamInMeters
The max jam length [m].
MSLane * myFirstLane
The first lane of the detector&#39;s lane sequence.
std::string id
vehicle&#39;s ID
int getCurrentJamNumber() const
Returns the current number of jams.
double myDetectorLength
The total detector length.
std::vector< MSLane * > getLanes()
Returns a vector containing pointers to the lanes covered by the detector ordered from its first to i...
virtual bool notifyLeave(SUMOVehicle &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Removes a known vehicle due to its lane-change.
double myCurrentMeanSpeed
The current mean speed.
std::map< std::string, VehicleInfo * > VehicleInfoMap
int myCurrentJamNo
The current jam number.
const MSLane * currentLane
Lane, on which the vehicle currently resides (always the one for which the last notifyEnter was recei...
void processJams(std::vector< JamInfo *> &jams, JamInfo *currentJam)
Calculates aggregated values from the given jam structure, deletes all jam-pointers.
int getCurrentHaltingNumber() const
Returns the number of current haltings within the area.
Something on a lane to be noticed about vehicle movement.
std::map< std::string, SUMOTime > myIntervalHaltingVehicleDurations
Storage for halting durations of known vehicles (current interval)
MoveNotificationInfo(std::string _vehID, double _oldPos, double _newPos, double _speed, double _accel, double _distToDetectorEnd, double _timeOnDetector, double _lengthOnDetector, double _timeLoss, bool _onDetector)
double myCurrentMaxJamLengthInMeters
the current maximum jam length in meters
double myEndPos
The position the detector ends at on the last lane.
MSLane * myLastLane
The last lane of the detector&#39;s lane sequence.
SUMOTime myJamHaltingTimeThreshold
A vehicle must be that long beyond myJamHaltingSpeedThreshold to be counted as a part of a jam...
bool checkJam(std::vector< MoveNotificationInfo *>::const_iterator mni, std::map< std::string, SUMOTime > &haltingVehicles, std::map< std::string, SUMOTime > &intervalHaltingVehicles)
checks whether the vehicle stands in a jam
VehicleInfoMap myVehicleInfos
double accumulatedTimeLoss
Accumulated time loss that this vehicle suffered since it entered the detector.
bool hasEntered
Whether the vehicle has already entered the detector (don&#39;t count twice!)
double myStartPos
The position the detector starts at on the first lane.
virtual void detectorUpdate(const SUMOTime step)
Computes the detector values in each time step.
MSLane * getLastLane() const
Returns the id of the detector&#39;s last lane.
void subtractPassedVeh(int passed)
Subtract the number of vehicles indicated from passed from the sensor count.
int getEstimatedCurrentVehicleNumber(double speedThreshold) const
Returns an estimate of the number of vehicles currently on the detector.
std::string type
vehicle&#39;s type
double getCurrentJamLengthInMeters() const
Returns the length of all jams in meters.
virtual void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Write the generated output to the given device.
DetectorUsage myUsage
Information about how this detector is used.
std::string entryLaneID
ID of the lane, on which the vehicle entered the detector.
double getCurrentMaxJamLengthInMeters() const
Returns the length in meters of the currently largest jam.
int getPassedVeh()
Returns the number of vehicles passed over the sensor (i.e. entered the sensor)
virtual void reset()
Resets all values.
void calculateTimeLossAndTimeOnDetector(const SUMOVehicle &veh, double oldPos, double newPos, const VehicleInfo &vi, double &timeOnDetector, double &timeLoss) const
Calculates the time spent on the detector in the last step and the timeloss suffered in the last step...
int getCurrentStartedHalts() const
Returns the length of all jams in meters.
std::map< std::string, SUMOTime > myHaltingVehicleDurations
Storage for halting durations of known vehicles (for halting vehicles)
virtual DetectorUsage getUsageType() const
Returns the detector&#39;s usage type.
int myMaxJamInVehicles
The max jam length [#veh].
int myNumberOfLeftVehicles
double distToDetectorEnd
Distance left till the detector end after the last integration step (may become negative if the vehic...
double myOccupancySum
The sum of occupancies [%].
void integrateMoveNotification(VehicleInfo *vi, const MoveNotificationInfo *mni)
This updates the detector values and the VehicleInfo of a vehicle on the detector with the given Move...
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
double myCurrentJamLengthInMeters
The overall jam length in meters.
int myCurrentHaltingsNumber
The number of halted vehicles [#].
long long int SUMOTime
Definition: TraCIDefs.h:52
void buildJam(bool isInJam, std::vector< MoveNotificationInfo *>::const_iterator mni, JamInfo *&currentJam, std::vector< JamInfo *> &jams)
Either adds the vehicle to the end of an existing jam, or closes the last jam, and/or creates a new j...
static double calculateSegmentTimeLoss(double timespan, double initialSpeed, double accel, double vmax)
Calculates the time loss for a segment with constant vmax.
double timeLoss
timeloss during the last integration step
virtual bool notifyMove(SUMOVehicle &veh, double oldPos, double newPos, double newSpeed)
Adds/removes vehicles from the list of vehicles to regard.
double myCurrentOccupancy
The current occupancy.
MoveNotificationInfo * makeMoveNotification(const SUMOVehicle &veh, double oldPos, double newPos, double newSpeed, const VehicleInfo &vehInfo) const
Creates and returns a MoveNotificationInfo containing detector specific information on the vehicle&#39;s ...
double speed
Speed after the last integration step.
std::set< std::string > myLeftVehicles
Keep track of vehicles that left the detector by a regular move along a junction (not lanechange...
double getCurrentMeanLength() const
Returns the mean vehicle length of vehicles currently on the detector.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
double getCurrentOccupancy() const
Returns the current detector occupancy.
int myNumberOfEnteredVehicles
The number of vehicles, which have entered the detector since the last reset.
Base of value-generating classes (detectors)
double getEstimateQueueLength() const
Returns an estimate of the lenght of the queue of vehicles currently stopped on the detector...
int getCurrentVehicleNumber() const
Returns the number of vehicles currently on the detector.
double length
vehicle&#39;s length