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;
506 while (pruneFringe) {
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) {
528 std::set<NBEdge*> finalIncoming;
529 std::vector<std::string> nodeIDs;
530 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) {
531 nodeIDs.push_back((*j)->getID());
532 const EdgeVector& edges = (*j)->getIncomingEdges();
533 for (EdgeVector::const_iterator it_edge = edges.begin(); it_edge != edges.end(); ++it_edge) {
537 finalIncoming.insert(edge);
542 if (finalIncoming.size() > 4) {
545 clusters.push_back(cluster);
550 return (
int)clusters.size();
557 for (NodeClusters::iterator i = clusters.begin(); i != clusters.end(); ++i) {
558 std::set<NBNode*> cluster = *i;
559 assert(cluster.size() > 1);
576 throw ProcessError(
"Could not allocate tls '" +
id +
"'.");
580 std::set<NBEdge*> allEdges;
581 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) {
583 allEdges.insert(edges.begin(), edges.end());
587 for (std::set<NBEdge*>::iterator j = allEdges.begin(); j != allEdges.end();) {
591 if (cluster.count(from) > 0 && cluster.count(to) > 0) {
592 for (std::set<NBEdge*>::iterator l = allEdges.begin(); l != allEdges.end(); ++l) {
605 for (std::set<NBEdge*>::iterator j = allEdges.begin(); j != allEdges.end(); ++j) {
608 const bool outgoing = cluster.count(e->
getFromNode()) > 0;
614 for (std::vector<NBEdge::Connection>::iterator k = conns.begin(); k != conns.end(); ++k) {
620 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); ++j) {
629 std::set<std::string> ids;
630 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); j++) {
631 ids.insert((*j)->getID());
642 std::vector<std::string> member_ids;
643 bool ambiguousType =
false;
644 for (std::set<NBNode*>::const_iterator j = cluster.begin(); j != cluster.end(); j++) {
645 member_ids.push_back((*j)->getID());
646 pos.
add((*j)->getPosition());
648 if ((*j)->isTLControlled()) {
651 type = (*(*j)->getControllingTLS().begin())->getType();
652 }
else if (type != (*(*j)->getControllingTLS().begin())->getType()) {
653 ambiguousType =
true;
658 pos.
mul(1.0 / cluster.size());
660 sort(member_ids.begin(), member_ids.end());
661 for (std::vector<std::string>::iterator j = member_ids.begin(); j != member_ids.end(); j++) {
662 id =
id +
"_" + (*j);
666 WRITE_WARNING(
"Ambiguous traffic light type for node cluster '" +
id +
"' set to '" +
toString(type) +
"'");
674 unsigned int noIncoming = 0;
675 unsigned int noOutgoing = 0;
676 bool tooFast =
false;
678 std::set<NBEdge*> seen;
679 for (std::set<NBNode*>::const_iterator j = c.begin(); j != c.end(); ++j) {
681 for (EdgeVector::const_iterator k = edges.begin(); k != edges.end(); ++k) {
682 if (c.find((*k)->getFromNode()) != c.end() && c.find((*k)->getToNode()) != c.end()) {
685 if ((*j)->hasIncoming(*k)) {
687 f += (
SUMOReal)(*k)->getNumLanes() * (*k)->getLaneSpeed(0);
691 if ((*k)->getLaneSpeed(0) * 3.6 > 79) {
696 return !tooFast && f >= 150. / 3.6 && c.size() != 0;
703 std::vector<NBNode*> ncontrolled;
704 if (oc.
isSet(
"tls.unset")) {
705 std::vector<std::string> notTLControlledNodes = oc.
getStringVector(
"tls.unset");
706 for (std::vector<std::string>::const_iterator i = notTLControlledNodes.begin(); i != notTLControlledNodes.end(); ++i) {
709 throw ProcessError(
" The node '" + *i +
"' to set as not-controlled is not known.");
712 for (std::set<NBTrafficLightDefinition*>::const_iterator j = tls.begin(); j != tls.end(); ++j) {
716 ncontrolled.push_back(n);
723 if (oc.
exists(
"tls.taz-nodes") && oc.
getBool(
"tls.taz-nodes")) {
724 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
725 NBNode* cur = (*i).second;
726 if (cur->
isNearDistrict() && find(ncontrolled.begin(), ncontrolled.end(), cur) == ncontrolled.end()) {
733 if (!oc.
getBool(
"tls.guess")) {
740 std::vector<std::set<NBNode*> > cands;
743 for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end();) {
744 std::set<NBNode*>& c = (*i);
747 for (std::set<NBNode*>::iterator j = c.begin(); j != c.end();) {
748 if ((*j)->isTLControlled() || find(ncontrolled.begin(), ncontrolled.end(), *j) != ncontrolled.end()) {
762 unsigned int index = 0;
763 for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end(); ++i) {
764 std::vector<NBNode*> nodes;
765 for (std::set<NBNode*>::iterator j = (*i).begin(); j != (*i).end(); j++) {
768 std::string
id =
"joinedG_" +
toString(index++);
780 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
781 NBNode* cur = (*i).second;
787 if (find(ncontrolled.begin(), ncontrolled.end(), cur) != ncontrolled.end()) {
802 std::vector<std::set<NBNode*> > cands;
804 unsigned int index = 0;
805 for (std::vector<std::set<NBNode*> >::iterator i = cands.begin(); i != cands.end(); ++i) {
806 std::set<NBNode*>& c = (*i);
807 for (std::set<NBNode*>::iterator j = c.begin(); j != c.end();) {
808 if (!(*j)->isTLControlled()) {
823 for (std::set<NBNode*>::iterator j = c.begin(); j != c.end(); ++j) {
824 std::set<NBTrafficLightDefinition*> tls = (*j)->getControllingTLS();
825 (*j)->removeTrafficLights();
826 for (std::set<NBTrafficLightDefinition*>::iterator k = tls.begin(); k != tls.end(); ++k) {
830 std::string
id =
"joinedS_" +
toString(index++);
831 std::vector<NBNode*> nodes;
832 for (std::set<NBNode*>::iterator j = c.begin(); j != c.end(); j++) {
855 WRITE_WARNING(
"Building a tl-logic for node '" +
id +
"' twice is not possible.");
865 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
866 (*i).second->computeLanes2Lanes();
874 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
875 (*i).second->computeLogic(ec, oc);
882 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
896 std::string ret =
"SUMOGenerated" + toString<int>(
size());
904 for (NodeCont::iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
905 (*i).second->computeNodeShape(leftHand);
912 int numUnregulatedJunctions = 0;
913 int numDeadEndJunctions = 0;
914 int numPriorityJunctions = 0;
915 int numRightBeforeLeftJunctions = 0;
916 for (NodeCont::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); i++) {
917 switch ((*i).second->getType()) {
919 ++numUnregulatedJunctions;
922 ++numDeadEndJunctions;
926 ++numPriorityJunctions;
929 ++numRightBeforeLeftJunctions;
932 ++numRightBeforeLeftJunctions;
942 if (numDeadEndJunctions > 0) {
950 std::vector<std::string>
952 std::vector<std::string> ret;
953 for (NodeCont::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); ++i) {
954 ret.push_back((*i).first);
962 if (
myNodes.count(newID) != 0) {
963 throw ProcessError(
"Attempt to rename node using existing id '" + newID +
"'");
973 for (NodeCont::const_iterator i =
myNodes.begin(); i !=
myNodes.end(); ++i) {
978 for (std::set<NBTrafficLightDefinition*>::const_iterator it = tldefs.begin(); it != tldefs.end(); ++it) {