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-2018 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(SUMOVehicle& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
98 
99 
113  bool notifyMove(SUMOVehicle& veh, double oldPos,
114  double newPos, double newSpeed);
115 
116 
125  virtual bool notifyLeave(SUMOVehicle& 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 SUMOVehicle& 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(SUMOVehicle& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
224 
225 
237  bool notifyEnter(SUMOVehicle& 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 SUMOVehicle*, TrackerEntry*> myTrackedData;
283 
285  std::list<TrackerEntry*> myCurrentData;
286 
287  };
288 
289 
290 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 double minSamples,
310  const double maxTravelTime,
311  const std::string& vTypes);
312 
313 
315  virtual ~MSMeanData();
316 
319  void init();
320 
323 
338  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
339 
346  virtual void writeXMLDetectorProlog(OutputDevice& dev) const;
348 
351  virtual void detectorUpdate(const SUMOTime step);
352 
353  double getMinSamples() const {
354  return myMinSamples;
355  }
356 
357  double getMaxTravelTime() const {
358  return myMaxTravelTime;
359  }
360 
361 
362 protected:
368  virtual MSMeanData::MeanDataValues* createValues(MSLane* const lane, const double length, const bool doAdd) const = 0;
369 
375  void resetOnly(SUMOTime stopTime);
376 
381  virtual std::string getEdgeID(const MSEdge* const edge);
382 
397  void writeEdge(OutputDevice& dev, const std::vector<MeanDataValues*>& edgeValues,
398  MSEdge* edge, SUMOTime startTime, SUMOTime stopTime);
399 
406  virtual void openInterval(OutputDevice& dev, const SUMOTime startTime, const SUMOTime stopTime);
407 
417  virtual bool writePrefix(OutputDevice& dev, const MeanDataValues& values,
418  const SumoXMLTag tag, const std::string id) const;
419 
420 protected:
422  const double myMinSamples;
423 
425  const double myMaxTravelTime;
426 
428  std::vector<std::vector<MeanDataValues*> > myMeasures;
429 
431  const bool myDumpEmpty;
432 
433 private:
435  const bool myAmEdgeBased;
436 
439 
442 
444  const bool myPrintDefaults;
445 
447  const bool myDumpInternal;
448 
450  const bool myTrackVehicles;
451 
453  std::list< std::pair<SUMOTime, SUMOTime> > myPendingIntervals;
454 
455 private:
457  MSMeanData(const MSMeanData&);
458 
461 
462 };
463 
464 
465 #endif
466 
467 /****************************************************************************/
468 
Data collector for edges/lanes.
Definition: MSMeanData.h:60
SumoXMLTag
Numbers representing SUMO-XML - element names.
long long int SUMOTime
Definition: SUMOTime.h:36
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
Definition: MSMeanData.h:428
const bool myDumpInternal
Whether internal lanes/edges shall be written.
Definition: MSMeanData.h:447
virtual bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle enters the reminder&#39;s lane.
Definition: MSMeanData.cpp:73
virtual ~TrackerEntry()
Constructor.
Definition: MSMeanData.h:267
const SUMOTime myDumpEnd
Definition: MSMeanData.h:438
const double myMaxTravelTime
the maximum travel time to write
Definition: MSMeanData.h:425
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.
std::map< const SUMOVehicle *, TrackerEntry * > myTrackedData
The map of vehicles to data entries.
Definition: MSMeanData.h:282
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
virtual void notifyMoveInternal(const SUMOVehicle &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.
TrackerEntry(MeanDataValues *const values)
Constructor.
Definition: MSMeanData.h:263
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.
bool notifyMove(SUMOVehicle &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
Definition: MSMeanData.cpp:85
A road/street connecting two junctions.
Definition: MSEdge.h:75
const bool myPrintDefaults
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:444
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
Representation of a vehicle.
Definition: SUMOVehicle.h:60
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:441
const bool myAmEdgeBased
Information whether the output shall be edge-based (not lane-based)
Definition: MSMeanData.h:435
std::vector< MSEdge * > MSEdgeVector
Definition: MSMeanData.h:42
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 double minSamples, const double maxTravelTime, const std::string &vTypes)
Constructor.
Definition: MSMeanData.cpp:405
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:438
const double myLaneLength
The length of the lane / edge the data collector is on.
Definition: MSMeanData.h:168
virtual ~MSMeanData()
Destructor.
Definition: MSMeanData.cpp:471
const double myMinSamples
the minimum sample seconds
Definition: MSMeanData.h:422
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:577
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:594
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:453
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "netstats" as root element.
Definition: MSMeanData.cpp:634
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:584
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:640
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:71
void resetOnly(SUMOTime stopTime)
Resets network value in order to allow processing of the next interval.
Definition: MSMeanData.cpp:481
const bool myDumpEmpty
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:431
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:450
Representation of a lane in the micro simulation.
Definition: MSLane.h:78
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:511
double getMaxTravelTime() const
Definition: MSMeanData.h:357
virtual std::string getEdgeID(const MSEdge *const edge)
Return the relevant edge id.
Definition: MSMeanData.cpp:505
virtual bool notifyLeave(SUMOVehicle &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder&#39;s lane.
Definition: MSMeanData.cpp:255
Base of value-generating classes (detectors)
double getMinSamples() const
Definition: MSMeanData.h:353
void init()
Adds the value collectors to all relevant edges.
Definition: MSMeanData.cpp:426