SUMO - Simulation of Urban MObility

NBNodeCont.h

Go to the documentation of this file.
00001 /****************************************************************************/
00011 // Container for nodes during the netbuilding process
00012 /****************************************************************************/
00013 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00014 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00015 /****************************************************************************/
00016 //
00017 //   This file is part of SUMO.
00018 //   SUMO is free software: you can redistribute it and/or modify
00019 //   it under the terms of the GNU General Public License as published by
00020 //   the Free Software Foundation, either version 3 of the License, or
00021 //   (at your option) any later version.
00022 //
00023 /****************************************************************************/
00024 #ifndef NBNodeCont_h
00025 #define NBNodeCont_h
00026 
00027 
00028 // ===========================================================================
00029 // included modules
00030 // ===========================================================================
00031 #ifdef _MSC_VER
00032 #include <windows_config.h>
00033 #else
00034 #include <config.h>
00035 #endif
00036 
00037 #include <string>
00038 #include <map>
00039 #include <vector>
00040 #include <set>
00041 #include <utils/geom/Position.h>
00042 #include "NBEdgeCont.h"
00043 #include "NBNode.h"
00044 #include <utils/common/UtilExceptions.h>
00045 
00046 
00047 // ===========================================================================
00048 // class declarations
00049 // ===========================================================================
00050 class NBDistrict;
00051 class OptionsCont;
00052 class OutputDevice;
00053 class NBJoinedEdgesMap;
00054 
00055 
00056 // ===========================================================================
00057 // class definitions
00058 // ===========================================================================
00063 class NBNodeCont {
00064 public:
00066     NBNodeCont() ;
00067 
00068 
00070     ~NBNodeCont() ;
00071 
00072 
00073 
00076 
00083     bool insert(const std::string& id, const Position& position,
00084                 NBDistrict* district) ;
00085 
00086 
00092     bool insert(const std::string& id, const Position& position) ;
00093 
00094 
00099     Position insert(const std::string& id) ;
00100 
00101 
00106     bool insert(NBNode* node) ;
00107 
00108 
00113     bool erase(NBNode* node) ;
00114 
00115 
00121     bool extract(NBNode* node, bool remember = false) ;
00122 
00127     NBNode* retrieve(const std::string& id) const ;
00128 
00129 
00135     NBNode* retrieve(const Position& position, SUMOReal offset = 0.) const ;
00136 
00137 
00141     std::map<std::string, NBNode*>::const_iterator begin() const {
00142         return myNodes.begin();
00143     }
00144 
00145 
00149     std::map<std::string, NBNode*>::const_iterator end() const {
00150         return myNodes.end();
00151     }
00153 
00154 
00155 
00158 
00159     /* @brief add ids of nodes wich shall not be joined
00160      * @param[in] ids A list of ids to exclude from joining
00161      * @param[in] check Whether to check if these nodes are known
00162      * @note checking is off by default because all nodes may not have been loaded yet
00163      */
00164     void addJoinExclusion(const std::vector<std::string> &ids, bool check = false);
00165 
00166 
00170     void addCluster2Join(std::set<std::string> cluster);
00171 
00172 
00175     unsigned int joinLoadedClusters(NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc);
00176 
00177 
00180     unsigned int joinJunctions(SUMOReal maxdist, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc);
00182 
00183 
00184 
00187 
00194     void removeSelfLoops(NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tc);
00195 
00196 
00203     void joinSimilarEdges(NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc);
00204 
00205 
00214     void removeIsolatedRoads(NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tc);
00215 
00216 
00232     unsigned int removeUnwishedNodes(NBDistrictCont& dc, NBEdgeCont& ec, NBJoinedEdgesMap& je,
00233                                      NBTrafficLightLogicCont& tlc, bool removeGeometryNodes);
00235 
00236 
00237 
00240 
00246     void guessTLs(OptionsCont& oc, NBTrafficLightLogicCont& tlc);
00247 
00248 
00253     void joinTLS(NBTrafficLightLogicCont& tlc);
00254 
00255 
00262     void setAsTLControlled(NBNode* node, NBTrafficLightLogicCont& tlc, std::string id = "");
00264 
00265 
00266 
00267 
00268 
00270     void computeLanes2Lanes();
00271 
00273     void computeLogics(const NBEdgeCont& ec, OptionsCont& oc);
00274 
00276     void sortNodesEdges(bool leftHand);
00277 
00279     void computeNodeTypes(const NBTypeCont& tc);
00280 
00282     void computePriorities();
00283 
00287     unsigned int size() const {
00288         return (unsigned int) myNodes.size();
00289     }
00290 
00292     void clear();
00293 
00294 
00295 
00296     std::string getFreeID();
00297 
00298     void computeNodeShapes(bool leftHand);
00299 
00300 
00301     void guessRamps(OptionsCont& oc, NBEdgeCont& ec, NBDistrictCont& dc);
00302 
00303 
00309     void printBuiltNodesStatistics() const ;
00310 
00311 
00313     std::vector<std::string> getAllNames() const ;
00314 
00315 
00316     /* @brief analyzes a cluster of nodes which shall be joined
00317      * @param[in] cluster The nodes to be joined
00318      * @param[out] id The name for the new node
00319      * @param[out] pos The position of the new node
00320      * @param[out] hasTLS Whether the new node has a traffic light
00321      */
00322     void analyzeCluster(std::set<NBNode*> cluster, std::string& id, Position& pos, bool& hasTLS);
00323 
00324 
00325 private:
00326     bool mayNeedOnRamp(OptionsCont& oc, NBNode* cur) const;
00327     bool mayNeedOffRamp(OptionsCont& oc, NBNode* cur) const;
00328     bool buildOnRamp(OptionsCont& oc, NBNode* cur,
00329                      NBEdgeCont& ec, NBDistrictCont& dc, EdgeVector& incremented);
00330 
00331     void buildOffRamp(OptionsCont& oc, NBNode* cur,
00332                       NBEdgeCont& ec, NBDistrictCont& dc, EdgeVector& incremented);
00333 
00334     void checkHighwayRampOrder(NBEdge *&pot_highway, NBEdge *&pot_ramp);
00335 
00336 
00337 
00340 
00342     typedef std::vector<std::set<NBNode*> > NodeClusters;
00343 
00344 
00352     void generateNodeClusters(SUMOReal maxDist, NodeClusters& into) const;
00353 
00354  
00355     // @brief joins the given node clusters
00356     void joinNodeClusters(NodeClusters clusters,
00357                           NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc);
00358 
00360 
00361 
00362 
00365 
00370     bool shouldBeTLSControlled(const std::set<NBNode*> &c) const;
00372 
00373 
00374 private:
00376     int myInternalID;
00377 
00379     typedef std::map<std::string, NBNode*> NodeCont;
00380 
00382     NodeCont myNodes;
00383 
00385     std::set<NBNode*> myExtractedNodes;
00386 
00387     // @brief set of node ids which should not be joined
00388     std::set<std::string> myJoinExclusions;
00389 
00390     // @brief loaded sets of node ids to join
00391     std::vector<std::set<std::string> > myClusters2Join;
00392 
00394     std::set<std::string> myJoined;
00395 
00396 
00397 private:
00399     NBNodeCont(const NBNodeCont& s);
00400 
00402     NBNodeCont& operator=(const NBNodeCont& s);
00403 
00404 };
00405 
00406 
00407 #endif
00408 
00409 /****************************************************************************/
00410 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines