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 
Data collector for edges/lanes.
Definition: MSMeanData.h:60
SumoXMLTag
Numbers representing SUMO-XML - element names.
long long int SUMOTime
Definition: SUMOTime.h:35
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
Definition: MSMeanData.h:430
const bool myDumpInternal
Whether internal lanes/edges shall be written.
Definition: MSMeanData.h:449
virtual ~TrackerEntry()
Constructor.
Definition: MSMeanData.h:267
const SUMOTime myDumpEnd
Definition: MSMeanData.h:440
const double myMaxTravelTime
the maximum travel time to write
Definition: MSMeanData.h:427
virtual bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle enters the reminder&#39;s lane.
Definition: MSMeanData.cpp:73
Notification
Definition of a vehicle state.
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.
virtual bool isEmpty() const
Returns whether any data was collected.
Definition: MSMeanData.cpp:264
MeanDataValues * myValues
The number of vehicles which left in the current interval.
Definition: MSMeanData.h:278
TrackerEntry(MeanDataValues *const values)
Constructor.
Definition: MSMeanData.h:263
virtual 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.
std::list< TrackerEntry * > myCurrentData
The currently active meandata "intervals".
Definition: MSMeanData.h:285
virtual MSMeanData::MeanDataValues * createValues(MSLane *const lane, const double length, const bool doAdd) const =0
Create an instance of MeanDataValues.
A road/street connecting two junctions.
Definition: MSEdge.h:76
const bool myPrintDefaults
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:446
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
double travelledDistance
The sum of the distances the vehicles travelled.
Definition: MSMeanData.h:176
int myNumVehicleLeft
The number of vehicles which left in the current interval.
Definition: MSMeanData.h:275
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:69
Definition: MSMeanData.h:260
MSEdgeVector myEdges
The corresponding first edges.
Definition: MSMeanData.h:443
const bool myAmEdgeBased
Information whether the output shall be edge-based (not lane-based)
Definition: MSMeanData.h:437
std::vector< MSEdge * > MSEdgeVector
Definition: MSMeanData.h:42
Something on a lane to be noticed about vehicle movement.
const SUMOTime myDumpBegin
The first and the last time step to write information (-1 indicates always)
Definition: MSMeanData.h:440
const double myLaneLength
The length of the lane / edge the data collector is on.
Definition: MSMeanData.h:168
virtual ~MSMeanData()
Destructor.
Definition: MSMeanData.cpp:474
const double myMinSamples
the minimum sample seconds
Definition: MSMeanData.h:424
virtual bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder&#39;s lane.
Definition: MSMeanData.cpp:255
virtual void addTo(MeanDataValues &val) const =0
Add the values of this to the given one and store them there.
virtual void openInterval(OutputDevice &dev, const SUMOTime startTime, const SUMOTime stopTime)
Writes the interval opener.
Definition: MSMeanData.cpp:580
double getTravelledDistance() const
Returns the total travelled distance.
Definition: MSMeanData.h:159
virtual ~MeanDataValues()
Destructor.
Definition: MSMeanData.cpp:68
const MSMeanData *const myParent
The meandata parent.
Definition: MSMeanData.h:165
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
Definition: MSMeanData.cpp:597
Representation of a vehicle or person.
virtual void reset(bool afterWrite=false)=0
Resets values so they may be used for the next interval.
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
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "netstats" as root element.
Definition: MSMeanData.cpp:637
virtual void update()
Called if a per timestep update is needed. Default does nothing.
Definition: MSMeanData.cpp:270
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
int myNumVehicleEntered
The number of vehicles which entered in the current interval.
Definition: MSMeanData.h:272
MSMoveReminder & operator=(const MSMoveReminder &)
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
Definition: MSMeanData.cpp:643
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
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
virtual double getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:275
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:72
void resetOnly(SUMOTime stopTime)
Resets network value in order to allow processing of the next interval.
Definition: MSMeanData.cpp:484
const bool myDumpEmpty
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:433
MeanDataValues(MSLane *const lane, const double length, const bool doAdd, const MSMeanData *const parent)
Constructor.
Definition: MSMeanData.cpp:58
Data structure for mean (aggregated) edge/lane values for tracked vehicles.
Definition: MSMeanData.h:186
const bool myTrackVehicles
Whether vehicles are tracked.
Definition: MSMeanData.h:452
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
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
double getMaxTravelTime() const
Definition: MSMeanData.h:359
virtual std::string getEdgeID(const MSEdge *const edge)
Return the relevant edge id.
Definition: MSMeanData.cpp:508
Base of value-generating classes (detectors)
double getMinSamples() const
Definition: MSMeanData.h:355
std::map< const SUMOTrafficObject *, TrackerEntry * > myTrackedData
The map of vehicles to data entries.
Definition: MSMeanData.h:282
void init()
Adds the value collectors to all relevant edges.
Definition: MSMeanData.cpp:428