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  unsigned 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 
288  virtual std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t) const;
289 
290 
291 protected:
294 
299  virtual void enterDetectorByMove(SUMOVehicle& veh, SUMOReal entryTimestep);
300 
301 
310  virtual void leaveDetectorByMove(SUMOVehicle& veh, SUMOReal leaveTimestep);
311 
312 
317  virtual void leaveDetectorByLaneChange(SUMOVehicle& veh, SUMOReal lastPos);
319 
320 
321 protected:
324 
326  static inline SUMOReal speedSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData& data) {
327  return sumSoFar + data.speedM;
328  }
329 
331  static inline SUMOReal lengthSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData& data) {
332  return sumSoFar + data.lengthM;
333  }
335 
336 
337 protected:
340 
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  void writeTypedXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime,
371  const std::string& type, const VehicleDataCont& vdc, const VehicleMap& vm);
372 
373 private:
375  MSInductLoop(const MSInductLoop&);
376 
379 
380 
381 };
382 
383 
384 #endif
385 
386 /****************************************************************************/
387 
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
unsigned myDismissedVehicleNumber
The number of dismissed vehicles.
Definition: MSInductLoop.h:351
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
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
virtual std::vector< VehicleData > collectVehiclesOnDet(SUMOTime t) const
Returns vehicle data for vehicles that have been on the detector starting at the given time...
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:339
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:358
SUMOReal speedM
Speed of the vehicle in [m/s].
Definition: MSInductLoop.h:277
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:263
static SUMOReal lengthSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
Definition: MSInductLoop.h:331
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:65
~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:326
bool mySplitByType
Whether additional information split by vehicle classes shall be generated.
Definition: MSInductLoop.h:342
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.
unsigned 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:254
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:345
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:77
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: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.