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,
86  const std::string& vTypes);
87 
88 
90  ~MSInductLoop();
91 
92 
95  virtual void reset();
96 
97 
102  return myPosition;
103  }
104 
105 
108 
118  bool notifyEnter(SUMOVehicle& veh, Notification reason);
119 
136  bool notifyMove(SUMOVehicle& veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed);
137 
138 
153  bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, MSMoveReminder::Notification reason);
154 
155 
157 
158 
159 
162 
170  SUMOReal getCurrentSpeed() const;
171 
172 
180  SUMOReal getCurrentLength() const;
181 
182 
193 
194 
204  int getCurrentPassedNumber() const;
205 
206 
212  std::vector<std::string> getCurrentVehicleIDs() const;
213 
214 
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, SUMOReal vehLength, SUMOReal entryTimestep, SUMOReal 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;
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, SUMOReal entryTimestep);
303 
304 
313  virtual void leaveDetectorByMove(SUMOVehicle& veh, SUMOReal leaveTimestep);
314 
315 
320  virtual void leaveDetectorByLaneChange(SUMOVehicle& veh, SUMOReal lastPos);
322 
323 
324 protected:
327 
329  static inline SUMOReal speedSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData& data) {
330  return sumSoFar + data.speedM;
331  }
332 
334  static inline SUMOReal lengthSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData& data) {
335  return sumSoFar + data.lengthM;
336  }
338 
339 
340 protected:
343 
346 
349 
352 
353 
355  typedef std::deque< VehicleData > VehicleDataCont;
356 
358  VehicleDataCont myVehicleDataCont;
359 
361  VehicleDataCont myLastVehicleDataCont;
362 
363 
365  typedef std::map< SUMOVehicle*, SUMOReal > VehicleMap;
366 
368  VehicleMap myVehiclesOnDet;
369 
370 private:
372  MSInductLoop(const MSInductLoop&);
373 
376 
377 
378 };
379 
380 
381 #endif
382 
383 /****************************************************************************/
384 
SUMOReal getTimestepsSinceLastDetection() const
Returns the time since the last vehicle left the detector.
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:82
long long int SUMOTime
Definition: SUMOTime.h:43
SUMOReal getPosition() const
Returns the position of the detector on the lane.
Definition: MSInductLoop.h:101
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.
Notification
Definition of a vehicle state.
T MAX2(T a, T b)
Definition: StdDefs.h:75
SUMOReal getCurrentOccupancy() const
Returns the current occupancy.
VehicleMap myVehiclesOnDet
Data for vehicles that have entered the detector (vehicle -> enter time)
Definition: MSInductLoop.h:368
VehicleDataCont myLastVehicleDataCont
Data of vehicles that have completely passed the detector in the last time interval.
Definition: MSInductLoop.h:361
const SUMOReal myPosition
Detector&#39;s position on lane [m].
Definition: MSInductLoop.h:342
SUMOReal lengthM
Length of the vehicle.
Definition: MSInductLoop.h:272
VehicleDataCont myVehicleDataCont
Data of vehicles that have completely passed the detector.
Definition: MSInductLoop.h:358
SUMOReal speedM
Speed of the vehicle in [m/s].
Definition: MSInductLoop.h:278
std::deque< VehicleData > VehicleDataCont
Type of myVehicleDataCont.
Definition: MSInductLoop.h:355
VehicleData(const std::string &id, SUMOReal vehLength, SUMOReal entryTimestep, SUMOReal leaveTimestep, const std::string &typeID)
Constructor.
Definition: MSInductLoop.h:264
static SUMOReal lengthSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
Definition: MSInductLoop.h:334
MSInductLoop & operator=(const MSInductLoop &)
Invalidated assignment operator.
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "detector" as root element.
SUMOReal leaveTimeM
Leave-time of the vehicle in [s].
Definition: MSInductLoop.h:276
SUMOReal entryTimeM
Entry-time of the vehicle in [s].
Definition: MSInductLoop.h:274
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:329
MSInductLoop(const std::string &id, MSLane *const lane, SUMOReal positionInMeters, const std::string &vTypes)
Constructor.
std::string idM
The id of the vehicle.
Definition: MSInductLoop.h:270
Something on a lane to be noticed about vehicle movement.
int myEnteredVehicleNumber
The number of entered vehicles.
Definition: MSInductLoop.h:351
int getCurrentPassedNumber() const
Returns the number of vehicles that have passed the detector.
SUMOReal myLastOccupancy
Occupancy by the last vehicle detected.
Definition: MSInductLoop.h:348
Struct to store the data of the counted vehicle internally.
Definition: MSInductLoop.h:255
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.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:213
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 myLastLeaveTime
Leave-time of the last vehicle detected [s].
Definition: MSInductLoop.h:345
#define NUMERICAL_EPS
Definition: config.h:160
virtual void leaveDetectorByMove(SUMOVehicle &veh, SUMOReal leaveTimestep)
Processes a vehicle that leaves the detector.
SUMOReal getCurrentSpeed() const
Returns the speed of the vehicle on the detector.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
SUMOReal getCurrentLength() const
Returns the length of the vehicle on the detector.
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:365
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
bool notifyMove(SUMOVehicle &veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed)
Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder.