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.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // Data collector for edges/lanes
16 /****************************************************************************/
17 #ifndef MSMeanData_h
18 #define MSMeanData_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <vector>
27 #include <set>
28 #include <list>
29 #include <limits>
32 #include <utils/common/SUMOTime.h>
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class OutputDevice;
39 class MSEdge;
40 class MSLane;
41 class SUMOTrafficObject;
42 
43 typedef std::vector<MSEdge*> MSEdgeVector;
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
60 public:
68  class MeanDataValues : public MSMoveReminder {
69  public:
71  MeanDataValues(MSLane* const lane, const double length, const bool doAdd, const MSMeanData* const parent);
72 
74  virtual ~MeanDataValues();
75 
76 
79  virtual void reset(bool afterWrite = false) = 0;
80 
85  virtual void addTo(MeanDataValues& val) const = 0;
86 
87 
96  virtual bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
97 
98 
112  bool notifyMove(SUMOTrafficObject& veh, double oldPos,
113  double newPos, double newSpeed);
114 
115 
124  virtual bool notifyLeave(SUMOTrafficObject& veh, double lastPos,
125  MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
126 
127 
132  virtual bool isEmpty() const;
133 
134 
137  virtual void update();
138 
146  virtual void write(OutputDevice& dev, const SUMOTime period,
147  const double numLanes, const double defaultTravelTime,
148  const int numVehicles = -1) const = 0;
149 
153  virtual double getSamples() const;
154 
158  double getTravelledDistance() const {
159  return travelledDistance;
160  }
161 
162  protected:
164  const MSMeanData* const myParent;
165 
167  const double myLaneLength;
168 
173 
177 
178  };
179 
180 
186  public:
188  MeanDataValueTracker(MSLane* const lane, const double length,
189  const MSMeanData* const parent);
190 
192  virtual ~MeanDataValueTracker();
193 
196  void reset(bool afterWrite);
197 
202  void addTo(MSMeanData::MeanDataValues& val) const;
203 
206 
210  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);
211 
212 
222  bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
223 
224 
236  bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
238 
239  bool isEmpty() const;
240 
248  void write(OutputDevice& dev, const SUMOTime period,
249  const double numLanes, const double defaultTravelTime,
250  const int numVehicles = -1) const;
251 
252  int getNumReady() const;
253 
254  void clearFirst();
255 
256  double getSamples() const;
257 
258  private:
259  class TrackerEntry {
260  public:
263  : myNumVehicleEntered(0), myNumVehicleLeft(0), myValues(values) {}
264 
266  virtual ~TrackerEntry() {
267  delete myValues;
268  }
269 
272 
275 
278  };
279 
281  std::map<const SUMOTrafficObject*, TrackerEntry*> myTrackedData;
282 
284  std::list<TrackerEntry*> myCurrentData;
285 
286  };
287 
288 
289 public:
305  MSMeanData(const std::string& id,
306  const SUMOTime dumpBegin, const SUMOTime dumpEnd,
307  const bool useLanes, const bool withEmpty,
308  const bool printDefaults, const bool withInternal,
309  const bool trackVehicles, const int detectPersons,
310  const double minSamples,
311  const double maxTravelTime,
312  const std::string& vTypes);
313 
314 
316  virtual ~MSMeanData();
317 
320  void init();
321 
324 
339  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
340 
347  virtual void writeXMLDetectorProlog(OutputDevice& dev) const;
349 
352  virtual void detectorUpdate(const SUMOTime step);
353 
354  double getMinSamples() const {
355  return myMinSamples;
356  }
357 
358  double getMaxTravelTime() const {
359  return myMaxTravelTime;
360  }
361 
362 
363 protected:
369  virtual MSMeanData::MeanDataValues* createValues(MSLane* const lane, const double length, const bool doAdd) const = 0;
370 
376  void resetOnly(SUMOTime stopTime);
377 
382  virtual std::string getEdgeID(const MSEdge* const edge);
383 
398  void writeEdge(OutputDevice& dev, const std::vector<MeanDataValues*>& edgeValues,
399  MSEdge* edge, SUMOTime startTime, SUMOTime stopTime);
400 
407  virtual void openInterval(OutputDevice& dev, const SUMOTime startTime, const SUMOTime stopTime);
408 
418  virtual bool writePrefix(OutputDevice& dev, const MeanDataValues& values,
419  const SumoXMLTag tag, const std::string id) const;
420 
421 protected:
423  const double myMinSamples;
424 
426  const double myMaxTravelTime;
427 
429  std::vector<std::vector<MeanDataValues*> > myMeasures;
430 
432  const bool myDumpEmpty;
433 
434 private:
436  const bool myAmEdgeBased;
437 
440 
443 
445  const bool myPrintDefaults;
446 
448  const bool myDumpInternal;
449 
451  const bool myTrackVehicles;
452 
454  std::list< std::pair<SUMOTime, SUMOTime> > myPendingIntervals;
455 
456 private:
459 
462 
463 };
464 
465 
466 #endif
467 
468 /****************************************************************************/
469 
MSMeanData::MeanDataValueTracker::TrackerEntry
Definition: MSMeanData.h:259
SUMOTrafficObject
Representation of a vehicle or person.
Definition: SUMOTrafficObject.h:47
MSMeanData::writeEdge
void writeEdge(OutputDevice &dev, const std::vector< MeanDataValues * > &edgeValues, MSEdge *edge, SUMOTime startTime, SUMOTime stopTime)
Writes edge values into the given stream.
Definition: MSMeanData.cpp:516
MSMeanData::MeanDataValueTracker::TrackerEntry::~TrackerEntry
virtual ~TrackerEntry()
Constructor.
Definition: MSMeanData.h:266
MSMeanData::myDumpEmpty
const bool myDumpEmpty
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:432
SUMOTime.h
MSDetectorFileOutput
Base of value-generating classes (detectors)
Definition: MSDetectorFileOutput.h:63
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSMeanData::getMaxTravelTime
double getMaxTravelTime() const
Definition: MSMeanData.h:358
MSMeanData::myAmEdgeBased
const bool myAmEdgeBased
Information whether the output shall be edge-based (not lane-based)
Definition: MSMeanData.h:436
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
MSMeanData::MSMeanData
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)
Constructor.
Definition: MSMeanData.cpp:407
MSMeanData::writeXMLDetectorProlog
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "netstats" as root element.
Definition: MSMeanData.cpp:639
MSMeanData::MeanDataValueTracker::getSamples
double getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:399
MSMeanData::MeanDataValueTracker::clearFirst
void clearFirst()
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSMeanData::MeanDataValues::notifyEnter
virtual bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle enters the reminder's lane.
Definition: MSMeanData.cpp:72
MSMeanData::MeanDataValues::isEmpty
virtual bool isEmpty() const
Returns whether any data was collected.
Definition: MSMeanData.cpp:266
MSMeanData::MeanDataValueTracker::MeanDataValueTracker
MeanDataValueTracker(MSLane *const lane, const double length, const MSMeanData *const parent)
Constructor.
Definition: MSMeanData.cpp:285
MSMeanData::myMeasures
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
Definition: MSMeanData.h:429
MSMeanData::myPrintDefaults
const bool myPrintDefaults
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:445
MSMeanData::MeanDataValues::write
virtual void write(OutputDevice &dev, const SUMOTime period, const double numLanes, const double defaultTravelTime, const int numVehicles=-1) const =0
Writes output values into the given stream.
MSMeanData::resetOnly
void resetOnly(SUMOTime stopTime)
Resets network value in order to allow processing of the next interval.
Definition: MSMeanData.cpp:486
MSMeanData::myDumpEnd
const SUMOTime myDumpEnd
Definition: MSMeanData.h:439
MSDetectorFileOutput.h
SumoXMLTag
SumoXMLTag
Numbers representing SUMO-XML - element names.
Definition: SUMOXMLDefinitions.h:41
MSMeanData::writeXMLOutput
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
Definition: MSMeanData.cpp:599
MSMoveReminder
Something on a lane to be noticed about vehicle movement.
Definition: MSMoveReminder.h:66
MSMeanData::myEdges
MSEdgeVector myEdges
The corresponding first edges.
Definition: MSMeanData.h:442
MSMeanData::MSMeanData
MSMeanData(const MSMeanData &)
Invalidated copy constructor.
MSMeanData::myDumpInternal
const bool myDumpInternal
Whether internal lanes/edges shall be written.
Definition: MSMeanData.h:448
MSMeanData::myMinSamples
const double myMinSamples
the minimum sample seconds
Definition: MSMeanData.h:423
MSMeanData::MeanDataValueTracker::notifyEnter
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes current values and adds them to their sums.
Definition: MSMeanData.cpp:343
MSMoveReminder.h
MSMeanData
Data collector for edges/lanes.
Definition: MSMeanData.h:59
MSMeanData::MeanDataValueTracker::~MeanDataValueTracker
virtual ~MeanDataValueTracker()
Destructor.
Definition: MSMeanData.cpp:293
MSMeanData::openInterval
virtual void openInterval(OutputDevice &dev, const SUMOTime startTime, const SUMOTime stopTime)
Writes the interval opener.
Definition: MSMeanData.cpp:582
MSMeanData::MeanDataValues::notifyMove
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:84
MSMeanData::MeanDataValueTracker::addTo
void addTo(MSMeanData::MeanDataValues &val) const
Add the values of this to the given one and store them there.
Definition: MSMeanData.cpp:322
MSMeanData::myPendingIntervals
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:454
MSMeanData::~MSMeanData
virtual ~MSMeanData()
Destructor.
Definition: MSMeanData.cpp:476
MSMeanData::MeanDataValues::notifyLeave
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:257
MSMeanData::MeanDataValues::travelledDistance
double travelledDistance
The sum of the distances the vehicles travelled.
Definition: MSMeanData.h:175
MSMeanData::myMaxTravelTime
const double myMaxTravelTime
the maximum travel time to write
Definition: MSMeanData.h:426
MSMeanData::MeanDataValues::getTravelledDistance
double getTravelledDistance() const
Returns the total travelled distance.
Definition: MSMeanData.h:158
MSMeanData::operator=
MSMeanData & operator=(const MSMeanData &)
Invalidated assignment operator.
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
MSMeanData::MeanDataValueTracker::TrackerEntry::myNumVehicleLeft
int myNumVehicleLeft
The number of vehicles which left in the current interval.
Definition: MSMeanData.h:274
MSMeanData::MeanDataValues::myParent
const MSMeanData *const myParent
The meandata parent.
Definition: MSMeanData.h:164
MSMeanData::MeanDataValueTracker::isEmpty
bool isEmpty() const
Returns whether any data was collected.
Definition: MSMeanData.cpp:367
MSMeanData::init
void init()
Adds the value collectors to all relevant edges.
Definition: MSMeanData.cpp:430
MSMeanData::MeanDataValues::update
virtual void update()
Called if a per timestep update is needed. Default does nothing.
Definition: MSMeanData.cpp:272
MSMeanData::MeanDataValues
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:68
MSDetectorFileOutput::detectPersons
bool detectPersons() const
Definition: MSDetectorFileOutput.h:166
MSMeanData::MeanDataValues::myLaneLength
const double myLaneLength
The length of the lane / edge the data collector is on.
Definition: MSMeanData.h:167
MSMeanData::MeanDataValueTracker::notifyMoveInternal
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:328
MSMeanData::MeanDataValues::~MeanDataValues
virtual ~MeanDataValues()
Destructor.
Definition: MSMeanData.cpp:67
MSMeanData::MeanDataValueTracker::myCurrentData
std::list< TrackerEntry * > myCurrentData
The currently active meandata "intervals".
Definition: MSMeanData.h:284
MSMeanData::MeanDataValueTracker
Data structure for mean (aggregated) edge/lane values for tracked vehicles.
Definition: MSMeanData.h:185
MSMeanData::myTrackVehicles
const bool myTrackVehicles
Whether vehicles are tracked.
Definition: MSMeanData.h:451
MSMeanData::MeanDataValues::getSamples
virtual double getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:277
MSMeanData::MeanDataValueTracker::reset
void reset(bool afterWrite)
Resets values so they may be used for the next interval.
Definition: MSMeanData.cpp:310
MSMeanData::MeanDataValueTracker::TrackerEntry::myNumVehicleEntered
int myNumVehicleEntered
The number of vehicles which entered in the current interval.
Definition: MSMeanData.h:271
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSMeanData.h:41
MSMeanData::MeanDataValues::sampleSeconds
double sampleSeconds
Definition: MSMeanData.h:172
MSMeanData::myDumpBegin
const SUMOTime myDumpBegin
The first and the last time step to write information (-1 indicates always)
Definition: MSMeanData.h:439
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:74
MSMeanData::MeanDataValues::reset
virtual void reset(bool afterWrite=false)=0
Resets values so they may be used for the next interval.
MSMeanData::createValues
virtual MSMeanData::MeanDataValues * createValues(MSLane *const lane, const double length, const bool doAdd) const =0
Create an instance of MeanDataValues.
MSMeanData::MeanDataValues::addTo
virtual void addTo(MeanDataValues &val) const =0
Add the values of this to the given one and store them there.
MSMeanData::getEdgeID
virtual std::string getEdgeID(const MSEdge *const edge)
Return the relevant edge id.
Definition: MSMeanData.cpp:510
MSMeanData::getMinSamples
double getMinSamples() const
Definition: MSMeanData.h:354
config.h
MSMeanData::MeanDataValueTracker::write
void write(OutputDevice &dev, const SUMOTime period, const double numLanes, const double defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
Definition: MSMeanData.cpp:373
MSMeanData::MeanDataValueTracker::notifyLeave
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:334
MSMeanData::MeanDataValueTracker::TrackerEntry::myValues
MeanDataValues * myValues
The number of vehicles which left in the current interval.
Definition: MSMeanData.h:277
MSMeanData::MeanDataValueTracker::TrackerEntry::TrackerEntry
TrackerEntry(MeanDataValues *const values)
Constructor.
Definition: MSMeanData.h:262
MSMoveReminder::Notification
Notification
Definition of a vehicle state.
Definition: MSMoveReminder.h:91
MSMeanData::MeanDataValueTracker::myTrackedData
std::map< const SUMOTrafficObject *, TrackerEntry * > myTrackedData
The map of vehicles to data entries.
Definition: MSMeanData.h:281
MSMeanData::writePrefix
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:589
MSMeanData::MeanDataValues::MeanDataValues
MeanDataValues(MSLane *const lane, const double length, const bool doAdd, const MSMeanData *const parent)
Constructor.
Definition: MSMeanData.cpp:57
MSMeanData::detectorUpdate
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
Definition: MSMeanData.cpp:645
MSMeanData::MeanDataValueTracker::getNumReady
int getNumReady() const
Definition: MSMeanData.cpp:385