SUMO - Simulation of Urban MObility
NBNodeCont.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
21 // Container for nodes during the netbuilding process
22 /****************************************************************************/
23 #ifndef NBNodeCont_h
24 #define NBNodeCont_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <string>
37 #include <map>
38 #include <vector>
39 #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 NBParkingCont;
54 class NBPTLineCont;
55 class NBPTStopCont;
56 
57 
58 
59 // ===========================================================================
60 // class definitions
61 // ===========================================================================
66 class NBNodeCont {
67 public:
69  NBNodeCont();
70 
72  ~NBNodeCont();
73 
76 
82  bool insert(const std::string& id, const Position& position, NBDistrict* district = 0);
83 
88  bool insert(NBNode* node);
89 
94  bool erase(NBNode* node);
95 
101  bool extract(NBNode* node, bool remember = false);
102 
107  NBNode* retrieve(const std::string& id) const;
108 
114  NBNode* retrieve(const Position& position, const double offset = 0.) const;
115 
117  std::map<std::string, NBNode*>::const_iterator begin() const {
118  return myNodes.begin();
119  }
120 
122  std::map<std::string, NBNode*>::const_iterator end() const {
123  return myNodes.end();
124  }
126 
129  /* @brief add ids of nodes wich shall not be joined
130  * @param[in] ids A list of ids to exclude from joining
131  * @param[in] check Whether to check if these nodes are known
132  * @note checking is off by default because all nodes may not have been loaded yet
133  */
134  void addJoinExclusion(const std::vector<std::string>& ids, bool check = false);
135 
139  void addCluster2Join(std::set<std::string> cluster);
140 
143 
145  int joinJunctions(double maxDist, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc, NBPTStopCont& sc);
147 
150 
157 
165 
167  void avoidOverlap();
168 
177 
185  void removeComponents(NBDistrictCont& dc, NBEdgeCont& ec, const int numKeep);
186 
202  NBPTStopCont& sc, NBPTLineCont& lc,
203  NBParkingCont& pc,
204  bool removeGeometryNodes);
206 
209 
215 
221  void joinTLS(NBTrafficLightLogicCont& tlc, double maxdist);
222 
230  void setAsTLControlled(NBNode* node, NBTrafficLightLogicCont& tlc, TrafficLightType type, std::string id = "");
232 
234  void rename(NBNode* node, const std::string& newID);
235 
237  void computeLanes2Lanes();
238 
240  void computeLogics(const NBEdgeCont& ec, OptionsCont& oc);
241 
243  int size() const {
244  return (int) myNodes.size();
245  }
246 
248  void clear();
249 
251  std::string getFreeID();
252 
256  void computeNodeShapes(double mismatchThreshold = -1);
257 
263  void printBuiltNodesStatistics() const;
264 
266  std::vector<std::string> getAllNames() const;
267 
268  /* @brief analyzes a cluster of nodes which shall be joined
269  * @param[in] cluster The nodes to be joined
270  * @param[out] id The name for the new node
271  * @param[out] pos The position of the new node
272  * @param[out] hasTLS Whether the new node has a traffic light
273  * @param[out] tlType The type of traffic light (if any)
274  */
275  void analyzeCluster(std::set<NBNode*> cluster, std::string& id, Position& pos, bool& hasTLS, TrafficLightType& type);
276 
278  void registerJoinedCluster(const std::set<NBNode*>& cluster);
279 
281  const std::vector<std::set<std::string> >& getJoinedClusters() const {
282  return myJoinedClusters;
283  }
284 
285  /* @brief discards traffic lights
286  * @param[in] geometryLike Whether only tls at geometry-like nodes shall be discarded
287  */
288  void discardTrafficLights(NBTrafficLightLogicCont& tlc, bool geometryLike, bool guessSignals);
289 
291  void markAsSplit(const NBNode* node) {
292  mySplit.insert(node);
293  }
294 
296  int remapIDs(bool numericaIDs, bool reservedIDs);
297 
298 private:
300  typedef std::vector<std::set<NBNode*> > NodeClusters;
301  typedef std::pair<NBNode*, double> NodeAndDist;
302 
305 
312  void generateNodeClusters(double maxDist, NodeClusters& into) const;
313 
315  void joinNodeClusters(NodeClusters clusters, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc);
316 
318 
321 
325  bool shouldBeTLSControlled(const std::set<NBNode*>& c) const;
327 
328 
329 private:
332 
334  typedef std::map<std::string, NBNode*> NodeCont;
335 
337  NodeCont myNodes;
338 
340  std::set<NBNode*> myExtractedNodes;
341 
343  std::set<std::string> myJoinExclusions;
344 
346  std::vector<std::set<std::string> > myClusters2Join;
347 
349  std::vector<std::set<std::string> > myJoinedClusters;
350 
352  std::set<std::string> myJoined;
353 
355  std::set<const NBNode*> mySplit;
356 
359 
360 private:
362  NBNodeCont(const NBNodeCont& s);
363 
365  NBNodeCont& operator=(const NBNodeCont& s);
366 
367 };
368 
369 
370 #endif
371 
372 /****************************************************************************/
373 
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:343
NodeCont myNodes
The map of names to nodes.
Definition: NBNodeCont.h:337
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:108
void joinSimilarEdges(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins edges connecting the same nodes.
Definition: NBNodeCont.cpp:179
const std::vector< std::set< std::string > > & getJoinedClusters() const
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.h:281
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:167
void registerJoinedCluster(const std::set< NBNode *> &cluster)
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.cpp:837
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:117
void addJoinExclusion(const std::vector< std::string > &ids, bool check=false)
Definition: NBNodeCont.cpp:503
int removeUnwishedNodes(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, NBPTStopCont &sc, NBPTLineCont &lc, NBParkingCont &pc, bool removeGeometryNodes)
Removes "unwished" nodes.
Definition: NBNodeCont.cpp:369
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:122
void removeIsolatedRoads(NBDistrictCont &dc, NBEdgeCont &ec)
Removes sequences of edges that are not connected with a junction. Simple roads without junctions som...
Definition: NBNodeCont.cpp:224
void markAsSplit(const NBNode *node)
mark a node as being created form a split
Definition: NBNodeCont.h:291
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:349
A RT-tree for efficient storing of SUMO&#39;s Named objects.
Definition: NamedRTree.h:71
A container for districts.
int joinLoadedClusters(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins loaded junction clusters (see NIXMLNodesHandler)
Definition: NBNodeCont.cpp:537
NamedRTree myRTree
node positions for faster lookup
Definition: NBNodeCont.h:358
void guessTLs(OptionsCont &oc, NBTrafficLightLogicCont &tlc)
Guesses which junctions or junction clusters shall be controlled by tls.
Definition: NBNodeCont.cpp:910
void avoidOverlap()
fix overlap
Definition: NBNodeCont.cpp:443
void computeLogics(const NBEdgeCont &ec, OptionsCont &oc)
build the list of outgoing edges and lanes
A class representing a single district.
Definition: NBDistrict.h:71
int joinJunctions(double maxDist, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, NBPTStopCont &sc)
Joins junctions that are very close together.
Definition: NBNodeCont.cpp:561
bool shouldBeTLSControlled(const std::set< NBNode *> &c) const
Returns whethe the given node cluster should be controlled by a tls.
Definition: NBNodeCont.cpp:882
void computeLanes2Lanes()
divides the incoming lanes on outgoing lanes
~NBNodeCont()
Destructor.
Definition: NBNodeCont.cpp:72
int size() const
Returns the number of nodes stored in this container.
Definition: NBNodeCont.h:243
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
int myInternalID
The running internal id.
Definition: NBNodeCont.h:331
NBNodeCont()
Constructor.
Definition: NBNodeCont.cpp:67
std::pair< NBNode *, double > NodeAndDist
Definition: NBNodeCont.h:301
void generateNodeClusters(double maxDist, NodeClusters &into) const
Builds node clusters.
Definition: NBNodeCont.cpp:451
std::map< std::string, NBNode * > NodeCont
Definition of the map of names to nodes.
Definition: NBNodeCont.h:334
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:760
std::set< NBNode * > myExtractedNodes
The extracted nodes which are kept for reference.
Definition: NBNodeCont.h:340
void analyzeCluster(std::set< NBNode *> cluster, std::string &id, Position &pos, bool &hasTLS, TrafficLightType &type)
Definition: NBNodeCont.cpp:847
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:519
int remapIDs(bool numericaIDs, bool reservedIDs)
remap node IDs accoring to options –numerical-ids and –reserved-ids
std::set< std::string > myJoined
ids found in loaded join clusters used for error checking
Definition: NBNodeCont.h:352
A storage for options typed value containers)
Definition: OptionsCont.h:98
std::vector< std::set< NBNode * > > NodeClusters
Definition of a node cluster container.
Definition: NBNodeCont.h:300
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:79
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:346
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:70
std::set< const NBNode * > mySplit
nodes that were created when splitting an edge
Definition: NBNodeCont.h:355
void printBuiltNodesStatistics() const
Prints statistics about built nodes.
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:66
bool extract(NBNode *node, bool remember=false)
Removes the given node but does not delete it.
Definition: NBNodeCont.cpp:149
bool erase(NBNode *node)
Removes the given node, deleting it.
Definition: NBNodeCont.cpp:138
TrafficLightType
void removeComponents(NBDistrictCont &dc, NBEdgeCont &ec, const int numKeep)
Checks the network for weak connectivity and removes all but the largest components. The connectivity check is done regardless of edge direction and vclass.
Definition: NBNodeCont.cpp:312