SUMO - Simulation of Urban MObility

MSInductLoop.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // An unextended detector measuring at a fixed position on a fixed lane.
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 MSInductLoop_h
00020 #define MSInductLoop_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 <string>
00033 #include <deque>
00034 #include <map>
00035 #include <functional>
00036 #include <microsim/MSMoveReminder.h>
00037 #include <microsim/output/MSDetectorFileOutput.h>
00038 
00039 
00040 // ===========================================================================
00041 // class declarations
00042 // ===========================================================================
00043 class MSLane;
00044 class MSVehicle;
00045 class OutputDevice;
00046 
00047 
00048 // ===========================================================================
00049 // class definitions
00050 // ===========================================================================
00066 class MSInductLoop
00067         : public MSMoveReminder, public MSDetectorFileOutput {
00068 public:
00079     MSInductLoop(const std::string& id, MSLane* const lane,
00080                  SUMOReal positionInMeters, bool splitByType) throw();
00081 
00082 
00084     ~MSInductLoop() throw();
00085 
00086 
00089     virtual void reset() throw();
00090 
00091 
00095     SUMOReal getPosition() const {
00096         return myPosition;
00097     }
00098 
00099 
00102 
00119     bool notifyMove(SUMOVehicle& veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed) throw();
00120 
00121 
00136     bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, MSMoveReminder::Notification reason) throw();
00137 
00138 
00152     bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason) throw();
00154 
00155 
00156 
00159 
00167     SUMOReal getCurrentSpeed() const throw();
00168 
00169 
00177     SUMOReal getCurrentLength() const throw();
00178 
00179 
00189     SUMOReal getCurrentOccupancy() const throw();
00190 
00191 
00201     unsigned int getCurrentPassedNumber() const throw();
00202 
00203 
00209     std::vector<std::string> getCurrentVehicleIDs() const throw();
00210 
00211 
00216     SUMOReal getTimestepsSinceLastDetection() const throw();
00218 
00219 
00220 
00223 
00232     void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime) throw(IOError);
00233 
00234 
00241     void writeXMLDetectorProlog(OutputDevice& dev) const throw(IOError);
00243 
00244 
00245 
00252     struct VehicleData {
00261         VehicleData(const std::string& id, SUMOReal vehLength, SUMOReal entryTimestep, SUMOReal leaveTimestep,
00262                     const std::string& typeID) throw()
00263             : idM(id), lengthM(vehLength), entryTimeM(entryTimestep), leaveTimeM(leaveTimestep),
00264               speedM(lengthM / ((leaveTimeM - entryTimeM))), typeIDM(typeID) {}
00265 
00267         std::string idM;
00269         SUMOReal lengthM;
00271         SUMOReal entryTimeM;
00273         SUMOReal leaveTimeM;
00275         SUMOReal speedM;
00277         std::string typeIDM;
00278     };
00279 
00280 
00286     virtual std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t) const throw();
00287 
00288 
00289 protected:
00292 
00297     virtual void enterDetectorByMove(SUMOVehicle& veh, SUMOReal entryTimestep) throw();
00298 
00299 
00308     virtual void leaveDetectorByMove(SUMOVehicle& veh, SUMOReal leaveTimestep) throw();
00309 
00310 
00314     virtual void leaveDetectorByLaneChange(SUMOVehicle& veh) throw();
00316 
00317 
00318 protected:
00321 
00323     static inline SUMOReal speedSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData& data) throw() {
00324         return sumSoFar + data.speedM;
00325     }
00326 
00328     static inline SUMOReal lengthSum(SUMOReal sumSoFar, const MSInductLoop::VehicleData& data) throw() {
00329         return sumSoFar + data.lengthM;
00330     }
00332 
00333 
00334 protected:
00336     const SUMOReal myPosition;
00337 
00339     bool mySplitByType;
00340 
00342     SUMOReal myLastLeaveTime;
00343 
00345     SUMOReal myLastOccupancy;
00346 
00348     unsigned myDismissedVehicleNumber;
00349 
00350 
00352     typedef std::deque< VehicleData > VehicleDataCont;
00353 
00355     VehicleDataCont myVehicleDataCont;
00356 
00358     VehicleDataCont myLastVehicleDataCont;
00359 
00360 
00362     typedef std::map< SUMOVehicle*, SUMOReal > VehicleMap;
00363 
00365     VehicleMap myVehiclesOnDet;
00366 
00367     void writeTypedXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime,
00368                              const std::string& type, const VehicleDataCont& vdc, const VehicleMap& vm) throw(IOError);
00369 
00370 private:
00372     MSInductLoop(const MSInductLoop&);
00373 
00375     MSInductLoop& operator=(const MSInductLoop&);
00376 
00377 
00378 };
00379 
00380 
00381 #endif
00382 
00383 /****************************************************************************/
00384 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines