SUMO - Simulation of Urban MObility

MSMeanData.h

Go to the documentation of this file.
00001 /****************************************************************************/
00008 // Data collector for edges/lanes
00009 /****************************************************************************/
00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00012 /****************************************************************************/
00013 //
00014 //   This file is part of SUMO.
00015 //   SUMO is free software: you can redistribute it and/or modify
00016 //   it under the terms of the GNU General Public License as published by
00017 //   the Free Software Foundation, either version 3 of the License, or
00018 //   (at your option) any later version.
00019 //
00020 /****************************************************************************/
00021 #ifndef MSMeanData_h
00022 #define MSMeanData_h
00023 
00024 
00025 // ===========================================================================
00026 // included modules
00027 // ===========================================================================
00028 #ifdef _MSC_VER
00029 #include <windows_config.h>
00030 #else
00031 #include <config.h>
00032 #endif
00033 
00034 #include <vector>
00035 #include <set>
00036 #include <list>
00037 #include <cassert>
00038 #include <limits>
00039 #include <microsim/output/MSDetectorFileOutput.h>
00040 #include <microsim/MSMoveReminder.h>
00041 #include <utils/common/SUMOTime.h>
00042 
00043 
00044 // ===========================================================================
00045 // class declarations
00046 // ===========================================================================
00047 class OutputDevice;
00048 class MSEdge;
00049 class MSLane;
00050 class SUMOVehicle;
00051 
00052 
00053 // ===========================================================================
00054 // class definitions
00055 // ===========================================================================
00067 class MSMeanData : public MSDetectorFileOutput {
00068 public:
00076     class MeanDataValues : public MSMoveReminder {
00077     public:
00079         MeanDataValues(MSLane* const lane, const SUMOReal length, const bool doAdd, const std::set<std::string>* const vTypes = 0) ;
00080 
00082         virtual ~MeanDataValues() ;
00083 
00084 
00087         virtual void reset(bool afterWrite = false) = 0;
00088 
00093         virtual void addTo(MeanDataValues& val) const = 0;
00094 
00095 
00104         virtual bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason) ;
00105 
00106 
00120         bool notifyMove(SUMOVehicle& veh, SUMOReal oldPos,
00121                         SUMOReal newPos, SUMOReal newSpeed) ;
00122 
00123 
00132         virtual bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos,
00133                                  MSMoveReminder::Notification reason) ;
00134 
00135 
00141         bool vehicleApplies(const SUMOVehicle& veh) const ;
00142 
00143 
00148         virtual bool isEmpty() const ;
00149 
00150 
00153         virtual void update() ;
00154 
00162         virtual void write(OutputDevice& dev, const SUMOTime period,
00163                            const SUMOReal numLanes,
00164                            const int numVehicles = -1) const = 0;
00165 
00169         virtual SUMOReal getSamples() const ;
00170 
00171     protected:
00173         const SUMOReal myLaneLength;
00174 
00178         SUMOReal sampleSeconds;
00179     public:
00181         SUMOReal travelledDistance;
00183 
00184     private:
00186         const std::set<std::string>* const myVehicleTypes;
00187 
00188     };
00189 
00190 
00195     class MeanDataValueTracker : public MeanDataValues {
00196     public:
00198         MeanDataValueTracker(MSLane* const lane, const SUMOReal length,
00199                              const std::set<std::string>* const vTypes = 0,
00200                              const MSMeanData* const parent = 0) ;
00201 
00203         virtual ~MeanDataValueTracker() ;
00204 
00207         void reset(bool afterWrite) ;
00208 
00213         void addTo(MSMeanData::MeanDataValues& val) const ;
00214 
00217 
00228         void notifyMoveInternal(SUMOVehicle& veh, SUMOReal timeOnLane, SUMOReal speed) ;
00229 
00230 
00240         bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, MSMoveReminder::Notification reason) ;
00241 
00242 
00254         bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason) ;
00256 
00257         bool isEmpty() const ;
00258 
00266         void write(OutputDevice& dev, const SUMOTime period,
00267                    const SUMOReal numLanes,
00268                    const int numVehicles = -1) const;
00269 
00270         size_t getNumReady() const ;
00271 
00272         void clearFirst() ;
00273 
00274         SUMOReal getSamples() const ;
00275 
00276     private:
00277         class TrackerEntry {
00278         public:
00280             TrackerEntry(MeanDataValues* const values)
00281                 : myNumVehicleEntered(0), myNumVehicleLeft(0), myValues(values) {}
00282 
00284             int myNumVehicleEntered;
00285 
00287             int myNumVehicleLeft;
00288 
00290             MeanDataValues* myValues;
00291         };
00292 
00294         std::map<SUMOVehicle*, TrackerEntry*> myTrackedData;
00295 
00297         std::list<TrackerEntry*> myCurrentData;
00298 
00300         const MSMeanData* myParent;
00301 
00302     };
00303 
00304 
00305 public:
00319     MSMeanData(const std::string& id,
00320                const SUMOTime dumpBegin, const SUMOTime dumpEnd,
00321                const bool useLanes, const bool withEmpty, const bool withInternal,
00322                const bool trackVehicles,
00323                const SUMOReal minSamples, const SUMOReal maxTravelTime,
00324                const std::set<std::string> vTypes) ;
00325 
00326 
00328     virtual ~MSMeanData() ;
00329 
00332     void init() ;
00333 
00336 
00351     void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
00352 
00359     void writeXMLDetectorProlog(OutputDevice& dev) const;
00361 
00364     virtual void detectorUpdate(const SUMOTime step) ;
00365 
00366 
00367 protected:
00373     virtual MSMeanData::MeanDataValues* createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const = 0;
00374 
00380     void resetOnly(SUMOTime stopTime) ;
00381 
00396     void writeEdge(OutputDevice& dev, const std::vector<MeanDataValues*> &edgeValues,
00397                    MSEdge* edge, SUMOTime startTime, SUMOTime stopTime);
00398 
00407     bool writePrefix(OutputDevice& dev, const MeanDataValues& values,
00408                      const std::string prefix) const;
00409 
00410 protected:
00412     const SUMOReal myMinSamples;
00413 
00415     const SUMOReal myMaxTravelTime;
00416 
00418     const std::set<std::string> myVehicleTypes;
00419 
00421     std::vector<std::vector<MeanDataValues*> > myMeasures;
00422 
00423 private:
00425     const bool myAmEdgeBased;
00426 
00428     const SUMOTime myDumpBegin, myDumpEnd;
00429 
00431     std::vector<MSEdge*> myEdges;
00432 
00434     const bool myDumpEmpty;
00435 
00437     const bool myDumpInternal;
00438 
00440     const bool myTrackVehicles;
00441 
00443     std::list< std::pair<SUMOTime, SUMOTime> > myPendingIntervals;
00444 
00445 private:
00447     MSMeanData(const MSMeanData&);
00448 
00450     MSMeanData& operator=(const MSMeanData&);
00451 
00452 };
00453 
00454 
00455 #endif
00456 
00457 /****************************************************************************/
00458 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines