SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
NBNodeCont.cpp
Go to the documentation of this file.
1 /****************************************************************************/
13 // Container for nodes during the netbuilding process
14 /****************************************************************************/
15 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
16 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
17 /****************************************************************************/
18 //
19 // This file is part of SUMO.
20 // SUMO is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 /****************************************************************************/
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 <algorithm>
40 #include <cmath>
42 #include <utils/geom/Boundary.h>
43 #include <utils/geom/GeomHelper.h>
47 #include <utils/common/StdDefs.h>
48 #include <utils/common/ToString.h>
52 #include "NBDistrict.h"
53 #include "NBEdgeCont.h"
55 #include "NBJoinedEdgesMap.h"
56 #include "NBOwnTLDef.h"
57 #include "NBNodeCont.h"
58 
59 #ifdef CHECK_MEMORY_LEAKS
60 #include <foreign/nvwa/debug_new.h>
61 #endif // CHECK_MEMORY_LEAKS
62 
63 
64 // ===========================================================================
65 // method definitions
66 // ===========================================================================
68  : myInternalID(1) {
69 }
70 
71 
73  clear();
74 }
75 
76 
77 // ----------- Insertion/removal/retrieval of nodes
78 bool
79 NBNodeCont::insert(const std::string& id, const Position& position,
80  NBDistrict* district) {
81  NodeCont::iterator i = myNodes.find(id);
82  if (i != myNodes.end()) {
83  return false;
84  }
85  NBNode* node = new NBNode(id, position, district);
86  myNodes[id] = node;
87  const float pos[2] = {(float)position.x(), (float)position.y()};
88  myRTree.Insert(pos, pos, node);
89  return true;
90 }
91 
92 
93 bool
95  std::string id = node->getID();
96  NodeCont::iterator i = myNodes.find(id);
97  if (i != myNodes.end()) {
98  return false;
99  }
100  myNodes[id] = node;
101  const float pos[2] = {(float)node->getPosition().x(), (float)node->getPosition().y()};
102  myRTree.Insert(pos, pos, node);
103  return true;
104 }
105 
106 
107 NBNode*
108 NBNodeCont::retrieve(const std::string& id) const {
109  NodeCont::const_iterator i = myNodes.find(id);
110  if (i == myNodes.end()) {
111  return 0;
112  }
113  return (*i).second;
114 }
115 
116 
117 NBNode*
118 NBNodeCont::retrieve(const Position& position, const SUMOReal offset) const {
119  const SUMOReal extOffset = offset + POSITION_EPS;
120  const float cmin[2] = {(float)(position.x() - extOffset), (float)(position.y() - extOffset)};
121  const float cmax[2] = {(float)(position.x() + extOffset), (float)(position.y() + extOffset)};
122  std::set<std::string> into;
123  Named::StoringVisitor sv(into);
124  myRTree.Search(cmin, cmax, sv);
125  for (std::set<std::string>::const_iterator i = into.begin(); i != into.end(); i++) {
126  NBNode* const node = myNodes.find(*i)->second;
127  if (fabs(node->getPosition().x() - position.x()) <= offset
128  &&
129  fabs(node->getPosition().y() - position.y()) <= offset) {
130  return node;
131  }
132  }
133  return 0;
134 }
135 
136 
137 bool
139  if (extract(node)) {
140  delete node;
141  return true;
142  } else {
143  return false;
144  }
145 }
146 
147 
148 bool
149 NBNodeCont::extract(NBNode* node, bool remember) {
150  NodeCont::iterator i = myNodes.find(node->getID());
151  if (i == myNodes.end()) {
152  return false;
153  }
154  myNodes.erase(i);
155  const float pos[2] = {(float)node->getPosition().x(), (float)node->getPosition().y()};
156  myRTree.Remove(pos, pos, node);
157  node->removeTrafficLights();
158  if (remember) {
159  myExtractedNodes.insert(node);
160  }
161  return true;
162 }
163 
164 
165 // ----------- Adapting the input
166 void
168  unsigned int no = 0;
169  for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
170  no += (*i).second->removeSelfLoops(dc, ec, tc);
171  }
172  if (no != 0) {
173  WRITE_WARNING(toString(no) + " self-looping edge(s) removed.");
174  }
175 }
176 
177 
178 void
180  // magic values
181  SUMOReal distanceThreshold = 7; // don't merge edges further apart
182  SUMOReal lengthThreshold = 0.05; // don't merge edges with higher relative length-difference
183 
184  for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
185  // count the edges to other nodes outgoing from the current node
186  std::map<NBNode*, EdgeVector> connectionCount;
187  const EdgeVector& outgoing = (*i).second->getOutgoingEdges();
188  for (EdgeVector::const_iterator j = outgoing.begin(); j != outgoing.end(); j++) {
189  NBEdge* e = (*j);
190  NBNode* connected = e->getToNode();
191  if (connectionCount.find(connected) == connectionCount.end()) {
192  connectionCount[connected] = EdgeVector();
193  }
194  connectionCount[connected].push_back(e);
195  }
196  // check whether more than a single edge connect another node and join them
197  std::map<NBNode*, EdgeVector>::iterator k;
198  for (k = connectionCount.begin(); k != connectionCount.end(); k++) {
199  // possibly we do not have anything to join...
200  if ((*k).second.size() < 2) {
201  continue;
202  }
203  // for the edges that seem to be a single street,
204  // check whether the geometry is similar
205  const EdgeVector& ev = (*k).second;
206  const NBEdge* const first = ev.front();
207  EdgeVector::const_iterator jci; // join candidate iterator
208  for (jci = ev.begin() + 1; jci != ev.end(); ++jci) {
209  const SUMOReal relativeLengthDifference = fabs(first->getLoadedLength() - (*jci)->getLoadedLength()) / first->getLoadedLength();
210  if ((!first->isNearEnough2BeJoined2(*jci, distanceThreshold)) ||
211  (relativeLengthDifference > lengthThreshold) ||
212  (first->getSpeed() != (*jci)->getSpeed())
213  // @todo check vclass
214  ) {
215  break;
216  }
217  }
218  // @bug If there are 3 edges of which 2 can be joined, no joining will
219  // take place with the current implementation
220  if (jci == ev.end()) {
221  ec.joinSameNodeConnectingEdges(dc, tlc, ev);
222  }
223  }
224  }
225 }
226 
227 
228 void
230  UNUSED_PARAMETER(tc);
231  // Warn of isolated edges, i.e. a single edge with no connection to another edge
232  int edgeCounter = 0;
233  const std::vector<std::string>& edgeNames = ec.getAllNames();
234  for (std::vector<std::string>::const_iterator it = edgeNames.begin(); it != edgeNames.end(); ++it) {
235  // Test whether this node starts at a dead end, i.e. it has only one adjacent node
236  // to which an edge exists and from which an edge may come.
237  NBEdge* e = ec.retrieve(*it);
238  if (e == 0) {
239  continue;
240  }
241  NBNode* from = e->getFromNode();
242  const EdgeVector& outgoingEdges = from->getOutgoingEdges();
243  if (outgoingEdges.size() != 1) {
244  // At this node, several edges or no edge start; so, this node is no dead end.
245  continue;
246  }
247  const EdgeVector& incomingEdges = from->getIncomingEdges();
248  if (incomingEdges.size() > 1) {
249  // At this node, several edges end; so, this node is no dead end.
250  continue;
251  } else if (incomingEdges.size() == 1) {
252  NBNode* fromNodeOfIncomingEdge = incomingEdges[0]->getFromNode();
253  NBNode* toNodeOfOutgoingEdge = outgoingEdges[0]->getToNode();
254  if (fromNodeOfIncomingEdge != toNodeOfOutgoingEdge) {
255  // At this node, an edge ends which is not the inverse direction of
256  // the starting node.
257  continue;
258  }
259  }
260  // Now we know that the edge e starts a dead end.
261  // Next we test if the dead end is isolated, i.e. does not lead to a junction
262  bool hasJunction = false;
263  EdgeVector road;
264  NBEdge* eOld = 0;
265  NBNode* to;
266  std::set<NBNode*> adjacentNodes;
267  do {
268  road.push_back(e);
269  eOld = e;
270  from = e->getFromNode();
271  to = e->getToNode();
272  const EdgeVector& outgoingEdgesOfToNode = to->getOutgoingEdges();
273  const EdgeVector& incomingEdgesOfToNode = to->getIncomingEdges();
274  adjacentNodes.clear();
275  for (EdgeVector::const_iterator itOfOutgoings = outgoingEdgesOfToNode.begin(); itOfOutgoings != outgoingEdgesOfToNode.end(); ++itOfOutgoings) {
276  if ((*itOfOutgoings)->getToNode() != from // The back path
277  && (*itOfOutgoings)->getToNode() != to // A loop / dummy edge
278  ) {
279  e = *itOfOutgoings; // Probably the next edge
280  }
281  adjacentNodes.insert((*itOfOutgoings)->getToNode());
282  }
283  for (EdgeVector::const_iterator itOfIncomings = incomingEdgesOfToNode.begin(); itOfIncomings != incomingEdgesOfToNode.end(); ++itOfIncomings) {
284  adjacentNodes.insert((*itOfIncomings)->getFromNode());
285  }
286  adjacentNodes.erase(to); // Omit loops
287  if (adjacentNodes.size() > 2) {
288  hasJunction = true;
289  }
290  } while (!hasJunction && eOld != e);
291  if (!hasJunction) {
292  edgeCounter += int(road.size());
293  std::string warningString = "Removed a road without junctions: ";
294  for (EdgeVector::iterator roadIt = road.begin(); roadIt != road.end(); ++roadIt) {
295  if (roadIt == road.begin()) {
296  warningString += (*roadIt)->getID();
297  } else {
298  warningString += ", " + (*roadIt)->getID();
299  }
300 
301  NBNode* fromNode = (*roadIt)->getFromNode();
302  NBNode* toNode = (*roadIt)->getToNode();
303  ec.erase(dc, *roadIt);
304  if (fromNode->getIncomingEdges().size() == 0 && fromNode->getOutgoingEdges().size() == 0) {
305  // Node is empty; can be removed
306  erase(fromNode);
307  }
308  if (toNode->getIncomingEdges().size() == 0 && toNode->getOutgoingEdges().size() == 0) {
309  // Node is empty; can be removed
310  erase(toNode);
311  }
312  }
313  WRITE_WARNING(warningString);
314  }
315  }
316  if (edgeCounter > 0 && !OptionsCont::getOptions().getBool("remove-edges.isolated")) {
317  WRITE_WARNING("Detected isolated roads. Use the option --remove-edges.isolated to get a list of all affected edges.");
318  }
319 }
320 
321 
322 unsigned int
325  bool removeGeometryNodes) {
326  unsigned int no = 0;
327  std::vector<NBNode*> toRemove;
328  for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
329  NBNode* current = (*i).second;
330  bool remove = false;
331  std::vector<std::pair<NBEdge*, NBEdge*> > toJoin;
332  // check for completely empty nodes
333  if (current->getOutgoingEdges().size() == 0 && current->getIncomingEdges().size() == 0) {
334  // remove if empty
335  remove = true;
336  }
337  // check for nodes which are only geometry nodes
338  if (removeGeometryNodes) {
339  if ((current->getOutgoingEdges().size() == 1 && current->getIncomingEdges().size() == 1)
340  ||
341  (current->getOutgoingEdges().size() == 2 && current->getIncomingEdges().size() == 2)) {
342  // ok, one in, one out or two in, two out
343  // -> ask the node whether to join
344  remove = current->checkIsRemovable();
345  if (remove) {
346  toJoin = current->getEdgesToJoin();
347  }
348  }
349  }
350  // remove the node and join the geometries when wished
351  if (!remove) {
352  continue;
353  }
354  for (std::vector<std::pair<NBEdge*, NBEdge*> >::iterator j = toJoin.begin(); j != toJoin.end(); j++) {
355  NBEdge* begin = (*j).first;
356  NBEdge* continuation = (*j).second;
357  begin->append(continuation);
358  continuation->getToNode()->replaceIncoming(continuation, begin, 0);
359  tlc.replaceRemoved(continuation, -1, begin, -1);
360  je.appended(begin->getID(), continuation->getID());
361  ec.erase(dc, continuation);
362  }
363  toRemove.push_back(current);
364  no++;
365  }
366  // erase all
367  for (std::vector<NBNode*>::iterator j = toRemove.begin(); j != toRemove.end(); ++j) {
368  erase(*j);
369  }
370  return no;
371 }
372 
373 
374 void
376  for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
377  (*i).second->avoidOverlap();
378  }
379 }
380 
381 // ----------- (Helper) methods for joining nodes
382 void
384  std::set<NBNode*> visited;
385  for (NodeCont::const_iterator i = myNodes.begin(); i != myNodes.end(); i++) {
386  std::vector<NBNode*> toProc;
387  if (visited.find((*i).second) != visited.end()) {
388  continue;
389  }
390  toProc.push_back((*i).second);
391  std::set<NBNode*> c;
392  while (!toProc.empty()) {
393  NBNode* n = toProc.back();
394  toProc.pop_back();
395  if (visited.find(n) != visited.end()) {
396  continue;
397  }
398  c.insert(n);
399  visited.insert(n);
400  const EdgeVector& edges = n->getEdges();
401  for (EdgeVector::const_iterator j = edges.begin(); j != edges.end(); ++j) {
402  NBEdge* e = *j;
403  NBNode* s = 0;
404  if (n->hasIncoming(e)) {
405  s = e->getFromNode();
406  } else {
407  s = e->getToNode();
408  }
409  if (visited.find(s) != visited.end()) {
410  continue;
411  }
412  if (e->getLoadedLength() < maxDist) {
413  toProc.push_back(s);
414  }
415  }
416  }
417  if (c.size() < 2) {
418  continue;
419  }
420  into.push_back(c);
421  }
422 }
423 
424 
425 void
426 NBNodeCont::addJoinExclusion(const std::vector<std::string>& ids, bool check) {
427  for (std::vector<std::string>::const_iterator it = ids.begin(); it != ids.end(); it++) {
428  // error handling has to take place here since joinExclusions could be
429  // loaded from multiple files / command line
430  if (myJoined.count(*it) > 0) {
431  WRITE_WARNING("Ignoring join exclusion for node '" + *it + "' since it already occured in a list of nodes to be joined");
432  } else if (check && retrieve(*it) == 0) {
433  WRITE_WARNING("Ignoring join exclusion for unknown node '" + *it + "'");
434  } else {
435  myJoinExclusions.insert(*it);
436  }
437  }
438 }
439 
440 
441 void
442 NBNodeCont::addCluster2Join(std::set<std::string> cluster) {
443  // error handling has to take place here since joins could be loaded from multiple files
444  for (std::set<std::string>::const_iterator it = cluster.begin(); it != cluster.end(); it++) {
445  if (myJoinExclusions.count(*it) > 0) {
446  WRITE_WARNING("Ignoring join-cluster because node '" + *it + "' was already excluded from joining");
447  return;
448  } else if (myJoined.count(*it) > 0) {
449  WRITE_WARNING("Ignoring join-cluster because node '" + *it + "' already occured in another join-cluster");
450  return;
451  } else {
452  myJoined.insert(*it);
453  }
454  }
455  myClusters2Join.push_back(cluster);
456 }
457 
458 
459 unsigned int
461  NodeClusters clusters;
462  for (std::vector<std::set<std::string> >::iterator it = myClusters2Join.begin(); it != myClusters2Join.end(); it++) {
463  // verify loaded cluster
464  std::set<NBNode*> cluster;
465  for (std::set<std::string>::iterator it_id = it->begin(); it_id != it->end(); it_id++) {
466  NBNode* node = retrieve(*it_id);
467  if (node == 0) {
468  WRITE_WARNING("Ignoring unknown node '" + *it_id + "' while joining");
469  } else {
470  cluster.insert(node);
471  }
472  }
473  if (cluster.size() > 1) {
474  clusters.push_back(cluster);
475  }
476  }
477  joinNodeClusters(clusters, dc, ec, tlc);
478  myClusters2Join.clear(); // make save for recompute
479  return (int)clusters.size();
480 }
481 
482 
483 unsigned int
485  NodeClusters cands;
486  NodeClusters clusters;
487  generateNodeClusters(maxDist, cands);
488  for (NodeClusters::iterator i = cands.begin(); i != cands.end(); ++i) {
489  std::set<NBNode*> cluster = (*i);
490  // remove join exclusions
491  for (std::set<NBNode*>::iterator j = cluster.begin(); j != cluster.end();) {
492  std::set<NBNode*>::iterator check = j;
493  ++j;
494  if (myJoinExclusions.count((*check)->getID()) > 0) {
495  cluster.erase(check);
496  }
497  }
498  // iteratively remove the fringe
499  bool pruneFringe = true;
500  while (pruneFringe) {
501  pruneFringe = false;
502  for (std::set<NBNode*>::iterator j = cluster.begin(); j != cluster.end();) {
503  std::set<NBNode*>::iterator check = j;
504  NBNode* n = *check;
505  ++j;
506  // remove geometry-like nodes at fringe of the cluster
507  // (they have 1 neighbor in the cluster and at most 1 neighbor outside the cluster)
508  std::set<NBNode*> neighbors;
509  std::set<NBNode*> clusterNeigbors;
510  for (EdgeVector::const_iterator it_edge = n->getOutgoingEdges().begin(); it_edge != n->getOutgoingEdges().end(); ++it_edge) {
511  NBNode* neighbor = (*it_edge)->getToNode();
512  if (cluster.count(neighbor) == 0) {
513  neighbors.insert(neighbor);
514  } else {
515  clusterNeigbors.insert(neighbor);
516  }
517  }
518  for (EdgeVector::const_iterator it_edge = n->getIncomingEdges().begin(); it_edge != n->getIncomingEdges().end(); ++it_edge) {
519  NBNode* neighbor = (*it_edge)->getFromNode();
520  if (cluster.count(neighbor) == 0) {
521  neighbors.insert(neighbor);
522  } else {
523  clusterNeigbors.insert(neighbor);
524  }
525  }
526  if (neighbors.size() <= 1 && clusterNeigbors.size() == 1) {
527  cluster.erase(check);
528  pruneFringe = true; // other nodes could belong to the fringe now
529  }
530  }
531  }
532  // exclude the fromNode of a long edge if the toNode is in the cluster (and they were both added via an alternative path).
533  std::set<NBNode*> toRemove;
534  for (std::set<NBNode*>::iterator j = cluster.begin(); j != cluster.end(); ++j) {
535  NBNode* n = *j;
536  const EdgeVector& edges = n->getOutgoingEdges();
537  for (EdgeVector::const_iterator it_edge = edges.begin(); it_edge != edges.end(); ++it_edge) {
538  NBEdge* edge = *it_edge;
539  if (cluster.count(edge->getToNode()) != 0 && edge->getLoadedLength() > maxDist) {
540  //std::cout << "long edge " << edge->getID() << " (" << edge->getLoadedLength() << ", max=" << maxDist << ")\n";
541  toRemove.insert(n);
542  toRemove.insert(edge->getToNode());
543  }
544  }
545  }
546  for (std::set<NBNode*>::iterator j = toRemove.begin(); j != toRemove.end(); ++j) {
547  cluster.erase(*j);
548  }
549  if (cluster.size() > 1) {
550  // check for clusters which are to complex and probably won't work very well
551  // we count the incoming edges of the final junction
552  std::map<std::string, SUMOReal> finalIncomingAngles;
553  std::map<std::string, SUMOReal> finalOutgoingAngles;
554  std::vector<std::string> nodeIDs;
555  for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) {
556  nodeIDs.push_back((*j)->getID());
557  for (EdgeVector::const_iterator it_edge = (*j)->getIncomingEdges().begin(); it_edge != (*j)->getIncomingEdges().end(); ++it_edge) {
558  NBEdge* edge = *it_edge;
559  if (cluster.count(edge->getFromNode()) == 0) {
560  // incoming edge, does not originate in the cluster
561  finalIncomingAngles[edge->getID()] = edge->getAngleAtNode(edge->getToNode());
562  }
563  }
564  for (EdgeVector::const_iterator it_edge = (*j)->getOutgoingEdges().begin(); it_edge != (*j)->getOutgoingEdges().end(); ++it_edge) {
565  NBEdge* edge = *it_edge;
566  if (cluster.count(edge->getToNode()) == 0) {
567  // outgoing edge, does not end in the cluster
568  finalOutgoingAngles[edge->getID()] = edge->getAngleAtNode(edge->getFromNode());
569  }
570  }
571 
572  }
573  if (finalIncomingAngles.size() > 4) {
574  std::sort(nodeIDs.begin(), nodeIDs.end());
575  WRITE_WARNING("Not joining junctions " + joinToStringSorting(nodeIDs, ',') + " because the cluster is too complex (" + toString(finalIncomingAngles.size()) + " incoming edges)");
576  } else {
577  // check for incoming parallel edges
578  const SUMOReal PARALLEL_INCOMING_THRESHOLD = 10.0;
579  bool foundParallel = false;
580  for (std::map<std::string, SUMOReal>::const_iterator j = finalIncomingAngles.begin(); j != finalIncomingAngles.end() && !foundParallel; ++j) {
581  std::map<std::string, SUMOReal>::const_iterator k = j;
582  for (++k; k != finalIncomingAngles.end() && !foundParallel; ++k) {
583  if (fabs(j->second - k->second) < PARALLEL_INCOMING_THRESHOLD) {
584  WRITE_WARNING("Not joining junctions " + joinToStringSorting(nodeIDs, ',') + " because the cluster is too complex (parallel incoming "
585  + j->first + "," + k->first + ")");
586  foundParallel = true;
587  }
588  }
589  }
590  // check for outgoing parallel edges
591  for (std::map<std::string, SUMOReal>::const_iterator j = finalOutgoingAngles.begin(); j != finalOutgoingAngles.end() && !foundParallel; ++j) {
592  std::map<std::string, SUMOReal>::const_iterator k = j;
593  for (++k; k != finalOutgoingAngles.end() && !foundParallel; ++k) {
594  if (fabs(j->second - k->second) < PARALLEL_INCOMING_THRESHOLD) {
595  WRITE_WARNING("Not joining junctions " + joinToStringSorting(nodeIDs, ',') + " because the cluster is too complex (parallel outgoing "
596  + j->first + "," + k->first + ")");
597  foundParallel = true;
598  }
599  }
600  }
601  if (!foundParallel && cluster.size() > 1) {
602  // compute all connected components of this cluster
603  // (may be more than 1 if intermediate nodes were removed)
604  NodeClusters components;
605  for (std::set<NBNode*>::iterator j = cluster.begin(); j != cluster.end(); ++j) {
606  // merge all connected components into newComp
607  std::set<NBNode*> newComp;
608  NBNode* current = *j;
609  //std::cout << "checking connectivity for " << current->getID() << "\n";
610  newComp.insert(current);
611  for (NodeClusters::iterator it_comp = components.begin(); it_comp != components.end();) {
612  NodeClusters::iterator check = it_comp;
613  //std::cout << " connected with " << toString(*check) << "?\n";
614  bool connected = false;
615  for (std::set<NBNode*>::iterator k = (*check).begin(); k != (*check).end(); ++k) {
616  if (current->getConnectionTo(*k) != 0 || (*k)->getConnectionTo(current) != 0) {
617  //std::cout << "joining with connected component " << toString(*check) << "\n";
618  newComp.insert((*check).begin(), (*check).end());
619  it_comp = components.erase(check);
620  connected = true;
621  break;
622  }
623  }
624  if (!connected) {
625  it_comp++;
626  }
627  }
628  //std::cout << "adding new component " << toString(newComp) << "\n";
629  components.push_back(newComp);
630  }
631  for (NodeClusters::iterator it_comp = components.begin(); it_comp != components.end(); ++it_comp) {
632  if ((*it_comp).size() > 1) {
633  //std::cout << "adding cluster " << toString(*it_comp) << "\n";
634  clusters.push_back(*it_comp);
635  }
636  }
637  }
638  }
639  }
640  }
641  joinNodeClusters(clusters, dc, ec, tlc);
642  return (int)clusters.size();
643 }
644 
645 
646 void
649  for (NodeClusters::iterator i = clusters.begin(); i != clusters.end(); ++i) {
650  std::set<NBNode*> cluster = *i;
651  assert(cluster.size() > 1);
652  Position pos;
653  bool setTL;
654  std::string id;
655  TrafficLightType type;
656  analyzeCluster(cluster, id, pos, setTL, type);
657  if (!insert(id, pos)) {
658  // should not fail
659  WRITE_WARNING("Could not join junctions " + id);
660  continue;
661  }
662  NBNode* newNode = retrieve(id);
663  if (setTL) {
664  NBTrafficLightDefinition* tlDef = new NBOwnTLDef(id, newNode, 0, type);
665  if (!tlc.insert(tlDef)) {
666  // actually, nothing should fail here
667  delete tlDef;
668  throw ProcessError("Could not allocate tls '" + id + "'.");
669  }
670  }
671  // collect edges
672  std::set<NBEdge*> allEdges;
673  for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) {
674  const EdgeVector& edges = (*j)->getEdges();
675  allEdges.insert(edges.begin(), edges.end());
676  }
677 
678  // remap and remove edges which are completely within the new intersection
679  for (std::set<NBEdge*>::iterator j = allEdges.begin(); j != allEdges.end();) {
680  NBEdge* e = (*j);
681  NBNode* from = e->getFromNode();
682  NBNode* to = e->getToNode();
683  if (cluster.count(from) > 0 && cluster.count(to) > 0) {
684  for (std::set<NBEdge*>::iterator l = allEdges.begin(); l != allEdges.end(); ++l) {
685  if (e != *l) {
686  (*l)->replaceInConnections(e, e->getConnections());
687  }
688  }
689  ec.erase(dc, e);
690  allEdges.erase(j++); // erase does not invalidate the other iterators
691  } else {
692  ++j;
693  }
694  }
695 
696  // remap edges which are incoming / outgoing
697  for (std::set<NBEdge*>::iterator j = allEdges.begin(); j != allEdges.end(); ++j) {
698  NBEdge* e = (*j);
699  std::vector<NBEdge::Connection> conns = e->getConnections();
700  const bool outgoing = cluster.count(e->getFromNode()) > 0;
701  NBNode* from = outgoing ? newNode : e->getFromNode();
702  NBNode* to = outgoing ? e->getToNode() : newNode;
703  e->reinitNodes(from, to);
704  // re-add connections which previously existed and may still valid.
705  // connections to removed edges will be ignored
706  for (std::vector<NBEdge::Connection>::iterator k = conns.begin(); k != conns.end(); ++k) {
707  e->addLane2LaneConnection((*k).fromLane, (*k).toEdge, (*k).toLane, NBEdge::L2L_USER, false, (*k).mayDefinitelyPass);
708  }
709  }
710  // remove original nodes
711  registerJoinedCluster(cluster);
712  for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) {
713  erase(*j);
714  }
715  }
716 }
717 
718 
719 void
720 NBNodeCont::registerJoinedCluster(const std::set<NBNode*>& cluster) {
721  std::set<std::string> ids;
722  for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); j++) {
723  ids.insert((*j)->getID());
724  }
725  myJoinedClusters.push_back(ids);
726 }
727 
728 
729 void
730 NBNodeCont::analyzeCluster(std::set<NBNode*> cluster, std::string& id, Position& pos,
731  bool& hasTLS, TrafficLightType& type) {
732  id = "cluster";
733  hasTLS = false;
734  std::vector<std::string> member_ids;
735  bool ambiguousType = false;
736  for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); j++) {
737  member_ids.push_back((*j)->getID());
738  pos.add((*j)->getPosition());
739  // add a traffic light if any of the cluster members was controlled
740  if ((*j)->isTLControlled()) {
741  if (!hasTLS) {
742  // init type
743  type = (*(*j)->getControllingTLS().begin())->getType();
744  } else if (type != (*(*j)->getControllingTLS().begin())->getType()) {
745  ambiguousType = true;
746  }
747  hasTLS = true;
748  }
749  }
750  pos.mul(1.0 / cluster.size());
751  // need to sort the member names to make the output deterministic
752  sort(member_ids.begin(), member_ids.end());
753  for (std::vector<std::string>::iterator j = member_ids.begin(); j != member_ids.end(); j++) {
754  id = id + "_" + (*j);
755  }
756  if (ambiguousType) {
757  type = SUMOXMLDefinitions::TrafficLightTypes.get(OptionsCont::getOptions().getString("tls.default-type"));
758  WRITE_WARNING("Ambiguous traffic light type for node cluster '" + id + "' set to '" + toString(type) + "'");
759  }
760 }
761 
762 
763 // ----------- (Helper) methods for guessing/computing traffic lights
764 bool
765 NBNodeCont::shouldBeTLSControlled(const std::set<NBNode*>& c) const {
766  unsigned int noIncoming = 0;
767  unsigned int noOutgoing = 0;
768  bool tooFast = false;
769  SUMOReal f = 0;
770  std::set<NBEdge*> seen;
771  for (std::set<NBNode*>::const_iterator j = c.begin(); j != c.end(); ++j) {
772  const EdgeVector& edges = (*j)->getEdges();
773  for (EdgeVector::const_iterator k = edges.begin(); k != edges.end(); ++k) {
774  if (c.find((*k)->getFromNode()) != c.end() && c.find((*k)->getToNode()) != c.end()) {
775  continue;
776  }
777  if ((*j)->hasIncoming(*k)) {
778  ++noIncoming;
779  f += (SUMOReal)(*k)->getNumLanes() * (*k)->getLaneSpeed(0);
780  } else {
781  ++noOutgoing;
782  }
783  if ((*k)->getLaneSpeed(0) * 3.6 > 79) {
784  tooFast = true;
785  }
786  }
787  }
788  return !tooFast && f >= 150. / 3.6 && c.size() != 0;
789 }
790 
791 
792 void
794  // build list of definitely not tls-controlled junctions
795  std::vector<NBNode*> ncontrolled;
796  if (oc.isSet("tls.unset")) {
797  std::vector<std::string> notTLControlledNodes = oc.getStringVector("tls.unset");
798  for (std::vector<std::string>::const_iterator i = notTLControlledNodes.begin(); i != notTLControlledNodes.end(); ++i) {
799  NBNode* n = NBNodeCont::retrieve(*i);
800  if (n == 0) {
801  throw ProcessError(" The node '" + *i + "' to set as not-controlled is not known.");
802  }
803  std::set<NBTrafficLightDefinition*> tls = n->getControllingTLS();
804  for (std::set<NBTrafficLightDefinition*>::const_iterator j = tls.begin(); j != tls.end(); ++j) {
805  (*j)->removeNode(n);
806  }
807  n->removeTrafficLights();
808  ncontrolled.push_back(n);
809  }
810  }
811 
813  // loop#1 checking whether the node shall be tls controlled,
814  // because it is assigned to a district
815  if (oc.exists("tls.taz-nodes") && oc.getBool("tls.taz-nodes")) {
816  for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
817  NBNode* cur = (*i).second;
818  if (cur->isNearDistrict() && find(ncontrolled.begin(), ncontrolled.end(), cur) == ncontrolled.end()) {
819  setAsTLControlled(cur, tlc, type);
820  }
821  }
822  }
823 
824  // figure out which nodes mark the locations of TLS signals
825  // This assumes nodes are already joined
826  if (oc.exists("tls.guess-signals") && oc.getBool("tls.guess-signals")) {
827  // prepare candidate edges
828  const SUMOReal signalDist = oc.getFloat("tls.guess-signals.dist");
829  for (std::map<std::string, NBNode*>::const_iterator i = myNodes.begin(); i != myNodes.end(); ++i) {
830  NBNode* node = (*i).second;
831  if (node->isTLControlled() && node->geometryLike()) {
832  const EdgeVector& outgoing = node->getOutgoingEdges();
833  for (EdgeVector::const_iterator it_o = outgoing.begin(); it_o != outgoing.end(); ++it_o) {
834  (*it_o)->setSignalOffset((*it_o)->getLength());
835  }
836  }
837  }
838  // check which nodes should be controlled
839  for (std::map<std::string, NBNode*>::const_iterator i = myNodes.begin(); i != myNodes.end(); ++i) {
840  NBNode* node = i->second;
841  const EdgeVector& incoming = node->getIncomingEdges();
842  if (!node->isTLControlled() && incoming.size() > 1 && !node->geometryLike()) {
843  std::vector<NBNode*> signals;
844  bool isTLS = true;
845  for (EdgeVector::const_iterator it_i = incoming.begin(); it_i != incoming.end(); ++it_i) {
846  const NBEdge* inEdge = *it_i;
847  if (inEdge->getSignalOffset() == NBEdge::UNSPECIFIED_SIGNAL_OFFSET || inEdge->getSignalOffset() > signalDist) {
848  isTLS = false;
849  break;
850  }
851  if (inEdge->getSignalOffset() == inEdge->getLength()) {
852  signals.push_back(inEdge->getFromNode());
853  }
854  }
855  if (isTLS) {
856  for (std::vector<NBNode*>::iterator j = signals.begin(); j != signals.end(); ++j) {
857  std::set<NBTrafficLightDefinition*> tls = (*j)->getControllingTLS();
858  (*j)->removeTrafficLights();
859  for (std::set<NBTrafficLightDefinition*>::iterator k = tls.begin(); k != tls.end(); ++k) {
860  tlc.removeFully((*j)->getID());
861  }
862  }
863  NBTrafficLightDefinition* tlDef = new NBOwnTLDef("GS_" + node->getID(), node, 0, TLTYPE_STATIC);
864  // @todo patch endOffset for all incoming lanes according to the signal positions
865  if (!tlc.insert(tlDef)) {
866  // actually, nothing should fail here
867  WRITE_WARNING("Could not build joined tls '" + node->getID() + "'.");
868  delete tlDef;
869  return;
870  }
871  }
872  }
873  }
874  }
875 
876  // maybe no tls shall be guessed
877  if (!oc.getBool("tls.guess")) {
878  return;
879  }
880 
881  // guess joined tls first, if wished
882  if (oc.getBool("tls.join")) {
883  // get node clusters
884  std::vector<std::set<NBNode*> > cands;
885  generateNodeClusters(oc.getFloat("tls.join-dist"), cands);
886  // check these candidates (clusters) whether they should be controlled by a tls
887  for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end();) {
888  std::set<NBNode*>& c = (*i);
889  // regard only junctions which are not yet controlled and are not
890  // forbidden to be controlled
891  for (std::set<NBNode*>::iterator j = c.begin(); j != c.end();) {
892  if ((*j)->isTLControlled() || find(ncontrolled.begin(), ncontrolled.end(), *j) != ncontrolled.end()) {
893  c.erase(j++);
894  } else {
895  ++j;
896  }
897  }
898  // check whether the cluster should be controlled
899  if (!shouldBeTLSControlled(c)) {
900  i = cands.erase(i);
901  } else {
902  ++i;
903  }
904  }
905  // cands now only contain sets of junctions that shall be joined into being tls-controlled
906  unsigned int index = 0;
907  for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end(); ++i) {
908  std::vector<NBNode*> nodes;
909  for (std::set<NBNode*>::iterator j = (*i).begin(); j != (*i).end(); j++) {
910  nodes.push_back(*j);
911  }
912  std::string id = "joinedG_" + toString(index++);
913  NBTrafficLightDefinition* tlDef = new NBOwnTLDef(id, nodes, 0, type);
914  if (!tlc.insert(tlDef)) {
915  // actually, nothing should fail here
916  WRITE_WARNING("Could not build guessed, joined tls");
917  delete tlDef;
918  return;
919  }
920  }
921  }
922 
923  // guess tls
924  for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
925  NBNode* cur = (*i).second;
926  // do nothing if already is tl-controlled
927  if (cur->isTLControlled()) {
928  continue;
929  }
930  // do nothing if in the list of explicit non-controlled junctions
931  if (find(ncontrolled.begin(), ncontrolled.end(), cur) != ncontrolled.end()) {
932  continue;
933  }
934  std::set<NBNode*> c;
935  c.insert(cur);
936  if (!shouldBeTLSControlled(c) || cur->getIncomingEdges().size() < 3) {
937  continue;
938  }
939  setAsTLControlled((*i).second, tlc, type);
940  }
941 }
942 
943 
944 void
946  std::vector<std::set<NBNode*> > cands;
947  generateNodeClusters(maxdist, cands);
948  unsigned int index = 0;
949  for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end(); ++i) {
950  std::set<NBNode*>& c = (*i);
951  for (std::set<NBNode*>::iterator j = c.begin(); j != c.end();) {
952  if (!(*j)->isTLControlled()) {
953  c.erase(j++);
954  } else {
955  ++j;
956  }
957  }
958  if (c.size() < 2) {
959  continue;
960  }
961  // figure out type of the joined TLS
962  Position dummyPos;
963  bool dummySetTL;
964  std::string dummyId;
965  TrafficLightType type;
966  analyzeCluster(c, dummyId, dummyPos, dummySetTL, type);
967  for (std::set<NBNode*>::iterator j = c.begin(); j != c.end(); ++j) {
968  std::set<NBTrafficLightDefinition*> tls = (*j)->getControllingTLS();
969  (*j)->removeTrafficLights();
970  for (std::set<NBTrafficLightDefinition*>::iterator k = tls.begin(); k != tls.end(); ++k) {
971  tlc.removeFully((*j)->getID());
972  }
973  }
974  std::string id = "joinedS_" + toString(index++);
975  std::vector<NBNode*> nodes;
976  for (std::set<NBNode*>::iterator j = c.begin(); j != c.end(); j++) {
977  nodes.push_back(*j);
978  }
979  NBTrafficLightDefinition* tlDef = new NBOwnTLDef(id, nodes, 0, type);
980  if (!tlc.insert(tlDef)) {
981  // actually, nothing should fail here
982  WRITE_WARNING("Could not build a joined tls.");
983  delete tlDef;
984  return;
985  }
986  }
987 }
988 
989 
990 void
992  TrafficLightType type, std::string id) {
993  if (id == "") {
994  id = node->getID();
995  }
996  NBTrafficLightDefinition* tlDef = new NBOwnTLDef(id, node, 0, type);
997  if (!tlc.insert(tlDef)) {
998  // actually, nothing should fail here
999  WRITE_WARNING("Building a tl-logic for node '" + id + "' twice is not possible.");
1000  delete tlDef;
1001  return;
1002  }
1003 }
1004 
1005 
1006 // -----------
1007 void
1008 NBNodeCont::computeLanes2Lanes(const bool buildCrossingsAndWalkingAreas) {
1009  for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
1010  (*i).second->computeLanes2Lanes(buildCrossingsAndWalkingAreas);
1011  }
1012 }
1013 
1014 
1015 // computes the "wheel" of incoming and outgoing edges for every node
1016 void
1018  for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
1019  (*i).second->computeLogic(ec, oc);
1020  }
1021 }
1022 
1023 
1024 void
1026  for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
1027  delete((*i).second);
1028  }
1029  myNodes.clear();
1030  for (std::set<NBNode*>::iterator i = myExtractedNodes.begin(); i != myExtractedNodes.end(); i++) {
1031  delete(*i);
1032  }
1033  myExtractedNodes.clear();
1034 }
1035 
1036 
1037 std::string
1039  // !!! not guaranteed to be free
1040  std::string ret = "SUMOGenerated" + toString<int>(size());
1041  assert(retrieve(ret) == 0);
1042  return ret;
1043 }
1044 
1045 
1046 void
1047 NBNodeCont::computeNodeShapes(bool leftHand, SUMOReal mismatchThreshold) {
1048  for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
1049  (*i).second->computeNodeShape(leftHand, mismatchThreshold);
1050  }
1051 }
1052 
1053 
1054 void
1056  int numUnregulatedJunctions = 0;
1057  int numDeadEndJunctions = 0;
1058  int numPriorityJunctions = 0;
1059  int numRightBeforeLeftJunctions = 0;
1060  int numAllWayStopJunctions = 0;
1061  int numRailSignals = 0;
1062  for (NodeCont::const_iterator i = myNodes.begin(); i != myNodes.end(); i++) {
1063  switch ((*i).second->getType()) {
1064  case NODETYPE_NOJUNCTION:
1066  ++numUnregulatedJunctions;
1067  break;
1068  case NODETYPE_DEAD_END:
1069  ++numDeadEndJunctions;
1070  break;
1071  case NODETYPE_PRIORITY:
1074  ++numPriorityJunctions;
1075  break;
1077  ++numRightBeforeLeftJunctions;
1078  break;
1079  case NODETYPE_ALLWAY_STOP:
1080  ++numAllWayStopJunctions;
1081  break;
1082  case NODETYPE_DISTRICT:
1083  ++numRightBeforeLeftJunctions;
1084  break;
1085  case NODETYPE_UNKNOWN:
1086  break;
1087  case NODETYPE_RAIL_SIGNAL:
1088  ++numRailSignals;
1089  break;
1090  default:
1091  break;
1092  }
1093  }
1094  WRITE_MESSAGE(" Node type statistics:");
1095  WRITE_MESSAGE(" Unregulated junctions : " + toString(numUnregulatedJunctions));
1096  if (numDeadEndJunctions > 0) {
1097  WRITE_MESSAGE(" Dead-end junctions : " + toString(numDeadEndJunctions));
1098  }
1099  WRITE_MESSAGE(" Priority junctions : " + toString(numPriorityJunctions));
1100  WRITE_MESSAGE(" Right-before-left junctions : " + toString(numRightBeforeLeftJunctions));
1101  if (numAllWayStopJunctions > 0) {
1102  WRITE_MESSAGE(" All-way stop junctions : " + toString(numAllWayStopJunctions));
1103  }
1104  if (numRailSignals > 0) {
1105  WRITE_MESSAGE(" Rail signal junctions : " + toString(numRailSignals));
1106  }
1107 }
1108 
1109 
1110 std::vector<std::string>
1112  std::vector<std::string> ret;
1113  for (NodeCont::const_iterator i = myNodes.begin(); i != myNodes.end(); ++i) {
1114  ret.push_back((*i).first);
1115  }
1116  return ret;
1117 }
1118 
1119 
1120 void
1121 NBNodeCont::rename(NBNode* node, const std::string& newID) {
1122  if (myNodes.count(newID) != 0) {
1123  throw ProcessError("Attempt to rename node using existing id '" + newID + "'");
1124  }
1125  myNodes.erase(node->getID());
1126  node->setID(newID);
1127  myNodes[newID] = node;
1128 }
1129 
1130 
1131 void
1132 NBNodeCont::discardTrafficLights(NBTrafficLightLogicCont& tlc, bool geometryLike, bool guessSignals) {
1133  for (NodeCont::const_iterator i = myNodes.begin(); i != myNodes.end(); ++i) {
1134  NBNode* node = i->second;
1135  if (!geometryLike || node->geometryLike()) {
1136  // make a copy of tldefs
1137  const std::set<NBTrafficLightDefinition*> tldefs = node->getControllingTLS();
1138  if (guessSignals && node->isTLControlled() && node->geometryLike()) {
1139  // record signal location
1140  const EdgeVector& outgoing = node->getOutgoingEdges();
1141  for (EdgeVector::const_iterator it_o = outgoing.begin(); it_o != outgoing.end(); ++it_o) {
1142  (*it_o)->setSignalOffset((*it_o)->getLength());
1143  }
1144  }
1145  for (std::set<NBTrafficLightDefinition*>::const_iterator it = tldefs.begin(); it != tldefs.end(); ++it) {
1146  NBTrafficLightDefinition* tlDef = *it;
1147  node->removeTrafficLight(tlDef);
1148  tlc.extract(tlDef);
1149  }
1150  node->reinit(node->getPosition(), NODETYPE_UNKNOWN);
1151  }
1152  }
1153 }
1154 
1155 /****************************************************************************/
1156 
std::string getFreeID()
std::set< std::string > myJoinExclusions
Definition: NBNodeCont.h:377
NodeCont myNodes
The map of names to nodes.
Definition: NBNodeCont.h:371
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
Definition: NamedRTree.h:90
void joinSimilarEdges(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins edges connecting the same nodes.
Definition: NBNodeCont.cpp:179
void replaceIncoming(NBEdge *which, NBEdge *by, unsigned int laneOff)
Replaces occurences of the first edge within the list of incoming by the second Connections are remap...
Definition: NBNode.cpp:917
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges.
Definition: NBNode.h:251
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
void computeNodeShapes(bool leftHand, SUMOReal mismatchThreshold=-1)
Compute the junction shape for this node.
std::vector< std::string > getAllNames() const
Returns all ids of known edges.
Definition: NBEdgeCont.cpp:504
static const SUMOReal UNSPECIFIED_SIGNAL_OFFSET
unspecified signal offset
Definition: NBEdge.h:210
void addJoinExclusion(const std::vector< std::string > &ids, bool check=false)
Definition: NBNodeCont.cpp:426
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:119
unsigned int removeUnwishedNodes(NBDistrictCont &dc, NBEdgeCont &ec, NBJoinedEdgesMap &je, NBTrafficLightLogicCont &tlc, bool removeGeometryNodes)
Removes "unwished" nodes.
Definition: NBNodeCont.cpp:323
A container for traffic light definitions and built programs.
void reinit(const Position &position, SumoXMLNodeType type, bool updateEdgeGeometries=false)
Resets initial values.
Definition: NBNode.cpp:261
bool isTLControlled() const
Returns whether this node is controlled by any tls.
Definition: NBNode.h:309
unsigned int joinJunctions(SUMOReal maxDist, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins junctions that are very close together.
Definition: NBNodeCont.cpp:484
std::vector< std::set< std::string > > myJoinedClusters
Definition: NBNodeCont.h:382
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
The representation of a single edge during network building.
Definition: NBEdge.h:71
void reinitNodes(NBNode *from, NBNode *to)
Resets nodes but keeps all other values the same (used when joining)
Definition: NBEdge.cpp:311
A container for districts.
The base class for traffic light logic definitions.
bool addLane2LaneConnection(unsigned int fromLane, NBEdge *dest, unsigned int toLane, Lane2LaneInfoType type, bool mayUseSameDestination=false, bool mayDefinitelyPass=false)
Adds a connection between the specified this edge's lane and an approached one.
Definition: NBEdge.cpp:649
NamedRTree myRTree
node positions for faster lookup
Definition: NBNodeCont.h:388
void guessTLs(OptionsCont &oc, NBTrafficLightLogicCont &tlc)
Guesses which junctions or junction clusters shall be controlled by tls.
Definition: NBNodeCont.cpp:793
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
void avoidOverlap()
fix overlap
Definition: NBNodeCont.cpp:375
bool checkIsRemovable() const
Definition: NBNode.cpp:1380
void removeTrafficLight(NBTrafficLightDefinition *tlDef)
Removes the given traffic light from this node.
Definition: NBNode.cpp:304
void extract(NBTrafficLightDefinition *definition)
Extracts a traffic light definition from myDefinitions but keeps it in myExtracted for eventual * del...
bool hasIncoming(const NBEdge *const e) const
Returns whether the given edge ends at this node.
Definition: NBNode.cpp:1024
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
void computeLanes2Lanes(const bool buildCrossingsAndWalkingAreas)
divides the incoming lanes on outgoing lanes
std::string joinToStringSorting(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:175
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
void computeLogics(const NBEdgeCont &ec, OptionsCont &oc)
build the list of outgoing edges and lanes
void generateNodeClusters(SUMOReal maxDist, NodeClusters &into) const
Builds node clusters.
Definition: NBNodeCont.cpp:383
A class representing a single district.
Definition: NBDistrict.h:72
const EdgeVector & getOutgoingEdges() const
Returns this node's outgoing edges.
Definition: NBNode.h:259
SUMOReal getLoadedLength() const
Returns the length was set explicitly or the computed length if it wasn't set.
Definition: NBEdge.h:415
const std::string & getID() const
Returns the id.
Definition: Named.h:60
void Remove(const float a_min[2], const float a_max[2], Named *const &a_data)
Remove entry.
Definition: NamedRTree.h:101
unsigned int size() const
Returns the number of known nodes.
Definition: NBNodeCont.h:273
const Position & getPosition() const
Returns the position of this node.
Definition: NBNode.h:239
const std::set< NBTrafficLightDefinition * > & getControllingTLS() const
Returns the traffic lights that were assigned to this node.
Definition: NBNode.h:323
~NBNodeCont()
Destructor.
Definition: NBNodeCont.cpp:72
void joinTLS(NBTrafficLightLogicCont &tlc, SUMOReal maxdist)
Builds clusters of tls-controlled junctions and joins the control if possible.
Definition: NBNodeCont.cpp:945
static StringBijection< TrafficLightType > TrafficLightTypes
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
NBNodeCont()
Constructor.
Definition: NBNodeCont.cpp:67
unsigned int joinLoadedClusters(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins loaded junction clusters (see NIXMLNodesHandler)
Definition: NBNodeCont.cpp:460
bool geometryLike() const
whether this is structurally similar to a geometry node
Definition: NBNode.cpp:2165
void removeTrafficLights()
Removes all references to traffic lights that control this tls.
Definition: NBNode.cpp:311
const EdgeVector & getEdges() const
Returns all edges which participate in this node.
Definition: NBNode.h:267
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
#define POSITION_EPS
Definition: config.h:189
void joinNodeClusters(NodeClusters clusters, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Definition: NBNodeCont.cpp:647
std::set< NBNode * > myExtractedNodes
The extracted nodes which are kept for reference.
Definition: NBNodeCont.h:374
std::vector< std::string > getAllNames() const
get all node names
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
The connection was given by the user.
Definition: NBEdge.h:114
SUMOReal getSignalOffset() const
Returns the offset of a traffic signal from the end of this edge.
Definition: NBEdge.h:489
NBEdge * getConnectionTo(NBNode *n) const
Definition: NBNode.cpp:1484
bool shouldBeTLSControlled(const std::set< NBNode * > &c) const
Returns whethe the given node cluster should be controlled by a tls.
Definition: NBNodeCont.cpp:765
void rename(NBNode *node, const std::string &newID)
Renames the node. Throws exception if newID already exists.
std::vector< std::pair< NBEdge *, NBEdge * > > getEdgesToJoin() const
Definition: NBNode.cpp:1437
void joinSameNodeConnectingEdges(NBDistrictCont &dc, NBTrafficLightLogicCont &tlc, EdgeVector edges)
Joins the given edges because they connect the same nodes.
Definition: NBEdgeCont.cpp:634
void setAsTLControlled(NBNode *node, NBTrafficLightLogicCont &tlc, TrafficLightType type, std::string id="")
Sets the given node as being controlled by a tls.
Definition: NBNodeCont.cpp:991
Allows to store the object; used as context while traveling the rtree in TraCI.
Definition: Named.h:92
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:371
bool isNearDistrict() const
Definition: NBNode.cpp:1495
void setID(const std::string &newID)
resets the id
Definition: Named.h:68
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:258
void addCluster2Join(std::set< std::string > cluster)
add ids of nodes which shall be joined into a single node
Definition: NBNodeCont.cpp:442
A structure storing information about which edges were joined.
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:41
void analyzeCluster(std::set< NBNode * > cluster, std::string &id, Position &pos, bool &hasTLS, TrafficLightType &type)
Definition: NBNodeCont.cpp:730
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:229
std::set< std::string > myJoined
ids found in loaded join clusters used for error checking
Definition: NBNodeCont.h:385
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
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:331
void erase(NBDistrictCont &dc, NBEdge *edge)
Removes the given edge from the container (deleting it)
Definition: NBEdgeCont.cpp:373
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:79
void clear()
void mul(SUMOReal val)
Multiplies both positions with the given value.
Definition: Position.h:99
void append(NBEdge *continuation)
Definition: NBEdge.cpp:2003
std::vector< std::set< std::string > > myClusters2Join
Definition: NBNodeCont.h:380
void discardTrafficLights(NBTrafficLightLogicCont &tlc, bool geometryLike, bool guessSignals)
Represents a single node (junction) during network building.
Definition: NBNode.h:75
T get(const std::string &str) const
bool removeFully(const std::string id)
Removes a logic definition (and all programs) from the dictionary.
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
#define SUMOReal
Definition: config.h:218
bool isNearEnough2BeJoined2(NBEdge *e, SUMOReal threshold) const
Definition: NBEdge.cpp:2061
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:108
SUMOReal getSpeed() const
Returns the speed allowed on this edge.
Definition: NBEdge.h:431
void printBuiltNodesStatistics() const
Prints statistics about built nodes.
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces occurences of the removed edge/lane in all definitions by the given edge.
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:54
void appended(const std::string &to, const std::string &what)
Informs the map that two edges have been joined.
bool extract(NBNode *node, bool remember=false)
Removes the given node but does not delete it.
Definition: NBNodeCont.cpp:149
int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor &c) const
Find all within search rectangle.
Definition: NamedRTree.h:123
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
bool erase(NBNode *node)
Removes the given node, deleting it.
Definition: NBNodeCont.cpp:138
const std::vector< Connection > & getConnections() const
Returns the connections.
Definition: NBEdge.h:761
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:127
bool exists(const std::string &name) const
Returns the information whether the named option is known.
TrafficLightType
SUMOReal getLength() const
Returns the computed length of the edge.
Definition: NBEdge.h:406
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
SUMOReal getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge's geometry at the given node.
Definition: NBEdge.cpp:1245
void registerJoinedCluster(const std::set< NBNode * > &cluster)
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.cpp:720
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:363