Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSMeanData.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-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/****************************************************************************/
19// Data collector for edges/lanes
20/****************************************************************************/
21#pragma once
22#include <config.h>
23
24#include <vector>
25#include <set>
26#include <list>
27#include <limits>
31
32
33// ===========================================================================
34// class declarations
35// ===========================================================================
36class OutputDevice;
37class MSEdge;
38class MSLane;
40
41typedef std::vector<MSEdge*> MSEdgeVector;
42
43// ===========================================================================
44// class definitions
45// ===========================================================================
58public:
67 public:
69 MeanDataValues(MSLane* const lane, const double length, const bool doAdd, const MSMeanData* const parent);
70
72 virtual ~MeanDataValues();
73
74
77 virtual void reset(bool afterWrite = false) = 0;
78
83 virtual void addTo(MeanDataValues& val) const = 0;
84
85
94 virtual bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
95
96
110 bool notifyMove(SUMOTrafficObject& veh, double oldPos,
111 double newPos, double newSpeed);
112
113
122 virtual bool notifyLeave(SUMOTrafficObject& veh, double lastPos,
123 MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
124
125
130 virtual bool isEmpty() const;
131
132
135 virtual void update();
136
144 virtual void write(OutputDevice& dev, const SumoXMLAttrMask& attributeMask, const SUMOTime period,
145 const int numLanes, const double speedLimit, const double defaultTravelTime,
146 const int numVehicles = -1) const = 0;
147
151 virtual double getSamples() const;
152
156 double getTravelledDistance() const {
157 return travelledDistance;
158 }
159
161 return resetTime;
162 }
163
164 double getLaneLength() const {
165 return myLaneLength;
166 }
167
169 virtual double getAttributeValue(SumoXMLAttr a, const SUMOTime period, const double numLanes, const double speedLimit) const {
171 UNUSED_PARAMETER(period);
172 UNUSED_PARAMETER(numLanes);
173 UNUSED_PARAMETER(speedLimit);
174 return 0;
175 }
176
177 protected:
179 const MSMeanData* const myParent;
180
182 const double myLaneLength;
183
188
192
195 };
196
197
203 public:
205 MeanDataValueTracker(MSLane* const lane, const double length,
206 const MSMeanData* const parent);
207
209 virtual ~MeanDataValueTracker();
210
213 void reset(bool afterWrite);
214
219 void addTo(MSMeanData::MeanDataValues& val) const;
220
223
227 void notifyMoveInternal(const SUMOTrafficObject& veh, const double frontOnLane, const double timeOnLane, const double meanSpeedFrontOnLane, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane, const double meanLengthOnLane);
228
229
239 bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
240
241
253 bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
255
256 bool isEmpty() const;
257
265 void write(OutputDevice& dev, const SumoXMLAttrMask& attributeMask, const SUMOTime period,
266 const int numLanes, const double speedLimit, const double defaultTravelTime,
267 const int numVehicles = -1) const;
268
269 int getNumReady() const;
270
272
273 double getSamples() const;
274
275 private:
277 public:
281
283 virtual ~TrackerEntry() {
284 delete myValues;
285 }
286
289
292
295 };
296
298 std::map<const SUMOTrafficObject*, TrackerEntry*> myTrackedData;
299
301 std::list<TrackerEntry*> myCurrentData;
302
303 };
304
305
306public:
321 MSMeanData(const std::string& id,
322 const SUMOTime dumpBegin, const SUMOTime dumpEnd,
323 const bool useLanes, const std::string& excludeEmpty, const bool withInternal,
324 const bool trackVehicles, const int detectPersons,
325 const double minSamples,
326 const double maxTravelTime,
327 const std::string& vTypes,
328 const std::string& writeAttributes,
329 const std::vector<MSEdge*>& edges,
330 AggregateType aggregate);
331
332
334 virtual ~MSMeanData();
335
338 void init();
339
342
357 void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
358
365 virtual void writeXMLDetectorProlog(OutputDevice& dev) const;
367
370 virtual void detectorUpdate(const SUMOTime step);
371
372 double getMinSamples() const {
373 return myMinSamples;
374 }
375
376 double getMaxTravelTime() const {
377 return myMaxTravelTime;
378 }
379
380 bool isEdgeData() const {
381 return myAmEdgeBased;
382 }
383
385 virtual std::vector<std::string> getAttributeNames() const {
386 return std::vector<std::string>();
387 }
388
390 virtual double getAttributeValue(const MSLane* lane, SumoXMLAttr a, double defaultValue) const {
391 UNUSED_PARAMETER(lane);
393 return defaultValue;
394 }
395
397 const std::vector<MSMoveReminder*> getReminders() const;
398
399protected:
405 virtual MSMeanData::MeanDataValues* createValues(MSLane* const lane, const double length, const bool doAdd) const = 0;
406
412 void resetOnly(SUMOTime stopTime);
413
418 virtual std::string getEdgeID(const MSEdge* const edge);
419
434 void writeEdge(OutputDevice& dev, const std::vector<MeanDataValues*>& edgeValues,
435 const MSEdge* const edge, SUMOTime startTime, SUMOTime stopTime);
436
437
449 void writeAggregated(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
450
462 void writeAggregatedTAZ(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
463
470 virtual void openInterval(OutputDevice& dev, const SUMOTime startTime, const SUMOTime stopTime);
471
480 virtual void writePrefix(OutputDevice& dev, const MeanDataValues& values,
481 const SumoXMLTag tag, const std::string id) const;
482
483
484protected:
485 const std::vector<MeanDataValues*>* getEdgeValues(const MSEdge* edge) const;
486
487protected:
489 const double myMinSamples;
490
492 const double myMaxTravelTime;
493
495 std::vector<std::vector<MeanDataValues*> > myMeasures;
496
498 bool myDumpEmpty = true;
499
501 const bool myAmEdgeBased;
502
503private:
506
509
512
514
516 std::map<const MSEdge*, int> myEdgeIndex;
517
519 bool myPrintDefaults = false;
520
522 bool myPrintModified = false;
523
525 const bool myDumpInternal;
526
528 const bool myTrackVehicles;
529
532
535
537 std::list< std::pair<SUMOTime, SUMOTime> > myPendingIntervals;
538
539private:
542
545
546};
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:74
std::vector< MSEdge * > MSEdgeVector
Definition MSMeanData.h:41
SumoXMLTag
Numbers representing SUMO-XML - element names.
std::bitset< 96 > SumoXMLAttrMask
AggregateType
Numbers representing special SUMO-XML-attribute values Information on edgeData/laneData output should...
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Base of value-generating classes (detectors)
virtual void reset()
Resets collected values.
A road/street connecting two junctions.
Definition MSEdge.h:77
Representation of a lane in the micro simulation.
Definition MSLane.h:84
Definition MSMeanData.h:276
MeanDataValues * myValues
The number of vehicles which left in the current interval.
Definition MSMeanData.h:294
virtual ~TrackerEntry()
Constructor.
Definition MSMeanData.h:283
int myNumVehicleEntered
The number of vehicles which entered in the current interval.
Definition MSMeanData.h:288
TrackerEntry(MeanDataValues *const values)
Constructor.
Definition MSMeanData.h:279
int myNumVehicleLeft
The number of vehicles which left in the current interval.
Definition MSMeanData.h:291
Data structure for mean (aggregated) edge/lane values for tracked vehicles.
Definition MSMeanData.h:202
double getSamples() const
Returns the number of collected sample seconds.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder's lane.
void addTo(MSMeanData::MeanDataValues &val) const
Add the values of this to the given one and store them there.
void notifyMoveInternal(const SUMOTrafficObject &veh, const double frontOnLane, const double timeOnLane, const double meanSpeedFrontOnLane, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane, const double meanLengthOnLane)
Internal notification about the vehicle moves.
void write(OutputDevice &dev, const SumoXMLAttrMask &attributeMask, const SUMOTime period, const int numLanes, const double speedLimit, const double defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
virtual ~MeanDataValueTracker()
Destructor.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes current values and adds them to their sums.
std::list< TrackerEntry * > myCurrentData
The currently active meandata "intervals".
Definition MSMeanData.h:301
bool isEmpty() const
Returns whether any data was collected.
std::map< const SUMOTrafficObject *, TrackerEntry * > myTrackedData
The map of vehicles to data entries.
Definition MSMeanData.h:298
Data structure for mean (aggregated) edge/lane values.
Definition MSMeanData.h:66
virtual void addTo(MeanDataValues &val) const =0
Add the values of this to the given one and store them there.
virtual bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder's lane.
double getTravelledDistance() const
Returns the total travelled distance.
Definition MSMeanData.h:156
SUMOTime getResetTime() const
Definition MSMeanData.h:160
virtual void write(OutputDevice &dev, const SumoXMLAttrMask &attributeMask, const SUMOTime period, const int numLanes, const double speedLimit, const double defaultTravelTime, const int numVehicles=-1) const =0
Writes output values into the given stream.
virtual void update()
Called if a per timestep update is needed. Default does nothing.
double getLaneLength() const
Definition MSMeanData.h:164
double travelledDistance
The sum of the distances the vehicles travelled.
Definition MSMeanData.h:190
virtual bool isEmpty() const
Returns whether any data was collected.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
const double myLaneLength
The length of the lane / edge the data collector is on.
Definition MSMeanData.h:182
virtual ~MeanDataValues()
Destructor.
virtual double getAttributeValue(SumoXMLAttr a, const SUMOTime period, const double numLanes, const double speedLimit) const
return attribute value
Definition MSMeanData.h:169
virtual void reset(bool afterWrite=false)=0
Resets values so they may be used for the next interval.
SUMOTime resetTime
time at which collection was reset;
Definition MSMeanData.h:194
virtual bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle enters the reminder's lane.
const MSMeanData *const myParent
The meandata parent.
Definition MSMeanData.h:179
virtual double getSamples() const
Returns the number of collected sample seconds.
Data collector for edges/lanes.
Definition MSMeanData.h:57
virtual double getAttributeValue(const MSLane *lane, SumoXMLAttr a, double defaultValue) const
return attribute value for the given lane
Definition MSMeanData.h:390
virtual MSMeanData::MeanDataValues * createValues(MSLane *const lane, const double length, const bool doAdd) const =0
Create an instance of MeanDataValues.
double getMaxTravelTime() const
Definition MSMeanData.h:376
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
virtual void writePrefix(OutputDevice &dev, const MeanDataValues &values, const SumoXMLTag tag, const std::string id) const
Writes the surrounding element into the given stream.
const bool myDumpInternal
Whether internal lanes/edges shall be written.
Definition MSMeanData.h:525
bool myPrintDefaults
Whether empty lanes/edges shall be written with default values.
Definition MSMeanData.h:519
const AggregateType myAggregate
whether the data for all edges shall be aggregated
Definition MSMeanData.h:534
virtual std::vector< std::string > getAttributeNames() const
return all attributes that are (potentially) written by this output
Definition MSMeanData.h:385
const SUMOTime myDumpBegin
The first and the last time step to write information (-1 indicates always)
Definition MSMeanData.h:505
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
bool isEdgeData() const
Definition MSMeanData.h:380
virtual ~MSMeanData()
Destructor.
double getMinSamples() const
Definition MSMeanData.h:372
void writeAggregated(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes aggregated data of all edge values into the given stream.
void init()
Adds the value collectors to all relevant edges.
const double myMinSamples
the minimum sample seconds
Definition MSMeanData.h:489
void resetOnly(SUMOTime stopTime)
Resets network value in order to allow processing of the next interval.
void writeAggregatedTAZ(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes aggregated data for each TAZ into the given stream.
MSMeanData(const MSMeanData &)
Invalidated copy constructor.
std::map< const MSEdge *, int > myEdgeIndex
The index in myEdges / myMeasures.
Definition MSMeanData.h:516
const SumoXMLAttrMask myWrittenAttributes
bit mask for checking attributes to be written
Definition MSMeanData.h:531
const bool myAmEdgeBased
Information whether the output shall be edge-based (not lane-based)
Definition MSMeanData.h:501
SUMOTime myInitTime
time at which init was called();
Definition MSMeanData.h:508
const double myMaxTravelTime
the maximum travel time to write
Definition MSMeanData.h:492
bool myDumpEmpty
Whether empty lanes/edges shall be written.
Definition MSMeanData.h:498
const SUMOTime myDumpEnd
Definition MSMeanData.h:505
std::list< std::pair< SUMOTime, SUMOTime > > myPendingIntervals
The intervals for which output still has to be generated (only in the tracking case)
Definition MSMeanData.h:537
const std::vector< MeanDataValues * > * getEdgeValues(const MSEdge *edge) const
void writeEdge(OutputDevice &dev, const std::vector< MeanDataValues * > &edgeValues, const MSEdge *const edge, SUMOTime startTime, SUMOTime stopTime)
Writes edge values into the given stream.
virtual std::string getEdgeID(const MSEdge *const edge)
Return the relevant edge id.
MSMeanData & operator=(const MSMeanData &)
Invalidated assignment operator.
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "netstats" as root element.
MSEdgeVector myEdges
The corresponding first edges.
Definition MSMeanData.h:511
const std::vector< MSMoveReminder * > getReminders() const
retrieve all MeanDataValues
virtual void openInterval(OutputDevice &dev, const SUMOTime startTime, const SUMOTime stopTime)
Writes the interval opener.
bool myPrintModified
Whether only empty lanes/edges which have been modified shall be written.
Definition MSMeanData.h:522
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
Definition MSMeanData.h:495
const bool myTrackVehicles
Whether vehicles are tracked.
Definition MSMeanData.h:528
ConstMSEdgeVector myTAZ
Definition MSMeanData.h:513
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
Static storage of an output device and its base (abstract) implementation.
Representation of a vehicle, person, or container.
#define UNUSED_PARAMETER(x)