|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Container for nodes during the netbuilding process 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 NBNodeCont_h 00020 #define NBNodeCont_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 <map> 00034 #include <vector> 00035 #include <set> 00036 #include <utils/geom/Position.h> 00037 #include "NBEdgeCont.h" 00038 #include "NBNode.h" 00039 #include <utils/common/UtilExceptions.h> 00040 00041 00042 // =========================================================================== 00043 // class declarations 00044 // =========================================================================== 00045 class NBDistrict; 00046 class OptionsCont; 00047 class OutputDevice; 00048 class NBJoinedEdgesMap; 00049 00050 00051 // =========================================================================== 00052 // class definitions 00053 // =========================================================================== 00058 class NBNodeCont { 00059 public: 00061 NBNodeCont() throw(); 00062 00063 00065 ~NBNodeCont() throw(); 00066 00067 00068 00071 00078 bool insert(const std::string& id, const Position& position, 00079 NBDistrict* district) throw(); 00080 00081 00087 bool insert(const std::string& id, const Position& position) throw(); 00088 00089 00094 Position insert(const std::string& id) throw(); 00095 00096 00101 bool insert(NBNode* node) throw(); 00102 00103 00108 bool erase(NBNode* node) throw(); 00109 00110 00116 bool extract(NBNode* node, bool remember=false) throw(); 00117 00122 NBNode* retrieve(const std::string& id) const throw(); 00123 00124 00130 NBNode* retrieve(const Position& position, SUMOReal offset=0.) const throw(); 00131 00132 00136 std::map<std::string, NBNode*>::const_iterator begin() const { 00137 return myNodes.begin(); 00138 } 00139 00140 00144 std::map<std::string, NBNode*>::const_iterator end() const { 00145 return myNodes.end(); 00146 } 00148 00149 00150 00153 00154 /* @brief add ids of nodes wich shall not be joined 00155 * @param[in] ids A list of ids to exclude from joining 00156 * @param[in] check Whether to check if these nodes are known 00157 * @note checking is off by default because all nodes may not have been loaded yet 00158 */ 00159 void addJoinExclusion(const std::vector<std::string> &ids, bool check=false); 00160 00161 00165 void addCluster2Join(std::set<std::string> cluster); 00166 00167 00170 unsigned int joinLoadedClusters(NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc); 00171 00172 00175 unsigned int joinJunctions(SUMOReal maxdist, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc); 00177 00178 00181 00188 void removeDummyEdges(NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tc); 00189 00190 00197 void joinDoubleNodeConnections(NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc); 00198 00199 00208 void removeIsolatedRoads(NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tc); 00209 00210 00226 unsigned int removeUnwishedNodes(NBDistrictCont& dc, NBEdgeCont& ec, NBJoinedEdgesMap& je, 00227 NBTrafficLightLogicCont& tlc, bool removeGeometryNodes); 00229 00230 00231 00234 00240 void guessTLs(OptionsCont& oc, NBTrafficLightLogicCont& tlc); 00241 00242 00247 void joinTLS(NBTrafficLightLogicCont& tlc); 00248 00249 00256 void setAsTLControlled(NBNode* node, NBTrafficLightLogicCont& tlc, std::string id=""); 00258 00259 00260 00261 00262 00264 void computeLanes2Lanes(); 00265 00267 void computeLogics(const NBEdgeCont& ec, OptionsCont& oc); 00268 00270 void sortNodesEdges(bool leftHand); 00271 00273 void computeNodeTypes(const NBTypeCont& tc); 00274 00276 void computePriorities(); 00277 00281 unsigned int size() const throw() { 00282 return (unsigned int) myNodes.size(); 00283 } 00284 00286 void clear(); 00287 00288 00289 00290 std::string getFreeID(); 00291 00292 void computeNodeShapes(bool leftHand); 00293 00294 00295 void guessRamps(OptionsCont& oc, NBEdgeCont& ec, NBDistrictCont& dc); 00296 00297 00303 void printBuiltNodesStatistics() const throw(); 00304 00305 00307 std::vector<std::string> getAllNames() const throw(); 00308 00309 00310 /* @brief analyzes a cluster of nodes which shall be joined 00311 * @param[in] cluster The nodes to be joined 00312 * @param[out] id The name for the new node 00313 * @param[out] pos The position of the new node 00314 * @param[out] hasTLS Whether the new node has a traffic light 00315 */ 00316 void analyzeCluster(std::set<NBNode*> cluster, std::string& id, Position& pos, bool& hasTLS); 00317 00318 00319 private: 00320 bool mayNeedOnRamp(OptionsCont& oc, NBNode* cur) const; 00321 bool mayNeedOffRamp(OptionsCont& oc, NBNode* cur) const; 00322 bool buildOnRamp(OptionsCont& oc, NBNode* cur, 00323 NBEdgeCont& ec, NBDistrictCont& dc, EdgeVector& incremented); 00324 00325 void buildOffRamp(OptionsCont& oc, NBNode* cur, 00326 NBEdgeCont& ec, NBDistrictCont& dc, EdgeVector& incremented); 00327 00328 void checkHighwayRampOrder(NBEdge *&pot_highway, NBEdge *&pot_ramp); 00329 00330 00331 00334 00336 typedef std::vector<std::set<NBNode*> > NodeClusters; 00337 00338 00346 void generateNodeClusters(SUMOReal maxDist, NodeClusters& into) const; 00347 00348 // @brief merges two nodes using name and position of target 00349 void merge(NBNode* moved, NBNode* target, NBDistrictCont& dc, NBEdgeCont& ec); 00350 00351 // @brief replaces oldEdge by an edge between from and to, keeping all attributes 00352 void remapEdge(NBEdge* oldEdge, NBNode* from, NBNode* to, NBDistrictCont& dc, NBEdgeCont& ec); 00353 00354 // @brief joins the given node clusters 00355 void joinNodeClusters(NodeClusters clusters, 00356 NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc); 00357 00359 00360 00361 00364 00369 bool shouldBeTLSControlled(const std::set<NBNode*> &c) const; 00371 00372 00373 private: 00375 int myInternalID; 00376 00378 typedef std::map<std::string, NBNode*> NodeCont; 00379 00381 NodeCont myNodes; 00382 00384 std::set<NBNode*> myExtractedNodes; 00385 00386 // @brief set of node ids which should not be joined 00387 std::set<std::string> myJoinExclusions; 00388 00389 // @brief loaded sets of node ids to join 00390 std::vector<std::set<std::string> > myClusters2Join; 00391 00393 std::set<std::string> myJoined; 00394 00395 00396 private: 00398 NBNodeCont(const NBNodeCont& s); 00399 00401 NBNodeCont& operator=(const NBNodeCont& s); 00402 00403 }; 00404 00405 00406 #endif 00407 00408 /****************************************************************************/ 00409