Eclipse SUMO - Simulation of Urban MObility
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-2023 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, long long int attributeMask, const SUMOTime period,
145 const double 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 virtual double getAttributeValue(SumoXMLAttr a, const SUMOTime period, const double numLanes, const double speedLimit) const {
163 UNUSED_PARAMETER(period);
164 UNUSED_PARAMETER(numLanes);
165 UNUSED_PARAMETER(speedLimit);
166 return 0;
167 }
168
169 protected:
171 const MSMeanData* const myParent;
172
174 const double myLaneLength;
175
180
184
185 };
186
187
193 public:
195 MeanDataValueTracker(MSLane* const lane, const double length,
196 const MSMeanData* const parent);
197
199 virtual ~MeanDataValueTracker();
200
203 void reset(bool afterWrite);
204
209 void addTo(MSMeanData::MeanDataValues& val) const;
210
213
217 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);
218
219
229 bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
230
231
243 bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
245
246 bool isEmpty() const;
247
255 void write(OutputDevice& dev, long long int attributeMask, const SUMOTime period,
256 const double numLanes, const double speedLimit, const double defaultTravelTime,
257 const int numVehicles = -1) const;
258
259 int getNumReady() const;
260
262
263 double getSamples() const;
264
265 private:
267 public:
271
273 virtual ~TrackerEntry() {
274 delete myValues;
275 }
276
279
282
285 };
286
288 std::map<const SUMOTrafficObject*, TrackerEntry*> myTrackedData;
289
291 std::list<TrackerEntry*> myCurrentData;
292
293 };
294
295
296public:
312 MSMeanData(const std::string& id,
313 const SUMOTime dumpBegin, const SUMOTime dumpEnd,
314 const bool useLanes, const bool withEmpty,
315 const bool printDefaults, const bool withInternal,
316 const bool trackVehicles, const int detectPersons,
317 const double minSamples,
318 const double maxTravelTime,
319 const std::string& vTypes,
320 const std::string& writeAttributes,
321 const std::vector<MSEdge*>& edges,
322 bool aggregate);
323
324
326 virtual ~MSMeanData();
327
330 void init();
331
334
349 void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
350
357 virtual void writeXMLDetectorProlog(OutputDevice& dev) const;
359
362 virtual void detectorUpdate(const SUMOTime step);
363
364 double getMinSamples() const {
365 return myMinSamples;
366 }
367
368 double getMaxTravelTime() const {
369 return myMaxTravelTime;
370 }
371
372 bool isEdgeData() const {
373 return myAmEdgeBased;
374 }
375
377 virtual std::vector<std::string> getAttributeNames() const {
378 return std::vector<std::string>();
379 }
380
382 virtual double getAttributeValue(const MSLane* lane, SumoXMLAttr a, double defaultValue) const {
383 UNUSED_PARAMETER(lane);
385 return defaultValue;
386 }
387
388protected:
394 virtual MSMeanData::MeanDataValues* createValues(MSLane* const lane, const double length, const bool doAdd) const = 0;
395
401 void resetOnly(SUMOTime stopTime);
402
407 virtual std::string getEdgeID(const MSEdge* const edge);
408
423 void writeEdge(OutputDevice& dev, const std::vector<MeanDataValues*>& edgeValues,
424 const MSEdge* const edge, SUMOTime startTime, SUMOTime stopTime);
425
426
438 void writeAggregated(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
439
446 virtual void openInterval(OutputDevice& dev, const SUMOTime startTime, const SUMOTime stopTime);
447
457 virtual bool writePrefix(OutputDevice& dev, const MeanDataValues& values,
458 const SumoXMLTag tag, const std::string id) const;
459
460
461protected:
462 const std::vector<MeanDataValues*>* getEdgeValues(const MSEdge* edge) const;
463
464protected:
466 const double myMinSamples;
467
469 const double myMaxTravelTime;
470
472 std::vector<std::vector<MeanDataValues*> > myMeasures;
473
475 const bool myDumpEmpty;
476
478 const bool myAmEdgeBased;
479
480private:
481 static long long int initWrittenAttributes(const std::string writeAttributes, const std::string& id);
482
485
488
491
493 std::map<const MSEdge*, int> myEdgeIndex;
494
496 const bool myPrintDefaults;
497
499 const bool myDumpInternal;
500
502 const bool myTrackVehicles;
503
505 const long long int myWrittenAttributes;
506
508 const bool myAggregate;
509
511 std::list< std::pair<SUMOTime, SUMOTime> > myPendingIntervals;
512
513private:
516
519
520};
long long int SUMOTime
Definition: GUI.h:36
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
std::vector< MSEdge * > MSEdgeVector
Definition: MSMeanData.h:41
SumoXMLTag
Numbers representing SUMO-XML - element names.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:30
Base of value-generating classes (detectors)
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:266
MeanDataValues * myValues
The number of vehicles which left in the current interval.
Definition: MSMeanData.h:284
virtual ~TrackerEntry()
Constructor.
Definition: MSMeanData.h:273
int myNumVehicleEntered
The number of vehicles which entered in the current interval.
Definition: MSMeanData.h:278
TrackerEntry(MeanDataValues *const values)
Constructor.
Definition: MSMeanData.h:269
int myNumVehicleLeft
The number of vehicles which left in the current interval.
Definition: MSMeanData.h:281
Data structure for mean (aggregated) edge/lane values for tracked vehicles.
Definition: MSMeanData.h:192
double getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:405
MeanDataValueTracker(MSLane *const lane, const double length, const MSMeanData *const parent)
Constructor.
Definition: MSMeanData.cpp:288
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder's lane.
Definition: MSMeanData.cpp:338
void addTo(MSMeanData::MeanDataValues &val) const
Add the values of this to the given one and store them there.
Definition: MSMeanData.cpp:326
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.
Definition: MSMeanData.cpp:332
virtual ~MeanDataValueTracker()
Destructor.
Definition: MSMeanData.cpp:296
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes current values and adds them to their sums.
Definition: MSMeanData.cpp:347
std::list< TrackerEntry * > myCurrentData
The currently active meandata "intervals".
Definition: MSMeanData.h:291
bool isEmpty() const
Returns whether any data was collected.
Definition: MSMeanData.cpp:371
void reset(bool afterWrite)
Resets values so they may be used for the next interval.
Definition: MSMeanData.cpp:313
void write(OutputDevice &dev, long long int attributeMask, const SUMOTime period, const double numLanes, const double speedLimit, const double defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
Definition: MSMeanData.cpp:377
std::map< const SUMOTrafficObject *, TrackerEntry * > myTrackedData
The map of vehicles to data entries.
Definition: MSMeanData.h:288
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 void write(OutputDevice &dev, long long int attributeMask, const SUMOTime period, const double numLanes, const double speedLimit, const double defaultTravelTime, const int numVehicles=-1) const =0
Writes output values into the given stream.
virtual bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder's lane.
Definition: MSMeanData.cpp:260
MeanDataValues(MSLane *const lane, const double length, const bool doAdd, const MSMeanData *const parent)
Constructor.
Definition: MSMeanData.cpp:60
double getTravelledDistance() const
Returns the total travelled distance.
Definition: MSMeanData.h:156
virtual void update()
Called if a per timestep update is needed. Default does nothing.
Definition: MSMeanData.cpp:275
double travelledDistance
The sum of the distances the vehicles travelled.
Definition: MSMeanData.h:182
virtual bool isEmpty() const
Returns whether any data was collected.
Definition: MSMeanData.cpp:269
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
Definition: MSMeanData.cpp:87
const double myLaneLength
The length of the lane / edge the data collector is on.
Definition: MSMeanData.h:174
virtual ~MeanDataValues()
Destructor.
Definition: MSMeanData.cpp:70
virtual double getAttributeValue(SumoXMLAttr a, const SUMOTime period, const double numLanes, const double speedLimit) const
return attribute value
Definition: MSMeanData.h:161
virtual void reset(bool afterWrite=false)=0
Resets values so they may be used for the next interval.
virtual bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle enters the reminder's lane.
Definition: MSMeanData.cpp:75
const MSMeanData *const myParent
The meandata parent.
Definition: MSMeanData.h:171
virtual double getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:280
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:382
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:368
const bool myAggregate
whether the data for all edges shall be aggregated
Definition: MSMeanData.h:508
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
Definition: MSMeanData.cpp:699
const bool myDumpInternal
Whether internal lanes/edges shall be written.
Definition: MSMeanData.h:499
virtual std::vector< std::string > getAttributeNames() const
return all attributes that are (potentially) written by this output
Definition: MSMeanData.h:377
const SUMOTime myDumpBegin
The first and the last time step to write information (-1 indicates always)
Definition: MSMeanData.h:484
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
Definition: MSMeanData.cpp:754
bool isEdgeData() const
Definition: MSMeanData.h:372
virtual ~MSMeanData()
Destructor.
Definition: MSMeanData.cpp:511
double getMinSamples() const
Definition: MSMeanData.h:364
void writeAggregated(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes aggregate of all edge values into the given stream.
Definition: MSMeanData.cpp:552
void init()
Adds the value collectors to all relevant edges.
Definition: MSMeanData.cpp:443
const double myMinSamples
the minimum sample seconds
Definition: MSMeanData.h:466
void resetOnly(SUMOTime stopTime)
Resets network value in order to allow processing of the next interval.
Definition: MSMeanData.cpp:521
const long long int myWrittenAttributes
bit mask for checking attributes to be written
Definition: MSMeanData.h:505
const bool myPrintDefaults
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:496
MSMeanData(const MSMeanData &)
Invalidated copy constructor.
std::map< const MSEdge *, int > myEdgeIndex
The index in myEdges / myMeasures.
Definition: MSMeanData.h:493
const bool myAmEdgeBased
Information whether the output shall be edge-based (not lane-based)
Definition: MSMeanData.h:478
SUMOTime myInitTime
time at which init was called();
Definition: MSMeanData.h:487
const double myMaxTravelTime
the maximum travel time to write
Definition: MSMeanData.h:469
const SUMOTime myDumpEnd
Definition: MSMeanData.h:484
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:511
const std::vector< MeanDataValues * > * getEdgeValues(const MSEdge *edge) const
Definition: MSMeanData.cpp:777
void writeEdge(OutputDevice &dev, const std::vector< MeanDataValues * > &edgeValues, const MSEdge *const edge, SUMOTime startTime, SUMOTime stopTime)
Writes edge values into the given stream.
Definition: MSMeanData.cpp:596
virtual std::string getEdgeID(const MSEdge *const edge)
Return the relevant edge id.
Definition: MSMeanData.cpp:546
MSMeanData & operator=(const MSMeanData &)
Invalidated assignment operator.
static long long int initWrittenAttributes(const std::string writeAttributes, const std::string &id)
Definition: MSMeanData.cpp:762
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "netstats" as root element.
Definition: MSMeanData.cpp:748
const bool myDumpEmpty
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:475
MSEdgeVector myEdges
The corresponding first edges.
Definition: MSMeanData.h:490
MSMeanData(const std::string &id, const SUMOTime dumpBegin, const SUMOTime dumpEnd, const bool useLanes, const bool withEmpty, const bool printDefaults, const bool withInternal, const bool trackVehicles, const int detectPersons, const double minSamples, const double maxTravelTime, const std::string &vTypes, const std::string &writeAttributes, const std::vector< MSEdge * > &edges, bool aggregate)
Constructor.
Definition: MSMeanData.cpp:413
virtual void openInterval(OutputDevice &dev, const SUMOTime startTime, const SUMOTime stopTime)
Writes the interval opener.
Definition: MSMeanData.cpp:680
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
Definition: MSMeanData.h:472
virtual bool writePrefix(OutputDevice &dev, const MeanDataValues &values, const SumoXMLTag tag, const std::string id) const
Checks for emptiness and writes prefix into the given stream.
Definition: MSMeanData.cpp:687
const bool myTrackVehicles
Whether vehicles are tracked.
Definition: MSMeanData.h:502
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.
Definition: OutputDevice.h:61
Representation of a vehicle, person, or container.