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 
144 
145 
146 
149 
157  SUMOReal getCurrentSpeed() const;
158 
159 
167  SUMOReal getCurrentLength() const;
168 
169 
180 
181 
191  unsigned int getCurrentPassedNumber() const;
192 
193 
199  std::vector<std::string> getCurrentVehicleIDs() const;
200 
201 
208 
209 
210 
213 
222  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
223 
224 
231  void writeXMLDetectorProlog(OutputDevice& dev) const;
233 
234 
235 
242  struct VehicleData {
251  VehicleData(const std::string& id, SUMOReal vehLength, SUMOReal entryTimestep, SUMOReal leaveTimestep,
252  const std::string& typeID)
253  : idM(id), lengthM(vehLength), entryTimeM(entryTimestep), leaveTimeM(leaveTimestep),
254  speedM(lengthM / ((leaveTimeM - entryTimeM))), typeIDM(typeID) {}
255 
257  std::string idM;
267  std::string typeIDM;
268  };
269 
270 
276  virtual std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t) const;
277 
278 
279 protected:
282 
287  virtual void enterDetectorByMove(SUMOVehicle& veh, SUMOReal entryTimestep);
288 
289 
298  virtual void leaveDetectorByMove(SUMOVehicle& veh, SUMOReal leaveTimestep);
299 
300 
305  virtual void leaveDetectorByLaneChange(SUMOVehicle& veh, SUMOReal lastPos);
307 
308 
309 protected:
312 
314  static inline SUMOReal speedSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData& data) {
315  return sumSoFar + data.speedM;
316  }
317 
319  static inline SUMOReal lengthSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData& data) {
320  return sumSoFar + data.lengthM;
321  }
323 
324 
325 protected:
328 
331 
334 
337 
340 
341 
343  typedef std::deque< VehicleData > VehicleDataCont;
344 
347 
350 
351 
353  typedef std::map< SUMOVehicle*, SUMOReal > VehicleMap;
354 
357 
358  void writeTypedXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime,
359  const std::string& type, const VehicleDataCont& vdc, const VehicleMap& vm);
360 
361 private:
363  MSInductLoop(const MSInductLoop&);
364 
367 
368 
369 };
370 
371 
372 #endif
373 
374 /****************************************************************************/
375 
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:339
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
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:356
VehicleDataCont myLastVehicleDataCont
Data of vehicles that have completely passed the detector in the last time interval.
Definition: MSInductLoop.h:349
const SUMOReal myPosition
Detector&#39;s position on lane [m].
Definition: MSInductLoop.h:327
SUMOReal lengthM
Length of the vehicle.
Definition: MSInductLoop.h:259
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:346
SUMOReal speedM
Speed of the vehicle in [m/s].
Definition: MSInductLoop.h:265
std::deque< VehicleData > VehicleDataCont
Type of myVehicleDataCont.
Definition: MSInductLoop.h:343
VehicleData(const std::string &id, SUMOReal vehLength, SUMOReal entryTimestep, SUMOReal leaveTimestep, const std::string &typeID)
Constructor.
Definition: MSInductLoop.h:251
static SUMOReal lengthSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
Definition: MSInductLoop.h:319
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:263
SUMOReal entryTimeM
Entry-time of the vehicle in [s].
Definition: MSInductLoop.h:261
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:314
bool mySplitByType
Whether additional information split by vehicle classes shall be generated.
Definition: MSInductLoop.h:330
std::string idM
The id of the vehicle.
Definition: MSInductLoop.h:257
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:336
Struct to store the data of the counted vehicle internally.
Definition: MSInductLoop.h:242
virtual void leaveDetectorByLaneChange(SUMOVehicle &veh, SUMOReal lastPos)
Removes a vehicle from the detector&#39;s map myVehiclesOnDet.
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:215
SUMOReal myLastLeaveTime
Leave-time of the last vehicle detected [s].
Definition: MSInductLoop.h:333
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: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:353
Base of value-generating classes (detectors)
std::string typeIDM
Type of the vehicle in.
Definition: MSInductLoop.h:267
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.