SUMO - Simulation of Urban MObility
MSInductLoop.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2004-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
21 // An unextended detector measuring at a fixed position on a fixed lane.
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  double positionInMeters,
85  const std::string& vTypes);
86 
87 
89  ~MSInductLoop();
90 
91 
94  virtual void reset();
95 
96 
100  double getPosition() const {
101  return myPosition;
102  }
103 
104 
107 
117  bool notifyEnter(SUMOVehicle& veh, Notification reason, const MSLane* enteredLane = 0);
118 
135  bool notifyMove(SUMOVehicle& veh, double oldPos, double newPos, double newSpeed);
136 
137 
152  bool notifyLeave(SUMOVehicle& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
153 
154 
156 
157 
158 
161 
169  double getCurrentSpeed() const;
170 
171 
179  double getCurrentLength() const;
180 
181 
191  double getCurrentOccupancy() const;
192 
193 
203  int getCurrentPassedNumber() const;
204 
205 
211  std::vector<std::string> getCurrentVehicleIDs() const;
212 
213 
218  double getTimeSinceLastDetection() const;
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, double vehLength, double entryTimestep, double 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;
271  double lengthM;
273  double entryTimeM;
275  double leaveTimeM;
277  double speedM;
279  std::string typeIDM;
280  };
281 
282 
290  virtual std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t, bool leaveTime = false) const;
291 
292 
293 protected:
296 
301  virtual void enterDetectorByMove(SUMOVehicle& veh, double entryTimestep);
302 
303 
312  virtual void leaveDetectorByMove(SUMOVehicle& veh, double leaveTimestep);
313 
314 
319  virtual void leaveDetectorByLaneChange(SUMOVehicle& veh, double lastPos);
321 
322 
323 protected:
326 
328  static inline double speedSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
329  return sumSoFar + data.speedM;
330  }
331 
333  static inline double lengthSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
334  return sumSoFar + data.lengthM;
335  }
337 
338 
339 protected:
341  const double myPosition;
342 
345 
348 
351 
352 
354  typedef std::deque< VehicleData > VehicleDataCont;
355 
357  VehicleDataCont myVehicleDataCont;
358 
360  VehicleDataCont myLastVehicleDataCont;
361 
362 
364 
365  typedef std::map< SUMOVehicle*, double > VehicleMap;
366 
368  VehicleMap myVehiclesOnDet;
369 
370 private:
372  MSInductLoop(const MSInductLoop&);
373 
376 
377 
378 };
379 
380 
381 #endif
382 
383 /****************************************************************************/
384 
const double myPosition
Detector&#39;s position on lane [m].
Definition: MSInductLoop.h:341
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
std::map< SUMOVehicle *, double > VehicleMap
Type of myVehiclesOnDet.
Definition: MSInductLoop.h:365
double myLastOccupancy
Occupancy by the last vehicle detected.
Definition: MSInductLoop.h:347
std::vector< std::string > getCurrentVehicleIDs() const
Returns the ids of vehicles that have passed the detector.
virtual void leaveDetectorByLaneChange(SUMOVehicle &veh, double lastPos)
Removes a vehicle from the detector&#39;s map myVehiclesOnDet.
virtual void reset()
Resets all generated values to allow computation of next interval.
bool notifyLeave(SUMOVehicle &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Dismisses the vehicle if it is on the detector due to a lane change.
static double speedSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::speedM.
Definition: MSInductLoop.h:328
virtual void leaveDetectorByMove(SUMOVehicle &veh, double leaveTimestep)
Processes a vehicle that leaves the detector.
Notification
Definition of a vehicle state.
T MAX2(T a, T b)
Definition: StdDefs.h:73
double getCurrentLength() const
Returns the length of the vehicle on the detector.
VehicleMap myVehiclesOnDet
Data for vehicles that have entered the detector (vehicle -> enter time)
Definition: MSInductLoop.h:368
double speedM
Speed of the vehicle in [m/s].
Definition: MSInductLoop.h:277
VehicleDataCont myLastVehicleDataCont
Data of vehicles that have completely passed the detector in the last time interval.
Definition: MSInductLoop.h:360
VehicleDataCont myVehicleDataCont
Data of vehicles that have completely passed the detector.
Definition: MSInductLoop.h:357
std::deque< VehicleData > VehicleDataCont
Type of myVehicleDataCont.
Definition: MSInductLoop.h:354
MSInductLoop & operator=(const MSInductLoop &)
Invalidated assignment operator.
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "detector" as root element.
double entryTimeM
Entry-time of the vehicle in [s].
Definition: MSInductLoop.h:273
VehicleData(const std::string &id, double vehLength, double entryTimestep, double leaveTimestep, const std::string &typeID)
Constructor.
Definition: MSInductLoop.h:263
Representation of a vehicle.
Definition: SUMOVehicle.h:66
~MSInductLoop()
Destructor.
virtual void enterDetectorByMove(SUMOVehicle &veh, double entryTimestep)
Introduces a vehicle to the detector&#39;s map myVehiclesOnDet.
double getCurrentSpeed() const
Returns the speed of the vehicle on the detector.
double getPosition() const
Returns the position of the detector on the lane.
Definition: MSInductLoop.h:100
double lengthM
Length of the vehicle.
Definition: MSInductLoop.h:271
std::string idM
The id of the vehicle.
Definition: MSInductLoop.h:269
Something on a lane to be noticed about vehicle movement.
double leaveTimeM
Leave-time of the vehicle in [s].
Definition: MSInductLoop.h:275
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
MSInductLoop(const std::string &id, MSLane *const lane, double positionInMeters, const std::string &vTypes)
Constructor.
int myEnteredVehicleNumber
The number of entered vehicles.
Definition: MSInductLoop.h:350
bool notifyEnter(SUMOVehicle &veh, Notification reason, const MSLane *enteredLane=0)
Checks whether the reminder is activated by a vehicle entering the lane.
int getCurrentPassedNumber() const
Returns the number of vehicles that have passed the detector.
Struct to store the data of the counted vehicle internally.
Definition: MSInductLoop.h:254
bool notifyMove(SUMOVehicle &veh, double oldPos, double newPos, double newSpeed)
Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
virtual std::vector< VehicleData > collectVehiclesOnDet(SUMOTime t, bool leaveTime=false) const
Returns vehicle data for vehicles that have been on the detector starting at the given time...
long long int SUMOTime
Definition: TraCIDefs.h:51
#define NUMERICAL_EPS
Definition: config.h:151
double getCurrentOccupancy() const
Returns the current occupancy.
double myLastLeaveTime
Leave-time of the last vehicle detected [s].
Definition: MSInductLoop.h:344
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
static double lengthSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
Definition: MSInductLoop.h:333
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:70