Eclipse SUMO - Simulation of Urban MObility
MSE2Collector.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 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 /****************************************************************************/
24 // An areal detector covering to a sequence of consecutive lanes
25 /****************************************************************************/
26 #pragma once
27 #include <config.h>
28 
29 #include <vector>
30 #include <list>
31 #include <microsim/MSLane.h>
32 #include <microsim/MSNet.h>
36 #include <cassert>
37 
38 
39 // ===========================================================================
40 // class declarations
41 // ===========================================================================
42 class OutputDevice;
43 class SUMOVehicle;
44 class SUMOTrafficObject;
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
80 public:
85  struct VehicleInfo {
88  VehicleInfo(std::string id, std::string type, double length, double minGap, const MSLane* entryLane, double entryOffset,
89  std::size_t currentOffsetIndex, double exitOffset, double distToDetectorEnd, bool onDetector) :
90  id(id),
91  type(type),
92  length(length),
93  minGap(minGap),
94  entryLaneID(entryLane->getID()),
96  currentLane(entryLane),
103  hasEntered(false),
104  lastAccel(0),
105  lastSpeed(0),
106  lastPos(0) {
107  assert(exitOffset < 0);
108  }
109  virtual ~VehicleInfo() {};
111  std::string id;
113  std::string type;
115  double length;
117  double minGap;
119  std::string entryLaneID;
123  double entryOffset;
127  std::size_t currentOffsetIndex;
130  double exitOffset;
137 
143  double lastAccel;
145  double lastSpeed;
148  double lastPos;
149  };
150 
151  typedef std::map<std::string, VehicleInfo*> VehicleInfoMap;
152 
153 
154 private:
160  MoveNotificationInfo(std::string _vehID, double _oldPos, double _newPos, double _speed, double _accel, double _distToDetectorEnd, double _timeOnDetector, double _lengthOnDetector, double _timeLoss, bool _onDetector) :
161  id(_vehID),
162  oldPos(_oldPos),
163  newPos(_newPos),
164  speed(_speed),
165  accel(_accel),
166  distToDetectorEnd(_distToDetectorEnd),
167  timeOnDetector(_timeOnDetector),
168  lengthOnDetector(_lengthOnDetector),
169  timeLoss(_timeLoss),
170  onDetector(_onDetector) {}
171 
172  virtual ~MoveNotificationInfo() {};
173 
175  std::string id;
177  double oldPos;
179  double newPos;
181  double speed;
183  double accel;
191  double timeLoss;
194  };
195 
196 
197 
203  struct JamInfo {
205  std::vector<MoveNotificationInfo*>::const_iterator firstStandingVehicle;
206 
208  std::vector<MoveNotificationInfo*>::const_iterator lastStandingVehicle;
209  };
210 
211 
212 public:
213 
232  MSE2Collector(const std::string& id,
233  DetectorUsage usage, MSLane* lane, double startPos, double endPos, double length,
234  SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold,
235  const std::string name, const std::string& vTypes,
236  const std::string& nextEdges,
237  int detectPersons);
238 
239 
252  MSE2Collector(const std::string& id,
253  DetectorUsage usage, std::vector<MSLane*> lanes, double startPos, double endPos,
254  SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold,
255  const std::string name, const std::string& vTypes,
256  const std::string& nextEdges,
257  int detectPersons);
258 
259 
261  virtual ~MSE2Collector();
262 
268  virtual DetectorUsage getUsageType() const {
269  return myUsage;
270  }
271 
272 
273 
276 
294  virtual bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos,
295  double newSpeed);
296 
297 
309  virtual bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
310 
311 
324  virtual bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane);
326 
327 
328 
329 
330 
333 
342  virtual void detectorUpdate(const SUMOTime step);
343 
344 
351  virtual void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
352 
353 
362  virtual void writeXMLDetectorProlog(OutputDevice& dev) const;
363 
365 
367  const std::string& getName() {
368  return myName;
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 
511 
512  double getIntervalOccupancy() const {
513  return myTimeSamples != 0 ? myOccupancySum / (double) myTimeSamples : 0;
514  }
515  double getIntervalMeanSpeed() const {
516  return myVehicleSamples != 0 ? mySpeedSum / myVehicleSamples : -1;
517  }
519  return myMaxJamInMeters;
520  }
522  return myNumberOfSeenVehicles;
523  }
524 
525  double getLastIntervalOccupancy() const {
527  }
528  double getLastIntervalMeanSpeed() const {
529  return myPreviousMeanSpeed;
530  }
533  }
536  }
537 
539 
540 
544 
545  int getEstimatedCurrentVehicleNumber(double speedThreshold) const;
546 
548  double getEstimateQueueLength() const;
550 
551 
552  virtual void setVisible(bool /*show*/) {};
553 
555  virtual void clearState(SUMOTime step);
556 
560  void overrideVehicleNumber(int num);
561 
562  double getOverrideVehNumber() const {
563  return myOverrideVehNumber;
564  }
565 private:
566 
574  bool checkJam(std::vector<MoveNotificationInfo*>::const_iterator mni, std::map<std::string, SUMOTime>& haltingVehicles, std::map<std::string, SUMOTime>& intervalHaltingVehicles);
575 
576 
584  void buildJam(bool isInJam, std::vector<MoveNotificationInfo*>::const_iterator mni, JamInfo*& currentJam, std::vector<JamInfo*>& jams);
585 
586 
591  void processJams(std::vector<JamInfo*>& jams, JamInfo* currentJam);
592 
602  void calculateTimeLossAndTimeOnDetector(const SUMOTrafficObject& veh, double oldPos, double newPos, const VehicleInfo& vi, double& timeOnDetector, double& timeLoss) const;
603 
608  void initAuxiliaries(std::vector<MSLane*>& lanes);
609 
612  void checkPositioning(bool posGiven = false, double desiredLength = 0.);
613 
616  static double snap(double value, double snapPoint, double snapDist);
617 
621 
622 
623 
634  std::vector<MSLane*> selectLanes(MSLane* endLane, double length, std::string dir);
635 
636 
639  void addDetectorToLanes(std::vector<MSLane*>& lanes);
640 
641 
644  void aggregateOutputValues();
645 
646 
653  void integrateMoveNotification(VehicleInfo* vi, const MoveNotificationInfo* mni);
654 
664  MoveNotificationInfo* makeMoveNotification(const SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed, const VehicleInfo& vehInfo) const;
665 
672  VehicleInfo* makeVehicleInfo(const SUMOTrafficObject& veh, const MSLane* enteredLane) const;
673 
682  static double calculateSegmentTimeLoss(double timespan, double initialSpeed, double accel, double vmax);
683 
687  return mni1->distToDetectorEnd < mni2->distToDetectorEnd;
688  }
689 
690  void notifyMovePerson(MSTransportable* p, int dir, double pos);
691 
692 private:
693 
696 
700  const std::string myName;
702  std::vector<std::string> myLanes;
704  std::vector<double> myOffsets;
710  double myStartPos;
712  double myEndPos;
715 
723 
724 
729 
732  std::vector<MoveNotificationInfo*> myMoveNotifications;
733 
737  std::set<std::string> myLeftVehicles;
738 
740  std::map<std::string, SUMOTime> myHaltingVehicleDurations;
741 
743  std::map<std::string, SUMOTime> myIntervalHaltingVehicleDurations;
744 
746  std::vector<SUMOTime> myPastStandingDurations;
747 
749  std::vector<SUMOTime> myPastIntervalStandingDurations;
751 
752 
753 
761  double mySpeedSum;
785 
786 
797 
821 
829 
832 
833 private:
836 
839 };
long long int SUMOTime
Definition: GUI.h:35
Base of value-generating classes (detectors)
An areal detector corresponding to a sequence of consecutive lanes.
Definition: MSE2Collector.h:79
void checkPositioning(bool posGiven=false, double desiredLength=0.)
Adjusts positioning if the detector length is less than POSITION_EPS and tests some assertions.
void notifyMovePerson(MSTransportable *p, int dir, double pos)
double myCurrentMaxJamLengthInMeters
the current maximum jam length in meters
VehicleInfo * makeVehicleInfo(const SUMOTrafficObject &veh, const MSLane *enteredLane) const
Creates and returns a VehicleInfo (called at the vehicle's entry)
double myVehicleSamples
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
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...
std::map< std::string, SUMOTime > myHaltingVehicleDurations
Storage for halting durations of known vehicles (for halting vehicles)
int myJamLengthInVehiclesSum
The sum of jam lengths [#veh].
MSLane * getLastLane() const
Returns the id of the detector's last lane.
int myMeanVehicleNumber
The mean number of vehicles [#veh].
int myCurrentStartedHalts
The number of started halts in the last step.
int myTimeSamples
The current aggregation duration [#steps].
static bool compareMoveNotification(MoveNotificationInfo *mni1, MoveNotificationInfo *mni2)
int myNumberOfSeenVehicles
The number of vehicles, present on the detector at the last reset.
int myCurrentMaxJamLengthInVehicles
The current maximum jam length in vehicles.
std::vector< MSLane * > getLanes()
Returns a vector containing pointers to the lanes covered by the detector ordered from its first to i...
int myNumberOfLeftVehicles
The number of vehicles, which have left the detector since the last reset.
std::vector< SUMOTime > myPastStandingDurations
Halting durations of ended halts [s].
void processJams(std::vector< JamInfo * > &jams, JamInfo *currentJam)
Calculates aggregated values from the given jam structure, deletes all jam-pointers.
std::vector< double > myOffsets
The distances of the lane-beginnings from the detector start-point.
double getCurrentMaxJamLengthInMeters() const
Returns the length in meters of the currently largest jam.
double getIntervalMaxJamLengthInMeters() const
double myPreviousMeanSpeed
int myMaxJamInVehicles
The max jam length [#veh].
virtual void reset()
Resets all values.
virtual bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Adds/removes vehicles from the list of vehicles to regard.
std::vector< VehicleInfo * > getCurrentVehicles() const
Returns the VehicleInfos for the vehicles currently on the detector.
MSE2Collector & operator=(const MSE2Collector &)
Invalidated assignment operator.
virtual void setVisible(bool)
double getStartPos() const
Returns the begin position of the detector.
double myPreviousMaxJamLengthInMeters
double myJamHaltingSpeedThreshold
A vehicle must driver slower than this to be counted as a part of a jam.
DetectorUsage myUsage
Information about how this detector is used.
virtual bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane)
Adds the vehicle to known vehicles if not beyond the dector.
VehicleInfoMap myVehicleInfos
int myNumberOfEnteredVehicles
static double snap(double value, double snapPoint, double snapDist)
Snaps value to snpPoint if they are closer than snapDist.
void initAuxiliaries(std::vector< MSLane * > &lanes)
Checks integrity of myLanes, adds internal-lane information, inits myLength, myFirstLane,...
MSLane * myFirstLane
The first lane of the detector's lane sequence.
double getLastIntervalOccupancy() const
std::vector< std::string > getCurrentVehicleIDs() const
Returns the IDs of the vehicles within the area.
double getCurrentMeanLength() const
Returns the mean vehicle length 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 mySpeedSum
The sum of collected vehicle speeds [m/s].
std::set< std::string > myLeftVehicles
Keep track of vehicles that left the detector by a regular move along a junction (not lanechange,...
double getIntervalMeanSpeed() const
int getCurrentMaxJamLengthInVehicles() const
Returns the length in vehicles of the currently largest jam.
double myEndPos
The position the detector ends at on the last lane.
int myPreviousNumberOfSeenVehicles
double getLastIntervalMeanSpeed() const
double myDetectorLength
The total detector length.
virtual DetectorUsage getUsageType() const
Returns the detector's usage type.
double getOverrideVehNumber() const
virtual void clearState(SUMOTime step)
Remove all vehicles before quick-loading state.
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...
int getCurrentVehicleNumber() const
Returns the number of vehicles currently on the detector.
double myCurrentMeanSpeed
The current mean speed.
double myStartPos
The position the detector starts at on the first lane.
std::vector< MoveNotificationInfo * > myMoveNotifications
Temporal storage for notifications from vehicles that did call the detector's notifyMove() in the las...
void addDetectorToLanes(std::vector< MSLane * > &lanes)
This adds the detector as a MoveReminder to the associated lanes.
SUMOTime myJamHaltingTimeThreshold
A vehicle must be that long beyond myJamHaltingSpeedThreshold to be counted as a part of a jam.
int myMaxVehicleNumber
The maximal number of vehicles located on the detector simultaneously since the last reset.
void recalculateDetectorLength()
Updates the detector length after myStartPos and myEndPos have been modified.
double myMaxOccupancy
The maximum occupancy [%].
int getCurrentJamLengthInVehicles() const
Returns the length of all jams in vehicles.
double myPreviousMeanOccupancy
virtual void detectorUpdate(const SUMOTime step)
Computes the detector values in each time step.
int myCurrentJamNo
The current jam number.
double myCurrentVehicleSamples
The current vehicle samples.
int getCurrentStartedHalts() const
Returns the length of all jams in meters.
std::map< std::string, VehicleInfo * > VehicleInfoMap
MSE2Collector(const std::string &id, DetectorUsage usage, MSLane *lane, double startPos, double endPos, double length, SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold, const std::string name, const std::string &vTypes, const std::string &nextEdges, int detectPersons)
Constructor with given end position and detector length.
virtual bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Removes a known vehicle due to its lane-change.
int getCurrentHaltingNumber() const
Returns the number of current haltings within the area.
double myStartedHalts
The number of started halts [#].
double getEstimateQueueLength() const
Returns an estimate of the length of the queue of vehicles currently stopped on the detector.
virtual void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Write the generated output to the given device.
double myMeanMaxJamInMeters
The mean jam length [m].
int myOverrideVehNumber
stores the overriden (via Traci) number of vehicles on detector
double myCurrentJamLengthInMeters
The overall jam length in meters.
double myCurrentMeanLength
The current mean length.
double getEndPos() const
Returns the end position of the detector.
double myMaxJamInMeters
The max jam length [m].
int getIntervalVehicleNumber() const
std::vector< std::string > myLanes
The detector's lane sequence.
int myMeanMaxJamInVehicles
The mean jam length [#veh].
int myCurrentJamLengthInVehicles
The overall jam length in vehicles.
void calculateTimeLossAndTimeOnDetector(const SUMOTrafficObject &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...
double myJamLengthInMetersSum
The sum of jam lengths [m].
double myJamDistanceThreshold
Two standing vehicles must be closer than this to be counted into the same jam.
void subtractPassedVeh(int passed)
Subtract the number of vehicles indicated from passed from the sensor count.
const std::string & getName()
get name
int getEstimatedCurrentVehicleNumber(double speedThreshold) const
Returns an estimate of the number of vehicles currently on the detector.
double getLength() const
Returns the length of the detector.
double getCurrentMeanSpeed() const
Returns the mean vehicle speed of vehicles currently on the detector.
std::vector< SUMOTime > myPastIntervalStandingDurations
Halting durations of ended halts for the current interval [s].
virtual ~MSE2Collector()
Destructor.
const std::string myName
MSLane * myLastLane
The last lane of the detector's lane sequence.
void overrideVehicleNumber(int num)
Persistently overrides the number of vehicles on top of the detector Setting a negative value removes...
double myCurrentOccupancy
The current occupancy.
double getCurrentJamLengthInMeters() const
Returns the length of all jams in meters.
double getIntervalOccupancy() const
double getLastIntervalMaxJamLengthInMeters() const
double myOccupancySum
The sum of occupancies [%].
int myCurrentHaltingsNumber
The number of halted vehicles [#].
int getCurrentJamNumber() const
Returns the current number of jams.
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Open the XML-output.
int getPassedVeh()
Returns the number of vehicles passed over the sensor (i.e. entered the sensor)
double myTotalTimeLoss
The total amount of all time losses [time x vehicle] since the last reset.
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...
std::map< std::string, SUMOTime > myIntervalHaltingVehicleDurations
Storage for halting durations of known vehicles (current interval)
MoveNotificationInfo * makeMoveNotification(const SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed, const VehicleInfo &vehInfo) const
Creates and returns a MoveNotificationInfo containing detector specific information on the vehicle's ...
double getCurrentOccupancy() const
Returns the current detector occupancy.
MSE2Collector(const MSE2Collector &)
Invalidated copy constructor.
void aggregateOutputValues()
Aggregates and normalize some values for the detector output during detectorUpdate()
int getLastIntervalVehicleNumber() const
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
const std::string & getID() const
Returns the id.
Definition: Named.h:74
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
Internal representation of a jam.
std::vector< MoveNotificationInfo * >::const_iterator lastStandingVehicle
The last standing vehicle.
std::vector< MoveNotificationInfo * >::const_iterator firstStandingVehicle
The first standing vehicle.
Values collected in notifyMove and needed in detectorUpdate() to calculate the accumulated quantities...
double oldPos
Position before the last integration step (relative to the vehicle's entry lane on the detector)
double speed
Speed after the last integration step.
double newPos
Position after the last integration step (relative to the vehicle's entry lane on the detector)
double distToDetectorEnd
Distance left till the detector end after the last integration step (may become negative if the vehic...
double accel
Acceleration in the last integration step.
double timeLoss
timeloss during the last integration step
double timeOnDetector
Time spent on the detector during the last integration step.
double lengthOnDetector
The length of the part of the vehicle on the detector at the end of the last time step.
bool onDetector
whether the vehicle is on the detector at the end of the current timestep
std::string id
Vehicle's id.
MoveNotificationInfo(std::string _vehID, double _oldPos, double _newPos, double _speed, double _accel, double _distToDetectorEnd, double _timeOnDetector, double _lengthOnDetector, double _timeLoss, bool _onDetector)
A VehicleInfo stores values that are tracked for the individual vehicles on the detector,...
Definition: MSE2Collector.h:85
std::size_t currentOffsetIndex
Index of currentLane in the detector's myLanes vector.
double lastAccel
Last value of the acceleration.
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:88
double length
vehicle's length
double accumulatedTimeLoss
Accumulated time loss that this vehicle suffered since it entered the detector.
std::string entryLaneID
ID of the lane, on which the vehicle entered the detector.
bool onDetector
whether the vehicle is on the detector at the end of the current timestep
double distToDetectorEnd
Distance left till the detector end after the last integration step (may become negative if the vehic...
double lastSpeed
Last value of the speed.
bool hasEntered
Whether the vehicle has already entered the detector (don't count twice!)
double minGap
vehicle's minGap
std::string id
vehicle's ID
const MSLane * currentLane
Lane, on which the vehicle currently resides (always the one for which the last notifyEnter was recei...
double totalTimeOnDetector
Accumulated time that this vehicle has spent on the detector since its last entry.
std::string type
vehicle's type