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  assert(exitOffset < 0);
116  }
117  virtual ~VehicleInfo() {};
119  std::string id;
121  std::string type;
123  double length;
125  double minGap;
127  std::string entryLaneID;
131  double entryOffset;
135  std::size_t currentOffsetIndex;
138  double exitOffset;
145 
151  double lastAccel;
153  double lastSpeed;
156  double lastPos;
157  };
158 
159  typedef std::map<std::string, VehicleInfo*> VehicleInfoMap;
160 
161 
162 private:
168  MoveNotificationInfo(std::string _vehID, double _oldPos, double _newPos, double _speed, double _accel, double _distToDetectorEnd, double _timeOnDetector, double _lengthOnDetector, double _timeLoss, bool _onDetector) :
169  id(_vehID),
170  oldPos(_oldPos),
171  newPos(_newPos),
172  speed(_speed),
173  accel(_accel),
174  distToDetectorEnd(_distToDetectorEnd),
175  timeOnDetector(_timeOnDetector),
176  lengthOnDetector(_lengthOnDetector),
177  timeLoss(_timeLoss),
178  onDetector(_onDetector) {}
179 
180  virtual ~MoveNotificationInfo() {};
181 
183  std::string id;
185  double oldPos;
187  double newPos;
189  double speed;
191  double accel;
199  double timeLoss;
202  };
203 
204 
205 
211  struct JamInfo {
213  std::vector<MoveNotificationInfo*>::const_iterator firstStandingVehicle;
214 
216  std::vector<MoveNotificationInfo*>::const_iterator lastStandingVehicle;
217  };
218 
219 
220 public:
221 
240  MSE2Collector(const std::string& id,
241  DetectorUsage usage, MSLane* lane, double startPos, double endPos, double length,
242  SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold,
243  const std::string& vTypes);
244 
245 
258  MSE2Collector(const std::string& id,
259  DetectorUsage usage, std::vector<MSLane*> lanes, double startPos, double endPos,
260  SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold,
261  const std::string& vTypes);
262 
263 
265  virtual ~MSE2Collector();
266 
272  virtual DetectorUsage getUsageType() const {
273  return myUsage;
274  }
275 
276 
277 
280 
298  virtual bool notifyMove(SUMOVehicle& veh, double oldPos, double newPos,
299  double newSpeed);
300 
301 
313  virtual bool notifyLeave(SUMOVehicle& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
314 
315 
328  virtual bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane);
330 
331 
332 
333 
334 
337 
346  virtual void detectorUpdate(const SUMOTime step);
347 
348 
355  virtual void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
356 
357 
366  virtual void writeXMLDetectorProlog(OutputDevice& dev) const;
367 
369 
370 
375  double getStartPos() const {
376  return myStartPos;
377  }
378 
379 
384  double getEndPos() const {
385  return myEndPos;
386  }
387 
392  double getLength() const {
393  return myDetectorLength;
394  }
395 
396 
401  MSLane* getLastLane() const {
402  return myLastLane;
403  }
404 
405 
408  std::vector<MSLane*> getLanes();
409 
416  virtual void reset();
417 
418 
421 
423  int getCurrentVehicleNumber() const;
424 
426  double getCurrentOccupancy() const {
427  return myCurrentOccupancy;
428  }
429 
431  double getCurrentMeanSpeed() const {
432  return myCurrentMeanSpeed;
433  }
434 
436  double getCurrentMeanLength() const {
437  return myCurrentMeanLength;
438  }
439 
441  int getCurrentJamNumber() const {
442  return myCurrentJamNo;
443  }
444 
448  }
449 
453  }
454 
458  }
459 
463  }
464 
467  return myCurrentStartedHalts;
468  }
469 
478  }
479 
484  std::vector<std::string> getCurrentVehicleIDs() const;
485 
488  std::vector<VehicleInfo*> getCurrentVehicles() const;
489 
494  int getPassedVeh() {
496  }
497 
502  void subtractPassedVeh(int passed) {
503  myNumberOfEnteredVehicles -= passed;
504  }
505 
507 
508 
509 
510 
511 
515 
516  int getEstimatedCurrentVehicleNumber(double speedThreshold) const;
517 
519  double getEstimateQueueLength() const;
521 
522 
523 
524 private:
525 
533  bool checkJam(std::vector<MoveNotificationInfo*>::const_iterator mni, std::map<std::string, SUMOTime>& haltingVehicles, std::map<std::string, SUMOTime>& intervalHaltingVehicles);
534 
535 
543  void buildJam(bool isInJam, std::vector<MoveNotificationInfo*>::const_iterator mni, JamInfo*& currentJam, std::vector<JamInfo*>& jams);
544 
545 
550  void processJams(std::vector<JamInfo*>& jams, JamInfo* currentJam);
551 
561  void calculateTimeLossAndTimeOnDetector(const SUMOVehicle& veh, double oldPos, double newPos, const VehicleInfo& vi, double& timeOnDetector, double& timeLoss) const;
562 
567  void initAuxiliaries(std::vector<MSLane*>& lanes);
568 
571  void checkPositioning(bool posGiven = false, double desiredLength = 0.);
572 
575  static double snap(double value, double snapPoint, double snapDist);
576 
580 
581 
582 
593  std::vector<MSLane*> selectLanes(MSLane* endLane, double length, std::string dir);
594 
595 
598  void addDetectorToLanes(std::vector<MSLane*>& lanes);
599 
600 
603  void aggregateOutputValues();
604 
605 
613 
623  MoveNotificationInfo* makeMoveNotification(const SUMOVehicle& veh, double oldPos, double newPos, double newSpeed, const VehicleInfo& vehInfo) const;
624 
631  VehicleInfo* makeVehicleInfo(const SUMOVehicle& veh, const MSLane* enteredLane) const;
632 
641  static double calculateSegmentTimeLoss(double timespan, double initialSpeed, double accel, double vmax);
642 
646  return mni1->distToDetectorEnd < mni2->distToDetectorEnd;
647  }
648 
649 
650 private:
651 
654 
658  std::vector<std::string> myLanes;
660  std::vector<double> myOffsets;
666  double myStartPos;
668  double myEndPos;
671 
679 
680 
684  VehicleInfoMap myVehicleInfos;
685 
688  std::vector<MoveNotificationInfo*> myMoveNotifications;
689 
693  std::set<std::string> myLeftVehicles;
694 
696  std::map<std::string, SUMOTime> myHaltingVehicleDurations;
697 
699  std::map<std::string, SUMOTime> myIntervalHaltingVehicleDurations;
700 
702  std::vector<SUMOTime> myPastStandingDurations;
703 
705  std::vector<SUMOTime> myPastIntervalStandingDurations;
707 
708 
709 
717  double mySpeedSum;
741 
742 
753 
775 
776 
777 private:
780 
783 };
784 
785 
786 #endif
787 
788 /****************************************************************************/
789 
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...
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
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< std::string > getCurrentVehicleIDs() const
Returns the IDs of the vehicles within the area.
double getEstimateQueueLength() const
Returns an estimate of the lenght of the queue of vehicles currently stopped on the detector...
double getEndPos() const
Returns the end position of the detector.
double getCurrentJamLengthInMeters() const
Returns the length of all jams in meters.
std::vector< MoveNotificationInfo * >::const_iterator firstStandingVehicle
The first standing vehicle.
std::vector< VehicleInfo * > getCurrentVehicles() const
Returns the VehicleInfos for the vehicles currently on the detector.
double myMeanMaxJamInMeters
The mean jam length [m].
bool onDetector
whether the vehicle is on the detector at the end of the current timestep
static bool compareMoveNotification(MoveNotificationInfo *mni1, MoveNotificationInfo *mni2)
double getCurrentMeanSpeed() const
Returns the mean vehicle speed of vehicles currently on the detector.
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 myMaxOccupancy
The maximum occupancy [%].
double lastSpeed
Last value of the speed.
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.
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...
bool onDetector
whether the vehicle is on the detector at the end of the current timestep
int getCurrentStartedHalts() const
Returns the length of all jams in meters.
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) ...
int getCurrentJamLengthInVehicles() const
Returns the length of all jams in vehicles.
std::vector< SUMOTime > myPastStandingDurations
Halting durations of ended halts [s].
double accel
Acceleration in the last integration step.
double getLength() const
Returns the length 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.
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.
double getCurrentOccupancy() const
Returns the current detector occupancy.
virtual DetectorUsage getUsageType() const
Returns the detector&#39;s usage type.
VehicleInfo * makeVehicleInfo(const SUMOVehicle &veh, const MSLane *enteredLane) const
Creates and returns a VehicleInfo (called at the vehicle&#39;s entry)
std::vector< MoveNotificationInfo * > myMoveNotifications
Temporal storage for notifications from vehicles that did call the detector&#39;s notifyMove() in the las...
double getCurrentMeanLength() const
Returns the mean vehicle length of vehicles currently on the detector.
void processJams(std::vector< JamInfo * > &jams, JamInfo *currentJam)
Calculates aggregated values from the given jam structure, deletes all jam-pointers.
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.
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].
const std::string & getID() const
Returns the id.
Definition: Named.h:66
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 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.
double getStartPos() const
Returns the begin position of the detector.
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.
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...
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 myNumberOfSeenVehicles
The number of vehicles, present on the detector at the last reset.
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
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...
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.
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...
int getCurrentVehicleNumber() const
Returns the number of vehicles currently on the detector.
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...
int getCurrentMaxJamLengthInVehicles() const
Returns the length in vehicles of the currently largest 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.
double getCurrentMaxJamLengthInMeters() const
Returns the length in meters of the currently largest jam.
void subtractPassedVeh(int passed)
Subtract the number of vehicles indicated from passed from the sensor count.
int getCurrentJamNumber() const
Returns the current number of jams.
std::string type
vehicle&#39;s type
void addDetectorToLanes(std::vector< MSLane * > &lanes)
This adds the detector as a MoveReminder to the associated lanes.
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.
int getPassedVeh()
Returns the number of vehicles passed over the sensor (i.e. entered the sensor)
virtual void reset()
Resets all values.
std::map< std::string, SUMOTime > myHaltingVehicleDurations
Storage for halting durations of known vehicles (for halting vehicles)
MSLane * getLastLane() const
Returns the id of the detector&#39;s last lane.
int myMaxJamInVehicles
The max jam length [#veh].
int myNumberOfLeftVehicles
The number of vehicles, which have left the detector since the last reset.
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
int getEstimatedCurrentVehicleNumber(double speedThreshold) const
Returns an estimate of the number of vehicles currently on the detector.
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.
double speed
Speed after the last integration step.
int getCurrentHaltingNumber() const
Returns the number of current haltings within the area.
std::set< std::string > myLeftVehicles
Keep track of vehicles that left the detector by a regular move along a junction (not lanechange...
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
int myNumberOfEnteredVehicles
Base of value-generating classes (detectors)
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Open the XML-output.
double length
vehicle&#39;s length