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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // Data collector for edges/lanes
19 /****************************************************************************/
20 #ifndef MSMeanData_h
21 #define MSMeanData_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <vector>
34 #include <set>
35 #include <list>
36 #include <limits>
39 #include <utils/common/SUMOTime.h>
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class OutputDevice;
46 class MSEdge;
47 class MSLane;
49 
50 typedef std::vector<MSEdge*> MSEdgeVector;
51 
52 // ===========================================================================
53 // class definitions
54 // ===========================================================================
67 public:
75  class MeanDataValues : public MSMoveReminder {
76  public:
78  MeanDataValues(MSLane* const lane, const double length, const bool doAdd, const MSMeanData* const parent);
79 
81  virtual ~MeanDataValues();
82 
83 
86  virtual void reset(bool afterWrite = false) = 0;
87 
92  virtual void addTo(MeanDataValues& val) const = 0;
93 
94 
103  virtual bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
104 
105 
119  bool notifyMove(SUMOVehicle& veh, double oldPos,
120  double newPos, double newSpeed);
121 
122 
131  virtual bool notifyLeave(SUMOVehicle& veh, double lastPos,
132  MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
133 
134 
139  virtual bool isEmpty() const;
140 
141 
144  virtual void update();
145 
153  virtual void write(OutputDevice& dev, const SUMOTime period,
154  const double numLanes, const double defaultTravelTime,
155  const int numVehicles = -1) const = 0;
156 
160  virtual double getSamples() const;
161 
165  double getTravelledDistance() const {
166  return travelledDistance;
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 SUMOVehicle& 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(SUMOVehicle& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
230 
231 
243  bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
245 
246  bool isEmpty() const;
247 
255  void write(OutputDevice& dev, const SUMOTime period,
256  const double numLanes, const double defaultTravelTime,
257  const int numVehicles = -1) const;
258 
259  int getNumReady() const;
260 
261  void clearFirst();
262 
263  double getSamples() const;
264 
265  private:
266  class TrackerEntry {
267  public:
270  : myNumVehicleEntered(0), myNumVehicleLeft(0), myValues(values) {}
271 
273  virtual ~TrackerEntry() {
274  delete myValues;
275  }
276 
279 
282 
285  };
286 
288  std::map<const SUMOVehicle*, TrackerEntry*> myTrackedData;
289 
291  std::list<TrackerEntry*> myCurrentData;
292 
293  };
294 
295 
296 public:
311  MSMeanData(const std::string& id,
312  const SUMOTime dumpBegin, const SUMOTime dumpEnd,
313  const bool useLanes, const bool withEmpty,
314  const bool printDefaults, const bool withInternal,
315  const bool trackVehicles, const double minSamples,
316  const double maxTravelTime,
317  const std::string& vTypes);
318 
319 
321  virtual ~MSMeanData();
322 
325  void init();
326 
329 
344  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
345 
352  virtual void writeXMLDetectorProlog(OutputDevice& dev) const;
354 
357  virtual void detectorUpdate(const SUMOTime step);
358 
359  double getMinSamples() const {
360  return myMinSamples;
361  }
362 
363  double getMaxTravelTime() const {
364  return myMaxTravelTime;
365  }
366 
367 
368 protected:
374  virtual MSMeanData::MeanDataValues* createValues(MSLane* const lane, const double length, const bool doAdd) const = 0;
375 
381  void resetOnly(SUMOTime stopTime);
382 
387  virtual std::string getEdgeID(const MSEdge* const edge);
388 
403  void writeEdge(OutputDevice& dev, const std::vector<MeanDataValues*>& edgeValues,
404  MSEdge* edge, SUMOTime startTime, SUMOTime stopTime);
405 
412  virtual void openInterval(OutputDevice& dev, const SUMOTime startTime, const SUMOTime stopTime);
413 
423  virtual bool writePrefix(OutputDevice& dev, const MeanDataValues& values,
424  const SumoXMLTag tag, const std::string id) const;
425 
426 protected:
428  const double myMinSamples;
429 
431  const double myMaxTravelTime;
432 
434  std::vector<std::vector<MeanDataValues*> > myMeasures;
435 
437  const bool myDumpEmpty;
438 
439 private:
441  const bool myAmEdgeBased;
442 
445 
448 
450  const bool myPrintDefaults;
451 
453  const bool myDumpInternal;
454 
456  const bool myTrackVehicles;
457 
459  std::list< std::pair<SUMOTime, SUMOTime> > myPendingIntervals;
460 
461 private:
463  MSMeanData(const MSMeanData&);
464 
467 
468 };
469 
470 
471 #endif
472 
473 /****************************************************************************/
474 
Data collector for edges/lanes.
Definition: MSMeanData.h:66
SumoXMLTag
Numbers representing SUMO-XML - element names.
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
Definition: MSMeanData.h:434
const bool myDumpInternal
Whether internal lanes/edges shall be written.
Definition: MSMeanData.h:453
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:79
virtual ~TrackerEntry()
Constructor.
Definition: MSMeanData.h:273
const SUMOTime myDumpEnd
Definition: MSMeanData.h:444
const double myMaxTravelTime
the maximum travel time to write
Definition: MSMeanData.h:431
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:288
virtual bool isEmpty() const
Returns whether any data was collected.
Definition: MSMeanData.cpp:270
MeanDataValues * myValues
The number of vehicles which left in the current interval.
Definition: MSMeanData.h:284
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:269
std::list< TrackerEntry * > myCurrentData
The currently active meandata "intervals".
Definition: MSMeanData.h:291
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:91
A road/street connecting two junctions.
Definition: MSEdge.h:80
const bool myPrintDefaults
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:450
double travelledDistance
The sum of the distances the vehicles travelled.
Definition: MSMeanData.h:182
int myNumVehicleLeft
The number of vehicles which left in the current interval.
Definition: MSMeanData.h:281
Representation of a vehicle.
Definition: SUMOVehicle.h:66
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:75
Definition: MSMeanData.h:266
MSEdgeVector myEdges
The corresponding first edges.
Definition: MSMeanData.h:447
const bool myAmEdgeBased
Information whether the output shall be edge-based (not lane-based)
Definition: MSMeanData.h:441
std::vector< MSEdge * > MSEdgeVector
Definition: MSMeanData.h:48
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:411
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:444
const double myLaneLength
The length of the lane / edge the data collector is on.
Definition: MSMeanData.h:174
virtual ~MSMeanData()
Destructor.
Definition: MSMeanData.cpp:477
const double myMinSamples
the minimum sample seconds
Definition: MSMeanData.h:428
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:583
double getTravelledDistance() const
Returns the total travelled distance.
Definition: MSMeanData.h:165
virtual ~MeanDataValues()
Destructor.
Definition: MSMeanData.cpp:74
const MSMeanData *const myParent
The meandata parent.
Definition: MSMeanData.h:171
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
Definition: MSMeanData.cpp:600
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:459
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "netstats" as root element.
Definition: MSMeanData.cpp:639
virtual void update()
Called if a per timestep update is needed. Default does nothing.
Definition: MSMeanData.cpp:276
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:590
int myNumVehicleEntered
The number of vehicles which entered in the current interval.
Definition: MSMeanData.h:278
MSMoveReminder & operator=(const MSMoveReminder &)
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
Definition: MSMeanData.cpp:645
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
virtual double getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:281
long long int SUMOTime
Definition: TraCIDefs.h:51
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
void resetOnly(SUMOTime stopTime)
Resets network value in order to allow processing of the next interval.
Definition: MSMeanData.cpp:487
const bool myDumpEmpty
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:437
MeanDataValues(MSLane *const lane, const double length, const bool doAdd, const MSMeanData *const parent)
Constructor.
Definition: MSMeanData.cpp:64
Data structure for mean (aggregated) edge/lane values for tracked vehicles.
Definition: MSMeanData.h:192
const bool myTrackVehicles
Whether vehicles are tracked.
Definition: MSMeanData.h:456
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
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:517
double getMaxTravelTime() const
Definition: MSMeanData.h:363
virtual std::string getEdgeID(const MSEdge *const edge)
Return the relevant edge id.
Definition: MSMeanData.cpp:511
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:261
Base of value-generating classes (detectors)
double getMinSamples() const
Definition: MSMeanData.h:359
void init()
Adds the value collectors to all relevant edges.
Definition: MSMeanData.cpp:432