SUMO - Simulation of Urban MObility
MSMeanData.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // Data collector for edges/lanes
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 #ifndef MSMeanData_h
22 #define MSMeanData_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <vector>
35 #include <set>
36 #include <list>
37 #include <limits>
40 #include <utils/common/SUMOTime.h>
41 
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
46 class OutputDevice;
47 class MSEdge;
48 class MSLane;
50 
51 typedef std::vector<MSEdge*> MSEdgeVector;
52 
53 // ===========================================================================
54 // class definitions
55 // ===========================================================================
68 public:
76  class MeanDataValues : public MSMoveReminder {
77  public:
79  MeanDataValues(MSLane* const lane, const SUMOReal length, const bool doAdd, const MSMeanData* const parent);
80 
82  virtual ~MeanDataValues();
83 
84 
87  virtual void reset(bool afterWrite = false) = 0;
88 
93  virtual void addTo(MeanDataValues& val) const = 0;
94 
95 
104  virtual bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason);
105 
106 
120  bool notifyMove(SUMOVehicle& veh, SUMOReal oldPos,
121  SUMOReal newPos, SUMOReal newSpeed);
122 
123 
132  virtual bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos,
134 
135 
140  virtual bool isEmpty() const;
141 
142 
145  virtual void update();
146 
154  virtual void write(OutputDevice& dev, const SUMOTime period,
155  const SUMOReal numLanes, const SUMOReal defaultTravelTime,
156  const int numVehicles = -1) const = 0;
157 
161  virtual SUMOReal getSamples() const;
162 
167  return travelledDistance;
168  }
169 
170  protected:
172  const MSMeanData* const myParent;
173 
176 
181 
185 
186  };
187 
188 
194  public:
196  MeanDataValueTracker(MSLane* const lane, const SUMOReal length,
197  const MSMeanData* const parent);
198 
200  virtual ~MeanDataValueTracker();
201 
204  void reset(bool afterWrite);
205 
210  void addTo(MSMeanData::MeanDataValues& val) const;
211 
214 
218  void notifyMoveInternal(const SUMOVehicle& veh, const SUMOReal frontOnLane, const SUMOReal timeOnLane, const SUMOReal meanSpeedFrontOnLane, const SUMOReal meanSpeedVehicleOnLane, const SUMOReal travelledDistanceFrontOnLane, const SUMOReal travelledDistanceVehicleOnLane);
219 
220 
230  bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, MSMoveReminder::Notification reason);
231 
232 
246 
247  bool isEmpty() const;
248 
256  void write(OutputDevice& dev, const SUMOTime period,
257  const SUMOReal numLanes, const SUMOReal defaultTravelTime,
258  const int numVehicles = -1) const;
259 
260  int getNumReady() const;
261 
262  void clearFirst();
263 
264  SUMOReal getSamples() const;
265 
266  private:
267  class TrackerEntry {
268  public:
271  : myNumVehicleEntered(0), myNumVehicleLeft(0), myValues(values) {}
272 
274  virtual ~TrackerEntry() {
275  delete myValues;
276  }
277 
280 
283 
286  };
287 
289  std::map<const SUMOVehicle*, TrackerEntry*> myTrackedData;
290 
292  std::list<TrackerEntry*> myCurrentData;
293 
294  };
295 
296 
297 public:
312  MSMeanData(const std::string& id,
313  const SUMOTime dumpBegin, const SUMOTime dumpEnd,
314  const bool useLanes, const bool withEmpty,
315  const bool printDefaults, const bool withInternal,
316  const bool trackVehicles, const SUMOReal minSamples,
317  const SUMOReal maxTravelTime,
318  const std::string& vTypes);
319 
320 
322  virtual ~MSMeanData();
323 
326  void init();
327 
330 
345  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
346 
353  virtual void writeXMLDetectorProlog(OutputDevice& dev) const;
355 
358  virtual void detectorUpdate(const SUMOTime step);
359 
361  return myMinSamples;
362  }
363 
365  return myMaxTravelTime;
366  }
367 
368 
369 protected:
375  virtual MSMeanData::MeanDataValues* createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const = 0;
376 
382  void resetOnly(SUMOTime stopTime);
383 
388  virtual std::string getEdgeID(const MSEdge* const edge);
389 
404  void writeEdge(OutputDevice& dev, const std::vector<MeanDataValues*>& edgeValues,
405  MSEdge* edge, SUMOTime startTime, SUMOTime stopTime);
406 
413  virtual void openInterval(OutputDevice& dev, const SUMOTime startTime, const SUMOTime stopTime);
414 
424  virtual bool writePrefix(OutputDevice& dev, const MeanDataValues& values,
425  const SumoXMLTag tag, const std::string id) const;
426 
427 protected:
430 
433 
435  std::vector<std::vector<MeanDataValues*> > myMeasures;
436 
438  const bool myDumpEmpty;
439 
440 private:
442  const bool myAmEdgeBased;
443 
446 
449 
451  const bool myPrintDefaults;
452 
454  const bool myDumpInternal;
455 
457  const bool myTrackVehicles;
458 
460  std::list< std::pair<SUMOTime, SUMOTime> > myPendingIntervals;
461 
462 private:
464  MSMeanData(const MSMeanData&);
465 
468 
469 };
470 
471 
472 #endif
473 
474 /****************************************************************************/
475 
Data collector for edges/lanes.
Definition: MSMeanData.h:67
virtual MSMeanData::MeanDataValues * createValues(MSLane *const lane, const SUMOReal length, const bool doAdd) const =0
Create an instance of MeanDataValues.
SumoXMLTag
Numbers representing SUMO-XML - element names.
const SUMOReal myLaneLength
The length of the lane / edge the data collector is on.
Definition: MSMeanData.h:175
long long int SUMOTime
Definition: SUMOTime.h:43
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
Definition: MSMeanData.h:435
const bool myDumpInternal
Whether internal lanes/edges shall be written.
Definition: MSMeanData.h:454
virtual ~TrackerEntry()
Constructor.
Definition: MSMeanData.h:274
const SUMOTime myDumpEnd
Definition: MSMeanData.h:445
SUMOReal travelledDistance
The sum of the distances the vehicles travelled.
Definition: MSMeanData.h:183
const SUMOReal myMaxTravelTime
the maximum travel time to write
Definition: MSMeanData.h:432
Notification
Definition of a vehicle state.
std::map< const SUMOVehicle *, TrackerEntry * > myTrackedData
The map of vehicles to data entries.
Definition: MSMeanData.h:289
virtual bool isEmpty() const
Returns whether any data was collected.
Definition: MSMeanData.cpp:175
MeanDataValues * myValues
The number of vehicles which left in the current interval.
Definition: MSMeanData.h:285
virtual void notifyMoveInternal(const SUMOVehicle &veh, const SUMOReal frontOnLane, const SUMOReal timeOnLane, const SUMOReal meanSpeedFrontOnLane, const SUMOReal meanSpeedVehicleOnLane, const SUMOReal travelledDistanceFrontOnLane, const SUMOReal travelledDistanceVehicleOnLane)
Internal notification about the vehicle moves.
TrackerEntry(MeanDataValues *const values)
Constructor.
Definition: MSMeanData.h:270
std::list< TrackerEntry * > myCurrentData
The currently active meandata "intervals".
Definition: MSMeanData.h:292
MeanDataValues(MSLane *const lane, const SUMOReal length, const bool doAdd, const MSMeanData *const parent)
Constructor.
Definition: MSMeanData.cpp:62
A road/street connecting two junctions.
Definition: MSEdge.h:80
const bool myPrintDefaults
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:451
virtual bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, MSMoveReminder::Notification reason)
Called if the vehicle leaves the reminder&#39;s lane.
Definition: MSMeanData.cpp:166
int myNumVehicleLeft
The number of vehicles which left in the current interval.
Definition: MSMeanData.h:282
Representation of a vehicle.
Definition: SUMOVehicle.h:66
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:76
SUMOReal getMaxTravelTime() const
Definition: MSMeanData.h:364
Definition: MSMeanData.h:267
MSEdgeVector myEdges
The corresponding first edges.
Definition: MSMeanData.h:448
const bool myAmEdgeBased
Information whether the output shall be edge-based (not lane-based)
Definition: MSMeanData.h:442
virtual bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Called if the vehicle enters the reminder&#39;s lane.
Definition: MSMeanData.cpp:77
std::vector< MSEdge * > MSEdgeVector
Definition: MSMeanData.h:49
virtual SUMOReal getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:186
SUMOReal getMinSamples() const
Definition: MSMeanData.h:360
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 SUMOReal minSamples, const SUMOReal maxTravelTime, const std::string &vTypes)
Constructor.
Definition: MSMeanData.cpp:311
virtual void write(OutputDevice &dev, const SUMOTime period, const SUMOReal numLanes, const SUMOReal defaultTravelTime, const int numVehicles=-1) const =0
Writes output values into the given stream.
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:445
virtual ~MSMeanData()
Destructor.
Definition: MSMeanData.cpp:379
bool notifyMove(SUMOVehicle &veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
Definition: MSMeanData.cpp:84
const SUMOReal myMinSamples
the minimum sample seconds
Definition: MSMeanData.h:429
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:485
virtual ~MeanDataValues()
Destructor.
Definition: MSMeanData.cpp:72
SUMOReal getTravelledDistance() const
Returns the total travelled distance.
Definition: MSMeanData.h:166
const MSMeanData *const myParent
The meandata parent.
Definition: MSMeanData.h:172
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
Definition: MSMeanData.cpp:502
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:460
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "netstats" as root element.
Definition: MSMeanData.cpp:541
virtual void update()
Called if a per timestep update is needed. Default does nothing.
Definition: MSMeanData.cpp:181
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:492
int myNumVehicleEntered
The number of vehicles which entered in the current interval.
Definition: MSMeanData.h:279
MSMoveReminder & operator=(const MSMoveReminder &)
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
Definition: MSMeanData.cpp:547
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:213
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:389
const bool myDumpEmpty
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:438
Data structure for mean (aggregated) edge/lane values for tracked vehicles.
Definition: MSMeanData.h:193
const bool myTrackVehicles
Whether vehicles are tracked.
Definition: MSMeanData.h:457
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
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:419
virtual std::string getEdgeID(const MSEdge *const edge)
Return the relevant edge id.
Definition: MSMeanData.cpp:413
Base of value-generating classes (detectors)
void init()
Adds the value collectors to all relevant edges.
Definition: MSMeanData.cpp:332