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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
19 // Container for nodes during the netbuilding process
20 /****************************************************************************/
21 #ifndef NBNodeCont_h
22 #define NBNodeCont_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #include <config.h>
29 
30 #include <string>
31 #include <map>
32 #include <vector>
33 #include <set>
35 #include <utils/geom/Position.h>
36 #include "NBEdgeCont.h"
37 #include "NBNode.h"
39 
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 class NBDistrict;
45 class OptionsCont;
46 class OutputDevice;
47 class NBParkingCont;
48 class NBPTLineCont;
49 class NBPTStopCont;
50 
51 
52 
53 // ===========================================================================
54 // class definitions
55 // ===========================================================================
60 class NBNodeCont {
61 public:
63  typedef std::set<NBNode*, ComparatorIdLess> NodeSet;
64  typedef std::vector<NodeSet> NodeClusters;
65  typedef std::pair<NBNode*, double> NodeAndDist;
66 
68  NBNodeCont();
69 
71  ~NBNodeCont();
72 
75 
81  bool insert(const std::string& id, const Position& position, NBDistrict* district = 0);
82 
87  bool insert(NBNode* node);
88 
93  bool erase(NBNode* node);
94 
100  bool extract(NBNode* node, bool remember = false);
101 
106  NBNode* retrieve(const std::string& id) const;
107 
113  NBNode* retrieve(const Position& position, const double offset = 0.) const;
114 
116  std::map<std::string, NBNode*>::const_iterator begin() const {
117  return myNodes.begin();
118  }
119 
121  std::map<std::string, NBNode*>::const_iterator end() const {
122  return myNodes.end();
123  }
125 
128  /* @brief add ids of nodes wich shall not be joined
129  * @param[in] ids A list of ids to exclude from joining
130  * @param[in] check Whether to check if these nodes are known
131  * @note checking is off by default because all nodes may not have been loaded yet
132  */
133  void addJoinExclusion(const std::vector<std::string>& ids, bool check = false);
134 
138  void addCluster2Join(std::set<std::string> cluster);
139 
142 
144  int joinJunctions(double maxDist, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc, NBPTStopCont& sc);
145 
147  void pruneClusterFringe(NodeSet& cluster) const;
148 
150  bool feasibleCluster(const NodeSet& cluster, const NBEdgeCont& ec, const NBPTStopCont& sc, std::string& reason) const;
151 
153  bool reduceToCircle(NodeSet& cluster, int circleSize, NodeSet startNodes, std::vector<NBNode*> cands = std::vector<NBNode*>()) const;
154 
156  NBEdge* shortestEdge(const NodeSet& cluster, const NodeSet& startNodes, const std::vector<NBNode*>& exclude) const;
158 
161 
168 
176 
178  void avoidOverlap();
179 
188 
196  void removeComponents(NBDistrictCont& dc, NBEdgeCont& ec, const int numKeep);
197 
213  NBPTStopCont& sc, NBPTLineCont& lc,
214  NBParkingCont& pc,
215  bool removeGeometryNodes);
217 
220 
226 
232  void joinTLS(NBTrafficLightLogicCont& tlc, double maxdist);
233 
241  void setAsTLControlled(NBNode* node, NBTrafficLightLogicCont& tlc, TrafficLightType type, std::string id = "");
243 
245  void rename(NBNode* node, const std::string& newID);
246 
248  void computeLanes2Lanes();
249 
251  void computeLogics(const NBEdgeCont& ec, OptionsCont& oc);
252 
254  void computeLogics2(const NBEdgeCont& ec, OptionsCont& oc);
255 
257  int size() const {
258  return (int) myNodes.size();
259  }
260 
262  void clear();
263 
265  std::string getFreeID();
266 
270  void computeNodeShapes(double mismatchThreshold = -1);
271 
277  void printBuiltNodesStatistics() const;
278 
280  std::vector<std::string> getAllNames() const;
281 
282  /* @brief analyzes a cluster of nodes which shall be joined
283  * @param[in] cluster The nodes to be joined
284  * @param[out] id The name for the new node
285  * @param[out] pos The position of the new node
286  * @param[out] hasTLS Whether the new node has a traffic light
287  * @param[out] tlType The type of traffic light (if any)
288  */
289  void analyzeCluster(NodeSet cluster, std::string& id, Position& pos,
290  bool& hasTLS, TrafficLightType& type, SumoXMLNodeType& nodeType);
291 
293  void registerJoinedCluster(const NodeSet& cluster);
294 
296  const std::vector<std::set<std::string> >& getJoinedClusters() const {
297  return myJoinedClusters;
298  }
299 
300  /* @brief discards traffic lights
301  * @param[in] geometryLike Whether only tls at geometry-like nodes shall be discarded
302  */
303  void discardTrafficLights(NBTrafficLightLogicCont& tlc, bool geometryLike, bool guessSignals);
304 
305  /* @brief discards rail signals
306  */
307  void discardRailSignals();
308 
310  void markAsSplit(const NBNode* node) {
311  mySplit.insert(node);
312  }
313 
315  int remapIDs(bool numericaIDs, bool reservedIDs, const std::string& prefix);
316 
317 private:
318 
321 
328  void generateNodeClusters(double maxDist, NodeClusters& into) const;
329 
331  void joinNodeClusters(NodeClusters clusters, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc);
332 
334 
337 
342  bool shouldBeTLSControlled(const NodeSet& c, double laneSpeedThreshold) const;
344 
345 
346 private:
349 
351  typedef std::map<std::string, NBNode*> NodeCont;
352 
354  NodeCont myNodes;
355 
357  std::set<NBNode*> myExtractedNodes;
358 
360  std::set<std::string> myJoinExclusions;
361 
363  std::vector<std::set<std::string> > myClusters2Join;
364 
366  std::vector<std::set<std::string> > myJoinedClusters;
367 
369  std::set<std::string> myJoined;
370 
372  std::set<const NBNode*> mySplit;
373 
376 
377 private:
379  NBNodeCont(const NBNodeCont& s);
380 
382  NBNodeCont& operator=(const NBNodeCont& s);
383 
384 };
385 
386 
387 #endif
388 
389 /****************************************************************************/
390 
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:360
NodeCont myNodes
The map of names to nodes.
Definition: NBNodeCont.h:354
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:296
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
bool feasibleCluster(const NodeSet &cluster, const NBEdgeCont &ec, const NBPTStopCont &sc, std::string &reason) const
determine wether the cluster is not too complex for joining
Definition: NBNodeCont.cpp:806
bool reduceToCircle(NodeSet &cluster, int circleSize, NodeSet startNodes, std::vector< NBNode *> cands=std::vector< NBNode *>()) const
try to find a joinable subset (recursively)
Definition: NBNodeCont.cpp:936
void computeLogics2(const NBEdgeCont &ec, OptionsCont &oc)
compute right-of-way logic for all lane-to-lane connections
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:116
void addJoinExclusion(const std::vector< std::string > &ids, bool check=false)
Definition: NBNodeCont.cpp:565
int removeUnwishedNodes(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, NBPTStopCont &sc, NBPTLineCont &lc, NBParkingCont &pc, bool removeGeometryNodes)
Removes "unwished" nodes.
Definition: NBNodeCont.cpp:370
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:121
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:310
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:366
The representation of a single edge during network building.
Definition: NBEdge.h:65
A RT-tree for efficient storing of SUMO&#39;s Named objects.
Definition: NamedRTree.h:65
A container for districts.
std::vector< NodeSet > NodeClusters
Definition: NBNodeCont.h:64
int joinLoadedClusters(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins loaded junction clusters (see NIXMLNodesHandler)
Definition: NBNodeCont.cpp:599
NamedRTree myRTree
node positions for faster lookup
Definition: NBNodeCont.h:375
void guessTLs(OptionsCont &oc, NBTrafficLightLogicCont &tlc)
Guesses which junctions or junction clusters shall be controlled by tls.
void avoidOverlap()
fix overlap
Definition: NBNodeCont.cpp:444
void discardRailSignals()
void computeLogics(const NBEdgeCont &ec, OptionsCont &oc)
build the list of outgoing edges and lanes
A class representing a single district.
Definition: NBDistrict.h:65
void registerJoinedCluster(const NodeSet &cluster)
gets all joined clusters (see doc for myClusters2Join)
int joinJunctions(double maxDist, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, NBPTStopCont &sc)
Joins junctions that are very close together.
Definition: NBNodeCont.cpp:623
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:257
NBEdge * shortestEdge(const NodeSet &cluster, const NodeSet &startNodes, const std::vector< NBNode *> &exclude) const
find closest neighbor for building circle
Definition: NBNodeCont.cpp:983
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
int myInternalID
The running internal id.
Definition: NBNodeCont.h:348
NBNodeCont()
Constructor.
Definition: NBNodeCont.cpp:67
std::pair< NBNode *, double > NodeAndDist
Definition: NBNodeCont.h:65
void generateNodeClusters(double maxDist, NodeClusters &into) const
Builds node clusters.
Definition: NBNodeCont.cpp:452
std::map< std::string, NBNode * > NodeCont
Definition of the map of names to nodes.
Definition: NBNodeCont.h:351
bool shouldBeTLSControlled(const NodeSet &c, double laneSpeedThreshold) const
Returns whethe the given node cluster should be controlled by a tls.
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:61
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
std::set< NBNode * > myExtractedNodes
The extracted nodes which are kept for reference.
Definition: NBNodeCont.h:357
int remapIDs(bool numericaIDs, bool reservedIDs, const std::string &prefix)
remap node IDs accoring to options –numerical-ids and –reserved-ids
void rename(NBNode *node, const std::string &newID)
Renames the node. Throws exception if newID already exists.
std::set< NBNode *, ComparatorIdLess > NodeSet
Definition of a node cluster container.
Definition: NBNodeCont.h:63
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:581
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
std::set< std::string > myJoined
ids found in loaded join clusters used for error checking
Definition: NBNodeCont.h:369
A storage for options typed value containers)
Definition: OptionsCont.h:92
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:363
void discardTrafficLights(NBTrafficLightLogicCont &tlc, bool geometryLike, bool guessSignals)
Represents a single node (junction) during network building.
Definition: NBNode.h:68
NBNodeCont & operator=(const NBNodeCont &s)
invalidated assignment operator
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
std::set< const NBNode * > mySplit
nodes that were created when splitting an edge
Definition: NBNodeCont.h:372
void printBuiltNodesStatistics() const
Prints statistics about built nodes.
void analyzeCluster(NodeSet cluster, std::string &id, Position &pos, bool &hasTLS, TrafficLightType &type, SumoXMLNodeType &nodeType)
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:60
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
void pruneClusterFringe(NodeSet &cluster) const
remove geometry-like fringe nodes from cluster
Definition: NBNodeCont.cpp:731
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