MSMeanData.h
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef MSMeanData_h
00020 #define MSMeanData_h
00021
00022
00023
00024
00025
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031
00032 #include <vector>
00033 #include <set>
00034 #include <list>
00035 #include <cassert>
00036 #include <limits>
00037 #include <microsim/output/MSDetectorFileOutput.h>
00038 #include <microsim/MSMoveReminder.h>
00039 #include <utils/common/SUMOTime.h>
00040
00041
00042
00043
00044
00045 class OutputDevice;
00046 class MSEdge;
00047 class MSLane;
00048 class SUMOVehicle;
00049
00050
00051
00052
00053
00065 class MSMeanData : public MSDetectorFileOutput {
00066 public:
00074 class MeanDataValues : public MSMoveReminder {
00075 public:
00077 MeanDataValues(MSLane * const lane, const bool doAdd, const std::set<std::string>* const vTypes=0) throw();
00078
00080 virtual ~MeanDataValues() throw();
00081
00082
00085 virtual void reset() throw() = 0;
00086
00091 virtual void addTo(MeanDataValues& val) const throw() = 0;
00092
00095
00101 bool vehicleApplies(const SUMOVehicle& veh) const throw();
00103
00104
00109 virtual bool isEmpty() const throw();
00110
00111
00114 virtual void update() throw();
00115
00124 virtual void write(OutputDevice &dev, const SUMOTime period,
00125 const SUMOReal numLanes, const SUMOReal length,
00126 const int numVehicles=-1) const throw(IOError) = 0;
00127
00128 virtual SUMOReal getSamples() const throw();
00129
00130 protected:
00134 SUMOReal sampleSeconds;
00136 public:
00137 SUMOReal travelledDistance;
00139
00140 private:
00142 const std::set<std::string>* const myVehicleTypes;
00143
00144 };
00145
00146
00151 class MeanDataValueTracker : public MeanDataValues {
00152 public:
00154 MeanDataValueTracker(MSLane * const lane, const std::set<std::string>* const vTypes=0,
00155 const MSMeanData* const parent=0) throw();
00156
00158 virtual ~MeanDataValueTracker() throw();
00159
00162 void reset() throw();
00163
00168 void addTo(MSMeanData::MeanDataValues& val) const throw();
00169
00172
00189 bool isStillActive(MSVehicle& veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed) throw();
00190
00191
00198 void notifyLeave(MSVehicle& veh, bool isArrival, bool isLaneChange) throw();
00199
00200
00213 bool notifyEnter(MSVehicle& veh, bool isEmit, bool isLaneChange) throw();
00215
00216 bool isEmpty() const throw();
00217
00226 void write(OutputDevice &dev, const SUMOTime period,
00227 const SUMOReal numLanes, const SUMOReal length,
00228 const int numVehicles=-1) const throw(IOError);
00229
00230 size_t getNumReady() const throw();
00231
00232 void clearFirst() throw();
00233
00234 SUMOReal getSamples() const throw();
00235
00236 private:
00237 class TrackerEntry {
00238 public:
00240 TrackerEntry(MeanDataValues* const values) throw()
00241 : myNumVehicleEntered(0), myNumVehicleLeft(0), myValues(values) {}
00242
00244 int myNumVehicleEntered;
00245
00247 int myNumVehicleLeft;
00248
00250 MeanDataValues* myValues;
00251
00252 void reset() {
00253 myNumVehicleEntered = 0;
00254 myNumVehicleLeft = 0;
00255 myValues->reset();
00256 }
00257 };
00258
00260 std::map<MSVehicle*, TrackerEntry*> myTrackedData;
00261
00263 std::list<TrackerEntry*> myCurrentData;
00264
00266 const MSMeanData* myParent;
00267
00268 };
00269
00270
00271 public:
00284 MSMeanData(const std::string &id,
00285 const SUMOTime dumpBegin, const SUMOTime dumpEnd,
00286 const bool useLanes, const bool withEmpty,
00287 const bool trackVehicles,
00288 const SUMOReal minSamples, const SUMOReal maxTravelTime,
00289 const std::set<std::string> vTypes) throw();
00290
00291
00293 virtual ~MSMeanData() throw();
00294
00300 void init(const std::vector<MSEdge*> &edges, const bool withInternal) throw();
00301
00304
00319 void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime) throw(IOError);
00320
00327 void writeXMLDetectorProlog(OutputDevice &dev) const throw(IOError);
00329
00332 void update() throw();
00333
00334
00335 protected:
00341 virtual MSMeanData::MeanDataValues* createValues(MSLane * const lane, const bool doAdd) const throw(IOError) = 0;
00342
00348 void resetOnly(SUMOTime stopTime) throw();
00349
00364 virtual void writeEdge(OutputDevice &dev, const std::vector<MeanDataValues*> &edgeValues,
00365 MSEdge *edge, SUMOTime startTime, SUMOTime stopTime) throw(IOError);
00366
00375 bool writePrefix(OutputDevice &dev, const MeanDataValues &values,
00376 const std::string prefix) const throw(IOError);
00377
00378 protected:
00380 const SUMOReal myMinSamples;
00381
00383 const SUMOReal myMaxTravelTime;
00384
00386 const std::set<std::string> myVehicleTypes;
00387
00388 private:
00390 const std::string myID;
00391
00393 const bool myAmEdgeBased;
00394
00396 const SUMOTime myDumpBegin, myDumpEnd;
00397
00399 std::vector<std::vector<MeanDataValues*> > myMeasures;
00400
00402 std::vector<MSEdge*> myEdges;
00403
00405 const bool myDumpEmpty;
00406
00408 const bool myTrackVehicles;
00409
00411 std::list< std::pair<SUMOTime, SUMOTime> > myPendingIntervals;
00412
00413 private:
00415 MSMeanData(const MSMeanData&);
00416
00418 MSMeanData& operator=(const MSMeanData&);
00419
00420 };
00421
00422
00423 #endif
00424
00425
00426