SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NBNodeCont.h
Go to the documentation of this file.
1 /****************************************************************************/
11 // Container for nodes during the netbuilding process
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
14 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 #ifndef NBNodeCont_h
25 #define NBNodeCont_h
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
37 #include <string>
38 #include <map>
39 #include <vector>
40 #include <set>
41 #include <utils/geom/Position.h>
42 #include "NBEdgeCont.h"
43 #include "NBNode.h"
45 
46 
47 // ===========================================================================
48 // class declarations
49 // ===========================================================================
50 class NBDistrict;
51 class OptionsCont;
52 class OutputDevice;
53 class NBJoinedEdgesMap;
54 
55 
56 // ===========================================================================
57 // class definitions
58 // ===========================================================================
63 class NBNodeCont {
64 public:
66  NBNodeCont() ;
67 
68 
70  ~NBNodeCont() ;
71 
72 
73 
76 
83  bool insert(const std::string& id, const Position& position,
84  NBDistrict* district) ;
85 
86 
92  bool insert(const std::string& id, const Position& position) ;
93 
94 
99  Position insert(const std::string& id) ;
100 
101 
106  bool insert(NBNode* node) ;
107 
108 
113  bool erase(NBNode* node) ;
114 
115 
121  bool extract(NBNode* node, bool remember = false) ;
122 
127  NBNode* retrieve(const std::string& id) const ;
128 
129 
135  NBNode* retrieve(const Position& position, SUMOReal offset = 0.) const ;
136 
137 
141  std::map<std::string, NBNode*>::const_iterator begin() const {
142  return myNodes.begin();
143  }
144 
145 
149  std::map<std::string, NBNode*>::const_iterator end() const {
150  return myNodes.end();
151  }
153 
154 
155 
158 
159  /* @brief add ids of nodes wich shall not be joined
160  * @param[in] ids A list of ids to exclude from joining
161  * @param[in] check Whether to check if these nodes are known
162  * @note checking is off by default because all nodes may not have been loaded yet
163  */
164  void addJoinExclusion(const std::vector<std::string> &ids, bool check = false);
165 
166 
170  void addCluster2Join(std::set<std::string> cluster);
171 
172 
176 
177 
180  unsigned int joinJunctions(SUMOReal maxdist, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc);
182 
183 
184 
187 
195 
196 
204 
205 
215 
216 
233  NBTrafficLightLogicCont& tlc, bool removeGeometryNodes);
235 
236 
237 
240 
247 
248 
253  void joinTLS(NBTrafficLightLogicCont& tlc);
254 
255 
262  void setAsTLControlled(NBNode* node, NBTrafficLightLogicCont& tlc, std::string id = "");
264 
265 
268  void rename(NBNode* node, const std::string& newID);
269 
270 
272  void computeLanes2Lanes();
273 
275  void computeLogics(const NBEdgeCont& ec, OptionsCont& oc);
276 
280  unsigned int size() const {
281  return (unsigned int) myNodes.size();
282  }
283 
285  void clear();
286 
287 
288 
289  std::string getFreeID();
290 
291  void computeNodeShapes(bool leftHand);
292 
293 
294  void guessRamps(OptionsCont& oc, NBEdgeCont& ec, NBDistrictCont& dc);
295 
296 
302  void printBuiltNodesStatistics() const ;
303 
304 
306  std::vector<std::string> getAllNames() const ;
307 
308 
309  /* @brief analyzes a cluster of nodes which shall be joined
310  * @param[in] cluster The nodes to be joined
311  * @param[out] id The name for the new node
312  * @param[out] pos The position of the new node
313  * @param[out] hasTLS Whether the new node has a traffic light
314  */
315  void analyzeCluster(std::set<NBNode*> cluster, std::string& id, Position& pos, bool& hasTLS);
316 
318  void registerJoinedCluster(const std::set<NBNode*>& cluster);
319 
321  const std::vector<std::set<std::string> >& getJoinedClusters() const {
322  return myJoinedClusters;
323  }
324 
325 
326 private:
327  bool mayNeedOnRamp(OptionsCont& oc, NBNode* cur) const;
328  bool mayNeedOffRamp(OptionsCont& oc, NBNode* cur) const;
329  bool buildOnRamp(OptionsCont& oc, NBNode* cur,
330  NBEdgeCont& ec, NBDistrictCont& dc, EdgeVector& incremented);
331 
332  void buildOffRamp(OptionsCont& oc, NBNode* cur,
333  NBEdgeCont& ec, NBDistrictCont& dc, EdgeVector& incremented);
334 
335  void checkHighwayRampOrder(NBEdge *&pot_highway, NBEdge *&pot_ramp);
336 
337 
338 
341 
343  typedef std::vector<std::set<NBNode*> > NodeClusters;
344 
345 
353  void generateNodeClusters(SUMOReal maxDist, NodeClusters& into) const;
354 
355 
356  // @brief joins the given node clusters
357  void joinNodeClusters(NodeClusters clusters,
359 
361 
362 
363 
366 
371  bool shouldBeTLSControlled(const std::set<NBNode*> &c) const;
373 
374 
375 private:
378 
380  typedef std::map<std::string, NBNode*> NodeCont;
381 
384 
386  std::set<NBNode*> myExtractedNodes;
387 
388  // @brief set of node ids which should not be joined
389  std::set<std::string> myJoinExclusions;
390 
391  // @brief loaded sets of node ids to join (cleared after use)
392  std::vector<std::set<std::string> > myClusters2Join;
393  // @brief sets of node ids which were joined
394  std::vector<std::set<std::string> > myJoinedClusters;
395 
397  std::set<std::string> myJoined;
398 
399 private:
401  NBNodeCont(const NBNodeCont& s);
402 
404  NBNodeCont& operator=(const NBNodeCont& s);
405 
406 };
407 
408 
409 #endif
410 
411 /****************************************************************************/
412