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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
19 // An unextended detector measuring at a fixed position on a fixed lane.
20 /****************************************************************************/
21 #ifndef MSInductLoop_h
22 #define MSInductLoop_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #include <config.h>
29 
30 #include <string>
31 #include <deque>
32 #include <map>
33 #include <functional>
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
41 class MSLane;
42 class MSVehicle;
43 class OutputDevice;
44 
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
65  : public MSMoveReminder, public MSDetectorFileOutput {
66 public:
77  MSInductLoop(const std::string& id, MSLane* const lane,
78  double positionInMeters,
79  const std::string& vTypes);
80 
81 
83  ~MSInductLoop();
84 
85 
88  virtual void reset();
89 
90 
94  double getPosition() const {
95  return myPosition;
96  }
97 
98 
101 
111  bool notifyEnter(SUMOVehicle& veh, Notification reason, const MSLane* enteredLane = 0);
112 
129  bool notifyMove(SUMOVehicle& veh, double oldPos, double newPos, double newSpeed);
130 
131 
146  bool notifyLeave(SUMOVehicle& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
147 
148 
150 
151 
152 
155 
163  double getCurrentSpeed() const;
164 
165 
173  double getCurrentLength() const;
174 
175 
185  double getCurrentOccupancy() const;
186 
187 
197  int getCurrentPassedNumber() const;
198 
199 
205  std::vector<std::string> getCurrentVehicleIDs() const;
206 
207 
212  double getTimeSinceLastDetection() const;
214 
215 
216 
219 
228  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
229 
230 
237  void writeXMLDetectorProlog(OutputDevice& dev) const;
239 
240 
241 
248  struct VehicleData {
257  VehicleData(const std::string& id, double vehLength, double entryTimestep, double leaveTimestep,
258  const std::string& typeID)
259  : idM(id), lengthM(vehLength), entryTimeM(entryTimestep), leaveTimeM(leaveTimestep),
260  speedM(vehLength / MAX2(leaveTimestep - entryTimestep, NUMERICAL_EPS)), typeIDM(typeID) {}
261 
263  std::string idM;
265  double lengthM;
267  double entryTimeM;
269  double leaveTimeM;
271  double speedM;
273  std::string typeIDM;
274  };
275 
276 
284  virtual std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t, bool leaveTime = false) const;
285 
286 
287 protected:
290 
295  virtual void enterDetectorByMove(SUMOVehicle& veh, double entryTimestep);
296 
297 
306  virtual void leaveDetectorByMove(SUMOVehicle& veh, double leaveTimestep);
307 
308 
313  virtual void leaveDetectorByLaneChange(SUMOVehicle& veh, double lastPos);
315 
316 
317 protected:
320 
322  static inline double speedSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
323  return sumSoFar + data.speedM;
324  }
325 
327  static inline double lengthSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
328  return sumSoFar + data.lengthM;
329  }
331 
332 
333 protected:
335  const double myPosition;
336 
339 
342 
345 
346 
348  typedef std::deque< VehicleData > VehicleDataCont;
349 
351  VehicleDataCont myVehicleDataCont;
352 
354  VehicleDataCont myLastVehicleDataCont;
355 
356 
358 
359  typedef std::map< SUMOVehicle*, double > VehicleMap;
360 
362  VehicleMap myVehiclesOnDet;
363 
364 private:
366  MSInductLoop(const MSInductLoop&);
367 
370 
371 
372 };
373 
374 
375 #endif
376 
377 /****************************************************************************/
378 
const double myPosition
Detector&#39;s position on lane [m].
Definition: MSInductLoop.h:335
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:79
long long int SUMOTime
Definition: SUMOTime.h:36
std::map< SUMOVehicle *, double > VehicleMap
Type of myVehiclesOnDet.
Definition: MSInductLoop.h:359
double myLastOccupancy
Occupancy by the last vehicle detected.
Definition: MSInductLoop.h:341
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:322
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:76
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:362
double speedM
Speed of the vehicle in [m/s].
Definition: MSInductLoop.h:271
VehicleDataCont myLastVehicleDataCont
Data of vehicles that have completely passed the detector in the last time interval.
Definition: MSInductLoop.h:354
VehicleDataCont myVehicleDataCont
Data of vehicles that have completely passed the detector.
Definition: MSInductLoop.h:351
std::deque< VehicleData > VehicleDataCont
Type of myVehicleDataCont.
Definition: MSInductLoop.h:348
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:267
VehicleData(const std::string &id, double vehLength, double entryTimestep, double leaveTimestep, const std::string &typeID)
Constructor.
Definition: MSInductLoop.h:257
Representation of a vehicle.
Definition: SUMOVehicle.h:60
~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:94
double lengthM
Length of the vehicle.
Definition: MSInductLoop.h:265
std::string idM
The id of the vehicle.
Definition: MSInductLoop.h:263
Something on a lane to be noticed about vehicle movement.
double leaveTimeM
Leave-time of the vehicle in [s].
Definition: MSInductLoop.h:269
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:344
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:248
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:64
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...
#define NUMERICAL_EPS
Definition: config.h:148
double getCurrentOccupancy() const
Returns the current occupancy.
double myLastLeaveTime
Leave-time of the last vehicle detected [s].
Definition: MSInductLoop.h:338
Representation of a lane in the micro simulation.
Definition: MSLane.h:78
static double lengthSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
Definition: MSInductLoop.h:327
Base of value-generating classes (detectors)
std::string typeIDM
Type of the vehicle in.
Definition: MSInductLoop.h:273
An unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:64