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-2022 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
223 double getTimeSinceLastDetection() const;
224
228 double getOccupancyTime() const;
229
232
233 double getOverrideTime() const {
234 return myOverrideTime;
235 }
237
238
239 /* @brief Persistently overrides the measured time since detection with the given value.
240 * Setting a negative value resets the override
241 */
242 void overrideTimeSinceDetection(double time);
243
246
255 void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
256
257
264 void writeXMLDetectorProlog(OutputDevice& dev) const;
265
271 void detectorUpdate(const SUMOTime step);
273
274
281 struct VehicleData {
290 VehicleData(const SUMOTrafficObject& v, double entryTimestep,
291 double leaveTimestep, const bool leftEarly);
292
294 std::string idM;
296 double lengthM;
302 double speedM;
304 std::string typeIDM;
307 };
308
309
317 std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t, bool includeEarly = false, bool leaveTime = false, bool forOccupancy = false) const;
318
320 virtual void setSpecialColor(const RGBColor* /*color*/) {};
321
322 virtual void setVisible(bool /*show*/) {};
323
325 virtual void clearState(SUMOTime time);
326
327protected:
330
332 static inline double speedSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
333 return sumSoFar + data.speedM;
334 }
335
337 static inline double lengthSum(double sumSoFar, const MSInductLoop::VehicleData& data) {
338 return sumSoFar + data.lengthM;
339 }
341
343 void notifyMovePerson(MSTransportable* p, int dir, double pos);
344
345protected:
347 std::string myName;
348
350 const double myPosition;
351
353 const double myEndPosition;
354
356 const bool myNeedLock;
357
360
363
366
369
371 typedef std::deque< VehicleData > VehicleDataCont;
372
375
378
380 std::map<SUMOTrafficObject*, double> myVehiclesOnDet;
381
382private:
385
388
389
390};
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.
Definition: MSInductLoop.h:62
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.
Definition: MSInductLoop.h:337
double getOccupancy() const
Returns the current occupancy.
int myEnteredVehicleNumber
The number of entered vehicles.
Definition: MSInductLoop.h:368
std::deque< VehicleData > VehicleDataCont
Type of myVehicleDataCont.
Definition: MSInductLoop.h:371
double getEnteredNumber(const int offset) const
Returns the number of vehicles that have passed the detector.
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:332
VehicleDataCont myVehicleDataCont
Data of vehicles that have completely passed the detector.
Definition: MSInductLoop.h:374
double getEndPosition() const
Returns the end position of the detector on the lane.
Definition: MSInductLoop.h:106
double getPosition() const
Returns the position of the detector on the lane.
Definition: MSInductLoop.h:99
void overrideTimeSinceDetection(double time)
double myOverrideEntryTime
records the time at which overrideTimeSinceDetection was activated
Definition: MSInductLoop.h:365
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:320
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:350
std::string getName() const
get name
Definition: MSInductLoop.h:92
double getOverrideTime() const
Definition: MSInductLoop.h:233
VehicleDataCont myLastVehicleDataCont
Data of vehicles that have completely passed the detector in the last time interval.
Definition: MSInductLoop.h:377
const double myEndPosition
Detector's end position (defaults to myPosition)
Definition: MSInductLoop.h:353
~MSInductLoop()
Destructor.
MSInductLoop(const MSInductLoop &)
Invalidated copy constructor.
std::string myName
detecto name
Definition: MSInductLoop.h:347
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
Definition: MSInductLoop.h:362
MSInductLoop(const std::string &id, MSLane *const lane, double positionInMeters, double length, std::string name, const std::string &vTypes, const std::string &nextEdges, int detectPersons, const bool needLocking)
Constructor.
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:359
virtual void setVisible(bool)
Definition: MSInductLoop.h:322
MSInductLoop & operator=(const MSInductLoop &)
Invalidated assignment operator.
const bool myNeedLock
whether internals need to be guarded against concurrent access (GUI or multi threading)
Definition: MSInductLoop.h:356
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::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:380
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.
Definition: OutputDevice.h:61
Representation of a vehicle, person, or container.
Struct to store the data of the counted vehicle internally.
Definition: MSInductLoop.h:281
double lengthM
Length of the vehicle.
Definition: MSInductLoop.h:296
double leaveTimeM
Leave-time of the vehicle in [s].
Definition: MSInductLoop.h:300
bool leftEarlyM
whether the vehicle left the detector with a lane change / teleport etc.
Definition: MSInductLoop.h:306
std::string idM
The id of the vehicle.
Definition: MSInductLoop.h:294
double entryTimeM
Entry-time of the vehicle in [s].
Definition: MSInductLoop.h:298
VehicleData(const SUMOTrafficObject &v, double entryTimestep, double leaveTimestep, const bool leftEarly)
Constructor.
double speedM
Speed of the vehicle in [m/s].
Definition: MSInductLoop.h:302
std::string typeIDM
Type of the vehicle.
Definition: MSInductLoop.h:304