SUMO - Simulation of Urban MObility
MSInductLoop.h
Go to the documentation of this file.
1 /****************************************************************************/
11 // An unextended detector measuring at a fixed position on a fixed lane.
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2004-2017 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 #ifndef MSInductLoop_h
25 #define MSInductLoop_h
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
37 #include <string>
38 #include <deque>
39 #include <map>
40 #include <functional>
43 
44 
45 // ===========================================================================
46 // class declarations
47 // ===========================================================================
48 class MSLane;
49 class MSVehicle;
50 class OutputDevice;
51 
52 
53 // ===========================================================================
54 // class definitions
55 // ===========================================================================
72  : public MSMoveReminder, public MSDetectorFileOutput {
73 public:
84  MSInductLoop(const std::string& id, MSLane* const lane,
85  double positionInMeters,
86  const std::string& vTypes);
87 
88 
90  ~MSInductLoop();
91 
92 
95  virtual void reset();
96 
97 
101  double getPosition() const {
102  return myPosition;
103  }
104 
105 
108 
118  bool notifyEnter(SUMOVehicle& veh, Notification reason, const MSLane* enteredLane = 0);
119 
136  bool notifyMove(SUMOVehicle& veh, double oldPos, double newPos, double newSpeed);
137 
138 
153  bool notifyLeave(SUMOVehicle& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
154 
155 
157 
158 
159 
162 
170  double getCurrentSpeed() const;
171 
172 
180  double getCurrentLength() const;
181 
182 
192  double getCurrentOccupancy() const;
193 
194 
204  int getCurrentPassedNumber() const;
205 
206 
212  std::vector<std::string> getCurrentVehicleIDs() const;
213 
214 
219  double getTimeSinceLastDetection() const;
221 
222 
223 
226 
235  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
236 
237 
244  void writeXMLDetectorProlog(OutputDevice& dev) const;
246 
247 
248 
255  struct VehicleData {
264  VehicleData(const std::string& id, double vehLength, double entryTimestep, double leaveTimestep,
265  const std::string& typeID)
266  : idM(id), lengthM(vehLength), entryTimeM(entryTimestep), leaveTimeM(leaveTimestep),
267  speedM(vehLength / MAX2(leaveTimestep - entryTimestep, NUMERICAL_EPS)), typeIDM(typeID) {}
268 
270  std::string idM;
272  double lengthM;
274  double entryTimeM;
276  double leaveTimeM;
278  double speedM;
280  std::string typeIDM;
281  };
282 
283 
291  virtual std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t, bool leaveTime = false) const;
292 
293 
294 protected:
297 
302  virtual void enterDetectorByMove(SUMOVehicle& veh, double entryTimestep);
303 
304 
313  virtual void leaveDetectorByMove(SUMOVehicle& veh, double leaveTimestep);
314 
315 
320  virtual void leaveDetectorByLaneChange(SUMOVehicle& veh, double lastPos);
322 
323 
324 protected:
327 
329  static inline double speedSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
330  return sumSoFar + data.speedM;
331  }
332 
334  static inline double lengthSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
335  return sumSoFar + data.lengthM;
336  }
338 
339 
340 protected:
342  const double myPosition;
343 
346 
349 
352 
353 
355  typedef std::deque< VehicleData > VehicleDataCont;
356 
358  VehicleDataCont myVehicleDataCont;
359 
361  VehicleDataCont myLastVehicleDataCont;
362 
363 
365 
366  typedef std::map< SUMOVehicle*, double > VehicleMap;
367 
369  VehicleMap myVehiclesOnDet;
370 
371 private:
373  MSInductLoop(const MSInductLoop&);
374 
377 
378 
379 };
380 
381 
382 #endif
383 
384 /****************************************************************************/
385 
const double myPosition
Detector&#39;s position on lane [m].
Definition: MSInductLoop.h:342
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:83
std::map< SUMOVehicle *, double > VehicleMap
Type of myVehiclesOnDet.
Definition: MSInductLoop.h:366
double myLastOccupancy
Occupancy by the last vehicle detected.
Definition: MSInductLoop.h:348
std::vector< std::string > getCurrentVehicleIDs() const
Returns the ids of vehicles that have passed the detector.
virtual void leaveDetectorByLaneChange(SUMOVehicle &veh, double lastPos)
Removes a vehicle from the detector&#39;s map myVehiclesOnDet.
virtual void reset()
Resets all generated values to allow computation of next interval.
bool notifyLeave(SUMOVehicle &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Dismisses the vehicle if it is on the detector due to a lane change.
static double speedSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::speedM.
Definition: MSInductLoop.h:329
virtual void leaveDetectorByMove(SUMOVehicle &veh, double leaveTimestep)
Processes a vehicle that leaves the detector.
Notification
Definition of a vehicle state.
T MAX2(T a, T b)
Definition: StdDefs.h:70
double getCurrentLength() const
Returns the length of the vehicle on the detector.
VehicleMap myVehiclesOnDet
Data for vehicles that have entered the detector (vehicle -> enter time)
Definition: MSInductLoop.h:369
double speedM
Speed of the vehicle in [m/s].
Definition: MSInductLoop.h:278
VehicleDataCont myLastVehicleDataCont
Data of vehicles that have completely passed the detector in the last time interval.
Definition: MSInductLoop.h:361
VehicleDataCont myVehicleDataCont
Data of vehicles that have completely passed the detector.
Definition: MSInductLoop.h:358
std::deque< VehicleData > VehicleDataCont
Type of myVehicleDataCont.
Definition: MSInductLoop.h:355
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:274
VehicleData(const std::string &id, double vehLength, double entryTimestep, double leaveTimestep, const std::string &typeID)
Constructor.
Definition: MSInductLoop.h:264
Representation of a vehicle.
Definition: SUMOVehicle.h:67
~MSInductLoop()
Destructor.
virtual void enterDetectorByMove(SUMOVehicle &veh, double entryTimestep)
Introduces a vehicle to the detector&#39;s map myVehiclesOnDet.
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:101
double lengthM
Length of the vehicle.
Definition: MSInductLoop.h:272
std::string idM
The id of the vehicle.
Definition: MSInductLoop.h:270
Something on a lane to be noticed about vehicle movement.
double leaveTimeM
Leave-time of the vehicle in [s].
Definition: MSInductLoop.h:276
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:351
bool notifyEnter(SUMOVehicle &veh, Notification reason, const MSLane *enteredLane=0)
Checks whether the reminder is activated by a vehicle entering the lane.
int getCurrentPassedNumber() const
Returns the number of vehicles that have passed the detector.
Struct to store the data of the counted vehicle internally.
Definition: MSInductLoop.h:255
bool notifyMove(SUMOVehicle &veh, double oldPos, double newPos, double newSpeed)
Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
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...
long long int SUMOTime
Definition: TraCIDefs.h:52
#define NUMERICAL_EPS
Definition: config.h:151
double getCurrentOccupancy() const
Returns the current occupancy.
double myLastLeaveTime
Leave-time of the last vehicle detected [s].
Definition: MSInductLoop.h:345
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
static double lengthSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
Definition: MSInductLoop.h:334
Base of value-generating classes (detectors)
std::string typeIDM
Type of the vehicle in.
Definition: MSInductLoop.h:280
An unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:71