SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
14 // Copyright (C) 2004-2014 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 
348 
351 
352 
354  typedef std::map< SUMOVehicle*, SUMOReal > VehicleMap;
355 
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