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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
22 // Container for nodes during the netbuilding process
23 /****************************************************************************/
24 #pragma once
25 #include <config.h>
26 
27 #include <string>
28 #include <map>
29 #include <vector>
30 #include <set>
32 #include <utils/geom/Position.h>
33 #include "NBCont.h"
34 #include "NBEdgeCont.h"
35 #include "NBNode.h"
37 
38 
39 // ===========================================================================
40 // class declarations
41 // ===========================================================================
42 class NBDistrict;
43 class OptionsCont;
44 class OutputDevice;
45 class NBParkingCont;
46 class NBPTLineCont;
47 class NBPTStopCont;
48 
49 
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
58 class NBNodeCont {
59 public:
61  typedef std::vector<NodeSet> NodeClusters;
62  typedef std::pair<NBNode*, double> NodeAndDist;
63 
65  NBNodeCont();
66 
68  ~NBNodeCont();
69 
72 
78  bool insert(const std::string& id, const Position& position, NBDistrict* district = 0);
79 
84  bool insert(NBNode* node);
85 
90  bool erase(NBNode* node);
91 
97  bool extract(NBNode* node, bool remember = false);
98 
103  NBNode* retrieve(const std::string& id) const;
104 
110  NBNode* retrieve(const Position& position, const double offset = 0.) const;
111 
113  std::map<std::string, NBNode*>::const_iterator begin() const {
114  return myNodes.begin();
115  }
116 
118  std::map<std::string, NBNode*>::const_iterator end() const {
119  return myNodes.end();
120  }
122 
125  /* @brief add ids of nodes wich shall not be joined
126  * @param[in] ids A list of ids to exclude from joining
127  * @param[in] check Whether to check if these nodes are known
128  * @note checking is off by default because all nodes may not have been loaded yet
129  */
130  void addJoinExclusion(const std::vector<std::string>& ids, bool check = false);
131 
135  void addCluster2Join(std::set<std::string> cluster, NBNode* node);
136 
139 
141  int joinJunctions(double maxDist, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc, NBPTStopCont& sc);
142 
145 
147  void pruneClusterFringe(NodeSet& cluster) const;
148 
150  static void pruneLongEdges(NodeSet& cluster, double maxDist);
151 
153  void pruneSlipLaneNodes(NodeSet& cluster) const;
154 
156  static NodeSet getClusterNeighbors(const NBNode* n, NodeSet& cluster);
157 
159  bool maybeSlipLaneStart(const NBNode* n, EdgeVector& outgoing, double& inAngle) const;
161  bool maybeSlipLaneEnd(const NBNode* n, EdgeVector& incoming, double& outAngle) const;
162 
164  bool feasibleCluster(const NodeSet& cluster, const NBEdgeCont& ec, const NBPTStopCont& sc, std::string& reason) const;
165 
167  bool reduceToCircle(NodeSet& cluster, int circleSize, NodeSet startNodes, std::vector<NBNode*> cands = std::vector<NBNode*>()) const;
168 
170  NBEdge* shortestEdge(const NodeSet& cluster, const NodeSet& startNodes, const std::vector<NBNode*>& exclude) const;
172 
175 
182 
189  void joinSimilarEdges(NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc, bool removeDuplicates);
190 
192  void avoidOverlap();
193 
202 
210  void removeComponents(NBDistrictCont& dc, NBEdgeCont& ec, const int numKeep, bool hasPTStops);
211 
214 
233  bool removeGeometryNodes);
235 
238 
244 
247 
249  void computeKeepClear();
250 
256  void joinTLS(NBTrafficLightLogicCont& tlc, double maxdist);
257 
265  void setAsTLControlled(NBNode* node, NBTrafficLightLogicCont& tlc, TrafficLightType type, std::string id = "");
267 
270  bool wasRemoved(std::string id) const {
271  return myExtractedNodes.count(id) != 0;
272  }
273 
274 
276  void rename(NBNode* node, const std::string& newID);
277 
279  void computeLanes2Lanes();
280 
282  void computeLogics(const NBEdgeCont& ec);
283 
285  void computeLogics2(const NBEdgeCont& ec, OptionsCont& oc);
286 
288  int size() const {
289  return (int) myNodes.size();
290  }
291 
293  void clear();
294 
296  std::string getFreeID();
297 
301  void computeNodeShapes(double mismatchThreshold = -1);
302 
308  void printBuiltNodesStatistics() const;
309 
311  std::vector<std::string> getAllNames() const;
312 
313  /* @brief analyzes a cluster of nodes which shall be joined
314  * @param[in] cluster The nodes to be joined
315  * @param[out] id The name for the new node
316  * @param[out] pos The position of the new node
317  * @param[out] hasTLS Whether the new node has a traffic light
318  * @param[out] tlType The type of traffic light (if any)
319  */
320  void analyzeCluster(NodeSet cluster, std::string& id, Position& pos,
321  bool& hasTLS, TrafficLightType& type, SumoXMLNodeType& nodeType);
322 
324  void registerJoinedCluster(const NodeSet& cluster);
325 
327  const std::vector<std::set<std::string> >& getJoinedClusters() const {
328  return myJoinedClusters;
329  }
330 
331  /* @brief discards traffic lights
332  * @param[in] geometryLike Whether only tls at geometry-like nodes shall be discarded
333  */
334  void discardTrafficLights(NBTrafficLightLogicCont& tlc, bool geometryLike, bool guessSignals);
335 
336  /* @brief discards rail signals
337  */
338  void discardRailSignals();
339 
341  void markAsSplit(const NBNode* node) {
342  mySplit.insert(node);
343  }
344 
346  int remapIDs(bool numericaIDs, bool reservedIDs, const std::string& prefix);
347 
349  int guessFringe();
350 
351 private:
352 
355 
362  void generateNodeClusters(double maxDist, NodeClusters& into) const;
363 
365  void joinNodeClusters(NodeClusters clusters, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc, bool resetConnections = false);
367  NBNode* predefined = nullptr, bool resetConnections = false);
368 
370 
373 
378  bool shouldBeTLSControlled(const NodeSet& c, double laneSpeedThreshold) const;
379 
381  bool onlyCrossings(const NodeSet& c) const;
382 
384  bool customTLID(const NodeSet& c) const;
386 
388  void paretoCheck(NBNode* node, NodeSet& frontier, int xSign, int ySign);
389 
390 private:
393 
395  typedef std::map<std::string, NBNode*> NodeCont;
396 
399 
402 
404  std::set<std::string> myJoinExclusions;
405 
407  std::vector<std::pair<std::set<std::string>, NBNode*> > myClusters2Join;
408 
410  std::vector<std::set<std::string> > myJoinedClusters;
411 
413  std::set<std::string> myJoined;
414 
416  std::set<const NBNode*> mySplit;
417 
419  std::set<NBNode*> myGuessedTLS;
420 
423 
425  std::vector<std::vector<std::string> > myRailComponents;
426 
427 private:
430 
433 
434 };
std::set< NBNode *, ComparatorIdLess > NodeSet
Definition: NBCont.h:52
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:35
TrafficLightType
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
A container for districts.
A class representing a single district.
Definition: NBDistrict.h:62
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:59
The representation of a single edge during network building.
Definition: NBEdge.h:91
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:58
void clear()
deletes all nodes
std::set< std::string > myJoinExclusions
set of node ids which should not be joined
Definition: NBNodeCont.h:404
std::vector< std::vector< std::string > > myRailComponents
network components that must be removed if not connected to the road network via stop access
Definition: NBNodeCont.h:425
bool wasRemoved(std::string id) const
Returns whether the node with the id was deleted explicitly.
Definition: NBNodeCont.h:270
NamedRTree myRTree
node positions for faster lookup
Definition: NBNodeCont.h:422
void removeRailComponents(NBDistrictCont &dc, NBEdgeCont &ec, NBPTStopCont &sc)
remove rail components after ptstops are built
Definition: NBNodeCont.cpp:415
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:113
void avoidOverlap()
fix overlap
Definition: NBNodeCont.cpp:536
bool onlyCrossings(const NodeSet &c) const
check wheter the set of nodes only contains pedestrian crossings
std::vector< std::pair< std::set< std::string >, NBNode * > > myClusters2Join
loaded sets of node ids to join (cleared after use)
Definition: NBNodeCont.h:407
void addCluster2Join(std::set< std::string > cluster, NBNode *node)
add ids of nodes which shall be joined into a single node
Definition: NBNodeCont.cpp:673
int size() const
Returns the number of nodes stored in this container.
Definition: NBNodeCont.h:288
void recheckGuessedTLS(NBTrafficLightLogicCont &tlc)
recheck myGuessedTLS after node logics are computed
std::vector< NodeSet > NodeClusters
Definition of a node cluster container.
Definition: NBNodeCont.h:61
void computeKeepClear()
compute keepClear status for all connections
NodeCont myNodes
The map of names to nodes.
Definition: NBNodeCont.h:398
static void pruneLongEdges(NodeSet &cluster, double maxDist)
avoid removal of long edges when joinining junction clusters
Definition: NBNodeCont.cpp:965
void registerJoinedCluster(const NodeSet &cluster)
gets all joined clusters (see doc for myClusters2Join)
std::string getFreeID()
generates a new node ID
void addJoinExclusion(const std::vector< std::string > &ids, bool check=false)
Definition: NBNodeCont.cpp:657
void paretoCheck(NBNode *node, NodeSet &frontier, int xSign, int ySign)
update pareto frontier with the given node
bool maybeSlipLaneStart(const NBNode *n, EdgeVector &outgoing, double &inAngle) const
check whether the given node maybe the start of a slip lane
bool erase(NBNode *node)
Removes the given node, deleting it.
Definition: NBNodeCont.cpp:149
std::map< std::string, NBNode * > NodeCont
Definition of the map of names to nodes.
Definition: NBNodeCont.h:395
int joinLoadedClusters(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins loaded junction clusters (see NIXMLNodesHandler)
Definition: NBNodeCont.cpp:713
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:90
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:119
NodeCont myExtractedNodes
The extracted nodes which are kept for reference.
Definition: NBNodeCont.h:401
void joinTLS(NBTrafficLightLogicCont &tlc, double maxdist)
Builds clusters of tls-controlled junctions and joins the control if possible.
int removeUnwishedNodes(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, NBPTStopCont &sc, NBPTLineCont &lc, NBParkingCont &pc, bool removeGeometryNodes)
Removes "unwished" nodes.
Definition: NBNodeCont.cpp:456
~NBNodeCont()
Destructor.
Definition: NBNodeCont.cpp:83
bool reduceToCircle(NodeSet &cluster, int circleSize, NodeSet startNodes, std::vector< NBNode * > cands=std::vector< NBNode * >()) const
try to find a joinable subset (recursively)
bool extract(NBNode *node, bool remember=false)
Removes the given node but does not delete it.
Definition: NBNodeCont.cpp:160
NBNodeCont()
Constructor.
Definition: NBNodeCont.cpp:78
std::vector< std::string > getAllNames() const
get all node names
void computeLogics2(const NBEdgeCont &ec, OptionsCont &oc)
compute right-of-way logic for all lane-to-lane connections
void rename(NBNode *node, const std::string &newID)
Renames the node. Throws exception if newID already exists.
void joinSimilarEdges(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, bool removeDuplicates)
Joins edges connecting the same nodes.
Definition: NBNodeCont.cpp:190
void joinNodeClusters(NodeClusters clusters, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, bool resetConnections=false)
joins the given node clusters
void discardRailSignals()
NBNodeCont & operator=(const NBNodeCont &s)
invalidated assignment operator
void printBuiltNodesStatistics() const
Prints statistics about built nodes.
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:241
void setAsTLControlled(NBNode *node, NBTrafficLightLogicCont &tlc, TrafficLightType type, std::string id="")
Sets the given node as being controlled by a tls.
std::set< const NBNode * > mySplit
nodes that were created when splitting an edge
Definition: NBNodeCont.h:416
NBNodeCont(const NBNodeCont &s)
invalidated copy constructor
void computeLogics(const NBEdgeCont &ec)
build the list of outgoing edges and lanes
void joinNodeCluster(NodeSet clusters, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, NBNode *predefined=nullptr, bool resetConnections=false)
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:118
void generateNodeClusters(double maxDist, NodeClusters &into) const
Builds node clusters.
Definition: NBNodeCont.cpp:544
void computeNodeShapes(double mismatchThreshold=-1)
Compute the junction shape for this node.
std::vector< std::set< std::string > > myJoinedClusters
sets of node ids which were joined
Definition: NBNodeCont.h:410
void pruneClusterFringe(NodeSet &cluster) const
remove geometry-like fringe nodes from cluster
Definition: NBNodeCont.cpp:886
NBEdge * shortestEdge(const NodeSet &cluster, const NodeSet &startNodes, const std::vector< NBNode * > &exclude) const
find closest neighbor for building circle
std::pair< NBNode *, double > NodeAndDist
Definition: NBNodeCont.h:62
void guessTLs(OptionsCont &oc, NBTrafficLightLogicCont &tlc)
Guesses which junctions or junction clusters shall be controlled by tls.
int guessFringe()
guess and mark fringe nodes
std::set< NBNode * > myGuessedTLS
nodes that received a traffic light due to guessing (–tls.guess)
Definition: NBNodeCont.h:419
void markAsSplit(const NBNode *node)
mark a node as being created form a split
Definition: NBNodeCont.h:341
int joinJunctions(double maxDist, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, NBPTStopCont &sc)
Joins junctions that are very close together.
Definition: NBNodeCont.cpp:738
void computeLanes2Lanes()
divides the incoming lanes on outgoing lanes
void discardTrafficLights(NBTrafficLightLogicCont &tlc, bool geometryLike, bool guessSignals)
int myInternalID
The running internal id.
Definition: NBNodeCont.h:392
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
static NodeSet getClusterNeighbors(const NBNode *n, NodeSet &cluster)
return all cluster neighbors for the given node
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:178
std::set< std::string > myJoined
ids found in loaded join clusters used for error checking
Definition: NBNodeCont.h:413
bool shouldBeTLSControlled(const NodeSet &c, double laneSpeedThreshold) const
Returns whethe the given node cluster should be controlled by a tls.
int joinSameJunctions(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins junctions with the same coordinates regardless of topology.
Definition: NBNodeCont.cpp:856
void analyzeCluster(NodeSet cluster, std::string &id, Position &pos, bool &hasTLS, TrafficLightType &type, SumoXMLNodeType &nodeType)
bool customTLID(const NodeSet &c) const
check wheter the set of nodes contains traffic lights with custom id
int remapIDs(bool numericaIDs, bool reservedIDs, const std::string &prefix)
remap node IDs accoring to options –numerical-ids and –reserved-ids
bool maybeSlipLaneEnd(const NBNode *n, EdgeVector &incoming, double &outAngle) const
check whether the given node maybe the end of a slip lane
void removeComponents(NBDistrictCont &dc, NBEdgeCont &ec, const int numKeep, bool hasPTStops)
Checks the network for weak connectivity and removes all but the largest components....
Definition: NBNodeCont.cpp:329
void pruneSlipLaneNodes(NodeSet &cluster) const
remove nodes that form a slip lane from cluster
const std::vector< std::set< std::string > > & getJoinedClusters() const
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.h:327
Represents a single node (junction) during network building.
Definition: NBNode.h:66
A container for traffic light definitions and built programs.
A RT-tree for efficient storing of SUMO's Named objects.
Definition: NamedRTree.h:61
A storage for options typed value containers)
Definition: OptionsCont.h:89
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37