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 /****************************************************************************/
18 // Container for nodes during the netbuilding process
19 /****************************************************************************/
20 #ifndef NBNodeCont_h
21 #define NBNodeCont_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <string>
30 #include <map>
31 #include <vector>
32 #include <set>
34 #include <utils/geom/Position.h>
35 #include "NBEdgeCont.h"
36 #include "NBNode.h"
38 
39 
40 // ===========================================================================
41 // class declarations
42 // ===========================================================================
43 class NBDistrict;
44 class OptionsCont;
45 class OutputDevice;
46 class NBParkingCont;
47 class NBPTLineCont;
48 class NBPTStopCont;
49 
50 
51 
52 // ===========================================================================
53 // class definitions
54 // ===========================================================================
59 class NBNodeCont {
60 public:
62  typedef std::set<NBNode*, ComparatorIdLess> NodeSet;
63  typedef std::vector<NodeSet> NodeClusters;
64  typedef std::pair<NBNode*, double> NodeAndDist;
65 
67  NBNodeCont();
68 
70  ~NBNodeCont();
71 
74 
80  bool insert(const std::string& id, const Position& position, NBDistrict* district = 0);
81 
86  bool insert(NBNode* node);
87 
92  bool erase(NBNode* node);
93 
99  bool extract(NBNode* node, bool remember = false);
100 
105  NBNode* retrieve(const std::string& id) const;
106 
112  NBNode* retrieve(const Position& position, const double offset = 0.) const;
113 
115  std::map<std::string, NBNode*>::const_iterator begin() const {
116  return myNodes.begin();
117  }
118 
120  std::map<std::string, NBNode*>::const_iterator end() const {
121  return myNodes.end();
122  }
124 
127  /* @brief add ids of nodes wich shall not be joined
128  * @param[in] ids A list of ids to exclude from joining
129  * @param[in] check Whether to check if these nodes are known
130  * @note checking is off by default because all nodes may not have been loaded yet
131  */
132  void addJoinExclusion(const std::vector<std::string>& ids, bool check = false);
133 
137  void addCluster2Join(std::set<std::string> cluster, NBNode* node);
138 
141 
143  int joinJunctions(double maxDist, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc, NBPTStopCont& sc);
144 
146  void pruneClusterFringe(NodeSet& cluster) const;
147 
149  bool feasibleCluster(const NodeSet& cluster, const NBEdgeCont& ec, const NBPTStopCont& sc, std::string& reason) const;
150 
152  bool reduceToCircle(NodeSet& cluster, int circleSize, NodeSet startNodes, std::vector<NBNode*> cands = std::vector<NBNode*>()) const;
153 
155  NBEdge* shortestEdge(const NodeSet& cluster, const NodeSet& startNodes, const std::vector<NBNode*>& exclude) const;
157 
160 
167 
175 
177  void avoidOverlap();
178 
187 
195  void removeComponents(NBDistrictCont& dc, NBEdgeCont& ec, const int numKeep);
196 
212  NBPTStopCont& sc, NBPTLineCont& lc,
213  NBParkingCont& pc,
214  bool removeGeometryNodes);
216 
219 
225 
231  void joinTLS(NBTrafficLightLogicCont& tlc, double maxdist);
232 
240  void setAsTLControlled(NBNode* node, NBTrafficLightLogicCont& tlc, TrafficLightType type, std::string id = "");
242 
245  bool wasRemoved(std::string id) const {
246  return myExtractedNodes.count(id) != 0;
247  }
248 
249 
251  void rename(NBNode* node, const std::string& newID);
252 
254  void computeLanes2Lanes();
255 
257  void computeLogics(const NBEdgeCont& ec);
258 
260  void computeLogics2(const NBEdgeCont& ec, OptionsCont& oc);
261 
263  int size() const {
264  return (int) myNodes.size();
265  }
266 
268  void clear();
269 
271  std::string getFreeID();
272 
276  void computeNodeShapes(double mismatchThreshold = -1);
277 
283  void printBuiltNodesStatistics() const;
284 
286  std::vector<std::string> getAllNames() const;
287 
288  /* @brief analyzes a cluster of nodes which shall be joined
289  * @param[in] cluster The nodes to be joined
290  * @param[out] id The name for the new node
291  * @param[out] pos The position of the new node
292  * @param[out] hasTLS Whether the new node has a traffic light
293  * @param[out] tlType The type of traffic light (if any)
294  */
295  void analyzeCluster(NodeSet cluster, std::string& id, Position& pos,
296  bool& hasTLS, TrafficLightType& type, SumoXMLNodeType& nodeType);
297 
299  void registerJoinedCluster(const NodeSet& cluster);
300 
302  const std::vector<std::set<std::string> >& getJoinedClusters() const {
303  return myJoinedClusters;
304  }
305 
306  /* @brief discards traffic lights
307  * @param[in] geometryLike Whether only tls at geometry-like nodes shall be discarded
308  */
309  void discardTrafficLights(NBTrafficLightLogicCont& tlc, bool geometryLike, bool guessSignals);
310 
311  /* @brief discards rail signals
312  */
313  void discardRailSignals();
314 
316  void markAsSplit(const NBNode* node) {
317  mySplit.insert(node);
318  }
319 
321  int remapIDs(bool numericaIDs, bool reservedIDs, const std::string& prefix);
322 
323 private:
324 
327 
334  void generateNodeClusters(double maxDist, NodeClusters& into) const;
335 
338  void joinNodeCluster(NodeSet clusters, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc, NBNode* predefined = nullptr);
339 
341 
344 
349  bool shouldBeTLSControlled(const NodeSet& c, double laneSpeedThreshold) const;
350 
352  bool onlyCrossings(const NodeSet& c) const;
353 
355  bool customTLID(const NodeSet& c) const;
357 
358 
359 private:
362 
364  typedef std::map<std::string, NBNode*> NodeCont;
365 
368 
371 
373  std::set<std::string> myJoinExclusions;
374 
376  std::vector<std::pair<std::set<std::string>, NBNode*> > myClusters2Join;
377 
379  std::vector<std::set<std::string> > myJoinedClusters;
380 
382  std::set<std::string> myJoined;
383 
385  std::set<const NBNode*> mySplit;
386 
389 
390 private:
392  NBNodeCont(const NBNodeCont& s);
393 
395  NBNodeCont& operator=(const NBNodeCont& s);
396 
397 };
398 
399 
400 #endif
401 
402 /****************************************************************************/
403 
NBNodeCont::myJoinedClusters
std::vector< std::set< std::string > > myJoinedClusters
sets of node ids which were joined
Definition: NBNodeCont.h:379
NBNodeCont::removeUnwishedNodes
int removeUnwishedNodes(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, NBPTStopCont &sc, NBPTLineCont &lc, NBParkingCont &pc, bool removeGeometryNodes)
Removes "unwished" nodes.
Definition: NBNodeCont.cpp:369
NBNodeCont::myJoinExclusions
std::set< std::string > myJoinExclusions
set of node ids which should not be joined
Definition: NBNodeCont.h:373
NBNodeCont::getFreeID
std::string getFreeID()
generates a new node ID
Definition: NBNodeCont.cpp:1695
NBNodeCont::computeNodeShapes
void computeNodeShapes(double mismatchThreshold=-1)
Compute the junction shape for this node.
Definition: NBNodeCont.cpp:1709
NBPTStopCont
Definition: NBPTStopCont.h:27
NBEdgeCont
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:60
NBNodeCont::rename
void rename(NBNode *node, const std::string &newID)
Renames the node. Throws exception if newID already exists.
Definition: NBNodeCont.cpp:1809
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:1628
NBNodeCont::computeLanes2Lanes
void computeLanes2Lanes()
divides the incoming lanes on outgoing lanes
Definition: NBNodeCont.cpp:1645
NBNodeCont::myNodes
NodeCont myNodes
The map of names to nodes.
Definition: NBNodeCont.h:367
NBTrafficLightLogicCont
A container for traffic light definitions and built programs.
Definition: NBTrafficLightLogicCont.h:57
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
NBNodeCont::end
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:120
NBNodeCont::markAsSplit
void markAsSplit(const NBNode *node)
mark a node as being created form a split
Definition: NBNodeCont.h:316
NBNodeCont::guessTLs
void guessTLs(OptionsCont &oc, NBTrafficLightLogicCont &tlc)
Guesses which junctions or junction clusters shall be controlled by tls.
Definition: NBNodeCont.cpp:1386
NBNodeCont::myJoined
std::set< std::string > myJoined
ids found in loaded join clusters used for error checking
Definition: NBNodeCont.h:382
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:1339
NBNodeCont::insert
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:78
NBNodeCont::getAllNames
std::vector< std::string > getAllNames() const
get all node names
Definition: NBNodeCont.cpp:1799
NBNodeCont::NodeAndDist
std::pair< NBNode *, double > NodeAndDist
Definition: NBNodeCont.h:64
TrafficLightType
TrafficLightType
Definition: SUMOXMLDefinitions.h:1197
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:115
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:311
NBNodeCont::avoidOverlap
void avoidOverlap()
fix overlap
Definition: NBNodeCont.cpp:443
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:580
NamedRTree.h
NBNodeCont::pruneClusterFringe
void pruneClusterFringe(NodeSet &cluster) const
remove geometry-like fringe nodes from cluster
Definition: NBNodeCont.cpp:750
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:1861
NBDistrictCont
A container for districts.
Definition: NBDistrictCont.h:52
NBNodeCont
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:59
NBNodeCont::erase
bool erase(NBNode *node)
Removes the given node, deleting it.
Definition: NBNodeCont.cpp:137
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
NBNodeCont::analyzeCluster
void analyzeCluster(NodeSet cluster, std::string &id, Position &pos, bool &hasTLS, TrafficLightType &type, SumoXMLNodeType &nodeType)
Definition: NBNodeCont.cpp:1269
NBNodeCont::myInternalID
int myInternalID
The running internal id.
Definition: NBNodeCont.h:361
NBPTLineCont
Definition: NBPTLineCont.h:26
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:223
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:166
NBNodeCont::joinSimilarEdges
void joinSimilarEdges(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins edges connecting the same nodes.
Definition: NBNodeCont.cpp:178
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:828
SumoXMLNodeType
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
Definition: SUMOXMLDefinitions.h:1054
NBNodeCont::joinNodeClusters
void joinNodeClusters(NodeClusters clusters, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
joins the given node clusters
Definition: NBNodeCont.cpp:1079
NBNodeCont::NodeSet
std::set< NBNode *, ComparatorIdLess > NodeSet
Definition of a node cluster container.
Definition: NBNodeCont.h:62
NBNodeCont::printBuiltNodesStatistics
void printBuiltNodesStatistics() const
Prints statistics about built nodes.
Definition: NBNodeCont.cpp:1717
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:376
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
UtilExceptions.h
NBParkingCont
Definition: NBParking.h:66
NBNodeCont::addJoinExclusion
void addJoinExclusion(const std::vector< std::string > &ids, bool check=false)
Definition: NBNodeCont.cpp:564
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
NBNodeCont::joinTLS
void joinTLS(NBTrafficLightLogicCont &tlc, double maxdist)
Builds clusters of tls-controlled junctions and joins the control if possible.
Definition: NBNodeCont.cpp:1579
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:1058
NBNodeCont::mySplit
std::set< const NBNode * > mySplit
nodes that were created when splitting an edge
Definition: NBNodeCont.h:385
NBNodeCont::getJoinedClusters
const std::vector< std::set< std::string > > & getJoinedClusters() const
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.h:302
NBNodeCont::retrieve
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:107
NBNodeCont::NBNodeCont
NBNodeCont()
Constructor.
Definition: NBNodeCont.cpp:66
NBNodeCont::wasRemoved
bool wasRemoved(std::string id) const
Returns whether the node with the id was deleted explicitly.
Definition: NBNodeCont.h:245
NBNodeCont::computeLogics
void computeLogics(const NBEdgeCont &ec)
build the list of outgoing edges and lanes
Definition: NBNodeCont.cpp:1654
Position.h
NBNodeCont::NodeCont
std::map< std::string, NBNode * > NodeCont
Definition of the map of names to nodes.
Definition: NBNodeCont.h:364
NBNodeCont::customTLID
bool customTLID(const NodeSet &c) const
check wheter the set of nodes contains traffic lights with custom id
Definition: NBNodeCont.cpp:1369
NBNodeCont::clear
void clear()
deletes all nodes
Definition: NBNodeCont.cpp:1682
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:1311
NBNodeCont::myRTree
NamedRTree myRTree
node positions for faster lookup
Definition: NBNodeCont.h:388
NBNodeCont::size
int size() const
Returns the number of nodes stored in this container.
Definition: NBNodeCont.h:263
NBNodeCont::registerJoinedCluster
void registerJoinedCluster(const NodeSet &cluster)
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.cpp:1259
NBNodeCont::~NBNodeCont
~NBNodeCont()
Destructor.
Definition: NBNodeCont.cpp:71
NamedRTree
A RT-tree for efficient storing of SUMO's Named objects.
Definition: NamedRTree.h:63
NBNodeCont::extract
bool extract(NBNode *node, bool remember=false)
Removes the given node but does not delete it.
Definition: NBNodeCont.cpp:148
config.h
NBNodeCont::joinNodeCluster
void joinNodeCluster(NodeSet clusters, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, NBNode *predefined=nullptr)
Definition: NBNodeCont.cpp:1088
NBNodeCont::joinLoadedClusters
int joinLoadedClusters(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins loaded junction clusters (see NIXMLNodesHandler)
Definition: NBNodeCont.cpp:617
NBNodeCont::discardRailSignals
void discardRailSignals()
Definition: NBNodeCont.cpp:1850
NBNodeCont::generateNodeClusters
void generateNodeClusters(double maxDist, NodeClusters &into) const
Builds node clusters.
Definition: NBNodeCont.cpp:451
NBNodeCont::joinJunctions
int joinJunctions(double maxDist, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, NBPTStopCont &sc)
Joins junctions that are very close together.
Definition: NBNodeCont.cpp:642
NBNodeCont::myExtractedNodes
NodeCont myExtractedNodes
The extracted nodes which are kept for reference.
Definition: NBNodeCont.h:370
NBNode
Represents a single node (junction) during network building.
Definition: NBNode.h:67
NBNodeCont::NodeClusters
std::vector< NodeSet > NodeClusters
Definition: NBNodeCont.h:63
NBNodeCont::discardTrafficLights
void discardTrafficLights(NBTrafficLightLogicCont &tlc, bool geometryLike, bool guessSignals)
Definition: NBNodeCont.cpp:1820
NBNode.h
NBDistrict
A class representing a single district.
Definition: NBDistrict.h:64
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:1011
NBNodeCont::computeLogics2
void computeLogics2(const NBEdgeCont &ec, OptionsCont &oc)
compute right-of-way logic for all lane-to-lane connections
Definition: NBNodeCont.cpp:1662