SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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-2014 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 // ----------- (Helper) methods for joining nodes
375 void
377  std::set<NBNode*> visited;
378  for (NodeCont::const_iterator i = myNodes.begin(); i != myNodes.end(); i++) {
379  std::vector<NBNode*> toProc;
380  if (visited.find((*i).second) != visited.end()) {
381  continue;
382  }
383  toProc.push_back((*i).second);
384  std::set<NBNode*> c;
385  while (!toProc.empty()) {
386  NBNode* n = toProc.back();
387  toProc.pop_back();
388  if (visited.find(n) != visited.end()) {
389  continue;
390  }
391  c.insert(n);
392  visited.insert(n);
393  const EdgeVector& edges = n->getEdges();
394  for (EdgeVector::const_iterator j = edges.begin(); j != edges.end(); ++j) {
395  NBEdge* e = *j;
396  NBNode* s = 0;
397  if (n->hasIncoming(e)) {
398  s = e->getFromNode();
399  } else {
400  s = e->getToNode();
401  }
402  if (visited.find(s) != visited.end()) {
403  continue;
404  }
405  if (e->getLoadedLength() < maxDist) {
406  toProc.push_back(s);
407  }
408  }
409  }
410  if (c.size() < 2) {
411  continue;
412  }
413  into.push_back(c);
414  }
415 }
416 
417 
418 void
419 NBNodeCont::addJoinExclusion(const std::vector<std::string>& ids, bool check) {
420  for (std::vector<std::string>::const_iterator it = ids.begin(); it != ids.end(); it++) {
421  // error handling has to take place here since joinExclusions could be
422  // loaded from multiple files / command line
423  if (myJoined.count(*it) > 0) {
424  WRITE_WARNING("Ignoring join exclusion for node '" + *it + "' since it already occured in a list of nodes to be joined");
425  } else if (check && retrieve(*it) == 0) {
426  WRITE_WARNING("Ignoring join exclusion for unknown node '" + *it + "'");
427  } else {
428  myJoinExclusions.insert(*it);
429  }
430  }
431 }
432 
433 
434 void
435 NBNodeCont::addCluster2Join(std::set<std::string> cluster) {
436  // error handling has to take place here since joins could be loaded from multiple files
437  for (std::set<std::string>::const_iterator it = cluster.begin(); it != cluster.end(); it++) {
438  if (myJoinExclusions.count(*it) > 0) {
439  WRITE_WARNING("Ignoring join-cluster because node '" + *it + "' was already excluded from joining");
440  return;
441  } else if (myJoined.count(*it) > 0) {
442  WRITE_WARNING("Ignoring join-cluster because node '" + *it + "' already occured in another join-cluster");
443  return;
444  } else {
445  myJoined.insert(*it);
446  }
447  }
448  myClusters2Join.push_back(cluster);
449 }
450 
451 
452 unsigned int
454  NodeClusters clusters;
455  for (std::vector<std::set<std::string> >::iterator it = myClusters2Join.begin(); it != myClusters2Join.end(); it++) {
456  // verify loaded cluster
457  std::set<NBNode*> cluster;
458  for (std::set<std::string>::iterator it_id = it->begin(); it_id != it->end(); it_id++) {
459  NBNode* node = retrieve(*it_id);
460  if (node == 0) {
461  WRITE_WARNING("Ignoring unknown node '" + *it_id + "' while joining");
462  } else {
463  cluster.insert(node);
464  }
465  }
466  if (cluster.size() > 1) {
467  clusters.push_back(cluster);
468  }
469  }
470  joinNodeClusters(clusters, dc, ec, tlc);
471  myClusters2Join.clear(); // make save for recompute
472  return (int)clusters.size();
473 }
474 
475 
476 unsigned int
478  NodeClusters cands;
479  NodeClusters clusters;
480  generateNodeClusters(maxDist, cands);
481  for (NodeClusters::iterator i = cands.begin(); i != cands.end(); ++i) {
482  std::set<NBNode*> cluster = (*i);
483  // remove join exclusions
484  for (std::set<NBNode*>::iterator j = cluster.begin(); j != cluster.end();) {
485  std::set<NBNode*>::iterator check = j;
486  ++j;
487  if (myJoinExclusions.count((*check)->getID()) > 0) {
488  cluster.erase(check);
489  }
490  }
491  // iteratively remove the fringe
492  bool pruneFringe = true;
493  while (pruneFringe) {
494  pruneFringe = false;
495  for (std::set<NBNode*>::iterator j = cluster.begin(); j != cluster.end();) {
496  std::set<NBNode*>::iterator check = j;
497  NBNode* n = *check;
498  ++j;
499  // remove geometry-like nodes at fringe of the cluster
500  // (they have 1 neighbor in the cluster and at most 1 neighbor outside the cluster)
501  std::set<NBNode*> neighbors;
502  std::set<NBNode*> clusterNeigbors;
503  for (EdgeVector::const_iterator it_edge = n->getOutgoingEdges().begin(); it_edge != n->getOutgoingEdges().end(); ++it_edge) {
504  NBNode* neighbor = (*it_edge)->getToNode();
505  if (cluster.count(neighbor) == 0) {
506  neighbors.insert(neighbor);
507  } else {
508  clusterNeigbors.insert(neighbor);
509  }
510  }
511  for (EdgeVector::const_iterator it_edge = n->getIncomingEdges().begin(); it_edge != n->getIncomingEdges().end(); ++it_edge) {
512  NBNode* neighbor = (*it_edge)->getFromNode();
513  if (cluster.count(neighbor) == 0) {
514  neighbors.insert(neighbor);
515  } else {
516  clusterNeigbors.insert(neighbor);
517  }
518  }
519  if (neighbors.size() <= 1 && clusterNeigbors.size() == 1) {
520  cluster.erase(check);
521  pruneFringe = true; // other nodes could belong to the fringe now
522  }
523  }
524  }
525  // exclude the fromNode of a long edge if the toNode is in the cluster (and they were both added via an alternative path).
526  std::set<NBNode*> toRemove;
527  for (std::set<NBNode*>::iterator j = cluster.begin(); j != cluster.end(); ++j) {
528  NBNode* n = *j;
529  const EdgeVector& edges = n->getOutgoingEdges();
530  for (EdgeVector::const_iterator it_edge = edges.begin(); it_edge != edges.end(); ++it_edge) {
531  NBEdge* edge = *it_edge;
532  if (cluster.count(edge->getToNode()) != 0 && edge->getLoadedLength() > maxDist) {
533  //std::cout << "long edge " << edge->getID() << " (" << edge->getLoadedLength() << ", max=" << maxDist << ")\n";
534  toRemove.insert(n);
535  toRemove.insert(edge->getToNode());
536  }
537  }
538  }
539  for (std::set<NBNode*>::iterator j = toRemove.begin(); j != toRemove.end(); ++j) {
540  cluster.erase(*j);
541  }
542  if (cluster.size() > 1) {
543  // check for clusters which are to complex and probably won't work very well
544  // we count the incoming edges of the final junction
545  std::map<std::string, SUMOReal> finalIncomingAngles;
546  std::map<std::string, SUMOReal> finalOutgoingAngles;
547  std::vector<std::string> nodeIDs;
548  for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) {
549  nodeIDs.push_back((*j)->getID());
550  for (EdgeVector::const_iterator it_edge = (*j)->getIncomingEdges().begin(); it_edge != (*j)->getIncomingEdges().end(); ++it_edge) {
551  NBEdge* edge = *it_edge;
552  if (cluster.count(edge->getFromNode()) == 0) {
553  // incoming edge, does not originate in the cluster
554  finalIncomingAngles[edge->getID()] = edge->getAngleAtNode(edge->getToNode());
555  }
556  }
557  for (EdgeVector::const_iterator it_edge = (*j)->getOutgoingEdges().begin(); it_edge != (*j)->getOutgoingEdges().end(); ++it_edge) {
558  NBEdge* edge = *it_edge;
559  if (cluster.count(edge->getToNode()) == 0) {
560  // outgoing edge, does not end in the cluster
561  finalOutgoingAngles[edge->getID()] = edge->getAngleAtNode(edge->getFromNode());
562  }
563  }
564 
565  }
566  if (finalIncomingAngles.size() > 4) {
567  std::sort(nodeIDs.begin(), nodeIDs.end());
568  WRITE_WARNING("Not joining junctions " + joinToStringSorting(nodeIDs, ',') + " because the cluster is too complex (" + toString(finalIncomingAngles.size()) + " incoming edges)");
569  } else {
570  // check for incoming parallel edges
571  const SUMOReal PARALLEL_INCOMING_THRESHOLD = 10.0;
572  bool foundParallel = false;
573  for (std::map<std::string, SUMOReal>::const_iterator j = finalIncomingAngles.begin(); j != finalIncomingAngles.end() && !foundParallel; ++j) {
574  std::map<std::string, SUMOReal>::const_iterator k = j;
575  for (++k; k != finalIncomingAngles.end() && !foundParallel; ++k) {
576  if (fabs(j->second - k->second) < PARALLEL_INCOMING_THRESHOLD) {
577  WRITE_WARNING("Not joining junctions " + joinToStringSorting(nodeIDs, ',') + " because the cluster is too complex (parallel incoming "
578  + j->first + "," + k->first + ")");
579  foundParallel = true;
580  }
581  }
582  }
583  // check for outgoing parallel edges
584  for (std::map<std::string, SUMOReal>::const_iterator j = finalOutgoingAngles.begin(); j != finalOutgoingAngles.end() && !foundParallel; ++j) {
585  std::map<std::string, SUMOReal>::const_iterator k = j;
586  for (++k; k != finalOutgoingAngles.end() && !foundParallel; ++k) {
587  if (fabs(j->second - k->second) < PARALLEL_INCOMING_THRESHOLD) {
588  WRITE_WARNING("Not joining junctions " + joinToStringSorting(nodeIDs, ',') + " because the cluster is too complex (parallel outgoing "
589  + j->first + "," + k->first + ")");
590  foundParallel = true;
591  }
592  }
593  }
594  if (!foundParallel && cluster.size() > 1) {
595  // compute all connected components of this cluster
596  // (may be more than 1 if intermediate nodes were removed)
597  NodeClusters components;
598  for (std::set<NBNode*>::iterator j = cluster.begin(); j != cluster.end(); ++j) {
599  // merge all connected components into newComp
600  std::set<NBNode*> newComp;
601  NBNode* current = *j;
602  //std::cout << "checking connectivity for " << current->getID() << "\n";
603  newComp.insert(current);
604  for (NodeClusters::iterator it_comp = components.begin(); it_comp != components.end();) {
605  NodeClusters::iterator check = it_comp;
606  //std::cout << " connected with " << toString(*check) << "?\n";
607  bool connected = false;
608  for (std::set<NBNode*>::iterator k = (*check).begin(); k != (*check).end(); ++k) {
609  if (current->getConnectionTo(*k) != 0 || (*k)->getConnectionTo(current) != 0) {
610  //std::cout << "joining with connected component " << toString(*check) << "\n";
611  newComp.insert((*check).begin(), (*check).end());
612  it_comp = components.erase(check);
613  connected = true;
614  break;
615  }
616  }
617  if (!connected) {
618  it_comp++;
619  }
620  }
621  //std::cout << "adding new component " << toString(newComp) << "\n";
622  components.push_back(newComp);
623  }
624  for (NodeClusters::iterator it_comp = components.begin(); it_comp != components.end(); ++it_comp) {
625  if ((*it_comp).size() > 1) {
626  //std::cout << "adding cluster " << toString(*it_comp) << "\n";
627  clusters.push_back(*it_comp);
628  }
629  }
630  }
631  }
632  }
633  }
634  joinNodeClusters(clusters, dc, ec, tlc);
635  return (int)clusters.size();
636 }
637 
638 
639 void
642  for (NodeClusters::iterator i = clusters.begin(); i != clusters.end(); ++i) {
643  std::set<NBNode*> cluster = *i;
644  assert(cluster.size() > 1);
645  Position pos;
646  bool setTL;
647  std::string id;
648  TrafficLightType type;
649  analyzeCluster(cluster, id, pos, setTL, type);
650  if (!insert(id, pos)) {
651  // should not fail
652  WRITE_WARNING("Could not join junctions " + id);
653  continue;
654  }
655  NBNode* newNode = retrieve(id);
656  if (setTL) {
657  NBTrafficLightDefinition* tlDef = new NBOwnTLDef(id, newNode, 0, type);
658  if (!tlc.insert(tlDef)) {
659  // actually, nothing should fail here
660  delete tlDef;
661  throw ProcessError("Could not allocate tls '" + id + "'.");
662  }
663  }
664  // collect edges
665  std::set<NBEdge*> allEdges;
666  for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) {
667  const EdgeVector& edges = (*j)->getEdges();
668  allEdges.insert(edges.begin(), edges.end());
669  }
670 
671  // remap and remove edges which are completely within the new intersection
672  for (std::set<NBEdge*>::iterator j = allEdges.begin(); j != allEdges.end();) {
673  NBEdge* e = (*j);
674  NBNode* from = e->getFromNode();
675  NBNode* to = e->getToNode();
676  if (cluster.count(from) > 0 && cluster.count(to) > 0) {
677  for (std::set<NBEdge*>::iterator l = allEdges.begin(); l != allEdges.end(); ++l) {
678  if (e != *l) {
679  (*l)->replaceInConnections(e, e->getConnections());
680  }
681  }
682  ec.erase(dc, e);
683  allEdges.erase(j++); // erase does not invalidate the other iterators
684  } else {
685  ++j;
686  }
687  }
688 
689  // remap edges which are incoming / outgoing
690  for (std::set<NBEdge*>::iterator j = allEdges.begin(); j != allEdges.end(); ++j) {
691  NBEdge* e = (*j);
692  std::vector<NBEdge::Connection> conns = e->getConnections();
693  const bool outgoing = cluster.count(e->getFromNode()) > 0;
694  NBNode* from = outgoing ? newNode : e->getFromNode();
695  NBNode* to = outgoing ? e->getToNode() : newNode;
696  e->reinitNodes(from, to);
697  // re-add connections which previously existed and may still valid.
698  // connections to removed edges will be ignored
699  for (std::vector<NBEdge::Connection>::iterator k = conns.begin(); k != conns.end(); ++k) {
700  e->addLane2LaneConnection((*k).fromLane, (*k).toEdge, (*k).toLane, NBEdge::L2L_USER, false, (*k).mayDefinitelyPass);
701  }
702  }
703  // remove original nodes
704  registerJoinedCluster(cluster);
705  for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) {
706  erase(*j);
707  }
708  }
709 }
710 
711 
712 void
713 NBNodeCont::registerJoinedCluster(const std::set<NBNode*>& cluster) {
714  std::set<std::string> ids;
715  for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); j++) {
716  ids.insert((*j)->getID());
717  }
718  myJoinedClusters.push_back(ids);
719 }
720 
721 
722 void
723 NBNodeCont::analyzeCluster(std::set<NBNode*> cluster, std::string& id, Position& pos,
724  bool& hasTLS, TrafficLightType& type) {
725  id = "cluster";
726  hasTLS = false;
727  std::vector<std::string> member_ids;
728  bool ambiguousType = false;
729  for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); j++) {
730  member_ids.push_back((*j)->getID());
731  pos.add((*j)->getPosition());
732  // add a traffic light if any of the cluster members was controlled
733  if ((*j)->isTLControlled()) {
734  if (!hasTLS) {
735  // init type
736  type = (*(*j)->getControllingTLS().begin())->getType();
737  } else if (type != (*(*j)->getControllingTLS().begin())->getType()) {
738  ambiguousType = true;
739  }
740  hasTLS = true;
741  }
742  }
743  pos.mul(1.0 / cluster.size());
744  // need to sort the member names to make the output deterministic
745  sort(member_ids.begin(), member_ids.end());
746  for (std::vector<std::string>::iterator j = member_ids.begin(); j != member_ids.end(); j++) {
747  id = id + "_" + (*j);
748  }
749  if (ambiguousType) {
750  type = SUMOXMLDefinitions::TrafficLightTypes.get(OptionsCont::getOptions().getString("tls.default-type"));
751  WRITE_WARNING("Ambiguous traffic light type for node cluster '" + id + "' set to '" + toString(type) + "'");
752  }
753 }
754 
755 
756 // ----------- (Helper) methods for guessing/computing traffic lights
757 bool
758 NBNodeCont::shouldBeTLSControlled(const std::set<NBNode*>& c) const {
759  unsigned int noIncoming = 0;
760  unsigned int noOutgoing = 0;
761  bool tooFast = false;
762  SUMOReal f = 0;
763  std::set<NBEdge*> seen;
764  for (std::set<NBNode*>::const_iterator j = c.begin(); j != c.end(); ++j) {
765  const EdgeVector& edges = (*j)->getEdges();
766  for (EdgeVector::const_iterator k = edges.begin(); k != edges.end(); ++k) {
767  if (c.find((*k)->getFromNode()) != c.end() && c.find((*k)->getToNode()) != c.end()) {
768  continue;
769  }
770  if ((*j)->hasIncoming(*k)) {
771  ++noIncoming;
772  f += (SUMOReal)(*k)->getNumLanes() * (*k)->getLaneSpeed(0);
773  } else {
774  ++noOutgoing;
775  }
776  if ((*k)->getLaneSpeed(0) * 3.6 > 79) {
777  tooFast = true;
778  }
779  }
780  }
781  return !tooFast && f >= 150. / 3.6 && c.size() != 0;
782 }
783 
784 
785 void
787  // build list of definitely not tls-controlled junctions
788  std::vector<NBNode*> ncontrolled;
789  if (oc.isSet("tls.unset")) {
790  std::vector<std::string> notTLControlledNodes = oc.getStringVector("tls.unset");
791  for (std::vector<std::string>::const_iterator i = notTLControlledNodes.begin(); i != notTLControlledNodes.end(); ++i) {
792  NBNode* n = NBNodeCont::retrieve(*i);
793  if (n == 0) {
794  throw ProcessError(" The node '" + *i + "' to set as not-controlled is not known.");
795  }
796  std::set<NBTrafficLightDefinition*> tls = n->getControllingTLS();
797  for (std::set<NBTrafficLightDefinition*>::const_iterator j = tls.begin(); j != tls.end(); ++j) {
798  (*j)->removeNode(n);
799  }
800  n->removeTrafficLights();
801  ncontrolled.push_back(n);
802  }
803  }
804 
806  // loop#1 checking whether the node shall be tls controlled,
807  // because it is assigned to a district
808  if (oc.exists("tls.taz-nodes") && oc.getBool("tls.taz-nodes")) {
809  for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
810  NBNode* cur = (*i).second;
811  if (cur->isNearDistrict() && find(ncontrolled.begin(), ncontrolled.end(), cur) == ncontrolled.end()) {
812  setAsTLControlled(cur, tlc, type);
813  }
814  }
815  }
816 
817  // figure out which nodes mark the locations of TLS signals
818  // This assumes nodes are already joined
819  if (oc.exists("tls.guess-signals") && oc.getBool("tls.guess-signals")) {
820  // prepare candidate edges
821  const SUMOReal signalDist = oc.getFloat("tls.guess-signals.dist");
822  for (std::map<std::string, NBNode*>::const_iterator i = myNodes.begin(); i != myNodes.end(); ++i) {
823  NBNode* node = (*i).second;
824  if (node->isTLControlled() && node->geometryLike()) {
825  const EdgeVector& outgoing = node->getOutgoingEdges();
826  for (EdgeVector::const_iterator it_o = outgoing.begin(); it_o != outgoing.end(); ++it_o) {
827  (*it_o)->setSignalOffset((*it_o)->getLength());
828  }
829  }
830  }
831  // check which nodes should be controlled
832  for (std::map<std::string, NBNode*>::const_iterator i = myNodes.begin(); i != myNodes.end(); ++i) {
833  NBNode* node = i->second;
834  const EdgeVector& incoming = node->getIncomingEdges();
835  if (!node->isTLControlled() && incoming.size() > 1 && !node->geometryLike()) {
836  std::vector<NBNode*> signals;
837  bool isTLS = true;
838  for (EdgeVector::const_iterator it_i = incoming.begin(); it_i != incoming.end(); ++it_i) {
839  const NBEdge* inEdge = *it_i;
840  if (inEdge->getSignalOffset() == NBEdge::UNSPECIFIED_SIGNAL_OFFSET || inEdge->getSignalOffset() > signalDist) {
841  isTLS = false;
842  break;
843  }
844  if (inEdge->getSignalOffset() == inEdge->getLength()) {
845  signals.push_back(inEdge->getFromNode());
846  }
847  }
848  if (isTLS) {
849  for (std::vector<NBNode*>::iterator j = signals.begin(); j != signals.end(); ++j) {
850  std::set<NBTrafficLightDefinition*> tls = (*j)->getControllingTLS();
851  (*j)->removeTrafficLights();
852  for (std::set<NBTrafficLightDefinition*>::iterator k = tls.begin(); k != tls.end(); ++k) {
853  tlc.removeFully((*j)->getID());
854  }
855  }
856  NBTrafficLightDefinition* tlDef = new NBOwnTLDef("GS_" + node->getID(), node, 0, TLTYPE_STATIC);
857  // @todo patch endOffset for all incoming lanes according to the signal positions
858  if (!tlc.insert(tlDef)) {
859  // actually, nothing should fail here
860  WRITE_WARNING("Could not build joined tls '" + node->getID() + "'.");
861  delete tlDef;
862  return;
863  }
864  }
865  }
866  }
867  }
868 
869  // maybe no tls shall be guessed
870  if (!oc.getBool("tls.guess")) {
871  return;
872  }
873 
874  // guess joined tls first, if wished
875  if (oc.getBool("tls.join")) {
876  // get node clusters
877  std::vector<std::set<NBNode*> > cands;
878  generateNodeClusters(oc.getFloat("tls.join-dist"), cands);
879  // check these candidates (clusters) whether they should be controlled by a tls
880  for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end();) {
881  std::set<NBNode*>& c = (*i);
882  // regard only junctions which are not yet controlled and are not
883  // forbidden to be controlled
884  for (std::set<NBNode*>::iterator j = c.begin(); j != c.end();) {
885  if ((*j)->isTLControlled() || find(ncontrolled.begin(), ncontrolled.end(), *j) != ncontrolled.end()) {
886  c.erase(j++);
887  } else {
888  ++j;
889  }
890  }
891  // check whether the cluster should be controlled
892  if (!shouldBeTLSControlled(c)) {
893  i = cands.erase(i);
894  } else {
895  ++i;
896  }
897  }
898  // cands now only contain sets of junctions that shall be joined into being tls-controlled
899  unsigned int index = 0;
900  for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end(); ++i) {
901  std::vector<NBNode*> nodes;
902  for (std::set<NBNode*>::iterator j = (*i).begin(); j != (*i).end(); j++) {
903  nodes.push_back(*j);
904  }
905  std::string id = "joinedG_" + toString(index++);
906  NBTrafficLightDefinition* tlDef = new NBOwnTLDef(id, nodes, 0, type);
907  if (!tlc.insert(tlDef)) {
908  // actually, nothing should fail here
909  WRITE_WARNING("Could not build guessed, joined tls");
910  delete tlDef;
911  return;
912  }
913  }
914  }
915 
916  // guess tls
917  for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
918  NBNode* cur = (*i).second;
919  // do nothing if already is tl-controlled
920  if (cur->isTLControlled()) {
921  continue;
922  }
923  // do nothing if in the list of explicit non-controlled junctions
924  if (find(ncontrolled.begin(), ncontrolled.end(), cur) != ncontrolled.end()) {
925  continue;
926  }
927  std::set<NBNode*> c;
928  c.insert(cur);
929  if (!shouldBeTLSControlled(c) || cur->getIncomingEdges().size() < 3) {
930  continue;
931  }
932  setAsTLControlled((*i).second, tlc, type);
933  }
934 }
935 
936 
937 void
939  std::vector<std::set<NBNode*> > cands;
940  generateNodeClusters(maxdist, cands);
941  unsigned int index = 0;
942  for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end(); ++i) {
943  std::set<NBNode*>& c = (*i);
944  for (std::set<NBNode*>::iterator j = c.begin(); j != c.end();) {
945  if (!(*j)->isTLControlled()) {
946  c.erase(j++);
947  } else {
948  ++j;
949  }
950  }
951  if (c.size() < 2) {
952  continue;
953  }
954  // figure out type of the joined TLS
955  Position dummyPos;
956  bool dummySetTL;
957  std::string dummyId;
958  TrafficLightType type;
959  analyzeCluster(c, dummyId, dummyPos, dummySetTL, type);
960  for (std::set<NBNode*>::iterator j = c.begin(); j != c.end(); ++j) {
961  std::set<NBTrafficLightDefinition*> tls = (*j)->getControllingTLS();
962  (*j)->removeTrafficLights();
963  for (std::set<NBTrafficLightDefinition*>::iterator k = tls.begin(); k != tls.end(); ++k) {
964  tlc.removeFully((*j)->getID());
965  }
966  }
967  std::string id = "joinedS_" + toString(index++);
968  std::vector<NBNode*> nodes;
969  for (std::set<NBNode*>::iterator j = c.begin(); j != c.end(); j++) {
970  nodes.push_back(*j);
971  }
972  NBTrafficLightDefinition* tlDef = new NBOwnTLDef(id, nodes, 0, type);
973  if (!tlc.insert(tlDef)) {
974  // actually, nothing should fail here
975  WRITE_WARNING("Could not build a joined tls.");
976  delete tlDef;
977  return;
978  }
979  }
980 }
981 
982 
983 void
985  TrafficLightType type, std::string id) {
986  if (id == "") {
987  id = node->getID();
988  }
989  NBTrafficLightDefinition* tlDef = new NBOwnTLDef(id, node, 0, type);
990  if (!tlc.insert(tlDef)) {
991  // actually, nothing should fail here
992  WRITE_WARNING("Building a tl-logic for node '" + id + "' twice is not possible.");
993  delete tlDef;
994  return;
995  }
996 }
997 
998 
999 // -----------
1000 void
1001 NBNodeCont::computeLanes2Lanes(const bool buildCrossingsAndWalkingAreas) {
1002  for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
1003  (*i).second->computeLanes2Lanes(buildCrossingsAndWalkingAreas);
1004  }
1005 }
1006 
1007 
1008 // computes the "wheel" of incoming and outgoing edges for every node
1009 void
1011  for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
1012  (*i).second->computeLogic(ec, oc);
1013  }
1014 }
1015 
1016 
1017 void
1019  for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
1020  delete((*i).second);
1021  }
1022  myNodes.clear();
1023  for (std::set<NBNode*>::iterator i = myExtractedNodes.begin(); i != myExtractedNodes.end(); i++) {
1024  delete(*i);
1025  }
1026  myExtractedNodes.clear();
1027 }
1028 
1029 
1030 std::string
1032  // !!! not guaranteed to be free
1033  std::string ret = "SUMOGenerated" + toString<int>(size());
1034  assert(retrieve(ret) == 0);
1035  return ret;
1036 }
1037 
1038 
1039 void
1040 NBNodeCont::computeNodeShapes(bool leftHand, SUMOReal mismatchThreshold) {
1041  for (NodeCont::iterator i = myNodes.begin(); i != myNodes.end(); i++) {
1042  (*i).second->computeNodeShape(leftHand, mismatchThreshold);
1043  }
1044 }
1045 
1046 
1047 void
1049  int numUnregulatedJunctions = 0;
1050  int numDeadEndJunctions = 0;
1051  int numPriorityJunctions = 0;
1052  int numRightBeforeLeftJunctions = 0;
1053  int numAllWayStopJunctions = 0;
1054  for (NodeCont::const_iterator i = myNodes.begin(); i != myNodes.end(); i++) {
1055  switch ((*i).second->getType()) {
1056  case NODETYPE_NOJUNCTION:
1058  ++numUnregulatedJunctions;
1059  break;
1060  case NODETYPE_DEAD_END:
1061  ++numDeadEndJunctions;
1062  break;
1063  case NODETYPE_PRIORITY:
1066  ++numPriorityJunctions;
1067  break;
1069  ++numRightBeforeLeftJunctions;
1070  break;
1071  case NODETYPE_ALLWAY_STOP:
1072  ++numAllWayStopJunctions;
1073  break;
1074  case NODETYPE_DISTRICT:
1075  ++numRightBeforeLeftJunctions;
1076  break;
1077  case NODETYPE_UNKNOWN:
1078  break;
1079  default:
1080  break;
1081  }
1082  }
1083  WRITE_MESSAGE(" Node type statistics:");
1084  WRITE_MESSAGE(" Unregulated junctions : " + toString(numUnregulatedJunctions));
1085  if (numDeadEndJunctions > 0) {
1086  WRITE_MESSAGE(" Dead-end junctions : " + toString(numDeadEndJunctions));
1087  }
1088  WRITE_MESSAGE(" Priority junctions : " + toString(numPriorityJunctions));
1089  WRITE_MESSAGE(" Right-before-left junctions : " + toString(numRightBeforeLeftJunctions));
1090  if (numAllWayStopJunctions > 0) {
1091  WRITE_MESSAGE(" All-way stop junctions : " + toString(numAllWayStopJunctions));
1092  }
1093 }
1094 
1095 
1096 std::vector<std::string>
1098  std::vector<std::string> ret;
1099  for (NodeCont::const_iterator i = myNodes.begin(); i != myNodes.end(); ++i) {
1100  ret.push_back((*i).first);
1101  }
1102  return ret;
1103 }
1104 
1105 
1106 void
1107 NBNodeCont::rename(NBNode* node, const std::string& newID) {
1108  if (myNodes.count(newID) != 0) {
1109  throw ProcessError("Attempt to rename node using existing id '" + newID + "'");
1110  }
1111  myNodes.erase(node->getID());
1112  node->setID(newID);
1113  myNodes[newID] = node;
1114 }
1115 
1116 
1117 void
1118 NBNodeCont::discardTrafficLights(NBTrafficLightLogicCont& tlc, bool geometryLike, bool guessSignals) {
1119  for (NodeCont::const_iterator i = myNodes.begin(); i != myNodes.end(); ++i) {
1120  NBNode* node = i->second;
1121  if (!geometryLike || node->geometryLike()) {
1122  // make a copy of tldefs
1123  const std::set<NBTrafficLightDefinition*> tldefs = node->getControllingTLS();
1124  if (guessSignals && node->isTLControlled() && node->geometryLike()) {
1125  // record signal location
1126  const EdgeVector& outgoing = node->getOutgoingEdges();
1127  for (EdgeVector::const_iterator it_o = outgoing.begin(); it_o != outgoing.end(); ++it_o) {
1128  (*it_o)->setSignalOffset((*it_o)->getLength());
1129  }
1130  }
1131  for (std::set<NBTrafficLightDefinition*>::const_iterator it = tldefs.begin(); it != tldefs.end(); ++it) {
1132  NBTrafficLightDefinition* tlDef = *it;
1133  node->removeTrafficLight(tlDef);
1134  tlc.extract(tlDef);
1135  }
1136  node->reinit(node->getPosition(), NODETYPE_UNKNOWN);
1137  }
1138  }
1139 }
1140 
1141 /****************************************************************************/
1142 
std::string getFreeID()
std::set< std::string > myJoinExclusions
Definition: NBNodeCont.h:372
NodeCont myNodes
The map of names to nodes.
Definition: NBNodeCont.h:366
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:851
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&#39;s incoming edges.
Definition: NBNode.h:244
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:490
static const SUMOReal UNSPECIFIED_SIGNAL_OFFSET
unspecified signal offset
Definition: NBEdge.h:205
void addJoinExclusion(const std::vector< std::string > &ids, bool check=false)
Definition: NBNodeCont.cpp:419
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 &quot;unwished&quot; 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:255
bool isTLControlled() const
Returns whether this node is controlled by any tls.
Definition: NBNode.h:295
unsigned int joinJunctions(SUMOReal maxDist, NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
Joins junctions that are very close together.
Definition: NBNodeCont.cpp:477
std::vector< std::set< std::string > > myJoinedClusters
Definition: NBNodeCont.h:377
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:290
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&#39;s lane and an approached one.
Definition: NBEdge.cpp:628
NamedRTree myRTree
node positions for faster lookup
Definition: NBNodeCont.h:383
void guessTLs(OptionsCont &oc, NBTrafficLightLogicCont &tlc)
Guesses which junctions or junction clusters shall be controlled by tls.
Definition: NBNodeCont.cpp:786
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
bool checkIsRemovable() const
Definition: NBNode.cpp:1316
void removeTrafficLight(NBTrafficLightDefinition *tlDef)
Removes the given traffic light from this node.
Definition: NBNode.cpp:298
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:958
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:169
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:376
A class representing a single district.
Definition: NBDistrict.h:72
const EdgeVector & getOutgoingEdges() const
Returns this node&#39;s outgoing edges.
Definition: NBNode.h:252
SUMOReal getLoadedLength() const
Returns the length was set explicitly or the computed length if it wasn&#39;t set.
Definition: NBEdge.h:412
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:268
const Position & getPosition() const
Returns the position of this node.
Definition: NBNode.h:232
const std::set< NBTrafficLightDefinition * > & getControllingTLS() const
Returns the traffic lights that were assigned to this node.
Definition: NBNode.h:309
~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:938
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:453
bool geometryLike() const
whether this is structurally similar to a geometry node
Definition: NBNode.cpp:1980
void removeTrafficLights()
Removes all references to traffic lights that control this tls.
Definition: NBNode.cpp:305
const EdgeVector & getEdges() const
Returns all edges which participate in this node.
Definition: NBNode.h:260
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:640
std::set< NBNode * > myExtractedNodes
The extracted nodes which are kept for reference.
Definition: NBNodeCont.h:369
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:482
NBEdge * getConnectionTo(NBNode *n) const
Definition: NBNode.cpp:1410
bool shouldBeTLSControlled(const std::set< NBNode * > &c) const
Returns whethe the given node cluster should be controlled by a tls.
Definition: NBNodeCont.cpp:758
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:1373
void joinSameNodeConnectingEdges(NBDistrictCont &dc, NBTrafficLightLogicCont &tlc, EdgeVector edges)
Joins the given edges because they connect the same nodes.
Definition: NBEdgeCont.cpp:620
void setAsTLControlled(NBNode *node, NBTrafficLightLogicCont &tlc, TrafficLightType type, std::string id="")
Sets the given node as being controlled by a tls.
Definition: NBNodeCont.cpp:984
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:368
bool isNearDistrict() const
Definition: NBNode.cpp:1421
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:245
void addCluster2Join(std::set< std::string > cluster)
add ids of nodes which shall be joined into a single node
Definition: NBNodeCont.cpp:435
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:723
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:380
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:326
void erase(NBDistrictCont &dc, NBEdge *edge)
Removes the given edge from the container (deleting it)
Definition: NBEdgeCont.cpp:360
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:1917
std::vector< std::set< std::string > > myClusters2Join
Definition: NBNodeCont.h:375
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:1971
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:428
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:747
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:403
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&#39;s geometry at the given node.
Definition: NBEdge.cpp:1162
void registerJoinedCluster(const std::set< NBNode * > &cluster)
gets all joined clusters (see doc for myClusters2Join)
Definition: NBNodeCont.cpp:713
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:360