Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NBNodeCont.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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// ===========================================================================
42class NBDistrict;
43class OptionsCont;
44class OutputDevice;
45class NBParkingCont;
46class NBPTLineCont;
47class NBPTStopCont;
48
49
50// ===========================================================================
51// class definitions
52// ===========================================================================
58
59public:
61 typedef std::vector<NodeSet> NodeClusters;
62 typedef std::pair<NBNode*, double> NodeAndDist;
63
66
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 * @note it does not check whether the nodes exist because all nodes may not have been loaded yet
128 */
129 void addJoinExclusion(const std::vector<std::string>& ids);
130
136 std::string createClusterId(const NodeSet& cluster, const std::string& prefix = "cluster_") {
137 std::set<std::string> clusterIds;
138 for (NBNode* j : cluster) {
139 clusterIds.insert(j->getID());
140 }
141 return createClusterId(clusterIds, prefix);
142 }
143
149 std::string createClusterId(const std::set<std::string>& cluster, const std::string& prefix = "cluster_");
150
154 void addCluster2Join(const std::set<std::string>& cluster, NBNode* node);
155
158
160 int joinJunctions(double maxDist, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc, NBPTStopCont& sc);
161
164
166 static NodeSet getClusterNeighbors(const NBNode* n, double longThreshold, NodeSet& cluster);
167
169 static bool isSlipLaneContinuation(const NBNode* cont);
170
172 bool maybeSlipLaneStart(const NBNode* n, EdgeVector& outgoing, double& inAngle) const;
174 bool maybeSlipLaneEnd(const NBNode* n, EdgeVector& incoming, double& outAngle) const;
175
177 bool reduceToCircle(NodeSet& cluster, int circleSize, NodeSet startNodes, double maxDist, std::vector<NBNode*> cands = std::vector<NBNode*>()) const;
178
180 NBEdge* shortestEdge(const NodeSet& cluster, const NodeSet& startNodes, const std::vector<NBNode*>& exclude) const;
182
185
193
200 void joinSimilarEdges(NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc, bool removeDuplicates);
201
203 void avoidOverlap();
204
214
223 int removeComponents(NBDistrictCont& dc, NBEdgeCont& ec, const int numKeep, bool hasPTStops);
224
225 /* @brief remove rail components after ptstops are built
226 * @return The number of removed edges
227 */
229
248 bool removeGeometryNodes);
250
253
259
262
264 bool recheckTLSThreshold(NBNode* node);
265
267 void computeKeepClear();
268
274 void joinTLS(NBTrafficLightLogicCont& tlc, double maxdist);
275
283 void setAsTLControlled(NBNode* node, NBTrafficLightLogicCont& tlc, TrafficLightType type, std::string id = "");
285
287 bool wasRemoved(std::string id) const {
288 return myExtractedNodes.count(id) != 0;
289 }
290
292 void addPrefix(const std::string& prefix);
293
295 void rename(NBNode* node, const std::string& newID);
296
298 void computeLanes2Lanes();
299
301 void computeLogics(const NBEdgeCont& ec);
302
304 void computeLogics2(const NBEdgeCont& ec, OptionsCont& oc);
305
307 int size() const {
308 return (int) myNodes.size();
309 }
310
312 void clear();
313
315 std::string getFreeID();
316
320 void computeNodeShapes(double mismatchThreshold = -1);
321
327 void printBuiltNodesStatistics() const;
328
330 std::vector<std::string> getAllNames() const;
331
332 /* @brief analyzes a cluster of nodes which shall be joined
333 * @param[in] cluster The nodes to be joined
334 * @param[out] id The name for the new node
335 * @param[out] pos The position of the new node
336 * @param[out] hasTLS Whether the new node has a traffic light
337 * @param[out] tlType The type of traffic light (if any)
338 */
339 void analyzeCluster(NodeSet cluster, std::string& id, Position& pos,
340 bool& hasTLS, TrafficLightType& type, SumoXMLNodeType& nodeType);
341
343 void registerJoinedCluster(const NodeSet& cluster);
344 void registerJoinedCluster(const std::set<std::string>& cluster);
345
347 void unregisterJoinedCluster(const std::set<std::string>& cluster);
348
350 const std::vector<std::set<std::string> >& getJoinedClusters() const {
351 return myJoinedClusters;
352 }
353
354 /* @brief discards traffic lights
355 * @param[in] geometryLike Whether only tls at geometry-like nodes shall be discarded
356 */
357 void discardTrafficLights(NBTrafficLightLogicCont& tlc, bool geometryLike, bool guessSignals);
358
360 void discardRailSignals();
361
363 void markAsSplit(const NBNode* node) {
364 mySplit.insert(node);
365 }
366
368 void markAsNotTLS(const NBNode* node) {
369 myUnsetTLS.insert(node);
370 }
371
373 int remapIDs(bool numericaIDs, bool reservedIDs, const std::string& prefix, NBTrafficLightLogicCont& tlc);
374
376 int guessFringe();
377
380
382 bool resetNodeShapes();
383
384private:
385
388
395 void generateNodeClusters(double maxDist, NodeClusters& into) const;
396
398 void pruneClusterFringe(NodeSet& cluster, double maxDist) const;
399
401 static int pruneLongEdges(NodeSet& cluster, double maxDist, const bool dryRun = false);
402
404 static double getDiameter(const NodeSet& cluster);
405
407 static bool geometryLikeForClass(const NBNode* n, SVCPermissions permissions);
408
410 void pruneSlipLaneNodes(NodeSet& cluster, double maxDist) const;
411
413 bool feasibleCluster(const NodeSet& cluster, const std::map<const NBNode*, std::vector<NBNode*> >& ptStopEnds,
414 double maxDist, std::string& reason) const;
415
417 void joinNodeClusters(NodeClusters clusters, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc, bool resetConnections = false);
419 NBNode* predefined = nullptr, bool resetConnections = false);
420
422
425
430 bool shouldBeTLSControlled(const NodeSet& c, double laneSpeedThreshold, bool recheck = false) const;
431
433 bool onlyCrossings(const NodeSet& c) const;
434
436 bool customTLID(const NodeSet& c) const;
438
440 void paretoCheck(NBNode* node, NodeSet& frontier, int xSign, int ySign);
441
443 typedef std::map<std::string, NBNode*> NodeCont;
444
447
450
452 std::set<std::string> myJoinExclusions;
453
455 std::vector<std::pair<std::set<std::string>, NBNode*> > myClusters2Join;
456
458 std::vector<std::set<std::string> > myJoinedClusters;
459
461 std::set<std::string> myJoined;
462
464 std::set<const NBNode*> mySplit;
465
467 std::set<NBNode*, ComparatorIdLess> myGuessedTLS;
468
470 std::set<const NBNode*> myUnsetTLS;
471
474
476 std::vector<std::vector<std::string> > myRailComponents;
477
479 NBNodeCont(const NBNodeCont& s) = delete;
480
482 NBNodeCont& operator=(const NBNodeCont& s) = delete;
483};
std::set< NBNode *, ComparatorIdLess > NodeSet
Definition NBCont.h:52
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition NBCont.h:42
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
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:92
Container for nodes during the netbuilding process.
Definition NBNodeCont.h:57
void clear()
deletes all nodes
std::set< std::string > myJoinExclusions
set of node ids which should not be joined
Definition NBNodeCont.h:452
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:476
void pruneClusterFringe(NodeSet &cluster, double maxDist) const
remove geometry-like fringe nodes from cluster
bool wasRemoved(std::string id) const
Returns whether the node with the id was deleted explicitly.
Definition NBNodeCont.h:287
static double getDiameter(const NodeSet &cluster)
compute the maximum distance between any two cluster nodes
NamedRTree myRTree
node positions for faster lookup
Definition NBNodeCont.h:473
void avoidOverlap()
fix overlap
int removeRailComponents(NBDistrictCont &dc, NBEdgeCont &ec, NBPTStopCont &sc)
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:455
void markAsNotTLS(const NBNode *node)
mark a node as explicitly not controlled by a TLS
Definition NBNodeCont.h:368
std::string createClusterId(const NodeSet &cluster, const std::string &prefix="cluster_")
generate id from cluster node ids
Definition NBNodeCont.h:136
int size() const
Returns the number of nodes stored in this container.
Definition NBNodeCont.h:307
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition NBNodeCont.h:113
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:446
bool reduceToCircle(NodeSet &cluster, int circleSize, NodeSet startNodes, double maxDist, std::vector< NBNode * > cands=std::vector< NBNode * >()) const
try to find a joinable subset (recursively)
bool feasibleCluster(const NodeSet &cluster, const std::map< const NBNode *, std::vector< NBNode * > > &ptStopEnds, double maxDist, std::string &reason) const
determine wether the cluster is not too complex for joining
void registerJoinedCluster(const NodeSet &cluster)
gets all joined clusters (see doc for myClusters2Join)
std::string getFreeID()
generates a new node ID
int removeSelfLoops(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tc)
Removes self-loop edges (edges where the source and the destination node are the same)
NBNodeCont(const NBNodeCont &s)=delete
invalidated copy constructor
bool recheckTLSThreshold(NBNode *node)
check whether a specific guessed tls should keep its type
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
void addJoinExclusion(const std::vector< std::string > &ids)
bool erase(NBNode *node)
Removes the given node, deleting it.
std::map< std::string, NBNode * > NodeCont
Definition of the map of names to nodes.
Definition NBNodeCont.h:443
int joinLoadedClusters(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins loaded junction clusters (see NIXMLNodesHandler)
static bool geometryLikeForClass(const NBNode *n, SVCPermissions permissions)
check whether the node is geometryLike when only considering edges that support the given permissions
void applyConditionalDefaults()
apply default values after loading
void pruneSlipLaneNodes(NodeSet &cluster, double maxDist) const
remove nodes that form a slip lane from cluster
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
std::set< const NBNode * > myUnsetTLS
nodes that are excluded from tls-guessing
Definition NBNodeCont.h:470
int remapIDs(bool numericaIDs, bool reservedIDs, const std::string &prefix, NBTrafficLightLogicCont &tlc)
remap node IDs according to options –numerical-ids and –reserved-ids
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
NodeCont myExtractedNodes
The extracted nodes which are kept for reference.
Definition NBNodeCont.h:449
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.
~NBNodeCont()
Destructor.
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition NBNodeCont.h:118
NBNodeCont & operator=(const NBNodeCont &s)=delete
invalidated assignment operator
const std::vector< std::set< std::string > > & getJoinedClusters() const
gets all joined clusters (see doc for myClusters2Join)
Definition NBNodeCont.h:350
bool extract(NBNode *node, bool remember=false)
Removes the given node but does not delete it.
int removeComponents(NBDistrictCont &dc, NBEdgeCont &ec, const int numKeep, bool hasPTStops)
Checks the network for weak connectivity and removes all but the largest components....
NBNodeCont()
Constructor.
Definition NBNodeCont.h:65
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
bool shouldBeTLSControlled(const NodeSet &c, double laneSpeedThreshold, bool recheck=false) const
Returns whethe the given node cluster should be controlled by a tls.
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.
int removeIsolatedRoads(NBDistrictCont &dc, NBEdgeCont &ec)
Removes sequences of edges that are not connected with a junction. Simple roads without junctions som...
void joinNodeClusters(NodeClusters clusters, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, bool resetConnections=false)
joins the given node clusters
void discardRailSignals()
discards rail signals
void addPrefix(const std::string &prefix)
add prefix to all nodes
void printBuiltNodesStatistics() const
Prints statistics about built nodes.
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:464
static NodeSet getClusterNeighbors(const NBNode *n, double longThreshold, NodeSet &cluster)
return all cluster neighbors for the given node
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)
void unregisterJoinedCluster(const std::set< std::string > &cluster)
remove cluster from list (on netedit-undo)
void generateNodeClusters(double maxDist, NodeClusters &into) const
Builds node clusters.
static bool isSlipLaneContinuation(const NBNode *cont)
whether the given node may continue a slip lane
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:458
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
void markAsSplit(const NBNode *node)
mark a node as being created form a split
Definition NBNodeCont.h:363
int joinJunctions(double maxDist, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc, NBPTStopCont &sc)
Joins junctions that are very close together.
void computeLanes2Lanes()
divides the incoming lanes on outgoing lanes
void discardTrafficLights(NBTrafficLightLogicCont &tlc, bool geometryLike, bool guessSignals)
std::set< NBNode *, ComparatorIdLess > myGuessedTLS
nodes that received a traffic light due to guessing (–tls.guess)
Definition NBNodeCont.h:467
std::set< std::string > myJoined
ids found in loaded join clusters used for error checking
Definition NBNodeCont.h:461
int joinSameJunctions(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins junctions with the same coordinates regardless of topology.
void analyzeCluster(NodeSet cluster, std::string &id, Position &pos, bool &hasTLS, TrafficLightType &type, SumoXMLNodeType &nodeType)
void addCluster2Join(const std::set< std::string > &cluster, NBNode *node)
add ids of nodes which shall be joined into a single node
bool customTLID(const NodeSet &c) const
check wheter the set of nodes contains traffic lights with custom id
bool resetNodeShapes()
reset all node shapes
static int pruneLongEdges(NodeSet &cluster, double maxDist, const bool dryRun=false)
avoid removal of long edges when joining junction clusters
bool maybeSlipLaneEnd(const NBNode *n, EdgeVector &incoming, double &outAngle) const
check whether the given node maybe the end of a slip lane
Represents a single node (junction) during network building.
Definition NBNode.h:66
Container for public transport stops during the net building process.
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.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37