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 
00268     void rename(NBNode* node, const std::string& newID);
00269 
00270 
00272     void computeLanes2Lanes();
00273 
00275     void computeLogics(const NBEdgeCont& ec, OptionsCont& oc);
00276 
00280     unsigned int size() const {
00281         return (unsigned int) myNodes.size();
00282     }
00283 
00285     void clear();
00286 
00287 
00288 
00289     std::string getFreeID();
00290 
00291     void computeNodeShapes(bool leftHand);
00292 
00293 
00294     void guessRamps(OptionsCont& oc, NBEdgeCont& ec, NBDistrictCont& dc);
00295 
00296 
00302     void printBuiltNodesStatistics() const ;
00303 
00304 
00306     std::vector<std::string> getAllNames() const ;
00307 
00308 
00309     /* @brief analyzes a cluster of nodes which shall be joined
00310      * @param[in] cluster The nodes to be joined
00311      * @param[out] id The name for the new node
00312      * @param[out] pos The position of the new node
00313      * @param[out] hasTLS Whether the new node has a traffic light
00314      */
00315     void analyzeCluster(std::set<NBNode*> cluster, std::string& id, Position& pos, bool& hasTLS);
00316 
00318     void registerJoinedCluster(const std::set<NBNode*>& cluster);
00319 
00321     const std::vector<std::set<std::string> >& getJoinedClusters() const {
00322         return myJoinedClusters;
00323     }
00324 
00325 
00326 private:
00327     bool mayNeedOnRamp(OptionsCont& oc, NBNode* cur) const;
00328     bool mayNeedOffRamp(OptionsCont& oc, NBNode* cur) const;
00329     bool buildOnRamp(OptionsCont& oc, NBNode* cur,
00330                      NBEdgeCont& ec, NBDistrictCont& dc, EdgeVector& incremented);
00331 
00332     void buildOffRamp(OptionsCont& oc, NBNode* cur,
00333                       NBEdgeCont& ec, NBDistrictCont& dc, EdgeVector& incremented);
00334 
00335     void checkHighwayRampOrder(NBEdge *&pot_highway, NBEdge *&pot_ramp);
00336 
00337 
00338 
00341 
00343     typedef std::vector<std::set<NBNode*> > NodeClusters;
00344 
00345 
00353     void generateNodeClusters(SUMOReal maxDist, NodeClusters& into) const;
00354 
00355  
00356     // @brief joins the given node clusters
00357     void joinNodeClusters(NodeClusters clusters,
00358                           NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc);
00359 
00361 
00362 
00363 
00366 
00371     bool shouldBeTLSControlled(const std::set<NBNode*> &c) const;
00373 
00374 
00375 private:
00377     int myInternalID;
00378 
00380     typedef std::map<std::string, NBNode*> NodeCont;
00381 
00383     NodeCont myNodes;
00384 
00386     std::set<NBNode*> myExtractedNodes;
00387 
00388     // @brief set of node ids which should not be joined
00389     std::set<std::string> myJoinExclusions;
00390 
00391     // @brief loaded sets of node ids to join (cleared after use)
00392     std::vector<std::set<std::string> > myClusters2Join;
00393     // @brief sets of node ids which were joined
00394     std::vector<std::set<std::string> > myJoinedClusters;
00395 
00397     std::set<std::string> myJoined;
00398 
00399 private:
00401     NBNodeCont(const NBNodeCont& s);
00402 
00404     NBNodeCont& operator=(const NBNodeCont& s);
00405 
00406 };
00407 
00408 
00409 #endif
00410 
00411 /****************************************************************************/
00412 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines