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-2016 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  SUMOReal positionInMeters, bool splitByType);
86 
87 
89  ~MSInductLoop();
90 
91 
94  virtual void reset();
95 
96 
101  return myPosition;
102  }
103 
104 
107 
117  bool notifyEnter(SUMOVehicle& veh, Notification reason);
118 
135  bool notifyMove(SUMOVehicle& veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed);
136 
137 
152  bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, MSMoveReminder::Notification reason);
153 
154 
156 
157 
158 
161 
169  SUMOReal getCurrentSpeed() const;
170 
171 
179  SUMOReal getCurrentLength() const;
180 
181 
192 
193 
203  int getCurrentPassedNumber() const;
204 
205 
211  std::vector<std::string> getCurrentVehicleIDs() const;
212 
213 
220 
221 
222 
225 
234  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
235 
236 
243  void writeXMLDetectorProlog(OutputDevice& dev) const;
245 
246 
247 
254  struct VehicleData {
263  VehicleData(const std::string& id, SUMOReal vehLength, SUMOReal entryTimestep, SUMOReal leaveTimestep,
264  const std::string& typeID)
265  : idM(id), lengthM(vehLength), entryTimeM(entryTimestep), leaveTimeM(leaveTimestep),
266  speedM(vehLength / MAX2(leaveTimestep - entryTimestep, NUMERICAL_EPS)), typeIDM(typeID) {}
267 
269  std::string idM;
279  std::string typeIDM;
280  };
281 
282 
290  virtual std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t, bool leaveTime = false) const;
291 
292 
293 protected:
296 
301  virtual void enterDetectorByMove(SUMOVehicle& veh, SUMOReal entryTimestep);
302 
303 
312  virtual void leaveDetectorByMove(SUMOVehicle& veh, SUMOReal leaveTimestep);
313 
314 
319  virtual void leaveDetectorByLaneChange(SUMOVehicle& veh, SUMOReal lastPos);
321 
322 
323 protected:
326 
328  static inline SUMOReal speedSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData& data) {
329  return sumSoFar + data.speedM;
330  }
331 
333  static inline SUMOReal lengthSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData& data) {
334  return sumSoFar + data.lengthM;
335  }
337 
338 
339 protected:
342 
345 
348 
351 
354 
355 
357  typedef std::deque< VehicleData > VehicleDataCont;
358 
360  VehicleDataCont myVehicleDataCont;
361 
363  VehicleDataCont myLastVehicleDataCont;
364 
365 
367  typedef std::map< SUMOVehicle*, SUMOReal > VehicleMap;
368 
370  VehicleMap myVehiclesOnDet;
371 
372  void writeTypedXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime,
373  const std::string& type, const VehicleDataCont& vdc, const VehicleMap& vm);
374 
375 private:
377  MSInductLoop(const MSInductLoop&);
378 
381 
382 
383 };
384 
385 
386 #endif
387 
388 /****************************************************************************/
389 
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:81
long long int SUMOTime
Definition: SUMOTime.h:43
MSInductLoop(const std::string &id, MSLane *const lane, SUMOReal positionInMeters, bool splitByType)
Constructor.
virtual void reset()
Resets all generated values to allow computation of next interval.
Notification
Definition of a vehicle state.
SUMOReal getPosition() const
Returns the position of the detector on the lane.
Definition: MSInductLoop.h:100
int getCurrentPassedNumber() const
Returns the number of vehicles that have passed the detector.
T MAX2(T a, T b)
Definition: StdDefs.h:75
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...
SUMOReal getCurrentOccupancy() const
Returns the current occupancy.
VehicleMap myVehiclesOnDet
Data for vehicles that have entered the detector (vehicle -> enter time)
Definition: MSInductLoop.h:370
VehicleDataCont myLastVehicleDataCont
Data of vehicles that have completely passed the detector in the last time interval.
Definition: MSInductLoop.h:363
const SUMOReal myPosition
Detector&#39;s position on lane [m].
Definition: MSInductLoop.h:341
SUMOReal lengthM
Length of the vehicle.
Definition: MSInductLoop.h:271
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "detector" as root element.
VehicleDataCont myVehicleDataCont
Data of vehicles that have completely passed the detector.
Definition: MSInductLoop.h:360
SUMOReal speedM
Speed of the vehicle in [m/s].
Definition: MSInductLoop.h:277
std::deque< VehicleData > VehicleDataCont
Type of myVehicleDataCont.
Definition: MSInductLoop.h:357
VehicleData(const std::string &id, SUMOReal vehLength, SUMOReal entryTimestep, SUMOReal leaveTimestep, const std::string &typeID)
Constructor.
Definition: MSInductLoop.h:263
static SUMOReal lengthSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
Definition: MSInductLoop.h:333
std::vector< std::string > getCurrentVehicleIDs() const
Returns the ids of vehicles that have passed the detector.
MSInductLoop & operator=(const MSInductLoop &)
Invalidated assignment operator.
SUMOReal leaveTimeM
Leave-time of the vehicle in [s].
Definition: MSInductLoop.h:275
SUMOReal entryTimeM
Entry-time of the vehicle in [s].
Definition: MSInductLoop.h:273
Representation of a vehicle.
Definition: SUMOVehicle.h:66
~MSInductLoop()
Destructor.
virtual void enterDetectorByMove(SUMOVehicle &veh, SUMOReal entryTimestep)
Introduces a vehicle to the detector&#39;s map myVehiclesOnDet.
static SUMOReal speedSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::speedM.
Definition: MSInductLoop.h:328
bool mySplitByType
Whether additional information split by vehicle classes shall be generated.
Definition: MSInductLoop.h:344
std::string idM
The id of the vehicle.
Definition: MSInductLoop.h:269
Something on a lane to be noticed about vehicle movement.
SUMOReal getCurrentSpeed() const
Returns the speed of the vehicle on the detector.
SUMOReal myLastOccupancy
Occupancy by the last vehicle detected.
Definition: MSInductLoop.h:350
Struct to store the data of the counted vehicle internally.
Definition: MSInductLoop.h:254
int myDismissedVehicleNumber
The number of dismissed vehicles.
Definition: MSInductLoop.h:353
bool notifyEnter(SUMOVehicle &veh, Notification reason)
Checks whether the reminder is activated by a vehicle entering the lane.
virtual void leaveDetectorByLaneChange(SUMOVehicle &veh, SUMOReal lastPos)
Removes a vehicle from the detector&#39;s map myVehiclesOnDet.
SUMOReal getTimestepsSinceLastDetection() const
Returns the time since the last vehicle left the detector.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:213
SUMOReal myLastLeaveTime
Leave-time of the last vehicle detected [s].
Definition: MSInductLoop.h:347
void writeTypedXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime, const std::string &type, const VehicleDataCont &vdc, const VehicleMap &vm)
#define NUMERICAL_EPS
Definition: config.h:160
SUMOReal getCurrentLength() const
Returns the length of the vehicle on the detector.
virtual void leaveDetectorByMove(SUMOVehicle &veh, SUMOReal leaveTimestep)
Processes a vehicle that leaves the detector.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, MSMoveReminder::Notification reason)
Dismisses the vehicle if it is on the detector due to a lane change.
std::map< SUMOVehicle *, SUMOReal > VehicleMap
Type of myVehiclesOnDet.
Definition: MSInductLoop.h:367
Base of value-generating classes (detectors)
std::string typeIDM
Type of the vehicle in.
Definition: MSInductLoop.h:279
An unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:71
bool notifyMove(SUMOVehicle &veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed)
Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder.