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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
22 // An unextended detector measuring at a fixed position on a fixed lane.
23 /****************************************************************************/
24 #pragma once
25 #include <config.h>
26 
27 #include <string>
28 #include <deque>
29 #include <map>
30 #include <functional>
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class MSLane;
39 class MSVehicle;
40 class OutputDevice;
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
62  : public MSMoveReminder, public MSDetectorFileOutput, public Parameterised {
63 public:
75  MSInductLoop(const std::string& id, MSLane* const lane,
76  double positionInMeters,
77  const std::string& vTypes,
78  const bool needLocking);
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 getEnteredNumber(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 
249  struct VehicleData {
258  VehicleData(const SUMOTrafficObject& v, double entryTimestep,
259  double leaveTimestep, const bool leftEarly);
260 
262  std::string idM;
264  double lengthM;
266  double entryTimeM;
268  double leaveTimeM;
270  double speedM;
272  std::string typeIDM;
275  };
276 
277 
285  std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t, bool includeEarly = false, bool leaveTime = false, bool forOccupancy = false) const;
286 
288  virtual void setSpecialColor(const RGBColor* /*color*/) {};
289 
290  virtual void setVisible(bool /*show*/) {};
291 
293  virtual void clearState();
294 
295 protected:
298 
300  static inline double speedSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
301  return sumSoFar + data.speedM;
302  }
303 
305  static inline double lengthSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
306  return sumSoFar + data.lengthM;
307  }
309 
310 
311 protected:
313  const double myPosition;
314 
316  const bool myNeedLock;
317 
320 
323 
325  typedef std::deque< VehicleData > VehicleDataCont;
326 
329 
332 
334  std::map<SUMOTrafficObject*, double> myVehiclesOnDet;
335 
336 private:
339 
342 
343 
344 };
long long int SUMOTime
Definition: SUMOTime.h:31
Base of value-generating classes (detectors)
An unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:62
static double lengthSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
Definition: MSInductLoop.h:305
double getOccupancy() const
Returns the current occupancy.
int myEnteredVehicleNumber
The number of entered vehicles.
Definition: MSInductLoop.h:322
std::deque< VehicleData > VehicleDataCont
Type of myVehicleDataCont.
Definition: MSInductLoop.h:325
double getEnteredNumber(const int offset) const
Returns the number of vehicles that have passed the detector.
MSInductLoop(const std::string &id, MSLane *const lane, double positionInMeters, const std::string &vTypes, const bool needLocking)
Constructor.
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
static double speedSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::speedM.
Definition: MSInductLoop.h:300
VehicleDataCont myVehicleDataCont
Data of vehicles that have completely passed the detector.
Definition: MSInductLoop.h:328
double getPosition() const
Returns the position of the detector on the lane.
Definition: MSInductLoop.h:93
MSInductLoop & operator=(const MSInductLoop &)
Invalidated assignment operator.
double getSpeed(const int offset) const
Returns the speed of the vehicle on the detector.
virtual void setSpecialColor(const RGBColor *)
allows for special color in the gui version
Definition: MSInductLoop.h:288
virtual void clearState()
Remove all vehicles before quick-loading state.
std::vector< std::string > getVehicleIDs(const int offset) const
Returns the ids of vehicles that have passed the detector.
double getVehicleLength(const int offset) const
Returns the length of the vehicle on the detector.
virtual void reset()
Resets all generated values to allow computation of next interval.
const double myPosition
Detector's position on lane [m].
Definition: MSInductLoop.h:313
VehicleDataCont myLastVehicleDataCont
Data of vehicles that have completely passed the detector in the last time interval.
Definition: MSInductLoop.h:331
~MSInductLoop()
Destructor.
MSInductLoop(const MSInductLoop &)
Invalidated copy constructor.
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "detector" as root element.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder.
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
double myLastLeaveTime
Leave-time of the last vehicle detected [s].
Definition: MSInductLoop.h:319
virtual void setVisible(bool)
Definition: MSInductLoop.h:290
const bool myNeedLock
whether internals need to be guarded against concurrent access (GUI or multi threading)
Definition: MSInductLoop.h:316
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane=0)
Checks whether the reminder is activated by a vehicle entering the lane.
std::vector< VehicleData > collectVehiclesOnDet(SUMOTime t, bool includeEarly=false, bool leaveTime=false, bool forOccupancy=false) const
Returns vehicle data for vehicles that have been on the detector starting at the given time.
std::map< SUMOTrafficObject *, double > myVehiclesOnDet
Data for vehicles that have entered the detector (vehicle -> enter time)
Definition: MSInductLoop.h:334
SUMOTime getLastDetectionTime() const
return last time a vehicle was on the detector
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.
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
An upper class for objects with additional parameters.
Definition: Parameterised.h:39
Representation of a vehicle, person, or container.
Struct to store the data of the counted vehicle internally.
Definition: MSInductLoop.h:249
double lengthM
Length of the vehicle.
Definition: MSInductLoop.h:264
double leaveTimeM
Leave-time of the vehicle in [s].
Definition: MSInductLoop.h:268
bool leftEarlyM
whether the vehicle left the detector with a lane change / teleport etc.
Definition: MSInductLoop.h:274
std::string idM
The id of the vehicle.
Definition: MSInductLoop.h:262
double entryTimeM
Entry-time of the vehicle in [s].
Definition: MSInductLoop.h:266
VehicleData(const SUMOTrafficObject &v, double entryTimestep, double leaveTimestep, const bool leftEarly)
Constructor.
double speedM
Speed of the vehicle in [m/s].
Definition: MSInductLoop.h:270
std::string typeIDM
Type of the vehicle.
Definition: MSInductLoop.h:272