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-2016 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 
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 = 0);
85 
86 
91  bool insert(NBNode* node);
92 
93 
98  bool erase(NBNode* node);
99 
100 
106  bool extract(NBNode* node, bool remember = false);
107 
112  NBNode* retrieve(const std::string& id) const;
113 
114 
120  NBNode* retrieve(const Position& position, const SUMOReal offset = 0.) const;
121 
122 
126  std::map<std::string, NBNode*>::const_iterator begin() const {
127  return myNodes.begin();
128  }
129 
130 
134  std::map<std::string, NBNode*>::const_iterator end() const {
135  return myNodes.end();
136  }
138 
139 
140 
143 
144  /* @brief add ids of nodes wich shall not be joined
145  * @param[in] ids A list of ids to exclude from joining
146  * @param[in] check Whether to check if these nodes are known
147  * @note checking is off by default because all nodes may not have been loaded yet
148  */
149  void addJoinExclusion(const std::vector<std::string>& ids, bool check = false);
150 
151 
155  void addCluster2Join(std::set<std::string> cluster);
156 
157 
161 
162 
167 
168 
169 
172 
180 
181 
189 
190 
193  void avoidOverlap();
194 
195 
205 
206 
222  NBTrafficLightLogicCont& tlc, bool removeGeometryNodes);
224 
225 
226 
229 
236 
237 
243  void joinTLS(NBTrafficLightLogicCont& tlc, SUMOReal maxdist);
244 
245 
253  void setAsTLControlled(NBNode* node, NBTrafficLightLogicCont& tlc, TrafficLightType type, std::string id = "");
255 
256 
259  void rename(NBNode* node, const std::string& newID);
260 
261 
263  void computeLanes2Lanes();
264 
266  void computeLogics(const NBEdgeCont& ec, OptionsCont& oc);
267 
271  int size() const {
272  return (int) myNodes.size();
273  }
274 
276  void clear();
277 
278 
279 
280  std::string getFreeID();
281 
285  void computeNodeShapes(SUMOReal mismatchThreshold = -1);
286 
292  void printBuiltNodesStatistics() const;
293 
294 
296  std::vector<std::string> getAllNames() const;
297 
298 
299  /* @brief analyzes a cluster of nodes which shall be joined
300  * @param[in] cluster The nodes to be joined
301  * @param[out] id The name for the new node
302  * @param[out] pos The position of the new node
303  * @param[out] hasTLS Whether the new node has a traffic light
304  * @param[out] tlType The type of traffic light (if any)
305  */
306  void analyzeCluster(std::set<NBNode*> cluster, std::string& id, Position& pos,
307  bool& hasTLS, TrafficLightType& type);
308 
310  void registerJoinedCluster(const std::set<NBNode*>& cluster);
311 
313  const std::vector<std::set<std::string> >& getJoinedClusters() const {
314  return myJoinedClusters;
315  }
316 
317 
318  /* @brief discards traffic lights
319  * @param[in] geometryLike Whether only tls at geometry-like nodes shall be discarded
320  */
321  void discardTrafficLights(NBTrafficLightLogicCont& tlc, bool geometryLike, bool guessSignals);
322 
324  void markAsSplit(const NBNode* node) {
325  mySplit.insert(node);
326  }
327 
329  int mapToNumericalIDs();
330 
331 private:
334 
336  typedef std::vector<std::set<NBNode*> > NodeClusters;
337  typedef std::pair<NBNode*, SUMOReal> NodeAndDist;
338 
339 
347  void generateNodeClusters(SUMOReal maxDist, NodeClusters& into) const;
348 
349 
350  // @brief joins the given node clusters
351  void joinNodeClusters(NodeClusters clusters,
353 
355 
356 
357 
360 
365  bool shouldBeTLSControlled(const std::set<NBNode*>& c) const;
367 
368 
369 private:
372 
374  typedef std::map<std::string, NBNode*> NodeCont;
375 
377  NodeCont myNodes;
378 
380  std::set<NBNode*> myExtractedNodes;
381 
382  // @brief set of node ids which should not be joined
383  std::set<std::string> myJoinExclusions;
384 
385  // @brief loaded sets of node ids to join (cleared after use)
386  std::vector<std::set<std::string> > myClusters2Join;
387  // @brief sets of node ids which were joined
388  std::vector<std::set<std::string> > myJoinedClusters;
389 
391  std::set<std::string> myJoined;
392 
394  std::set<const NBNode*> mySplit;
395 
398 
399 private:
401  NBNodeCont(const NBNodeCont& s);
402 
404  NBNodeCont& operator=(const NBNodeCont& s);
405 
406 };
407 
408 
409 #endif
410 
411 /****************************************************************************/
412 
std::string getFreeID()
std::set< std::string > myJoinExclusions
Definition: NBNodeCont.h:383
NodeCont myNodes
The map of names to nodes.
Definition: NBNodeCont.h:377
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:110
void joinSimilarEdges(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins edges connecting the same nodes.
Definition: NBNodeCont.cpp:181
const std::vector< std::set< std::string > > & getJoinedClusters() const
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.h:313
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:169
void registerJoinedCluster(const std::set< NBNode *> &cluster)
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.cpp:766
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:126
void addJoinExclusion(const std::vector< std::string > &ids, bool check=false)
Definition: NBNodeCont.cpp:450
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:134
int removeUnwishedNodes(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, bool removeGeometryNodes)
Removes "unwished" nodes.
Definition: NBNodeCont.cpp:320
void markAsSplit(const NBNode *node)
mark a node as being created form a split
Definition: NBNodeCont.h:324
A container for traffic light definitions and built programs.
std::vector< std::set< std::string > > myJoinedClusters
Definition: NBNodeCont.h:388
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:337
int joinLoadedClusters(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins loaded junction clusters (see NIXMLNodesHandler)
Definition: NBNodeCont.cpp:484
NamedRTree myRTree
node positions for faster lookup
Definition: NBNodeCont.h:397
int mapToNumericalIDs()
ensure that all node ids are integers
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
A class representing a single district.
Definition: NBDistrict.h:72
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 computeLanes2Lanes()
divides the incoming lanes on outgoing lanes
int joinJunctions(SUMOReal maxDist, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins junctions that are very close together.
Definition: NBNodeCont.cpp:508
~NBNodeCont()
Destructor.
Definition: NBNodeCont.cpp:74
int size() const
Returns the number of known nodes.
Definition: NBNodeCont.h:271
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:371
NBNodeCont()
Constructor.
Definition: NBNodeCont.cpp:69
void generateNodeClusters(SUMOReal maxDist, NodeClusters &into) const
Builds node clusters.
Definition: NBNodeCont.cpp:398
std::map< std::string, NBNode * > NodeCont
Definition of the map of names to nodes.
Definition: NBNodeCont.h:374
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:380
void analyzeCluster(std::set< NBNode *> cluster, std::string &id, Position &pos, bool &hasTLS, TrafficLightType &type)
Definition: NBNodeCont.cpp:776
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.
std::vector< std::string > getAllNames() const
get all node names
void addCluster2Join(std::set< std::string > cluster)
add ids of nodes which shall be joined into a single node
Definition: NBNodeCont.cpp:466
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:226
std::set< std::string > myJoined
ids found in loaded join clusters used for error checking
Definition: NBNodeCont.h:391
A storage for options typed value containers)
Definition: OptionsCont.h:99
std::vector< std::set< NBNode * > > NodeClusters
Definition of a node cluster container.
Definition: NBNodeCont.h:336
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:81
void clear()
std::vector< std::set< std::string > > myClusters2Join
Definition: NBNodeCont.h:386
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:213
std::set< const NBNode * > mySplit
nodes that were created when splitting an edge
Definition: NBNodeCont.h:394
void printBuiltNodesStatistics() const
Prints statistics about built nodes.
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:63
bool extract(NBNode *node, bool remember=false)
Removes the given node but does not delete it.
Definition: NBNodeCont.cpp:151
bool erase(NBNode *node)
Removes the given node, deleting it.
Definition: NBNodeCont.cpp:140
TrafficLightType