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  int size() const {
255  return (int) myNodes.size();
256  }
257 
259  void clear();
260 
262  std::string getFreeID();
263 
267  void computeNodeShapes(double mismatchThreshold = -1);
268 
274  void printBuiltNodesStatistics() const;
275 
277  std::vector<std::string> getAllNames() const;
278 
279  /* @brief analyzes a cluster of nodes which shall be joined
280  * @param[in] cluster The nodes to be joined
281  * @param[out] id The name for the new node
282  * @param[out] pos The position of the new node
283  * @param[out] hasTLS Whether the new node has a traffic light
284  * @param[out] tlType The type of traffic light (if any)
285  */
286  void analyzeCluster(NodeSet cluster, std::string& id, Position& pos,
287  bool& hasTLS, TrafficLightType& type, SumoXMLNodeType& nodeType);
288 
290  void registerJoinedCluster(const NodeSet& cluster);
291 
293  const std::vector<std::set<std::string> >& getJoinedClusters() const {
294  return myJoinedClusters;
295  }
296 
297  /* @brief discards traffic lights
298  * @param[in] geometryLike Whether only tls at geometry-like nodes shall be discarded
299  */
300  void discardTrafficLights(NBTrafficLightLogicCont& tlc, bool geometryLike, bool guessSignals);
301 
302  /* @brief discards rail signals
303  */
304  void discardRailSignals();
305 
307  void markAsSplit(const NBNode* node) {
308  mySplit.insert(node);
309  }
310 
312  int remapIDs(bool numericaIDs, bool reservedIDs, const std::string& prefix);
313 
314 private:
315 
318 
325  void generateNodeClusters(double maxDist, NodeClusters& into) const;
326 
328  void joinNodeClusters(NodeClusters clusters, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc);
329 
331 
334 
338  bool shouldBeTLSControlled(const NodeSet& c) const;
340 
341 
342 private:
345 
347  typedef std::map<std::string, NBNode*> NodeCont;
348 
350  NodeCont myNodes;
351 
353  std::set<NBNode*> myExtractedNodes;
354 
356  std::set<std::string> myJoinExclusions;
357 
359  std::vector<std::set<std::string> > myClusters2Join;
360 
362  std::vector<std::set<std::string> > myJoinedClusters;
363 
365  std::set<std::string> myJoined;
366 
368  std::set<const NBNode*> mySplit;
369 
372 
373 private:
375  NBNodeCont(const NBNodeCont& s);
376 
378  NBNodeCont& operator=(const NBNodeCont& s);
379 
380 };
381 
382 
383 #endif
384 
385 /****************************************************************************/
386 
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:356
NodeCont myNodes
The map of names to nodes.
Definition: NBNodeCont.h:350
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:293
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:813
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:943
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:570
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:307
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:362
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:604
NamedRTree myRTree
node positions for faster lookup
Definition: NBNodeCont.h:371
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
bool shouldBeTLSControlled(const NodeSet &c) const
Returns whethe the given node cluster should be controlled by a tls.
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:628
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:254
NBEdge * shortestEdge(const NodeSet &cluster, const NodeSet &startNodes, const std::vector< NBNode *> &exclude) const
find closest neighbor for building circle
Definition: NBNodeCont.cpp:990
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
int myInternalID
The running internal id.
Definition: NBNodeCont.h:344
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:347
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:353
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:586
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:365
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:359
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:368
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:738
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