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, const SUMOReal defaultTravelTime,
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, const SUMOReal defaultTravelTime,
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:
00320     MSMeanData(const std::string& id,
00321                const SUMOTime dumpBegin, const SUMOTime dumpEnd,
00322                const bool useLanes, const bool withEmpty,
00323                const bool printDefaults, const bool withInternal,
00324                const bool trackVehicles, const SUMOReal minSamples,
00325                const SUMOReal maxTravelTime,
00326                const std::set<std::string> vTypes);
00327 
00328 
00330     virtual ~MSMeanData() ;
00331 
00334     void init() ;
00335 
00338 
00353     void writeXMLOutput(OutputDevice& dev, SUMOTime startTime, SUMOTime stopTime);
00354 
00361     void writeXMLDetectorProlog(OutputDevice& dev) const;
00363 
00366     virtual void detectorUpdate(const SUMOTime step) ;
00367 
00368 
00369 protected:
00375     virtual MSMeanData::MeanDataValues* createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const = 0;
00376 
00382     void resetOnly(SUMOTime stopTime) ;
00383 
00398     void writeEdge(OutputDevice& dev, const std::vector<MeanDataValues*> &edgeValues,
00399                    MSEdge* edge, SUMOTime startTime, SUMOTime stopTime);
00400 
00410     bool writePrefix(OutputDevice& dev, const MeanDataValues& values,
00411                      const std::string tag, const std::string id) const;
00412 
00413 protected:
00415     const SUMOReal myMinSamples;
00416 
00418     const SUMOReal myMaxTravelTime;
00419 
00421     const std::set<std::string> myVehicleTypes;
00422 
00424     std::vector<std::vector<MeanDataValues*> > myMeasures;
00425 
00426 private:
00428     const bool myAmEdgeBased;
00429 
00431     const SUMOTime myDumpBegin, myDumpEnd;
00432 
00434     std::vector<MSEdge*> myEdges;
00435 
00437     const bool myDumpEmpty;
00438 
00440     const bool myPrintDefaults;
00441 
00443     const bool myDumpInternal;
00444 
00446     const bool myTrackVehicles;
00447 
00449     std::list< std::pair<SUMOTime, SUMOTime> > myPendingIntervals;
00450 
00451 private:
00453     MSMeanData(const MSMeanData&);
00454 
00456     MSMeanData& operator=(const MSMeanData&);
00457 
00458 };
00459 
00460 
00461 #endif
00462 
00463 /****************************************************************************/
00464 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines