59 #ifdef CHECK_MEMORY_LEAKS
61 #endif // CHECK_MEMORY_LEAKS
81 NodeCont::iterator i =
myNodes.find(
id);
87 const float pos[2] = {(
float)position.
x(), (
float)position.
y()};
95 std::pair<SUMOReal, SUMOReal> ret(-1.0, -1.0);
96 NodeCont::iterator i =
myNodes.find(
id);
98 return (*i).second->getPosition();
102 const float pos[2] = {(
float) - 1, (
float) - 1};
111 std::string
id = node->
getID();
112 NodeCont::iterator i =
myNodes.find(
id);
125 NodeCont::const_iterator i =
myNodes.find(
id);
136 const float cmin[2] = {(
float)(position.
x() - extOffset), (
float)(position.
y() - extOffset)};
137 const float cmax[2] = {(
float)(position.
x() + extOffset), (
float)(position.
y() + extOffset)};
138 std::set<std::string> into;
141 for (std::set<std::string>::const_iterator i = into.begin(); i != into.end(); i++) {
185 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
186 no += (*i).second->removeSelfLoops(dc, ec, tc);
200 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
202 std::map<NBNode*, EdgeVector> connectionCount;
203 const EdgeVector& outgoing = (*i).second->getOutgoingEdges();
204 for (EdgeVector::const_iterator j = outgoing.begin(); j != outgoing.end(); j++) {
207 if (connectionCount.find(connected) == connectionCount.end()) {
210 connectionCount[connected].push_back(e);
213 std::map<NBNode*, EdgeVector>::iterator k;
214 for (k = connectionCount.begin(); k != connectionCount.end(); k++) {
216 if ((*k).second.size() < 2) {
222 const NBEdge*
const first = ev.front();
223 EdgeVector::const_iterator jci;
224 for (jci = ev.begin() + 1; jci != ev.end(); ++jci) {
227 (relativeLengthDifference > lengthThreshold) ||
228 (first->
getSpeed() != (*jci)->getSpeed())
236 if (jci == ev.end()) {
249 const std::vector<std::string>& edgeNames = ec.
getAllNames();
250 for (std::vector<std::string>::const_iterator it = edgeNames.begin(); it != edgeNames.end(); ++it) {
259 if (outgoingEdges.size() != 1) {
264 if (incomingEdges.size() > 1) {
267 }
else if (incomingEdges.size() == 1) {
268 NBNode* fromNodeOfIncomingEdge = incomingEdges[0]->getFromNode();
269 NBNode* toNodeOfOutgoingEdge = outgoingEdges[0]->getToNode();
270 if (fromNodeOfIncomingEdge != toNodeOfOutgoingEdge) {
278 bool hasJunction =
false;
282 std::set<NBNode*> adjacentNodes;
290 adjacentNodes.clear();
291 for (EdgeVector::const_iterator itOfOutgoings = outgoingEdgesOfToNode.begin(); itOfOutgoings != outgoingEdgesOfToNode.end(); ++itOfOutgoings) {
292 if ((*itOfOutgoings)->getToNode() != from
293 && (*itOfOutgoings)->getToNode() != to
297 adjacentNodes.insert((*itOfOutgoings)->getToNode());
299 for (EdgeVector::const_iterator itOfIncomings = incomingEdgesOfToNode.begin(); itOfIncomings != incomingEdgesOfToNode.end(); ++itOfIncomings) {
300 adjacentNodes.insert((*itOfIncomings)->getFromNode());
302 adjacentNodes.erase(to);
303 if (adjacentNodes.size() > 2) {
306 }
while (!hasJunction && eOld != e);
308 edgeCounter +=
int(road.size());
309 std::string warningString =
"Removed a road without junctions: ";
310 for (EdgeVector::iterator roadIt = road.begin(); roadIt != road.end(); ++roadIt) {
311 if (roadIt == road.begin()) {
312 warningString += (*roadIt)->getID();
314 warningString +=
", " + (*roadIt)->getID();
317 NBNode* fromNode = (*roadIt)->getFromNode();
318 NBNode* toNode = (*roadIt)->getToNode();
319 ec.
erase(dc, *roadIt);
333 WRITE_WARNING(
"Detected isolated roads. Use the option --remove-edges.isolated to get a list of all affected edges.");
341 bool removeGeometryNodes) {
343 std::vector<NBNode*> toRemove;
344 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
345 NBNode* current = (*i).second;
347 std::vector<std::pair<NBEdge*, NBEdge*> > toJoin;
354 if (removeGeometryNodes) {
370 for (std::vector<std::pair<NBEdge*, NBEdge*> >::iterator j = toJoin.begin(); j != toJoin.end(); j++) {
372 NBEdge* continuation = (*j).second;
373 begin->
append(continuation);
377 ec.
erase(dc, continuation);
379 toRemove.push_back(current);
383 for (std::vector<NBNode*>::iterator j = toRemove.begin(); j != toRemove.end(); ++j) {
393 std::set<NBNode*> visited;
394 for (NodeCont::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
395 std::vector<NBNode*> toProc;
396 if (visited.find((*i).second) != visited.end()) {
399 toProc.push_back((*i).second);
401 while (!toProc.empty()) {
402 NBNode* n = toProc.back();
404 if (visited.find(n) != visited.end()) {
410 for (EdgeVector::const_iterator j = edges.begin(); j != edges.end(); ++j) {
418 if (visited.find(s) != visited.end()) {
436 for (std::vector<std::string>::const_iterator it = ids.begin(); it != ids.end(); it++) {
440 WRITE_WARNING(
"Ignoring join exclusion for node '" + *it +
"' since it already occured in a list of nodes to be joined");
441 }
else if (check &&
retrieve(*it) == 0) {
442 WRITE_WARNING(
"Ignoring join exclusion for unknown node '" + *it +
"'");
453 for (std::set<std::string>::const_iterator it = cluster.begin(); it != cluster.end(); it++) {
455 WRITE_WARNING(
"Ignoring join-cluster because node '" + *it +
"' was already excluded from joining");
457 }
else if (
myJoined.count(*it) > 0) {
458 WRITE_WARNING(
"Ignoring join-cluster because node '" + *it +
"' already occured in another join-cluster");
473 std::set<NBNode*> cluster;
474 for (std::set<std::string>::iterator it_id = it->begin(); it_id != it->end(); it_id++) {
477 WRITE_WARNING(
"Ignoring unknown node '" + *it_id +
"' while joining");
479 cluster.insert(node);
482 if (cluster.size() > 1) {
483 clusters.push_back(cluster);
488 return (
int)clusters.size();
497 for (NodeClusters::iterator i = cands.begin(); i != cands.end(); ++i) {
498 std::set<NBNode*> cluster = (*i);
500 for (std::set<NBNode*>::iterator j = cluster.begin(); j != cluster.end();) {
501 std::set<NBNode*>::iterator check = j;
504 cluster.erase(check);
508 bool pruneFringe =
true;
509 while (pruneFringe) {
511 for (std::set<NBNode*>::iterator j = cluster.begin(); j != cluster.end();) {
512 std::set<NBNode*>::iterator check = j;
517 std::set<NBNode*> neighbors;
518 std::set<NBNode*> clusterNeigbors;
520 NBNode* neighbor = (*it_edge)->getToNode();
521 if (cluster.count(neighbor) == 0) {
522 neighbors.insert(neighbor);
524 clusterNeigbors.insert(neighbor);
528 NBNode* neighbor = (*it_edge)->getFromNode();
529 if (cluster.count(neighbor) == 0) {
530 neighbors.insert(neighbor);
532 clusterNeigbors.insert(neighbor);
535 if (neighbors.size() <= 1 && clusterNeigbors.size() == 1) {
536 cluster.erase(check);
542 std::set<NBNode*> toRemove;
543 for (std::set<NBNode*>::iterator j = cluster.begin(); j != cluster.end(); ++j) {
546 for (EdgeVector::const_iterator it_edge = edges.begin(); it_edge != edges.end(); ++it_edge) {
555 for (std::set<NBNode*>::iterator j = toRemove.begin(); j != toRemove.end(); ++j) {
558 if (cluster.size() > 1) {
561 std::set<NBEdge*> finalIncoming;
562 std::set<NBEdge*> finalOutgoing;
563 std::vector<std::string> nodeIDs;
564 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) {
565 nodeIDs.push_back((*j)->getID());
566 for (EdgeVector::const_iterator it_edge = (*j)->getIncomingEdges().begin(); it_edge != (*j)->getIncomingEdges().end(); ++it_edge) {
570 finalIncoming.insert(edge);
573 for (EdgeVector::const_iterator it_edge = (*j)->getOutgoingEdges().begin(); it_edge != (*j)->getOutgoingEdges().end(); ++it_edge) {
575 if (cluster.count(edge->
getToNode()) == 0) {
577 finalOutgoing.insert(edge);
582 if (finalIncoming.size() > 4) {
583 std::sort(nodeIDs.begin(), nodeIDs.end());
587 const SUMOReal PARALLEL_INCOMING_THRESHOLD = 10.0;
588 bool foundParallel =
false;
589 for (std::set<NBEdge*>::const_iterator j = finalIncoming.begin(); j != finalIncoming.end() && !foundParallel; ++j) {
590 for (std::set<NBEdge*>::const_iterator k = finalIncoming.begin(); k != finalIncoming.end() && !foundParallel; ++k) {
591 if ((*j) != (*k) && fabs((*j)->getAngleAtNode((*j)->getToNode()) - (*k)->getAngleAtNode((*k)->getToNode())) < PARALLEL_INCOMING_THRESHOLD) {
592 std::vector<std::string> parallelEdgeIDs;
593 parallelEdgeIDs.push_back((*j)->getID());
594 parallelEdgeIDs.push_back((*k)->getID());
595 std::sort(parallelEdgeIDs.begin(), parallelEdgeIDs.end());
598 foundParallel =
true;
603 for (std::set<NBEdge*>::const_iterator j = finalOutgoing.begin(); j != finalOutgoing.end() && !foundParallel; ++j) {
604 for (std::set<NBEdge*>::const_iterator k = finalOutgoing.begin(); k != finalOutgoing.end() && !foundParallel; ++k) {
605 if ((*j) != (*k) && fabs((*j)->getAngleAtNode((*j)->getFromNode()) - (*k)->getAngleAtNode((*k)->getFromNode())) < PARALLEL_INCOMING_THRESHOLD) {
606 std::vector<std::string> parallelEdgeIDs;
607 parallelEdgeIDs.push_back((*j)->getID());
608 parallelEdgeIDs.push_back((*k)->getID());
609 std::sort(parallelEdgeIDs.begin(), parallelEdgeIDs.end());
612 foundParallel =
true;
616 if (!foundParallel && cluster.size() > 1) {
620 for (std::set<NBNode*>::iterator j = cluster.begin(); j != cluster.end(); ++j) {
622 std::set<NBNode*> newComp;
625 newComp.insert(current);
626 for (NodeClusters::iterator it_comp = components.begin(); it_comp != components.end();) {
627 NodeClusters::iterator check = it_comp;
629 bool connected =
false;
630 for (std::set<NBNode*>::iterator k = (*check).begin(); k != (*check).end(); ++k) {
631 if (current->
getConnectionTo(*k) != 0 || (*k)->getConnectionTo(current) != 0) {
633 newComp.insert((*check).begin(), (*check).end());
634 it_comp = components.erase(check);
644 components.push_back(newComp);
646 for (NodeClusters::iterator it_comp = components.begin(); it_comp != components.end(); ++it_comp) {
647 if ((*it_comp).size() > 1) {
649 clusters.push_back(*it_comp);
657 return (
int)clusters.size();
664 for (NodeClusters::iterator i = clusters.begin(); i != clusters.end(); ++i) {
665 std::set<NBNode*> cluster = *i;
666 assert(cluster.size() > 1);
683 throw ProcessError(
"Could not allocate tls '" +
id +
"'.");
687 std::set<NBEdge*> allEdges;
688 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) {
690 allEdges.insert(edges.begin(), edges.end());
694 for (std::set<NBEdge*>::iterator j = allEdges.begin(); j != allEdges.end();) {
698 if (cluster.count(from) > 0 && cluster.count(to) > 0) {
699 for (std::set<NBEdge*>::iterator l = allEdges.begin(); l != allEdges.end(); ++l) {
712 for (std::set<NBEdge*>::iterator j = allEdges.begin(); j != allEdges.end(); ++j) {
715 const bool outgoing = cluster.count(e->
getFromNode()) > 0;
721 for (std::vector<NBEdge::Connection>::iterator k = conns.begin(); k != conns.end(); ++k) {
727 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) {
736 std::set<std::string> ids;
737 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); j++) {
738 ids.insert((*j)->getID());
749 std::vector<std::string> member_ids;
750 bool ambiguousType =
false;
751 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); j++) {
752 member_ids.push_back((*j)->getID());
753 pos.
add((*j)->getPosition());
755 if ((*j)->isTLControlled()) {
758 type = (*(*j)->getControllingTLS().begin())->getType();
759 }
else if (type != (*(*j)->getControllingTLS().begin())->getType()) {
760 ambiguousType =
true;
765 pos.
mul(1.0 / cluster.size());
767 sort(member_ids.begin(), member_ids.end());
768 for (std::vector<std::string>::iterator j = member_ids.begin(); j != member_ids.end(); j++) {
769 id =
id +
"_" + (*j);
773 WRITE_WARNING(
"Ambiguous traffic light type for node cluster '" +
id +
"' set to '" +
toString(type) +
"'");
781 unsigned int noIncoming = 0;
782 unsigned int noOutgoing = 0;
783 bool tooFast =
false;
785 std::set<NBEdge*> seen;
786 for (std::set<NBNode*>::const_iterator j = c.begin(); j != c.end(); ++j) {
788 for (EdgeVector::const_iterator k = edges.begin(); k != edges.end(); ++k) {
789 if (c.find((*k)->getFromNode()) != c.end() && c.find((*k)->getToNode()) != c.end()) {
792 if ((*j)->hasIncoming(*k)) {
794 f += (
SUMOReal)(*k)->getNumLanes() * (*k)->getLaneSpeed(0);
798 if ((*k)->getLaneSpeed(0) * 3.6 > 79) {
803 return !tooFast && f >= 150. / 3.6 && c.size() != 0;
810 std::vector<NBNode*> ncontrolled;
811 if (oc.
isSet(
"tls.unset")) {
812 std::vector<std::string> notTLControlledNodes = oc.
getStringVector(
"tls.unset");
813 for (std::vector<std::string>::const_iterator i = notTLControlledNodes.begin(); i != notTLControlledNodes.end(); ++i) {
816 throw ProcessError(
" The node '" + *i +
"' to set as not-controlled is not known.");
819 for (std::set<NBTrafficLightDefinition*>::const_iterator j = tls.begin(); j != tls.end(); ++j) {
823 ncontrolled.push_back(n);
830 if (oc.
exists(
"tls.taz-nodes") && oc.
getBool(
"tls.taz-nodes")) {
831 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
832 NBNode* cur = (*i).second;
833 if (cur->
isNearDistrict() && find(ncontrolled.begin(), ncontrolled.end(), cur) == ncontrolled.end()) {
841 if (oc.
exists(
"tls.guess-signals") && oc.
getBool(
"tls.guess-signals")) {
844 for (std::map<std::string, NBNode*>::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); ++i) {
845 NBNode* node = (*i).second;
848 for (EdgeVector::const_iterator it_o = outgoing.begin(); it_o != outgoing.end(); ++it_o) {
849 (*it_o)->setSignalOffset((*it_o)->getLength());
854 for (std::map<std::string, NBNode*>::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); ++i) {
858 std::vector<NBNode*> signals;
860 for (EdgeVector::const_iterator it_i = incoming.begin(); it_i != incoming.end(); ++it_i) {
861 const NBEdge* inEdge = *it_i;
871 for (std::vector<NBNode*>::iterator j = signals.begin(); j != signals.end(); ++j) {
872 std::set<NBTrafficLightDefinition*> tls = (*j)->getControllingTLS();
873 (*j)->removeTrafficLights();
874 for (std::set<NBTrafficLightDefinition*>::iterator k = tls.begin(); k != tls.end(); ++k) {
892 if (!oc.
getBool(
"tls.guess")) {
899 std::vector<std::set<NBNode*> > cands;
902 for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end();) {
903 std::set<NBNode*>& c = (*i);
906 for (std::set<NBNode*>::iterator j = c.begin(); j != c.end();) {
907 if ((*j)->isTLControlled() || find(ncontrolled.begin(), ncontrolled.end(), *j) != ncontrolled.end()) {
921 unsigned int index = 0;
922 for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end(); ++i) {
923 std::vector<NBNode*> nodes;
924 for (std::set<NBNode*>::iterator j = (*i).begin(); j != (*i).end(); j++) {
927 std::string
id =
"joinedG_" +
toString(index++);
939 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
940 NBNode* cur = (*i).second;
946 if (find(ncontrolled.begin(), ncontrolled.end(), cur) != ncontrolled.end()) {
961 std::vector<std::set<NBNode*> > cands;
963 unsigned int index = 0;
964 for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end(); ++i) {
965 std::set<NBNode*>& c = (*i);
966 for (std::set<NBNode*>::iterator j = c.begin(); j != c.end();) {
967 if (!(*j)->isTLControlled()) {
982 for (std::set<NBNode*>::iterator j = c.begin(); j != c.end(); ++j) {
983 std::set<NBTrafficLightDefinition*> tls = (*j)->getControllingTLS();
984 (*j)->removeTrafficLights();
985 for (std::set<NBTrafficLightDefinition*>::iterator k = tls.begin(); k != tls.end(); ++k) {
989 std::string
id =
"joinedS_" +
toString(index++);
990 std::vector<NBNode*> nodes;
991 for (std::set<NBNode*>::iterator j = c.begin(); j != c.end(); j++) {
1012 if (!tlc.
insert(tlDef)) {
1014 WRITE_WARNING(
"Building a tl-logic for node '" +
id +
"' twice is not possible.");
1024 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
1025 (*i).second->computeLanes2Lanes(buildCrossingsAndWalkingAreas);
1033 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
1034 (*i).second->computeLogic(ec, oc);
1041 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
1042 delete((*i).second);
1055 std::string ret =
"SUMOGenerated" + toString<int>(
size());
1063 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
1064 (*i).second->computeNodeShape(leftHand, mismatchThreshold);
1071 int numUnregulatedJunctions = 0;
1072 int numDeadEndJunctions = 0;
1073 int numPriorityJunctions = 0;
1074 int numRightBeforeLeftJunctions = 0;
1075 int numAllWayStopJunctions = 0;
1076 for (NodeCont::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
1077 switch ((*i).second->getType()) {
1080 ++numUnregulatedJunctions;
1083 ++numDeadEndJunctions;
1088 ++numPriorityJunctions;
1091 ++numRightBeforeLeftJunctions;
1094 ++numAllWayStopJunctions;
1097 ++numRightBeforeLeftJunctions;
1107 if (numDeadEndJunctions > 0) {
1112 if (numAllWayStopJunctions > 0) {
1118 std::vector<std::string>
1120 std::vector<std::string> ret;
1121 for (NodeCont::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); ++i) {
1122 ret.push_back((*i).first);
1130 if (
myNodes.count(newID) != 0) {
1131 throw ProcessError(
"Attempt to rename node using existing id '" + newID +
"'");
1141 for (NodeCont::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); ++i) {
1142 NBNode* node = i->second;
1149 for (EdgeVector::const_iterator it_o = outgoing.begin(); it_o != outgoing.end(); ++it_o) {
1150 (*it_o)->setSignalOffset((*it_o)->getLength());
1153 for (std::set<NBTrafficLightDefinition*>::const_iterator it = tldefs.begin(); it != tldefs.end(); ++it) {