Eclipse 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-2019 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 /****************************************************************************/
18 // An unextended detector measuring at a fixed position on a fixed lane.
19 /****************************************************************************/
20 #ifndef MSInductLoop_h
21 #define MSInductLoop_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <string>
30 #include <deque>
31 #include <map>
32 #include <functional>
35 
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 class MSLane;
41 class MSVehicle;
42 class OutputDevice;
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
64  : public MSMoveReminder, public MSDetectorFileOutput {
65 public:
76  MSInductLoop(const std::string& id, MSLane* const lane,
77  double positionInMeters,
78  const std::string& vTypes);
79 
80 
82  ~MSInductLoop();
83 
84 
87  virtual void reset();
88 
89 
93  double getPosition() const {
94  return myPosition;
95  }
96 
97 
100 
110  bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane = 0);
111 
128  bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
129 
130 
145  bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
146 
147 
149 
150 
151 
154 
162  double getSpeed(const int offset) const;
163 
164 
172  double getVehicleLength(const int offset) const;
173 
174 
184  double getOccupancy() const;
185 
186 
196  double getPassedNumber(const int offset) const;
197 
198 
204  std::vector<std::string> getVehicleIDs(const int offset) const;
205 
206 
211  double getTimeSinceLastDetection() const;
212 
216 
217 
218 
221 
230  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
231 
232 
239  void writeXMLDetectorProlog(OutputDevice& dev) const;
241 
242 
243 
250  struct VehicleData {
259  VehicleData(const std::string& id, double vehLength, double entryTimestep, double leaveTimestep,
260  const std::string& typeID)
261  : idM(id), lengthM(vehLength), entryTimeM(entryTimestep), leaveTimeM(leaveTimestep),
262  speedM(vehLength / MAX2(leaveTimestep - entryTimestep, NUMERICAL_EPS)), typeIDM(typeID) {}
263 
265  std::string idM;
267  double lengthM;
269  double entryTimeM;
271  double leaveTimeM;
273  double speedM;
275  std::string typeIDM;
276  };
277 
278 
286  virtual std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t, bool leaveTime = false) const;
287 
289  virtual void setSpecialColor(const RGBColor* /*color*/) {};
290 
291  virtual void setVisible(bool /*show*/) {};
292 
293 protected:
296 
301  virtual void enterDetectorByMove(SUMOTrafficObject& veh, double entryTimestep);
302 
303 
312  virtual void leaveDetectorByMove(SUMOTrafficObject& veh, double leaveTimestep);
313 
314 
319  virtual void leaveDetectorByLaneChange(SUMOTrafficObject& 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 
350  typedef std::deque< VehicleData > VehicleDataCont;
351 
354 
357 
359  std::map<SUMOTrafficObject*, double> myVehiclesOnDet;
360 
361 private:
363  MSInductLoop(const MSInductLoop&);
364 
367 
368 
369 };
370 
371 
372 #endif
373 
374 /****************************************************************************/
375 
MSInductLoop::VehicleData::VehicleData
VehicleData(const std::string &id, double vehLength, double entryTimestep, double leaveTimestep, const std::string &typeID)
Constructor.
Definition: MSInductLoop.h:259
SUMOTrafficObject
Representation of a vehicle or person.
Definition: SUMOTrafficObject.h:47
MSInductLoop::getPosition
double getPosition() const
Returns the position of the detector on the lane.
Definition: MSInductLoop.h:93
MSDetectorFileOutput
Base of value-generating classes (detectors)
Definition: MSDetectorFileOutput.h:63
MSInductLoop::myLastLeaveTime
double myLastLeaveTime
Leave-time of the last vehicle detected [s].
Definition: MSInductLoop.h:344
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSInductLoop::VehicleData
Struct to store the data of the counted vehicle internally.
Definition: MSInductLoop.h:250
MSInductLoop::getVehicleLength
double getVehicleLength(const int offset) const
Returns the length of the vehicle on the detector.
Definition: MSInductLoop.cpp:157
MSInductLoop::VehicleDataCont
std::deque< VehicleData > VehicleDataCont
Type of myVehicleDataCont.
Definition: MSInductLoop.h:350
MSInductLoop::enterDetectorByMove
virtual void enterDetectorByMove(SUMOTrafficObject &veh, double entryTimestep)
Introduces a vehicle to the detector's map myVehiclesOnDet.
Definition: MSInductLoop.cpp:253
MSInductLoop::lengthSum
static double lengthSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
Definition: MSInductLoop.h:333
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
NUMERICAL_EPS
#define NUMERICAL_EPS
Definition: config.h:148
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSInductLoop::VehicleData::typeIDM
std::string typeIDM
Type of the vehicle in.
Definition: MSInductLoop.h:275
MSInductLoop
An unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:63
MSInductLoop::notifyEnter
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane=0)
Checks whether the reminder is activated by a vehicle entering the lane.
Definition: MSInductLoop.cpp:75
MSInductLoop::getTimeSinceLastDetection
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
Definition: MSInductLoop.cpp:195
MSDetectorFileOutput.h
MSInductLoop::leaveDetectorByLaneChange
virtual void leaveDetectorByLaneChange(SUMOTrafficObject &veh, double lastPos)
Removes a vehicle from the detector's map myVehiclesOnDet.
Definition: MSInductLoop.cpp:274
MSInductLoop::VehicleData::idM
std::string idM
The id of the vehicle.
Definition: MSInductLoop.h:265
MSMoveReminder
Something on a lane to be noticed about vehicle movement.
Definition: MSMoveReminder.h:66
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
RGBColor
Definition: RGBColor.h:39
MSMoveReminder.h
MSInductLoop::VehicleData::speedM
double speedM
Speed of the vehicle in [m/s].
Definition: MSInductLoop.h:273
MSInductLoop::leaveDetectorByMove
virtual void leaveDetectorByMove(SUMOTrafficObject &veh, double leaveTimestep)
Processes a vehicle that leaves the detector.
Definition: MSInductLoop.cpp:260
MSInductLoop::setSpecialColor
virtual void setSpecialColor(const RGBColor *)
allows for special color in the gui version
Definition: MSInductLoop.h:289
MSInductLoop::VehicleData::lengthM
double lengthM
Length of the vehicle.
Definition: MSInductLoop.h:267
MSInductLoop::getVehicleIDs
std::vector< std::string > getVehicleIDs(const int offset) const
Returns the ids of vehicles that have passed the detector.
Definition: MSInductLoop.cpp:184
MSInductLoop::speedSum
static double speedSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::speedM.
Definition: MSInductLoop.h:328
MSInductLoop::collectVehiclesOnDet
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.
Definition: MSInductLoop.cpp:281
MSInductLoop::notifyMove
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder.
Definition: MSInductLoop.cpp:93
MSInductLoop::setVisible
virtual void setVisible(bool)
Definition: MSInductLoop.h:291
MSInductLoop::getPassedNumber
double getPassedNumber(const int offset) const
Returns the number of vehicles that have passed the detector.
Definition: MSInductLoop.cpp:178
MSInductLoop::myVehiclesOnDet
std::map< SUMOTrafficObject *, double > myVehiclesOnDet
Data for vehicles that have entered the detector (vehicle -> enter time)
Definition: MSInductLoop.h:359
MSInductLoop::notifyLeave
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Dismisses the vehicle if it is on the detector due to a lane change.
Definition: MSInductLoop.cpp:140
MSInductLoop::VehicleData::leaveTimeM
double leaveTimeM
Leave-time of the vehicle in [s].
Definition: MSInductLoop.h:271
MSInductLoop::myLastVehicleDataCont
VehicleDataCont myLastVehicleDataCont
Data of vehicles that have completely passed the detector in the last time interval.
Definition: MSInductLoop.h:356
MSInductLoop::getSpeed
double getSpeed(const int offset) const
Returns the speed of the vehicle on the detector.
Definition: MSInductLoop.cpp:150
config.h
MSInductLoop::~MSInductLoop
~MSInductLoop()
Destructor.
Definition: MSInductLoop.cpp:62
MSInductLoop::myPosition
const double myPosition
Detector's position on lane [m].
Definition: MSInductLoop.h:341
MSInductLoop::writeXMLOutput
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
Definition: MSInductLoop.cpp:220
MSInductLoop::getOccupancy
double getOccupancy() const
Returns the current occupancy.
Definition: MSInductLoop.cpp:164
MSInductLoop::getLastDetectionTime
SUMOTime getLastDetectionTime() const
return last time a vehicle was on the detector
Definition: MSInductLoop.cpp:205
MSInductLoop::MSInductLoop
MSInductLoop(const std::string &id, MSLane *const lane, double positionInMeters, const std::string &vTypes)
Constructor.
Definition: MSInductLoop.cpp:48
MSInductLoop::myVehicleDataCont
VehicleDataCont myVehicleDataCont
Data of vehicles that have completely passed the detector.
Definition: MSInductLoop.h:353
MSInductLoop::myEnteredVehicleNumber
int myEnteredVehicleNumber
The number of entered vehicles.
Definition: MSInductLoop.h:347
MSMoveReminder::Notification
Notification
Definition of a vehicle state.
Definition: MSMoveReminder.h:91
MSInductLoop::reset
virtual void reset()
Resets all generated values to allow computation of next interval.
Definition: MSInductLoop.cpp:67
MSInductLoop::operator=
MSInductLoop & operator=(const MSInductLoop &)
Invalidated assignment operator.
MSInductLoop::writeXMLDetectorProlog
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "detector" as root element.
Definition: MSInductLoop.cpp:214
MSInductLoop::VehicleData::entryTimeM
double entryTimeM
Entry-time of the vehicle in [s].
Definition: MSInductLoop.h:269
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79