LCOV - code coverage report
Current view: top level - src/netbuild - NBEdgeCont.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 91.9 % 1061 975
Test Date: 2024-12-21 15:45:41 Functions: 95.8 % 71 68

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    NBEdgeCont.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Sascha Krieg
      18              : /// @author  Michael Behrisch
      19              : /// @date    Tue, 20 Nov 2001
      20              : ///
      21              : // Storage for edges, including some functionality operating on multiple edges
      22              : /****************************************************************************/
      23              : #include <config.h>
      24              : 
      25              : #include <vector>
      26              : #include <string>
      27              : #include <cassert>
      28              : #include <algorithm>
      29              : #include <cmath>
      30              : #include <utils/geom/Boundary.h>
      31              : #include <utils/geom/GeomHelper.h>
      32              : #include <utils/geom/GeoConvHelper.h>
      33              : #include <utils/geom/GeomConvHelper.h>
      34              : #include <utils/common/MsgHandler.h>
      35              : #include <utils/common/ToString.h>
      36              : #include <utils/common/StringUtils.h>
      37              : #include <utils/common/IDSupplier.h>
      38              : #include <utils/common/StringUtils.h>
      39              : #include <utils/common/StringTokenizer.h>
      40              : #include <utils/common/UtilExceptions.h>
      41              : #include <utils/iodevices/OutputDevice.h>
      42              : #include <utils/options/OptionsCont.h>
      43              : #include "NBNetBuilder.h"
      44              : #include "NBEdgeCont.h"
      45              : #include "NBNodeCont.h"
      46              : #include "NBPTLineCont.h"
      47              : #include "NBPTStop.h"
      48              : #include "NBHelpers.h"
      49              : #include "NBCont.h"
      50              : #include "NBTrafficLightLogicCont.h"
      51              : #include "NBDistrictCont.h"
      52              : #include "NBTypeCont.h"
      53              : 
      54              : #define JOIN_TRAM_MAX_ANGLE 10
      55              : #define JOIN_TRAM_MIN_LENGTH 3
      56              : 
      57              : //#define DEBUG_GUESS_ROUNDABOUT
      58              : //#define DEBUG_JOIN_TRAM
      59              : #define DEBUG_EDGE_ID ""
      60              : 
      61              : // ===========================================================================
      62              : // method definitions
      63              : // ===========================================================================
      64         2002 : NBEdgeCont::NBEdgeCont(NBTypeCont& tc) :
      65         2002 :     myTypeCont(tc),
      66         2002 :     myVehicleClasses2Keep(0),
      67         2002 :     myVehicleClasses2Remove(0),
      68         2002 :     myNeedGeoTransformedPruningBoundary(false) {
      69         2002 : }
      70              : 
      71              : 
      72         2002 : NBEdgeCont::~NBEdgeCont() {
      73         2002 :     clear();
      74         2002 : }
      75              : 
      76              : 
      77              : void
      78         2002 : NBEdgeCont::applyOptions(OptionsCont& oc) {
      79              :     // set edges dismiss/accept options
      80         2002 :     myEdgesMinSpeed = oc.getFloat("keep-edges.min-speed");
      81         3904 :     myRemoveEdgesAfterLoading = oc.exists("keep-edges.postload") && oc.getBool("keep-edges.postload");
      82              :     // we possibly have to load the edges to keep/remove
      83         4004 :     if (oc.isSet("keep-edges.input-file")) {
      84            4 :         NBHelpers::loadEdgesFromFile(oc.getString("keep-edges.input-file"), myEdges2Keep);
      85              :     }
      86         4004 :     if (oc.isSet("remove-edges.input-file")) {
      87            2 :         NBHelpers::loadEdgesFromFile(oc.getString("remove-edges.input-file"), myEdges2Remove);
      88              :     }
      89         4004 :     if (oc.isSet("keep-edges.explicit")) {
      90           22 :         const std::vector<std::string> edges = oc.getStringVector("keep-edges.explicit");
      91              :         myEdges2Keep.insert(edges.begin(), edges.end());
      92           11 :     }
      93         4004 :     if (oc.isSet("remove-edges.explicit")) {
      94           28 :         const std::vector<std::string> edges = oc.getStringVector("remove-edges.explicit");
      95              :         myEdges2Remove.insert(edges.begin(), edges.end());
      96           14 :     }
      97         3904 :     if (oc.exists("keep-edges.by-vclass") && oc.isSet("keep-edges.by-vclass")) {
      98           50 :         myVehicleClasses2Keep = parseVehicleClasses(oc.getStringVector("keep-edges.by-vclass"));
      99              :     }
     100         3904 :     if (oc.exists("remove-edges.by-vclass") && oc.isSet("remove-edges.by-vclass")) {
     101           39 :         myVehicleClasses2Remove = parseVehicleClasses(oc.getStringVector("remove-edges.by-vclass"));
     102              :     }
     103         3890 :     if (oc.exists("keep-edges.by-type") && oc.isSet("keep-edges.by-type")) {
     104           10 :         const std::vector<std::string> types = oc.getStringVector("keep-edges.by-type");
     105              :         myTypes2Keep.insert(types.begin(), types.end());
     106            5 :     }
     107         3890 :     if (oc.exists("remove-edges.by-type") && oc.isSet("remove-edges.by-type")) {
     108           18 :         const std::vector<std::string> types = oc.getStringVector("remove-edges.by-type");
     109              :         myTypes2Remove.insert(types.begin(), types.end());
     110            9 :     }
     111              : 
     112         3980 :     if (oc.isSet("keep-edges.in-boundary") || oc.isSet("keep-edges.in-geo-boundary")) {
     113              : 
     114           14 :         std::string polyPlainString = oc.getValueString(oc.isSet("keep-edges.in-boundary") ?
     115           18 :                                       "keep-edges.in-boundary" : "keep-edges.in-geo-boundary");
     116              :         // try interpreting the boundary like shape attribute with spaces
     117           14 :         bool ok = true;
     118           17 :         PositionVector boundaryShape = GeomConvHelper::parseShapeReporting(polyPlainString, "pruning-boundary", 0, ok, false, false);
     119           14 :         if (ok) {
     120            2 :             if (boundaryShape.size() < 2) {
     121            2 :                 throw ProcessError(TL("Invalid boundary: need at least 2 coordinates"));
     122            1 :             } else if (boundaryShape.size() == 2) {
     123              :                 // prunning boundary (box)
     124            0 :                 myPruningBoundary.push_back(boundaryShape[0]);
     125            0 :                 myPruningBoundary.push_back(Position(boundaryShape[1].x(), boundaryShape[0].y()));
     126            0 :                 myPruningBoundary.push_back(boundaryShape[1]);
     127            0 :                 myPruningBoundary.push_back(Position(boundaryShape[0].x(), boundaryShape[1].y()));
     128              :             } else {
     129              :                 myPruningBoundary = boundaryShape;
     130              :             }
     131              :         } else {
     132              :             // maybe positions are separated by ',' instead of ' '
     133           28 :             std::vector<std::string> polyS = oc.getStringVector(oc.isSet("keep-edges.in-boundary") ?
     134           12 :                                              "keep-edges.in-boundary" : "keep-edges.in-geo-boundary");
     135              :             std::vector<double> poly;
     136           83 :             for (std::vector<std::string>::iterator i = polyS.begin(); i != polyS.end(); ++i) {
     137           73 :                 poly.push_back(StringUtils::toDouble((*i))); // !!! may throw something anyhow...
     138              :             }
     139           11 :             if (poly.size() < 4) {
     140            0 :                 throw ProcessError(TL("Invalid boundary: need at least 2 coordinates"));
     141           11 :             } else if (poly.size() % 2 != 0) {
     142            2 :                 throw ProcessError(TL("Invalid boundary: malformed coordinate"));
     143           10 :             } else if (poly.size() == 4) {
     144              :                 // prunning boundary (box)
     145            8 :                 myPruningBoundary.push_back(Position(poly[0], poly[1]));
     146            8 :                 myPruningBoundary.push_back(Position(poly[2], poly[1]));
     147            8 :                 myPruningBoundary.push_back(Position(poly[2], poly[3]));
     148            8 :                 myPruningBoundary.push_back(Position(poly[0], poly[3]));
     149              :             } else {
     150           19 :                 for (std::vector<double>::iterator j = poly.begin(); j != poly.end();) {
     151           17 :                     double x = *j++;
     152           17 :                     double y = *j++;
     153           17 :                     myPruningBoundary.push_back(Position(x, y));
     154              :                 }
     155              :             }
     156           14 :         }
     157           11 :         myNeedGeoTransformedPruningBoundary = oc.isSet("keep-edges.in-geo-boundary");
     158           14 :     }
     159         1992 : }
     160              : 
     161              : 
     162              : void
     163         2002 : NBEdgeCont::clear() {
     164        93295 :     for (const auto& i : myEdges) {
     165        91293 :         delete i.second;
     166              :     }
     167              :     myEdges.clear();
     168        10893 :     for (const auto& i : myExtractedEdges) {
     169         8891 :         delete i.second;
     170              :     }
     171              :     myExtractedEdges.clear();
     172         2020 :     for (NBEdge* const e : myEdgeCemetery) {
     173           18 :         delete e;
     174              :     }
     175              :     myEdgeCemetery.clear();
     176         2002 : }
     177              : 
     178              : 
     179              : 
     180              : // ----- edge access methods
     181              : bool
     182       107680 : NBEdgeCont::insert(NBEdge* edge, bool ignorePrunning) {
     183       107680 :     if (myEdges.count(edge->getID()) != 0) {
     184            0 :         return false;
     185              :     }
     186       107680 :     if (!ignorePrunning && ignoreFilterMatch(edge)) {
     187         7075 :         edge->getFromNode()->removeEdge(edge);
     188         7075 :         edge->getToNode()->removeEdge(edge);
     189         7075 :         myIgnoredEdges.insert(edge->getID());
     190         7075 :         delete edge;
     191              :     } else {
     192       100605 :         OptionsCont& oc = OptionsCont::getOptions();
     193       185791 :         if (oc.exists("dismiss-vclasses") && oc.getBool("dismiss-vclasses")) {
     194          200 :             edge->dismissVehicleClassInformation();
     195              :         }
     196       100605 :         myEdges[edge->getID()] = edge;
     197              :     }
     198              :     return true;
     199              : }
     200              : 
     201              : 
     202              : bool
     203       129400 : NBEdgeCont::ignoreFilterMatch(NBEdge* edge) {
     204       129400 :     if (!myRemoveEdgesAfterLoading) {
     205              :         // check whether the edge is a named edge to keep
     206       129287 :         if (myEdges2Keep.size() != 0) {
     207          142 :             if (myEdges2Keep.count(edge->getID()) == 0) {
     208              :                 // explicit whitelisting may be combined additively with other filters
     209           63 :                 if (myVehicleClasses2Keep == 0 && myVehicleClasses2Remove == 0
     210           63 :                         && myTypes2Keep.size() == 0 && myTypes2Remove.size() == 0
     211          104 :                         && myPruningBoundary.size() == 0) {
     212              :                     return true;
     213              :                 }
     214              :             } else {
     215              :                 // explicit whitelisting overrides other filters
     216           79 :                 return false;
     217              :             }
     218              :         }
     219              :         // remove edges which allow a speed below a set one (set using "keep-edges.min-speed")
     220       129167 :         if (edge->getSpeed() < myEdgesMinSpeed) {
     221              :             return true;
     222              :         }
     223              :         // check whether the edge shall be removed because it does not allow any of the wished classes
     224       129161 :         if (myVehicleClasses2Keep != 0 && (myVehicleClasses2Keep & edge->getPermissions()) == 0) {
     225              :             return true;
     226              :         }
     227              :         // check whether the edge shall be removed due to allowing unwished classes only
     228       124745 :         if (myVehicleClasses2Remove != 0 && (myVehicleClasses2Remove | edge->getPermissions()) == myVehicleClasses2Remove) {
     229              :             return true;
     230              :         }
     231              :     }
     232              :     // check whether the edge is a named edge to remove
     233       124539 :     if (myEdges2Remove.size() != 0) {
     234          292 :         if (myEdges2Remove.count(edge->getID()) != 0) {
     235           33 :             return true;
     236              :         }
     237              :     }
     238              :     // check whether the edge shall be removed because it does not have one of the requested types
     239       124506 :     if (myTypes2Keep.size() != 0) {
     240              :         if (myTypes2Keep.count(edge->getTypeID()) == 0) {
     241         1443 :             return true;
     242              :         }
     243              :     }
     244              :     // check whether the edge shall be removed because it has one of the forbidden types
     245       123063 :     if (myTypes2Remove.size() != 0) {
     246              :         if (myTypes2Remove.count(edge->getTypeID()) > 0) {
     247           68 :             return true;
     248              :         }
     249              :     }
     250              :     // check whether the edge is within the pruning boundary
     251       122995 :     if (myPruningBoundary.size() != 0) {
     252          987 :         if (myNeedGeoTransformedPruningBoundary) {
     253            4 :             if (GeoConvHelper::getProcessing().usingGeoProjection()) {
     254            2 :                 NBNetBuilder::transformCoordinates(myPruningBoundary, false);
     255            2 :             } else if (GeoConvHelper::getLoaded().usingGeoProjection()) {
     256              :                 // XXX what if input file with different projections are loaded?
     257           10 :                 for (int i = 0; i < (int) myPruningBoundary.size(); i++) {
     258            8 :                     GeoConvHelper::getLoaded().x2cartesian_const(myPruningBoundary[i]);
     259              :                 }
     260              :             } else {
     261            0 :                 WRITE_ERROR(TL("Cannot prune edges using a geo-boundary because no projection has been loaded"));
     262              :             }
     263            4 :             myNeedGeoTransformedPruningBoundary = false;
     264              :         }
     265          987 :         if (!(edge->getGeometry().getBoxBoundary().grow(POSITION_EPS).overlapsWith(myPruningBoundary))) {
     266              :             return true;
     267          691 :         } else if (!(edge->getGeometry().partialWithin(myPruningBoundary, 2 * POSITION_EPS) || edge->getGeometry().intersects(myPruningBoundary))) {
     268              :             // a more detailed check is necessary because the bounding box may be much bigger than the edge
     269              :             // @note: overlapsWith implicitly closes the edge shape but this is not wanted here
     270              :             return true;
     271              :         }
     272              :     }
     273       122697 :     if (myTypeCont.knows(edge->getTypeID()) && myTypeCont.getEdgeTypeShallBeDiscarded(edge->getTypeID())) {
     274              :         return true;
     275              :     }
     276              :     return false;
     277              : }
     278              : 
     279              : 
     280              : NBEdge*
     281       315074 : NBEdgeCont::retrieve(const std::string& id, bool retrieveExtracted) const {
     282              :     EdgeCont::const_iterator i = myEdges.find(id);
     283       315074 :     if (i == myEdges.end()) {
     284        86899 :         if (retrieveExtracted) {
     285              :             i = myExtractedEdges.find(id);
     286        18476 :             if (i == myExtractedEdges.end()) {
     287              :                 return nullptr;
     288              :             }
     289              :         } else {
     290              :             return nullptr;
     291              :         }
     292              :     }
     293       228212 :     return (*i).second;
     294              : }
     295              : 
     296              : // FIXME: This can't work
     297              : /*
     298              : NBEdge*
     299              : NBEdgeCont::retrievePossiblySplit(const std::string& id, bool downstream) const {
     300              :     NBEdge* edge = retrieve(id);
     301              :     if (edge == 0) {
     302              :         return 0;
     303              :     }
     304              :     const EdgeVector* candidates = downstream ? &edge->getToNode()->getOutgoingEdges() : &edge->getFromNode()->getIncomingEdges();
     305              :     while (candidates->size() == 1) {
     306              :         const std::string& nextID = candidates->front()->getID();
     307              :         if (nextID.find(id) != 0 || nextID.size() <= id.size() + 1 || (nextID[id.size()] != '.' && nextID[id.size()] != '-')) {
     308              :             break;
     309              :         }
     310              :         edge = candidates->front();
     311              :         candidates = downstream ? &edge->getToNode()->getOutgoingEdges() : &edge->getFromNode()->getIncomingEdges();
     312              :     }
     313              :     return edge;
     314              : }*/
     315              : 
     316              : NBEdge*
     317          104 : NBEdgeCont::retrievePossiblySplit(const std::string& id, bool downstream) const {
     318          104 :     NBEdge* edge = retrieve(id);
     319          104 :     if (edge != nullptr) {
     320              :         return edge;
     321              :     }
     322              :     // NOTE: (TODO) for multiply split edges (e.g. 15[0][0]) one could try recursion
     323            0 :     if ((retrieve(id + "[0]") != nullptr) && (retrieve(id + "[1]") != nullptr)) {
     324              :         // Edge was split during the netbuilding process
     325            0 :         if (downstream) {
     326            0 :             return retrieve(id + "[1]");
     327              :         } else {
     328            0 :             return retrieve(id + "[0]");
     329              :         }
     330              :     }
     331              :     return edge;
     332              : }
     333              : 
     334              : 
     335              : NBEdge*
     336         2402 : NBEdgeCont::retrievePossiblySplit(const std::string& id, const std::string& hint, bool incoming) const {
     337              :     // try to retrieve using the given name (iterative)
     338         2402 :     NBEdge* edge = retrieve(id);
     339         2402 :     if (edge != nullptr) {
     340              :         return edge;
     341              :     }
     342              :     // now, we did not find it; we have to look over all possibilities
     343              :     EdgeVector hints;
     344              :     // check whether at least the hint was not splitted
     345          710 :     NBEdge* hintedge = retrieve(hint);
     346          710 :     if (hintedge == nullptr) {
     347          132 :         hints = getGeneratedFrom(hint);
     348              :     } else {
     349          578 :         hints.push_back(hintedge);
     350              :     }
     351          710 :     EdgeVector candidates = getGeneratedFrom(id);
     352          965 :     for (const NBEdge* const currHint : hints) {
     353         3555 :         for (NBEdge* const poss_searched : candidates) {
     354         3300 :             const NBNode* const node = incoming ? poss_searched->myTo : poss_searched->myFrom;
     355         3300 :             const EdgeVector& cont = incoming ? node->getOutgoingEdges() : node->getIncomingEdges();
     356         3300 :             if (find(cont.begin(), cont.end(), currHint) != cont.end()) {
     357              :                 return poss_searched;
     358              :             }
     359              :         }
     360              :     }
     361           33 :     return nullptr;
     362          710 : }
     363              : 
     364              : 
     365              : NBEdge*
     366          261 : NBEdgeCont::retrievePossiblySplit(const std::string& id, double pos) const {
     367              :     // check whether the edge was not split, yet
     368          261 :     NBEdge* edge = retrieve(id);
     369          261 :     if (edge != nullptr) {
     370              :         return edge;
     371              :     }
     372              :     int maxLength = 0;
     373          111 :     std::string tid = id + "[";
     374        21423 :     for (EdgeCont::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
     375        21312 :         if ((*i).first.find(tid) == 0) {
     376          660 :             maxLength = MAX2(maxLength, (int)(*i).first.length());
     377              :         }
     378              :     }
     379              :     // find the part of the edge which matches the position
     380              :     double seen = 0;
     381              :     std::vector<std::string> names;
     382          111 :     names.push_back(id + "[1]");
     383          111 :     names.push_back(id + "[0]");
     384          576 :     while (names.size() > 0) {
     385              :         // retrieve the first subelement (to follow)
     386              :         std::string cid = names.back();
     387              :         names.pop_back();
     388          558 :         edge = retrieve(cid);
     389              :         // The edge was splitted; check its subparts within the
     390              :         //  next step
     391          558 :         if (edge == nullptr) {
     392          231 :             if ((int)cid.length() + 3 < maxLength) {
     393          213 :                 names.push_back(cid + "[1]");
     394          426 :                 names.push_back(cid + "[0]");
     395              :             }
     396              :         }
     397              :         // an edge with the name was found,
     398              :         //  check whether the position lies within it
     399              :         else {
     400          327 :             seen += edge->getLength();
     401          327 :             if (seen >= pos) {
     402              :                 return edge;
     403              :             }
     404              :         }
     405              :     }
     406              :     return nullptr;
     407          111 : }
     408              : 
     409              : 
     410              : void
     411          378 : NBEdgeCont::erase(NBDistrictCont& dc, NBEdge* edge) {
     412          378 :     extract(dc, edge);
     413          378 :     delete edge;
     414          378 : }
     415              : 
     416              : 
     417              : void
     418         9314 : NBEdgeCont::extract(NBDistrictCont& dc, NBEdge* edge, bool remember) {
     419         9314 :     if (remember) {
     420         8911 :         const auto& prevExtracted = myExtractedEdges.find(edge->getID());
     421         8911 :         if (prevExtracted != myExtractedEdges.end()) {
     422           20 :             if (edge != prevExtracted->second) {
     423           18 :                 myEdgeCemetery.insert(prevExtracted->second);
     424           18 :                 prevExtracted->second = edge;
     425              :             }
     426              :         } else {
     427         8891 :             myExtractedEdges[edge->getID()] = edge;
     428              :         }
     429              :     }
     430         9314 :     myEdges.erase(edge->getID());
     431         9314 :     edge->myFrom->removeEdge(edge);
     432         9314 :     edge->myTo->removeEdge(edge);
     433         9314 :     dc.removeFromSinksAndSources(edge);
     434         9314 : }
     435              : 
     436              : 
     437              : void
     438          181 : NBEdgeCont::rename(NBEdge* edge, const std::string& newID) {
     439              :     if (myEdges.count(newID) != 0) {
     440            0 :         throw ProcessError(TLF("Attempt to rename edge using existing id '%'", newID));
     441              :     }
     442          181 :     myEdges.erase(edge->getID());
     443          181 :     edge->setID(newID);
     444          181 :     myEdges[newID] = edge;
     445              :     // update oppositeID
     446          181 :     if (edge->getLanes().back().oppositeID != "") {
     447            0 :         NBEdge* oppo = retrieve(SUMOXMLDefinitions::getEdgeIDFromLane(edge->getLanes().back().oppositeID));
     448            0 :         if (oppo != nullptr) {
     449            0 :             oppo->getLaneStruct(oppo->getNumLanes() - 1).oppositeID = edge->getLaneID(edge->getNumLanes() - 1);
     450              :         }
     451              :     }
     452          181 : }
     453              : 
     454              : 
     455              : // ----- explicit edge manipulation methods
     456              : 
     457              : void
     458        18485 : NBEdgeCont::processSplits(NBEdge* e, std::vector<Split> splits,
     459              :                           NBNodeCont& nc, NBDistrictCont& dc, NBTrafficLightLogicCont& tlc) {
     460        18485 :     if (splits.empty()) {
     461        18261 :         return;
     462              :     }
     463          226 :     const std::string origID = e->getID();
     464          226 :     sort(splits.begin(), splits.end(), split_sorter());
     465              :     int maxNumLanes = e->getNumLanes();
     466              :     // compute the node positions and sort the lanes
     467          529 :     for (Split& split : splits) {
     468          303 :         sort(split.lanes.begin(), split.lanes.end());
     469          303 :         maxNumLanes = MAX2(maxNumLanes, (int)split.lanes.size());
     470              :     }
     471              :     // split the edge
     472              :     std::vector<int> currLanes;
     473          648 :     for (int l = 0; l < e->getNumLanes(); ++l) {
     474          422 :         currLanes.push_back(l);
     475              :     }
     476          226 :     if (e->getNumLanes() != (int)splits.back().lanes.size()) {
     477              :         // invalidate traffic light definitions loaded from a SUMO network
     478          175 :         e->getToNode()->invalidateTLS(tlc, true, true);
     479              :         // if the number of lanes changes the connections should be
     480              :         // recomputed
     481          175 :         e->invalidateConnections(true);
     482              :     }
     483              : 
     484          226 :     std::string firstID = "";
     485              :     double seen = 0;
     486          527 :     for (const Split& exp : splits) {
     487              :         assert(exp.lanes.size() != 0);
     488          566 :         if (exp.pos > 0 && e->getLoadedLength() + seen > exp.pos && exp.pos > seen) {
     489          262 :             nc.insert(exp.node);
     490          262 :             nc.markAsSplit(exp.node);
     491              :             //  split the edge
     492          262 :             const std::string idBefore = exp.idBefore == "" ? e->getID() : exp.idBefore;
     493          262 :             const std::string idAfter = exp.idAfter == "" ? exp.nameID : exp.idAfter;
     494          262 :             if (firstID == "") {
     495              :                 firstID = idBefore;
     496              :             }
     497          262 :             const bool ok = splitAt(dc, e, exp.pos - seen, exp.node,
     498          262 :                                     idBefore, idAfter, e->getNumLanes(), (int) exp.lanes.size(), exp.speed);
     499          262 :             if (!ok) {
     500            6 :                 WRITE_WARNINGF(TL("Error on parsing a split (edge '%')."), origID);
     501              :                 return;
     502              :             }
     503          260 :             seen = exp.pos;
     504          260 :             std::vector<int> newLanes = exp.lanes;
     505          260 :             NBEdge* pe = retrieve(idBefore);
     506          260 :             NBEdge* ne = retrieve(idAfter);
     507              :             // reconnect lanes
     508          260 :             pe->invalidateConnections(true);
     509              :             //  new on right
     510          260 :             int rightMostP = currLanes[0];
     511          260 :             int rightMostN = newLanes[0];
     512          299 :             for (int l = 0; l < (int) rightMostP - (int) rightMostN; ++l) {
     513           78 :                 pe->addLane2LaneConnection(0, ne, l, NBEdge::Lane2LaneInfoType::VALIDATED, true);
     514              :             }
     515              :             //  new on left
     516          260 :             int leftMostP = currLanes.back();
     517          260 :             int leftMostN = newLanes.back();
     518          431 :             for (int l = 0; l < (int) leftMostN - (int) leftMostP; ++l) {
     519          342 :                 pe->addLane2LaneConnection(pe->getNumLanes() - 1, ne, leftMostN - l - rightMostN, NBEdge::Lane2LaneInfoType::VALIDATED, true);
     520              :             }
     521              :             //  all other connected
     522          943 :             for (int l = 0; l < maxNumLanes; ++l) {
     523          683 :                 if (find(currLanes.begin(), currLanes.end(), l) == currLanes.end()) {
     524          224 :                     continue;
     525              :                 }
     526          459 :                 if (find(newLanes.begin(), newLanes.end(), l) == newLanes.end()) {
     527           55 :                     continue;
     528              :                 }
     529          808 :                 pe->addLane2LaneConnection(l - rightMostP, ne, l - rightMostN, NBEdge::Lane2LaneInfoType::VALIDATED, true);
     530              :             }
     531              :             //  if there are edges at this node which are not connected
     532              :             //  we can assume that this split was attached to an
     533              :             //  existing node. Reset all connections to let the default
     534              :             //  algorithm recompute them
     535          260 :             if (exp.node->getIncomingEdges().size() > 1 || exp.node->getOutgoingEdges().size() > 1) {
     536           19 :                 for (NBEdge* in : exp.node->getIncomingEdges()) {
     537           13 :                     in->invalidateConnections(true);
     538              :                 }
     539              :             }
     540              :             // move to next
     541              :             e = ne;
     542          260 :             currLanes = newLanes;
     543          301 :         }  else if (exp.pos == 0) {
     544           40 :             const int laneCountDiff = e->getNumLanes() - (int)exp.lanes.size();
     545           40 :             if (laneCountDiff < 0) {
     546            1 :                 e->incLaneNo(-laneCountDiff);
     547              :             } else {
     548           39 :                 e->decLaneNo(laneCountDiff);
     549              :             }
     550           40 :             currLanes = exp.lanes;
     551              :             // invalidate traffic light definition loaded from a SUMO network
     552              :             // XXX it would be preferable to reconstruct the phase definitions heuristically
     553           40 :             e->getFromNode()->invalidateTLS(tlc, true, true);
     554           40 :             if (exp.speed != -1.) {
     555           40 :                 e->setSpeed(-1, exp.speed);
     556              :             }
     557              :         } else {
     558            3 :             WRITE_WARNINGF(TL("Split at '%' lies beyond the edge's length (edge '%')."), toString(exp.pos), origID);
     559              :         }
     560              :     }
     561              :     // patch lane offsets
     562          224 :     e = retrieve(firstID);
     563          224 :     if (e != nullptr) {
     564          222 :         if (splits.front().pos != 0) {
     565              :             // add a dummy split at the beginning to ensure correct offset
     566              :             Split start;
     567          183 :             start.pos = 0;
     568          516 :             for (int lane = 0; lane < (int)e->getNumLanes(); ++lane) {
     569          333 :                 start.lanes.push_back(lane);
     570              :             }
     571          183 :             start.offset = splits.front().offset;
     572          183 :             start.offsetFactor = splits.front().offsetFactor;
     573          183 :             splits.insert(splits.begin(), start);
     574          183 :         }
     575          703 :         for (const Split& split : splits) {
     576          481 :             int maxLeft = split.lanes.back();
     577          481 :             double offset = split.offset;
     578          481 :             if (maxLeft < maxNumLanes) {
     579          481 :                 if (e->getLaneSpreadFunction() == LaneSpreadFunction::RIGHT) {
     580          406 :                     offset += split.offsetFactor * SUMO_const_laneWidth * (maxNumLanes - 1 - maxLeft);
     581              :                 } else {
     582           75 :                     offset += split.offsetFactor * SUMO_const_halfLaneWidth * (maxNumLanes - 1 - maxLeft);
     583              :                 }
     584              :             }
     585          481 :             int maxRight = split.lanes.front();
     586          481 :             if (maxRight > 0 && e->getLaneSpreadFunction() == LaneSpreadFunction::CENTER) {
     587           19 :                 offset -= split.offsetFactor * SUMO_const_halfLaneWidth * maxRight;
     588              :             }
     589              :             //std::cout << " processSplits " << origID << " splitOffset=" << (*i).offset << " offset=" << offset << "\n";
     590          481 :             if (offset != 0) {
     591              :                 PositionVector g = e->getGeometry();
     592          267 :                 g.move2side(offset);
     593          267 :                 e->setGeometry(g);
     594          267 :             }
     595          481 :             if (e->getToNode()->getOutgoingEdges().size() != 0) {
     596          410 :                 e = e->getToNode()->getOutgoingEdges()[0];
     597              :             }
     598              :         }
     599              :     }
     600          226 : }
     601              : 
     602              : 
     603              : bool
     604          188 : NBEdgeCont::splitAt(NBDistrictCont& dc, NBEdge* edge, NBNode* node) {
     605          376 :     return splitAt(dc, edge, node, edge->getID() + "[0]", edge->getID() + "[1]",
     606          188 :                    (int) edge->myLanes.size(), (int) edge->myLanes.size());
     607              : }
     608              : 
     609              : 
     610              : bool
     611          313 : NBEdgeCont::splitAt(NBDistrictCont& dc, NBEdge* edge, NBNode* node,
     612              :                     const std::string& firstEdgeName,
     613              :                     const std::string& secondEdgeName,
     614              :                     int noLanesFirstEdge, int noLanesSecondEdge,
     615              :                     const double speed, const double friction,
     616              :                     const int changedLeft) {
     617              :     double pos;
     618          313 :     pos = edge->getGeometry().nearest_offset_to_point2D(node->getPosition());
     619          313 :     if (pos <= 0) {
     620            3 :         pos = GeomHelper::nearest_offset_on_line_to_point2D(
     621            3 :                   edge->myFrom->getPosition(), edge->myTo->getPosition(),
     622              :                   node->getPosition());
     623              :     }
     624          313 :     if (pos <= 0 || pos + POSITION_EPS > edge->getGeometry().length()) {
     625            3 :         return false;
     626              :     }
     627          310 :     return splitAt(dc, edge, pos, node, firstEdgeName, secondEdgeName,
     628          310 :                    noLanesFirstEdge, noLanesSecondEdge, speed, friction, changedLeft);
     629              : }
     630              : 
     631              : 
     632              : bool
     633          608 : NBEdgeCont::splitAt(NBDistrictCont& dc,
     634              :                     NBEdge* edge, double pos, NBNode* node,
     635              :                     const std::string& firstEdgeName,
     636              :                     const std::string& secondEdgeName,
     637              :                     int noLanesFirstEdge, int noLanesSecondEdge,
     638              :                     const double speed, const double friction,
     639              :                     const int changedLeft) {
     640          608 :     if (firstEdgeName != edge->getID() && myEdges.count(firstEdgeName) != 0) {
     641            0 :         WRITE_ERRORF(TL("Could not insert edge '%' before split of edge '%'."), firstEdgeName, edge->getID());
     642            0 :         return false;
     643              :     }
     644          608 :     if (secondEdgeName == firstEdgeName || (secondEdgeName != edge->getID() && myEdges.count(secondEdgeName) != 0)) {
     645            6 :         WRITE_ERRORF(TL("Could not insert edge '%' after split of edge '%'."), secondEdgeName, edge->getID());
     646            2 :         return false;
     647              :     }
     648              :     // there must be at least some overlap between first and second edge
     649              :     assert(changedLeft > -((int)noLanesFirstEdge));
     650              :     assert(changedLeft < (int)noLanesSecondEdge);
     651              : 
     652              :     // build the new edges' geometries
     653              :     double geomPos = pos;
     654          606 :     if (edge->hasLoadedLength()) {
     655            4 :         geomPos *= edge->getGeometry().length() / edge->getLoadedLength();
     656              :     }
     657          606 :     std::pair<PositionVector, PositionVector> geoms = edge->getGeometry().splitAt(geomPos);
     658              :     // reduce inaccuracies and preserve bidi
     659         1212 :     if (geoms.first[-1].almostSame(node->getPosition()) || edge->isBidi()) {
     660          453 :         geoms.first[-1] = node->getPosition();
     661          453 :         geoms.second[0] = node->getPosition();
     662              :     }
     663              :     // build and insert the edges
     664          606 :     NBEdge* one = new NBEdge(firstEdgeName, edge->myFrom, node, edge, geoms.first, noLanesFirstEdge);
     665          606 :     NBEdge* two = new NBEdge(secondEdgeName, node, edge->myTo, edge, geoms.second, noLanesSecondEdge);
     666         1212 :     if (OptionsCont::getOptions().getBool("output.original-names")) {
     667           54 :         const std::string origID = edge->getLaneStruct(0).getParameter(SUMO_PARAM_ORIGID, edge->getID());
     668           18 :         if (firstEdgeName != origID) {
     669           34 :             one->setOrigID(origID, false);
     670              :         }
     671           18 :         if (secondEdgeName != origID) {
     672           20 :             two->setOrigID(origID, false);
     673              :         }
     674              :     }
     675          606 :     two->copyConnectionsFrom(edge);
     676          606 :     if (speed != -1.) {
     677          260 :         two->setSpeed(-1, speed);
     678              :     }
     679          606 :     if (friction != -1.) {
     680          606 :         two->setFriction(-1, friction);
     681              :     }
     682          606 :     if (edge->getDistance() != 0) {
     683              :         one->setDistance(edge->getDistance());
     684            3 :         two->setDistance(one->getDistance() + pos);
     685              :     }
     686          606 :     if (edge->hasLoadedLength()) {
     687            4 :         one->setLoadedLength(pos);
     688            4 :         two->setLoadedLength(edge->getLoadedLength() - pos);
     689              :     }
     690              :     // replace information about this edge within the nodes
     691          606 :     edge->myFrom->replaceOutgoing(edge, one, 0);
     692          606 :     edge->myTo->replaceIncoming(edge, two, 0);
     693              :     // patch tls
     694          625 :     for (NBTrafficLightDefinition* const tld : edge->myFrom->getControllingTLS()) {
     695           19 :         tld->replaceRemoved(edge, -1, one, -1, false);
     696              :     }
     697          641 :     for (NBTrafficLightDefinition* const tld : edge->myTo->getControllingTLS()) {
     698           35 :         tld->replaceRemoved(edge, -1, two, -1, true);
     699              :     }
     700              :     // the edge is now occuring twice in both nodes...
     701              :     //  clean up
     702          606 :     edge->myFrom->removeDoubleEdges();
     703          606 :     edge->myTo->removeDoubleEdges();
     704              :     // add connections from the first to the second edge
     705              :     // there will be as many connections as there are lanes on the second edge
     706              :     // by default lanes will be added / discontinued on the right side
     707              :     // (appropriate for highway on-/off-ramps)
     708          606 :     const int offset = (int)one->getNumLanes() - (int)two->getNumLanes() + changedLeft;
     709         1866 :     for (int i2 = 0; i2 < (int)two->getNumLanes(); i2++) {
     710         1260 :         const int i1 = MIN2(MAX2((int)0, i2 + offset), (int)one->getNumLanes());
     711         2520 :         if (!one->addLane2LaneConnection(i1, two, i2, NBEdge::Lane2LaneInfoType::COMPUTED)) {
     712            0 :             throw ProcessError(TL("Could not set connection!"));
     713              :         }
     714              :     }
     715          606 :     if (myRemoveEdgesAfterLoading) {
     716            0 :         if (myEdges2Keep.count(edge->getID()) != 0) {
     717            0 :             myEdges2Keep.insert(one->getID());
     718            0 :             myEdges2Keep.insert(two->getID());
     719              :         }
     720            0 :         if (myEdges2Remove.count(edge->getID()) != 0) {
     721            0 :             myEdges2Remove.insert(one->getID());
     722            0 :             myEdges2Remove.insert(two->getID());
     723              :         }
     724              :     }
     725              :     // erase the splitted edge
     726          606 :     patchRoundabouts(edge, one, two, myRoundabouts);
     727          606 :     patchRoundabouts(edge, one, two, myGuessedRoundabouts);
     728          606 :     const std::string oldID = edge->getID();
     729          606 :     extract(dc, edge, true);
     730          606 :     insert(one, true);  // duplicate id check happened earlier
     731          606 :     insert(two, true);  // duplicate id check happened earlier
     732          606 :     myEdgesSplit[edge] = {one, two};
     733              :     myWasSplit.insert(one);
     734              :     myWasSplit.insert(two);
     735              :     return true;
     736              : }
     737              : 
     738              : 
     739              : void
     740         1212 : NBEdgeCont::patchRoundabouts(NBEdge* orig, NBEdge* part1, NBEdge* part2, std::set<EdgeSet>& roundabouts) {
     741              :     std::set<EdgeSet> addLater;
     742         1215 :     for (std::set<EdgeSet>::iterator it = roundabouts.begin(); it != roundabouts.end(); ++it) {
     743              :         EdgeSet roundaboutSet = *it;
     744              :         if (roundaboutSet.count(orig) > 0) {
     745              :             roundaboutSet.erase(orig);
     746              :             roundaboutSet.insert(part1);
     747              :             roundaboutSet.insert(part2);
     748              :         }
     749              :         addLater.insert(roundaboutSet);
     750              :     }
     751              :     roundabouts.clear();
     752         1212 :     roundabouts.insert(addLater.begin(), addLater.end());
     753         1212 : }
     754              : 
     755              : 
     756              : // ----- container access methods
     757              : std::vector<std::string>
     758           53 : NBEdgeCont::getAllNames() const {
     759              :     std::vector<std::string> ret;
     760        17696 :     for (EdgeCont::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
     761        17643 :         ret.push_back((*i).first);
     762              :     }
     763           53 :     return ret;
     764            0 : }
     765              : 
     766              : 
     767              : // ----- Adapting the input
     768              : int
     769            2 : NBEdgeCont::removeUnwishedEdges(NBDistrictCont& dc) {
     770              :     EdgeVector toRemove;
     771           32 :     for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
     772           30 :         NBEdge* edge = (*i).second;
     773           30 :         if (!myEdges2Keep.count(edge->getID())) {
     774           13 :             edge->getFromNode()->removeEdge(edge);
     775           13 :             edge->getToNode()->removeEdge(edge);
     776           13 :             toRemove.push_back(edge);
     777              :         }
     778              :     }
     779           15 :     for (EdgeVector::iterator j = toRemove.begin(); j != toRemove.end(); ++j) {
     780           13 :         erase(dc, *j);
     781              :     }
     782            2 :     return (int)toRemove.size();
     783            2 : }
     784              : 
     785              : 
     786              : void
     787            3 : NBEdgeCont::splitGeometry(NBDistrictCont& dc, NBNodeCont& nc) {
     788              :     // make a copy of myEdges because splitting will modify it
     789              :     EdgeCont edges = myEdges;
     790           36 :     for (auto& item : edges) {
     791           33 :         NBEdge* edge = item.second;
     792           33 :         if (edge->getGeometry().size() < 3) {
     793            0 :             continue;
     794              :         }
     795              :         PositionVector geom = edge->getGeometry();
     796           33 :         const std::string id = edge->getID();
     797              :         double offset = 0;
     798          155 :         for (int i = 1; i < (int)geom.size() - 1; i++) {
     799          122 :             offset += geom[i - 1].distanceTo(geom[i]);
     800          244 :             std::string nodeID = id + "." + toString((int)offset);
     801          122 :             if (!nc.insert(nodeID, geom[i])) {
     802          126 :                 WRITE_WARNING("Could not split geometry of edge '" + id + "' at index " + toString(i));
     803              :                 continue;
     804              :             }
     805           80 :             NBNode* node = nc.retrieve(nodeID);
     806           80 :             splitAt(dc, edge, node, edge->getID(), nodeID, edge->getNumLanes(), edge->getNumLanes());
     807           80 :             edge = retrieve(nodeID);
     808              :         }
     809           33 :     }
     810            3 : }
     811              : 
     812              : 
     813              : void
     814           11 : NBEdgeCont::reduceGeometries(const double minDist) {
     815          473 :     for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
     816          462 :         (*i).second->reduceGeometry(minDist);
     817              :     }
     818           11 : }
     819              : 
     820              : 
     821              : void
     822         1651 : NBEdgeCont::checkGeometries(const double maxAngle, bool fixAngle, const double minRadius, bool fix, bool fixRailways, bool silent) {
     823         1651 :     if (maxAngle > 0 || minRadius > 0) {
     824        85681 :         for (auto& item : myEdges) {
     825        84030 :             if (isSidewalk(item.second->getPermissions()) || isForbidden(item.second->getPermissions())) {
     826        15563 :                 continue;
     827              :             }
     828       136934 :             item.second->checkGeometry(maxAngle, fixAngle, minRadius, fix || (fixRailways && isRailway(item.second->getPermissions())), silent);
     829              :         }
     830              :     }
     831         1651 : }
     832              : 
     833              : 
     834              : // ----- processing methods
     835              : void
     836         1704 : NBEdgeCont::clearControllingTLInformation() const {
     837        92564 :     for (EdgeCont::const_iterator i = myEdges.begin(); i != myEdges.end(); i++) {
     838        90860 :         (*i).second->clearControllingTLInformation();
     839              :     }
     840         1704 : }
     841              : 
     842              : 
     843              : void
     844         1704 : NBEdgeCont::sortOutgoingLanesConnections() {
     845        92564 :     for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); i++) {
     846        90860 :         (*i).second->sortOutgoingConnectionsByAngle();
     847              :     }
     848         1704 : }
     849              : 
     850              : 
     851              : void
     852         1704 : NBEdgeCont::computeEdge2Edges(bool noLeftMovers) {
     853        92564 :     for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); i++) {
     854        90860 :         (*i).second->computeEdge2Edges(noLeftMovers);
     855              :     }
     856         1704 : }
     857              : 
     858              : 
     859              : void
     860         1704 : NBEdgeCont::computeLanes2Edges() {
     861        92564 :     for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); i++) {
     862        90860 :         (*i).second->computeLanes2Edges();
     863              :     }
     864         1704 : }
     865              : 
     866              : 
     867              : void
     868         1704 : NBEdgeCont::recheckLanes() {
     869         3408 :     const bool fixOppositeLengths = OptionsCont::getOptions().getBool("opposites.guess.fix-lengths");
     870        92564 :     for (const auto& edgeIt : myEdges) {
     871        90860 :         NBEdge* const edge = edgeIt.second;
     872        90860 :         edge->recheckLanes();
     873              :         // check opposites
     874        90860 :         if (edge->getNumLanes() > 0) {
     875        90860 :             const int leftmostLane = edge->getNumLanes() - 1;
     876              :             // check oppositeID stored in other lanes
     877       118618 :             for (int i = 0; i < leftmostLane; i++) {
     878        27758 :                 const std::string& oppositeID = edge->getLanes()[i].oppositeID;
     879        55516 :                 NBEdge* oppEdge = retrieve(oppositeID.substr(0, oppositeID.rfind("_")));
     880        27758 :                 if (oppositeID != "" && oppositeID != "-") {
     881            6 :                     if (edge->getLanes().back().oppositeID == "" && oppEdge != nullptr) {
     882            1 :                         edge->getLaneStruct(leftmostLane).oppositeID = oppositeID;
     883            3 :                         WRITE_WARNINGF(TL("Moving opposite lane '%' from invalid lane '%' to lane index %."), oppositeID, edge->getLaneID(i), leftmostLane);
     884              :                     } else {
     885           15 :                         WRITE_WARNINGF(TL("Removing opposite lane '%' for invalid lane '%'."), oppositeID, edge->getLaneID(i));
     886              :                     }
     887            6 :                     edge->getLaneStruct(i).oppositeID = "";
     888              :                 }
     889              :             }
     890        90860 :             const std::string& oppositeID = edge->getLanes().back().oppositeID;
     891        90860 :             if (oppositeID != "" && oppositeID != "-") {
     892           96 :                 NBEdge* oppEdge = retrieve(oppositeID.substr(0, oppositeID.rfind("_")));
     893           96 :                 if (oppEdge == nullptr) {
     894            3 :                     WRITE_WARNINGF(TL("Removing unknown opposite lane '%' for edge '%'."), oppositeID, edge->getID());
     895            1 :                     edge->getLaneStruct(leftmostLane).oppositeID = "";
     896            3 :                     continue;
     897          190 :                 } else if (oppEdge->getLaneID(oppEdge->getNumLanes() - 1) != oppositeID) {
     898            1 :                     const std::string oppEdgeLeftmost = oppEdge->getLaneID(oppEdge->getNumLanes() - 1);
     899            4 :                     WRITE_WARNINGF(TL("Adapting invalid opposite lane '%' for edge '%' to '%'."), oppositeID, edge->getID(), oppEdgeLeftmost);
     900            1 :                     edge->getLaneStruct(leftmostLane).oppositeID = oppEdgeLeftmost;
     901              :                 }
     902           95 :                 NBEdge::Lane& oppLane = oppEdge->getLaneStruct(oppEdge->getNumLanes() - 1);
     903           95 :                 if (oppLane.oppositeID == "") {
     904            4 :                     const std::string leftmostID = edge->getLaneID(leftmostLane);
     905           12 :                     WRITE_WARNINGF(TL("Adapting missing opposite lane '%' for edge '%'."), leftmostID, oppEdge->getID());
     906              :                     oppLane.oppositeID = leftmostID;
     907              :                 }
     908           95 :                 if (fabs(oppEdge->getLoadedLength() - edge->getLoadedLength()) > NUMERICAL_EPS) {
     909            3 :                     if (fixOppositeLengths) {
     910            1 :                         const double avgLength = 0.5 * (edge->getFinalLength() + oppEdge->getFinalLength());
     911            4 :                         WRITE_WARNINGF(TL("Averaging edge lengths for lane '%' (length %) and edge '%' (length %)."),
     912              :                                        oppositeID, oppEdge->getLoadedLength(), edge->getID(), edge->getLoadedLength());
     913            1 :                         edge->setLoadedLength(avgLength);
     914            1 :                         oppEdge->setLoadedLength(avgLength);
     915              :                     } else {
     916           10 :                         WRITE_ERROR("Opposite lane '" + oppositeID + "' (length " + toString(oppEdge->getLoadedLength()) +
     917              :                                     ") differs in length from edge '" + edge->getID() + "' (length " +
     918              :                                     toString(edge->getLoadedLength()) + "). Set --opposites.guess.fix-lengths to fix this.");
     919            2 :                         edge->getLaneStruct(edge->getNumLanes() - 1).oppositeID = "";
     920            2 :                         continue;
     921              :                     }
     922              :                 }
     923           93 :                 if (oppEdge->getFromNode() != edge->getToNode() || oppEdge->getToNode() != edge->getFromNode()) {
     924            3 :                     WRITE_ERRORF(TL("Opposite lane '%' does not connect the same nodes as edge '%'!"), oppositeID, edge->getID());
     925            1 :                     edge->getLaneStruct(edge->getNumLanes() - 1).oppositeID = "";
     926              :                 }
     927              :             }
     928              :         }
     929              :         // check for matching bidi lane shapes (at least for the simple case of 1-lane edges)
     930        90857 :         const NBEdge* bidi = edge->getBidiEdge();
     931        90857 :         if (bidi != nullptr && edge->getNumLanes() == 1 && bidi->getNumLanes() == 1 && edge->getID() < bidi->getID()) {
     932         4054 :             edge->getLaneStruct(0).shape = bidi->getLaneStruct(0).shape.reverse();
     933              :         }
     934              : 
     935              :         // check for valid offset and speed
     936        94901 :         const double startOffset = edge->isBidiRail() ? edge->getTurnDestination(true)->getEndOffset() : 0;
     937              :         int i = 0;
     938       209470 :         for (const NBEdge::Lane& l : edge->getLanes()) {
     939       118613 :             if (startOffset + l.endOffset > edge->getLength()) {
     940            4 :                 WRITE_WARNINGF(TL("Invalid endOffset % at lane '%' with length % (startOffset %)."),
     941              :                                toString(l.endOffset), edge->getLaneID(i), toString(l.shape.length()), toString(startOffset));
     942       118611 :             } else if (l.speed < 0.) {
     943            0 :                 WRITE_WARNINGF(TL("Negative allowed speed (%) on lane '%', use --speed.minimum to prevent this."), toString(l.speed), edge->getLaneID(i));
     944       118611 :             } else if (l.speed == 0.) {
     945            0 :                 WRITE_WARNINGF(TL("Lane '%' has a maximum allowed speed of 0."), edge->getLaneID(i));
     946              :             }
     947       118613 :             i++;
     948              :         }
     949              :     }
     950         1704 : }
     951              : 
     952              : 
     953              : void
     954         1020 : NBEdgeCont::appendTurnarounds(bool noTLSControlled, bool noFringe, bool onlyDeadends, bool onlyTurnlane, bool noGeometryLike) {
     955        66533 :     for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); i++) {
     956        65513 :         (*i).second->appendTurnaround(noTLSControlled, noFringe, onlyDeadends, onlyTurnlane, noGeometryLike, true);
     957              :     }
     958         1020 : }
     959              : 
     960              : 
     961              : void
     962          684 : NBEdgeCont::appendTurnarounds(const std::set<std::string>& ids, bool noTLSControlled) {
     963          684 :     for (std::set<std::string>::const_iterator it = ids.begin(); it != ids.end(); it++) {
     964            0 :         myEdges[*it]->appendTurnaround(noTLSControlled, false, false, false, false, false);
     965              :     }
     966          684 : }
     967              : 
     968              : 
     969              : void
     970           25 : NBEdgeCont::appendRailwayTurnarounds(const NBPTStopCont& sc) {
     971              :     std::set<std::string> stopEdgeIDs;
     972          373 :     for (auto& stopItem : sc.getStops()) {
     973          348 :         stopEdgeIDs.insert(stopItem.second->getEdgeId());
     974              :     }
     975         7166 :     for (auto& item : myEdges) {
     976         7141 :         NBEdge* edge = item.second;
     977         7141 :         if (edge->isBidiRail()
     978         7141 :                 && (stopEdgeIDs.count(item.first) > 0 ||
     979         2182 :                     stopEdgeIDs.count(edge->getTurnDestination(true)->getID()) > 0)) {
     980          296 :             NBEdge* to = edge->getTurnDestination(true);
     981              :             assert(to != 0);
     982          592 :             edge->setConnection(edge->getNumLanes() - 1,
     983              :                                 to, to->getNumLanes() - 1, NBEdge::Lane2LaneInfoType::VALIDATED, false, false,
     984              :                                 KEEPCLEAR_UNSPECIFIED,
     985              :                                 NBEdge::UNSPECIFIED_CONTPOS, NBEdge::UNSPECIFIED_VISIBILITY_DISTANCE,
     986              :                                 SUMO_const_haltingSpeed);
     987              :         }
     988              :     }
     989           25 : }
     990              : 
     991              : void
     992         1853 : NBEdgeCont::computeEdgeShapes(double smoothElevationThreshold) {
     993       125603 :     for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); i++) {
     994       123750 :         (*i).second->computeEdgeShape(smoothElevationThreshold);
     995              :     }
     996              :     // equalize length of opposite edges
     997       125603 :     for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); i++) {
     998       123750 :         NBEdge* edge = i->second;
     999       123750 :         const std::string& oppositeID = edge->getLanes().back().oppositeID;
    1000       123750 :         if (oppositeID != "" && oppositeID != "-") {
    1001           93 :             NBEdge* oppEdge = retrieve(oppositeID.substr(0, oppositeID.rfind("_")));
    1002          185 :             if (oppEdge == nullptr || oppEdge->getLaneID(oppEdge->getNumLanes() - 1) != oppositeID) {
    1003            1 :                 continue;
    1004              :             }
    1005           92 :             if (fabs(oppEdge->getLength() - edge->getLength()) > NUMERICAL_EPS) {
    1006            5 :                 double avgLength = (oppEdge->getLength() + edge->getLength()) / 2;
    1007            5 :                 edge->setAverageLengthWithOpposite(avgLength);
    1008            5 :                 oppEdge->setAverageLengthWithOpposite(avgLength);
    1009              :             }
    1010              :         }
    1011              :     }
    1012         1853 : }
    1013              : 
    1014              : 
    1015              : void
    1016         1853 : NBEdgeCont::computeLaneShapes() {
    1017       125603 :     for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
    1018       123750 :         (*i).second->computeLaneShapes();
    1019              :     }
    1020         1853 : }
    1021              : 
    1022              : 
    1023              : void
    1024           12 : NBEdgeCont::joinSameNodeConnectingEdges(NBDistrictCont& dc,
    1025              :                                         NBTrafficLightLogicCont& tlc,
    1026              :                                         EdgeVector edges) {
    1027              :     // !!! Attention!
    1028              :     //  No merging of the geometry to come is being done
    1029              :     //  The connections are moved from one edge to another within
    1030              :     //   the replacement where the edge is a node's incoming edge.
    1031              : 
    1032              :     // count the number of lanes, the speed and the id
    1033              :     int nolanes = 0;
    1034              :     double speed = 0;
    1035              :     int priority = -1;
    1036              :     bool joinEdges = true;
    1037              :     std::string id;
    1038           12 :     sort(edges.begin(), edges.end(), NBContHelper::same_connection_edge_sorter());
    1039              :     // retrieve the connected nodes
    1040           12 :     NBEdge* tpledge = *(edges.begin());
    1041              :     NBNode* from = tpledge->getFromNode();
    1042              :     NBNode* to = tpledge->getToNode();
    1043              :     EdgeVector::const_iterator i;
    1044              :     int myPriority = (*edges.begin())->getPriority();
    1045           36 :     for (i = edges.begin(); i != edges.end(); i++) {
    1046              :         // some assertions
    1047              :         assert((*i)->getFromNode() == from);
    1048              :         assert((*i)->getToNode() == to);
    1049              :         // ad the number of lanes the current edge has
    1050           24 :         nolanes += (*i)->getNumLanes();
    1051              :         // build the id
    1052           24 :         if (i != edges.begin()) {
    1053              :             id += "+";
    1054              :         }
    1055           24 :         id += (*i)->getID();
    1056              :         // compute the speed
    1057           24 :         speed += (*i)->getSpeed();
    1058              :         // build the priority
    1059              :         // merged edges should have the same inherited priority
    1060           24 :         if (myPriority == (*i)->getPriority()) {
    1061              :             priority = myPriority;
    1062              :         } else {
    1063              :             priority = -1;
    1064              :             joinEdges = false;
    1065              :         }
    1066              :     }
    1067           12 :     if (joinEdges) {
    1068           11 :         speed /= (double)edges.size();
    1069              :         // build the new edge
    1070              :         NBEdge* newEdge = new NBEdge(id, from, to, "", speed, NBEdge::UNSPECIFIED_FRICTION, nolanes, priority,
    1071              :                                      NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET,
    1072           22 :                                      tpledge->myLaneSpreadFunction, tpledge->getStreetName());
    1073              :         // copy lane attributes
    1074              :         int laneIndex = 0;
    1075           33 :         for (i = edges.begin(); i != edges.end(); ++i) {
    1076           22 :             const std::vector<NBEdge::Lane>& lanes = (*i)->getLanes();
    1077           49 :             for (int j = 0; j < (int)lanes.size(); ++j) {
    1078           27 :                 newEdge->setPermissions(lanes[j].permissions, laneIndex);
    1079           27 :                 newEdge->setLaneWidth(laneIndex, lanes[j].width);
    1080           27 :                 newEdge->setEndOffset(laneIndex, lanes[j].endOffset);
    1081           27 :                 laneIndex++;
    1082              :             }
    1083              :         }
    1084           11 :         insert(newEdge, true);
    1085              :         // replace old edge by current within the nodes
    1086              :         //  and delete the old
    1087           11 :         from->replaceOutgoing(edges, newEdge);
    1088           11 :         to->replaceIncoming(edges, newEdge);
    1089              :         // patch connections
    1090              :         //  add edge2edge-information
    1091           33 :         for (i = edges.begin(); i != edges.end(); i++) {
    1092           22 :             EdgeVector ev = (*i)->getConnectedEdges();
    1093           59 :             for (EdgeVector::iterator j = ev.begin(); j != ev.end(); j++) {
    1094           37 :                 newEdge->addEdge2EdgeConnection(*j);
    1095              :             }
    1096           22 :         }
    1097              :         //  copy outgoing connections to the new edge
    1098              :         int currLane = 0;
    1099           33 :         for (i = edges.begin(); i != edges.end(); i++) {
    1100           22 :             newEdge->moveOutgoingConnectionsFrom(*i, currLane);
    1101           22 :             currLane += (*i)->getNumLanes();
    1102              :         }
    1103              :         // patch tl-information
    1104              :         currLane = 0;
    1105           33 :         for (i = edges.begin(); i != edges.end(); i++) {
    1106           22 :             int noLanes = (*i)->getNumLanes();
    1107           49 :             for (int j = 0; j < noLanes; j++, currLane++) {
    1108              :                 // replace in traffic lights
    1109           27 :                 tlc.replaceRemoved(*i, j, newEdge, currLane, true);
    1110           27 :                 tlc.replaceRemoved(*i, j, newEdge, currLane, false);
    1111              :             }
    1112              :         }
    1113              :         // delete joined edges
    1114           33 :         for (i = edges.begin(); i != edges.end(); i++) {
    1115           22 :             extract(dc, *i, true);
    1116              :         }
    1117              :     }
    1118           12 : }
    1119              : 
    1120              : 
    1121              : void
    1122           16 : NBEdgeCont::guessOpposites() {
    1123              :     //@todo magic values
    1124           63 :     for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
    1125           47 :         NBEdge* edge = i->second;
    1126           47 :         edge->guessOpposite();
    1127              :     }
    1128           16 : }
    1129              : 
    1130              : 
    1131              : void
    1132           49 : NBEdgeCont::recheckLaneSpread() {
    1133          704 :     for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
    1134          655 :         NBEdge* opposite = getOppositeByID(i->first);
    1135          655 :         if (opposite != nullptr) {
    1136          324 :             i->second->setLaneSpreadFunction(LaneSpreadFunction::RIGHT);
    1137          324 :             opposite->setLaneSpreadFunction(LaneSpreadFunction::RIGHT);
    1138              :         } else {
    1139          331 :             i->second->setLaneSpreadFunction(LaneSpreadFunction::CENTER);
    1140              :         }
    1141              :     }
    1142           49 : }
    1143              : 
    1144              : 
    1145              : NBEdge*
    1146         1141 : NBEdgeCont::getOppositeByID(const std::string& edgeID) const {
    1147         1141 :     const std::string oppositeID = edgeID[0] == '-' ? edgeID.substr(1) :  "-" + edgeID;
    1148              :     EdgeCont::const_iterator it = myEdges.find(oppositeID);
    1149         1141 :     return it != myEdges.end() ? it->second : (NBEdge*)nullptr;
    1150              : }
    1151              : 
    1152              : NBEdge*
    1153        19086 : NBEdgeCont::getByID(const std::string& edgeID) const {
    1154              :     EdgeCont::const_iterator it = myEdges.find(edgeID);
    1155        19086 :     return it != myEdges.end() ? it->second : (NBEdge*)nullptr;
    1156              : }
    1157              : 
    1158              : // ----- other
    1159              : void
    1160           18 : NBEdgeCont::addPostProcessConnection(const std::string& from, int fromLane, const std::string& to, int toLane, bool mayDefinitelyPass,
    1161              :                                      KeepClear keepClear, double contPos, double visibility, double speed, double friction, double length,
    1162              :                                      const PositionVector& customShape, bool uncontrolled, bool warnOnly,
    1163              :                                      SVCPermissions permissions, bool indirectLeft, const std::string& edgeType, SVCPermissions changeLeft, SVCPermissions changeRight) {
    1164           36 :     myConnections[from].push_back(PostProcessConnection(from, fromLane, to, toLane, mayDefinitelyPass, keepClear, contPos, visibility,
    1165              :                                   speed, friction, length, customShape, uncontrolled, warnOnly, permissions, indirectLeft, edgeType, changeLeft, changeRight));
    1166           18 : }
    1167              : 
    1168              : bool
    1169         7909 : NBEdgeCont::hasPostProcessConnection(const std::string& from, const std::string& to) {
    1170              :     if (myConnections.count(from) == 0) {
    1171         7905 :         return false;
    1172              :     } else {
    1173            4 :         if (to == "") {
    1174              :             // wildcard
    1175              :             return true;
    1176              :         }
    1177            0 :         for (const auto& ppc : myConnections[from]) {
    1178            0 :             if (ppc.to == to) {
    1179              :                 return true;
    1180              :             }
    1181              :         }
    1182              :         return false;
    1183              :     }
    1184              : }
    1185              : 
    1186              : void
    1187         1704 : NBEdgeCont::recheckPostProcessConnections() {
    1188         3320 :     const bool warnOnly = OptionsCont::getOptions().exists("ignore-errors.connections") && OptionsCont::getOptions().getBool("ignore-errors.connections");
    1189         1711 :     for (const auto& item : myConnections) {
    1190           25 :         for (std::vector<PostProcessConnection>::const_iterator i = item.second.begin(); i != item.second.end(); ++i) {
    1191           18 :             NBEdge* from = retrievePossiblySplit((*i).from, true);
    1192           18 :             NBEdge* to = retrievePossiblySplit((*i).to, false);
    1193           36 :             if (from == nullptr || to == nullptr ||
    1194           18 :                     !from->addLane2LaneConnection((*i).fromLane, to, (*i).toLane, NBEdge::Lane2LaneInfoType::USER, true, (*i).mayDefinitelyPass,
    1195           18 :                                                   (*i).keepClear, (*i).contPos, (*i).visibility, (*i).speed, (*i).friction, (*i).customLength, (*i).customShape,
    1196           18 :                                                   (*i).uncontrolled, (*i).permissions, (*i).indirectLeft, (*i).edgeType, (*i).changeLeft, (*i).changeRight,
    1197              :                                                   true)) {
    1198            1 :                 const std::string msg = "Could not insert connection between '" + (*i).from + "' and '" + (*i).to + "' after build.";
    1199            1 :                 if (warnOnly || (*i).warnOnly) {
    1200            0 :                     WRITE_WARNING(msg);
    1201              :                 } else {
    1202            3 :                     WRITE_ERROR(msg);
    1203              :                 }
    1204              :             }
    1205              :         }
    1206              :     }
    1207              :     // during loading we also kept some ambiguous connections in hope they might be valid after processing
    1208              :     // we need to make sure that all invalid connections are removed now
    1209        92564 :     for (EdgeCont::iterator it = myEdges.begin(); it != myEdges.end(); ++it) {
    1210        90860 :         NBEdge* edge = it->second;
    1211              :         NBNode* to = edge->getToNode();
    1212              :         // make a copy because we may delete connections
    1213        90860 :         std::vector<NBEdge::Connection> connections = edge->getConnections();
    1214       142482 :         for (std::vector<NBEdge::Connection>::iterator it_con = connections.begin(); it_con != connections.end(); ++it_con) {
    1215              :             NBEdge::Connection& c = *it_con;
    1216        51622 :             if (c.toEdge != nullptr && c.toEdge->getFromNode() != to) {
    1217           12 :                 WRITE_WARNING("Found and removed invalid connection from edge '" + edge->getID() +
    1218              :                               "' to edge '" + c.toEdge->getID() + "' via junction '" + to->getID() + "'.");
    1219            6 :                 edge->removeFromConnections(c.toEdge);
    1220              :             }
    1221              :         }
    1222        90860 :     }
    1223         1704 : }
    1224              : 
    1225              : 
    1226              : EdgeVector
    1227          842 : NBEdgeCont::getGeneratedFrom(const std::string& id) const {
    1228          842 :     int len = (int)id.length();
    1229              :     EdgeVector ret;
    1230       149420 :     for (EdgeCont::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
    1231              :         std::string curr = (*i).first;
    1232              :         // the next check makes it possibly faster - we don not have
    1233              :         //  to compare the names
    1234       148578 :         if ((int)curr.length() <= len) {
    1235        55988 :             continue;
    1236              :         }
    1237              :         // the name must be the same as the given id but something
    1238              :         //  beginning with a '[' must be appended to it
    1239       185180 :         if (curr.substr(0, len) == id && curr[len] == '[') {
    1240         4828 :             ret.push_back((*i).second);
    1241         4828 :             continue;
    1242              :         }
    1243              :         // ok, maybe the edge is a compound made during joining of edges
    1244              :         std::string::size_type pos = curr.find(id);
    1245              :         // surely not
    1246        87762 :         if (pos == std::string::npos) {
    1247        75438 :             continue;
    1248              :         }
    1249              :         // check leading char
    1250        12324 :         if (pos > 0) {
    1251         3975 :             if (curr[pos - 1] != ']' && curr[pos - 1] != '+') {
    1252              :                 // actually, this is another id
    1253         3975 :                 continue;
    1254              :             }
    1255              :         }
    1256         8349 :         if (pos + id.length() < curr.length()) {
    1257         8349 :             if (curr[pos + id.length()] != '[' && curr[pos + id.length()] != '+') {
    1258              :                 // actually, this is another id
    1259         8349 :                 continue;
    1260              :             }
    1261              :         }
    1262            0 :         ret.push_back((*i).second);
    1263              :     }
    1264          842 :     return ret;
    1265            0 : }
    1266              : 
    1267              : 
    1268              : int
    1269         1872 : NBEdgeCont::guessRoundabouts() {
    1270              :     myGuessedRoundabouts.clear();
    1271              :     std::set<NBEdge*> loadedRoundaboutEdges;
    1272         1943 :     for (std::set<EdgeSet>::const_iterator it = myRoundabouts.begin(); it != myRoundabouts.end(); ++it) {
    1273           71 :         loadedRoundaboutEdges.insert(it->begin(), it->end());
    1274              :     }
    1275              :     // step 1: keep only those edges which have no turnarounds and which are not
    1276              :     // part of a loaded roundabout
    1277              :     std::set<NBEdge*> candidates;
    1278         1872 :     SVCPermissions valid = SVCAll & ~SVC_PEDESTRIAN;
    1279       126648 :     for (EdgeCont::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
    1280       124776 :         NBEdge* e = (*i).second;
    1281              :         NBNode* const to = e->getToNode();
    1282       124776 :         if (e->getTurnDestination() == nullptr
    1283        56868 :                 && to->getConnectionTo(e->getFromNode()) == nullptr
    1284       171363 :                 && (e->getPermissions() & valid) != 0) {
    1285              :             candidates.insert(e);
    1286              :         }
    1287              :     }
    1288              : 
    1289              :     // step 2:
    1290              :     std::set<NBEdge*> visited;
    1291        28818 :     for (std::set<NBEdge*>::const_iterator i = candidates.begin(); i != candidates.end(); ++i) {
    1292              :         EdgeVector loopEdges;
    1293              :         // start with a random edge (this doesn't have to be a roundabout edge)
    1294              :         // loop over connected edges (using always the leftmost one)
    1295              :         // and keep the list in loopEdges
    1296              :         // continue until we loop back onto a loopEdges and extract the loop
    1297        26946 :         NBEdge* e = (*i);
    1298        12384 :         if (visited.count(e) > 0) {
    1299              :             // already seen
    1300              :             continue;
    1301              :         }
    1302        14562 :         loopEdges.push_back(e);
    1303              :         bool doLoop = true;
    1304              : #ifdef DEBUG_GUESS_ROUNDABOUT
    1305              :         gDebugFlag1 = e->getID() == DEBUG_EDGE_ID;
    1306              : #endif
    1307        18881 :         do {
    1308              : #ifdef DEBUG_GUESS_ROUNDABOUT
    1309              :             if (gDebugFlag1) {
    1310              :                 std::cout << " e=" << e->getID() << " loopEdges=" << toString(loopEdges) << "\n";
    1311              :                 gDebugFlag1 = true;
    1312              :             }
    1313              : #endif
    1314              :             visited.insert(e);
    1315        29527 :             const EdgeVector& edges = e->getToNode()->getEdges();
    1316        28516 :             if ((e->getToNode()->getType() == SumoXMLNodeType::RIGHT_BEFORE_LEFT || e->getToNode()->getType() == SumoXMLNodeType::LEFT_BEFORE_RIGHT)
    1317        29527 :                     && !e->getToNode()->typeWasGuessed()) {
    1318              :                 doLoop = false;
    1319              : #ifdef DEBUG_GUESS_ROUNDABOUT
    1320              :                 if (gDebugFlag1) {
    1321              :                     std::cout << " rbl\n";
    1322              :                 }
    1323              :                 gDebugFlag1 = false;
    1324              : #endif
    1325        10646 :                 break;
    1326              :             }
    1327        28889 :             if (edges.size() < 2) {
    1328              :                 doLoop = false;
    1329              : #ifdef DEBUG_GUESS_ROUNDABOUT
    1330              :                 if (gDebugFlag1) {
    1331              :                     std::cout << " deadend\n";
    1332              :                 }
    1333              :                 gDebugFlag1 = false;
    1334              : #endif
    1335              :                 break;
    1336              :             }
    1337        25848 :             if (e->getTurnDestination() != nullptr || e->getToNode()->getConnectionTo(e->getFromNode()) != nullptr) {
    1338              :                 // do not follow turn-arounds while in a (tentative) loop
    1339              :                 doLoop = false;
    1340              : #ifdef DEBUG_GUESS_ROUNDABOUT
    1341              :                 if (gDebugFlag1) {
    1342              :                     std::cout << " invalid turnAround e=" << e->getID() << " dest=" << Named::getIDSecure(e->getTurnDestination()) << "\n";
    1343              :                 }
    1344              :                 gDebugFlag1 = false;
    1345              : #endif
    1346              :                 break;
    1347              :             }
    1348        23267 :             EdgeVector::const_iterator me = std::find(edges.begin(), edges.end(), e);
    1349        23267 :             NBContHelper::nextCW(edges, me);
    1350        23267 :             NBEdge* left = *me;
    1351        24918 :             while ((left->getPermissions() & valid) == 0 && left != e) {
    1352         1651 :                 NBContHelper::nextCW(edges, me);
    1353         1651 :                 left = *me;
    1354              :             }
    1355        23267 :             if (left == e) {
    1356              :                 // no usable continuation edge found
    1357              :                 doLoop = false;
    1358              : #ifdef DEBUG_GUESS_ROUNDABOUT
    1359              :                 if (gDebugFlag1) {
    1360              :                     std::cout << " noContinuation\n";
    1361              :                 }
    1362              :                 gDebugFlag1 = false;
    1363              : #endif
    1364              :                 break;
    1365              :             }
    1366        23239 :             NBContHelper::nextCW(edges, me);
    1367        23239 :             NBEdge* nextLeft = *me;
    1368        23239 :             double angle = fabs(NBHelpers::relAngle(e->getAngleAtNode(e->getToNode()), left->getAngleAtNode(e->getToNode())));
    1369        23239 :             double nextAngle = nextLeft == e ? 180 : fabs(NBHelpers::relAngle(e->getAngleAtNode(e->getToNode()), nextLeft->getAngleAtNode(e->getToNode())));
    1370              : #ifdef DEBUG_GUESS_ROUNDABOUT
    1371              :             if (gDebugFlag1) {
    1372              :                 std::cout << "   e=" << e->getID() << " left=" << left->getID() << " nextLeft=" << nextLeft->getID() << " angle=" << angle << " nextAngle=" << nextAngle << " eLength=" << e->getLength() << " lLength=" << left->getLength() << " dist=" << e->getLaneShape(0).back().distanceTo2D(left->getLaneShape(0).front()) << "\n";
    1373              :             }
    1374              : #endif
    1375              :             if (angle >= 120
    1376        25360 :                     || (angle >= 90 &&
    1377              :                         // if the edges are long or the junction shape is small we should expect roundness (low angles)
    1378         2121 :                         (MAX2(e->getLength(), left->getLength()) > 5
    1379          367 :                          || e->getLaneShape(0).back().distanceTo2D(left->getLaneShape(0).front()) < 10
    1380              :                          // there should be no straigher edge further left
    1381          102 :                          || (nextAngle < 45)
    1382              :                         ))) {
    1383              :                 // roundabouts do not have sharp turns (or they wouldn't be called 'round')
    1384              :                 // however, if the roundabout is very small then most of the roundness may be in the junction so the angle may be as high as 120
    1385              :                 doLoop = false;
    1386              : #ifdef DEBUG_GUESS_ROUNDABOUT
    1387              :                 if (gDebugFlag1) {
    1388              :                     std::cout << "     failed angle=" << angle << "\n";
    1389              :                 }
    1390              :                 gDebugFlag1 = false;
    1391              : #endif
    1392              :                 break;
    1393              :             }
    1394        19043 :             EdgeVector::const_iterator loopClosed = std::find(loopEdges.begin(), loopEdges.end(), left);
    1395        19043 :             const int loopSize = (int)(loopEdges.end() - loopClosed);
    1396        19043 :             if (loopSize > 0) {
    1397              :                 // loop found
    1398          162 :                 if (loopSize < 3) {
    1399              :                     doLoop = false; // need at least 3 edges for a roundabout
    1400           94 :                 } else if (loopSize < (int)loopEdges.size()) {
    1401              :                     // remove initial edges not belonging to the loop
    1402           38 :                     EdgeVector(loopEdges.begin() + (loopEdges.size() - loopSize), loopEdges.end()).swap(loopEdges);
    1403              :                 }
    1404              :                 // count attachments to the outside. need at least 3 or a roundabout doesn't make much sense
    1405              :                 int attachments = 0;
    1406          909 :                 for (EdgeVector::const_iterator j = loopEdges.begin(); j != loopEdges.end(); ++j) {
    1407          747 :                     if ((*j)->getToNode()->getEdges().size() > 2) {
    1408          472 :                         attachments++;
    1409              :                     }
    1410              :                 }
    1411          162 :                 if (attachments < 3) {
    1412              :                     doLoop = false;
    1413              : #ifdef DEBUG_GUESS_ROUNDABOUT
    1414              :                     if (gDebugFlag1) {
    1415              :                         std::cout << " attachments=" << attachments << "\n";
    1416              :                     }
    1417              :                     gDebugFlag1 = false;
    1418              : #endif
    1419              :                 }
    1420              :                 break;
    1421              :             }
    1422              :             if (visited.count(left) > 0) {
    1423              :                 doLoop = false;
    1424              :             } else {
    1425              :                 // keep going
    1426        14965 :                 loopEdges.push_back(left);
    1427        14965 :                 e = left;
    1428              :             }
    1429              :         } while (doLoop);
    1430        14489 :         if (doLoop) {
    1431              :             // check form factor to avoid elongated shapes (circle: 1, square: ~0.79)
    1432              : #ifdef DEBUG_GUESS_ROUNDABOUT
    1433              :             if (gDebugFlag1) {
    1434              :                 std::cout << " formFactor=" << formFactor(loopEdges) << "\n";
    1435              :             }
    1436              : #endif
    1437              :             double loopLength = 0;
    1438          541 :             for (const NBEdge* const le : loopEdges) {
    1439          457 :                 loopLength += le->getLoadedLength();
    1440              :             }
    1441           84 :             if (formFactor(loopEdges) > 0.6
    1442          164 :                     && loopLength < OptionsCont::getOptions().getFloat("roundabouts.guess.max-length")) {
    1443              :                 // collected edges are marked in markRoundabouts
    1444           78 :                 EdgeSet guessed(loopEdges.begin(), loopEdges.end());
    1445              :                 if (loadedRoundaboutEdges.count(loopEdges.front()) != 0) {
    1446           63 :                     if (find(myRoundabouts.begin(), myRoundabouts.end(), guessed) == myRoundabouts.end()) {
    1447            2 :                         for (auto it = myRoundabouts.begin(); it != myRoundabouts.end(); it++) {
    1448              :                             if ((*it).count(loopEdges.front()) != 0) {
    1449            4 :                                 WRITE_WARNINGF(TL("Replacing loaded roundabout '%' with '%'."), toString(*it), toString(guessed));
    1450              :                                 myRoundabouts.erase(it);
    1451              :                                 break;
    1452              :                             }
    1453              :                         }
    1454              :                         myGuessedRoundabouts.insert(guessed);
    1455              :                     }
    1456              :                 } else {
    1457              :                     myGuessedRoundabouts.insert(guessed);
    1458              : #ifdef DEBUG_GUESS_ROUNDABOUT
    1459              :                     if (gDebugFlag1) {
    1460              :                         std::cout << " foundRoundabout=" << toString(loopEdges) << "\n";
    1461              :                     }
    1462              : #endif
    1463              :                 }
    1464              :             }
    1465              :         }
    1466              : #ifdef DEBUG_GUESS_ROUNDABOUT
    1467              :         gDebugFlag1 = false;
    1468              : #endif
    1469        26946 :     }
    1470         3744 :     return (int)myGuessedRoundabouts.size();
    1471              : }
    1472              : 
    1473              : 
    1474              : int
    1475          168 : NBEdgeCont::extractRoundabouts() {
    1476              :     std::set<NBEdge*> candidateEdges;
    1477        41395 :     for (const auto& edge : myEdges) {
    1478        41227 :         NBEdge* const e = edge.second;
    1479        41227 :         if (e->getJunctionPriority(e->getToNode()) == NBEdge::JunctionPriority::ROUNDABOUT || e->getJunctionPriority(e->getFromNode()) == NBEdge::JunctionPriority::ROUNDABOUT) {
    1480              :             candidateEdges.insert(e);
    1481              :         }
    1482              :     }
    1483              :     std::set<NBEdge*> visited;
    1484              :     int extracted = 0;
    1485          227 :     for (const auto& edgeIt : candidateEdges) {
    1486              :         EdgeVector loopEdges;
    1487           59 :         NBEdge* e = edgeIt;
    1488           48 :         if (visited.count(e) > 0) {
    1489              :             // already seen
    1490              :             continue;
    1491              :         }
    1492           11 :         loopEdges.push_back(e);
    1493              :         bool doLoop = true;
    1494              :         //
    1495           59 :         do {
    1496           70 :             if (std::find(visited.begin(), visited.end(), e) != visited.end()) {
    1497           11 :                 if (loopEdges.size() > 1) {
    1498           11 :                     addRoundabout(EdgeSet(loopEdges.begin(), loopEdges.end()));
    1499           11 :                     ++extracted;
    1500              :                 }
    1501              :                 doLoop = false;
    1502              :                 break;
    1503              :             }
    1504              :             visited.insert(e);
    1505           59 :             loopEdges.push_back(e);
    1506           59 :             const EdgeVector& outgoingEdges = e->getToNode()->getOutgoingEdges();
    1507              :             EdgeVector::const_iterator me = std::find_if(outgoingEdges.begin(), outgoingEdges.end(), [](const NBEdge * outgoingEdge) {
    1508           83 :                 return outgoingEdge->getJunctionPriority(outgoingEdge->getToNode()) == NBEdge::JunctionPriority::ROUNDABOUT;
    1509              :             });
    1510           59 :             if (me == outgoingEdges.end()) { // no closed loop
    1511              :                 doLoop = false;
    1512              :             } else {
    1513           59 :                 e = *me;
    1514              :             }
    1515              :         } while (doLoop);
    1516           59 :     }
    1517          168 :     return extracted;
    1518              : }
    1519              : 
    1520              : 
    1521              : void
    1522           20 : NBEdgeCont::cleanupRoundabouts() {
    1523              :     // only loaded roundabouts are of concern here since guessing comes later
    1524              :     std::set<EdgeSet> validRoundabouts;
    1525              :     std::set<NBEdge*> validEdges;
    1526         1641 :     for (auto item : myEdges) {
    1527              :         validEdges.insert(item.second);
    1528              :     }
    1529           23 :     for (EdgeSet roundabout : myRoundabouts) {
    1530              :         EdgeSet validRoundabout;
    1531            5 :         for (NBEdge* cand : roundabout) {
    1532              :             if (validEdges.count(cand) != 0) {
    1533              :                 validRoundabout.insert(cand);
    1534              :             }
    1535              :         }
    1536            3 :         if (validRoundabout.size() > 0) {
    1537              :             validRoundabouts.insert(validRoundabout);
    1538              :         }
    1539              :     }
    1540              :     myRoundabouts = validRoundabouts;
    1541           20 : }
    1542              : 
    1543              : 
    1544              : double
    1545           84 : NBEdgeCont::formFactor(const EdgeVector& loopEdges) {
    1546              :     // A circle (which maximizes area per circumference) has a formfactor of 1, non-circular shapes have a smaller value
    1547           84 :     PositionVector points;
    1548          541 :     for (EdgeVector::const_iterator it = loopEdges.begin(); it != loopEdges.end(); ++it) {
    1549          457 :         points.append((*it)->getGeometry());
    1550              :     }
    1551           84 :     double circumference = points.length2D();
    1552          168 :     return 4 * M_PI * points.area() / (circumference * circumference);
    1553           84 : }
    1554              : 
    1555              : 
    1556              : const std::set<EdgeSet>
    1557         7007 : NBEdgeCont::getRoundabouts() const {
    1558              :     std::set<EdgeSet> result = myRoundabouts;
    1559         7007 :     result.insert(myGuessedRoundabouts.begin(), myGuessedRoundabouts.end());
    1560         7007 :     return result;
    1561              : }
    1562              : 
    1563              : 
    1564              : void
    1565           66 : NBEdgeCont::addRoundabout(const EdgeSet& roundabout) {
    1566           66 :     if (roundabout.size() > 0) {
    1567           64 :         if (find(myRoundabouts.begin(), myRoundabouts.end(), roundabout) != myRoundabouts.end()) {
    1568            0 :             WRITE_WARNING("Ignoring duplicate roundabout: " + toString(roundabout));
    1569              :         } else {
    1570              :             myRoundabouts.insert(roundabout);
    1571              :         }
    1572              :     }
    1573           66 : }
    1574              : 
    1575              : void
    1576            4 : NBEdgeCont::removeRoundabout(const NBNode* node) {
    1577            4 :     for (auto it = myRoundabouts.begin(); it != myRoundabouts.end(); ++it) {
    1578            2 :         for (NBEdge* e : *it) {
    1579            2 :             if (e->getToNode() == node) {
    1580              :                 myRoundabouts.erase(it);
    1581              :                 return;
    1582              :             }
    1583              :         }
    1584              :     }
    1585              : }
    1586              : 
    1587              : void
    1588           23 : NBEdgeCont::removeRoundaboutEdges(const EdgeSet& toRemove) {
    1589           23 :     removeRoundaboutEdges(toRemove, myRoundabouts);
    1590           23 :     removeRoundaboutEdges(toRemove, myGuessedRoundabouts);
    1591           23 : }
    1592              : 
    1593              : void
    1594           46 : NBEdgeCont::removeRoundaboutEdges(const EdgeSet& toRemove, std::set<EdgeSet>& roundabouts) {
    1595              :     // members of a set are constant so we have to do some tricks
    1596              :     std::vector<EdgeSet> rList;
    1597           48 :     for (const EdgeSet& r : roundabouts) {
    1598              :         EdgeSet r2;
    1599            2 :         std::set_difference(r.begin(), r.end(), toRemove.begin(), toRemove.end(), std::inserter(r2, r2.end()));
    1600            2 :         rList.push_back(r2);
    1601              :     }
    1602              :     roundabouts.clear();
    1603              :     roundabouts.insert(rList.begin(), rList.end());
    1604           46 : }
    1605              : 
    1606              : 
    1607              : void
    1608         1752 : NBEdgeCont::markRoundabouts() {
    1609         1826 :     for (const EdgeSet& roundaboutSet : getRoundabouts()) {
    1610          432 :         for (NBEdge* const edge : roundaboutSet) {
    1611              :             // disable turnarounds on incoming edges
    1612              :             NBNode* const node = edge->getToNode();
    1613          967 :             for (NBEdge* const inEdge : node->getIncomingEdges()) {
    1614          358 :                 if (roundaboutSet.count(inEdge) > 0) {
    1615          358 :                     continue;
    1616              :                 }
    1617          251 :                 if (inEdge->getStep() >= NBEdge::EdgeBuildingStep::LANES2LANES_USER) {
    1618          143 :                     continue;
    1619              :                 }
    1620          108 :                 if (inEdge->getTurnDestination() != nullptr) {
    1621           46 :                     inEdge->removeFromConnections(inEdge->getTurnDestination(), -1);
    1622              :                 } else {
    1623              :                     // also remove connections that are effecively a turnaround but
    1624              :                     // where not correctly detector due to geometrical quirks
    1625           62 :                     const std::vector<NBEdge::Connection> cons = inEdge->getConnections();
    1626          126 :                     for (const NBEdge::Connection& con : cons) {
    1627           64 :                         if (con.toEdge && roundaboutSet.count(con.toEdge) == 0) {
    1628           10 :                             const double angle = fabs(NBHelpers::normRelAngle(inEdge->getAngleAtNode(node), con.toEdge->getAngleAtNode(node)));
    1629           10 :                             if (angle > 160) {
    1630            1 :                                 inEdge->removeFromConnections(con.toEdge, -1);
    1631              :                             }
    1632              :                         }
    1633              :                     }
    1634           62 :                 }
    1635              : 
    1636              :             }
    1637              :             // let the connections to succeeding roundabout edge have a higher priority
    1638          358 :             edge->setJunctionPriority(node, NBEdge::JunctionPriority::ROUNDABOUT);
    1639          358 :             edge->setJunctionPriority(edge->getFromNode(), NBEdge::JunctionPriority::ROUNDABOUT);
    1640          358 :             node->setRoundabout();
    1641              :         }
    1642              :     }
    1643         1752 : }
    1644              : 
    1645              : 
    1646              : void
    1647            1 : NBEdgeCont::generateStreetSigns() {
    1648           23 :     for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
    1649           22 :         NBEdge* e = i->second;
    1650           22 :         const double offset = MAX2(0., e->getLength() - 3);
    1651           22 :         if (e->getToNode()->isSimpleContinuation(false)) {
    1652              :             // not a "real" junction?
    1653           10 :             continue;
    1654              :         }
    1655              :         const SumoXMLNodeType nodeType = e->getToNode()->getType();
    1656           12 :         switch (nodeType) {
    1657            4 :             case SumoXMLNodeType::PRIORITY:
    1658              :                 // yield or major?
    1659            4 :                 if (e->getJunctionPriority(e->getToNode()) > 0) {
    1660            6 :                     e->addSign(NBSign(NBSign::SIGN_TYPE_PRIORITY, offset));
    1661              :                 } else {
    1662            6 :                     e->addSign(NBSign(NBSign::SIGN_TYPE_YIELD, offset));
    1663              :                 }
    1664              :                 break;
    1665            0 :             case SumoXMLNodeType::PRIORITY_STOP:
    1666              :                 // yield or major?
    1667            0 :                 if (e->getJunctionPriority(e->getToNode()) > 0) {
    1668            0 :                     e->addSign(NBSign(NBSign::SIGN_TYPE_PRIORITY, offset));
    1669              :                 } else {
    1670            0 :                     e->addSign(NBSign(NBSign::SIGN_TYPE_STOP, offset));
    1671              :                 }
    1672              :                 break;
    1673            0 :             case SumoXMLNodeType::ALLWAY_STOP:
    1674            0 :                 e->addSign(NBSign(NBSign::SIGN_TYPE_ALLWAY_STOP, offset));
    1675            0 :                 break;
    1676            4 :             case SumoXMLNodeType::RIGHT_BEFORE_LEFT:
    1677            8 :                 e->addSign(NBSign(NBSign::SIGN_TYPE_RIGHT_BEFORE_LEFT, offset));
    1678            4 :                 break;
    1679            0 :             case SumoXMLNodeType::LEFT_BEFORE_RIGHT:
    1680            0 :                 e->addSign(NBSign(NBSign::SIGN_TYPE_LEFT_BEFORE_RIGHT, offset));
    1681            0 :                 break;
    1682              :             default:
    1683              :                 break;
    1684              :         }
    1685              :     }
    1686            1 : }
    1687              : 
    1688              : 
    1689              : int
    1690           20 : NBEdgeCont::guessSpecialLanes(SUMOVehicleClass svc, double width, double minSpeed, double maxSpeed, bool fromPermissions, const std::string& excludeOpt,
    1691              :                               NBTrafficLightLogicCont& tlc) {
    1692              :     int lanesCreated = 0;
    1693              :     std::vector<std::string> edges;
    1694           20 :     if (excludeOpt != "") {
    1695           20 :         edges = OptionsCont::getOptions().getStringVector(excludeOpt);
    1696              :     }
    1697           20 :     std::set<std::string> exclude(edges.begin(), edges.end());
    1698          440 :     for (EdgeCont::iterator it = myEdges.begin(); it != myEdges.end(); it++) {
    1699          420 :         NBEdge* edge = it->second;
    1700              :         if (// not excluded
    1701          420 :             exclude.count(edge->getID()) == 0
    1702              :             // does not yet have a sidewalk
    1703          417 :             && !edge->hasRestrictedLane(svc)
    1704          299 :             && (
    1705              :                 // guess.from-permissions
    1706          139 :                 (fromPermissions && (edge->getPermissions() & svc) != 0)
    1707              :                 // guess from speed
    1708          160 :                 || (!fromPermissions && edge->getSpeed() > minSpeed && edge->getSpeed() <= maxSpeed)
    1709              :             )) {
    1710          235 :             edge->addRestrictedLane(width, svc);
    1711          235 :             lanesCreated += 1;
    1712          235 :             if (svc != SVC_PEDESTRIAN) {
    1713           34 :                 edge->invalidateConnections(true);
    1714           34 :                 edge->getFromNode()->invalidateOutgoingConnections(true);
    1715           34 :                 edge->getFromNode()->invalidateTLS(tlc, true, true);
    1716           34 :                 edge->getToNode()->invalidateTLS(tlc, true, true);
    1717              :             }
    1718              :         }
    1719              :     }
    1720           20 :     return lanesCreated;
    1721           20 : }
    1722              : 
    1723              : 
    1724              : void
    1725            3 : NBEdgeCont::updateAllChangeRestrictions(SVCPermissions ignoring) {
    1726            9 :     for (auto item : myEdges) {
    1727            6 :         item.second->updateChangeRestrictions(ignoring);
    1728              :     }
    1729            3 : }
    1730              : 
    1731              : 
    1732              : void
    1733            0 : NBEdgeCont::addPrefix(const std::string& prefix) {
    1734              :     // make a copy of node containers
    1735              :     const auto nodeContainerCopy = myEdges;
    1736              :     myEdges.clear();
    1737            0 :     for (const auto& node : nodeContainerCopy) {
    1738            0 :         node.second->setID(prefix + node.second->getID());
    1739            0 :         myEdges[node.second->getID()] = node.second;
    1740              :     }
    1741            0 : }
    1742              : 
    1743              : 
    1744              : int
    1745         1704 : NBEdgeCont::remapIDs(bool numericaIDs, bool reservedIDs, const std::string& prefix, NBPTStopCont& sc) {
    1746         1704 :     bool startGiven = !OptionsCont::getOptions().isDefault("numerical-ids.edge-start");
    1747         1704 :     if (!numericaIDs && !reservedIDs && prefix == "" && !startGiven) {
    1748              :         return 0;
    1749              :     }
    1750              :     std::vector<std::string> avoid;
    1751           33 :     if (startGiven) {
    1752            6 :         avoid.push_back(toString(OptionsCont::getOptions().getInt("numerical-ids.edge-start") - 1));
    1753              :     } else {
    1754           30 :         avoid = getAllNames();
    1755              :     }
    1756              :     std::set<std::string> reserve;
    1757           33 :     if (reservedIDs) {
    1758            4 :         NBHelpers::loadPrefixedIDsFomFile(OptionsCont::getOptions().getString("reserved-ids"), "edge:", reserve);
    1759            2 :         avoid.insert(avoid.end(), reserve.begin(), reserve.end());
    1760              :     }
    1761           66 :     IDSupplier idSupplier("", avoid);
    1762              :     std::set<NBEdge*, ComparatorIdLess> toChange;
    1763        15298 :     for (EdgeCont::iterator it = myEdges.begin(); it != myEdges.end(); it++) {
    1764        15265 :         if (startGiven) {
    1765           78 :             toChange.insert(it->second);
    1766           78 :             continue;
    1767              :         }
    1768        15187 :         if (numericaIDs) {
    1769              :             try {
    1770        15013 :                 StringUtils::toLong(it->first);
    1771         5866 :             } catch (NumberFormatException&) {
    1772         5866 :                 toChange.insert(it->second);
    1773         5866 :             }
    1774              :         }
    1775        15187 :         if (reservedIDs && reserve.count(it->first) > 0) {
    1776            2 :             toChange.insert(it->second);
    1777              :         }
    1778              :     }
    1779              : 
    1780              :     std::map<std::string, std::vector<std::shared_ptr<NBPTStop> > > stopsOnEdge;
    1781           57 :     for (const auto& item : sc.getStops()) {
    1782           24 :         stopsOnEdge[item.second->getEdgeId()].push_back(item.second);
    1783              :     }
    1784              : 
    1785           66 :     const bool origNames = OptionsCont::getOptions().getBool("output.original-names");
    1786         5979 :     for (NBEdge* edge : toChange) {
    1787         5946 :         myEdges.erase(edge->getID());
    1788              :     }
    1789         5979 :     for (NBEdge* edge : toChange) {
    1790         5946 :         const std::string origID = edge->getID();
    1791         5946 :         if (origNames) {
    1792        11024 :             edge->setOrigID(origID, false);
    1793              :         }
    1794         5946 :         edge->setID(idSupplier.getNext());
    1795         5946 :         myEdges[edge->getID()] = edge;
    1796         5965 :         for (std::shared_ptr<NBPTStop> stop : stopsOnEdge[origID]) {
    1797           57 :             stop->setEdgeId(prefix + edge->getID(), *this);
    1798              :         }
    1799              :     }
    1800           33 :     if (prefix.empty()) {
    1801           25 :         return (int)toChange.size();
    1802              :     } else {
    1803              :         int renamed = 0;
    1804              :         // make a copy because we will modify the map
    1805              :         auto oldEdges = myEdges;
    1806          190 :         for (auto item : oldEdges) {
    1807          364 :             if (!StringUtils::startsWith(item.first, prefix)) {
    1808          181 :                 rename(item.second, prefix + item.first);
    1809          181 :                 renamed++;
    1810              :             }
    1811              :         }
    1812              :         return renamed;
    1813              :     }
    1814           66 : }
    1815              : 
    1816              : 
    1817              : void
    1818            0 : NBEdgeCont::checkOverlap(double threshold, double zThreshold) const {
    1819            0 :     for (EdgeCont::const_iterator it = myEdges.begin(); it != myEdges.end(); it++) {
    1820            0 :         const NBEdge* e1 = it->second;
    1821            0 :         Boundary b1 = e1->getGeometry().getBoxBoundary();
    1822            0 :         b1.grow(e1->getTotalWidth());
    1823            0 :         PositionVector outline1 = e1->getCCWBoundaryLine(*e1->getFromNode());
    1824            0 :         outline1.append(e1->getCCWBoundaryLine(*e1->getToNode()));
    1825              :         // check is symmetric. only check once per pair
    1826            0 :         for (EdgeCont::const_iterator it2 = it; it2 != myEdges.end(); it2++) {
    1827            0 :             const NBEdge* e2 = it2->second;
    1828            0 :             if (e1 == e2) {
    1829            0 :                 continue;
    1830              :             }
    1831            0 :             Boundary b2 = e2->getGeometry().getBoxBoundary();
    1832            0 :             b2.grow(e2->getTotalWidth());
    1833            0 :             if (b1.overlapsWith(b2)) {
    1834            0 :                 PositionVector outline2 = e2->getCCWBoundaryLine(*e2->getFromNode());
    1835            0 :                 outline2.append(e2->getCCWBoundaryLine(*e2->getToNode()));
    1836            0 :                 const double overlap = outline1.getOverlapWith(outline2, zThreshold);
    1837            0 :                 if (overlap > threshold) {
    1838            0 :                     WRITE_WARNINGF(TL("Edge '%' overlaps with edge '%' by %."), e1->getID(), e2->getID(), overlap);
    1839              :                 }
    1840            0 :             }
    1841            0 :         }
    1842            0 :     }
    1843            0 : }
    1844              : 
    1845              : 
    1846              : void
    1847           21 : NBEdgeCont::checkGrade(double threshold) const {
    1848         2811 :     for (EdgeCont::const_iterator it = myEdges.begin(); it != myEdges.end(); it++) {
    1849         2790 :         const NBEdge* edge = it->second;
    1850         5367 :         for (int i = 0; i < (int)edge->getNumLanes(); i++) {
    1851         2872 :             double maxJump = 0;
    1852         2872 :             const double grade = edge->getLaneShape(i).getMaxGrade(maxJump);
    1853         2872 :             if (maxJump > 0.01) {
    1854            0 :                 WRITE_WARNINGF(TL("Edge '%' has a vertical jump of %m."), edge->getID(), maxJump);
    1855         2872 :             } else if (grade > threshold) {
    1856          885 :                 WRITE_WARNINGF(TL("Edge '%' has a grade of %%."), edge->getID(), grade * 100, "%");
    1857          295 :                 break;
    1858              :             }
    1859              :         }
    1860              :         const std::vector<NBEdge::Connection>& connections = edge->getConnections();
    1861         3820 :         for (std::vector<NBEdge::Connection>::const_iterator it_con = connections.begin(); it_con != connections.end(); ++it_con) {
    1862              :             const NBEdge::Connection& c = *it_con;
    1863         1034 :             double maxJump = 0;
    1864         1034 :             const double grade = MAX2(c.shape.getMaxGrade(maxJump), c.viaShape.getMaxGrade(maxJump));
    1865         1034 :             if (maxJump > 0.01) {
    1866            0 :                 WRITE_WARNINGF(TL("Connection '%' has a vertical jump of %m."), c.getDescription(edge), maxJump);
    1867         1034 :             } else if (grade > threshold) {
    1868            8 :                 WRITE_WARNINGF(TL("Connection '%' has a grade of %%."), c.getDescription(edge), grade * 100, "%");
    1869            4 :                 break;
    1870              :             }
    1871              :         }
    1872              :     }
    1873           21 : }
    1874              : 
    1875              : 
    1876              : int
    1877            2 : NBEdgeCont::joinLanes(SVCPermissions perms) {
    1878              :     int affectedEdges = 0;
    1879           38 :     for (auto item : myEdges) {
    1880           36 :         if (item.second->joinLanes(perms)) {
    1881           18 :             affectedEdges++;
    1882              :         }
    1883              :     }
    1884            2 :     return affectedEdges;
    1885              : }
    1886              : 
    1887              : 
    1888              : bool
    1889         2898 : NBEdgeCont::MinLaneComparatorIdLess::operator()(const std::pair<NBEdge*, int>& a, const std::pair<NBEdge*, int>& b) const {
    1890         2898 :     if (a.first->getID() == b.first->getID()) {
    1891           44 :         return a.second < b.second;
    1892              :     }
    1893         2854 :     return a.first->getID() < b.first->getID();
    1894              : }
    1895              : 
    1896              : int
    1897            6 : NBEdgeCont::joinTramEdges(NBDistrictCont& dc, NBPTStopCont& sc, NBPTLineCont& lc, double maxDist) {
    1898              :     // this is different from joinSimilarEdges because there don't need to be
    1899              :     // shared nodes and tram edges may be split
    1900              :     std::vector<NBEdge*> tramEdges;
    1901              :     std::vector<NBEdge*> targetEdges;
    1902         2225 :     for (auto item : myEdges) {
    1903         2219 :         SVCPermissions permissions = item.second->getPermissions();
    1904         2219 :         if (isTram(permissions)) {
    1905          486 :             if (item.second->getNumLanes() == 1) {
    1906          458 :                 tramEdges.push_back(item.second);
    1907              :             } else {
    1908           84 :                 WRITE_WARNINGF(TL("Not joining tram edge '%' with % lanes."), item.second->getID(), item.second->getNumLanes());
    1909              :             }
    1910         1733 :         } else if ((permissions & (SVC_PASSENGER | SVC_BUS)) != 0) {
    1911         1165 :             targetEdges.push_back(item.second);
    1912              :         }
    1913              :     }
    1914            6 :     if (tramEdges.empty() || targetEdges.empty()) {
    1915              :         return 0;
    1916              :     }
    1917              :     int numJoined = 0;
    1918              :     NamedRTree tramTree;
    1919          464 :     for (NBEdge* const edge : tramEdges) {
    1920          458 :         const Boundary& bound = edge->getGeometry().getBoxBoundary();
    1921          458 :         float min[2] = { static_cast<float>(bound.xmin()), static_cast<float>(bound.ymin()) };
    1922          458 :         float max[2] = { static_cast<float>(bound.xmax()), static_cast<float>(bound.ymax()) };
    1923          458 :         tramTree.Insert(min, max, edge);
    1924          458 :     }
    1925              :     // {targetEdge, laneIndex : tramEdge}
    1926              :     std::map<std::pair<NBEdge*, int>, NBEdge*, MinLaneComparatorIdLess> matches;
    1927              : 
    1928         1171 :     for (NBEdge* const edge : targetEdges) {
    1929         1165 :         Boundary bound = edge->getGeometry().getBoxBoundary();
    1930         1165 :         bound.grow(maxDist + edge->getTotalWidth());
    1931         1165 :         float min[2] = { static_cast<float>(bound.xmin()), static_cast<float>(bound.ymin()) };
    1932         1165 :         float max[2] = { static_cast<float>(bound.xmax()), static_cast<float>(bound.ymax()) };
    1933              :         std::set<const Named*> near;
    1934              :         Named::StoringVisitor visitor(near);
    1935              :         tramTree.Search(min, max, visitor);
    1936              :         // the nearby set is actually just re-sorting according to the id to make the tests comparable
    1937              :         std::set<NBEdge*, ComparatorIdLess> nearby;
    1938         4721 :         for (const Named* namedEdge : near) {
    1939         3556 :             nearby.insert(const_cast<NBEdge*>(static_cast<const NBEdge*>(namedEdge)));
    1940              :         }
    1941         4721 :         for (NBEdge* const tramEdge : nearby) {
    1942              :             // find a continous stretch of tramEdge that runs along one of the
    1943              :             // lanes of the road edge
    1944              :             const PositionVector& tramShape = tramEdge->getGeometry();
    1945         3556 :             double minEdgeDist = maxDist + 1;
    1946              :             int minLane = -1;
    1947              :             // find the lane where the maximum distance from the tram geometry
    1948              :             // is minimal and within maxDist
    1949        10405 :             for (int i = 0; i < edge->getNumLanes(); i++) {
    1950              :                 double maxLaneDist = -1;
    1951         6849 :                 if ((edge->getPermissions(i) & (SVC_PASSENGER | SVC_BUS)) != 0) {
    1952         6327 :                     const PositionVector& laneShape = edge->getLaneShape(i);
    1953         7373 :                     for (Position pos : laneShape) {
    1954         7119 :                         const double dist = tramShape.distance2D(pos, false);
    1955              : #ifdef DEBUG_JOIN_TRAM
    1956              :                         //if (edge->getID() == "106838214#1") {
    1957              :                         //    std::cout << " edge=" << edge->getID() << " tramEdge=" << tramEdge->getID() << " lane=" << i << " pos=" << pos << " dist=" << dist << "\n";
    1958              :                         //}
    1959              : #endif
    1960         7119 :                         if (dist == GeomHelper::INVALID_OFFSET || dist > maxDist) {
    1961              :                             maxLaneDist = -1;
    1962              :                             break;
    1963              :                         }
    1964              :                         maxLaneDist = MAX2(maxLaneDist, dist);
    1965              :                     }
    1966          254 :                     if (maxLaneDist >= 0 && maxLaneDist < minEdgeDist) {
    1967              :                         minEdgeDist = maxLaneDist;
    1968              :                         minLane = i;
    1969              :                     }
    1970              :                 }
    1971              :             }
    1972         3556 :             if (minLane >= 0) {
    1973              :                 // edge could run in the wrong direction and still fit the threshold we check the angle as well
    1974          248 :                 const PositionVector& laneShape = edge->getLaneShape(minLane);
    1975          248 :                 const double offset1 = tramShape.nearest_offset_to_point2D(laneShape.front(), false);
    1976          248 :                 const double offset2 = tramShape.nearest_offset_to_point2D(laneShape.back(), false);
    1977          248 :                 Position p1 = tramShape.positionAtOffset2D(offset1);
    1978          248 :                 Position p2 = tramShape.positionAtOffset2D(offset2);
    1979          248 :                 double tramAngle = GeomHelper::legacyDegree(p1.angleTo2D(p2), true);
    1980          248 :                 bool angleOK = GeomHelper::getMinAngleDiff(tramAngle, edge->getTotalAngle()) < JOIN_TRAM_MAX_ANGLE;
    1981          248 :                 if (angleOK && offset2 > offset1) {
    1982          198 :                     std::pair<NBEdge*, int> key = std::make_pair(edge, minLane);
    1983              :                     if (matches.count(key) == 0) {
    1984          188 :                         matches[key] = tramEdge;
    1985              :                     } else {
    1986           40 :                         WRITE_WARNINGF(TL("Ambiguous tram edges '%' and '%' for lane '%'."), matches[key]->getID(), tramEdge->getID(), edge->getLaneID(minLane));
    1987              :                     }
    1988              : #ifdef DEBUG_JOIN_TRAM
    1989              :                     std::cout << edge->getLaneID(minLane) << " is close to tramEdge " << tramEdge->getID() << " maxLaneDist=" << minEdgeDist << " tramLength=" << tramEdge->getLength() << " edgeLength=" << edge->getLength() << " tramAngle=" << tramAngle << " edgeAngle=" << edge->getTotalAngle() << "\n";
    1990              : #endif
    1991              :                 }
    1992              :             }
    1993              :         }
    1994         1165 :     }
    1995            6 :     if (matches.size() == 0) {
    1996              :         return 0;
    1997              :     }
    1998           12 :     const bool origNames = OptionsCont::getOptions().getBool("output.original-names");
    1999              :     // find continous runs of matched edges for each tramEdge
    2000          464 :     for (NBEdge* tramEdge : tramEdges) {
    2001              :         std::vector<std::pair<double, std::pair<NBEdge*, int> > > roads;
    2002        14710 :         for (auto item : matches) {
    2003        14252 :             if (item.second == tramEdge) {
    2004              :                 NBEdge* road = item.first.first;
    2005              :                 int laneIndex = item.first.second;
    2006          188 :                 const PositionVector& laneShape = road->getLaneShape(laneIndex);
    2007          188 :                 double tramPos = tramEdge->getGeometry().nearest_offset_to_point2D(laneShape.front(), false);
    2008          188 :                 roads.push_back(std::make_pair(tramPos, item.first));
    2009              :             }
    2010              :         }
    2011          458 :         if (roads.size() != 0) {
    2012              : 
    2013           55 :             sort(roads.begin(), roads.end());
    2014              : #ifdef DEBUG_JOIN_TRAM
    2015              :             std::cout << " tramEdge=" << tramEdge->getID() << " roads=";
    2016              :             for (auto item : roads) {
    2017              :                 std::cout << item.second.first->getLaneID(item.second.second) << ",";
    2018              :             }
    2019              :             std::cout << " offsets=";
    2020              :             for (auto item : roads) {
    2021              :                 std::cout << item.first << ",";
    2022              :             }
    2023              :             std::cout << "\n";
    2024              : #endif
    2025              :             // merge tramEdge into road lanes
    2026              :             EdgeVector replacement;
    2027              :             double pos = 0;
    2028              :             int tramPart = 0;
    2029           55 :             std::string tramEdgeID = tramEdge->getID();
    2030              :             NBNode* tramFrom = tramEdge->getFromNode();
    2031              :             PositionVector tramShape = tramEdge->getGeometry();
    2032           55 :             const double tramLength = tramShape.length();
    2033           55 :             EdgeVector incoming = tramFrom->getIncomingEdges();
    2034              :             bool erasedLast = false;
    2035          243 :             for (const auto& item : roads) {
    2036          188 :                 const double gap = item.first - pos;
    2037          188 :                 NBEdge* road = item.second.first;
    2038          188 :                 int laneIndex = item.second.second;
    2039          188 :                 if (gap >= JOIN_TRAM_MIN_LENGTH) {
    2040              : #ifdef DEBUG_JOIN_TRAM
    2041              :                     std::cout << "    splitting tramEdge=" << tramEdge->getID() << " at " << item.first << " (gap=" << gap << ")\n";
    2042              : #endif
    2043           72 :                     const std::string firstPartID = tramEdgeID + "#" + toString(tramPart++);
    2044           36 :                     splitAt(dc, tramEdge, gap, road->getFromNode(), firstPartID, tramEdgeID, 1, 1);
    2045           36 :                     tramEdge = retrieve(tramEdgeID); // second part;
    2046           36 :                     NBEdge* firstPart = retrieve(firstPartID);
    2047           36 :                     firstPart->invalidateConnections(true);
    2048              :                     incoming.clear();
    2049           36 :                     incoming.push_back(firstPart);
    2050           36 :                     replacement.push_back(firstPart);
    2051              :                 }
    2052          188 :                 pos = item.first + road->getGeometry().length();
    2053          188 :                 numJoined++;
    2054          188 :                 replacement.push_back(road);
    2055              :                 // merge section of tramEdge into road lane
    2056          188 :                 if (road->getToNode() != tramEdge->getToNode() && (tramLength - pos) >= JOIN_TRAM_MIN_LENGTH) {
    2057          164 :                     tramEdge->reinitNodes(road->getToNode(), tramEdge->getToNode());
    2058          164 :                     tramEdge->setGeometry(tramShape.getSubpart(pos, tramShape.length()));
    2059              :                     erasedLast = false;
    2060              : #ifdef DEBUG_JOIN_TRAM
    2061              :                     std::cout << "    shorted tramEdge=" << tramEdge->getID() << " (joined with roadEdge=" << road->getID() << "\n";
    2062              : #endif
    2063              :                 } else {
    2064              : #ifdef DEBUG_JOIN_TRAM
    2065              :                     std::cout << "    erased tramEdge=" << tramEdge->getID() << "\n";
    2066              : #endif
    2067           24 :                     extract(dc, tramEdge, true);
    2068              :                     erasedLast = true;
    2069              :                 }
    2070          188 :                 road->setPermissions(road->getPermissions(laneIndex) | SVC_TRAM, laneIndex);
    2071          188 :                 if (origNames) {
    2072          114 :                     road->setOrigID(tramEdgeID, true, laneIndex);
    2073              :                 }
    2074          263 :                 for (NBEdge* in : incoming) {
    2075           75 :                     if (isTram(in->getPermissions()) && !in->isConnectedTo(road)) {
    2076           47 :                         if (in->getFromNode() != road->getFromNode()) {
    2077           44 :                             in->reinitNodes(in->getFromNode(), road->getFromNode());
    2078              :                         } else {
    2079            3 :                             extract(dc, in, true);
    2080              : #ifdef DEBUG_JOIN_TRAM
    2081              :                             std::cout << "    erased incoming tramEdge=" << in->getID() << "\n";
    2082              : #endif
    2083              :                         }
    2084              :                     }
    2085              :                 }
    2086              :                 incoming.clear();
    2087              :             }
    2088           55 :             NBEdge* lastRoad = roads.back().second.first;
    2089           55 :             if (erasedLast) {
    2090              :                 // copy to avoid concurrent modification
    2091           22 :                 auto outEdges = tramEdge->getToNode()->getOutgoingEdges();
    2092           68 :                 for (NBEdge* out : outEdges) {
    2093           46 :                     if (isTram(out->getPermissions()) && !lastRoad->isConnectedTo(out)) {
    2094           25 :                         if (lastRoad->getToNode() != out->getToNode()) {
    2095           24 :                             out->reinitNodes(lastRoad->getToNode(), out->getToNode());
    2096              :                         } else {
    2097            1 :                             extract(dc, out, true);
    2098              : #ifdef DEBUG_JOIN_TRAM
    2099              :                             std::cout << "    erased outgoing tramEdge=" << out->getID() << "\n";
    2100              : #endif
    2101              : 
    2102              :                         }
    2103              :                     }
    2104              :                 }
    2105           22 :             } else {
    2106           33 :                 replacement.push_back(tramEdge);
    2107              :             }
    2108              :             // update ptstops and ptlines
    2109           55 :             sc.replaceEdge(tramEdgeID, replacement);
    2110           55 :             lc.replaceEdge(tramEdgeID, replacement);
    2111          110 :         }
    2112          458 :     }
    2113              : 
    2114            6 :     return numJoined;
    2115            6 : }
    2116              : 
    2117              : 
    2118              : EdgeVector
    2119          153 : NBEdgeCont::getAllEdges() const {
    2120              :     EdgeVector result;
    2121        52740 :     for (auto item : myEdges) {
    2122        52587 :         item.second->setNumericalID((int)result.size());
    2123        52587 :         result.push_back(item.second);
    2124              :     }
    2125          153 :     return result;
    2126            0 : }
    2127              : 
    2128              : RouterEdgeVector
    2129           63 : NBEdgeCont::getAllRouterEdges() const {
    2130           63 :     EdgeVector all = getAllEdges();
    2131          126 :     return RouterEdgeVector(all.begin(), all.end());
    2132           63 : }
    2133              : 
    2134              : bool
    2135         1795 : NBEdgeCont::checkConsistency(const NBNodeCont& nc) {
    2136              :     bool ok = true;
    2137        85257 :     for (const auto& item : myEdges) {
    2138        83462 :         NBEdge* e = item.second;
    2139        83462 :         if (nc.retrieve(e->getFromNode()->getID()) == nullptr) {
    2140            4 :             WRITE_ERRORF(TL("Edge's '%' from-node '%' is not known."), e->getID(), e->getFromNode()->getID());
    2141              :             ok = false;
    2142              :         }
    2143        83462 :         if (nc.retrieve(e->getToNode()->getID()) == nullptr) {
    2144            4 :             WRITE_ERRORF(TL("Edge's '%' to-node '%' is not known."), e->getID(), e->getToNode()->getID());
    2145              :             ok = false;
    2146              :         }
    2147              : 
    2148              :     }
    2149         1795 :     return ok;
    2150              : }
    2151              : 
    2152              : 
    2153              : void
    2154           75 : NBEdgeCont::fixSplitCustomLength() {
    2155         2192 :     for (auto item : myEdges) {
    2156              :         NBEdge* e = item.second;
    2157         2117 :         if (e->hasLoadedLength() && myWasSplit.count(e) != 0) {
    2158              :             // subtract half the length of the longest incoming / outgoing connection
    2159              :             double maxLengthOut = 0;
    2160            5 :             for (const NBEdge::Connection& c : e->getConnections()) {
    2161            3 :                 maxLengthOut = MAX2(maxLengthOut, c.length + c.viaLength);
    2162              :             }
    2163              :             double maxLengthIn = 0;
    2164            4 :             for (const NBEdge* in : e->getIncomingEdges()) {
    2165            7 :                 for (const NBEdge::Connection& c : in->getConnectionsFromLane(-1, e, -1)) {
    2166            5 :                     maxLengthIn = MAX2(maxLengthIn, c.length + c.viaLength);
    2167            2 :                 }
    2168            2 :             }
    2169            4 :             e->setLoadedLength(MAX2(POSITION_EPS, e->getLoadedLength() - (maxLengthIn + maxLengthOut) / 2));
    2170              :         }
    2171              :     }
    2172           75 : }
    2173              : 
    2174              : void
    2175            0 : NBEdgeCont::computeAngles() {
    2176            0 :     for (auto item : myEdges) {
    2177            0 :         item.second->computeAngle();
    2178              :     }
    2179            0 : }
    2180              : 
    2181              : 
    2182              : std::set<std::string>
    2183         1636 : NBEdgeCont::getUsedTypes() const {
    2184              :     std::set<std::string> result;
    2185        90707 :     for (auto item : myEdges) {
    2186        89071 :         if (item.second->getTypeID() != "") {
    2187              :             result.insert(item.second->getTypeID());
    2188              :         }
    2189              :     }
    2190         1636 :     return result;
    2191              : }
    2192              : 
    2193              : 
    2194              : int
    2195            4 : NBEdgeCont::removeEdgesBySpeed(NBDistrictCont& dc) {
    2196              :     EdgeSet toRemove;
    2197           84 :     for (auto item : myEdges) {
    2198           80 :         NBEdge* edge = item.second;
    2199              :         // remove edges which allow a speed below a set one (set using "keep-edges.min-speed")
    2200           80 :         if (edge->getSpeed() < myEdgesMinSpeed) {
    2201              :             toRemove.insert(edge);
    2202              :         }
    2203              :     }
    2204              :     int numRemoved = 0;
    2205            4 :     for (NBEdge* edge : toRemove) {
    2206              :         // explicit whitelist overrides removal
    2207            0 :         if (myEdges2Keep.size() == 0 || myEdges2Keep.count(edge->getID()) == 0) {
    2208            0 :             extract(dc, edge);
    2209            0 :             numRemoved++;
    2210              :         }
    2211              :     }
    2212            4 :     return numRemoved;
    2213              : }
    2214              : 
    2215              : 
    2216              : int
    2217            4 : NBEdgeCont::removeEdgesByPermissions(NBDistrictCont& dc) {
    2218              :     EdgeSet toRemove;
    2219           84 :     for (auto item : myEdges) {
    2220           80 :         NBEdge* edge = item.second;
    2221              :         // check whether the edge shall be removed because it does not allow any of the wished classes
    2222           80 :         if (myVehicleClasses2Keep != 0 && (myVehicleClasses2Keep & edge->getPermissions()) == 0) {
    2223              :             toRemove.insert(edge);
    2224              :         }
    2225              :         // check whether the edge shall be removed due to allowing unwished classes only
    2226           80 :         if (myVehicleClasses2Remove != 0 && (myVehicleClasses2Remove | edge->getPermissions()) == myVehicleClasses2Remove) {
    2227              :             toRemove.insert(edge);
    2228              :         }
    2229              :     }
    2230              :     int numRemoved = 0;
    2231           29 :     for (NBEdge* edge : toRemove) {
    2232              :         // explicit whitelist overrides removal
    2233           25 :         if (myEdges2Keep.size() == 0 || myEdges2Keep.count(edge->getID()) == 0) {
    2234           25 :             extract(dc, edge);
    2235           25 :             numRemoved++;
    2236              :         }
    2237              :     }
    2238            4 :     return numRemoved;
    2239              : }
    2240              : 
    2241              : 
    2242              : int
    2243         1704 : NBEdgeCont::removeLanesByWidth(NBDistrictCont& dc, const double minWidth) {
    2244              :     EdgeSet toRemove;
    2245        99606 :     for (auto item : myEdges) {
    2246        97902 :         NBEdge* const edge = item.second;
    2247              :         std::vector<int> indices;
    2248        97902 :         int idx = 0;
    2249       226842 :         for (const auto& lane : edge->getLanes()) {
    2250       128940 :             if (lane.width != NBEdge::UNSPECIFIED_WIDTH && lane.width < minWidth) {
    2251            4 :                 indices.push_back(idx);
    2252              :             }
    2253       128940 :             idx++;
    2254              :         }
    2255        97902 :         if ((int)indices.size() == edge->getNumLanes()) {
    2256              :             toRemove.insert(edge);
    2257              :         } else {
    2258              :             std::reverse(indices.begin(), indices.end());
    2259        97906 :             for (const int i : indices) {
    2260            4 :                 edge->deleteLane(i, false, true);
    2261              :             }
    2262              :         }
    2263        97902 :     }
    2264              :     int numRemoved = 0;
    2265         1704 :     for (NBEdge* edge : toRemove) {
    2266              :         // explicit whitelist overrides removal
    2267            0 :         if (myEdges2Keep.size() == 0 || myEdges2Keep.count(edge->getID()) == 0) {
    2268            0 :             extract(dc, edge);
    2269            0 :             numRemoved++;
    2270              :         }
    2271              :     }
    2272         1704 :     return numRemoved;
    2273              : }
    2274              : 
    2275              : 
    2276              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1