SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // Class representing a detector within the DFROUTER 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 #ifndef RODFDetector_h 00023 #define RODFDetector_h 00024 00025 00026 // =========================================================================== 00027 // included modules 00028 // =========================================================================== 00029 #ifdef _MSC_VER 00030 #include <windows_config.h> 00031 #else 00032 #include <config.h> 00033 #endif 00034 00035 #include <map> 00036 #include <string> 00037 #include <vector> 00038 #include <map> 00039 #include <utils/common/SUMOTime.h> 00040 #include <utils/common/RandomDistributor.h> 00041 #include "RODFRouteCont.h" 00042 00043 00044 // =========================================================================== 00045 // class declarations 00046 // =========================================================================== 00047 class RODFRouteCont; 00048 class RODFDetectorFlows; 00049 class ROEdge; 00050 class RODFEdge; 00051 class RODFDetectorCon; 00052 class RODFNet; 00053 struct RODFRouteDesc; 00054 class OutputDevice; 00055 00056 00057 // =========================================================================== 00058 // enumerations 00059 // =========================================================================== 00064 enum RODFDetectorType { 00066 TYPE_NOT_DEFINED = 0, 00067 00069 DISCARDED_DETECTOR, 00070 00072 BETWEEN_DETECTOR, 00073 00075 SOURCE_DETECTOR, 00076 SINK_DETECTOR 00077 }; 00078 00079 00080 // =========================================================================== 00081 // class definitions 00082 // =========================================================================== 00087 class RODFDetector { 00088 public: 00099 RODFDetector(const std::string& id, const std::string& laneID, 00100 SUMOReal pos, const RODFDetectorType type) ; 00101 00102 00110 RODFDetector(const std::string& id, const RODFDetector& f) ; 00111 00112 00114 ~RODFDetector() ; 00115 00116 00117 00120 00124 const std::string& getID() const { 00125 return myID; 00126 }; 00127 00128 00132 const std::string& getLaneID() const { 00133 return myLaneID; 00134 }; 00135 00136 00140 std::string getEdgeID() const { 00141 return myLaneID.substr(0, myLaneID.rfind('_')); 00142 } 00143 00144 00148 SUMOReal getPos() const { 00149 return myPosition; 00150 }; 00151 00152 00157 RODFDetectorType getType() const { 00158 return myType; 00159 }; 00161 00162 00163 void setType(RODFDetectorType type); 00164 void addRoute(RODFRouteDesc& nrd); 00165 void addRoutes(RODFRouteCont* routes); 00166 bool hasRoutes() const; 00167 const std::vector<RODFRouteDesc> &getRouteVector() const; 00168 void addPriorDetector(RODFDetector* det); 00169 void addFollowingDetector(RODFDetector* det); 00170 const std::vector<RODFDetector*> &getPriorDetectors() const; 00171 const std::vector<RODFDetector*> &getFollowerDetectors() const; 00172 00173 00176 00177 bool writeEmitterDefinition(const std::string& file, 00178 const std::map<size_t, RandomDistributor<size_t>* > &dists, 00179 const RODFDetectorFlows& flows, 00180 SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, 00181 bool includeUnusedRoutes, SUMOReal scale, 00182 bool insertionsOnly, SUMOReal defaultSpeed) const; 00183 bool writeRoutes(std::vector<std::string> &saved, 00184 OutputDevice& out); 00185 void writeSingleSpeedTrigger(const std::string& file, 00186 const RODFDetectorFlows& flows, 00187 SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, 00188 SUMOReal defaultSpeed); 00189 void writeEndRerouterDetectors(const std::string& file); 00191 00192 void buildDestinationDistribution(const RODFDetectorCon& detectors, 00193 const RODFDetectorFlows& flows, 00194 SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, 00195 const RODFNet& net, 00196 std::map<size_t, RandomDistributor<size_t>* > &into, 00197 int maxFollower) const; 00198 00199 void computeSplitProbabilities(const RODFNet* net, const RODFDetectorCon& detectors, 00200 const RODFDetectorFlows& flows, 00201 SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset); 00202 00203 const std::vector<std::map<RODFEdge*, SUMOReal> > &getSplitProbabilities() const { 00204 return mySplitProbabilities; 00205 } 00206 00207 protected: 00208 int getFlowFor(const ROEdge* edge, SUMOTime time) const; 00209 SUMOReal computeDistanceFactor(const RODFRouteDesc& rd) const; 00210 00211 00212 protected: 00213 std::string myID; 00214 std::string myLaneID; 00215 SUMOReal myPosition; 00216 RODFDetectorType myType; 00217 RODFRouteCont* myRoutes; 00218 std::vector<RODFDetector*> myPriorDetectors, myFollowingDetectors; 00219 std::vector<std::map<RODFEdge*, SUMOReal> > mySplitProbabilities; 00220 std::map<std::string, RODFEdge*> myRoute2Edge; 00221 00222 00223 private: 00225 RODFDetector(const RODFDetector& src); 00226 00228 RODFDetector& operator=(const RODFDetector& src); 00229 00230 }; 00231 00232 00237 class RODFDetectorCon { 00238 public: 00239 RODFDetectorCon(); 00240 ~RODFDetectorCon(); 00241 bool addDetector(RODFDetector* dfd); 00242 void removeDetector(const std::string& id); 00243 bool detectorsHaveCompleteTypes() const; 00244 bool detectorsHaveRoutes() const; 00245 const std::vector<RODFDetector*> &getDetectors() const; 00246 void save(const std::string& file) const; 00247 void saveAsPOIs(const std::string& file) const; 00248 void saveRoutes(const std::string& file) const; 00249 00250 const RODFDetector& getDetector(const std::string& id) const; 00251 const RODFDetector& getAnyDetectorForEdge(const RODFEdge* const edge) const; 00252 00253 bool knows(const std::string& id) const; 00254 void writeEmitters(const std::string& file, 00255 const RODFDetectorFlows& flows, 00256 SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, 00257 const RODFNet& net, 00258 bool writeCalibrators, bool includeUnusedRoutes, 00259 SUMOReal scale, int maxFollower, 00260 bool insertionsOnly); 00261 00262 void writeEmitterPOIs(const std::string& file, 00263 const RODFDetectorFlows& flows); 00264 00265 void writeSpeedTrigger(const RODFNet* const net, const std::string& file, 00266 const RODFDetectorFlows& flows, 00267 SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset); 00268 00269 void writeValidationDetectors(const std::string& file, 00270 bool includeSources, bool singleFile, bool friendly); 00271 void writeEndRerouterDetectors(const std::string& file); 00272 00273 int getAggFlowFor(const ROEdge* edge, SUMOTime time, SUMOTime period, 00274 const RODFDetectorFlows& flows) const; 00275 00276 void guessEmptyFlows(RODFDetectorFlows& flows); 00277 00278 void mesoJoin(const std::string& nid, const std::vector<std::string> &oldids); 00279 00280 00281 protected: 00285 void clearDists(std::map<size_t, RandomDistributor<size_t>* > &dists) const ; 00286 00287 00288 protected: 00289 std::vector<RODFDetector*> myDetectors; 00290 std::map<std::string, RODFDetector*> myDetectorMap; 00291 std::map<std::string, std::vector<RODFDetector*> > myDetectorEdgeMap; 00292 00293 private: 00295 RODFDetectorCon(const RODFDetectorCon& src); 00296 00298 RODFDetectorCon& operator=(const RODFDetectorCon& src); 00299 00300 }; 00301 00302 00303 #endif 00304 00305 /****************************************************************************/ 00306