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 /****************************************************************************/
10 // An unextended detector measuring at a fixed position on a fixed lane.
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 #ifndef MSInductLoop_h
24 #define MSInductLoop_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <string>
37 #include <deque>
38 #include <map>
39 #include <functional>
42 
43 
44 // ===========================================================================
45 // class declarations
46 // ===========================================================================
47 class MSLane;
48 class MSVehicle;
49 class OutputDevice;
50 
51 
52 // ===========================================================================
53 // class definitions
54 // ===========================================================================
71  : public MSMoveReminder, public MSDetectorFileOutput {
72 public:
83  MSInductLoop(const std::string& id, MSLane* const lane,
84  SUMOReal positionInMeters, bool splitByType);
85 
86 
88  ~MSInductLoop();
89 
90 
93  virtual void reset();
94 
95 
100  return myPosition;
101  }
102 
103 
106 
123  bool notifyMove(SUMOVehicle& veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed);
124 
125 
140  bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, MSMoveReminder::Notification reason);
141 
142 
158 
159 
160 
163 
171  SUMOReal getCurrentSpeed() const;
172 
173 
181  SUMOReal getCurrentLength() const;
182 
183 
194 
195 
205  unsigned int getCurrentPassedNumber() const;
206 
207 
213  std::vector<std::string> getCurrentVehicleIDs() const;
214 
215 
222 
223 
224 
227 
236  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
237 
238 
245  void writeXMLDetectorProlog(OutputDevice& dev) const;
247 
248 
249 
256  struct VehicleData {
265  VehicleData(const std::string& id, SUMOReal vehLength, SUMOReal entryTimestep, SUMOReal leaveTimestep,
266  const std::string& typeID)
267  : idM(id), lengthM(vehLength), entryTimeM(entryTimestep), leaveTimeM(leaveTimestep),
268  speedM(lengthM / ((leaveTimeM - entryTimeM))), typeIDM(typeID) {}
269 
271  std::string idM;
281  std::string typeIDM;
282  };
283 
284 
290  virtual std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t) 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 
318  virtual void leaveDetectorByLaneChange(SUMOVehicle& veh);
320 
321 
322 protected:
325 
327  static inline SUMOReal speedSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData& data) {
328  return sumSoFar + data.speedM;
329  }
330 
332  static inline SUMOReal lengthSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData& data) {
333  return sumSoFar + data.lengthM;
334  }
336 
337 
338 protected:
341 
344 
347 
350 
353 
354 
356  typedef std::deque< VehicleData > VehicleDataCont;
357 
360 
363 
364 
366  typedef std::map< SUMOVehicle*, SUMOReal > VehicleMap;
367 
370 
371  void writeTypedXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime,
372  const std::string& type, const VehicleDataCont& vdc, const VehicleMap& vm);
373 
374 private:
376  MSInductLoop(const MSInductLoop&);
377 
380 
381 
382 };
383 
384 
385 #endif
386 
387 /****************************************************************************/
388 
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:352
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
virtual void leaveDetectorByLaneChange(SUMOVehicle &veh)
Removes a vehicle from the detector&#39;s map myVehiclesOnDet.
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:99
virtual std::vector< VehicleData > collectVehiclesOnDet(SUMOTime t) 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 -&gt; enter time)
Definition: MSInductLoop.h:369
VehicleDataCont myLastVehicleDataCont
Data of vehicles that have completely passed the detector in the last time interval.
Definition: MSInductLoop.h:362
const SUMOReal myPosition
Detector&#39;s position on lane [m].
Definition: MSInductLoop.h:340
SUMOReal lengthM
Length of the vehicle.
Definition: MSInductLoop.h:273
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using &quot;detector&quot; as root element.
VehicleDataCont myVehicleDataCont
Data of vehicles that have completely passed the detector.
Definition: MSInductLoop.h:359
SUMOReal speedM
Speed of the vehicle in [m/s].
Definition: MSInductLoop.h:279
std::deque< VehicleData > VehicleDataCont
Type of myVehicleDataCont.
Definition: MSInductLoop.h:356
VehicleData(const std::string &id, SUMOReal vehLength, SUMOReal entryTimestep, SUMOReal leaveTimestep, const std::string &typeID)
Constructor.
Definition: MSInductLoop.h:265
static SUMOReal lengthSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
Definition: MSInductLoop.h:332
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:277
SUMOReal entryTimeM
Entry-time of the vehicle in [s].
Definition: MSInductLoop.h:275
Representation of a vehicle.
Definition: SUMOVehicle.h:63
~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:327
bool mySplitByType
Whether additional information split by vehicle classes shall be generated.
Definition: MSInductLoop.h:343
std::string idM
The id of the vehicle.
Definition: MSInductLoop.h:271
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:349
Struct to store the data of the counted vehicle internally.
Definition: MSInductLoop.h:256
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Returns whether the detector may has to be concerned during the vehicle&#39;s further movement...
int SUMOTime
Definition: SUMOTime.h:43
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:70
#define SUMOReal
Definition: config.h:221
SUMOReal myLastLeaveTime
Leave-time of the last vehicle detected [s].
Definition: MSInductLoop.h:346
void writeTypedXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime, const std::string &type, const VehicleDataCont &vdc, const VehicleMap &vm)
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:73
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:366
Base of value-generating classes (detectors)
std::string typeIDM
Type of the vehicle in.
Definition: MSInductLoop.h:281
An unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:70
bool notifyMove(SUMOVehicle &veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed)
Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder.