SUMO - Simulation of Urban MObility
MSInductLoop.h
Go to the documentation of this file.
00001 /****************************************************************************/
00010 // An unextended detector measuring at a fixed position on a fixed lane.
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 MSInductLoop_h
00024 #define MSInductLoop_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 <string>
00037 #include <deque>
00038 #include <map>
00039 #include <functional>
00040 #include <microsim/MSMoveReminder.h>
00041 #include <microsim/output/MSDetectorFileOutput.h>
00042 
00043 
00044 // ===========================================================================
00045 // class declarations
00046 // ===========================================================================
00047 class MSLane;
00048 class MSVehicle;
00049 class OutputDevice;
00050 
00051 
00052 // ===========================================================================
00053 // class definitions
00054 // ===========================================================================
00070 class MSInductLoop
00071         : public MSMoveReminder, public MSDetectorFileOutput {
00072 public:
00083     MSInductLoop(const std::string& id, MSLane* const lane,
00084                  SUMOReal positionInMeters, bool splitByType) ;
00085 
00086 
00088     ~MSInductLoop() ;
00089 
00090 
00093     virtual void reset() ;
00094 
00095 
00099     SUMOReal getPosition() const {
00100         return myPosition;
00101     }
00102 
00103 
00106 
00123     bool notifyMove(SUMOVehicle& veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed) ;
00124 
00125 
00140     bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, MSMoveReminder::Notification reason) ;
00141 
00142 
00156     bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason) ;
00158 
00159 
00160 
00163 
00171     SUMOReal getCurrentSpeed() const ;
00172 
00173 
00181     SUMOReal getCurrentLength() const ;
00182 
00183 
00193     SUMOReal getCurrentOccupancy() const ;
00194 
00195 
00205     unsigned int getCurrentPassedNumber() const ;
00206 
00207 
00213     std::vector<std::string> getCurrentVehicleIDs() const ;
00214 
00215 
00220     SUMOReal getTimestepsSinceLastDetection() const ;
00222 
00223 
00224 
00227 
00236     void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
00237 
00238 
00245     void writeXMLDetectorProlog(OutputDevice& dev) const;
00247 
00248 
00249 
00256     struct VehicleData {
00265         VehicleData(const std::string& id, SUMOReal vehLength, SUMOReal entryTimestep, SUMOReal leaveTimestep,
00266                     const std::string& typeID)
00267             : idM(id), lengthM(vehLength), entryTimeM(entryTimestep), leaveTimeM(leaveTimestep),
00268               speedM(lengthM / ((leaveTimeM - entryTimeM))), typeIDM(typeID) {}
00269 
00271         std::string idM;
00273         SUMOReal lengthM;
00275         SUMOReal entryTimeM;
00277         SUMOReal leaveTimeM;
00279         SUMOReal speedM;
00281         std::string typeIDM;
00282     };
00283 
00284 
00290     virtual std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t) const ;
00291 
00292 
00293 protected:
00296 
00301     virtual void enterDetectorByMove(SUMOVehicle& veh, SUMOReal entryTimestep) ;
00302 
00303 
00312     virtual void leaveDetectorByMove(SUMOVehicle& veh, SUMOReal leaveTimestep) ;
00313 
00314 
00318     virtual void leaveDetectorByLaneChange(SUMOVehicle& veh) ;
00320 
00321 
00322 protected:
00325 
00327     static inline SUMOReal speedSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData& data) {
00328         return sumSoFar + data.speedM;
00329     }
00330 
00332     static inline SUMOReal lengthSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData& data) {
00333         return sumSoFar + data.lengthM;
00334     }
00336 
00337 
00338 protected:
00340     const SUMOReal myPosition;
00341 
00343     bool mySplitByType;
00344 
00346     SUMOReal myLastLeaveTime;
00347 
00349     SUMOReal myLastOccupancy;
00350 
00352     unsigned myDismissedVehicleNumber;
00353 
00354 
00356     typedef std::deque< VehicleData > VehicleDataCont;
00357 
00359     VehicleDataCont myVehicleDataCont;
00360 
00362     VehicleDataCont myLastVehicleDataCont;
00363 
00364 
00366     typedef std::map< SUMOVehicle*, SUMOReal > VehicleMap;
00367 
00369     VehicleMap myVehiclesOnDet;
00370 
00371     void writeTypedXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime,
00372                              const std::string& type, const VehicleDataCont& vdc, const VehicleMap& vm);
00373 
00374 private:
00376     MSInductLoop(const MSInductLoop&);
00377 
00379     MSInductLoop& operator=(const MSInductLoop&);
00380 
00381 
00382 };
00383 
00384 
00385 #endif
00386 
00387 /****************************************************************************/
00388 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines