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-2015 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 
124  bool notifyMove(SUMOVehicle& veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed);
125 
126 
141  bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, MSMoveReminder::Notification reason);
142 
143 
145 
146 
147 
150 
158  SUMOReal getCurrentSpeed() const;
159 
160 
168  SUMOReal getCurrentLength() const;
169 
170 
181 
182 
192  unsigned int getCurrentPassedNumber() const;
193 
194 
200  std::vector<std::string> getCurrentVehicleIDs() const;
201 
202 
209 
210 
211 
214 
223  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
224 
225 
232  void writeXMLDetectorProlog(OutputDevice& dev) const;
234 
235 
236 
243  struct VehicleData {
252  VehicleData(const std::string& id, SUMOReal vehLength, SUMOReal entryTimestep, SUMOReal leaveTimestep,
253  const std::string& typeID)
254  : idM(id), lengthM(vehLength), entryTimeM(entryTimestep), leaveTimeM(leaveTimestep),
255  speedM(vehLength / MAX2(leaveTimestep - entryTimestep, NUMERICAL_EPS)), typeIDM(typeID) {}
256 
258  std::string idM;
268  std::string typeIDM;
269  };
270 
271 
277  virtual std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t) const;
278 
279 
280 protected:
283 
288  virtual void enterDetectorByMove(SUMOVehicle& veh, SUMOReal entryTimestep);
289 
290 
299  virtual void leaveDetectorByMove(SUMOVehicle& veh, SUMOReal leaveTimestep);
300 
301 
306  virtual void leaveDetectorByLaneChange(SUMOVehicle& veh, SUMOReal lastPos);
308 
309 
310 protected:
313 
315  static inline SUMOReal speedSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData& data) {
316  return sumSoFar + data.speedM;
317  }
318 
320  static inline SUMOReal lengthSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData& data) {
321  return sumSoFar + data.lengthM;
322  }
324 
325 
326 protected:
329 
332 
335 
338 
341 
342 
344  typedef std::deque< VehicleData > VehicleDataCont;
345 
347  VehicleDataCont myVehicleDataCont;
348 
350  VehicleDataCont myLastVehicleDataCont;
351 
352 
354  typedef std::map< SUMOVehicle*, SUMOReal > VehicleMap;
355 
357  VehicleMap myVehiclesOnDet;
358 
359  void writeTypedXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime,
360  const std::string& type, const VehicleDataCont& vdc, const VehicleMap& vm);
361 
362 private:
364  MSInductLoop(const MSInductLoop&);
365 
368 
369 
370 };
371 
372 
373 #endif
374 
375 /****************************************************************************/
376 
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:340
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:79
SUMOReal getCurrentOccupancy() const
Returns the current occupancy.
VehicleMap myVehiclesOnDet
Data for vehicles that have entered the detector (vehicle -> enter time)
Definition: MSInductLoop.h:357
VehicleDataCont myLastVehicleDataCont
Data of vehicles that have completely passed the detector in the last time interval.
Definition: MSInductLoop.h:350
const SUMOReal myPosition
Detector&#39;s position on lane [m].
Definition: MSInductLoop.h:328
SUMOReal lengthM
Length of the vehicle.
Definition: MSInductLoop.h:260
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:347
SUMOReal speedM
Speed of the vehicle in [m/s].
Definition: MSInductLoop.h:266
std::deque< VehicleData > VehicleDataCont
Type of myVehicleDataCont.
Definition: MSInductLoop.h:344
VehicleData(const std::string &id, SUMOReal vehLength, SUMOReal entryTimestep, SUMOReal leaveTimestep, const std::string &typeID)
Constructor.
Definition: MSInductLoop.h:252
static SUMOReal lengthSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
Definition: MSInductLoop.h:320
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:264
SUMOReal entryTimeM
Entry-time of the vehicle in [s].
Definition: MSInductLoop.h:262
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:315
bool mySplitByType
Whether additional information split by vehicle classes shall be generated.
Definition: MSInductLoop.h:331
std::string idM
The id of the vehicle.
Definition: MSInductLoop.h:258
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:337
Struct to store the data of the counted vehicle internally.
Definition: MSInductLoop.h:243
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:214
SUMOReal myLastLeaveTime
Leave-time of the last vehicle detected [s].
Definition: MSInductLoop.h:334
void writeTypedXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime, const std::string &type, const VehicleDataCont &vdc, const VehicleMap &vm)
#define NUMERICAL_EPS
Definition: config.h:161
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:354
Base of value-generating classes (detectors)
std::string typeIDM
Type of the vehicle in.
Definition: MSInductLoop.h:268
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.