59 #ifdef CHECK_MEMORY_LEAKS
61 #endif // CHECK_MEMORY_LEAKS
80 NodeCont::iterator i =
myNodes.find(
id);
92 NodeCont::iterator i =
myNodes.find(
id);
104 std::pair<SUMOReal, SUMOReal> ret(-1.0, -1.0);
105 NodeCont::iterator i =
myNodes.find(
id);
107 return (*i).second->getPosition();
118 std::string
id = node->
getID();
119 NodeCont::iterator i =
myNodes.find(
id);
130 NodeCont::const_iterator i =
myNodes.find(
id);
140 for (NodeCont::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
141 NBNode* node = (*i).second;
182 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
183 no += (*i).second->removeSelfLoops(dc, ec, tc);
197 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
199 std::map<NBNode*, EdgeVector> connectionCount;
200 const EdgeVector& outgoing = (*i).second->getOutgoingEdges();
201 for (EdgeVector::const_iterator j = outgoing.begin(); j != outgoing.end(); j++) {
204 if (connectionCount.find(connected) == connectionCount.end()) {
207 connectionCount[connected].push_back(e);
210 std::map<NBNode*, EdgeVector>::iterator k;
211 for (k = connectionCount.begin(); k != connectionCount.end(); k++) {
213 if ((*k).second.size() < 2) {
219 const NBEdge*
const first = ev.front();
220 EdgeVector::const_iterator jci;
221 for (jci = ev.begin() + 1; jci != ev.end(); ++jci) {
224 (relativeLengthDifference > lengthThreshold) ||
225 (first->
getSpeed() != (*jci)->getSpeed())
233 if (jci == ev.end()) {
246 const std::vector<std::string> &edgeNames = ec.
getAllNames();
247 for (std::vector<std::string>::const_iterator it = edgeNames.begin(); it != edgeNames.end(); ++it) {
256 if (outgoingEdges.size() != 1) {
261 if (incomingEdges.size() > 1) {
264 }
else if (incomingEdges.size() == 1) {
265 NBNode* fromNodeOfIncomingEdge = incomingEdges[0]->getFromNode();
266 NBNode* toNodeOfOutgoingEdge = outgoingEdges[0]->getToNode();
267 if (fromNodeOfIncomingEdge != toNodeOfOutgoingEdge) {
275 bool hasJunction =
false;
279 std::set<NBNode*> adjacentNodes;
287 adjacentNodes.clear();
288 for (EdgeVector::const_iterator itOfOutgoings = outgoingEdgesOfToNode.begin(); itOfOutgoings != outgoingEdgesOfToNode.end(); ++itOfOutgoings) {
289 if ((*itOfOutgoings)->getToNode() != from
290 && (*itOfOutgoings)->getToNode() != to
294 adjacentNodes.insert((*itOfOutgoings)->getToNode());
296 for (EdgeVector::const_iterator itOfIncomings = incomingEdgesOfToNode.begin(); itOfIncomings != incomingEdgesOfToNode.end(); ++itOfIncomings) {
297 adjacentNodes.insert((*itOfIncomings)->getFromNode());
299 adjacentNodes.erase(to);
300 if (adjacentNodes.size() > 2) {
303 }
while (!hasJunction && eOld != e);
305 edgeCounter +=
int(road.size());
306 std::string warningString =
"Removed a road without junctions: ";
307 for (EdgeVector::iterator roadIt = road.begin(); roadIt != road.end(); ++roadIt) {
308 if (roadIt == road.begin()) {
309 warningString += (*roadIt)->getID();
311 warningString +=
", " + (*roadIt)->getID();
314 NBNode* fromNode = (*roadIt)->getFromNode();
315 NBNode* toNode = (*roadIt)->getToNode();
316 ec.
erase(dc, *roadIt);
330 WRITE_WARNING(
"Detected isolated roads. Use the option --remove-edges.isolated to get a list of all affected edges.");
338 bool removeGeometryNodes) {
340 std::vector<NBNode*> toRemove;
341 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
342 NBNode* current = (*i).second;
344 std::vector<std::pair<NBEdge*, NBEdge*> > toJoin;
351 if (removeGeometryNodes) {
367 for (std::vector<std::pair<NBEdge*, NBEdge*> >::iterator j = toJoin.begin(); j != toJoin.end(); j++) {
369 NBEdge* continuation = (*j).second;
370 begin->
append(continuation);
374 ec.
erase(dc, continuation);
376 toRemove.push_back(current);
380 for (std::vector<NBNode*>::iterator j = toRemove.begin(); j != toRemove.end(); ++j) {
390 std::set<NBNode*> visited;
391 for (NodeCont::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
392 std::vector<NBNode*> toProc;
393 if (visited.find((*i).second) != visited.end()) {
396 toProc.push_back((*i).second);
398 while (!toProc.empty()) {
399 NBNode* n = toProc.back();
401 if (visited.find(n) != visited.end()) {
407 for (EdgeVector::const_iterator j = edges.begin(); j != edges.end(); ++j) {
415 if (visited.find(s) != visited.end()) {
433 for (std::vector<std::string>::const_iterator it = ids.begin(); it != ids.end(); it++) {
437 WRITE_WARNING(
"Ignoring join exclusion for node '" + *it +
"' since it already occured in a list of nodes to be joined");
438 }
else if (check &&
retrieve(*it) == 0) {
439 WRITE_WARNING(
"Ignoring join exclusion for unknown node '" + *it +
"'");
450 for (std::set<std::string>::const_iterator it = cluster.begin(); it != cluster.end(); it++) {
452 WRITE_WARNING(
"Ignoring join-cluster because node '" + *it +
"' was already excluded from joining");
454 }
else if (
myJoined.count(*it) > 0) {
455 WRITE_WARNING(
"Ignoring join-cluster because node '" + *it +
"' already occured in another join-cluster");
470 std::set<NBNode*> cluster;
471 for (std::set<std::string>::iterator it_id = it->begin(); it_id != it->end(); it_id++) {
474 WRITE_WARNING(
"Ignoring unknown node '" + *it_id +
"' while joining");
476 cluster.insert(node);
479 if (cluster.size() > 1) {
480 clusters.push_back(cluster);
485 return (
int)clusters.size();
494 for (NodeClusters::iterator i = cands.begin(); i != cands.end(); ++i) {
495 std::set<NBNode*> cluster = (*i);
497 for (std::set<NBNode*>::iterator j = cluster.begin(); j != cluster.end();) {
498 std::set<NBNode*>::iterator check = j;
501 cluster.erase(check);
505 bool pruneFringe =
true;
508 for (std::set<NBNode*>::iterator j = cluster.begin(); j != cluster.end();) {
509 std::set<NBNode*>::iterator check = j;
520 cluster.erase(check);
525 if (cluster.size() > 1) {
526 clusters.push_back(cluster);
530 return (
int)clusters.size();
537 for (NodeClusters::iterator i = clusters.begin(); i != clusters.end(); ++i) {
538 std::set<NBNode*> cluster = *i;
539 assert(cluster.size() > 1);
555 throw ProcessError(
"Could not allocate tls '" +
id +
"'.");
559 std::set<NBEdge*> allEdges;
560 for (std::set<NBNode*>::const_iterator j=cluster.begin(); j!=cluster.end(); ++j) {
561 const std::vector<NBEdge*> &edges = (*j)->getEdges();
562 allEdges.insert(edges.begin(), edges.end());
566 for(std::set<NBEdge*>::iterator j=allEdges.begin(); j!=allEdges.end();) {
570 if(cluster.count(from) > 0 && cluster.count(to) > 0) {
571 for(std::set<NBEdge*>::iterator l=allEdges.begin(); l!=allEdges.end(); ++l) {
584 for(std::set<NBEdge*>::iterator j=allEdges.begin(); j!=allEdges.end(); ++j) {
588 const bool outgoing = cluster.count(e->
getFromNode()) > 0;
595 for(std::vector<NBEdge::Connection>::iterator k=conns.begin(); k!=conns.end(); ++k) {
606 std::set<std::string> ids;
607 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); j++) {
608 ids.insert((*j)->getID());
618 std::vector<std::string> member_ids;
619 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); j++) {
620 member_ids.push_back((*j)->getID());
621 pos.
add((*j)->getPosition());
623 if ((*j)->isTLControlled()) {
627 pos.
mul(1.0 / cluster.size());
629 sort(member_ids.begin(), member_ids.end());
630 for (std::vector<std::string>::iterator j = member_ids.begin(); j != member_ids.end(); j++) {
631 id =
id +
"_" + (*j);
639 unsigned int noIncoming = 0;
640 unsigned int noOutgoing = 0;
641 bool tooFast =
false;
643 std::set<NBEdge*> seen;
644 for (std::set<NBNode*>::const_iterator j = c.begin(); j != c.end(); ++j) {
646 for (EdgeVector::const_iterator k = edges.begin(); k != edges.end(); ++k) {
647 if (c.find((*k)->getFromNode()) != c.end() && c.find((*k)->getToNode()) != c.end()) {
650 if ((*j)->hasIncoming(*k)) {
652 f += (
SUMOReal)(*k)->getNumLanes() * (*k)->getLaneSpeed(0);
656 if ((*k)->getLaneSpeed(0) * 3.6 > 79) {
661 return !tooFast && f >= 150. / 3.6 && c.size() != 0;
668 std::vector<NBNode*> ncontrolled;
669 if (oc.
isSet(
"tls.unset")) {
670 std::vector<std::string> notTLControlledNodes = oc.
getStringVector(
"tls.unset");
671 for (std::vector<std::string>::const_iterator i = notTLControlledNodes.begin(); i != notTLControlledNodes.end(); ++i) {
674 throw ProcessError(
" The node '" + *i +
"' to set as not-controlled is not known.");
677 for (std::set<NBTrafficLightDefinition*>::const_iterator j = tls.begin(); j != tls.end(); ++j) {
681 ncontrolled.push_back(n);
687 if (oc.
exists(
"tls.taz-nodes") && oc.
getBool(
"tls.taz-nodes")) {
688 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
689 NBNode* cur = (*i).second;
690 if (cur->
isNearDistrict() && find(ncontrolled.begin(), ncontrolled.end(), cur) == ncontrolled.end()) {
697 if (!oc.
getBool(
"tls.guess")) {
702 if (oc.
getBool(
"tls-guess.joining")) {
705 std::vector<std::set<NBNode*> > cands;
708 for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end();) {
709 std::set<NBNode*> &c = (*i);
712 for (std::set<NBNode*>::iterator j = c.begin(); j != c.end();) {
713 if ((*j)->isTLControlled() || find(ncontrolled.begin(), ncontrolled.end(), *j) != ncontrolled.end()) {
727 unsigned int index = 0;
728 for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end(); ++i) {
729 std::vector<NBNode*> nodes;
730 for (std::set<NBNode*>::iterator j = (*i).begin(); j != (*i).end(); j++) {
733 std::string
id =
"joinedG_" +
toString(index++);
745 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
746 NBNode* cur = (*i).second;
752 if (find(ncontrolled.begin(), ncontrolled.end(), cur) != ncontrolled.end()) {
768 std::vector<std::set<NBNode*> > cands;
770 unsigned int index = 0;
771 for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end(); ++i) {
772 std::set<NBNode*> &c = (*i);
773 for (std::set<NBNode*>::iterator j = c.begin(); j != c.end();) {
774 if (!(*j)->isTLControlled()) {
783 for (std::set<NBNode*>::iterator j = c.begin(); j != c.end(); ++j) {
784 std::set<NBTrafficLightDefinition*> tls = (*j)->getControllingTLS();
785 (*j)->removeTrafficLights();
786 for (std::set<NBTrafficLightDefinition*>::iterator k = tls.begin(); k != tls.end(); ++k) {
790 std::string
id =
"joinedS_" +
toString(index++);
791 std::vector<NBNode*> nodes;
792 for (std::set<NBNode*>::iterator j = c.begin(); j != c.end(); j++) {
814 WRITE_WARNING(
"Building a tl-logic for node '" +
id +
"' twice is not possible.");
824 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
825 (*i).second->computeLanes2Lanes();
833 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
834 (*i).second->computeLogic(ec, oc);
841 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
855 std::string ret =
"SUMOGenerated" + toString<int>(
size());
863 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
864 (*i).second->computeNodeShape(leftHand);
889 std::swap(pot_highway, pot_ramp);
894 std::swap(pot_highway, pot_ramp);
900 if (pot_highway->
getSpeed() < minHighwaySpeed || cont->
getSpeed() < minHighwaySpeed) {
905 if (maxRampSpeed > 0 && maxRampSpeed < pot_ramp->getSpeed()) {
923 bool bEdgeDeleted =
false;
927 std::swap(pot_highway, pot_ramp);
932 std::swap(pot_highway, pot_ramp);
945 if (find(incremented.begin(), incremented.end(), cont) == incremented.end()) {
947 incremented.push_back(cont);
958 if (o1.size() == 1 && o1[0]->getNumLanes() < cont->
getNumLanes()) {
985 throw ProcessError(
"Ups - could not build on-ramp for edge '" + pot_highway->
getID() +
"' (node could not be build)!");
987 std::string name = cont->
getID();
988 bool ok = ec.
splitAt(dc, cont, rn,
989 cont->
getID() +
"-AddedOnRampEdge", cont->
getID(),
992 WRITE_ERROR(
"Ups - could not build on-ramp for edge '" + pot_highway->
getID() +
"'!");
997 incremented.push_back(added_ramp);
1032 return bEdgeDeleted;
1045 std::swap(pot_highway, pot_ramp);
1050 std::swap(pot_highway, pot_ramp);
1061 if (find(incremented.begin(), incremented.end(), prev) == incremented.end()) {
1062 incremented.push_back(prev);
1095 throw ProcessError(
"Ups - could not build off-ramp for edge '" + pot_highway->
getID() +
"' (node could not be build)!");
1098 std::string name = prev->
getID();
1099 bool ok = ec.
splitAt(dc, prev, rn,
1100 prev->
getID(), prev->
getID() +
"-AddedOffRampEdge",
1103 WRITE_ERROR(
"Ups - could not build on-ramp for edge '" + pot_highway->
getID() +
"'!");
1109 incremented.push_back(added_ramp);
1167 std::swap(pot_highway, pot_ramp);
1172 std::swap(pot_highway, pot_ramp);
1178 if (pot_highway->
getSpeed() < minHighwaySpeed || prev->
getSpeed() < minHighwaySpeed) {
1183 if (maxRampSpeed > 0 && maxRampSpeed < pot_ramp->getSpeed()) {
1196 std::swap(pot_highway, pot_ramp);
1201 std::swap(pot_highway, pot_ramp);
1210 bool bEdgeDeleted =
false;
1212 if (oc.
getBool(
"ramps.guess")) {
1213 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
1214 NBNode* cur = (*i).second;
1224 if (oc.
isSet(
"ramps.set")) {
1226 for (std::vector<std::string>::iterator i = edges.begin(); i != edges.end(); ++i) {
1229 WRITE_WARNING(
"Can not build on ramp on edge '" + *i +
"' - the edge is not known.");
1234 bEdgeDeleted =
buildOnRamp(oc, from, ec, dc, incremented);
1239 WRITE_WARNING(
"Can not build off ramp on edge '" + *i +
"' - the edge is not known.");
1253 int numUnregulatedJunctions = 0;
1254 int numDeadEndJunctions = 0;
1255 int numPriorityJunctions = 0;
1256 int numRightBeforeLeftJunctions = 0;
1257 for (NodeCont::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
1258 switch ((*i).second->getType()) {
1260 ++numUnregulatedJunctions;
1263 ++numDeadEndJunctions;
1267 ++numPriorityJunctions;
1270 ++numRightBeforeLeftJunctions;
1273 ++numRightBeforeLeftJunctions;
1283 if (numDeadEndJunctions > 0) {
1291 std::vector<std::string>
1293 std::vector<std::string> ret;
1294 for (NodeCont::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); ++i) {
1295 ret.push_back((*i).first);
1303 if (
myNodes.count(newID) != 0) {
1304 throw ProcessError(
"Attempt to rename node using existing id '" + newID +
"'");