SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
11 // Copyright (C) 2001-2014 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;
49 class SUMOVehicle;
50 
51 
52 // ===========================================================================
53 // class definitions
54 // ===========================================================================
67 public:
75  class MeanDataValues : public MSMoveReminder {
76  public:
78  MeanDataValues(MSLane* const lane, const SUMOReal length, const bool doAdd, const std::set<std::string>* const vTypes = 0);
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);
104 
105 
119  bool notifyMove(SUMOVehicle& veh, SUMOReal oldPos,
120  SUMOReal newPos, SUMOReal newSpeed);
121 
122 
131  virtual bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos,
133 
134 
140  bool vehicleApplies(const SUMOVehicle& veh) const;
141 
142 
147  virtual bool isEmpty() const;
148 
149 
152  virtual void update();
153 
161  virtual void write(OutputDevice& dev, const SUMOTime period,
162  const SUMOReal numLanes, const SUMOReal defaultTravelTime,
163  const int numVehicles = -1) const = 0;
164 
168  virtual SUMOReal getSamples() const;
169 
170  protected:
173 
178  public:
182 
183  protected:
185  const std::set<std::string>* const myVehicleTypes;
186 
187  };
188 
189 
195  public:
197  MeanDataValueTracker(MSLane* const lane, const SUMOReal length,
198  const std::set<std::string>* const vTypes = 0,
199  const MSMeanData* const parent = 0);
200 
202  virtual ~MeanDataValueTracker();
203 
206  void reset(bool afterWrite);
207 
212  void addTo(MSMeanData::MeanDataValues& val) const;
213 
216 
227  void notifyMoveInternal(SUMOVehicle& veh, SUMOReal timeOnLane, SUMOReal speed);
228 
229 
239  bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, MSMoveReminder::Notification reason);
240 
241 
255 
256  bool isEmpty() const;
257 
265  void write(OutputDevice& dev, const SUMOTime period,
266  const SUMOReal numLanes, const SUMOReal defaultTravelTime,
267  const int numVehicles = -1) const;
268 
269  int getNumReady() const;
270 
271  void clearFirst();
272 
273  SUMOReal getSamples() const;
274 
275  private:
276  class TrackerEntry {
277  public:
280  : myNumVehicleEntered(0), myNumVehicleLeft(0), myValues(values) {}
281 
284 
287 
290  };
291 
293  std::map<SUMOVehicle*, TrackerEntry*> myTrackedData;
294 
296  std::list<TrackerEntry*> myCurrentData;
297 
300 
301  };
302 
303 
304 public:
319  MSMeanData(const std::string& id,
320  const SUMOTime dumpBegin, const SUMOTime dumpEnd,
321  const bool useLanes, const bool withEmpty,
322  const bool printDefaults, const bool withInternal,
323  const bool trackVehicles, const SUMOReal minSamples,
324  const SUMOReal maxTravelTime,
325  const std::set<std::string> vTypes);
326 
327 
329  virtual ~MSMeanData();
330 
333  void init();
334 
337 
352  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
353 
360  virtual void writeXMLDetectorProlog(OutputDevice& dev) const;
362 
365  virtual void detectorUpdate(const SUMOTime step);
366 
367 
368 protected:
374  virtual MSMeanData::MeanDataValues* createValues(MSLane* const lane, const SUMOReal 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:
429 
432 
434  const std::set<std::string> myVehicleTypes;
435 
437  std::vector<std::vector<MeanDataValues*> > myMeasures;
438 
440  const bool myDumpEmpty;
441 
442 private:
444  const bool myAmEdgeBased;
445 
448 
450  std::vector<MSEdge*> myEdges;
451 
453  const bool myPrintDefaults;
454 
456  const bool myDumpInternal;
457 
459  const bool myTrackVehicles;
460 
462  std::list< std::pair<SUMOTime, SUMOTime> > myPendingIntervals;
463 
464 private:
466  MSMeanData(const MSMeanData&);
467 
470 
471 };
472 
473 
474 #endif
475 
476 /****************************************************************************/
477 
Data collector for edges/lanes.
Definition: MSMeanData.h:66
virtual ~MeanDataValueTracker()
Destructor.
Definition: MSMeanData.cpp:154
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:172
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
Definition: MSMeanData.h:437
MeanDataValues(MSLane *const lane, const SUMOReal length, const bool doAdd, const std::set< std::string > *const vTypes=0)
Constructor.
Definition: MSMeanData.cpp:63
const bool myDumpInternal
Whether internal lanes/edges shall be written.
Definition: MSMeanData.h:456
const SUMOTime myDumpEnd
Definition: MSMeanData.h:447
const std::set< std::string > *const myVehicleTypes
The vehicle types to look for (0 or empty means all)
Definition: MSMeanData.h:185
SUMOReal travelledDistance
The sum of the distances the vehicles travelled.
Definition: MSMeanData.h:180
const SUMOReal myMaxTravelTime
the maximum travel time to write
Definition: MSMeanData.h:431
Notification
Definition of a vehicle state.
MeanDataValues * myValues
The number of vehicles which left in the current interval.
Definition: MSMeanData.h:289
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Computes current values and adds them to their sums.
Definition: MSMeanData.cpp:190
const std::set< std::string > myVehicleTypes
The vehicle types to look for (empty means all)
Definition: MSMeanData.h:434
MSMeanData & operator=(const MSMeanData &)
Invalidated assignment operator.
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:434
const MSMeanData * myParent
The meandata parent.
Definition: MSMeanData.h:299
TrackerEntry(MeanDataValues *const values)
Constructor.
Definition: MSMeanData.h:279
std::list< TrackerEntry * > myCurrentData
The currently active meandata "intervals".
Definition: MSMeanData.h:296
A road/street connecting two junctions.
Definition: MSEdge.h:74
const bool myPrintDefaults
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:453
MeanDataValueTracker(MSLane *const lane, const SUMOReal length, const std::set< std::string > *const vTypes=0, const MSMeanData *const parent=0)
Constructor.
Definition: MSMeanData.cpp:145
virtual bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, MSMoveReminder::Notification reason)
Called if the vehicle leaves the reminder's lane.
Definition: MSMeanData.cpp:113
int myNumVehicleLeft
The number of vehicles which left in the current interval.
Definition: MSMeanData.h:286
Representation of a vehicle.
Definition: SUMOVehicle.h:64
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:75
Definition: MSMeanData.h:276
const bool myAmEdgeBased
Information whether the output shall be edge-based (not lane-based)
Definition: MSMeanData.h:444
virtual bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Called if the vehicle enters the reminder's lane.
Definition: MSMeanData.cpp:78
virtual bool isEmpty() const
Returns whether any data was collected.
Definition: MSMeanData.cpp:126
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Opens the XML-output using "netstats" as root element.
Definition: MSMeanData.cpp:483
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:447
virtual ~MSMeanData()
Destructor.
Definition: MSMeanData.cpp:317
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:85
const SUMOReal myMinSamples
the minimum sample seconds
Definition: MSMeanData.h:428
void notifyMoveInternal(SUMOVehicle &veh, SUMOReal timeOnLane, SUMOReal speed)
Internal notification about the vehicle moves.
Definition: MSMeanData.cpp:175
bool isEmpty() const
Returns whether any data was collected.
Definition: MSMeanData.cpp:209
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:427
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::set< std::string > vTypes)
Constructor.
Definition: MSMeanData.cpp:249
void addTo(MSMeanData::MeanDataValues &val) const
Add the values of this to the given one and store them there.
Definition: MSMeanData.cpp:169
virtual ~MeanDataValues()
Destructor.
Definition: MSMeanData.cpp:73
void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Writes collected values into the given stream.
Definition: MSMeanData.cpp:444
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:462
std::vector< MSEdge * > myEdges
The corresponding first edges.
Definition: MSMeanData.h:450
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:359
virtual void update()
Called if a per timestep update is needed. Default does nothing.
Definition: MSMeanData.cpp:132
int myNumVehicleEntered
The number of vehicles which entered in the current interval.
Definition: MSMeanData.h:283
std::map< SUMOVehicle *, TrackerEntry * > myTrackedData
The map of vehicles to data entries.
Definition: MSMeanData.h:293
void write(OutputDevice &dev, const SUMOTime period, const SUMOReal numLanes, const SUMOReal defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
Definition: MSMeanData.cpp:215
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
Definition: MSMeanData.cpp:489
SUMOReal getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:241
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:215
virtual SUMOReal getSamples() const
Returns the number of collected sample seconds.
Definition: MSMeanData.cpp:137
bool vehicleApplies(const SUMOVehicle &veh) const
Tests whether the vehicles type is to be regarded.
Definition: MSMeanData.cpp:119
void resetOnly(SUMOTime stopTime)
Resets network value in order to allow processing of the next interval.
Definition: MSMeanData.cpp:327
const bool myDumpEmpty
Whether empty lanes/edges shall be written.
Definition: MSMeanData.h:440
Data structure for mean (aggregated) edge/lane values for tracked vehicles.
Definition: MSMeanData.h:194
const bool myTrackVehicles
Whether vehicles are tracked.
Definition: MSMeanData.h:459
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
virtual std::string getEdgeID(const MSEdge *const edge)
Return the relevant edge id.
Definition: MSMeanData.cpp:353
Base of value-generating classes (detectors)
bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, MSMoveReminder::Notification reason)
Called if the vehicle leaves the reminder's lane.
Definition: MSMeanData.cpp:181
void init()
Adds the value collectors to all relevant edges.
Definition: MSMeanData.cpp:271
void reset(bool afterWrite)
Resets values so they may be used for the next interval.
Definition: MSMeanData.cpp:159