SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NBNodeCont.h
Go to the documentation of this file.
1 /****************************************************************************/
11 // Container for nodes during the netbuilding process
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
14 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 #ifndef NBNodeCont_h
25 #define NBNodeCont_h
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
37 #include <string>
38 #include <map>
39 #include <vector>
40 #include <set>
41 #include <utils/geom/Position.h>
42 #include "NBEdgeCont.h"
43 #include "NBNode.h"
45 
46 
47 // ===========================================================================
48 // class declarations
49 // ===========================================================================
50 class NBDistrict;
51 class OptionsCont;
52 class OutputDevice;
53 class NBJoinedEdgesMap;
54 
55 
56 // ===========================================================================
57 // class definitions
58 // ===========================================================================
63 class NBNodeCont {
64 public:
66  NBNodeCont();
67 
68 
70  ~NBNodeCont();
71 
72 
73 
76 
83  bool insert(const std::string& id, const Position& position,
84  NBDistrict* district);
85 
86 
92  bool insert(const std::string& id, const Position& position);
93 
94 
99  Position insert(const std::string& id);
100 
101 
106  bool insert(NBNode* node);
107 
108 
113  bool erase(NBNode* node);
114 
115 
121  bool extract(NBNode* node, bool remember = false);
122 
127  NBNode* retrieve(const std::string& id) const;
128 
129 
135  NBNode* retrieve(const Position& position, SUMOReal offset = 0.) const;
136 
137 
141  std::map<std::string, NBNode*>::const_iterator begin() const {
142  return myNodes.begin();
143  }
144 
145 
149  std::map<std::string, NBNode*>::const_iterator end() const {
150  return myNodes.end();
151  }
153 
154 
155 
158 
159  /* @brief add ids of nodes wich shall not be joined
160  * @param[in] ids A list of ids to exclude from joining
161  * @param[in] check Whether to check if these nodes are known
162  * @note checking is off by default because all nodes may not have been loaded yet
163  */
164  void addJoinExclusion(const std::vector<std::string>& ids, bool check = false);
165 
166 
170  void addCluster2Join(std::set<std::string> cluster);
171 
172 
176 
177 
180  unsigned int joinJunctions(SUMOReal maxdist, NBDistrictCont& dc, NBEdgeCont& ec, NBTrafficLightLogicCont& tlc);
182 
183 
184 
187 
195 
196 
204 
205 
215 
216 
233  NBTrafficLightLogicCont& tlc, bool removeGeometryNodes);
235 
236 
237 
240 
247 
248 
254  void joinTLS(NBTrafficLightLogicCont& tlc, SUMOReal maxdist);
255 
256 
264  void setAsTLControlled(NBNode* node, NBTrafficLightLogicCont& tlc, TrafficLightType type, std::string id = "");
266 
267 
270  void rename(NBNode* node, const std::string& newID);
271 
272 
274  void computeLanes2Lanes();
275 
277  void computeLogics(const NBEdgeCont& ec, OptionsCont& oc);
278 
282  unsigned int size() const {
283  return (unsigned int) myNodes.size();
284  }
285 
287  void clear();
288 
289 
290 
291  std::string getFreeID();
292 
293  void computeNodeShapes(bool leftHand);
294 
295 
296 
297 
303  void printBuiltNodesStatistics() const;
304 
305 
307  std::vector<std::string> getAllNames() const;
308 
309 
310  /* @brief analyzes a cluster of nodes which shall be joined
311  * @param[in] cluster The nodes to be joined
312  * @param[out] id The name for the new node
313  * @param[out] pos The position of the new node
314  * @param[out] hasTLS Whether the new node has a traffic light
315  * @param[out] tlType The type of traffic light (if any)
316  */
317  void analyzeCluster(std::set<NBNode*> cluster, std::string& id, Position& pos,
318  bool& hasTLS, TrafficLightType& type);
319 
321  void registerJoinedCluster(const std::set<NBNode*>& cluster);
322 
324  const std::vector<std::set<std::string> >& getJoinedClusters() const {
325  return myJoinedClusters;
326  }
327 
328 
329  /* @brief discards traffic lights
330  * @param[in] geometryLike Whether only tls at geometry-like nodes shall be discarded
331  */
332  void discardTrafficLights(NBTrafficLightLogicCont& tlc, bool geometryLike);
333 
334 private:
337 
339  typedef std::vector<std::set<NBNode*> > NodeClusters;
340 
341 
349  void generateNodeClusters(SUMOReal maxDist, NodeClusters& into) const;
350 
351 
352  // @brief joins the given node clusters
353  void joinNodeClusters(NodeClusters clusters,
355 
357 
358 
359 
362 
367  bool shouldBeTLSControlled(const std::set<NBNode*>& c) const;
369 
370 
371 private:
374 
376  typedef std::map<std::string, NBNode*> NodeCont;
377 
380 
382  std::set<NBNode*> myExtractedNodes;
383 
384  // @brief set of node ids which should not be joined
385  std::set<std::string> myJoinExclusions;
386 
387  // @brief loaded sets of node ids to join (cleared after use)
388  std::vector<std::set<std::string> > myClusters2Join;
389  // @brief sets of node ids which were joined
390  std::vector<std::set<std::string> > myJoinedClusters;
391 
393  std::set<std::string> myJoined;
394 
395 private:
397  NBNodeCont(const NBNodeCont& s);
398 
400  NBNodeCont& operator=(const NBNodeCont& s);
401 
402 };
403 
404 
405 #endif
406 
407 /****************************************************************************/
408 
std::string getFreeID()
Definition: NBNodeCont.cpp:894
std::set< std::string > myJoinExclusions
Definition: NBNodeCont.h:385
NodeCont myNodes
The map of names to nodes.
Definition: NBNodeCont.h:379
void joinSimilarEdges(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins edges connecting the same nodes.
Definition: NBNodeCont.cpp:192
const std::vector< std::set< std::string > > & getJoinedClusters() const
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.h:324
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:180
bool insert(const std::string &id, const Position &position, NBDistrict *district)
Inserts a node into the map.
Definition: NBNodeCont.cpp:78
void addJoinExclusion(const std::vector< std::string > &ids, bool check=false)
Definition: NBNodeCont.cpp:432
unsigned int removeUnwishedNodes(NBDistrictCont &dc, NBEdgeCont &ec, NBJoinedEdgesMap &je, NBTrafficLightLogicCont &tlc, bool removeGeometryNodes)
Removes &quot;unwished&quot; nodes.
Definition: NBNodeCont.cpp:336
A container for traffic light definitions and built programs.
std::vector< std::set< std::string > > myJoinedClusters
Definition: NBNodeCont.h:390
A container for districts.
unsigned int joinJunctions(SUMOReal maxdist, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins junctions that are very close together.
Definition: NBNodeCont.cpp:490
void guessTLs(OptionsCont &oc, NBTrafficLightLogicCont &tlc)
Guesses which junctions or junction clusters shall be controlled by tls.
Definition: NBNodeCont.cpp:701
void computeLogics(const NBEdgeCont &ec, OptionsCont &oc)
build the list of outgoing edges and lanes
Definition: NBNodeCont.cpp:873
void generateNodeClusters(SUMOReal maxDist, NodeClusters &into) const
Builds node clusters.
Definition: NBNodeCont.cpp:389
A class representing a single district.
Definition: NBDistrict.h:72
unsigned int size() const
Returns the number of known nodes.
Definition: NBNodeCont.h:282
void computeLanes2Lanes()
divides the incoming lanes on outgoing lanes
Definition: NBNodeCont.cpp:864
~NBNodeCont()
Destructor.
Definition: NBNodeCont.cpp:71
void joinTLS(NBTrafficLightLogicCont &tlc, SUMOReal maxdist)
Builds clusters of tls-controlled junctions and joins the control if possible.
Definition: NBNodeCont.cpp:801
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
int myInternalID
The running internal id.
Definition: NBNodeCont.h:373
NBNodeCont()
Constructor.
Definition: NBNodeCont.cpp:67
unsigned int joinLoadedClusters(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins loaded junction clusters (see NIXMLNodesHandler)
Definition: NBNodeCont.cpp:466
std::map< std::string, NBNode * > NodeCont
Definition of the map of names to nodes.
Definition: NBNodeCont.h:376
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
void joinNodeClusters(NodeClusters clusters, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Definition: NBNodeCont.cpp:555
std::set< NBNode * > myExtractedNodes
The extracted nodes which are kept for reference.
Definition: NBNodeCont.h:382
std::vector< std::string > getAllNames() const
get all node names
Definition: NBNodeCont.cpp:960
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:149
bool shouldBeTLSControlled(const std::set< NBNode * > &c) const
Returns whethe the given node cluster should be controlled by a tls.
Definition: NBNodeCont.cpp:673
void rename(NBNode *node, const std::string &newID)
Renames the node. Throws exception if newID already exists.
Definition: NBNodeCont.cpp:970
void setAsTLControlled(NBNode *node, NBTrafficLightLogicCont &tlc, TrafficLightType type, std::string id="")
Sets the given node as being controlled by a tls.
Definition: NBNodeCont.cpp:847
void addCluster2Join(std::set< std::string > cluster)
add ids of nodes which shall be joined into a single node
Definition: NBNodeCont.cpp:448
A structure storing information about which edges were joined.
void analyzeCluster(std::set< NBNode * > cluster, std::string &id, Position &pos, bool &hasTLS, TrafficLightType &type)
Definition: NBNodeCont.cpp:638
void removeIsolatedRoads(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tc)
Removes sequences of edges that are not connected with a junction. Simple roads without junctions som...
Definition: NBNodeCont.cpp:242
std::set< std::string > myJoined
ids found in loaded join clusters used for error checking
Definition: NBNodeCont.h:393
A storage for options typed value containers)
Definition: OptionsCont.h:108
std::vector< std::set< NBNode * > > NodeClusters
Definition of a node cluster container.
Definition: NBNodeCont.h:339
void clear()
Definition: NBNodeCont.cpp:881
void computeNodeShapes(bool leftHand)
Definition: NBNodeCont.cpp:903
std::vector< std::set< std::string > > myClusters2Join
Definition: NBNodeCont.h:388
Represents a single node (junction) during network building.
Definition: NBNode.h:74
NBNodeCont & operator=(const NBNodeCont &s)
invalidated assignment operator
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
#define SUMOReal
Definition: config.h:221
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:129
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:63
void printBuiltNodesStatistics() const
Prints statistics about built nodes.
Definition: NBNodeCont.cpp:911
void discardTrafficLights(NBTrafficLightLogicCont &tlc, bool geometryLike)
Definition: NBNodeCont.cpp:981
bool extract(NBNode *node, bool remember=false)
Removes the given node but does not delete it.
Definition: NBNodeCont.cpp:164
bool erase(NBNode *node)
Removes the given node, deleting it.
Definition: NBNodeCont.cpp:153
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:141
TrafficLightType
void registerJoinedCluster(const std::set< NBNode * > &cluster)
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.cpp:628