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-sim.org/
14 // Copyright (C) 2001-2013 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 
254  void joinTLS(NBTrafficLightLogicCont& tlc, SUMOReal maxdist);
255 
256 
264  void setAsTLControlled(NBNode* node, NBTrafficLightLogicCont& tlc, TrafficLightType type, std::string id = "");
266 
267 
270  void rename(NBNode* node, const std::string& newID);
271 
272 
274  void computeLanes2Lanes();
275 
277  void computeLogics(const NBEdgeCont& ec, OptionsCont& oc);
278 
282  unsigned int size() const {
283  return (unsigned int) myNodes.size();
284  }
285 
287  void clear();
288 
289 
290 
291  std::string getFreeID();
292 
293  void computeNodeShapes(bool leftHand);
294 
295 
296 
297 
303  void printBuiltNodesStatistics() const;
304 
305 
307  std::vector<std::string> getAllNames() const;
308 
309 
310  /* @brief analyzes a cluster of nodes which shall be joined
311  * @param[in] cluster The nodes to be joined
312  * @param[out] id The name for the new node
313  * @param[out] pos The position of the new node
314  * @param[out] hasTLS Whether the new node has a traffic light
315  * @param[out] tlType The type of traffic light (if any)
316  */
317  void analyzeCluster(std::set<NBNode*> cluster, std::string& id, Position& pos,
318  bool& hasTLS, TrafficLightType& type);
319 
321  void registerJoinedCluster(const std::set<NBNode*>& cluster);
322 
324  const std::vector<std::set<std::string> >& getJoinedClusters() const {
325  return myJoinedClusters;
326  }
327 
328 
329  /* @brief discards traffic lights
330  * @param[in] geometryLike Whether only tls at geometry-like nodes shall be discarded
331  */
332  void discardTrafficLights(NBTrafficLightLogicCont& tlc, bool geometryLike);
333 
334 private:
337 
339  typedef std::vector<std::set<NBNode*> > NodeClusters;
340 
341 
349  void generateNodeClusters(SUMOReal maxDist, NodeClusters& into) const;
350 
351 
352  // @brief joins the given node clusters
353  void joinNodeClusters(NodeClusters clusters,
355 
357 
358 
359 
362 
367  bool shouldBeTLSControlled(const std::set<NBNode*>& c) const;
369 
370 
371 private:
374 
376  typedef std::map<std::string, NBNode*> NodeCont;
377 
380 
382  std::set<NBNode*> myExtractedNodes;
383 
384  // @brief set of node ids which should not be joined
385  std::set<std::string> myJoinExclusions;
386 
387  // @brief loaded sets of node ids to join (cleared after use)
388  std::vector<std::set<std::string> > myClusters2Join;
389  // @brief sets of node ids which were joined
390  std::vector<std::set<std::string> > myJoinedClusters;
391 
393  std::set<std::string> myJoined;
394 
395 private:
397  NBNodeCont(const NBNodeCont& s);
398 
400  NBNodeCont& operator=(const NBNodeCont& s);
401 
402 };
403 
404 
405 #endif
406 
407 /****************************************************************************/
408