SUMO - Simulation of Urban MObility
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.dlr.de/
14 // Copyright (C) 2001-2015 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>
42 #include <utils/geom/Position.h>
43 #include "NBEdgeCont.h"
44 #include "NBNode.h"
46 
47 
48 // ===========================================================================
49 // class declarations
50 // ===========================================================================
51 class NBDistrict;
52 class OptionsCont;
53 class OutputDevice;
54 class NBJoinedEdgesMap;
55 
56 
57 // ===========================================================================
58 // class definitions
59 // ===========================================================================
64 class NBNodeCont {
65 public:
67  NBNodeCont();
68 
69 
71  ~NBNodeCont();
72 
73 
74 
77 
84  bool insert(const std::string& id, const Position& position,
85  NBDistrict* district = 0);
86 
87 
92  bool insert(NBNode* node);
93 
94 
99  bool erase(NBNode* node);
100 
101 
107  bool extract(NBNode* node, bool remember = false);
108 
113  NBNode* retrieve(const std::string& id) const;
114 
115 
121  NBNode* retrieve(const Position& position, const SUMOReal offset = 0.) const;
122 
123 
127  std::map<std::string, NBNode*>::const_iterator begin() const {
128  return myNodes.begin();
129  }
130 
131 
135  std::map<std::string, NBNode*>::const_iterator end() const {
136  return myNodes.end();
137  }
139 
140 
141 
144 
145  /* @brief add ids of nodes wich shall not be joined
146  * @param[in] ids A list of ids to exclude from joining
147  * @param[in] check Whether to check if these nodes are known
148  * @note checking is off by default because all nodes may not have been loaded yet
149  */
150  void addJoinExclusion(const std::vector<std::string>& ids, bool check = false);
151 
152 
156  void addCluster2Join(std::set<std::string> cluster);
157 
158 
162 
163 
166  unsigned int joinJunctions(SUMOReal maxDist, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc);
168 
169 
170 
173 
181 
182 
190 
191 
194  void avoidOverlap();
195 
196 
206 
207 
224  NBTrafficLightLogicCont& tlc, bool removeGeometryNodes);
226 
227 
228 
231 
238 
239 
245  void joinTLS(NBTrafficLightLogicCont& tlc, SUMOReal maxdist);
246 
247 
255  void setAsTLControlled(NBNode* node, NBTrafficLightLogicCont& tlc, TrafficLightType type, std::string id = "");
257 
258 
261  void rename(NBNode* node, const std::string& newID);
262 
263 
265  void computeLanes2Lanes();
266 
268  void computeLogics(const NBEdgeCont& ec, OptionsCont& oc);
269 
273  unsigned int size() const {
274  return (unsigned int) myNodes.size();
275  }
276 
278  void clear();
279 
280 
281 
282  std::string getFreeID();
283 
287  void computeNodeShapes(SUMOReal mismatchThreshold = -1);
288 
294  void printBuiltNodesStatistics() const;
295 
296 
298  std::vector<std::string> getAllNames() const;
299 
300 
301  /* @brief analyzes a cluster of nodes which shall be joined
302  * @param[in] cluster The nodes to be joined
303  * @param[out] id The name for the new node
304  * @param[out] pos The position of the new node
305  * @param[out] hasTLS Whether the new node has a traffic light
306  * @param[out] tlType The type of traffic light (if any)
307  */
308  void analyzeCluster(std::set<NBNode*> cluster, std::string& id, Position& pos,
309  bool& hasTLS, TrafficLightType& type);
310 
312  void registerJoinedCluster(const std::set<NBNode*>& cluster);
313 
315  const std::vector<std::set<std::string> >& getJoinedClusters() const {
316  return myJoinedClusters;
317  }
318 
319 
320  /* @brief discards traffic lights
321  * @param[in] geometryLike Whether only tls at geometry-like nodes shall be discarded
322  */
323  void discardTrafficLights(NBTrafficLightLogicCont& tlc, bool geometryLike, bool guessSignals);
324 
326  void markAsSplit(const NBNode* node) {
327  mySplit.insert(node);
328  }
329 
330 private:
333 
335  typedef std::vector<std::set<NBNode*> > NodeClusters;
336  typedef std::pair<NBNode*, SUMOReal> NodeAndDist;
337 
338 
346  void generateNodeClusters(SUMOReal maxDist, NodeClusters& into) const;
347 
348 
349  // @brief joins the given node clusters
350  void joinNodeClusters(NodeClusters clusters,
352 
354 
355 
356 
359 
364  bool shouldBeTLSControlled(const std::set<NBNode*>& c) const;
366 
367 
368 private:
371 
373  typedef std::map<std::string, NBNode*> NodeCont;
374 
376  NodeCont myNodes;
377 
379  std::set<NBNode*> myExtractedNodes;
380 
381  // @brief set of node ids which should not be joined
382  std::set<std::string> myJoinExclusions;
383 
384  // @brief loaded sets of node ids to join (cleared after use)
385  std::vector<std::set<std::string> > myClusters2Join;
386  // @brief sets of node ids which were joined
387  std::vector<std::set<std::string> > myJoinedClusters;
388 
390  std::set<std::string> myJoined;
391 
393  std::set<const NBNode*> mySplit;
394 
397 
398 private:
400  NBNodeCont(const NBNodeCont& s);
401 
403  NBNodeCont& operator=(const NBNodeCont& s);
404 
405 };
406 
407 
408 #endif
409 
410 /****************************************************************************/
411 
std::string getFreeID()
std::set< std::string > myJoinExclusions
Definition: NBNodeCont.h:382
NodeCont myNodes
The map of names to nodes.
Definition: NBNodeCont.h:376
void joinSimilarEdges(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins edges connecting the same nodes.
Definition: NBNodeCont.cpp:180
const std::vector< std::set< std::string > > & getJoinedClusters() const
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.h:315
void removeSelfLoops(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tc)
Removes self-loop edges (edges where the source and the destination node are the same) ...
Definition: NBNodeCont.cpp:168
void addJoinExclusion(const std::vector< std::string > &ids, bool check=false)
Definition: NBNodeCont.cpp:450
unsigned int removeUnwishedNodes(NBDistrictCont &dc, NBEdgeCont &ec, NBJoinedEdgesMap &je, NBTrafficLightLogicCont &tlc, bool removeGeometryNodes)
Removes "unwished" nodes.
Definition: NBNodeCont.cpp:319
void markAsSplit(const NBNode *node)
mark a node as being created form a split
Definition: NBNodeCont.h:326
A container for traffic light definitions and built programs.
unsigned int joinJunctions(SUMOReal maxDist, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins junctions that are very close together.
Definition: NBNodeCont.cpp:508
std::vector< std::set< std::string > > myJoinedClusters
Definition: NBNodeCont.h:387
A RT-tree for efficient storing of SUMO&#39;s Named objects.
Definition: NamedRTree.h:72
A container for districts.
std::pair< NBNode *, SUMOReal > NodeAndDist
Definition: NBNodeCont.h:336
NamedRTree myRTree
node positions for faster lookup
Definition: NBNodeCont.h:396
void guessTLs(OptionsCont &oc, NBTrafficLightLogicCont &tlc)
Guesses which junctions or junction clusters shall be controlled by tls.
Definition: NBNodeCont.cpp:839
void avoidOverlap()
fix overlap
Definition: NBNodeCont.cpp:390
void computeLogics(const NBEdgeCont &ec, OptionsCont &oc)
build the list of outgoing edges and lanes
void generateNodeClusters(SUMOReal maxDist, NodeClusters &into) const
Builds node clusters.
Definition: NBNodeCont.cpp:398
A class representing a single district.
Definition: NBDistrict.h:72
unsigned int size() const
Returns the number of known nodes.
Definition: NBNodeCont.h:273
void computeLanes2Lanes()
divides the incoming lanes on outgoing lanes
~NBNodeCont()
Destructor.
Definition: NBNodeCont.cpp:73
void joinTLS(NBTrafficLightLogicCont &tlc, SUMOReal maxdist)
Builds clusters of tls-controlled junctions and joins the control if possible.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
int myInternalID
The running internal id.
Definition: NBNodeCont.h:370
NBNodeCont()
Constructor.
Definition: NBNodeCont.cpp:68
unsigned int joinLoadedClusters(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins loaded junction clusters (see NIXMLNodesHandler)
Definition: NBNodeCont.cpp:484
std::map< std::string, NBNode * > NodeCont
Definition of the map of names to nodes.
Definition: NBNodeCont.h:373
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
void joinNodeClusters(NodeClusters clusters, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Definition: NBNodeCont.cpp:693
std::set< NBNode * > myExtractedNodes
The extracted nodes which are kept for reference.
Definition: NBNodeCont.h:379
std::vector< std::string > getAllNames() const
get all node names
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:135
bool shouldBeTLSControlled(const std::set< NBNode * > &c) const
Returns whethe the given node cluster should be controlled by a tls.
Definition: NBNodeCont.cpp:811
void rename(NBNode *node, const std::string &newID)
Renames the node. Throws exception if newID already exists.
void setAsTLControlled(NBNode *node, NBTrafficLightLogicCont &tlc, TrafficLightType type, std::string id="")
Sets the given node as being controlled by a tls.
void addCluster2Join(std::set< std::string > cluster)
add ids of nodes which shall be joined into a single node
Definition: NBNodeCont.cpp:466
A structure storing information about which edges were joined.
void analyzeCluster(std::set< NBNode * > cluster, std::string &id, Position &pos, bool &hasTLS, TrafficLightType &type)
Definition: NBNodeCont.cpp:776
void removeIsolatedRoads(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tc)
Removes sequences of edges that are not connected with a junction. Simple roads without junctions som...
Definition: NBNodeCont.cpp:225
std::set< std::string > myJoined
ids found in loaded join clusters used for error checking
Definition: NBNodeCont.h:390
A storage for options typed value containers)
Definition: OptionsCont.h:108
std::vector< std::set< NBNode * > > NodeClusters
Definition of a node cluster container.
Definition: NBNodeCont.h:335
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:80
void clear()
std::vector< std::set< std::string > > myClusters2Join
Definition: NBNodeCont.h:385
void computeNodeShapes(SUMOReal mismatchThreshold=-1)
Compute the junction shape for this node.
void discardTrafficLights(NBTrafficLightLogicCont &tlc, bool geometryLike, bool guessSignals)
Represents a single node (junction) during network building.
Definition: NBNode.h:74
NBNodeCont & operator=(const NBNodeCont &s)
invalidated assignment operator
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:214
std::set< const NBNode * > mySplit
nodes that were created when splitting an edge
Definition: NBNodeCont.h:393
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:109
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:64
void printBuiltNodesStatistics() const
Prints statistics about built nodes.
bool extract(NBNode *node, bool remember=false)
Removes the given node but does not delete it.
Definition: NBNodeCont.cpp:150
bool erase(NBNode *node)
Removes the given node, deleting it.
Definition: NBNodeCont.cpp:139
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:127
TrafficLightType
void registerJoinedCluster(const std::set< NBNode * > &cluster)
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.cpp:766