|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Class representing a detector within the DFROUTER 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 RODFDetector_h 00020 #define RODFDetector_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 <map> 00033 #include <string> 00034 #include <vector> 00035 #include <map> 00036 #include <utils/common/SUMOTime.h> 00037 #include <utils/common/RandomDistributor.h> 00038 #include "RODFRouteCont.h" 00039 00040 00041 // =========================================================================== 00042 // class declarations 00043 // =========================================================================== 00044 class RODFRouteCont; 00045 class RODFDetectorFlows; 00046 class ROEdge; 00047 class RODFEdge; 00048 class RODFDetectorCon; 00049 class RODFNet; 00050 struct RODFRouteDesc; 00051 class OutputDevice; 00052 00053 00054 // =========================================================================== 00055 // enumerations 00056 // =========================================================================== 00061 enum RODFDetectorType { 00063 TYPE_NOT_DEFINED = 0, 00064 00066 DISCARDED_DETECTOR, 00067 00069 BETWEEN_DETECTOR, 00070 00072 SOURCE_DETECTOR, 00073 SINK_DETECTOR 00074 }; 00075 00076 00077 // =========================================================================== 00078 // class definitions 00079 // =========================================================================== 00084 class RODFDetector { 00085 public: 00096 RODFDetector(const std::string& id, const std::string& laneID, 00097 SUMOReal pos, const RODFDetectorType type) throw(); 00098 00099 00107 RODFDetector(const std::string& id, const RODFDetector& f) throw(); 00108 00109 00111 ~RODFDetector() throw(); 00112 00113 00114 00117 00121 const std::string& getID() const throw() { 00122 return myID; 00123 }; 00124 00125 00129 const std::string& getLaneID() const throw() { 00130 return myLaneID; 00131 }; 00132 00133 00137 std::string getEdgeID() const throw() { 00138 return myLaneID.substr(0, myLaneID.rfind('_')); 00139 } 00140 00141 00145 SUMOReal getPos() const throw() { 00146 return myPosition; 00147 }; 00148 00149 00154 RODFDetectorType getType() const throw() { 00155 return myType; 00156 }; 00158 00159 00160 void setType(RODFDetectorType type); 00161 void addRoute(RODFRouteDesc& nrd); 00162 void addRoutes(RODFRouteCont* routes); 00163 bool hasRoutes() const; 00164 const std::vector<RODFRouteDesc> &getRouteVector() const; 00165 void addPriorDetector(RODFDetector* det); 00166 void addFollowingDetector(RODFDetector* det); 00167 const std::vector<RODFDetector*> &getPriorDetectors() const; 00168 const std::vector<RODFDetector*> &getFollowerDetectors() const; 00169 00170 00173 00174 bool writeEmitterDefinition(const std::string& file, 00175 const std::map<size_t, RandomDistributor<size_t>* > &dists, 00176 const RODFDetectorFlows& flows, 00177 SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, 00178 bool includeUnusedRoutes, SUMOReal scale, 00179 bool insertionsOnly, SUMOReal defaultSpeed) const; 00180 bool writeRoutes(std::vector<std::string> &saved, 00181 OutputDevice& out); 00182 void writeSingleSpeedTrigger(const std::string& file, 00183 const RODFDetectorFlows& flows, 00184 SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, 00185 SUMOReal defaultSpeed); 00186 void writeEndRerouterDetectors(const std::string& file); 00188 00189 void buildDestinationDistribution(const RODFDetectorCon& detectors, 00190 const RODFDetectorFlows& flows, 00191 SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, 00192 const RODFNet& net, 00193 std::map<size_t, RandomDistributor<size_t>* > &into, 00194 int maxFollower) const; 00195 00196 void computeSplitProbabilities(const RODFNet* net, const RODFDetectorCon& detectors, 00197 const RODFDetectorFlows& flows, 00198 SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset); 00199 00200 const std::vector<std::map<RODFEdge*, SUMOReal> > &getSplitProbabilities() const { 00201 return mySplitProbabilities; 00202 } 00203 00204 protected: 00205 int getFlowFor(const ROEdge* edge, SUMOTime time) const; 00206 SUMOReal computeDistanceFactor(const RODFRouteDesc& rd) const; 00207 00208 00209 protected: 00210 std::string myID; 00211 std::string myLaneID; 00212 SUMOReal myPosition; 00213 RODFDetectorType myType; 00214 RODFRouteCont* myRoutes; 00215 std::vector<RODFDetector*> myPriorDetectors, myFollowingDetectors; 00216 std::vector<std::map<RODFEdge*, SUMOReal> > mySplitProbabilities; 00217 std::map<std::string, RODFEdge*> myRoute2Edge; 00218 00219 00220 private: 00222 RODFDetector(const RODFDetector& src); 00223 00225 RODFDetector& operator=(const RODFDetector& src); 00226 00227 }; 00228 00229 00234 class RODFDetectorCon { 00235 public: 00236 RODFDetectorCon(); 00237 ~RODFDetectorCon(); 00238 bool addDetector(RODFDetector* dfd); 00239 void removeDetector(const std::string& id); 00240 bool detectorsHaveCompleteTypes() const; 00241 bool detectorsHaveRoutes() const; 00242 const std::vector<RODFDetector*> &getDetectors() const; 00243 void save(const std::string& file) const; 00244 void saveAsPOIs(const std::string& file) const; 00245 void saveRoutes(const std::string& file) const; 00246 00247 const RODFDetector& getDetector(const std::string& id) const; 00248 const RODFDetector& getAnyDetectorForEdge(const RODFEdge* const edge) const; 00249 00250 bool knows(const std::string& id) const; 00251 void writeEmitters(const std::string& file, 00252 const RODFDetectorFlows& flows, 00253 SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset, 00254 const RODFNet& net, 00255 bool writeCalibrators, bool includeUnusedRoutes, 00256 SUMOReal scale, int maxFollower, 00257 bool insertionsOnly); 00258 00259 void writeEmitterPOIs(const std::string& file, 00260 const RODFDetectorFlows& flows); 00261 00262 void writeSpeedTrigger(const RODFNet* const net, const std::string& file, 00263 const RODFDetectorFlows& flows, 00264 SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset); 00265 00266 void writeValidationDetectors(const std::string& file, 00267 bool includeSources, bool singleFile, bool friendly); 00268 void writeEndRerouterDetectors(const std::string& file); 00269 00270 int getAggFlowFor(const ROEdge* edge, SUMOTime time, SUMOTime period, 00271 const RODFDetectorFlows& flows) const; 00272 00273 void guessEmptyFlows(RODFDetectorFlows& flows); 00274 00275 void mesoJoin(const std::string& nid, const std::vector<std::string> &oldids); 00276 00277 00278 protected: 00282 void clearDists(std::map<size_t, RandomDistributor<size_t>* > &dists) const throw(); 00283 00284 00285 protected: 00286 std::vector<RODFDetector*> myDetectors; 00287 std::map<std::string, RODFDetector*> myDetectorMap; 00288 std::map<std::string, std::vector<RODFDetector*> > myDetectorEdgeMap; 00289 00290 private: 00292 RODFDetectorCon(const RODFDetectorCon& src); 00293 00295 RODFDetectorCon& operator=(const RODFDetectorCon& src); 00296 00297 }; 00298 00299 00300 #endif 00301 00302 /****************************************************************************/ 00303