Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSInductLoop.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2004-2023 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// ===========================================================================
38class MSLane;
39class MSVehicle;
40class OutputDevice;
41
42
43// ===========================================================================
44// class definitions
45// ===========================================================================
62 : public MSMoveReminder, public MSDetectorFileOutput {
63public:
75 MSInductLoop(const std::string& id, MSLane* const lane,
76 double positionInMeters,
77 double length, std::string name,
78 const std::string& vTypes,
79 const std::string& nextEdges,
80 int detectPersons,
81 const bool needLocking);
82
83
86
87
89 virtual void reset();
90
92 std::string getName() const {
93 return myName;
94 }
95
99 double getPosition() const {
100 return myPosition;
101 }
102
106 double getEndPosition() const {
107 return myEndPosition;
108 }
109
110
113
123 bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane = 0);
124
141 bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
142
143
158 bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
159
160
162
163
164
167
175 double getSpeed(const int offset) const;
176
177
185 double getVehicleLength(const int offset) const;
186
187
197 double getOccupancy() const;
198
208 double getEnteredNumber(const int offset) const;
209
210
216 std::vector<std::string> getVehicleIDs(const int offset) const;
217
218 double getIntervalOccupancy(bool lastInterval = false) const;
219 double getIntervalMeanSpeed(bool lastInterval = false) const;
220 int getIntervalVehicleNumber(bool lastInterval = false) const;
221 std::vector<std::string> getIntervalVehicleIDs(bool lastInterval = false) const;
222
227 double getTimeSinceLastDetection() const;
228
232 double getOccupancyTime() const;
233
236
237 double getOverrideTime() const {
238 return myOverrideTime;
239 }
241
242
243 /* @brief Persistently overrides the measured time since detection with the given value.
244 * Setting a negative value resets the override
245 */
246 void overrideTimeSinceDetection(double time);
247
250
259 void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
260
261
268 void writeXMLDetectorProlog(OutputDevice& dev) const;
269
275 void detectorUpdate(const SUMOTime step);
277
278
285 struct VehicleData {
294 VehicleData(const SUMOTrafficObject& v, double entryTimestep,
295 double leaveTimestep, const bool leftEarly);
296
298 std::string idM;
300 double lengthM;
306 double speedM;
308 std::string typeIDM;
311 };
312
313
321 std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t, bool includeEarly = false, bool leaveTime = false, bool forOccupancy = false, bool lastInterval = false) const;
322
324 virtual void setSpecialColor(const RGBColor* /*color*/) {};
325
326 virtual void setVisible(bool /*show*/) {};
327
329 virtual void clearState(SUMOTime time);
330
331protected:
334
336 static inline double speedSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
337 return sumSoFar + data.speedM;
338 }
339
341 static inline double lengthSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
342 return sumSoFar + data.lengthM;
343 }
345
347 void notifyMovePerson(MSTransportable* p, int dir, double pos);
348
349protected:
351 std::string myName;
352
354 const double myPosition;
355
357 const double myEndPosition;
358
360 const bool myNeedLock;
361
364
367
370
373
375 typedef std::deque< VehicleData > VehicleDataCont;
376
379
382
384 std::map<SUMOTrafficObject*, double> myVehiclesOnDet;
385
388
389private:
392
395
396
397};
long long int SUMOTime
Definition GUI.h:36
Base of value-generating classes (detectors)
An unextended detector measuring at a fixed position on a fixed lane.
double getOccupancyTime() const
Returns the time of continous occupation by the same vehicle in seconds or 0 if there is no vehicle o...
static double lengthSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::lengthM.
double getOccupancy() const
Returns the current occupancy.
double getIntervalOccupancy(bool lastInterval=false) const
std::vector< std::string > getIntervalVehicleIDs(bool lastInterval=false) const
int myEnteredVehicleNumber
The number of entered vehicles.
std::deque< VehicleData > VehicleDataCont
Type of myVehicleDataCont.
double getEnteredNumber(const int offset) const
Returns the number of vehicles that have passed the detector.
int getIntervalVehicleNumber(bool lastInterval=false) const
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.
std::vector< VehicleData > collectVehiclesOnDet(SUMOTime t, bool includeEarly=false, bool leaveTime=false, bool forOccupancy=false, bool lastInterval=false) const
Returns vehicle data for vehicles that have been on the detector starting at the given time.
VehicleDataCont myVehicleDataCont
Data of vehicles that have completely passed the detector.
double getEndPosition() const
Returns the end position of the detector on the lane.
double getPosition() const
Returns the position of the detector on the lane.
void overrideTimeSinceDetection(double time)
double myOverrideEntryTime
records the time at which overrideTimeSinceDetection was activated
double getSpeed(const int offset) const
Returns the speed of the vehicle on the detector.
SUMOTime myLastIntervalEnd
virtual void setSpecialColor(const RGBColor *)
allows for special color in the gui version
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.
SUMOTime myLastIntervalBegin
virtual void reset()
Resets all generated values to allow computation of next interval.
const double myPosition
Detector's position on lane [m].
std::string getName() const
get name
double getOverrideTime() const
VehicleDataCont myLastVehicleDataCont
Data of vehicles that have completely passed the detector in the last time interval.
const double myEndPosition
Detector's end position (defaults to myPosition)
~MSInductLoop()
Destructor.
MSInductLoop(const MSInductLoop &)
Invalidated copy constructor.
std::string myName
detecto name
void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "detector" as root element.
void detectorUpdate(const SUMOTime step)
Updates the detector (computes values) only used when detecting persons.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder.
void notifyMovePerson(MSTransportable *p, int dir, double pos)
helper function for mapping person movement
double myOverrideTime
overrides the time since last detection
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
double myLastLeaveTime
Leave-time of the last vehicle detected [s].
virtual void setVisible(bool)
MSInductLoop & operator=(const MSInductLoop &)
Invalidated assignment operator.
const bool myNeedLock
whether internals need to be guarded against concurrent access (GUI or multi threading)
double getIntervalMeanSpeed(bool lastInterval=false) const
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane=0)
Checks whether the reminder is activated by a vehicle entering the lane.
virtual void clearState(SUMOTime time)
Remove all vehicles before quick-loading state.
std::map< SUMOTrafficObject *, double > myVehiclesOnDet
Data for vehicles that have entered the detector (vehicle -> enter time)
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:84
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.
Representation of a vehicle, person, or container.
Struct to store the data of the counted vehicle internally.
double lengthM
Length of the vehicle.
double leaveTimeM
Leave-time of the vehicle in [s].
bool leftEarlyM
whether the vehicle left the detector with a lane change / teleport etc.
std::string idM
The id of the vehicle.
double entryTimeM
Entry-time of the vehicle in [s].
double speedM
Speed of the vehicle in [m/s].
std::string typeIDM
Type of the vehicle.