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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
19 // An unextended detector measuring at a fixed position on a fixed lane.
20 /****************************************************************************/
21 #ifndef MSInductLoop_h
22 #define MSInductLoop_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #include <config.h>
29 
30 #include <string>
31 #include <deque>
32 #include <map>
33 #include <functional>
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
41 class MSLane;
42 class MSVehicle;
43 class OutputDevice;
44 
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
65  : public MSMoveReminder, public MSDetectorFileOutput {
66 public:
77  MSInductLoop(const std::string& id, MSLane* const lane,
78  double positionInMeters,
79  const std::string& vTypes);
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 getCurrentSpeed() const;
164 
165 
173  double getCurrentLength() const;
174 
175 
185  double getCurrentOccupancy() const;
186 
187 
197  int getCurrentPassedNumber() const;
198 
199 
205  std::vector<std::string> getCurrentVehicleIDs() const;
206 
207 
212  double getTimeSinceLastDetection() const;
214 
215 
216 
219 
228  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
229 
230 
237  void writeXMLDetectorProlog(OutputDevice& dev) const;
239 
240 
241 
248  struct VehicleData {
257  VehicleData(const std::string& id, double vehLength, double entryTimestep, double leaveTimestep,
258  const std::string& typeID)
259  : idM(id), lengthM(vehLength), entryTimeM(entryTimestep), leaveTimeM(leaveTimestep),
260  speedM(vehLength / MAX2(leaveTimestep - entryTimestep, NUMERICAL_EPS)), typeIDM(typeID) {}
261 
263  std::string idM;
265  double lengthM;
267  double entryTimeM;
269  double leaveTimeM;
271  double speedM;
273  std::string typeIDM;
274  };
275 
276 
284  virtual std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t, bool leaveTime = false) const;
285 
287  virtual void setSpecialColor(const RGBColor* /*color*/) {};
288 
289  virtual void setVisible(bool /*show*/) {};
290 
291 protected:
294 
299  virtual void enterDetectorByMove(SUMOTrafficObject& veh, double entryTimestep);
300 
301 
310  virtual void leaveDetectorByMove(SUMOTrafficObject& veh, double leaveTimestep);
311 
312 
317  virtual void leaveDetectorByLaneChange(SUMOTrafficObject& veh, double lastPos);
319 
320 
321 protected:
324 
326  static inline double speedSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
327  return sumSoFar + data.speedM;
328  }
329 
331  static inline double lengthSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
332  return sumSoFar + data.lengthM;
333  }
335 
336 
337 protected:
339  const double myPosition;
340 
343 
346 
349 
350 
352  typedef std::deque< VehicleData > VehicleDataCont;
353 
355  VehicleDataCont myVehicleDataCont;
356 
358  VehicleDataCont myLastVehicleDataCont;
359 
360 
362 
363  typedef std::map< SUMOTrafficObject*, double > VehicleMap;
364 
366  VehicleMap myVehiclesOnDet;
367 
368 private:
370  MSInductLoop(const MSInductLoop&);
371 
374 
375 
376 };
377 
378 
379 #endif
380 
381 /****************************************************************************/
382 
const double myPosition
Detector&#39;s position on lane [m].
Definition: MSInductLoop.h:339
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
long long int SUMOTime
Definition: SUMOTime.h:35
virtual void leaveDetectorByMove(SUMOTrafficObject &veh, double leaveTimestep)
Processes a vehicle that leaves 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.
virtual void leaveDetectorByLaneChange(SUMOTrafficObject &veh, double lastPos)
Removes a vehicle from the detector&#39;s map myVehiclesOnDet.
double myLastOccupancy
Occupancy by the last vehicle detected.
Definition: MSInductLoop.h:345
std::vector< std::string > getCurrentVehicleIDs() const
Returns the ids of vehicles that have passed the detector.
virtual void reset()
Resets all generated values to allow computation of next interval.
static double speedSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::speedM.
Definition: MSInductLoop.h:326
Notification
Definition of a vehicle state.
virtual void setVisible(bool)
Definition: MSInductLoop.h:289
T MAX2(T a, T b)
Definition: StdDefs.h:80
double getCurrentLength() const
Returns the length of the vehicle on the detector.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder.
VehicleMap myVehiclesOnDet
Data for vehicles that have entered the detector (vehicle -> enter time)
Definition: MSInductLoop.h:366
virtual void setSpecialColor(const RGBColor *)
allows for special color in the gui version
Definition: MSInductLoop.h:287
double speedM
Speed of the vehicle in [m/s].
Definition: MSInductLoop.h:271
VehicleDataCont myLastVehicleDataCont
Data of vehicles that have completely passed the detector in the last time interval.
Definition: MSInductLoop.h:358
VehicleDataCont myVehicleDataCont
Data of vehicles that have completely passed the detector.
Definition: MSInductLoop.h:355
std::deque< VehicleData > VehicleDataCont
Type of myVehicleDataCont.
Definition: MSInductLoop.h:352
MSInductLoop & operator=(const MSInductLoop &)
Invalidated assignment operator.
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "detector" as root element.
double entryTimeM
Entry-time of the vehicle in [s].
Definition: MSInductLoop.h:267
VehicleData(const std::string &id, double vehLength, double entryTimestep, double leaveTimestep, const std::string &typeID)
Constructor.
Definition: MSInductLoop.h:257
~MSInductLoop()
Destructor.
double getCurrentSpeed() const
Returns the speed of the vehicle on the detector.
double getPosition() const
Returns the position of the detector on the lane.
Definition: MSInductLoop.h:94
double lengthM
Length of the vehicle.
Definition: MSInductLoop.h:265
std::string idM
The id of the vehicle.
Definition: MSInductLoop.h:263
Something on a lane to be noticed about vehicle movement.
double leaveTimeM
Leave-time of the vehicle in [s].
Definition: MSInductLoop.h:269
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane=0)
Checks whether the reminder is activated by a vehicle entering the lane.
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
MSInductLoop(const std::string &id, MSLane *const lane, double positionInMeters, const std::string &vTypes)
Constructor.
int myEnteredVehicleNumber
The number of entered vehicles.
Definition: MSInductLoop.h:348
virtual void enterDetectorByMove(SUMOTrafficObject &veh, double entryTimestep)
Introduces a vehicle to the detector&#39;s map myVehiclesOnDet.
int getCurrentPassedNumber() const
Returns the number of vehicles that have passed the detector.
std::map< SUMOTrafficObject *, double > VehicleMap
Type of myVehiclesOnDet.
Definition: MSInductLoop.h:363
Struct to store the data of the counted vehicle internally.
Definition: MSInductLoop.h:248
Representation of a vehicle or person.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
virtual std::vector< VehicleData > collectVehiclesOnDet(SUMOTime t, bool leaveTime=false) const
Returns vehicle data for vehicles that have been on the detector starting at the given time...
#define NUMERICAL_EPS
Definition: config.h:145
double getCurrentOccupancy() const
Returns the current occupancy.
double myLastLeaveTime
Leave-time of the last vehicle detected [s].
Definition: MSInductLoop.h:342
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
static double lengthSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
Definition: MSInductLoop.h:331
Base of value-generating classes (detectors)
std::string typeIDM
Type of the vehicle in.
Definition: MSInductLoop.h:273
An unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:64