|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Data collector for edges/lanes 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 #ifndef MSMeanData_h 00020 #define MSMeanData_h 00021 00022 00023 // =========================================================================== 00024 // included modules 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 // class declarations 00044 // =========================================================================== 00045 class OutputDevice; 00046 class MSEdge; 00047 class MSLane; 00048 class SUMOVehicle; 00049 00050 00051 // =========================================================================== 00052 // class definitions 00053 // =========================================================================== 00065 class MSMeanData : public MSDetectorFileOutput { 00066 public: 00074 class MeanDataValues : public MSMoveReminder { 00075 public: 00077 MeanDataValues(MSLane* const lane, const SUMOReal length, const bool doAdd, const std::set<std::string>* const vTypes=0) throw(); 00078 00080 virtual ~MeanDataValues() throw(); 00081 00082 00085 virtual void reset(bool afterWrite=false) throw() = 0; 00086 00091 virtual void addTo(MeanDataValues& val) const throw() = 0; 00092 00093 00102 virtual bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason) throw(); 00103 00104 00118 bool notifyMove(SUMOVehicle& veh, SUMOReal oldPos, 00119 SUMOReal newPos, SUMOReal newSpeed) throw(); 00120 00121 00130 virtual bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, 00131 MSMoveReminder::Notification reason) throw(); 00132 00133 00139 bool vehicleApplies(const SUMOVehicle& veh) const throw(); 00140 00141 00146 virtual bool isEmpty() const throw(); 00147 00148 00151 virtual void update() throw(); 00152 00160 virtual void write(OutputDevice& dev, const SUMOTime period, 00161 const SUMOReal numLanes, 00162 const int numVehicles=-1) const throw(IOError) = 0; 00163 00167 virtual SUMOReal getSamples() const throw(); 00168 00169 protected: 00171 const SUMOReal myLaneLength; 00172 00176 SUMOReal sampleSeconds; 00177 public: 00179 SUMOReal travelledDistance; 00181 00182 private: 00184 const std::set<std::string>* const myVehicleTypes; 00185 00186 }; 00187 00188 00193 class MeanDataValueTracker : public MeanDataValues { 00194 public: 00196 MeanDataValueTracker(MSLane* const lane, const SUMOReal length, 00197 const std::set<std::string>* const vTypes=0, 00198 const MSMeanData* const parent=0) throw(); 00199 00201 virtual ~MeanDataValueTracker() throw(); 00202 00205 void reset(bool afterWrite) throw(); 00206 00211 void addTo(MSMeanData::MeanDataValues& val) const throw(); 00212 00215 00226 void notifyMoveInternal(SUMOVehicle& veh, SUMOReal timeOnLane, SUMOReal speed) throw(); 00227 00228 00238 bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, MSMoveReminder::Notification reason) throw(); 00239 00240 00252 bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason) throw(); 00254 00255 bool isEmpty() const throw(); 00256 00264 void write(OutputDevice& dev, const SUMOTime period, 00265 const SUMOReal numLanes, 00266 const int numVehicles=-1) const throw(IOError); 00267 00268 size_t getNumReady() const throw(); 00269 00270 void clearFirst() throw(); 00271 00272 SUMOReal getSamples() const throw(); 00273 00274 private: 00275 class TrackerEntry { 00276 public: 00278 TrackerEntry(MeanDataValues* const values) throw() 00279 : myNumVehicleEntered(0), myNumVehicleLeft(0), myValues(values) {} 00280 00282 int myNumVehicleEntered; 00283 00285 int myNumVehicleLeft; 00286 00288 MeanDataValues* myValues; 00289 }; 00290 00292 std::map<SUMOVehicle*, TrackerEntry*> myTrackedData; 00293 00295 std::list<TrackerEntry*> myCurrentData; 00296 00298 const MSMeanData* myParent; 00299 00300 }; 00301 00302 00303 public: 00317 MSMeanData(const std::string& id, 00318 const SUMOTime dumpBegin, const SUMOTime dumpEnd, 00319 const bool useLanes, const bool withEmpty, const bool withInternal, 00320 const bool trackVehicles, 00321 const SUMOReal minSamples, const SUMOReal maxTravelTime, 00322 const std::set<std::string> vTypes) throw(); 00323 00324 00326 virtual ~MSMeanData() throw(); 00327 00330 void init() throw(); 00331 00334 00349 void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime) throw(IOError); 00350 00357 void writeXMLDetectorProlog(OutputDevice& dev) const throw(IOError); 00359 00362 virtual void detectorUpdate(const SUMOTime step) throw(); 00363 00364 00365 protected: 00371 virtual MSMeanData::MeanDataValues* createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const throw(IOError) = 0; 00372 00378 void resetOnly(SUMOTime stopTime) throw(); 00379 00394 void writeEdge(OutputDevice& dev, const std::vector<MeanDataValues*> &edgeValues, 00395 MSEdge* edge, SUMOTime startTime, SUMOTime stopTime) throw(IOError); 00396 00405 bool writePrefix(OutputDevice& dev, const MeanDataValues& values, 00406 const std::string prefix) const throw(IOError); 00407 00408 protected: 00410 const SUMOReal myMinSamples; 00411 00413 const SUMOReal myMaxTravelTime; 00414 00416 const std::set<std::string> myVehicleTypes; 00417 00419 std::vector<std::vector<MeanDataValues*> > myMeasures; 00420 00421 private: 00423 const bool myAmEdgeBased; 00424 00426 const SUMOTime myDumpBegin, myDumpEnd; 00427 00429 std::vector<MSEdge*> myEdges; 00430 00432 const bool myDumpEmpty; 00433 00435 const bool myDumpInternal; 00436 00438 const bool myTrackVehicles; 00439 00441 std::list< std::pair<SUMOTime, SUMOTime> > myPendingIntervals; 00442 00443 private: 00445 MSMeanData(const MSMeanData&); 00446 00448 MSMeanData& operator=(const MSMeanData&); 00449 00450 }; 00451 00452 00453 #endif 00454 00455 /****************************************************************************/ 00456