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
178 return mySubData;
179 }
180
181 void setSubData(MeanDataValues* subData) {
182 mySubData = subData;
183 }
184
185 protected:
187 const MSMeanData* const myParent;
188
190 const double myLaneLength;
191
196
200
203
206 };
207
208
214 public:
216 MeanDataValueTracker(MSLane* const lane, const double length,
217 const MSMeanData* const parent);
218
220 virtual ~MeanDataValueTracker();
221
224 void reset(bool afterWrite);
225
230 void addTo(MSMeanData::MeanDataValues& val) const;
231
234
238 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);
239
240
250 bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
251
252
264 bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
266
267 bool isEmpty() const;
268
276 void write(OutputDevice& dev, const SumoXMLAttrMask& attributeMask, const SUMOTime period,
277 const int numLanes, const double speedLimit, const double defaultTravelTime,
278 const int numVehicles = -1) const;
279
280 int getNumReady() const;
281
283
284 double getSamples() const;
285
286 private:
288 public:
292
294 virtual ~TrackerEntry() {
295 delete myValues;
296 }
297
300
303
306 };
307
309 std::map<const SUMOTrafficObject*, std::shared_ptr<TrackerEntry> > myTrackedData;
310
312 std::list<std::shared_ptr<TrackerEntry> > myCurrentData;
313
314 };
315
316
317public:
332 MSMeanData(const std::string& id,
333 const SUMOTime dumpBegin, const SUMOTime dumpEnd,
334 const bool useLanes, const std::string& excludeEmpty, const bool withInternal,
335 const bool trackVehicles, const int detectPersons,
336 const double minSamples,
337 const double maxTravelTime,
338 const std::string& vTypes,
339 const std::string& writeAttributes,
340 const std::vector<MSEdge*>& edges,
341 AggregateType aggregate);
342
343
345 virtual ~MSMeanData();
346
349 void init();
350
353
368 void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
369
376 virtual void writeXMLDetectorProlog(OutputDevice& dev) const;
378
381 virtual void detectorUpdate(const SUMOTime step);
382
383 double getMinSamples() const {
384 return myMinSamples;
385 }
386
387 double getMaxTravelTime() const {
388 return myMaxTravelTime;
389 }
390
391 bool isEdgeData() const {
392 return myAmEdgeBased;
393 }
394
396 virtual std::vector<std::string> getAttributeNames() const = 0;
397
399 double getAttributeValue(const MSLane* lane, SumoXMLAttr a, double defaultValue) const;
400
402 const std::vector<MSMoveReminder*> getReminders() const;
403
405 void setSubData(MSMeanData* subData) {
406 mySubData = subData;
407 }
408
409protected:
416 virtual MSMeanData::MeanDataValues* createValues(MSLane* const lane, const double length, const bool doAdd) const = 0;
417
423 void resetOnly(SUMOTime stopTime);
424
429 virtual std::string getEdgeID(const MSEdge* const edge);
430
445 void writeEdge(OutputDevice& dev, const std::vector<MeanDataValues*>& edgeValues,
446 const MSEdge* const edge, SUMOTime startTime, SUMOTime stopTime);
447
448
460 void writeAggregated(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
461
473 void writeAggregatedTAZ(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
474
481 virtual void openInterval(OutputDevice& dev, const SUMOTime startTime, const SUMOTime stopTime);
482
491 virtual void writePrefix(OutputDevice& dev, const MeanDataValues& values,
492 const SumoXMLTag tag, const std::string id) const;
493
494 const std::vector<MeanDataValues*>* getEdgeValues(const MSEdge* edge) const;
495
496private:
503 MSMeanData::MeanDataValues* createValuesSubData(MSLane* const lane, const double length, const bool doAdd) const;
504
505protected:
507 const double myMinSamples;
508
510 const double myMaxTravelTime;
511
513 std::vector<std::vector<MeanDataValues*> > myMeasures;
514
516 bool myDumpEmpty = true;
517
519 const bool myAmEdgeBased;
520
521private:
524
527
530
532
534 std::map<const MSEdge*, int> myEdgeIndex;
535
537 bool myPrintDefaults = false;
538
540 bool myPrintModified = false;
541
543 const bool myDumpInternal;
544
546 const bool myTrackVehicles;
547
550
553
556
558 std::list< std::pair<SUMOTime, SUMOTime> > myPendingIntervals;
559
560private:
563
566
567};
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:287
MeanDataValues * myValues
The number of vehicles which left in the current interval.
Definition MSMeanData.h:305
virtual ~TrackerEntry()
Constructor.
Definition MSMeanData.h:294
int myNumVehicleEntered
The number of vehicles which entered in the current interval.
Definition MSMeanData.h:299
TrackerEntry(MeanDataValues *const values)
Constructor.
Definition MSMeanData.h:290
int myNumVehicleLeft
The number of vehicles which left in the current interval.
Definition MSMeanData.h:302
Data structure for mean (aggregated) edge/lane values for tracked vehicles.
Definition MSMeanData.h:213
std::map< const SUMOTrafficObject *, std::shared_ptr< TrackerEntry > > myTrackedData
The map of vehicles to data entries.
Definition MSMeanData.h:309
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.
std::list< std::shared_ptr< TrackerEntry > > myCurrentData
The currently active meandata "intervals".
Definition MSMeanData.h:312
virtual ~MeanDataValueTracker()
Destructor.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes current values and adds them to their sums.
bool isEmpty() const
Returns whether any data was collected.
Data structure for mean (aggregated) edge/lane values.
Definition MSMeanData.h:66
MeanDataValues * mySubData
additional data to collect and write
Definition MSMeanData.h:205
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.
void setSubData(MeanDataValues *subData)
Definition MSMeanData.h:181
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:198
virtual bool isEmpty() const
Returns whether any data was collected.
MeanDataValues * getSubData()
Definition MSMeanData.h:177
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:190
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:202
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:187
virtual double getSamples() const
Returns the number of collected sample seconds.
Data collector for edges/lanes.
Definition MSMeanData.h:57
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:387
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
virtual std::vector< std::string > getAttributeNames() const =0
return all attributes that are (potentially) written by this output
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:543
bool myPrintDefaults
Whether empty lanes/edges shall be written with default values.
Definition MSMeanData.h:537
const AggregateType myAggregate
whether the data for all edges shall be aggregated
Definition MSMeanData.h:552
const SUMOTime myDumpBegin
The first and the last time step to write information (-1 indicates always)
Definition MSMeanData.h:523
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
bool isEdgeData() const
Definition MSMeanData.h:391
virtual ~MSMeanData()
Destructor.
double getMinSamples() const
Definition MSMeanData.h:383
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.
void setSubData(MSMeanData *subData)
set a sub collector
Definition MSMeanData.h:405
const double myMinSamples
the minimum sample seconds
Definition MSMeanData.h:507
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:534
const SumoXMLAttrMask myWrittenAttributes
bit mask for checking attributes to be written
Definition MSMeanData.h:549
MSMeanData * mySubData
more data collectors which write to the same output
Definition MSMeanData.h:555
const bool myAmEdgeBased
Information whether the output shall be edge-based (not lane-based)
Definition MSMeanData.h:519
SUMOTime myInitTime
time at which init was called();
Definition MSMeanData.h:526
const double myMaxTravelTime
the maximum travel time to write
Definition MSMeanData.h:510
bool myDumpEmpty
Whether empty lanes/edges shall be written.
Definition MSMeanData.h:516
const SUMOTime myDumpEnd
Definition MSMeanData.h:523
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:558
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.
MSMeanData::MeanDataValues * createValuesSubData(MSLane *const lane, const double length, const bool doAdd) const
Create an instance of MeanDataValues with subdata.
MSEdgeVector myEdges
The corresponding first edges.
Definition MSMeanData.h:529
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:540
double getAttributeValue(const MSLane *lane, SumoXMLAttr a, double defaultValue) const
return attribute value for the given lane
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
Definition MSMeanData.h:513
const bool myTrackVehicles
Whether vehicles are tracked.
Definition MSMeanData.h:546
ConstMSEdgeVector myTAZ
Definition MSMeanData.h:531
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)