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-2024 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 <functional>
34
35
36// ===========================================================================
37// class declarations
38// ===========================================================================
39class MSLane;
40class MSVehicle;
41class OutputDevice;
42
43
44// ===========================================================================
45// class definitions
46// ===========================================================================
63 : public MSMoveReminder, public MSDetectorFileOutput {
64public:
76 MSInductLoop(const std::string& id, MSLane* const lane,
77 double positionInMeters,
78 double length, std::string name,
79 const std::string& vTypes,
80 const std::string& nextEdges,
81 int detectPersons,
82 const bool needLocking);
83
84
87
88
90 virtual void reset();
91
93 std::string getName() const {
94 return myName;
95 }
96
100 double getPosition() const {
101 return myPosition;
102 }
103
107 double getEndPosition() const {
108 return myEndPosition;
109 }
110
111
114
124 bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane = 0);
125
142 bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
143
144
159 bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
160
161
163
164
165
168
176 double getSpeed(const int offset) const;
177
178
186 double getVehicleLength(const int offset) const;
187
188
198 double getOccupancy() const;
199
209 double getEnteredNumber(const int offset) const;
210
211
217 std::vector<std::string> getVehicleIDs(const int offset) const;
218
219 double getIntervalOccupancy(bool lastInterval = false) const;
220 double getIntervalMeanSpeed(bool lastInterval = false) const;
221 int getIntervalVehicleNumber(bool lastInterval = false) const;
222 std::vector<std::string> getIntervalVehicleIDs(bool lastInterval = false) const;
223
228 double getTimeSinceLastDetection() const;
229
233 double getOccupancyTime() const;
234
237
238 double getOverrideTime() const {
239 return myOverrideTime;
240 }
242
243
244 /* @brief Persistently overrides the measured time since detection with the given value.
245 * Setting a negative value resets the override
246 */
247 void overrideTimeSinceDetection(double time);
248
251
260 void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
261
262
269 void writeXMLDetectorProlog(OutputDevice& dev) const;
270
276 void detectorUpdate(const SUMOTime step);
278
279
286 struct VehicleData {
297 VehicleData(const SUMOTrafficObject& v, double entryTimestep,
298 double leaveTimestep, const bool leftEarly, const double detLength = 0);
299
301 std::string idM;
303 double lengthM;
309 double speedM;
311 std::string typeIDM;
314 };
315
316
324 std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t, bool includeEarly = false, bool leaveTime = false, bool forOccupancy = false, bool lastInterval = false) const;
325
327 virtual void setSpecialColor(const RGBColor* /*color*/) {};
328
329 virtual void setVisible(bool /*show*/) {};
330
332 virtual void clearState(SUMOTime time);
333
334protected:
337
339 static inline double speedSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
340 return sumSoFar + data.speedM;
341 }
342
344 static inline double lengthSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
345 return sumSoFar + data.lengthM;
346 }
348
350 void notifyMovePerson(MSTransportable* p, int dir, double pos);
351
352protected:
354 std::string myName;
355
357 const double myPosition;
358
360 const double myEndPosition;
361
363 const bool myNeedLock;
364
367
370
373
376
378 typedef std::deque< VehicleData > VehicleDataCont;
379
382
385
387 std::map<SUMOTrafficObject*, double> myVehiclesOnDet;
388
391
392private:
395
398
399
400};
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.