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-2017 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 
69  ~NBNodeCont();
70 
73 
79  bool insert(const std::string& id, const Position& position, NBDistrict* district = 0);
80 
85  bool insert(NBNode* node);
86 
91  bool erase(NBNode* node);
92 
98  bool extract(NBNode* node, bool remember = false);
99 
104  NBNode* retrieve(const std::string& id) const;
105 
111  NBNode* retrieve(const Position& position, const double offset = 0.) const;
112 
114  std::map<std::string, NBNode*>::const_iterator begin() const {
115  return myNodes.begin();
116  }
117 
119  std::map<std::string, NBNode*>::const_iterator end() const {
120  return myNodes.end();
121  }
123 
126  /* @brief add ids of nodes wich shall not be joined
127  * @param[in] ids A list of ids to exclude from joining
128  * @param[in] check Whether to check if these nodes are known
129  * @note checking is off by default because all nodes may not have been loaded yet
130  */
131  void addJoinExclusion(const std::vector<std::string>& ids, bool check = false);
132 
136  void addCluster2Join(std::set<std::string> cluster);
137 
140 
142  int joinJunctions(double maxDist, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc);
144 
147 
154 
162 
164  void avoidOverlap();
165 
175 
190  int removeUnwishedNodes(NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc, bool removeGeometryNodes);
192 
195 
201 
207  void joinTLS(NBTrafficLightLogicCont& tlc, double maxdist);
208 
216  void setAsTLControlled(NBNode* node, NBTrafficLightLogicCont& tlc, TrafficLightType type, std::string id = "");
218 
220  void rename(NBNode* node, const std::string& newID);
221 
223  void computeLanes2Lanes();
224 
226  void computeLogics(const NBEdgeCont& ec, OptionsCont& oc);
227 
229  int size() const {
230  return (int) myNodes.size();
231  }
232 
234  void clear();
235 
237  std::string getFreeID();
238 
242  void computeNodeShapes(double mismatchThreshold = -1);
243 
249  void printBuiltNodesStatistics() const;
250 
252  std::vector<std::string> getAllNames() const;
253 
254  /* @brief analyzes a cluster of nodes which shall be joined
255  * @param[in] cluster The nodes to be joined
256  * @param[out] id The name for the new node
257  * @param[out] pos The position of the new node
258  * @param[out] hasTLS Whether the new node has a traffic light
259  * @param[out] tlType The type of traffic light (if any)
260  */
261  void analyzeCluster(std::set<NBNode*> cluster, std::string& id, Position& pos, bool& hasTLS, TrafficLightType& type);
262 
264  void registerJoinedCluster(const std::set<NBNode*>& cluster);
265 
267  const std::vector<std::set<std::string> >& getJoinedClusters() const {
268  return myJoinedClusters;
269  }
270 
271  /* @brief discards traffic lights
272  * @param[in] geometryLike Whether only tls at geometry-like nodes shall be discarded
273  */
274  void discardTrafficLights(NBTrafficLightLogicCont& tlc, bool geometryLike, bool guessSignals);
275 
277  void markAsSplit(const NBNode* node) {
278  mySplit.insert(node);
279  }
280 
282  int remapIDs(bool numericaIDs, bool reservedIDs);
283 
284 private:
286  typedef std::vector<std::set<NBNode*> > NodeClusters;
287  typedef std::pair<NBNode*, double> NodeAndDist;
288 
291 
298  void generateNodeClusters(double maxDist, NodeClusters& into) const;
299 
301  void joinNodeClusters(NodeClusters clusters, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc);
302 
304 
307 
311  bool shouldBeTLSControlled(const std::set<NBNode*>& c) const;
313 
314 
315 private:
318 
320  typedef std::map<std::string, NBNode*> NodeCont;
321 
323  NodeCont myNodes;
324 
326  std::set<NBNode*> myExtractedNodes;
327 
329  std::set<std::string> myJoinExclusions;
330 
332  std::vector<std::set<std::string> > myClusters2Join;
333 
335  std::vector<std::set<std::string> > myJoinedClusters;
336 
338  std::set<std::string> myJoined;
339 
341  std::set<const NBNode*> mySplit;
342 
345 
346 private:
348  NBNodeCont(const NBNodeCont& s);
349 
351  NBNodeCont& operator=(const NBNodeCont& s);
352 
353 };
354 
355 
356 #endif
357 
358 /****************************************************************************/
359 
std::string getFreeID()
generates a new node ID
std::set< std::string > myJoinExclusions
set of node ids which should not be joined
Definition: NBNodeCont.h:329
NodeCont myNodes
The map of names to nodes.
Definition: NBNodeCont.h:323
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:106
void joinSimilarEdges(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins edges connecting the same nodes.
Definition: NBNodeCont.cpp:177
const std::vector< std::set< std::string > > & getJoinedClusters() const
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.h:267
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:165
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:114
void addJoinExclusion(const std::vector< std::string > &ids, bool check=false)
Definition: NBNodeCont.cpp:446
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:119
int removeUnwishedNodes(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, bool removeGeometryNodes)
Removes "unwished" nodes.
Definition: NBNodeCont.cpp:316
void markAsSplit(const NBNode *node)
mark a node as being created form a split
Definition: NBNodeCont.h:277
A container for traffic light definitions and built programs.
void joinTLS(NBTrafficLightLogicCont &tlc, double maxdist)
Builds clusters of tls-controlled junctions and joins the control if possible.
std::vector< std::set< std::string > > myJoinedClusters
sets of node ids which were joined
Definition: NBNodeCont.h:335
A RT-tree for efficient storing of SUMO&#39;s Named objects.
Definition: NamedRTree.h:72
A container for districts.
int joinLoadedClusters(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins loaded junction clusters (see NIXMLNodesHandler)
Definition: NBNodeCont.cpp:480
NamedRTree myRTree
node positions for faster lookup
Definition: NBNodeCont.h:344
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:386
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
~NBNodeCont()
Destructor.
Definition: NBNodeCont.cpp:70
int size() const
Returns the number of nodes stored in this container.
Definition: NBNodeCont.h:229
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
int myInternalID
The running internal id.
Definition: NBNodeCont.h:317
NBNodeCont()
Constructor.
Definition: NBNodeCont.cpp:65
std::pair< NBNode *, double > NodeAndDist
Definition: NBNodeCont.h:287
void generateNodeClusters(double maxDist, NodeClusters &into) const
Builds node clusters.
Definition: NBNodeCont.cpp:394
std::map< std::string, NBNode * > NodeCont
Definition of the map of names to nodes.
Definition: NBNodeCont.h:320
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
void computeNodeShapes(double mismatchThreshold=-1)
Compute the junction shape for this node.
void joinNodeClusters(NodeClusters clusters, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
joins the given node clusters
Definition: NBNodeCont.cpp:689
std::set< NBNode * > myExtractedNodes
The extracted nodes which are kept for reference.
Definition: NBNodeCont.h:326
int joinJunctions(double maxDist, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins junctions that are very close together.
Definition: NBNodeCont.cpp:504
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:462
int remapIDs(bool numericaIDs, bool reservedIDs)
remap node IDs accoring to options –numerical-ids and –reserved-ids
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:222
std::set< std::string > myJoined
ids found in loaded join clusters used for error checking
Definition: NBNodeCont.h:338
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:286
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:77
void clear()
deletes all nodes
std::vector< std::set< std::string > > myClusters2Join
loaded sets of node ids to join (cleared after use)
Definition: NBNodeCont.h:332
void discardTrafficLights(NBTrafficLightLogicCont &tlc, bool geometryLike, bool guessSignals)
Represents a single node (junction) during network building.
Definition: NBNode.h:75
NBNodeCont & operator=(const NBNodeCont &s)
invalidated assignment operator
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
std::set< const NBNode * > mySplit
nodes that were created when splitting an edge
Definition: NBNodeCont.h:341
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:147
bool erase(NBNode *node)
Removes the given node, deleting it.
Definition: NBNodeCont.cpp:136
TrafficLightType