Eclipse 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-2019 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, NBNode* node);
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 
246  bool wasRemoved(std::string id) const {
247  return myExtractedNodes.count(id) != 0;
248  }
249 
250 
252  void rename(NBNode* node, const std::string& newID);
253 
255  void computeLanes2Lanes();
256 
258  void computeLogics(const NBEdgeCont& ec, OptionsCont& oc);
259 
261  void computeLogics2(const NBEdgeCont& ec, OptionsCont& oc);
262 
264  int size() const {
265  return (int) myNodes.size();
266  }
267 
269  void clear();
270 
272  std::string getFreeID();
273 
277  void computeNodeShapes(double mismatchThreshold = -1);
278 
284  void printBuiltNodesStatistics() const;
285 
287  std::vector<std::string> getAllNames() const;
288 
289  /* @brief analyzes a cluster of nodes which shall be joined
290  * @param[in] cluster The nodes to be joined
291  * @param[out] id The name for the new node
292  * @param[out] pos The position of the new node
293  * @param[out] hasTLS Whether the new node has a traffic light
294  * @param[out] tlType The type of traffic light (if any)
295  */
296  void analyzeCluster(NodeSet cluster, std::string& id, Position& pos,
297  bool& hasTLS, TrafficLightType& type, SumoXMLNodeType& nodeType);
298 
300  void registerJoinedCluster(const NodeSet& cluster);
301 
303  const std::vector<std::set<std::string> >& getJoinedClusters() const {
304  return myJoinedClusters;
305  }
306 
307  /* @brief discards traffic lights
308  * @param[in] geometryLike Whether only tls at geometry-like nodes shall be discarded
309  */
310  void discardTrafficLights(NBTrafficLightLogicCont& tlc, bool geometryLike, bool guessSignals);
311 
312  /* @brief discards rail signals
313  */
314  void discardRailSignals();
315 
317  void markAsSplit(const NBNode* node) {
318  mySplit.insert(node);
319  }
320 
322  int remapIDs(bool numericaIDs, bool reservedIDs, const std::string& prefix);
323 
324 private:
325 
328 
335  void generateNodeClusters(double maxDist, NodeClusters& into) const;
336 
339  void joinNodeCluster(NodeSet clusters, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc, NBNode* predefined = nullptr);
340 
342 
345 
350  bool shouldBeTLSControlled(const NodeSet& c, double laneSpeedThreshold) const;
351 
353  bool onlyCrossings(const NodeSet& c) const;
354 
356  bool customTLID(const NodeSet& c) const;
358 
359 
360 private:
363 
365  typedef std::map<std::string, NBNode*> NodeCont;
366 
369 
372 
374  std::set<std::string> myJoinExclusions;
375 
377  std::vector<std::pair<std::set<std::string>, NBNode*> > myClusters2Join;
378 
380  std::vector<std::set<std::string> > myJoinedClusters;
381 
383  std::set<std::string> myJoined;
384 
386  std::set<const NBNode*> mySplit;
387 
390 
391 private:
393  NBNodeCont(const NBNodeCont& s);
394 
396  NBNodeCont& operator=(const NBNodeCont& s);
397 
398 };
399 
400 
401 #endif
402 
403 /****************************************************************************/
404 
NBNodeCont::myJoinedClusters
std::vector< std::set< std::string > > myJoinedClusters
sets of node ids which were joined
Definition: NBNodeCont.h:380
NBNodeCont::removeUnwishedNodes
int removeUnwishedNodes(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, NBPTStopCont &sc, NBPTLineCont &lc, NBParkingCont &pc, bool removeGeometryNodes)
Removes "unwished" nodes.
Definition: NBNodeCont.cpp:370
NBNodeCont::myJoinExclusions
std::set< std::string > myJoinExclusions
set of node ids which should not be joined
Definition: NBNodeCont.h:374
NBNodeCont::getFreeID
std::string getFreeID()
generates a new node ID
Definition: NBNodeCont.cpp:1699
NBNodeCont::computeNodeShapes
void computeNodeShapes(double mismatchThreshold=-1)
Compute the junction shape for this node.
Definition: NBNodeCont.cpp:1713
NBPTStopCont
Definition: NBPTStopCont.h:28
NBEdgeCont
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:61
NBNodeCont::rename
void rename(NBNode *node, const std::string &newID)
Renames the node. Throws exception if newID already exists.
Definition: NBNodeCont.cpp:1813
NBNodeCont::setAsTLControlled
void setAsTLControlled(NBNode *node, NBTrafficLightLogicCont &tlc, TrafficLightType type, std::string id="")
Sets the given node as being controlled by a tls.
Definition: NBNodeCont.cpp:1632
NBNodeCont::computeLanes2Lanes
void computeLanes2Lanes()
divides the incoming lanes on outgoing lanes
Definition: NBNodeCont.cpp:1649
NBNodeCont::myNodes
NodeCont myNodes
The map of names to nodes.
Definition: NBNodeCont.h:368
NBTrafficLightLogicCont
A container for traffic light definitions and built programs.
Definition: NBTrafficLightLogicCont.h:58
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
NBNodeCont::end
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:121
NBNodeCont::markAsSplit
void markAsSplit(const NBNode *node)
mark a node as being created form a split
Definition: NBNodeCont.h:317
NBNodeCont::guessTLs
void guessTLs(OptionsCont &oc, NBTrafficLightLogicCont &tlc)
Guesses which junctions or junction clusters shall be controlled by tls.
Definition: NBNodeCont.cpp:1390
NBNodeCont::myJoined
std::set< std::string > myJoined
ids found in loaded join clusters used for error checking
Definition: NBNodeCont.h:383
NBNodeCont::operator=
NBNodeCont & operator=(const NBNodeCont &s)
invalidated assignment operator
NBNodeCont::onlyCrossings
bool onlyCrossings(const NodeSet &c) const
check wheter the set of nodes only contains pedestrian crossings
Definition: NBNodeCont.cpp:1343
NBNodeCont::insert
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:79
NBNodeCont::getAllNames
std::vector< std::string > getAllNames() const
get all node names
Definition: NBNodeCont.cpp:1803
NBNodeCont::NodeAndDist
std::pair< NBNode *, double > NodeAndDist
Definition: NBNodeCont.h:65
TrafficLightType
TrafficLightType
Definition: SUMOXMLDefinitions.h:1192
NBEdgeCont.h
NBNodeCont::begin
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:116
NBNodeCont::removeComponents
void removeComponents(NBDistrictCont &dc, NBEdgeCont &ec, const int numKeep)
Checks the network for weak connectivity and removes all but the largest components....
Definition: NBNodeCont.cpp:312
NBNodeCont::avoidOverlap
void avoidOverlap()
fix overlap
Definition: NBNodeCont.cpp:444
NBNodeCont::addCluster2Join
void addCluster2Join(std::set< std::string > cluster, NBNode *node)
add ids of nodes which shall be joined into a single node
Definition: NBNodeCont.cpp:581
NamedRTree.h
NBNodeCont::pruneClusterFringe
void pruneClusterFringe(NodeSet &cluster) const
remove geometry-like fringe nodes from cluster
Definition: NBNodeCont.cpp:754
NBNodeCont::remapIDs
int remapIDs(bool numericaIDs, bool reservedIDs, const std::string &prefix)
remap node IDs accoring to options –numerical-ids and –reserved-ids
Definition: NBNodeCont.cpp:1865
NBDistrictCont
A container for districts.
Definition: NBDistrictCont.h:53
NBNodeCont
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:60
NBNodeCont::erase
bool erase(NBNode *node)
Removes the given node, deleting it.
Definition: NBNodeCont.cpp:138
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:86
NBNodeCont::analyzeCluster
void analyzeCluster(NodeSet cluster, std::string &id, Position &pos, bool &hasTLS, TrafficLightType &type, SumoXMLNodeType &nodeType)
Definition: NBNodeCont.cpp:1273
NBNodeCont::computeLogics
void computeLogics(const NBEdgeCont &ec, OptionsCont &oc)
build the list of outgoing edges and lanes
Definition: NBNodeCont.cpp:1658
NBNodeCont::myInternalID
int myInternalID
The running internal id.
Definition: NBNodeCont.h:362
NBPTLineCont
Definition: NBPTLineCont.h:27
NBNodeCont::removeIsolatedRoads
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
NBNodeCont::removeSelfLoops
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
NBNodeCont::joinSimilarEdges
void joinSimilarEdges(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins edges connecting the same nodes.
Definition: NBNodeCont.cpp:179
NBNodeCont::feasibleCluster
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:832
SumoXMLNodeType
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
Definition: SUMOXMLDefinitions.h:1049
NBNodeCont::joinNodeClusters
void joinNodeClusters(NodeClusters clusters, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
joins the given node clusters
Definition: NBNodeCont.cpp:1083
NBNodeCont::NodeSet
std::set< NBNode *, ComparatorIdLess > NodeSet
Definition of a node cluster container.
Definition: NBNodeCont.h:63
NBNodeCont::printBuiltNodesStatistics
void printBuiltNodesStatistics() const
Prints statistics about built nodes.
Definition: NBNodeCont.cpp:1721
NBNodeCont::myClusters2Join
std::vector< std::pair< std::set< std::string >, NBNode * > > myClusters2Join
loaded sets of node ids to join (cleared after use)
Definition: NBNodeCont.h:377
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
UtilExceptions.h
NBParkingCont
Definition: NBParking.h:63
NBNodeCont::addJoinExclusion
void addJoinExclusion(const std::vector< std::string > &ids, bool check=false)
Definition: NBNodeCont.cpp:565
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:90
NBNodeCont::joinTLS
void joinTLS(NBTrafficLightLogicCont &tlc, double maxdist)
Builds clusters of tls-controlled junctions and joins the control if possible.
Definition: NBNodeCont.cpp:1583
NBNodeCont::shortestEdge
NBEdge * shortestEdge(const NodeSet &cluster, const NodeSet &startNodes, const std::vector< NBNode * > &exclude) const
find closest neighbor for building circle
Definition: NBNodeCont.cpp:1062
NBNodeCont::mySplit
std::set< const NBNode * > mySplit
nodes that were created when splitting an edge
Definition: NBNodeCont.h:386
NBNodeCont::getJoinedClusters
const std::vector< std::set< std::string > > & getJoinedClusters() const
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.h:303
NBNodeCont::retrieve
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:108
NBNodeCont::NBNodeCont
NBNodeCont()
Constructor.
Definition: NBNodeCont.cpp:67
NBNodeCont::wasRemoved
bool wasRemoved(std::string id) const
Returns whether the node with the id was deleted explicitly.
Definition: NBNodeCont.h:246
Position.h
NBNodeCont::NodeCont
std::map< std::string, NBNode * > NodeCont
Definition of the map of names to nodes.
Definition: NBNodeCont.h:365
NBNodeCont::customTLID
bool customTLID(const NodeSet &c) const
check wheter the set of nodes contains traffic lights with custom id
Definition: NBNodeCont.cpp:1373
NBNodeCont::clear
void clear()
deletes all nodes
Definition: NBNodeCont.cpp:1686
NBNodeCont::shouldBeTLSControlled
bool shouldBeTLSControlled(const NodeSet &c, double laneSpeedThreshold) const
Returns whethe the given node cluster should be controlled by a tls.
Definition: NBNodeCont.cpp:1315
NBNodeCont::myRTree
NamedRTree myRTree
node positions for faster lookup
Definition: NBNodeCont.h:389
NBNodeCont::size
int size() const
Returns the number of nodes stored in this container.
Definition: NBNodeCont.h:264
NBNodeCont::registerJoinedCluster
void registerJoinedCluster(const NodeSet &cluster)
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.cpp:1263
NBNodeCont::~NBNodeCont
~NBNodeCont()
Destructor.
Definition: NBNodeCont.cpp:72
NamedRTree
A RT-tree for efficient storing of SUMO's Named objects.
Definition: NamedRTree.h:64
NBNodeCont::extract
bool extract(NBNode *node, bool remember=false)
Removes the given node but does not delete it.
Definition: NBNodeCont.cpp:149
config.h
NBNodeCont::joinNodeCluster
void joinNodeCluster(NodeSet clusters, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, NBNode *predefined=nullptr)
Definition: NBNodeCont.cpp:1092
NBNodeCont::joinLoadedClusters
int joinLoadedClusters(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins loaded junction clusters (see NIXMLNodesHandler)
Definition: NBNodeCont.cpp:621
NBNodeCont::discardRailSignals
void discardRailSignals()
Definition: NBNodeCont.cpp:1854
NBNodeCont::generateNodeClusters
void generateNodeClusters(double maxDist, NodeClusters &into) const
Builds node clusters.
Definition: NBNodeCont.cpp:452
NBNodeCont::joinJunctions
int joinJunctions(double maxDist, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, NBPTStopCont &sc)
Joins junctions that are very close together.
Definition: NBNodeCont.cpp:646
NBNodeCont::myExtractedNodes
NodeCont myExtractedNodes
The extracted nodes which are kept for reference.
Definition: NBNodeCont.h:371
NBNode
Represents a single node (junction) during network building.
Definition: NBNode.h:68
NBNodeCont::NodeClusters
std::vector< NodeSet > NodeClusters
Definition: NBNodeCont.h:64
NBNodeCont::discardTrafficLights
void discardTrafficLights(NBTrafficLightLogicCont &tlc, bool geometryLike, bool guessSignals)
Definition: NBNodeCont.cpp:1824
NBNode.h
NBDistrict
A class representing a single district.
Definition: NBDistrict.h:65
NBNodeCont::reduceToCircle
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:1015
NBNodeCont::computeLogics2
void computeLogics2(const NBEdgeCont &ec, OptionsCont &oc)
compute right-of-way logic for all lane-to-lane connections
Definition: NBNodeCont.cpp:1666