|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00010 // An areal (along a single lane) detector 00011 /****************************************************************************/ 00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00014 /****************************************************************************/ 00015 // 00016 // This file is part of SUMO. 00017 // SUMO is free software: you can redistribute it and/or modify 00018 // it under the terms of the GNU General Public License as published by 00019 // the Free Software Foundation, either version 3 of the License, or 00020 // (at your option) any later version. 00021 // 00022 /****************************************************************************/ 00023 #ifndef MSE2Collector_h 00024 #define MSE2Collector_h 00025 00026 00027 // =========================================================================== 00028 // included modules 00029 // =========================================================================== 00030 #ifdef _MSC_VER 00031 #include <windows_config.h> 00032 #else 00033 #include <config.h> 00034 #endif 00035 00036 #include <vector> 00037 #include <list> 00038 #include <microsim/MSLane.h> 00039 #include <microsim/MSMoveReminder.h> 00040 #include <microsim/output/MSDetectorFileOutput.h> 00041 #include <utils/common/UtilExceptions.h> 00042 #include <utils/common/SUMOVehicle.h> 00043 00044 00045 // =========================================================================== 00046 // class declarations 00047 // =========================================================================== 00048 class OutputDevice; 00049 00050 00051 // =========================================================================== 00052 // class definitions 00053 // =========================================================================== 00077 class MSE2Collector : public MSMoveReminder, public MSDetectorFileOutput { 00078 public: 00091 MSE2Collector(const std::string& id, DetectorUsage usage, 00092 MSLane* const lane, SUMOReal startPos, SUMOReal detLength, 00093 SUMOTime haltingTimeThreshold, SUMOReal haltingSpeedThreshold, 00094 SUMOReal jamDistThreshold) ; 00095 00096 00098 virtual ~MSE2Collector() ; 00099 00100 00106 virtual DetectorUsage getUsageType() const { 00107 return myUsage; 00108 } 00109 00110 00111 00114 00130 bool notifyMove(SUMOVehicle& veh, SUMOReal oldPos, SUMOReal newPos, 00131 SUMOReal newSpeed) ; 00132 00133 00145 bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, MSMoveReminder::Notification reason) ; 00146 00147 00160 bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason) ; 00162 00163 00164 00173 void detectorUpdate(const SUMOTime step) ; 00174 00175 00176 00179 00188 void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime); 00189 00190 00197 void writeXMLDetectorProlog(OutputDevice& dev) const; 00199 00200 00205 SUMOReal getStartPos() const { 00206 return myStartPos; 00207 } 00208 00209 00214 SUMOReal getEndPos() const { 00215 return myEndPos; 00216 } 00217 00218 00225 void reset() ; 00226 00227 00230 00232 unsigned getCurrentVehicleNumber() const ; 00233 00235 SUMOReal getCurrentOccupancy() const ; 00236 00238 SUMOReal getCurrentMeanSpeed() const ; 00239 00241 SUMOReal getCurrentMeanLength() const ; 00242 00244 unsigned getCurrentJamNumber() const ; 00245 00247 unsigned getCurrentMaxJamLengthInVehicles() const ; 00248 00250 SUMOReal getCurrentMaxJamLengthInMeters() const ; 00251 00253 unsigned getCurrentJamLengthInVehicles() const ; 00254 00256 SUMOReal getCurrentJamLengthInMeters() const ; 00257 00259 unsigned getCurrentStartedHalts() const ; 00261 00262 00263 protected: 00269 struct JamInfo { 00271 std::list<SUMOVehicle*>::const_iterator firstStandingVehicle; 00272 00274 std::list<SUMOVehicle*>::const_iterator lastStandingVehicle; 00275 }; 00276 00277 00288 class by_vehicle_position_sorter { 00289 public: 00294 by_vehicle_position_sorter(const MSLane* const lane) 00295 : myLane(lane) { } 00296 00297 00302 by_vehicle_position_sorter(const by_vehicle_position_sorter& s) 00303 : myLane(s.myLane) { } 00304 00305 00312 int operator()(const SUMOVehicle* v1, const SUMOVehicle* v2) { 00313 const MSVehicle* const occ = myLane->getPartialOccupator(); 00314 if (v1 == occ) { 00315 return true; 00316 } 00317 if (v2 == occ) { 00318 return false; 00319 } 00320 return v1->getPositionOnLane() > v2->getPositionOnLane(); 00321 } 00322 00323 private: 00324 by_vehicle_position_sorter& operator=(const by_vehicle_position_sorter&); // just to avoid a compiler warning 00325 private: 00327 const MSLane* const myLane; 00328 }; 00329 00330 00331 private: 00334 00336 SUMOReal myJamHaltingSpeedThreshold; 00338 SUMOTime myJamHaltingTimeThreshold; 00340 SUMOReal myJamDistanceThreshold; 00342 SUMOReal myStartPos; 00344 SUMOReal myEndPos; 00346 00348 DetectorUsage myUsage; 00349 00351 std::list<SUMOVehicle*> myKnownVehicles; 00352 00354 std::map<SUMOVehicle*, SUMOTime> myHaltingVehicleDurations; 00355 00357 std::map<SUMOVehicle*, SUMOTime> myIntervalHaltingVehicleDurations; 00358 00360 std::vector<SUMOTime> myPastStandingDurations; 00361 00363 std::vector<SUMOTime> myPastIntervalStandingDurations; 00364 00365 00368 00370 SUMOReal mySpeedSum; 00372 SUMOReal myStartedHalts; 00374 SUMOReal myJamLengthInMetersSum; 00376 unsigned myJamLengthInVehiclesSum; 00378 unsigned myVehicleSamples; 00380 unsigned myTimeSamples; 00382 SUMOReal myOccupancySum; 00384 SUMOReal myMaxOccupancy; 00386 unsigned myMeanMaxJamInVehicles; 00388 SUMOReal myMeanMaxJamInMeters; 00390 unsigned myMaxJamInVehicles; 00392 SUMOReal myMaxJamInMeters; 00394 unsigned myMeanVehicleNumber; 00396 unsigned myMaxVehicleNumber; 00398 00399 00402 00404 SUMOReal myCurrentOccupancy; 00406 SUMOReal myCurrentMeanSpeed; 00408 SUMOReal myCurrentMeanLength; 00410 unsigned myCurrentJamNo; 00412 SUMOReal myCurrentMaxJamLengthInMeters; 00414 unsigned myCurrentMaxJamLengthInVehicles; 00416 SUMOReal myCurrentJamLengthInMeters; 00418 unsigned myCurrentJamLengthInVehicles; 00420 unsigned myCurrentStartedHalts; 00422 00423 00424 private: 00426 MSE2Collector(const MSE2Collector&); 00427 00429 MSE2Collector& operator=(const MSE2Collector&); 00430 00431 00432 }; 00433 00434 00435 #endif 00436 00437 /****************************************************************************/ 00438