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-2026 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/****************************************************************************/
23// An unextended detector measuring at a fixed position on a fixed lane.
24/****************************************************************************/
25#pragma once
26#include <config.h>
27
28#include <string>
29#include <deque>
30#include <map>
31#include <queue>
32#include <functional>
35
36
37// ===========================================================================
38// class declarations
39// ===========================================================================
40class MSLane;
41class MESegment;
42class MSVehicle;
43class OutputDevice;
44
45
46// ===========================================================================
47// class definitions
48// ===========================================================================
65 : public MSMoveReminder, public MSDetectorFileOutput {
66public:
78 MSInductLoop(const std::string& id, MSLane* const lane,
79 double positionInMeters,
80 double length, std::string name,
81 const std::string& vTypes,
82 const std::string& nextEdges,
83 int detectPersons,
84 const bool needLocking);
85
86
89
90
92 virtual void reset() override;
93
95 std::string getName() const {
96 return myName;
97 }
98
102 double getPosition() const {
103 return myPosition;
104 }
105
109 double getEndPosition() const {
110 return myEndPosition;
111 }
112
113
116
126 bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane = 0) override;
127
144 bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed) override;
145
146
161 bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0) override;
162
163
165
166
167
170
178 double getSpeed(const int offset) const;
179
180
188 double getVehicleLength(const int offset) const;
189
190
200 double getOccupancy() const;
201
211 double getEnteredNumber(const int offset) const;
212
213
219 std::vector<std::string> getVehicleIDs(const int offset) const;
220
221 double getIntervalOccupancy(bool lastInterval = false) const;
222 double getIntervalMeanSpeed(bool lastInterval = false) const;
223 int getIntervalVehicleNumber(bool lastInterval = false) const;
224 std::vector<std::string> getIntervalVehicleIDs(bool lastInterval = false) const;
225
230 double getTimeSinceLastDetection() const;
231
235 double getOccupancyTime() const;
236
240 double getArrivalDelay() const;
241
244
245 double getOverrideTime() const {
246 return myOverrideTime;
247 }
249
250
251 /* @brief Persistently overrides the measured time since detection with the given value.
252 * Setting a negative value resets the override
253 */
254 void overrideTimeSinceDetection(double time);
255
257 void saveState(OutputDevice& out) const override;
258
260 void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset) override;
261
264
273 void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime) override;
274
275
282 void writeXMLDetectorProlog(OutputDevice& dev) const override;
283
289 void detectorUpdate(const SUMOTime step) override;
291
292
299 struct VehicleData {
310 VehicleData(const SUMOTrafficObject& v, double entryTimestep,
311 double leaveTimestep, const bool leftEarly, const double detLength = 0);
312
314 std::string idM;
316 double lengthM;
322 double speedM;
324 std::string typeIDM;
327 };
328
329
337 std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t, bool includeEarly = false, bool leaveTime = false, bool forOccupancy = false, bool lastInterval = false) const;
338
340 virtual void setSpecialColor(const RGBColor* /*color*/) {};
341
342 virtual void setVisible(bool /*show*/) {};
343
345 virtual void clearState(SUMOTime time) override;
346
347protected:
350
352 static inline double speedSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
353 return sumSoFar + data.speedM;
354 }
355
357 static inline double lengthSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
358 return sumSoFar + data.lengthM;
359 }
361
363 void notifyMovePerson(MSTransportable* p, int dir, double pos);
364
366 typedef std::priority_queue<SUMOTime, std::vector<SUMOTime>, std::greater<SUMOTime>> TimeQueue;
367 static void discardOldTimes(TimeQueue& tq, SUMOTime now);
368 static std::vector<SUMOTime> getTimes(TimeQueue tq, SUMOTime now);
369
370protected:
372 std::string myName;
373
375 const double myPosition;
376
378 const double myEndPosition;
379
381 const bool myNeedLock;
382
385
389
392
395
398
400 typedef std::deque< VehicleData > VehicleDataCont;
401
404
407
409 std::map<SUMOTrafficObject*, double> myVehiclesOnDet;
410
413
416
419
420private:
423
426
427
428};
long long int SUMOTime
Definition GUI.h:36
A single mesoscopic segment (cell)
Definition MESegment.h:50
Base of value-generating classes (detectors)
An unextended detector measuring at a fixed position on a fixed lane.
void writeXMLDetectorProlog(OutputDevice &dev) const override
Opens the XML-output using "detector" as root element.
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::priority_queue< SUMOTime, std::vector< SUMOTime >, std::greater< SUMOTime > > TimeQueue
helper function for managing meso timings
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
static double speedSum(double sumSoFar, const MSInductLoop::VehicleData &data)
Adds up VehicleData::speedM.
MESegment * mySegment
current segment (for actuated tls in meso)
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
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset) override
Loads the detection state, shifting all times by the given offset.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0) override
Dismisses the vehicle if it is on the detector due to a lane change.
static std::vector< SUMOTime > getTimes(TimeQueue tq, SUMOTime now)
virtual void setSpecialColor(const RGBColor *)
allows for special color in the gui version
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane=0) override
Checks whether the reminder is activated by a vehicle entering the lane.
static void discardOldTimes(TimeQueue &tq, SUMOTime now)
TimeQueue myLastMesoLeaveTimes
void detectorUpdate(const SUMOTime step) override
Updates the detector (computes values) only used when detecting persons.
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
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime) override
Writes collected values into the given stream.
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.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed) override
Checks whether the vehicle shall be counted and/or shall still touch this MSMoveReminder.
std::string myName
detecto name
void saveState(OutputDevice &out) const override
Saves the time of the last detection and the pending meso detections.
void notifyMovePerson(MSTransportable *p, int dir, double pos)
helper function for mapping person movement
double myOverrideTime
overrides the time since last detection
double getArrivalDelay() const
Returns the maximum stop arrival delay of public transport vehicles that are on the detector or passe...
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)
TimeQueue myNextMesoLeaveTimes
extrapolated leave times for meso vehicle
MSInductLoop & operator=(const MSInductLoop &)
Invalidated assignment operator.
const bool myNeedLock
whether internals need to be guarded against concurrent access (GUI or multi threading)
virtual void reset() override
Resets all generated values to allow computation of next interval.
double mySegmentPos
position relative to the current segment
double getIntervalMeanSpeed(bool lastInterval=false) const
virtual void clearState(SUMOTime time) override
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
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.
Encapsulated SAX-Attributes.
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.