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.sourceforge.net/
11 // Copyright (C) 2001-2012 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 <cassert>
38 #include <limits>
41 #include <utils/common/SUMOTime.h>
42 
43 
44 // ===========================================================================
45 // class declarations
46 // ===========================================================================
47 class OutputDevice;
48 class MSEdge;
49 class MSLane;
50 class SUMOVehicle;
51 
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 std::set<std::string>* const vTypes = 0);
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 
141  bool vehicleApplies(const SUMOVehicle& veh) const ;
142 
143 
148  virtual bool isEmpty() const ;
149 
150 
153  virtual void update() ;
154 
162  virtual void write(OutputDevice& dev, const SUMOTime period,
163  const SUMOReal numLanes, const SUMOReal defaultTravelTime,
164  const int numVehicles = -1) const = 0;
165 
169  virtual SUMOReal getSamples() const ;
170 
171  protected:
174 
179  public:
183 
184  private:
186  const std::set<std::string>* const myVehicleTypes;
187 
188  };
189 
190 
196  public:
198  MeanDataValueTracker(MSLane* const lane, const SUMOReal length,
199  const std::set<std::string>* const vTypes = 0,
200  const MSMeanData* const parent = 0) ;
201 
203  virtual ~MeanDataValueTracker() ;
204 
207  void reset(bool afterWrite) ;
208 
213  void addTo(MSMeanData::MeanDataValues& val) const ;
214 
217 
228  void notifyMoveInternal(SUMOVehicle& veh, SUMOReal timeOnLane, SUMOReal speed) ;
229 
230 
240  bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, MSMoveReminder::Notification reason) ;
241 
242 
256 
257  bool isEmpty() const ;
258 
266  void write(OutputDevice& dev, const SUMOTime period,
267  const SUMOReal numLanes, const SUMOReal defaultTravelTime,
268  const int numVehicles = -1) const;
269 
270  size_t getNumReady() const ;
271 
272  void clearFirst() ;
273 
274  SUMOReal getSamples() const ;
275 
276  private:
277  class TrackerEntry {
278  public:
281  : myNumVehicleEntered(0), myNumVehicleLeft(0), myValues(values) {}
282 
285 
288 
291  };
292 
294  std::map<SUMOVehicle*, TrackerEntry*> myTrackedData;
295 
297  std::list<TrackerEntry*> myCurrentData;
298 
301 
302  };
303 
304 
305 public:
320  MSMeanData(const std::string& id,
321  const SUMOTime dumpBegin, const SUMOTime dumpEnd,
322  const bool useLanes, const bool withEmpty,
323  const bool printDefaults, const bool withInternal,
324  const bool trackVehicles, const SUMOReal minSamples,
325  const SUMOReal maxTravelTime,
326  const std::set<std::string> vTypes);
327 
328 
330  virtual ~MSMeanData() ;
331 
334  void init() ;
335 
338 
353  void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
354 
361  void writeXMLDetectorProlog(OutputDevice& dev) const;
363 
366  virtual void detectorUpdate(const SUMOTime step) ;
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 
398  void writeEdge(OutputDevice& dev, const std::vector<MeanDataValues*> &edgeValues,
399  MSEdge* edge, SUMOTime startTime, SUMOTime stopTime);
400 
410  bool writePrefix(OutputDevice& dev, const MeanDataValues& values,
411  const std::string tag, const std::string id) const;
412 
413 protected:
416 
419 
421  const std::set<std::string> myVehicleTypes;
422 
424  std::vector<std::vector<MeanDataValues*> > myMeasures;
425 
426 private:
428  const bool myAmEdgeBased;
429 
432 
434  std::vector<MSEdge*> myEdges;
435 
437  const bool myDumpEmpty;
438 
440  const bool myPrintDefaults;
441 
443  const bool myDumpInternal;
444 
446  const bool myTrackVehicles;
447 
449  std::list< std::pair<SUMOTime, SUMOTime> > myPendingIntervals;
450 
451 private:
453  MSMeanData(const MSMeanData&);
454 
457 
458 };
459 
460 
461 #endif
462 
463 /****************************************************************************/
464