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 /****************************************************************************/
16 // Data collector for edges/lanes
17 /****************************************************************************/
18 #ifndef MSMeanData_h
19 #define MSMeanData_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <vector>
28 #include <set>
29 #include <list>
30 #include <limits>
33 #include <utils/common/SUMOTime.h>
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class OutputDevice;
40 class MSEdge;
41 class MSLane;
43 
44 typedef std::vector<MSEdge*> MSEdgeVector;
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
61 public:
69  class MeanDataValues : public MSMoveReminder {
70  public:
72  MeanDataValues(MSLane* const lane, const double length, const bool doAdd, const MSMeanData* const parent);
73 
75  virtual ~MeanDataValues();
76 
77 
80  virtual void reset(bool afterWrite = false) = 0;
81 
86  virtual void addTo(MeanDataValues& val) const = 0;
87 
88 
97  virtual bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
98 
99 
113  bool notifyMove(SUMOTrafficObject& veh, double oldPos,
114  double newPos, double newSpeed);
115 
116 
125  virtual bool notifyLeave(SUMOTrafficObject& veh, double lastPos,
126  MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
127 
128 
133  virtual bool isEmpty() const;
134 
135 
138  virtual void update();
139 
147  virtual void write(OutputDevice& dev, const SUMOTime period,
148  const double numLanes, const double defaultTravelTime,
149  const int numVehicles = -1) const = 0;
150 
154  virtual double getSamples() const;
155 
159  double getTravelledDistance() const {
160  return travelledDistance;
161  }
162 
163  protected:
165  const MSMeanData* const myParent;
166 
168  const double myLaneLength;
169 
174 
178 
179  };
180 
181 
187  public:
189  MeanDataValueTracker(MSLane* const lane, const double length,
190  const MSMeanData* const parent);
191 
193  virtual ~MeanDataValueTracker();
194 
197  void reset(bool afterWrite);
198 
203  void addTo(MSMeanData::MeanDataValues& val) const;
204 
207 
211  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);
212 
213 
223  bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
224 
225 
237  bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
239 
240  bool isEmpty() const;
241 
249  void write(OutputDevice& dev, const SUMOTime period,
250  const double numLanes, const double defaultTravelTime,
251  const int numVehicles = -1) const;
252 
253  int getNumReady() const;
254 
255  void clearFirst();
256 
257  double getSamples() const;
258 
259  private:
260  class TrackerEntry {
261  public:
264  : myNumVehicleEntered(0), myNumVehicleLeft(0), myValues(values) {}
265 
267  virtual ~TrackerEntry() {
268  delete myValues;
269  }
270 
273 
276 
279  };
280 
282  std::map<const SUMOTrafficObject*, TrackerEntry*> myTrackedData;
283 
285  std::list<TrackerEntry*> myCurrentData;
286 
287  };
288 
289 
290 public:
306  MSMeanData(const std::string& id,
307  const SUMOTime dumpBegin, const SUMOTime dumpEnd,
308  const bool useLanes, const bool withEmpty,
309  const bool printDefaults, const bool withInternal,
310  const bool trackVehicles, const int detectPersons,
311  const double minSamples,
312  const double maxTravelTime,
313  const std::string& vTypes);
314 
315 
317  virtual ~MSMeanData();
318 
321  void init();
322 
325 
340  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
341 
348  virtual void writeXMLDetectorProlog(OutputDevice& dev) const;
350 
353  virtual void detectorUpdate(const SUMOTime step);
354 
355  double getMinSamples() const {
356  return myMinSamples;
357  }
358 
359  double getMaxTravelTime() const {
360  return myMaxTravelTime;
361  }
362 
363 
364 protected:
370  virtual MSMeanData::MeanDataValues* createValues(MSLane* const lane, const double length, const bool doAdd) const = 0;
371 
377  void resetOnly(SUMOTime stopTime);
378 
383  virtual std::string getEdgeID(const MSEdge* const edge);
384 
399  void writeEdge(OutputDevice& dev, const std::vector<MeanDataValues*>& edgeValues,
400  MSEdge* edge, SUMOTime startTime, SUMOTime stopTime);
401 
408  virtual void openInterval(OutputDevice& dev, const SUMOTime startTime, const SUMOTime stopTime);
409 
419  virtual bool writePrefix(OutputDevice& dev, const MeanDataValues& values,
420  const SumoXMLTag tag, const std::string id) const;
421 
422 protected:
424  const double myMinSamples;
425 
427  const double myMaxTravelTime;
428 
430  std::vector<std::vector<MeanDataValues*> > myMeasures;
431 
433  const bool myDumpEmpty;
434 
435 private:
437  const bool myAmEdgeBased;
438 
441 
444 
446  const bool myPrintDefaults;
447 
449  const bool myDumpInternal;
450 
452  const bool myTrackVehicles;
453 
455  std::list< std::pair<SUMOTime, SUMOTime> > myPendingIntervals;
456 
457 private:
459  MSMeanData(const MSMeanData&);
460 
463 
464 };
465 
466 
467 #endif
468 
469 /****************************************************************************/
470 
MSMeanData::MeanDataValueTracker::TrackerEntry
Definition: MSMeanData.h:260
SUMOTrafficObject
Representation of a vehicle or person.
Definition: SUMOTrafficObject.h:48
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:514
MSMeanData::MeanDataValueTracker::TrackerEntry::~TrackerEntry
virtual ~TrackerEntry()
Constructor.
Definition: MSMeanData.h:267
MSMeanData::myDumpEmpty
const bool myDumpEmpty
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:433
SUMOTime.h
MSDetectorFileOutput
Base of value-generating classes (detectors)
Definition: MSDetectorFileOutput.h:64
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
MSMeanData::getMaxTravelTime
double getMaxTravelTime() const
Definition: MSMeanData.h:359
MSMeanData::myAmEdgeBased
const bool myAmEdgeBased
Information whether the output shall be edge-based (not lane-based)
Definition: MSMeanData.h:437
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
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:405
MSMeanData::writeXMLDetectorProlog
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "netstats" as root element.
Definition: MSMeanData.cpp:637
MSMeanData::MeanDataValueTracker::getSamples
double getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:397
MSMeanData::MeanDataValueTracker::clearFirst
void clearFirst()
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
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:73
MSMeanData::MeanDataValues::isEmpty
virtual bool isEmpty() const
Returns whether any data was collected.
Definition: MSMeanData.cpp:264
MSMeanData::MeanDataValueTracker::MeanDataValueTracker
MeanDataValueTracker(MSLane *const lane, const double length, const MSMeanData *const parent)
Constructor.
Definition: MSMeanData.cpp:283
MSMeanData::myMeasures
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
Definition: MSMeanData.h:430
MSMeanData::myPrintDefaults
const bool myPrintDefaults
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:446
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:484
MSMeanData::myDumpEnd
const SUMOTime myDumpEnd
Definition: MSMeanData.h:440
MSDetectorFileOutput.h
SumoXMLTag
SumoXMLTag
Numbers representing SUMO-XML - element names.
Definition: SUMOXMLDefinitions.h:42
MSMeanData::writeXMLOutput
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
Definition: MSMeanData.cpp:597
MSMoveReminder
Something on a lane to be noticed about vehicle movement.
Definition: MSMoveReminder.h:64
MSMeanData::myEdges
MSEdgeVector myEdges
The corresponding first edges.
Definition: MSMeanData.h:443
MSMeanData::myDumpInternal
const bool myDumpInternal
Whether internal lanes/edges shall be written.
Definition: MSMeanData.h:449
MSMeanData::myMinSamples
const double myMinSamples
the minimum sample seconds
Definition: MSMeanData.h:424
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:341
MSMoveReminder.h
MSMeanData
Data collector for edges/lanes.
Definition: MSMeanData.h:60
MSMeanData::MeanDataValueTracker::~MeanDataValueTracker
virtual ~MeanDataValueTracker()
Destructor.
Definition: MSMeanData.cpp:291
MSMeanData::openInterval
virtual void openInterval(OutputDevice &dev, const SUMOTime startTime, const SUMOTime stopTime)
Writes the interval opener.
Definition: MSMeanData.cpp:580
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:85
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:320
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:455
MSMeanData::~MSMeanData
virtual ~MSMeanData()
Destructor.
Definition: MSMeanData.cpp:474
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:255
MSMeanData::MeanDataValues::travelledDistance
double travelledDistance
The sum of the distances the vehicles travelled.
Definition: MSMeanData.h:176
MSMeanData::myMaxTravelTime
const double myMaxTravelTime
the maximum travel time to write
Definition: MSMeanData.h:427
MSMeanData::MeanDataValues::getTravelledDistance
double getTravelledDistance() const
Returns the total travelled distance.
Definition: MSMeanData.h:159
MSMeanData::operator=
MSMeanData & operator=(const MSMeanData &)
Invalidated assignment operator.
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:76
MSMeanData::MeanDataValueTracker::TrackerEntry::myNumVehicleLeft
int myNumVehicleLeft
The number of vehicles which left in the current interval.
Definition: MSMeanData.h:275
MSMeanData::MeanDataValues::myParent
const MSMeanData *const myParent
The meandata parent.
Definition: MSMeanData.h:165
MSMeanData::MeanDataValueTracker::isEmpty
bool isEmpty() const
Returns whether any data was collected.
Definition: MSMeanData.cpp:365
MSMeanData::init
void init()
Adds the value collectors to all relevant edges.
Definition: MSMeanData.cpp:428
MSMeanData::MeanDataValues::update
virtual void update()
Called if a per timestep update is needed. Default does nothing.
Definition: MSMeanData.cpp:270
MSMeanData::MeanDataValues
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:69
MSDetectorFileOutput::detectPersons
bool detectPersons() const
Definition: MSDetectorFileOutput.h:167
MSMeanData::MeanDataValues::myLaneLength
const double myLaneLength
The length of the lane / edge the data collector is on.
Definition: MSMeanData.h:168
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:326
MSMeanData::MeanDataValues::~MeanDataValues
virtual ~MeanDataValues()
Destructor.
Definition: MSMeanData.cpp:68
MSMeanData::MeanDataValueTracker::myCurrentData
std::list< TrackerEntry * > myCurrentData
The currently active meandata "intervals".
Definition: MSMeanData.h:285
MSMeanData::MeanDataValueTracker
Data structure for mean (aggregated) edge/lane values for tracked vehicles.
Definition: MSMeanData.h:186
MSMeanData::myTrackVehicles
const bool myTrackVehicles
Whether vehicles are tracked.
Definition: MSMeanData.h:452
MSMeanData::MeanDataValues::getSamples
virtual double getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:275
MSMeanData::MeanDataValueTracker::reset
void reset(bool afterWrite)
Resets values so they may be used for the next interval.
Definition: MSMeanData.cpp:308
MSMeanData::MeanDataValueTracker::TrackerEntry::myNumVehicleEntered
int myNumVehicleEntered
The number of vehicles which entered in the current interval.
Definition: MSMeanData.h:272
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSMeanData.h:42
MSMeanData::MeanDataValues::sampleSeconds
double sampleSeconds
Definition: MSMeanData.h:173
MSMeanData::myDumpBegin
const SUMOTime myDumpBegin
The first and the last time step to write information (-1 indicates always)
Definition: MSMeanData.h:440
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:72
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:508
MSMeanData::getMinSamples
double getMinSamples() const
Definition: MSMeanData.h:355
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:371
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:332
MSMeanData::MeanDataValueTracker::TrackerEntry::myValues
MeanDataValues * myValues
The number of vehicles which left in the current interval.
Definition: MSMeanData.h:278
MSMeanData::MeanDataValueTracker::TrackerEntry::TrackerEntry
TrackerEntry(MeanDataValues *const values)
Constructor.
Definition: MSMeanData.h:263
MSMoveReminder::Notification
Notification
Definition of a vehicle state.
Definition: MSMoveReminder.h:89
MSMeanData::MeanDataValueTracker::myTrackedData
std::map< const SUMOTrafficObject *, TrackerEntry * > myTrackedData
The map of vehicles to data entries.
Definition: MSMeanData.h:282
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:587
MSMeanData::MeanDataValues::MeanDataValues
MeanDataValues(MSLane *const lane, const double length, const bool doAdd, const MSMeanData *const parent)
Constructor.
Definition: MSMeanData.cpp:58
MSMeanData::detectorUpdate
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
Definition: MSMeanData.cpp:643
MSMeanData::MeanDataValueTracker::getNumReady
int getNumReady() const
Definition: MSMeanData.cpp:383