Eclipse SUMO - Simulation of Urban MObility
MSInductLoop.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2004-2022 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 /****************************************************************************/
22 // An unextended detector measuring at a fixed position on a fixed lane.
23 /****************************************************************************/
24 #pragma once
25 #include <config.h>
26 
27 #include <string>
28 #include <deque>
29 #include <map>
30 #include <functional>
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class MSLane;
39 class MSVehicle;
40 class OutputDevice;
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
62  : public MSMoveReminder, public MSDetectorFileOutput {
63 public:
75  MSInductLoop(const std::string& id, MSLane* const lane,
76  double positionInMeters,
77  const std::string& vTypes,
78  int detectPersons,
79  const bool needLocking);
80 
81 
83  ~MSInductLoop();
84 
85 
88  virtual void reset();
89 
90 
94  double getPosition() const {
95  return myPosition;
96  }
97 
98 
101 
111  bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane = 0);
112 
129  bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
130 
131 
146  bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
147 
148 
150 
151 
152 
155 
163  double getSpeed(const int offset) const;
164 
165 
173  double getVehicleLength(const int offset) const;
174 
175 
185  double getOccupancy() const;
186 
196  double getEnteredNumber(const int offset) const;
197 
198 
204  std::vector<std::string> getVehicleIDs(const int offset) const;
205 
206 
211  double getTimeSinceLastDetection() const;
212 
216 
217 
218 
221 
230  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
231 
232 
239  void writeXMLDetectorProlog(OutputDevice& dev) const;
240 
246  void detectorUpdate(const SUMOTime step);
248 
249 
256  struct VehicleData {
265  VehicleData(const SUMOTrafficObject& v, double entryTimestep,
266  double leaveTimestep, const bool leftEarly);
267 
269  std::string idM;
271  double lengthM;
273  double entryTimeM;
275  double leaveTimeM;
277  double speedM;
279  std::string typeIDM;
282  };
283 
284 
292  std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t, bool includeEarly = false, bool leaveTime = false, bool forOccupancy = false) const;
293 
295  virtual void setSpecialColor(const RGBColor* /*color*/) {};
296 
297  virtual void setVisible(bool /*show*/) {};
298 
300  virtual void clearState();
301 
302 protected:
305 
307  static inline double speedSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
308  return sumSoFar + data.speedM;
309  }
310 
312  static inline double lengthSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
313  return sumSoFar + data.lengthM;
314  }
316 
318  void notifyMovePerson(MSTransportable* p, int dir, double pos);
319 
320 protected:
322  const double myPosition;
323 
325  const bool myNeedLock;
326 
329 
332 
334  typedef std::deque< VehicleData > VehicleDataCont;
335 
338 
341 
343  std::map<SUMOTrafficObject*, double> myVehiclesOnDet;
344 
345 private:
348 
351 
352 
353 };
long long int SUMOTime
Definition: SUMOTime.h:32
Base of value-generating classes (detectors)
An unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:62
static double lengthSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
Definition: MSInductLoop.h:312
double getOccupancy() const
Returns the current occupancy.
int myEnteredVehicleNumber
The number of entered vehicles.
Definition: MSInductLoop.h:331
std::deque< VehicleData > VehicleDataCont
Type of myVehicleDataCont.
Definition: MSInductLoop.h:334
double getEnteredNumber(const int offset) const
Returns the number of vehicles that have passed the detector.
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
static double speedSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::speedM.
Definition: MSInductLoop.h:307
VehicleDataCont myVehicleDataCont
Data of vehicles that have completely passed the detector.
Definition: MSInductLoop.h:337
double getPosition() const
Returns the position of the detector on the lane.
Definition: MSInductLoop.h:94
MSInductLoop(const std::string &id, MSLane *const lane, double positionInMeters, const std::string &vTypes, int detectPersons, const bool needLocking)
Constructor.
MSInductLoop & operator=(const MSInductLoop &)
Invalidated assignment operator.
double getSpeed(const int offset) const
Returns the speed of the vehicle on the detector.
virtual void setSpecialColor(const RGBColor *)
allows for special color in the gui version
Definition: MSInductLoop.h:295
virtual void clearState()
Remove all vehicles before quick-loading state.
std::vector< std::string > getVehicleIDs(const int offset) const
Returns the ids of vehicles that have passed the detector.
double getVehicleLength(const int offset) const
Returns the length of the vehicle on the detector.
virtual void reset()
Resets all generated values to allow computation of next interval.
const double myPosition
Detector's position on lane [m].
Definition: MSInductLoop.h:322
VehicleDataCont myLastVehicleDataCont
Data of vehicles that have completely passed the detector in the last time interval.
Definition: MSInductLoop.h:340
~MSInductLoop()
Destructor.
MSInductLoop(const MSInductLoop &)
Invalidated copy constructor.
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "detector" as root element.
void detectorUpdate(const SUMOTime step)
Updates the detector (computes values) only used when detecting persons.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder.
void notifyMovePerson(MSTransportable *p, int dir, double pos)
helper function for mapping person movement
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
double myLastLeaveTime
Leave-time of the last vehicle detected [s].
Definition: MSInductLoop.h:328
virtual void setVisible(bool)
Definition: MSInductLoop.h:297
const bool myNeedLock
whether internals need to be guarded against concurrent access (GUI or multi threading)
Definition: MSInductLoop.h:325
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane=0)
Checks whether the reminder is activated by a vehicle entering the lane.
std::vector< VehicleData > collectVehiclesOnDet(SUMOTime t, bool includeEarly=false, bool leaveTime=false, bool forOccupancy=false) const
Returns vehicle data for vehicles that have been on the detector starting at the given time.
std::map< SUMOTrafficObject *, double > myVehiclesOnDet
Data for vehicles that have entered the detector (vehicle -> enter time)
Definition: MSInductLoop.h:343
SUMOTime getLastDetectionTime() const
return last time a vehicle was on the detector
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Dismisses the vehicle if it is on the detector due to a lane change.
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:75
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
Representation of a vehicle, person, or container.
Struct to store the data of the counted vehicle internally.
Definition: MSInductLoop.h:256
double lengthM
Length of the vehicle.
Definition: MSInductLoop.h:271
double leaveTimeM
Leave-time of the vehicle in [s].
Definition: MSInductLoop.h:275
bool leftEarlyM
whether the vehicle left the detector with a lane change / teleport etc.
Definition: MSInductLoop.h:281
std::string idM
The id of the vehicle.
Definition: MSInductLoop.h:269
double entryTimeM
Entry-time of the vehicle in [s].
Definition: MSInductLoop.h:273
VehicleData(const SUMOTrafficObject &v, double entryTimestep, double leaveTimestep, const bool leftEarly)
Constructor.
double speedM
Speed of the vehicle in [m/s].
Definition: MSInductLoop.h:277
std::string typeIDM
Type of the vehicle.
Definition: MSInductLoop.h:279