|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // An areal (along a single lane) detector 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 MSE2Collector_h 00020 #define MSE2Collector_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 <list> 00034 #include <microsim/MSLane.h> 00035 #include <microsim/MSMoveReminder.h> 00036 #include <microsim/output/MSDetectorFileOutput.h> 00037 #include <utils/common/UtilExceptions.h> 00038 #include <utils/common/SUMOVehicle.h> 00039 00040 00041 // =========================================================================== 00042 // class declarations 00043 // =========================================================================== 00044 class OutputDevice; 00045 00046 00047 // =========================================================================== 00048 // class definitions 00049 // =========================================================================== 00073 class MSE2Collector : public MSMoveReminder, public MSDetectorFileOutput { 00074 public: 00087 MSE2Collector(const std::string& id, DetectorUsage usage, 00088 MSLane* const lane, SUMOReal startPos, SUMOReal detLength, 00089 SUMOTime haltingTimeThreshold, SUMOReal haltingSpeedThreshold, 00090 SUMOReal jamDistThreshold) throw(); 00091 00092 00094 virtual ~MSE2Collector() throw(); 00095 00096 00102 virtual DetectorUsage getUsageType() const throw() { 00103 return myUsage; 00104 } 00105 00106 00107 00110 00126 bool notifyMove(SUMOVehicle& veh, SUMOReal oldPos, SUMOReal newPos, 00127 SUMOReal newSpeed) throw(); 00128 00129 00141 bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, MSMoveReminder::Notification reason) throw(); 00142 00143 00156 bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason) throw(); 00158 00159 00160 00169 void detectorUpdate(const SUMOTime step) throw(); 00170 00171 00172 00175 00184 void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime) throw(IOError); 00185 00186 00193 void writeXMLDetectorProlog(OutputDevice& dev) const throw(IOError); 00195 00196 00201 SUMOReal getStartPos() const throw() { 00202 return myStartPos; 00203 } 00204 00205 00210 SUMOReal getEndPos() const throw() { 00211 return myEndPos; 00212 } 00213 00214 00221 void reset() throw(); 00222 00223 00226 00228 unsigned getCurrentVehicleNumber() const throw(); 00229 00231 SUMOReal getCurrentOccupancy() const throw(); 00232 00234 SUMOReal getCurrentMeanSpeed() const throw(); 00235 00237 SUMOReal getCurrentMeanLength() const throw(); 00238 00240 unsigned getCurrentJamNumber() const throw(); 00241 00243 unsigned getCurrentMaxJamLengthInVehicles() const throw(); 00244 00246 SUMOReal getCurrentMaxJamLengthInMeters() const throw(); 00247 00249 unsigned getCurrentJamLengthInVehicles() const throw(); 00250 00252 SUMOReal getCurrentJamLengthInMeters() const throw(); 00253 00255 unsigned getCurrentStartedHalts() const throw(); 00257 00258 00259 protected: 00265 struct JamInfo { 00267 std::list<SUMOVehicle*>::const_iterator firstStandingVehicle; 00268 00270 std::list<SUMOVehicle*>::const_iterator lastStandingVehicle; 00271 }; 00272 00273 00284 class by_vehicle_position_sorter { 00285 public: 00290 by_vehicle_position_sorter(const MSLane* const lane) throw() 00291 : myLane(lane) { } 00292 00293 00298 by_vehicle_position_sorter(const by_vehicle_position_sorter& s) throw() 00299 : myLane(s.myLane) { } 00300 00301 00308 int operator()(const SUMOVehicle* v1, const SUMOVehicle* v2) throw() { 00309 const MSVehicle* const occ = myLane->getPartialOccupator(); 00310 if (v1 == occ) { 00311 return true; 00312 } 00313 if (v2 == occ) { 00314 return false; 00315 } 00316 return v1->getPositionOnLane() > v2->getPositionOnLane(); 00317 } 00318 00319 private: 00320 by_vehicle_position_sorter& operator=(const by_vehicle_position_sorter&); // just to avoid a compiler warning 00321 private: 00323 const MSLane* const myLane; 00324 }; 00325 00326 00327 private: 00330 00332 SUMOReal myJamHaltingSpeedThreshold; 00334 SUMOTime myJamHaltingTimeThreshold; 00336 SUMOReal myJamDistanceThreshold; 00338 SUMOReal myStartPos; 00340 SUMOReal myEndPos; 00342 00344 DetectorUsage myUsage; 00345 00347 std::list<SUMOVehicle*> myKnownVehicles; 00348 00350 std::map<SUMOVehicle*, SUMOTime> myHaltingVehicleDurations; 00351 00353 std::map<SUMOVehicle*, SUMOTime> myIntervalHaltingVehicleDurations; 00354 00356 std::vector<SUMOTime> myPastStandingDurations; 00357 00359 std::vector<SUMOTime> myPastIntervalStandingDurations; 00360 00361 00364 00366 SUMOReal mySpeedSum; 00368 SUMOReal myStartedHalts; 00370 SUMOReal myJamLengthInMetersSum; 00372 unsigned myJamLengthInVehiclesSum; 00374 unsigned myVehicleSamples; 00376 unsigned myTimeSamples; 00378 SUMOReal myOccupancySum; 00380 SUMOReal myMaxOccupancy; 00382 unsigned myMeanMaxJamInVehicles; 00384 SUMOReal myMeanMaxJamInMeters; 00386 unsigned myMaxJamInVehicles; 00388 SUMOReal myMaxJamInMeters; 00390 unsigned myMeanVehicleNumber; 00392 unsigned myMaxVehicleNumber; 00394 00395 00398 00400 SUMOReal myCurrentOccupancy; 00402 SUMOReal myCurrentMeanSpeed; 00404 SUMOReal myCurrentMeanLength; 00406 unsigned myCurrentJamNo; 00408 SUMOReal myCurrentMaxJamLengthInMeters; 00410 unsigned myCurrentMaxJamLengthInVehicles; 00412 SUMOReal myCurrentJamLengthInMeters; 00414 unsigned myCurrentJamLengthInVehicles; 00416 unsigned myCurrentStartedHalts; 00418 00419 00420 private: 00422 MSE2Collector(const MSE2Collector&); 00423 00425 MSE2Collector& operator=(const MSE2Collector&); 00426 00427 00428 }; 00429 00430 00431 #endif 00432 00433 /****************************************************************************/ 00434