Eclipse SUMO - Simulation of Urban MObility
MSE3Collector.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2003-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 /****************************************************************************/
21 // A detector of vehicles passing an area between entry/exit points
22 /****************************************************************************/
23 #pragma once
24 #include <config.h>
25 
26 #include <string>
27 #include <vector>
28 #include <limits>
31 #include <utils/common/Named.h>
34 #ifdef HAVE_FOX
36 #endif
37 
38 
39 // ===========================================================================
40 // class declarations
41 // ===========================================================================
42 class SUMOTrafficObject;
43 class OutputDevice;
44 class MSTransportable;
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
60 public:
66  public:
72  MSE3EntryReminder(const MSCrossSection& crossSection, MSE3Collector& collector);
73 
74 
77 
87  bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane);
88 
104  bool notifyMove(SUMOTrafficObject& veh, double, double newPos, double);
105 
106 
117  bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
119 
120 
121  double getPosition() const {
122  return myPosition;
123  }
124 
125  private:
128 
130  double myPosition;
131 
132  private:
135 
138 
139  };
140 
141 
142 
148  public:
154  MSE3LeaveReminder(const MSCrossSection& crossSection, MSE3Collector& collector);
155 
156 
158 
159 
169  bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane);
170 
186  bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double);
187 
197  bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
199 
200  double getPosition() const {
201  return myPosition;
202  }
203 
204 
205  private:
208 
210  double myPosition;
211 
212  private:
215 
218 
219  };
220 
221 
232  MSE3Collector(const std::string& id,
233  const CrossSectionVector& entries, const CrossSectionVector& exits,
234  double haltingSpeedThreshold,
235  SUMOTime haltingTimeThreshold,
236  const std::string name, const std::string& vTypes,
237  const std::string& nextEdges,
238  int detectPersons, bool openEntry, bool expectArrival);
239 
240 
242  virtual ~MSE3Collector();
243 
244 
247  void reset();
248 
249 
258  void enter(const SUMOTrafficObject& veh, const double entryTimestep, const double fractionTimeOnDet, MSE3EntryReminder* entryReminder, bool isBackward = false);
259 
260 
266  void leaveFront(const SUMOTrafficObject& veh, const double leaveTimestep);
267 
268 
277  void leave(const SUMOTrafficObject& veh, const double leaveTimestep, const double fractionTimeOnDet, bool isBackward = false);
278 
280  const CrossSectionVector& getEntries() const;
281 
283  const CrossSectionVector& getExits() const;
284 
287 
294  double getCurrentMeanSpeed() const;
295 
296 
303  int getCurrentHaltingNumber() const;
304 
305 
309  int getVehiclesWithin() const;
310 
311 
316  std::vector<std::string> getCurrentVehicleIDs() const;
318 
321 
323  return myLastMeanTravelTime;
324  }
325 
328  }
329 
331  return myLastMeanTimeLoss;
332  }
333 
335  return myLastVehicleSum;
336  }
338 
341 
350  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
351 
352 
361  void writeXMLDetectorProlog(OutputDevice& dev) const;
363 
364 
365 
374  void detectorUpdate(const SUMOTime step);
375 
377  virtual void clearState(SUMOTime step);
378 
379 protected:
380  void notifyMovePerson(MSTransportable* p, MSMoveReminder* rem, double detPos, int dir, double pos);
381 
382 protected:
384  std::string myName;
385 
388 
391 
393  std::vector<MSE3EntryReminder*> myEntryReminders;
394 
396  std::vector<MSE3LeaveReminder*> myLeaveReminders;
397 
398 
399  // @brief Time-threshold to determine if a vehicle is halting.
401 
404 
413  struct E3Values {
415  double entryTime;
421  double speedSum;
423  int haltings;
435  bool hadUpdate;
438  };
439 
441  std::map<const SUMOTrafficObject*, E3Values> myEnteredContainer;
442 
444  std::vector<E3Values> myLeftContainer;
445 
446 #ifdef HAVE_FOX
448  FXMutex myContainerMutex;
449 #endif
450 
453 
456 
460 
468 
471 
473  const bool myOpenEntry;
475  const bool myExpectArrival;
476 
477 private:
480 
483 
484 
485 };
long long int SUMOTime
Definition: GUI.h:35
std::vector< MSCrossSection > CrossSectionVector
A simple description of a position on a lane (crossing of a lane)
Base of value-generating classes (detectors)
A place on the road net (at a certain lane and position on it) where the E3 area begins.
Definition: MSE3Collector.h:65
bool notifyMove(SUMOTrafficObject &veh, double, double newPos, double)
Checks whether the vehicle enters.
MSE3EntryReminder & operator=(const MSE3EntryReminder &)
Invalidated assignment operator.
MSE3EntryReminder(const MSCrossSection &crossSection, MSE3Collector &collector)
Constructor.
double myPosition
The position on the lane.
MSE3Collector & myCollector
The parent collector.
double getPosition() const
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Processes state changes of a vehicle.
MSE3EntryReminder(const MSE3EntryReminder &)
Invalidated copy constructor.
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane)
Checks whether the reminder is activated by a vehicle entering the lane.
A place on the road net (at a certain lane and position on it) where the E3 area ends.
MSE3LeaveReminder & operator=(const MSE3LeaveReminder &)
Invalidated assignment operator.
MSE3LeaveReminder(const MSCrossSection &crossSection, MSE3Collector &collector)
Constructor.
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane)
Checks whether the reminder is activated by a vehicle entering the lane.
MSE3Collector & myCollector
The parent collector.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double)
Checks whether the vehicle leaves.
double myPosition
The position on the lane.
MSE3LeaveReminder(const MSE3LeaveReminder &)
Invalidated copy constructor.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Processes state changes of a vehicle.
A detector of vehicles passing an area between entry/exit points.
Definition: MSE3Collector.h:59
std::vector< E3Values > myLeftContainer
Container for vehicles that have left the area.
std::map< const SUMOTrafficObject *, E3Values > myEnteredContainer
Container for vehicles that have entered the area.
double myHaltingSpeedThreshold
Speed-threshold to determine if a vehicle is halting.
const CrossSectionVector & getEntries() const
Returns the entry cross sections.
virtual void clearState(SUMOTime step)
Remove all vehicles before quick-loading state.
double myCurrentMeanSpeed
The current mean speed of known vehicles (inside)
void reset()
Resets all generated values to allow computation of next interval.
double myLastMeanTravelTime
CrossSectionVector myExits
The detector's exits.
void enter(const SUMOTrafficObject &veh, const double entryTimestep, const double fractionTimeOnDet, MSE3EntryReminder *entryReminder, bool isBackward=false)
Called if a vehicle touches an entry-cross-section.
int myCurrentHaltingsNumber
The current number of haltings (inside)
SUMOTime myLastResetTime
Information when the last reset has been done.
int getVehiclesWithin() const
Returns the number of vehicles within the area.
std::vector< MSE3EntryReminder * > myEntryReminders
The detector's built entry reminder.
const bool myOpenEntry
whether this dector is declared as having incomplete entry detectors
std::vector< MSE3LeaveReminder * > myLeaveReminders
The detector's built exit reminder.
double myLastMeanHaltsPerVehicle
const CrossSectionVector & getExits() const
Returns the exit cross sections.
double myLastMeanTimeLoss
void notifyMovePerson(MSTransportable *p, MSMoveReminder *rem, double detPos, int dir, double pos)
std::string myName
name
std::vector< std::string > getCurrentVehicleIDs() const
Returns the number of vehicles within the area.
const bool myExpectArrival
Whether the detector expects vehicles to arrive inside (and doesn't issue a warning in this case)
virtual ~MSE3Collector()
Destructor.
double getLastIntervalMeanTravelTime() const
MSE3Collector(const std::string &id, const CrossSectionVector &entries, const CrossSectionVector &exits, double haltingSpeedThreshold, SUMOTime haltingTimeThreshold, const std::string name, const std::string &vTypes, const std::string &nextEdges, int detectPersons, bool openEntry, bool expectArrival)
Constructor.
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "e3Detector" as root element.
int getLastIntervalVehicleSum() const
double getCurrentMeanSpeed() const
Returns the mean speed within the area.
double getLastIntervalMeanHaltsPerVehicle() const
MSE3Collector & operator=(const MSE3Collector &)
Invalidated assignment operator.
MSE3Collector(const MSE3Collector &)
Invalidated copy constructor.
int getCurrentHaltingNumber() const
Returns the number of current haltings within the area.
void detectorUpdate(const SUMOTime step)
Computes the detector values in each time step.
double getLastIntervalMeanTimeLoss() const
SUMOTime myHaltingTimeThreshold
CrossSectionVector myEntries
The detector's entrys.
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
void leave(const SUMOTrafficObject &veh, const double leaveTimestep, const double fractionTimeOnDet, bool isBackward=false)
Called if a vehicle back passes a leave-cross-section.
void leaveFront(const SUMOTrafficObject &veh, const double leaveTimestep)
Called if a vehicle front passes a leave-cross-section.
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.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
Representation of a vehicle, person, or container.
Internal storage for values from a vehicle.
int intervalHaltings
The sum of haltings the vehicle has/had within the area during the current interval.
MSE3EntryReminder * entryReminder
the reminder on which the vehicle entered the detector
SUMOTime timeLoss
The timeLoss of the vehicle when entering. Updated to the actual time loss within the area when leavi...
double frontLeaveTime
The time the vehicle's front was crossing the leave line.
double entryTime
The vehicle's entry time.
SUMOTime intervalTimeLoss
The timeLoss of the vehicle when entering. Updated to the current timeLoss at interval write.
double speedSum
The sum of registered speeds the vehicle has/had inside the area.
bool hadUpdate
An internal information whether the update step was performed.
SUMOTime haltingBegin
Begin time of last halt begin.
double intervalSpeedSum
The sum of registered speeds the vehicle has/had inside the area during the current interval.
int haltings
The sum of haltings the vehicle has/had within the area.
double backLeaveTime
The time the vehicle's back was crossing the leave line.