Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NBEdgeCont.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2026 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/****************************************************************************/
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>
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"
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// ===========================================================================
65 myTypeCont(tc),
66 myVehicleClasses2Keep(0),
67 myVehicleClasses2Remove(0),
68 myNeedGeoTransformedPruningBoundary(false) {
69}
70
71
75
76
77void
79 // set edges dismiss/accept options
80 myEdgesMinSpeed = oc.getFloat("keep-edges.min-speed");
81 myRemoveEdgesAfterLoading = oc.exists("keep-edges.postload") && oc.getBool("keep-edges.postload");
82 // we possibly have to load the edges to keep/remove
83 if (oc.isSet("keep-edges.input-file")) {
84 NBHelpers::loadEdgesFromFile(oc.getString("keep-edges.input-file"), myEdges2Keep);
85 }
86 if (oc.isSet("remove-edges.input-file")) {
87 NBHelpers::loadEdgesFromFile(oc.getString("remove-edges.input-file"), myEdges2Remove);
88 }
89 if (oc.isSet("keep-edges.explicit")) {
90 const std::vector<std::string> edges = oc.getStringVector("keep-edges.explicit");
91 myEdges2Keep.insert(edges.begin(), edges.end());
92 }
93 if (oc.isSet("remove-edges.explicit")) {
94 const std::vector<std::string> edges = oc.getStringVector("remove-edges.explicit");
95 myEdges2Remove.insert(edges.begin(), edges.end());
96 }
97 if (oc.exists("keep-edges.by-vclass") && oc.isSet("keep-edges.by-vclass")) {
98 myVehicleClasses2Keep = parseVehicleClasses(oc.getStringVector("keep-edges.by-vclass"));
99 }
100 if (oc.exists("remove-edges.by-vclass") && oc.isSet("remove-edges.by-vclass")) {
101 myVehicleClasses2Remove = parseVehicleClasses(oc.getStringVector("remove-edges.by-vclass"));
102 }
103 if (oc.exists("keep-edges.by-type") && oc.isSet("keep-edges.by-type")) {
104 const std::vector<std::string> types = oc.getStringVector("keep-edges.by-type");
105 myTypes2Keep.insert(types.begin(), types.end());
106 }
107 if (oc.exists("remove-edges.by-type") && oc.isSet("remove-edges.by-type")) {
108 const std::vector<std::string> types = oc.getStringVector("remove-edges.by-type");
109 myTypes2Remove.insert(types.begin(), types.end());
110 }
111
112 if (oc.isSet("keep-edges.in-boundary") || oc.isSet("keep-edges.in-geo-boundary")) {
113
114 std::string polyPlainString = oc.getValueString(oc.isSet("keep-edges.in-boundary") ?
115 "keep-edges.in-boundary" : "keep-edges.in-geo-boundary");
116 // try interpreting the boundary like shape attribute with spaces
117 bool ok = true;
118 PositionVector boundaryShape = GeomConvHelper::parseShapeReporting(polyPlainString, "pruning-boundary", 0, ok, false, false);
119 if (ok) {
120 if (boundaryShape.size() < 2) {
121 throw ProcessError(TL("Invalid boundary: need at least 2 coordinates"));
122 } else if (boundaryShape.size() == 2) {
123 // prunning boundary (box)
124 myPruningBoundary.push_back(boundaryShape[0]);
125 myPruningBoundary.push_back(Position(boundaryShape[1].x(), boundaryShape[0].y()));
126 myPruningBoundary.push_back(boundaryShape[1]);
127 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 std::vector<std::string> polyS = oc.getStringVector(oc.isSet("keep-edges.in-boundary") ?
134 "keep-edges.in-boundary" : "keep-edges.in-geo-boundary");
135 std::vector<double> poly;
136 for (std::vector<std::string>::iterator i = polyS.begin(); i != polyS.end(); ++i) {
137 poly.push_back(StringUtils::toDouble((*i))); // !!! may throw something anyhow...
138 }
139 if (poly.size() < 4) {
140 throw ProcessError(TL("Invalid boundary: need at least 2 coordinates"));
141 } else if (poly.size() % 2 != 0) {
142 throw ProcessError(TL("Invalid boundary: malformed coordinate"));
143 } else if (poly.size() == 4) {
144 // prunning boundary (box)
145 myPruningBoundary.push_back(Position(poly[0], poly[1]));
146 myPruningBoundary.push_back(Position(poly[2], poly[1]));
147 myPruningBoundary.push_back(Position(poly[2], poly[3]));
148 myPruningBoundary.push_back(Position(poly[0], poly[3]));
149 } else {
150 for (std::vector<double>::iterator j = poly.begin(); j != poly.end();) {
151 double x = *j++;
152 double y = *j++;
153 myPruningBoundary.push_back(Position(x, y));
154 }
155 }
156 }
157 myNeedGeoTransformedPruningBoundary = oc.isSet("keep-edges.in-geo-boundary");
158 }
159}
160
161
162void
164 for (const auto& i : myEdges) {
165 delete i.second;
166 }
167 myEdges.clear();
168 for (const auto& i : myExtractedEdges) {
169 delete i.second;
170 }
171 myExtractedEdges.clear();
172 for (NBEdge* const e : myEdgeCemetery) {
173 delete e;
174 }
175 myEdgeCemetery.clear();
176}
177
178
179
180// ----- edge access methods
181bool
182NBEdgeCont::insert(NBEdge* edge, bool ignorePrunning) {
183 if (myEdges.count(edge->getID()) != 0) {
184 return false;
185 }
186 if (!ignorePrunning && ignoreFilterMatch(edge)) {
187 edge->getFromNode()->removeEdge(edge);
188 edge->getToNode()->removeEdge(edge);
189 myIgnoredEdges.insert(edge->getID());
190 delete edge;
191 } else {
193 if (oc.exists("dismiss-vclasses") && oc.getBool("dismiss-vclasses")) {
195 }
196 myEdges[edge->getID()] = edge;
197 }
198 return true;
199}
200
201
202bool
205 // check whether the edge is a named edge to keep
206 if (myEdges2Keep.size() != 0) {
207 if (myEdges2Keep.count(edge->getID()) == 0) {
208 // explicit whitelisting may be combined additively with other filters
210 && myTypes2Keep.size() == 0 && myTypes2Remove.size() == 0
211 && myPruningBoundary.size() == 0) {
212 return true;
213 }
214 } else {
215 // explicit whitelisting overrides other filters
216 return false;
217 }
218 }
219 // remove edges which allow a speed below a set one (set using "keep-edges.min-speed")
220 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 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
229 return true;
230 }
231 }
232 // check whether the edge is a named edge to remove
233 if (myEdges2Remove.size() != 0) {
234 if (myEdges2Remove.count(edge->getID()) != 0) {
235 return true;
236 }
237 }
238 // check whether the edge shall be removed because it does not have one of the requested types
239 if (myTypes2Keep.size() != 0) {
240 if (myTypes2Keep.count(edge->getTypeID()) == 0) {
241 return true;
242 }
243 }
244 // check whether the edge shall be removed because it has one of the forbidden types
245 if (myTypes2Remove.size() != 0) {
246 if (myTypes2Remove.count(edge->getTypeID()) > 0) {
247 return true;
248 }
249 }
250 // check whether the edge is within the pruning boundary
251 if (myPruningBoundary.size() != 0) {
253 if (GeoConvHelper::getProcessing().usingGeoProjection()) {
255 } else if (GeoConvHelper::getLoaded().usingGeoProjection()) {
256 // XXX what if input file with different projections are loaded?
257 for (int i = 0; i < (int) myPruningBoundary.size(); i++) {
259 }
260 } else {
261 WRITE_ERROR(TL("Cannot prune edges using a geo-boundary because no projection has been loaded"));
262 }
264 }
265 if (!(edge->getGeometry().getBoxBoundary().grow(POSITION_EPS).overlapsWith(myPruningBoundary))) {
266 return true;
267 } 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 }
274 return true;
275 }
276 return false;
277}
278
279
280NBEdge*
281NBEdgeCont::retrieve(const std::string& id, bool retrieveExtracted) const {
282 EdgeCont::const_iterator i = myEdges.find(id);
283 if (i == myEdges.end()) {
284 if (retrieveExtracted) {
285 i = myExtractedEdges.find(id);
286 if (i == myExtractedEdges.end()) {
287 return nullptr;
288 }
289 } else {
290 return nullptr;
291 }
292 }
293 return (*i).second;
294}
295
296// FIXME: This can't work
297/*
298NBEdge*
299NBEdgeCont::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
316NBEdge*
317NBEdgeCont::retrievePossiblySplit(const std::string& id, bool downstream) const {
318 NBEdge* edge = retrieve(id);
319 if (edge != nullptr) {
320 return edge;
321 }
322 // NOTE: (TODO) for multiply split edges (e.g. 15[0][0]) one could try recursion
323 if ((retrieve(id + "[0]") != nullptr) && (retrieve(id + "[1]") != nullptr)) {
324 // Edge was split during the netbuilding process
325 if (downstream) {
326 return retrieve(id + "[1]");
327 } else {
328 return retrieve(id + "[0]");
329 }
330 }
331 return edge;
332}
333
334
335NBEdge*
336NBEdgeCont::retrievePossiblySplit(const std::string& id, const std::string& hint, bool incoming) const {
337 // try to retrieve using the given name (iterative)
338 NBEdge* edge = retrieve(id);
339 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 NBEdge* hintedge = retrieve(hint);
346 if (hintedge == nullptr) {
347 hints = getGeneratedFrom(hint);
348 } else {
349 hints.push_back(hintedge);
350 }
351 EdgeVector candidates = getGeneratedFrom(id);
352 for (const NBEdge* const currHint : hints) {
353 for (NBEdge* const poss_searched : candidates) {
354 const NBNode* const node = incoming ? poss_searched->myTo : poss_searched->myFrom;
355 const EdgeVector& cont = incoming ? node->getOutgoingEdges() : node->getIncomingEdges();
356 if (find(cont.begin(), cont.end(), currHint) != cont.end()) {
357 return poss_searched;
358 }
359 }
360 }
361 return nullptr;
362}
363
364
365NBEdge*
366NBEdgeCont::retrievePossiblySplit(const std::string& id, double pos) const {
367 // check whether the edge was not split, yet
368 NBEdge* edge = retrieve(id);
369 if (edge != nullptr) {
370 return edge;
371 }
372 int maxLength = 0;
373 std::string tid = id + "[";
374 for (EdgeCont::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
375 if ((*i).first.find(tid) == 0) {
376 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 names.push_back(id + "[1]");
383 names.push_back(id + "[0]");
384 while (names.size() > 0) {
385 // retrieve the first subelement (to follow)
386 std::string cid = names.back();
387 names.pop_back();
388 edge = retrieve(cid);
389 // The edge was splitted; check its subparts within the
390 // next step
391 if (edge == nullptr) {
392 if ((int)cid.length() + 3 < maxLength) {
393 names.push_back(cid + "[1]");
394 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 seen += edge->getLength();
401 if (seen >= pos) {
402 return edge;
403 }
404 }
405 }
406 return nullptr;
407}
408
409
410void
412 extract(dc, edge);
413 delete edge;
414}
415
416
417void
418NBEdgeCont::extract(NBDistrictCont& dc, NBEdge* edge, bool remember) {
419 if (remember) {
420 const auto& prevExtracted = myExtractedEdges.find(edge->getID());
421 if (prevExtracted != myExtractedEdges.end()) {
422 if (edge != prevExtracted->second) {
423 myEdgeCemetery.insert(prevExtracted->second);
424 prevExtracted->second = edge;
425 }
426 } else {
427 myExtractedEdges[edge->getID()] = edge;
428 }
429 }
430 myEdges.erase(edge->getID());
431 edge->myFrom->removeEdge(edge);
432 edge->myTo->removeEdge(edge);
434}
435
436
437void
438NBEdgeCont::rename(NBEdge* edge, const std::string& newID) {
439 if (myEdges.count(newID) != 0) {
440 throw ProcessError(TLF("Attempt to rename edge using existing id '%'", newID));
441 }
442 myEdges.erase(edge->getID());
443 edge->setID(newID);
444 myEdges[newID] = edge;
445 // update oppositeID
446 if (edge->getLanes().back().oppositeID != "") {
447 NBEdge* oppo = retrieve(SUMOXMLDefinitions::getEdgeIDFromLane(edge->getLanes().back().oppositeID));
448 if (oppo != nullptr) {
449 oppo->getLaneStruct(oppo->getNumLanes() - 1).oppositeID = edge->getLaneID(edge->getNumLanes() - 1);
450 }
451 }
452}
453
454
455// ----- explicit edge manipulation methods
456
457void
458NBEdgeCont::processSplits(NBEdge* e, std::vector<Split> splits,
460 if (splits.empty()) {
461 return;
462 }
463 const std::string origID = e->getID();
464 sort(splits.begin(), splits.end(), split_sorter());
465 int maxNumLanes = e->getNumLanes();
466 // compute the node positions and sort the lanes
467 for (Split& split : splits) {
468 sort(split.lanes.begin(), split.lanes.end());
469 maxNumLanes = MAX2(maxNumLanes, (int)split.lanes.size());
470 }
471 // split the edge
472 std::vector<int> currLanes;
473 for (int l = 0; l < e->getNumLanes(); ++l) {
474 currLanes.push_back(l);
475 }
476 if (e->getNumLanes() != (int)splits.back().lanes.size()) {
477 // invalidate traffic light definitions loaded from a SUMO network
478 e->getToNode()->invalidateTLS(tlc, true, true);
479 // if the number of lanes changes the connections should be
480 // recomputed
481 e->invalidateConnections(true);
482 }
483
484 std::string firstID = "";
485 double seen = 0;
486 for (const Split& exp : splits) {
487 assert(exp.lanes.size() != 0);
488 if (exp.pos > 0 && e->getLoadedLength() + seen > exp.pos && exp.pos > seen) {
489 nc.insert(exp.node);
490 nc.markAsSplit(exp.node);
491 // split the edge
492 const std::string idBefore = exp.idBefore == "" ? e->getID() : exp.idBefore;
493 const std::string idAfter = exp.idAfter == "" ? exp.nameID : exp.idAfter;
494 if (firstID == "") {
495 firstID = idBefore;
496 }
497 const bool ok = splitAt(dc, e, exp.pos - seen, exp.node,
498 idBefore, idAfter, e->getNumLanes(), (int) exp.lanes.size(), exp.speed);
499 if (!ok) {
500 WRITE_WARNINGF(TL("Error on parsing a split (edge '%')."), origID);
501 return;
502 }
503 seen = exp.pos;
504 std::vector<int> newLanes = exp.lanes;
505 NBEdge* pe = retrieve(idBefore);
506 NBEdge* ne = retrieve(idAfter);
507 // reconnect lanes
508 pe->invalidateConnections(true);
509 // new on right
510 int rightMostP = currLanes[0];
511 int rightMostN = newLanes[0];
512 for (int l = 0; l < (int) rightMostP - (int) rightMostN; ++l) {
514 }
515 // new on left
516 int leftMostP = currLanes.back();
517 int leftMostN = newLanes.back();
518 for (int l = 0; l < (int) leftMostN - (int) leftMostP; ++l) {
519 pe->addLane2LaneConnection(pe->getNumLanes() - 1, ne, leftMostN - l - rightMostN, NBEdge::Lane2LaneInfoType::VALIDATED, true);
520 }
521 // all other connected
522 for (int l = 0; l < maxNumLanes; ++l) {
523 if (find(currLanes.begin(), currLanes.end(), l) == currLanes.end()) {
524 continue;
525 }
526 if (find(newLanes.begin(), newLanes.end(), l) == newLanes.end()) {
527 continue;
528 }
529 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 if (exp.node->getIncomingEdges().size() > 1 || exp.node->getOutgoingEdges().size() > 1 || exp.node->getType() == SumoXMLNodeType::ZIPPER) {
536 for (NBEdge* in : exp.node->getIncomingEdges()) {
537 in->invalidateConnections(true);
538 }
539 }
540 // move to next
541 e = ne;
542 currLanes = newLanes;
543 } else if (exp.pos == 0) {
544 const int laneCountDiff = e->getNumLanes() - (int)exp.lanes.size();
545 if (laneCountDiff < 0) {
546 e->incLaneNo(-laneCountDiff);
547 } else {
548 e->decLaneNo(laneCountDiff);
549 }
550 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 e->getFromNode()->invalidateTLS(tlc, true, true);
554 if (exp.speed != -1.) {
555 e->setSpeed(-1, exp.speed);
556 }
557 } else {
558 WRITE_WARNINGF(TL("Split at '%' lies beyond the edge's length (edge '%')."), toString(exp.pos), origID);
559 }
560 }
561 // patch lane offsets
562 e = retrieve(firstID);
563 if (e != nullptr) {
564 if (splits.front().pos != 0) {
565 // add a dummy split at the beginning to ensure correct offset
566 Split start;
567 start.pos = 0;
568 for (int lane = 0; lane < (int)e->getNumLanes(); ++lane) {
569 start.lanes.push_back(lane);
570 }
571 start.offset = splits.front().offset;
572 start.offsetFactor = splits.front().offsetFactor;
573 splits.insert(splits.begin(), start);
574 }
575 for (const Split& split : splits) {
576 int maxLeft = split.lanes.back();
577 double offset = split.offset;
578 if (maxLeft < maxNumLanes) {
580 offset += split.offsetFactor * SUMO_const_laneWidth * (maxNumLanes - 1 - maxLeft);
581 } else {
582 offset += split.offsetFactor * SUMO_const_halfLaneWidth * (maxNumLanes - 1 - maxLeft);
583 }
584 }
585 int maxRight = split.lanes.front();
586 if (maxRight > 0 && e->getLaneSpreadFunction() == LaneSpreadFunction::CENTER) {
587 offset -= split.offsetFactor * SUMO_const_halfLaneWidth * maxRight;
588 }
589 //std::cout << " processSplits " << origID << " splitOffset=" << (*i).offset << " offset=" << offset << "\n";
590 if (offset != 0) {
592 g.move2side(offset);
593 e->setGeometry(g);
594 }
595 if (e->getToNode()->getOutgoingEdges().size() != 0) {
596 e = e->getToNode()->getOutgoingEdges()[0];
597 }
598 }
599 }
600}
601
602
603bool
605 return splitAt(dc, edge, node, edge->getID() + "[0]", edge->getID() + "[1]",
606 (int) edge->myLanes.size(), (int) edge->myLanes.size());
607}
608
609
610bool
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 pos = edge->getGeometry().nearest_offset_to_point2D(node->getPosition());
619 if (pos <= 0) {
621 edge->myFrom->getPosition(), edge->myTo->getPosition(),
622 node->getPosition());
623 }
624 if (pos <= 0 || pos + POSITION_EPS > edge->getGeometry().length()) {
625 return false;
626 }
627 return splitAt(dc, edge, pos, node, firstEdgeName, secondEdgeName,
628 noLanesFirstEdge, noLanesSecondEdge, speed, friction, changedLeft);
629}
630
631
632bool
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 if (firstEdgeName != edge->getID() && myEdges.count(firstEdgeName) != 0) {
641 WRITE_ERRORF(TL("Could not insert edge '%' before split of edge '%'."), firstEdgeName, edge->getID());
642 return false;
643 }
644 if (secondEdgeName == firstEdgeName || (secondEdgeName != edge->getID() && myEdges.count(secondEdgeName) != 0)) {
645 WRITE_ERRORF(TL("Could not insert edge '%' after split of edge '%'."), secondEdgeName, edge->getID());
646 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 if (edge->hasLoadedLength()) {
655 geomPos = edge->getGeometry().nearest_offset_to_point2D(node->getPosition());
656 if (geomPos <= 0) {
657 geomPos = pos * edge->getGeometry().length() / edge->getLoadedLength();
658 }
659 }
660 std::pair<PositionVector, PositionVector> geoms = edge->getGeometry().splitAt(geomPos);
661 // reduce inaccuracies and preserve bidi
662 if (geoms.first[-1].almostSame(node->getPosition()) || edge->isBidi()) {
663 geoms.first[-1] = node->getPosition();
664 geoms.second[0] = node->getPosition();
665 }
666 // build and insert the edges
667 NBEdge* one = new NBEdge(firstEdgeName, edge->myFrom, node, edge, geoms.first, noLanesFirstEdge);
668 NBEdge* two = new NBEdge(secondEdgeName, node, edge->myTo, edge, geoms.second, noLanesSecondEdge);
669 if (OptionsCont::getOptions().getBool("output.original-names")) {
670 const std::string origID = edge->getLaneStruct(0).getParameter(SUMO_PARAM_ORIGID, edge->getID());
671 if (firstEdgeName != origID) {
672 one->setOrigID(origID, false);
673 }
674 if (secondEdgeName != origID) {
675 two->setOrigID(origID, false);
676 }
677 }
678 two->copyConnectionsFrom(edge);
679 if (speed != -1.) {
680 two->setSpeed(-1, speed);
681 }
682 if (friction != -1.) {
683 two->setFriction(-1, friction);
684 }
685 if (edge->getDistance() != 0) {
686 one->setDistance(edge->getDistance());
687 two->setDistance(one->getDistance() + pos);
688 }
689 if (edge->hasLoadedLength()) {
690 one->setLoadedLength(pos);
691 two->setLoadedLength(edge->getLoadedLength() - pos);
692 }
693 // replace information about this edge within the nodes
694 edge->myFrom->replaceOutgoing(edge, one, 0);
695 edge->myTo->replaceIncoming(edge, two, 0);
696 // patch tls
697 for (NBTrafficLightDefinition* const tld : edge->myFrom->getControllingTLS()) {
698 tld->replaceRemoved(edge, -1, one, -1, false);
699 }
700 for (NBTrafficLightDefinition* const tld : edge->myTo->getControllingTLS()) {
701 tld->replaceRemoved(edge, -1, two, -1, true);
702 }
703 // the edge is now occuring twice in both nodes...
704 // clean up
705 edge->myFrom->removeDoubleEdges();
706 edge->myTo->removeDoubleEdges();
707 // add connections from the first to the second edge
708 // there will be as many connections as there are lanes on the second edge
709 // by default lanes will be added / discontinued on the right side
710 // (appropriate for highway on-/off-ramps)
711 const int offset = (int)one->getNumLanes() - (int)two->getNumLanes() + changedLeft;
712 for (int i2 = 0; i2 < (int)two->getNumLanes(); i2++) {
713 const int i1 = MIN2(MAX2((int)0, i2 + offset), (int)one->getNumLanes());
715 throw ProcessError(TL("Could not set connection!"));
716 }
717 }
719 if (myEdges2Keep.count(edge->getID()) != 0) {
720 myEdges2Keep.insert(one->getID());
721 myEdges2Keep.insert(two->getID());
722 }
723 if (myEdges2Remove.count(edge->getID()) != 0) {
724 myEdges2Remove.insert(one->getID());
725 myEdges2Remove.insert(two->getID());
726 }
727 }
728 // erase the splitted edge
729 patchRoundabouts(edge, one, two, myRoundabouts);
730 patchRoundabouts(edge, one, two, myGuessedRoundabouts);
731 const std::string oldID = edge->getID();
732 extract(dc, edge, true);
733 insert(one, true); // duplicate id check happened earlier
734 insert(two, true); // duplicate id check happened earlier
735 myEdgesSplit[edge] = {one, two};
736 myWasSplit.insert(one);
737 myWasSplit.insert(two);
738 return true;
739}
740
741
742std::string
743NBEdgeCont::createUnusedID(const std::string& base, const std::string& sep) {
744 std::string result = base;
745 int i = 0;
746 while (myEdges.find(result) != myEdges.end()) {
747 result = base + sep + toString(i++);
748 }
749 return result;
750}
751
752
753void
754NBEdgeCont::patchRoundabouts(NBEdge* orig, NBEdge* part1, NBEdge* part2, std::set<EdgeSet>& roundabouts) {
755 std::set<EdgeSet> addLater;
756 for (std::set<EdgeSet>::iterator it = roundabouts.begin(); it != roundabouts.end(); ++it) {
757 EdgeSet roundaboutSet = *it;
758 if (roundaboutSet.count(orig) > 0) {
759 roundaboutSet.erase(orig);
760 roundaboutSet.insert(part1);
761 roundaboutSet.insert(part2);
762 }
763 addLater.insert(roundaboutSet);
764 }
765 roundabouts.clear();
766 roundabouts.insert(addLater.begin(), addLater.end());
767}
768
769
770// ----- container access methods
771std::vector<std::string>
773 std::vector<std::string> ret;
774 for (EdgeCont::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
775 ret.push_back((*i).first);
776 }
777 return ret;
778}
779
780
781NBEdge*
782NBEdgeCont::getSplitBase(const std::string& edgeID) const {
783 NBEdge* longest = nullptr;
784 for (auto item : myEdgesSplit) {
785 if (item.first->getID() == edgeID) {
786 if (longest == nullptr || longest->getLoadedLength() < item.first->getLoadedLength()) {
787 longest = const_cast<NBEdge*>(item.first);
788 }
789 }
790 }
791 return longest;
792}
793
794// ----- Adapting the input
795int
797 EdgeVector toRemove;
798 for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
799 NBEdge* edge = (*i).second;
800 if (!myEdges2Keep.count(edge->getID())) {
801 edge->getFromNode()->removeEdge(edge);
802 edge->getToNode()->removeEdge(edge);
803 toRemove.push_back(edge);
804 }
805 }
806 for (EdgeVector::iterator j = toRemove.begin(); j != toRemove.end(); ++j) {
807 erase(dc, *j);
808 }
809 return (int)toRemove.size();
810}
811
812
813void
815 // make a copy of myEdges because splitting will modify it
816 EdgeCont edges = myEdges;
817 for (auto& item : edges) {
818 NBEdge* edge = item.second;
819 if (edge->getGeometry().size() < 3) {
820 continue;
821 }
822 PositionVector geom = edge->getGeometry();
823 const std::string id = edge->getID();
824 double offset = 0;
825 for (int i = 1; i < (int)geom.size() - 1; i++) {
826 offset += geom[i - 1].distanceTo(geom[i]);
827 std::string nodeID = id + "." + toString((int)offset);
828 if (!nc.insert(nodeID, geom[i])) {
829 WRITE_WARNING("Could not split geometry of edge '" + id + "' at index " + toString(i));
830 continue;
831 }
832 NBNode* node = nc.retrieve(nodeID);
833 splitAt(dc, edge, node, edge->getID(), nodeID, edge->getNumLanes(), edge->getNumLanes());
834 edge = retrieve(nodeID);
835 }
836 }
837}
838
839
840void
841NBEdgeCont::reduceGeometries(const double minDist) {
842 for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
843 (*i).second->reduceGeometry(minDist);
844 }
845}
846
847
848void
849NBEdgeCont::checkGeometries(const double maxAngle, bool fixAngle, const double minRadius, bool fix, bool fixRailways, bool silent) {
850 if (maxAngle > 0 || minRadius > 0) {
851 for (auto& item : myEdges) {
852 if ((item.second->getPermissions() & (SVC_PUBLIC_CLASSES | SVC_PASSENGER)) == 0) {
853 continue;
854 }
855 item.second->checkGeometry(maxAngle, fixAngle, minRadius, fix || (fixRailways && isRailway(item.second->getPermissions())), silent);
856 }
857 }
858}
859
860
861// ----- processing methods
862void
864 for (EdgeCont::const_iterator i = myEdges.begin(); i != myEdges.end(); i++) {
865 (*i).second->clearControllingTLInformation();
866 }
867}
868
869
870void
872 for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); i++) {
873 (*i).second->sortOutgoingConnectionsByAngle();
874 }
875}
876
877
878void
880 for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); i++) {
881 (*i).second->computeEdge2Edges(noLeftMovers);
882 }
883}
884
885
886void
888 for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); i++) {
889 (*i).second->computeLanes2Edges();
890 }
891}
892
893
894void
896 const bool fixOppositeLengths = OptionsCont::getOptions().getBool("opposites.guess.fix-lengths");
897 for (const auto& edgeIt : myEdges) {
898 NBEdge* const edge = edgeIt.second;
899 edge->recheckLanes();
900 edge->recheckOpposite(*this, fixOppositeLengths);
901 }
902}
903
904
905void
906NBEdgeCont::appendTurnarounds(bool noTLSControlled, bool noFringe, bool onlyDeadends, bool onlyTurnlane, bool noGeometryLike) {
907 for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); i++) {
908 (*i).second->appendTurnaround(noTLSControlled, noFringe, onlyDeadends, onlyTurnlane, noGeometryLike, true);
909 }
910}
911
912
913void
914NBEdgeCont::appendTurnarounds(const std::set<std::string>& ids, bool noTLSControlled) {
915 for (std::set<std::string>::const_iterator it = ids.begin(); it != ids.end(); it++) {
916 myEdges[*it]->appendTurnaround(noTLSControlled, false, false, false, false, false);
917 }
918}
919
920
921void
923 std::set<std::string> stopEdgeIDs;
924 for (auto& stopItem : sc.getStops()) {
925 stopEdgeIDs.insert(stopItem.second->getEdgeId());
926 }
927 for (auto& item : myEdges) {
928 NBEdge* edge = item.second;
929 if (edge->isBidiRail()
930 && (stopEdgeIDs.count(item.first) > 0 ||
931 stopEdgeIDs.count(edge->getTurnDestination(true)->getID()) > 0)) {
932 NBEdge* to = edge->getTurnDestination(true);
933 assert(to != 0);
934 edge->setConnection(edge->getNumLanes() - 1,
935 to, to->getNumLanes() - 1, NBEdge::Lane2LaneInfoType::VALIDATED, false, false,
939 // finalize connections to prevent removal during recheck
941 }
942 }
943}
944
945void
946NBEdgeCont::computeEdgeShapes(double smoothElevationThreshold) {
947 for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); i++) {
948 (*i).second->computeEdgeShape(smoothElevationThreshold);
949 }
950 // equalize length of opposite edges
951 for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); i++) {
952 NBEdge* edge = i->second;
953 const std::string& oppositeID = edge->getLanes().back().oppositeID;
954 if (oppositeID != "" && oppositeID != "-") {
955 NBEdge* oppEdge = retrieve(oppositeID.substr(0, oppositeID.rfind("_")));
956 if (oppEdge == nullptr || oppEdge->getLaneID(oppEdge->getNumLanes() - 1) != oppositeID) {
957 continue;
958 }
959 if (fabs(oppEdge->getLength() - edge->getLength()) > NUMERICAL_EPS) {
960 double avgLength = (oppEdge->getLength() + edge->getLength()) / 2;
961 edge->setAverageLengthWithOpposite(avgLength);
962 oppEdge->setAverageLengthWithOpposite(avgLength);
963 }
964 }
965 }
966}
967
968
969void
971 for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
972 (*i).second->computeLaneShapes();
973 }
974}
975
976
977void
980 EdgeVector edges) {
981 // !!! Attention!
982 // No merging of the geometry to come is being done
983 // The connections are moved from one edge to another within
984 // the replacement where the edge is a node's incoming edge.
985
986 // count the number of lanes, the speed and the id
987 int nolanes = 0;
988 double speed = 0;
989 int priority = -1;
990 bool joinEdges = true;
991 std::string id;
992 sort(edges.begin(), edges.end(), NBContHelper::same_connection_edge_sorter());
993 // retrieve the connected nodes
994 NBEdge* tpledge = *(edges.begin());
995 NBNode* from = tpledge->getFromNode();
996 NBNode* to = tpledge->getToNode();
997 EdgeVector::const_iterator i;
998 int myPriority = (*edges.begin())->getPriority();
999 for (i = edges.begin(); i != edges.end(); i++) {
1000 // some assertions
1001 assert((*i)->getFromNode() == from);
1002 assert((*i)->getToNode() == to);
1003 // ad the number of lanes the current edge has
1004 nolanes += (*i)->getNumLanes();
1005 // build the id
1006 if (i != edges.begin()) {
1007 id += "+";
1008 }
1009 id += (*i)->getID();
1010 // compute the speed
1011 speed += (*i)->getSpeed();
1012 // build the priority
1013 // merged edges should have the same inherited priority
1014 if (myPriority == (*i)->getPriority()) {
1015 priority = myPriority;
1016 } else {
1017 priority = -1;
1018 joinEdges = false;
1019 }
1020 }
1021 if (joinEdges) {
1022 speed /= (double)edges.size();
1023 // build the new edge
1024 NBEdge* newEdge = new NBEdge(id, from, to, "", speed, NBEdge::UNSPECIFIED_FRICTION, nolanes, priority,
1026 tpledge->myLaneSpreadFunction, tpledge->getStreetName());
1027 newEdge->setRoundaboutGuessExcluded(std::any_of(edges.begin(), edges.end(), [](const NBEdge* edge) {
1028 return edge->isRoundaboutGuessExcluded();
1029 }));
1030 // copy lane attributes
1031 int laneIndex = 0;
1032 for (i = edges.begin(); i != edges.end(); ++i) {
1033 const std::vector<NBEdge::Lane>& lanes = (*i)->getLanes();
1034 for (int j = 0; j < (int)lanes.size(); ++j) {
1035 newEdge->setPermissions(lanes[j].permissions, laneIndex);
1036 newEdge->setLaneWidth(laneIndex, lanes[j].width);
1037 newEdge->setEndOffset(laneIndex, lanes[j].endOffset);
1038 laneIndex++;
1039 }
1040 }
1041 insert(newEdge, true);
1042 // replace old edge by current within the nodes
1043 // and delete the old
1044 from->replaceOutgoing(edges, newEdge);
1045 to->replaceIncoming(edges, newEdge);
1046 // patch connections
1047 // add edge2edge-information
1048 for (i = edges.begin(); i != edges.end(); i++) {
1049 EdgeVector ev = (*i)->getConnectedEdges();
1050 for (EdgeVector::iterator j = ev.begin(); j != ev.end(); j++) {
1051 newEdge->addEdge2EdgeConnection(*j);
1052 }
1053 }
1054 // copy outgoing connections to the new edge
1055 int currLane = 0;
1056 for (i = edges.begin(); i != edges.end(); i++) {
1057 newEdge->moveOutgoingConnectionsFrom(*i, currLane);
1058 currLane += (*i)->getNumLanes();
1059 }
1060 // patch tl-information
1061 currLane = 0;
1062 for (i = edges.begin(); i != edges.end(); i++) {
1063 int noLanes = (*i)->getNumLanes();
1064 for (int j = 0; j < noLanes; j++, currLane++) {
1065 // replace in traffic lights
1066 tlc.replaceRemoved(*i, j, newEdge, currLane, true);
1067 tlc.replaceRemoved(*i, j, newEdge, currLane, false);
1068 }
1069 }
1070 // delete joined edges
1071 for (i = edges.begin(); i != edges.end(); i++) {
1072 extract(dc, *i, true);
1073 }
1074 }
1075}
1076
1077
1078void
1080 //@todo magic values
1081 const bool fixOppositeLengths = OptionsCont::getOptions().getBool("opposites.guess.fix-lengths");
1082 // ensure consistency of loaded values before starting to guess
1083 for (const auto& edgeIt : myEdges) {
1084 NBEdge* const edge = edgeIt.second;
1085 edge->recheckOpposite(*this, fixOppositeLengths);
1086 }
1087 for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
1088 NBEdge* edge = i->second;
1089 edge->guessOpposite();
1090 }
1091}
1092
1093
1094void
1096 for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
1097 NBEdge* opposite = getOppositeByID(i->first);
1098 if (opposite != nullptr) {
1099 i->second->setLaneSpreadFunction(LaneSpreadFunction::RIGHT);
1101 } else {
1102 i->second->setLaneSpreadFunction(LaneSpreadFunction::CENTER);
1103 }
1104 }
1105}
1106
1107
1108NBEdge*
1109NBEdgeCont::getOppositeByID(const std::string& edgeID) const {
1110 const std::string oppositeID = edgeID[0] == '-' ? edgeID.substr(1) : "-" + edgeID;
1111 EdgeCont::const_iterator it = myEdges.find(oppositeID);
1112 return it != myEdges.end() ? it->second : (NBEdge*)nullptr;
1113}
1114
1115NBEdge*
1116NBEdgeCont::getByID(const std::string& edgeID) const {
1117 EdgeCont::const_iterator it = myEdges.find(edgeID);
1118 return it != myEdges.end() ? it->second : (NBEdge*)nullptr;
1119}
1120
1121// ----- other
1122void
1123NBEdgeCont::addPostProcessConnection(const std::string& from, int fromLane, const std::string& to, int toLane, bool mayDefinitelyPass,
1124 KeepClear keepClear, double contPos, double visibility, double speed, double friction, double length,
1125 const PositionVector& customShape, bool uncontrolled, bool warnOnly,
1126 SVCPermissions permissions, bool indirectLeft, const std::string& edgeType, SVCPermissions changeLeft, SVCPermissions changeRight) {
1127 myConnections[from].push_back(PostProcessConnection(from, fromLane, to, toLane, mayDefinitelyPass, keepClear, contPos, visibility,
1128 speed, friction, length, customShape, uncontrolled, warnOnly, permissions, indirectLeft, edgeType, changeLeft, changeRight));
1129}
1130
1131bool
1132NBEdgeCont::hasPostProcessConnection(const std::string& from, const std::string& to) {
1133 if (myConnections.count(from) == 0) {
1134 return false;
1135 } else {
1136 if (to == "") {
1137 // wildcard
1138 return true;
1139 }
1140 for (const auto& ppc : myConnections[from]) {
1141 if (ppc.to == to) {
1142 return true;
1143 }
1144 }
1145 return false;
1146 }
1147}
1148
1149void
1151 const bool warnOnly = OptionsCont::getOptions().exists("ignore-errors.connections") && OptionsCont::getOptions().getBool("ignore-errors.connections");
1152 for (const auto& item : myConnections) {
1153 for (std::vector<PostProcessConnection>::const_iterator i = item.second.begin(); i != item.second.end(); ++i) {
1154 NBEdge* from = retrievePossiblySplit((*i).from, true);
1155 NBEdge* to = retrievePossiblySplit((*i).to, false);
1156 if (from == nullptr || to == nullptr ||
1157 !from->addLane2LaneConnection((*i).fromLane, to, (*i).toLane, NBEdge::Lane2LaneInfoType::USER, true, (*i).mayDefinitelyPass,
1158 (*i).keepClear, (*i).contPos, (*i).visibility, (*i).speed, (*i).friction, (*i).customLength, (*i).customShape,
1159 (*i).uncontrolled, (*i).permissions, (*i).indirectLeft, (*i).edgeType, (*i).changeLeft, (*i).changeRight,
1160 true)) {
1161 const std::string msg = "Could not insert connection between '" + (*i).from + "' and '" + (*i).to + "' after build.";
1162 if (warnOnly || (*i).warnOnly) {
1163 WRITE_WARNING(msg);
1164 } else {
1165 WRITE_ERROR(msg);
1166 }
1167 }
1168 }
1169 }
1170 // during loading we also kept some ambiguous connections in hope they might be valid after processing
1171 // we need to make sure that all invalid connections are removed now
1172 for (EdgeCont::iterator it = myEdges.begin(); it != myEdges.end(); ++it) {
1173 NBEdge* edge = it->second;
1174 NBNode* to = edge->getToNode();
1175 // make a copy because we may delete connections
1176 std::vector<NBEdge::Connection> connections = edge->getConnections();
1177 for (std::vector<NBEdge::Connection>::iterator it_con = connections.begin(); it_con != connections.end(); ++it_con) {
1178 NBEdge::Connection& c = *it_con;
1179 if (c.toEdge != nullptr && c.toEdge->getFromNode() != to) {
1180 WRITE_WARNING("Found and removed invalid connection from edge '" + edge->getID() +
1181 "' to edge '" + c.toEdge->getID() + "' via junction '" + to->getID() + "'.");
1183 }
1184 }
1185 }
1186}
1187
1188
1190NBEdgeCont::getGeneratedFrom(const std::string& id) const {
1191 int len = (int)id.length();
1192 EdgeVector ret;
1193 for (EdgeCont::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
1194 std::string curr = (*i).first;
1195 // the next check makes it possibly faster - we don not have
1196 // to compare the names
1197 if ((int)curr.length() <= len) {
1198 continue;
1199 }
1200 // the name must be the same as the given id but something
1201 // beginning with a '[' must be appended to it
1202 if (curr.substr(0, len) == id && curr[len] == '[') {
1203 ret.push_back((*i).second);
1204 continue;
1205 }
1206 // ok, maybe the edge is a compound made during joining of edges
1207 std::string::size_type pos = curr.find(id);
1208 // surely not
1209 if (pos == std::string::npos) {
1210 continue;
1211 }
1212 // check leading char
1213 if (pos > 0) {
1214 if (curr[pos - 1] != ']' && curr[pos - 1] != '+') {
1215 // actually, this is another id
1216 continue;
1217 }
1218 }
1219 if (pos + id.length() < curr.length()) {
1220 if (curr[pos + id.length()] != '[' && curr[pos + id.length()] != '+') {
1221 // actually, this is another id
1222 continue;
1223 }
1224 }
1225 ret.push_back((*i).second);
1226 }
1227 return ret;
1228}
1229
1230
1231static bool
1233 for (size_t i = 0; i < loop.size(); ++i) {
1234 const NBEdge* ringIn = loop[i];
1235 const NBEdge* ringOut = loop[(i + 1) % loop.size()];
1236 const NBNode* node = ringIn->getToNode();
1237 const double outAngle = ringOut->getAngleAtNode(node);
1238 const double ringTurn = std::abs(NBHelpers::relAngle(ringIn->getAngleAtNode(node), outAngle));
1239 if (ringTurn <= 30.) {
1240 continue;
1241 }
1242 for (const NBEdge* approach : node->getIncomingEdges()) {
1243 if (approach->getPriority() > ringIn->getPriority()
1244 && (approach->getPermissions() & ringOut->getPermissions() & ~SVC_PEDESTRIAN) != 0
1245 && std::abs(NBHelpers::relAngle(approach->getAngleAtNode(node), outAngle)) <= 15.) {
1246 return true;
1247 }
1248 }
1249 }
1250 return false;
1251}
1252
1253
1254int
1256 myGuessedRoundabouts.clear();
1257 std::set<NBEdge*> loadedRoundaboutEdges;
1258 for (std::set<EdgeSet>::const_iterator it = myRoundabouts.begin(); it != myRoundabouts.end(); ++it) {
1259 loadedRoundaboutEdges.insert(it->begin(), it->end());
1260 }
1261 // step 1: keep only those edges which have no turnarounds and which are not
1262 // part of a loaded roundabout
1263 std::set<NBEdge*, ComparatorIdLess> candidates;
1264 SVCPermissions valid = SVCAll & ~SVC_PEDESTRIAN;
1265 for (EdgeCont::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
1266 NBEdge* e = (*i).second;
1267 NBNode* const to = e->getToNode();
1268 if (e->getTurnDestination() == nullptr
1269 && to->getConnectionTo(e->getFromNode()) == nullptr
1270 && (e->getPermissions() & valid) != 0) {
1271 candidates.insert(e);
1272 }
1273 }
1274
1275 // step 2:
1276 std::set<NBEdge*> visited;
1277 for (std::set<NBEdge*, ComparatorIdLess>::const_iterator i = candidates.begin(); i != candidates.end(); ++i) {
1278 EdgeVector loopEdges;
1279 // start with a random edge (this doesn't have to be a roundabout edge)
1280 // loop over connected edges (using always the leftmost one)
1281 // and keep the list in loopEdges
1282 // continue until we loop back onto a loopEdges and extract the loop
1283 NBEdge* e = (*i);
1284 if (visited.count(e) > 0) {
1285 // already seen
1286 continue;
1287 }
1288 loopEdges.push_back(e);
1289 bool doLoop = true;
1290#ifdef DEBUG_GUESS_ROUNDABOUT
1292#endif
1293 do {
1294#ifdef DEBUG_GUESS_ROUNDABOUT
1295 if (gDebugFlag1) {
1296 std::cout << " e=" << e->getID() << " loopEdges=" << toString(loopEdges) << "\n";
1297 gDebugFlag1 = true;
1298 }
1299#endif
1300 visited.insert(e);
1301 const EdgeVector& edges = e->getToNode()->getEdges();
1303 && !e->getToNode()->typeWasGuessed()) {
1304 doLoop = false;
1305#ifdef DEBUG_GUESS_ROUNDABOUT
1306 if (gDebugFlag1) {
1307 std::cout << " rbl\n";
1308 }
1309 gDebugFlag1 = false;
1310#endif
1311 break;
1312 }
1314 doLoop = false;
1315#ifdef DEBUG_GUESS_ROUNDABOUT
1316 if (gDebugFlag1) {
1317 std::cout << " disabled\n";
1318 }
1319 gDebugFlag1 = false;
1320#endif
1321 break;
1322 }
1323 if (edges.size() < 2) {
1324 doLoop = false;
1325#ifdef DEBUG_GUESS_ROUNDABOUT
1326 if (gDebugFlag1) {
1327 std::cout << " deadend\n";
1328 }
1329 gDebugFlag1 = false;
1330#endif
1331 break;
1332 }
1333 if (e->getTurnDestination(true) != nullptr || e->getToNode()->getConnectionTo(e->getFromNode()) != nullptr) {
1334 // do not follow turn-arounds while in a (tentative) loop
1335 doLoop = false;
1336#ifdef DEBUG_GUESS_ROUNDABOUT
1337 if (gDebugFlag1) {
1338 std::cout << " invalid turnAround e=" << e->getID() << " dest=" << Named::getIDSecure(e->getTurnDestination()) << "\n";
1339 }
1340 gDebugFlag1 = false;
1341#endif
1342 break;
1343 }
1344 EdgeVector::const_iterator me = std::find(edges.begin(), edges.end(), e);
1345 NBContHelper::nextCW(edges, me);
1346 NBEdge* left = *me;
1347 while ((left->getPermissions() & valid) == 0 && left != e) {
1348 NBContHelper::nextCW(edges, me);
1349 left = *me;
1350 }
1351 if (left == e) {
1352 // no usable continuation edge found
1353 doLoop = false;
1354#ifdef DEBUG_GUESS_ROUNDABOUT
1355 if (gDebugFlag1) {
1356 std::cout << " noContinuation\n";
1357 }
1358 gDebugFlag1 = false;
1359#endif
1360 break;
1361 }
1362 NBContHelper::nextCW(edges, me);
1363 NBEdge* nextLeft = *me;
1364 double angle = fabs(NBHelpers::relAngle(e->getAngleAtNode(e->getToNode()), left->getAngleAtNode(e->getToNode())));
1365 double nextAngle = nextLeft == e ? 180 : fabs(NBHelpers::relAngle(e->getAngleAtNode(e->getToNode()), nextLeft->getAngleAtNode(e->getToNode())));
1366#ifdef DEBUG_GUESS_ROUNDABOUT
1367 if (gDebugFlag1) {
1368 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";
1369 }
1370#endif
1371 // there should be no straigher edge further left
1372 if (angle >= 90 && nextAngle < 45) {
1373 doLoop = false;
1374#ifdef DEBUG_GUESS_ROUNDABOUT
1375 if (gDebugFlag1) {
1376 std::cout << " failed nextAngle=" << nextAngle << "\n";
1377 }
1378 gDebugFlag1 = false;
1379#endif
1380 break;
1381 }
1382 // roundabouts do not have sharp turns (or they wouldn't be called 'round')
1383 // 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 180 (for smooth attachments at a joined junction)
1384 if (angle >= 90) {
1385 double edgeAngle = fabs(NBHelpers::relAngle(e->getStartAngle(), e->getEndAngle()));
1386 double edgeAngle2 = fabs(NBHelpers::relAngle(left->getStartAngle(), left->getEndAngle()));
1387 double edgeRadius = e->getGeometry().length2D() / DEG2RAD(edgeAngle);
1388 double edgeRadius2 = left->getGeometry().length2D() / DEG2RAD(edgeAngle2);
1389 const double avgRadius = 0.5 * (edgeRadius + edgeRadius2);
1390 double junctionRadius = e->getLaneShape(0).back().distanceTo2D(left->getLaneShape(0).front()) / DEG2RAD(angle);
1391 //std::cout << " junction=" << e->getToNode()->getID() << " e=" << e->getID() << " left=" << left->getID() << " angle=" << angle << " eRadius=" << edgeRadius << " eRadius2=" << edgeRadius2 << " jRadius3=" << junctionRadius << "\n";
1392 if (junctionRadius < 0.8 * avgRadius) {
1393 doLoop = false;
1394#ifdef DEBUG_GUESS_ROUNDABOUT
1395 if (gDebugFlag1) {
1396 std::cout << " failed angle=" << angle << " eRadius=" << edgeRadius << " eRadius2=" << edgeRadius2 << " jRadius3=" << junctionRadius << "\n";
1397 }
1398 gDebugFlag1 = false;
1399#endif
1400 break;
1401 }
1402 }
1403
1404 EdgeVector::const_iterator loopClosed = std::find(loopEdges.begin(), loopEdges.end(), left);
1405 const int loopSize = (int)(loopEdges.end() - loopClosed);
1406 if (loopSize > 0) {
1407 // loop found
1408 if (loopSize < 3) {
1409 doLoop = false; // need at least 3 edges for a roundabout
1410 } else if (loopSize < (int)loopEdges.size()) {
1411 // remove initial edges not belonging to the loop
1412 EdgeVector(loopEdges.begin() + (loopEdges.size() - loopSize), loopEdges.end()).swap(loopEdges);
1413 }
1414 // count attachments to the outside. need at least 3 or a roundabout doesn't make much sense
1415 int attachments = 0;
1416 for (EdgeVector::const_iterator j = loopEdges.begin(); j != loopEdges.end(); ++j) {
1417 if ((*j)->getToNode()->getEdges().size() > 2) {
1418 attachments++;
1419 }
1420 }
1421 if (attachments < 3) {
1422 doLoop = false;
1423#ifdef DEBUG_GUESS_ROUNDABOUT
1424 if (gDebugFlag1) {
1425 std::cout << " attachments=" << attachments << "\n";
1426 }
1427 gDebugFlag1 = false;
1428#endif
1429 }
1430 break;
1431 }
1432 if (visited.count(left) > 0) {
1433 doLoop = false;
1434 } else {
1435 // keep going
1436 loopEdges.push_back(left);
1437 e = left;
1438 }
1439 } while (doLoop);
1440 if (doLoop) {
1441 // check form factor to avoid elongated shapes (circle: 1, square: ~0.79)
1442#ifdef DEBUG_GUESS_ROUNDABOUT
1443 if (gDebugFlag1) {
1444 std::cout << " formFactor=" << formFactor(loopEdges) << "\n";
1445 }
1446#endif
1447 double loopLength = 0;
1448 for (const NBEdge* const le : loopEdges) {
1449 loopLength += le->getLoadedLength();
1450 }
1451 if (formFactor(loopEdges) > 0.8
1452 && loopLength < OptionsCont::getOptions().getFloat("roundabouts.guess.max-length")) {
1453 // Preserve explicitly loaded roundabouts.
1454 const bool loaded = std::any_of(loopEdges.begin(), loopEdges.end(), [&loadedRoundaboutEdges](NBEdge* edge) {
1455 return loadedRoundaboutEdges.count(edge) != 0;
1456 });
1457 if (!loaded) {
1458 const bool excluded = std::any_of(loopEdges.begin(), loopEdges.end(), [](const NBEdge* edge) {
1459 // Netconvert can also load previously converted OSM networks.
1460 if (edge->isRoundaboutGuessExcluded()) {
1461 return true;
1462 }
1463 const auto types = StringTokenizer(edge->getTypeID(), "|").getVector();
1464 return std::any_of(types.begin(), types.end(), [](const std::string& type) {
1465 return type == "highway.service"
1466 || (StringUtils::startsWith(type, "highway.") && StringUtils::endsWith(type, "_link"));
1467 });
1468 });
1469 const bool allSignals = std::all_of(loopEdges.begin(), loopEdges.end(), [](const NBEdge* edge) {
1470 const NBNode* node = edge->getToNode();
1471 return node->isTrafficLight() || node->isTLControlled();
1472 });
1473 if (excluded || allSignals || hasStraightPriorityApproach(loopEdges)) {
1474 continue;
1475 }
1476 }
1477 // collected edges are marked in markRoundabouts
1478 EdgeSet guessed(loopEdges.begin(), loopEdges.end());
1479 if (loadedRoundaboutEdges.count(loopEdges.front()) != 0) {
1480 if (find(myRoundabouts.begin(), myRoundabouts.end(), guessed) == myRoundabouts.end()) {
1481 for (auto it = myRoundabouts.begin(); it != myRoundabouts.end(); it++) {
1482 if ((*it).count(loopEdges.front()) != 0) {
1483 WRITE_WARNINGF(TL("Replacing loaded roundabout '%' with '%'."), toString(*it), toString(guessed));
1484 myRoundabouts.erase(it);
1485 break;
1486 }
1487 }
1488 myGuessedRoundabouts.insert(guessed);
1489 }
1490 } else {
1491 myGuessedRoundabouts.insert(guessed);
1492#ifdef DEBUG_GUESS_ROUNDABOUT
1493 if (gDebugFlag1) {
1494 std::cout << " foundRoundabout=" << toString(loopEdges) << "\n";
1495 }
1496#endif
1497 }
1498 }
1499 }
1500#ifdef DEBUG_GUESS_ROUNDABOUT
1501 gDebugFlag1 = false;
1502#endif
1503 }
1504 return (int)myGuessedRoundabouts.size();
1505}
1506
1507
1508int
1510 EdgeVector candidateEdges;
1511 for (const auto& edge : myEdges) {
1512 NBEdge* const e = edge.second;
1514 candidateEdges.push_back(e);
1515 }
1516 }
1517 std::set<NBEdge*> visited;
1518 int extracted = 0;
1519 for (NBEdge* const startEdge : candidateEdges) {
1520 if (visited.count(startEdge) > 0) {
1521 // already seen
1522 continue;
1523 }
1524 EdgeVector loopEdges;
1525 NBEdge* e = startEdge;
1526 while (true) {
1527 const auto loopIt = std::find(loopEdges.begin(), loopEdges.end(), e);
1528 if (loopIt != loopEdges.end()) {
1529 if (loopEdges.end() - loopIt > 1) {
1530 addRoundabout(EdgeSet(loopIt, loopEdges.end()));
1531 visited.insert(loopIt, loopEdges.end());
1532 ++extracted;
1533 } else {
1534 visited.insert(e);
1535 }
1536 break;
1537 }
1538 if (visited.count(e) > 0) {
1539 visited.insert(loopEdges.begin(), loopEdges.end());
1540 break;
1541 }
1542 loopEdges.push_back(e);
1543 const EdgeVector& outgoingEdges = e->getToNode()->getOutgoingEdges();
1544 NBEdge* next = nullptr;
1545 for (NBEdge* const outgoingEdge : outgoingEdges) {
1546 if (outgoingEdge->getJunctionPriority(outgoingEdge->getToNode()) == NBEdge::JunctionPriority::ROUNDABOUT
1547 && std::find(loopEdges.begin(), loopEdges.end(), outgoingEdge) != loopEdges.end()) {
1548 next = outgoingEdge;
1549 break;
1550 }
1551 }
1552 if (next == nullptr) {
1553 for (NBEdge* const outgoingEdge : outgoingEdges) {
1554 if (outgoingEdge->getJunctionPriority(outgoingEdge->getToNode()) == NBEdge::JunctionPriority::ROUNDABOUT
1555 && visited.count(outgoingEdge) == 0) {
1556 next = outgoingEdge;
1557 break;
1558 }
1559 }
1560 }
1561 if (next == nullptr) { // no closed loop
1562 visited.insert(loopEdges.begin(), loopEdges.end());
1563 break;
1564 }
1565 e = next;
1566 }
1567 }
1568 return extracted;
1569}
1570
1571
1572void
1574 // only loaded roundabouts are of concern here since guessing comes later
1575 std::set<EdgeSet> validRoundabouts;
1576 std::set<NBEdge*> validEdges;
1577 for (auto item : myEdges) {
1578 validEdges.insert(item.second);
1579 }
1580 for (EdgeSet roundabout : myRoundabouts) {
1581 EdgeSet validRoundabout;
1582 for (NBEdge* cand : roundabout) {
1583 if (validEdges.count(cand) != 0) {
1584 validRoundabout.insert(cand);
1585 }
1586 }
1587 if (validRoundabout.size() > 0) {
1588 validRoundabouts.insert(validRoundabout);
1589 }
1590 }
1591 myRoundabouts = validRoundabouts;
1592}
1593
1594
1595double
1597 // A circle (which maximizes area per circumference) has a formfactor of 1, non-circular shapes have a smaller value
1598 PositionVector points;
1599 for (EdgeVector::const_iterator it = loopEdges.begin(); it != loopEdges.end(); ++it) {
1600 points.append((*it)->getGeometry());
1601 }
1602 double circumference = points.length2D();
1603 return 4 * M_PI * points.area() / (circumference * circumference);
1604}
1605
1606
1607const std::set<EdgeSet>
1609 std::set<EdgeSet> result = myRoundabouts;
1610 result.insert(myGuessedRoundabouts.begin(), myGuessedRoundabouts.end());
1611 return result;
1612}
1613
1614
1615void
1617 if (roundabout.size() > 0) {
1618 if (find(myRoundabouts.begin(), myRoundabouts.end(), roundabout) != myRoundabouts.end()) {
1619 WRITE_WARNING("Ignoring duplicate roundabout: " + toString(roundabout));
1620 } else {
1621 myRoundabouts.insert(roundabout);
1622 }
1623 }
1624}
1625
1626void
1628 for (auto it = myRoundabouts.begin(); it != myRoundabouts.end(); ++it) {
1629 for (NBEdge* e : *it) {
1630 if (e->getToNode() == node) {
1631 myRoundabouts.erase(it);
1632 return;
1633 }
1634 }
1635 }
1636}
1637
1638void
1643
1644void
1645NBEdgeCont::removeRoundaboutEdges(const EdgeSet& toRemove, std::set<EdgeSet>& roundabouts) {
1646 // members of a set are constant so we have to do some tricks
1647 std::vector<EdgeSet> rList;
1648 for (const EdgeSet& r : roundabouts) {
1649 EdgeSet r2;
1650 std::set_difference(r.begin(), r.end(), toRemove.begin(), toRemove.end(), std::inserter(r2, r2.end()));
1651 if (!r2.empty()) {
1652 rList.push_back(r2);
1653 }
1654 }
1655 roundabouts.clear();
1656 roundabouts.insert(rList.begin(), rList.end());
1657}
1658
1659
1660void
1662 for (const EdgeSet& roundaboutSet : getRoundabouts()) {
1663 for (NBEdge* const edge : roundaboutSet) {
1664 // disable turnarounds on incoming edges
1665 NBNode* const node = edge->getToNode();
1666 for (NBEdge* const inEdge : node->getIncomingEdges()) {
1667 if (roundaboutSet.count(inEdge) > 0) {
1668 continue;
1669 }
1670 if (inEdge->getStep() >= NBEdge::EdgeBuildingStep::LANES2LANES_USER) {
1671 continue;
1672 }
1673 if (inEdge->getTurnDestination() != nullptr) {
1674 inEdge->removeFromConnections(inEdge->getTurnDestination(), -1);
1675 } else {
1676 // also remove connections that are effecively a turnaround but
1677 // where not correctly detector due to geometrical quirks
1678 const std::vector<NBEdge::Connection> cons = inEdge->getConnections();
1679 for (const NBEdge::Connection& con : cons) {
1680 if (con.toEdge && roundaboutSet.count(con.toEdge) == 0) {
1681 const double angle = fabs(NBHelpers::normRelAngle(inEdge->getAngleAtNode(node), con.toEdge->getAngleAtNode(node)));
1682 if (angle > 160) {
1683 inEdge->removeFromConnections(con.toEdge, -1);
1684 }
1685 }
1686 }
1687 }
1688
1689 }
1690 // let the connections to succeeding roundabout edge have a higher priority
1691 edge->setJunctionPriority(node, NBEdge::JunctionPriority::ROUNDABOUT);
1692 edge->setJunctionPriority(edge->getFromNode(), NBEdge::JunctionPriority::ROUNDABOUT);
1693 node->setRoundabout();
1694 }
1695 }
1696}
1697
1698
1699void
1701 for (EdgeCont::iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
1702 NBEdge* e = i->second;
1703 const double offset = MAX2(0., e->getLength() - 3);
1704 if (e->getToNode()->isSimpleContinuation(false)) {
1705 // not a "real" junction?
1706 continue;
1707 }
1708 const SumoXMLNodeType nodeType = e->getToNode()->getType();
1709 switch (nodeType) {
1711 // yield or major?
1712 if (e->getJunctionPriority(e->getToNode()) > 0) {
1714 } else {
1716 }
1717 break;
1719 // yield or major?
1720 if (e->getJunctionPriority(e->getToNode()) > 0) {
1722 } else {
1724 }
1725 break;
1728 break;
1731 break;
1734 break;
1735 default:
1736 break;
1737 }
1738 }
1739}
1740
1741
1742int
1743NBEdgeCont::guessSpecialLanes(SUMOVehicleClass svc, double width, double minSpeed, double maxSpeed, bool fromPermissions, const std::string& excludeOpt,
1745 int lanesCreated = 0;
1746 std::vector<std::string> edges;
1747 if (excludeOpt != "") {
1748 edges = OptionsCont::getOptions().getStringVector(excludeOpt);
1749 }
1750 std::set<std::string> exclude(edges.begin(), edges.end());
1751 for (EdgeCont::iterator it = myEdges.begin(); it != myEdges.end(); it++) {
1752 NBEdge* edge = it->second;
1753 if (// not excluded
1754 exclude.count(edge->getID()) == 0
1755 // does not yet have a sidewalk/bikelane
1756 && !edge->hasRestrictedLane(svc)
1757 // needs a sidewalk/bikelane
1758 && ((edge->getPermissions() & ~SVC_VULNERABLE) != 0 || (edge->getPermissions() & svc) == 0)
1759 && (
1760 // guess.from-permissions
1761 (fromPermissions && (edge->getPermissions() & svc) != 0)
1762 // guess from speed
1763 || (!fromPermissions && edge->getSpeed() > minSpeed && edge->getSpeed() <= maxSpeed)
1764 )) {
1765 edge->addRestrictedLane(width, svc);
1766 lanesCreated += 1;
1767 if (svc != SVC_PEDESTRIAN) {
1769 // preserve existing connections and only add new ones
1772 for (NBEdge* to : edge->getToNode()->getOutgoingEdges()) {
1774 }
1775 // patching TLS is not feasible because existing states may
1776 // change from 'G' to 'g' when bike lanes are added (i.e. right-turns)
1777 } else {
1778 edge->invalidateConnections(true);
1780 }
1781 edge->getFromNode()->invalidateTLS(tlc, true, false);
1782 edge->getToNode()->invalidateTLS(tlc, true, false);
1783 }
1784 } else if (!fromPermissions && edge->getSpeed() > maxSpeed && !edge->hasRestrictedLane(svc)) {
1785 edge->disallowVehicleClass(-1, svc);
1786 }
1787 }
1788 return lanesCreated;
1789}
1790
1791
1792void
1794 for (auto item : myEdges) {
1795 item.second->updateChangeRestrictions(ignoring);
1796 }
1797}
1798
1799
1800void
1801NBEdgeCont::addPrefix(const std::string& prefix) {
1802 // make a copy of node containers
1803 const auto nodeContainerCopy = myEdges;
1804 myEdges.clear();
1805 for (const auto& node : nodeContainerCopy) {
1806 node.second->setID(prefix + node.second->getID());
1807 myEdges[node.second->getID()] = node.second;
1808 }
1809}
1810
1811
1812int
1813NBEdgeCont::remapIDs(bool numericaIDs, bool reservedIDs, bool keptIDs, const std::string& prefix, NBPTStopCont& sc) {
1814 bool startGiven = !OptionsCont::getOptions().isDefault("numerical-ids.edge-start");
1815 if (!numericaIDs && !reservedIDs && prefix == "" && !startGiven) {
1816 return 0;
1817 }
1818 std::vector<std::string> avoid;
1819 if (startGiven) {
1820 avoid.push_back(toString(OptionsCont::getOptions().getInt("numerical-ids.edge-start") - 1));
1821 } else {
1822 avoid = getAllNames();
1823 }
1824 std::set<std::string> reserve;
1825 if (reservedIDs) {
1826 NBHelpers::loadPrefixedIDsFomFile(OptionsCont::getOptions().getString("reserved-ids"), "edge:", reserve);
1827 avoid.insert(avoid.end(), reserve.begin(), reserve.end());
1828 }
1829 IDSupplier idSupplier("", avoid);
1830 std::set<NBEdge*, ComparatorIdLess> toChange;
1831 for (EdgeCont::iterator it = myEdges.begin(); it != myEdges.end(); it++) {
1832 if (startGiven) {
1833 toChange.insert(it->second);
1834 continue;
1835 }
1836 if (numericaIDs) {
1837 try {
1838 StringUtils::toLong(it->first);
1839 } catch (NumberFormatException&) {
1840 toChange.insert(it->second);
1841 }
1842 }
1843 if (reservedIDs && reserve.count(it->first) > 0) {
1844 toChange.insert(it->second);
1845 }
1846 }
1847 std::set<std::string> keep;
1848 if (keptIDs) {
1849 NBHelpers::loadPrefixedIDsFomFile(OptionsCont::getOptions().getString("kept-ids"), "edge:", keep);
1850 for (auto it = toChange.begin(); it != toChange.end();) {
1851 if (keep.count((*it)->getID()) != 0) {
1852 toChange.erase(it++);
1853 } else {
1854 it++;
1855 }
1856 }
1857 }
1858
1859 std::map<std::string, std::vector<std::shared_ptr<NBPTStop> > > stopsOnEdge;
1860 for (const auto& item : sc.getStops()) {
1861 stopsOnEdge[item.second->getEdgeId()].push_back(item.second);
1862 }
1863
1864 const bool origNames = OptionsCont::getOptions().getBool("output.original-names");
1865 for (NBEdge* edge : toChange) {
1866 myEdges.erase(edge->getID());
1867 }
1868 for (NBEdge* edge : toChange) {
1869 const std::string origID = edge->getID();
1870 if (origNames) {
1871 edge->setOrigID(origID, false);
1872 }
1873 edge->setID(idSupplier.getNext());
1874 myEdges[edge->getID()] = edge;
1875 for (std::shared_ptr<NBPTStop> stop : stopsOnEdge[origID]) {
1876 stop->setEdgeId(prefix + edge->getID(), *this);
1877 }
1878 }
1879 if (prefix.empty()) {
1880 return (int)toChange.size();
1881 } else {
1882 int renamed = 0;
1883 // make a copy because we will modify the map
1884 auto oldEdges = myEdges;
1885 for (auto item : oldEdges) {
1886 if (!StringUtils::startsWith(item.first, prefix) && keep.count(item.first) == 0) {
1887 rename(item.second, prefix + item.first);
1888 renamed++;
1889 }
1890 }
1891 return renamed;
1892 }
1893}
1894
1895
1896void
1897NBEdgeCont::checkOverlap(double threshold, double zThreshold) const {
1898 for (EdgeCont::const_iterator it = myEdges.begin(); it != myEdges.end(); it++) {
1899 const NBEdge* e1 = it->second;
1900 Boundary b1 = e1->getGeometry().getBoxBoundary();
1901 b1.grow(e1->getTotalWidth());
1902 PositionVector outline1 = e1->getCCWBoundaryLine(*e1->getFromNode());
1903 outline1.append(e1->getCCWBoundaryLine(*e1->getToNode()));
1904 // check is symmetric. only check once per pair
1905 for (EdgeCont::const_iterator it2 = it; it2 != myEdges.end(); it2++) {
1906 const NBEdge* e2 = it2->second;
1907 if (e1 == e2) {
1908 continue;
1909 }
1910 Boundary b2 = e2->getGeometry().getBoxBoundary();
1911 b2.grow(e2->getTotalWidth());
1912 if (b1.overlapsWith(b2)) {
1913 PositionVector outline2 = e2->getCCWBoundaryLine(*e2->getFromNode());
1914 outline2.append(e2->getCCWBoundaryLine(*e2->getToNode()));
1915 const double overlap = outline1.getOverlapWith(outline2, zThreshold);
1916 if (overlap > threshold) {
1917 WRITE_WARNINGF(TL("Edge '%' overlaps with edge '%' by %."), e1->getID(), e2->getID(), overlap);
1918 }
1919 }
1920 }
1921 }
1922}
1923
1924
1925void
1926NBEdgeCont::checkGrade(double threshold) const {
1927 for (EdgeCont::const_iterator it = myEdges.begin(); it != myEdges.end(); it++) {
1928 const NBEdge* edge = it->second;
1929 for (int i = 0; i < (int)edge->getNumLanes(); i++) {
1930 double maxJump = 0;
1931 const double grade = edge->getLaneShape(i).getMaxGrade(maxJump);
1932 if (maxJump > 0.01) {
1933 WRITE_WARNINGF(TL("Edge '%' has a vertical jump of %m."), edge->getID(), maxJump);
1934 } else if (grade > threshold) {
1935 WRITE_WARNINGF(TL("Edge '%' has a grade of %%."), edge->getID(), grade * 100, "%");
1936 break;
1937 }
1938 }
1939 const std::vector<NBEdge::Connection>& connections = edge->getConnections();
1940 for (std::vector<NBEdge::Connection>::const_iterator it_con = connections.begin(); it_con != connections.end(); ++it_con) {
1941 const NBEdge::Connection& c = *it_con;
1942 double maxJump = 0;
1943 const double grade = MAX2(c.shape.getMaxGrade(maxJump), c.viaShape.getMaxGrade(maxJump));
1944 if (maxJump > 0.01) {
1945 WRITE_WARNINGF(TL("Connection '%' has a vertical jump of %m."), c.getDescription(edge), maxJump);
1946 } else if (grade > threshold) {
1947 WRITE_WARNINGF(TL("Connection '%' has a grade of %%."), c.getDescription(edge), grade * 100, "%");
1948 break;
1949 }
1950 }
1951 }
1952}
1953
1954
1955int
1957 int affectedEdges = 0;
1958 for (auto item : myEdges) {
1959 if (item.second->joinLanes(perms)) {
1960 affectedEdges++;
1961 }
1962 }
1963 return affectedEdges;
1964}
1965
1966
1967bool
1968NBEdgeCont::MinLaneComparatorIdLess::operator()(const std::pair<NBEdge*, int>& a, const std::pair<NBEdge*, int>& b) const {
1969 if (a.first->getID() == b.first->getID()) {
1970 return a.second < b.second;
1971 }
1972 return a.first->getID() < b.first->getID();
1973}
1974
1975int
1977 // this is different from joinSimilarEdges because there don't need to be
1978 // shared nodes and tram edges may be split
1979 std::vector<NBEdge*> tramEdges;
1980 std::vector<NBEdge*> targetEdges;
1981 for (auto item : myEdges) {
1982 SVCPermissions permissions = item.second->getPermissions();
1983 if (isTram(permissions)) {
1984 if (item.second->getNumLanes() == 1) {
1985 tramEdges.push_back(item.second);
1986 } else {
1987 WRITE_WARNINGF(TL("Not joining tram edge '%' with % lanes."), item.second->getID(), item.second->getNumLanes());
1988 }
1989 } else if ((permissions & (SVC_PASSENGER | SVC_BUS)) != 0) {
1990 targetEdges.push_back(item.second);
1991 }
1992 }
1993 if (tramEdges.empty() || targetEdges.empty()) {
1994 return 0;
1995 }
1996 int numJoined = 0;
1997 NamedRTree tramTree;
1998 for (NBEdge* const edge : tramEdges) {
1999 const Boundary& bound = edge->getGeometry().getBoxBoundary();
2000 float min[2] = { static_cast<float>(bound.xmin()), static_cast<float>(bound.ymin()) };
2001 float max[2] = { static_cast<float>(bound.xmax()), static_cast<float>(bound.ymax()) };
2002 tramTree.Insert(min, max, edge);
2003 }
2004 // {targetEdge, laneIndex : tramEdge}
2005 std::map<std::pair<NBEdge*, int>, NBEdge*, MinLaneComparatorIdLess> matches;
2006
2007 for (NBEdge* const edge : targetEdges) {
2008 Boundary bound = edge->getGeometry().getBoxBoundary();
2009 bound.grow(maxDist + edge->getTotalWidth());
2010 float min[2] = { static_cast<float>(bound.xmin()), static_cast<float>(bound.ymin()) };
2011 float max[2] = { static_cast<float>(bound.xmax()), static_cast<float>(bound.ymax()) };
2012 std::set<const Named*> near;
2013 Named::StoringVisitor visitor(near);
2014 tramTree.Search(min, max, visitor);
2015 // the nearby set is actually just re-sorting according to the id to make the tests comparable
2016 std::set<NBEdge*, ComparatorIdLess> nearby;
2017 for (const Named* namedEdge : near) {
2018 nearby.insert(const_cast<NBEdge*>(static_cast<const NBEdge*>(namedEdge)));
2019 }
2020 for (NBEdge* const tramEdge : nearby) {
2021 // find a continous stretch of tramEdge that runs along one of the lanes of the road edge
2022 PositionVector tramShape = tramEdge->getGeometry();
2023 if (tramEdge->getToNode() == edge->getToNode()) {
2024 tramShape.extrapolate(tramShape.back().distanceTo2D(edge->getGeometry().back()), false, true);
2025 }
2026 double minEdgeDist = maxDist + 1;
2027 int minLane = -1;
2028 // find the lane where the maximum distance from the tram geometry
2029 // is minimal and within maxDist
2030 for (int i = 0; i < edge->getNumLanes(); i++) {
2031 double maxLaneDist = -1;
2032 if ((edge->getPermissions(i) & (SVC_PASSENGER | SVC_BUS)) != 0) {
2033 const PositionVector& laneShape = edge->getLaneShape(i);
2034 for (Position pos : laneShape) {
2035 const double dist = tramShape.distance2D(pos, false);
2036#ifdef DEBUG_JOIN_TRAM
2037 //if (edge->getID() == "106838214#1") {
2038 // std::cout << " edge=" << edge->getID() << " tramEdge=" << tramEdge->getID() << " lane=" << i << " pos=" << pos << " dist=" << dist << "\n";
2039 //}
2040#endif
2041 if (dist == GeomHelper::INVALID_OFFSET || dist > maxDist) {
2042 maxLaneDist = -1;
2043 break;
2044 }
2045 maxLaneDist = MAX2(maxLaneDist, dist);
2046 }
2047 if (maxLaneDist >= 0 && maxLaneDist < minEdgeDist) {
2048 minEdgeDist = maxLaneDist;
2049 minLane = i;
2050 }
2051 }
2052 }
2053 if (minLane >= 0) {
2054 // edge could run in the wrong direction and still fit the threshold we check the angle as well
2055 const PositionVector& laneShape = edge->getLaneShape(minLane);
2056 const double offset1 = tramShape.nearest_offset_to_point2D(laneShape.front(), false);
2057 const double offset2 = tramShape.nearest_offset_to_point2D(laneShape.back(), false);
2058 Position p1 = tramShape.positionAtOffset2D(offset1);
2059 Position p2 = tramShape.positionAtOffset2D(offset2);
2060 double tramAngle = GeomHelper::legacyDegree(p1.angleTo2D(p2), true);
2061 double laneAngle = GeomHelper::legacyDegree(laneShape[0].angleTo2D(laneShape[-1]), true);
2062 const double angleMismatch = MIN2(GeomHelper::getMinAngleDiff(tramAngle, edge->getTotalAngle()),
2063 GeomHelper::getMinAngleDiff(tramAngle, laneAngle));
2064 bool angleOK = angleMismatch < JOIN_TRAM_MAX_ANGLE;
2065 if (angleOK && offset2 > offset1) {
2066 std::pair<NBEdge*, int> key = std::make_pair(edge, minLane);
2067 if (matches.count(key) == 0) {
2068 matches[key] = tramEdge;
2069 } else {
2070 WRITE_WARNINGF(TL("Ambiguous tram edges '%' and '%' for lane '%'."), matches[key]->getID(), tramEdge->getID(), edge->getLaneID(minLane));
2071 }
2072#ifdef DEBUG_JOIN_TRAM
2073 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";
2074#endif
2075 }
2076 }
2077 }
2078 }
2079 if (matches.size() == 0) {
2080 return 0;
2081 }
2082 const bool origNames = OptionsCont::getOptions().getBool("output.original-names");
2083 // find continous runs of matched edges for each tramEdge
2084 for (NBEdge* tramEdge : tramEdges) {
2085 std::vector<std::pair<double, std::pair<NBEdge*, int> > > roads;
2086 for (auto item : matches) {
2087 if (item.second == tramEdge) {
2088 NBEdge* road = item.first.first;
2089 int laneIndex = item.first.second;
2090 const PositionVector& laneShape = road->getLaneShape(laneIndex);
2091 double tramPos = tramEdge->getGeometry().nearest_offset_to_point2D(laneShape.front(), false);
2092 //std::cout << " road=" << road->getID() << " tramEdge=" << tramEdge->getID() << " tramShape=" << tramEdge->getGeometry() << " laneFront=" << laneShape.front() << " tramPos=" << tramPos << "\n";
2093 roads.push_back(std::make_pair(tramPos, item.first));
2094 }
2095 }
2096 if (roads.size() != 0) {
2097
2098 sort(roads.begin(), roads.end());
2099#ifdef DEBUG_JOIN_TRAM
2100 std::cout << " tramEdge=" << tramEdge->getID() << " roads=";
2101 for (auto item : roads) {
2102 std::cout << item.second.first->getLaneID(item.second.second) << ",";
2103 }
2104 std::cout << " offsets=";
2105 for (auto item : roads) {
2106 std::cout << item.first << ",";
2107 }
2108 std::cout << "\n";
2109#endif
2110 // merge tramEdge into road lanes
2111 EdgeVector replacement;
2112 double pos = 0;
2113 int tramPart = 0;
2114 std::string tramEdgeID = tramEdge->getID();
2115 NBNode* tramFrom = tramEdge->getFromNode();
2116 PositionVector tramShape = tramEdge->getGeometry();
2117 const double tramLength = tramShape.length();
2118 EdgeVector incoming = tramFrom->getIncomingEdges();
2119 bool erasedLast = false;
2120 for (const auto& item : roads) {
2121 const double gap = item.first - pos;
2122 NBEdge* road = item.second.first;
2123 int laneIndex = item.second.second;
2124 if (gap >= JOIN_TRAM_MIN_LENGTH && road->getFromNode() != tramEdge->getFromNode()) {
2125#ifdef DEBUG_JOIN_TRAM
2126 std::cout << " splitting tramEdge=" << tramEdge->getID() << " at " << item.first << " (gap=" << gap << ")\n";
2127#endif
2128 const std::string firstPartID = tramEdgeID + "#" + toString(tramPart++);
2129 splitAt(dc, tramEdge, gap, road->getFromNode(), firstPartID, tramEdgeID, 1, 1);
2130 tramEdge = retrieve(tramEdgeID); // second part;
2131 NBEdge* firstPart = retrieve(firstPartID);
2132 firstPart->invalidateConnections(true);
2133 incoming.clear();
2134 incoming.push_back(firstPart);
2135 replacement.push_back(firstPart);
2136 }
2137 pos = item.first + road->getGeometry().length();
2138 numJoined++;
2139 replacement.push_back(road);
2140 // merge section of tramEdge into road lane
2141 if (road->getToNode() != tramEdge->getToNode() && (tramLength - pos) >= JOIN_TRAM_MIN_LENGTH) {
2142 tramEdge->reinitNodes(road->getToNode(), tramEdge->getToNode());
2143 tramEdge->setGeometry(tramShape.getSubpart(pos, tramShape.length()));
2144 erasedLast = false;
2145#ifdef DEBUG_JOIN_TRAM
2146 std::cout << " shorted tramEdge=" << tramEdge->getID() << " (joined with roadEdge=" << road->getID() << "\n";
2147#endif
2148 } else {
2149#ifdef DEBUG_JOIN_TRAM
2150 std::cout << " erased tramEdge=" << tramEdge->getID() << "\n";
2151#endif
2152 extract(dc, tramEdge, true);
2153 erasedLast = true;
2154 }
2155 road->setPermissions(road->getPermissions(laneIndex) | SVC_TRAM, laneIndex);
2156 if (origNames) {
2157 road->setOrigID(tramEdgeID, true, laneIndex);
2158 }
2159 for (NBEdge* in : incoming) {
2160 if (isTram(in->getPermissions()) && !in->isConnectedTo(road)) {
2161 if (in->getFromNode() != road->getFromNode()) {
2162 in->reinitNodes(in->getFromNode(), road->getFromNode());
2163 } else {
2164 extract(dc, in, true);
2165#ifdef DEBUG_JOIN_TRAM
2166 std::cout << " erased incoming tramEdge=" << in->getID() << "\n";
2167#endif
2168 }
2169 }
2170 }
2171 incoming.clear();
2172 }
2173 NBEdge* lastRoad = roads.back().second.first;
2174 if (erasedLast) {
2175 // copy to avoid concurrent modification
2176 auto outEdges = tramEdge->getToNode()->getOutgoingEdges();
2177 for (NBEdge* out : outEdges) {
2178 if (isTram(out->getPermissions()) && !lastRoad->isConnectedTo(out)) {
2179 if (lastRoad->getToNode() != out->getToNode()) {
2180 out->reinitNodes(lastRoad->getToNode(), out->getToNode());
2181 } else {
2182 extract(dc, out, true);
2183#ifdef DEBUG_JOIN_TRAM
2184 std::cout << " erased outgoing tramEdge=" << out->getID() << "\n";
2185#endif
2186
2187 }
2188 }
2189 }
2190 } else {
2191 replacement.push_back(tramEdge);
2192 }
2193 // update ptstops and ptlines
2194 sc.replaceEdge(tramEdgeID, replacement);
2195 lc.replaceEdge(tramEdgeID, replacement);
2196 }
2197 }
2198
2199 return numJoined;
2200}
2201
2202
2205 EdgeVector result;
2206 for (auto item : myEdges) {
2207 item.second->setNumericalID((int)result.size());
2208 result.push_back(item.second);
2209 }
2210 return result;
2211}
2212
2215 EdgeVector all = getAllEdges();
2216 return RouterEdgeVector(all.begin(), all.end());
2217}
2218
2219bool
2221 bool ok = true;
2222 for (const auto& item : myEdges) {
2223 NBEdge* e = item.second;
2224 if (nc.retrieve(e->getFromNode()->getID()) == nullptr) {
2225 WRITE_ERRORF(TL("Edge's '%' from-node '%' is not known."), e->getID(), e->getFromNode()->getID());
2226 ok = false;
2227 }
2228 if (nc.retrieve(e->getToNode()->getID()) == nullptr) {
2229 WRITE_ERRORF(TL("Edge's '%' to-node '%' is not known."), e->getID(), e->getToNode()->getID());
2230 ok = false;
2231 }
2232
2233 }
2234 return ok;
2235}
2236
2237
2238void
2240 for (auto item : myEdges) {
2241 NBEdge* e = item.second;
2242 if (e->hasLoadedLength() && myWasSplit.count(e) != 0) {
2243 // subtract half the length of the longest incoming / outgoing connection
2244 double maxLengthOut = 0;
2245 for (const NBEdge::Connection& c : e->getConnections()) {
2246 maxLengthOut = MAX2(maxLengthOut, c.length + c.viaLength);
2247 }
2248 double maxLengthIn = 0;
2249 for (const NBEdge* in : e->getIncomingEdges()) {
2250 for (const NBEdge::Connection& c : in->getConnectionsFromLane(-1, e, -1)) {
2251 maxLengthIn = MAX2(maxLengthIn, c.length + c.viaLength);
2252 }
2253 }
2254 e->setLoadedLength(MAX2(POSITION_EPS, e->getLoadedLength() - (maxLengthIn + maxLengthOut) / 2));
2255 }
2256 }
2257}
2258
2259void
2261 for (auto item : myEdges) {
2262 item.second->computeAngle();
2263 }
2264}
2265
2266
2267std::set<std::string>
2269 std::set<std::string> result;
2270 for (auto item : myEdges) {
2271 if (item.second->getTypeID() != "") {
2272 result.insert(item.second->getTypeID());
2273 }
2274 }
2275 return result;
2276}
2277
2278
2279int
2281 EdgeSet toRemove;
2282 for (const auto& item : myEdges) {
2283 NBEdge* edge = item.second;
2284 // remove edges which allow a speed below a set one (set using "keep-edges.min-speed")
2285 // explicit whitelist overrides removal
2286 if (edge->getSpeed() < myEdgesMinSpeed && myEdges2Keep.count(edge->getID()) == 0) {
2287 toRemove.insert(edge);
2288 }
2289 }
2290 const int numRemoved = (int)toRemove.size();
2291 for (NBEdge* edge : toRemove) {
2292 erase(dc, edge);
2293 }
2294 return numRemoved;
2295}
2296
2297
2298int
2300 EdgeSet toRemove;
2301 for (const auto& item : myEdges) {
2302 NBEdge* edge = item.second;
2303 // check whether the edge shall be removed because it does not allow any of the wished classes
2304 // explicit whitelist overrides removal
2305 if (myVehicleClasses2Keep != 0 && (myVehicleClasses2Keep & edge->getPermissions()) == 0 && myEdges2Keep.count(edge->getID()) == 0) {
2306 toRemove.insert(edge);
2307 }
2308 // check whether the edge shall be removed due to allowing unwished classes only
2309 // explicit whitelist overrides removal
2311 toRemove.insert(edge);
2312 }
2313 }
2314 const int numRemoved = (int)toRemove.size();
2315 for (NBEdge* edge : toRemove) {
2316 erase(dc, edge);
2317 }
2318 return numRemoved;
2319}
2320
2321
2322int
2324 EdgeSet toRemove;
2325 for (auto item : myEdges) {
2326 NBEdge* const edge = item.second;
2327 std::vector<int> indices;
2328 int idx = 0;
2329 for (const auto& lane : edge->getLanes()) {
2330 if (lane.width != NBEdge::UNSPECIFIED_WIDTH && lane.width < minWidth) {
2331 indices.push_back(idx);
2332 }
2333 idx++;
2334 }
2335 if ((int)indices.size() == edge->getNumLanes()) {
2336 toRemove.insert(edge);
2337 } else {
2338 std::reverse(indices.begin(), indices.end());
2339 for (const int i : indices) {
2340 edge->deleteLane(i, false, true);
2341 }
2342 }
2343 }
2344 int numRemoved = 0;
2345 for (NBEdge* edge : toRemove) {
2346 // explicit whitelist overrides removal
2347 if (myEdges2Keep.size() == 0 || myEdges2Keep.count(edge->getID()) == 0) {
2348 extract(dc, edge);
2349 numRemoved++;
2350 }
2351 }
2352 return numRemoved;
2353}
2354
2355
2356int
2357NBEdgeCont::attachRemoved(NBNodeCont& nc, NBDistrictCont& dc, const double maxDist) {
2358 int numSplit = 0;
2359 std::map<std::string, std::vector<std::string> > node2edge;
2360 for (auto item : myEdges) {
2361 if (item.second->hasParameter(SUMO_PARAM_REMOVED_NODES)) {
2362 for (std::string& nodeID : StringTokenizer(item.second->getParameter(SUMO_PARAM_REMOVED_NODES)).getVector()) {
2363 node2edge[nodeID].push_back(item.first);
2364 }
2365 }
2366 }
2367 for (auto item : nc) {
2368 NBNode* n = item.second;
2369 auto itRN = node2edge.find(n->getID());
2370 if (itRN != node2edge.end()) {
2371 bool rebuildConnections = false;
2372 // make a copy because we modify the original
2373 std::vector<std::string> edgeIDs = itRN->second;
2374 for (const std::string& eID : edgeIDs) {
2375 NBEdge* edge = retrieve(eID);
2376 assert(edge != nullptr);
2377 const double dist = edge->getGeometry().distance2D(n->getPosition(), true);
2378 if (dist != GeomHelper::INVALID_OFFSET && dist <= maxDist) {
2379 std::string idAfter = edge->getID();
2380 int index = 1;
2381 size_t spos = idAfter.find("#");
2382 if (spos != std::string::npos && spos > 1) {
2383 idAfter = idAfter.substr(0, spos);
2384 }
2385 while (retrieve(idAfter + "#" + toString(index), true) != nullptr) {
2386 index++;
2387 }
2388 idAfter += "#" + toString(index);
2389 const bool ok = splitAt(dc, edge, n, edge->getID(), idAfter, edge->getNumLanes(), edge->getNumLanes());
2390 if (ok) {
2391 rebuildConnections = true;
2392 numSplit++;
2393 NBEdge* secondEdge = retrieve(eID); // original was extracted on splitting
2394 for (std::string& nodeID : StringTokenizer(secondEdge->getParameter(SUMO_PARAM_REMOVED_NODES)).getVector()) {
2395 node2edge[nodeID].push_back(idAfter);
2396 }
2397 }
2398 }
2399 }
2400 if (rebuildConnections) {
2401 for (NBEdge* e : n->getIncomingEdges()) {
2402 e->invalidateConnections(true);
2403 }
2404 }
2405 }
2406 }
2407 return numSplit;
2408}
2409
2410/****************************************************************************/
#define DEG2RAD(x)
Definition GeomHelper.h:35
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:299
#define WRITE_ERRORF(...)
Definition MsgHandler.h:308
#define WRITE_ERROR(msg)
Definition MsgHandler.h:307
#define WRITE_WARNING(msg)
Definition MsgHandler.h:298
#define TL(string)
Definition MsgHandler.h:316
#define TLF(string,...)
Definition MsgHandler.h:318
std::set< NBEdge * > EdgeSet
container for unique edges
Definition NBCont.h:50
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition NBCont.h:42
KeepClear
keepClear status of connections
Definition NBCont.h:58
@ KEEPCLEAR_UNSPECIFIED
Definition NBCont.h:61
std::vector< NBRouterEdge * > RouterEdgeVector
Definition NBCont.h:43
#define JOIN_TRAM_MIN_LENGTH
#define JOIN_TRAM_MAX_ANGLE
static bool hasStraightPriorityApproach(const EdgeVector &loop)
#define DEBUG_EDGE_ID
const SVCPermissions SVCAll
all VClasses are allowed
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permissions is a (exclusive) railway edge.
bool isTram(SVCPermissions permissions)
Returns whether an edge with the given permissions is a tram edge.
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_TRAM
vehicle is a light rail
@ SVC_PUBLIC_CLASSES
public transport
@ SVC_BUS
vehicle is a bus
@ SVC_PEDESTRIAN
pedestrian
const std::string SUMO_PARAM_ORIGID
const std::string SUMO_PARAM_REMOVED_NODES
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
bool gDebugFlag1
global utility flags for debugging
Definition StdDefs.cpp:44
const double SUMO_const_laneWidth
Definition StdDefs.h:52
T MIN2(T a, T b)
Definition StdDefs.h:80
const double SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
Definition StdDefs.h:62
T MAX2(T a, T b)
Definition StdDefs.h:86
const double SUMO_const_halfLaneWidth
Definition StdDefs.h:53
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
double ymin() const
Returns minimum y-coordinate.
Definition Boundary.cpp:127
double xmin() const
Returns minimum x-coordinate.
Definition Boundary.cpp:115
Boundary & grow(double by)
extends the boundary by the given amount
Definition Boundary.cpp:340
bool overlapsWith(const AbstractPoly &poly, double offset=0) const
Returns whether the boundary overlaps with the given polygon.
Definition Boundary.cpp:194
double ymax() const
Returns maximum y-coordinate.
Definition Boundary.cpp:133
double xmax() const
Returns maximum x-coordinate.
Definition Boundary.cpp:121
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation.
static GeoConvHelper & getLoaded()
the coordinate transformation that was loaded fron an input file
static PositionVector parseShapeReporting(const std::string &shpdef, const std::string &objecttype, const char *objectid, bool &ok, bool allowEmpty, bool report=true)
Builds a PositionVector from a string representation, reporting occurred errors.
static const double INVALID_OFFSET
a value to signify offsets outside the range of [0, Line.length()]
Definition GeomHelper.h:50
static double nearest_offset_on_line_to_point2D(const Position &lineStart, const Position &lineEnd, const Position &p, bool perpendicular=true)
static double legacyDegree(const double angle, const bool positive=false)
static double getMinAngleDiff(double angle1, double angle2)
Returns the minimum distance (clockwise/counter-clockwise) between both angles.
std::string getNext()
Returns the next id.
static void nextCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
A container for districts.
void removeFromSinksAndSources(NBEdge *const e)
Removes the given edge from the lists of sources and sinks in all stored districts.
Sorts splits by their position (increasing)
Definition NBEdgeCont.h:805
void patchRoundabouts(NBEdge *orig, NBEdge *part1, NBEdge *part2, std::set< EdgeSet > &roundabouts)
fix roundabout information after splitting an edge
void computeEdgeShapes(double smoothElevationThreshold=-1)
Computes the shapes of all edges stored in the container.
NBEdge * getByID(const std::string &edgeID) const
Returns the edge with id if it exists.
const std::set< EdgeSet > getRoundabouts() const
Returns the determined roundabouts.
void computeEdge2Edges(bool noLeftMovers)
Computes for each edge the approached edges.
int guessRoundabouts()
Determines which edges belong to roundabouts and increases their priority.
bool myNeedGeoTransformedPruningBoundary
whether a geo transform has been applied to the pruning boundary
Definition NBEdgeCont.h:793
~NBEdgeCont()
Destructor.
void sortOutgoingLanesConnections()
Sorts all lanes of all edges within the container by their direction.
void addRoundabout(const EdgeSet &roundabout)
add user specified roundabout
std::set< EdgeSet > myRoundabouts
Edges marked as belonging to a roundabout by the user (each EdgeVector is a roundabout)
Definition NBEdgeCont.h:797
void appendRailwayTurnarounds(const NBPTStopCont &sc)
Appends turnarounds to all bidiRail edges with stops.
std::set< std::string > myEdges2Remove
Set of ids of edges which shall explicitly be removed.
Definition NBEdgeCont.h:775
std::set< std::string > myIgnoredEdges
The ids of ignored edges.
Definition NBEdgeCont.h:755
void updateAllChangeRestrictions(SVCPermissions ignoring)
modify all restrictions on lane changing for edges and connections
double myEdgesMinSpeed
The minimum speed an edge may have in order to be kept (default: -1)
Definition NBEdgeCont.h:766
void recheckPostProcessConnections()
Try to set any stored connections.
void extract(NBDistrictCont &dc, NBEdge *edge, bool remember=false)
Removes the given edge from the container like erase but does not delete it.
void processSplits(NBEdge *e, std::vector< Split > splits, NBNodeCont &nc, NBDistrictCont &dc, NBTrafficLightLogicCont &tlc)
process splits
EdgeVector getAllEdges() const
return all edges
void erase(NBDistrictCont &dc, NBEdge *edge)
Removes the given edge from the container (deleting it)
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
std::set< std::string > myTypes2Keep
Set of edges types which shall be kept.
Definition NBEdgeCont.h:784
void recheckLanes()
Rechecks whether all lanes have a successor for each of the stored edges.
NBEdge * getOppositeByID(const std::string &edgeID) const
Returns the edge with negated id if it exists.
void checkGeometries(const double maxAngle, bool fixAngle, const double minRadius, bool fix, bool fixRailways, bool silent=false)
EdgeCont myExtractedEdges
The extracted edges which are kept for reference.
Definition NBEdgeCont.h:749
std::string createUnusedID(const std::string &base, const std::string &sep)
if base is an existing edge id, find a unused id of the form base + sep + INT
void reduceGeometries(const double minDist)
void recheckLaneSpread()
Rechecks whether the lane spread is proper.
bool ignoreFilterMatch(NBEdge *edge)
Returns true if this edge matches one of the removal criteria.
void removeRoundabout(const NBNode *node)
remove roundabout that contains the given node
void cleanupRoundabouts()
void splitGeometry(NBDistrictCont &dc, NBNodeCont &nc)
Splits edges into multiple if they have a complex geometry.
void addPostProcessConnection(const std::string &from, int fromLane, const std::string &to, int toLane, bool mayDefinitelyPass, KeepClear keepClear, double contPos, double visibility, double speed, double friction, double length, const PositionVector &customShape, bool uncontrolled, bool warnOnly, SVCPermissions permissions=SVC_UNSPECIFIED, bool indirectLeft=false, const std::string &edgeType="", SVCPermissions changeLeft=SVC_UNSPECIFIED, SVCPermissions changeRight=SVC_UNSPECIFIED)
Adds a connection which could not be set during loading.
std::set< std::string > getUsedTypes() const
return all edge types in used
void computeLanes2Edges()
Computes for each edge which lanes approach the next edges.
int extractRoundabouts()
Determines which edges have been marked as roundabouts and stores them internally.
NBEdge * retrievePossiblySplit(const std::string &id, bool downstream) const
Tries to retrieve an edge, even if it is splitted.
RouterEdgeVector getAllRouterEdges() const
return all router edges
std::set< const NBEdge * > myWasSplit
the edges that were created as result of splitting
Definition NBEdgeCont.h:760
void rename(NBEdge *edge, const std::string &newID)
Renames the edge. Throws exception if newID already exists.
int joinTramEdges(NBDistrictCont &dc, NBPTStopCont &sc, NBPTLineCont &lc, double maxDist)
join tram edges into adjacent lanes
bool hasPostProcessConnection(const std::string &from, const std::string &to="")
add post process connections
EdgeCont myEdges
The instance of the dictionary (id->edge)
Definition NBEdgeCont.h:746
int removeUnwishedEdges(NBDistrictCont &dc)
Removes unwished edges (not in keep-edges)
std::set< std::string > myEdges2Keep
Set of ids of edges which shall explicitly be kept.
Definition NBEdgeCont.h:772
NBTypeCont & myTypeCont
The network builder; used to obtain type information.
Definition NBEdgeCont.h:636
void generateStreetSigns()
assigns street signs to edges based on toNode types
void clearControllingTLInformation() const
Clears information about controlling traffic lights for all connenections of all edges.
std::set< EdgeSet > myGuessedRoundabouts
Edges marked as belonging to a roundabout after guessing.
Definition NBEdgeCont.h:800
void computeAngles()
compute all edge angles
void clear()
Deletes all edges.
void guessOpposites()
Sets opposite lane information for geometrically close edges.
void markRoundabouts()
mark edge priorities and prohibit turn-arounds for all roundabout edges
std::set< std::string > myTypes2Remove
Set of edges types which shall be removed.
Definition NBEdgeCont.h:787
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
void removeRoundaboutEdges(const EdgeSet &toRemove)
remove edges from all stored roundabouts
PositionVector myPruningBoundary
Boundary within which an edge must be located in order to be kept.
Definition NBEdgeCont.h:790
int joinLanes(SVCPermissions perms)
join adjacent lanes with the given permissions
void checkOverlap(double threshold, double zThreshold) const
check whether edges overlap
SVCPermissions myVehicleClasses2Remove
Set of vehicle types which need not be supported (edges which allow ONLY these are removed)
Definition NBEdgeCont.h:781
int guessSpecialLanes(SUMOVehicleClass svc, double width, double minSpeed, double maxSpeed, bool fromPermissions, const std::string &excludeOpt, NBTrafficLightLogicCont &tlc)
add sidwalks to edges within the given limits or permissions and return the number of edges affected
EdgeVector getGeneratedFrom(const std::string &id) const
Returns the edges which have been built by splitting the edge of the given id.
void appendTurnarounds(bool noTLSControlled, bool noFringe, bool onlyDeadends, bool onlyTurnlane, bool noGeometryLike)
Appends turnarounds to all edges stored in the container.
SVCPermissions myVehicleClasses2Keep
Set of vehicle types which must be allowed on edges in order to keep them.
Definition NBEdgeCont.h:778
void computeLaneShapes()
Computes the shapes of all lanes of all edges stored in the container.
void joinSameNodeConnectingEdges(NBDistrictCont &dc, NBTrafficLightLogicCont &tlc, EdgeVector edges)
Joins the given edges because they connect the same nodes.
std::map< std::string, NBEdge * > EdgeCont
The type of the dictionary where an edge may be found by its id.
Definition NBEdgeCont.h:743
void addPrefix(const std::string &prefix)
add prefix to all edges
void fixSplitCustomLength()
adapt custom lengths of split edges to account for intersection size
std::map< const NBEdge *, std::pair< NBEdge *, NBEdge * > > myEdgesSplit
the number of splits of edges during the building
Definition NBEdgeCont.h:758
NBEdge * getSplitBase(const std::string &edgeID) const
std::map< std::string, std::vector< PostProcessConnection > > myConnections
The list of connections to recheck.
Definition NBEdgeCont.h:740
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
NBEdgeCont(NBTypeCont &tc)
Constructor.
std::set< NBEdge * > myEdgeCemetery
The edges which got extracted twice but may still be referenced somewhere TODO smart_ptr?
Definition NBEdgeCont.h:752
bool checkConsistency(const NBNodeCont &nc)
ensure that all edges have valid nodes
static double formFactor(const EdgeVector &loopEdges)
compute the form factor for a loop of edges
int removeLanesByWidth(NBDistrictCont &dc, const double minWidth)
bool splitAt(NBDistrictCont &dc, NBEdge *edge, NBNode *node)
Splits the edge at the position nearest to the given node.
std::vector< std::string > getAllNames() const
Returns all ids of known edges.
int removeEdgesBySpeed(NBDistrictCont &dc)
return number of edges removed
int remapIDs(bool numericaIDs, bool reservedIDs, bool keptIDs, const std::string &prefix, NBPTStopCont &sc)
remap node IDs accoring to options –numerical-ids and –reserved-ids
void checkGrade(double threshold) const
check whether edges are to steep
int attachRemoved(NBNodeCont &nc, NBDistrictCont &dc, const double maxDist)
return number of edges split
int removeEdgesByPermissions(NBDistrictCont &dc)
bool myRemoveEdgesAfterLoading
Whether edges shall be joined and patched first, then removed.
Definition NBEdgeCont.h:769
The representation of a single edge during network building.
Definition NBEdge.h:92
NBEdge * guessOpposite(bool reguess=false)
set oppositeID and return opposite edge if found
Definition NBEdge.cpp:5070
double getLength() const
Returns the computed length of the edge.
Definition NBEdge.h:599
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition NBEdge.cpp:4545
const std::vector< Connection > & getConnections() const
Returns the connections.
Definition NBEdge.h:1047
void setPermissions(SVCPermissions permissions, int lane=-1)
set allowed/disallowed classes for the given lane or for all lanes if -1 is given
Definition NBEdge.cpp:4508
@ ROUNDABOUT
Definition NBEdge.h:387
double getLoadedLength() const
Returns the length was set explicitly or the computed length if it wasn't set.
Definition NBEdge.h:608
void recheckOpposite(const NBEdgeCont &ec, bool fixOppositeLengths)
recheck whether all opposite and bidi settings are consistent
Definition NBEdge.cpp:3202
void setSpeed(int lane, double speed)
set lane specific speed (negative lane implies set for all lanes)
Definition NBEdge.cpp:4460
NBNode * getToNode() const
Returns the destination node of the edge.
Definition NBEdge.h:552
PositionVector getCCWBoundaryLine(const NBNode &n) const
get the outer boundary of this edge when going counter-clock-wise around the given node
Definition NBEdge.cpp:3962
static const double UNSPECIFIED_FRICTION
unspecified lane friction
Definition NBEdge.h:355
void incLaneNo(int by)
increment lane
Definition NBEdge.cpp:4241
Lane & getLaneStruct(int lane)
Definition NBEdge.h:1459
void setAverageLengthWithOpposite(double val)
patch average lane length in regard to the opposite edge
Definition NBEdge.cpp:4565
void disallowVehicleClass(int lane, SUMOVehicleClass vclass)
set disallowed class for the given lane or for all lanes if -1 is given
Definition NBEdge.cpp:4304
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition NBEdge.h:789
LaneSpreadFunction getLaneSpreadFunction() const
Returns how this edge's lanes' lateral offset is computed.
Definition NBEdge.cpp:1022
bool isBidiRail(bool ignoreSpread=false) const
whether this edge is part of a bidirectional railway
Definition NBEdge.cpp:773
void dismissVehicleClassInformation()
dimiss vehicle class information
Definition NBEdge.cpp:4571
EdgeBuildingStep getStep() const
The building step of this edge.
Definition NBEdge.h:641
LaneSpreadFunction myLaneSpreadFunction
The information about how to spread the lanes.
Definition NBEdge.h:1822
bool hasLoadedLength() const
Returns whether a length was set explicitly.
Definition NBEdge.h:618
bool addEdge2EdgeConnection(NBEdge *dest, bool overrideRemoval=false, SVCPermissions permission=SVC_UNSPECIFIED)
Adds a connection to another edge.
Definition NBEdge.cpp:1121
bool addLane2LaneConnection(int fromLane, NBEdge *dest, int toLane, Lane2LaneInfoType type, bool mayUseSameDestination=false, bool mayDefinitelyPass=false, KeepClear keepClear=KEEPCLEAR_UNSPECIFIED, double contPos=UNSPECIFIED_CONTPOS, double visibility=UNSPECIFIED_VISIBILITY_DISTANCE, double speed=UNSPECIFIED_SPEED, double friction=UNSPECIFIED_FRICTION, double length=myDefaultConnectionLength, const PositionVector &customShape=PositionVector::EMPTY, const bool uncontrolled=UNSPECIFIED_CONNECTION_UNCONTROLLED, SVCPermissions permissions=SVC_UNSPECIFIED, const bool indirectLeft=false, const std::string &edgeType="", SVCPermissions changeLeft=SVC_UNSPECIFIED, SVCPermissions changeRight=SVC_UNSPECIFIED, bool postProcess=false)
Adds a connection between the specified this edge's lane and an approached one.
Definition NBEdge.cpp:1157
void setDistance(double distance)
set kilometrage at start of edge (negative value implies couting down along the edge)
Definition NBEdge.h:1425
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition NBEdge.h:736
@ LANES2LANES_DONE
Lanes to lanes - relationships are computed; no recheck is necessary/wished.
@ LANES2LANES_USER
Lanes to lanes - relationships are loaded; no recheck is necessary/wished.
double getSpeed() const
Returns the speed allowed on this edge.
Definition NBEdge.h:625
NBNode * myTo
Definition NBEdge.h:1771
const std::string & getID() const
Definition NBEdge.h:1559
double getDistance() const
get distance
Definition NBEdge.h:685
void setLaneWidth(int lane, double width)
set lane specific width (negative lane implies set for all lanes)
Definition NBEdge.cpp:4331
void setLaneSpreadFunction(LaneSpreadFunction spread)
(Re)sets how the lanes lateral offset shall be computed
Definition NBEdge.cpp:1016
std::vector< Lane > myLanes
Lane information.
Definition NBEdge.h:1839
int getNumLanes() const
Returns the number of lanes.
Definition NBEdge.h:526
void setFriction(int lane, double friction)
set lane specific friction (negative lane implies set for all lanes)
Definition NBEdge.cpp:4476
static const double UNSPECIFIED_CONTPOS
unspecified internal junction position
Definition NBEdge.h:358
void setRoundaboutGuessExcluded(bool excluded)
Definition NBEdge.h:1439
void addRestrictedLane(double width, SUMOVehicleClass vclass)
add a lane of the given width, restricted to the given class and shift existing connections
Definition NBEdge.cpp:4773
void removeFromConnections(NBEdge *toEdge, int fromLane=-1, int toLane=-1, bool tryLater=false, const bool adaptToLaneRemoval=false, const bool keepPossibleTurns=false)
Removes the specified connection(s)
Definition NBEdge.cpp:1474
void invalidateConnections(bool reallowSetting=false)
invalidate current connections of edge
Definition NBEdge.cpp:1555
double getTotalWidth() const
Returns the combined width of all lanes of this edge.
Definition NBEdge.cpp:4383
static const double UNSPECIFIED_VISIBILITY_DISTANCE
unspecified foe visibility for connections
Definition NBEdge.h:361
bool isConnectedTo(const NBEdge *e, const bool ignoreTurnaround=false) const
Returns the information whethe a connection to the given edge has been added (or computed)
Definition NBEdge.cpp:1355
void addSign(NBSign sign)
add Sign
Definition NBEdge.h:1491
void deleteLane(int index, bool recompute, bool shiftIndices)
delete lane
Definition NBEdge.cpp:4252
void moveOutgoingConnectionsFrom(NBEdge *e, int laneOff)
move outgoing connection
Definition NBEdge.cpp:3838
std::string getLaneID(int lane) const
get lane ID
Definition NBEdge.cpp:4183
@ USER
The connection was given by the user.
@ VALIDATED
The connection was computed and validated.
@ COMPUTED
The connection was computed.
double getStartAngle() const
Returns the angle at the start of the edge (relative to the node shape center) The angle is computed ...
Definition NBEdge.h:561
bool setConnection(int lane, NBEdge *destEdge, int destLane, Lane2LaneInfoType type, bool mayUseSameDestination=false, bool mayDefinitelyPass=false, KeepClear keepClear=KEEPCLEAR_UNSPECIFIED, double contPos=UNSPECIFIED_CONTPOS, double visibility=UNSPECIFIED_VISIBILITY_DISTANCE, double speed=UNSPECIFIED_SPEED, double friction=UNSPECIFIED_FRICTION, double length=myDefaultConnectionLength, const PositionVector &customShape=PositionVector::EMPTY, const bool uncontrolled=UNSPECIFIED_CONNECTION_UNCONTROLLED, SVCPermissions permissions=SVC_UNSPECIFIED, bool indirectLeft=false, const std::string &edgeType="", SVCPermissions changeLeft=SVC_UNSPECIFIED, SVCPermissions changeRight=SVC_UNSPECIFIED, bool postProcess=false)
Adds a connection to a certain lane of a certain edge.
Definition NBEdge.cpp:1210
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
Definition NBEdge.cpp:2161
const std::string & getTypeID() const
get ID of type
Definition NBEdge.h:1187
const std::string & getStreetName() const
Returns the street name of this edge.
Definition NBEdge.h:675
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition NBEdge.h:545
NBEdge * getTurnDestination(bool possibleDestination=false) const
Definition NBEdge.cpp:4174
double getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge's geometry at the given node.
Definition NBEdge.cpp:2187
bool isBidi() const
return whether this edge should be a bidi edge
Definition NBEdge.h:1435
int getPriority() const
Returns the priority of the edge.
Definition NBEdge.h:533
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition NBEdge.h:346
bool hasRestrictedLane(SUMOVehicleClass vclass) const
returns whether any lane already allows the given vclass exclusively
Definition NBEdge.cpp:4762
void copyConnectionsFrom(NBEdge *src)
copy connections from antoher edge
Definition NBEdge.cpp:1670
double getEndAngle() const
Returns the angle at the end of the edge (relative to the node shape center) The angle is computed in...
Definition NBEdge.h:570
void declareConnectionsAsLoaded(EdgeBuildingStep step=EdgeBuildingStep::LANES2LANES_USER)
declares connections as fully loaded. This is needed to avoid recomputing connections if an edge has ...
Definition NBEdge.h:1473
void setEndOffset(int lane, double offset)
set lane specific end-offset (negative lane implies set for all lanes)
Definition NBEdge.cpp:4414
static const double UNSPECIFIED_OFFSET
unspecified lane offset
Definition NBEdge.h:349
bool recheckLanes()
recheck whether all lanes within the edge are all right and optimises the connections once again
Definition NBEdge.cpp:2958
void setOrigID(const std::string origID, const bool append, const int laneIdx=-1)
set origID for all lanes or for a specific lane
Definition NBEdge.cpp:4918
const PositionVector & getLaneShape(int i) const
Returns the shape of the nth lane.
Definition NBEdge.cpp:1010
void setLoadedLength(double val)
set loaded length
Definition NBEdge.cpp:4560
void decLaneNo(int by)
decrement lane
Definition NBEdge.cpp:4272
NBNode * myFrom
The source and the destination node.
Definition NBEdge.h:1771
void setGeometry(const PositionVector &g, bool inner=false)
(Re)sets the edge's geometry
Definition NBEdge.cpp:661
EdgeVector getIncomingEdges() const
Returns the list of incoming edges unsorted.
Definition NBEdge.cpp:1417
static void loadPrefixedIDsFomFile(const std::string &file, const std::string prefix, std::set< std::string > &into)
Add prefixed ids defined in file.
static double relAngle(double angle1, double angle2)
computes the relative angle between the two angles
Definition NBHelpers.cpp:45
static double normRelAngle(double angle1, double angle2)
ensure that reverse relAngles (>=179.999) always count as turnarounds (-180)
Definition NBHelpers.cpp:58
static void loadEdgesFromFile(const std::string &file, std::set< std::string > &into)
Add edge ids defined in file (either ID or edge:ID per line) into the given set.
Definition NBHelpers.cpp:86
static bool transformCoordinates(PositionVector &from, bool includeInBoundary=true, GeoConvHelper *from_srs=nullptr)
Container for nodes during the netbuilding process.
Definition NBNodeCont.h:57
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
void markAsSplit(const NBNode *node)
mark a node as being created form a split
Definition NBNodeCont.h:371
Represents a single node (junction) during network building.
Definition NBNode.h:66
void invalidateOutgoingConnections(bool reallowSetting=false)
invalidate outgoing connections
Definition NBNode.cpp:2145
void removeEdge(NBEdge *edge, bool removeFromConnections=true)
Removes edge from this node and optionally removes connections as well.
Definition NBNode.cpp:2076
const std::set< NBTrafficLightDefinition * > & getControllingTLS() const
Returns the traffic lights that were assigned to this node (The set of tls that control this node)
Definition NBNode.h:347
bool isSimpleContinuation(bool checkLaneNumbers=true, bool checkWidth=false) const
check if node is a simple continuation
Definition NBNode.cpp:561
void recheckVClassConnections(NBEdge *currentOutgoing)
ensure connectivity for all vClasses
Definition NBNode.cpp:1549
SumoXMLNodeType getType() const
Returns the type of this node.
Definition NBNode.h:287
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges (The edges which yield in this node)
Definition NBNode.h:270
void invalidateTLS(NBTrafficLightLogicCont &tlCont, bool addedConnections, bool removedConnections)
causes the traffic light to be computed anew
Definition NBNode.cpp:477
const EdgeVector & getOutgoingEdges() const
Returns this node's outgoing edges (The edges which start at this node)
Definition NBNode.h:275
void replaceOutgoing(NBEdge *which, NBEdge *by, int laneOff)
Replaces occurrences of the first edge within the list of outgoing by the second Connections are rema...
Definition NBNode.cpp:1861
void replaceIncoming(NBEdge *which, NBEdge *by, int laneOff)
Replaces occurrences of the first edge within the list of incoming by the second Connections are rema...
Definition NBNode.cpp:1897
const Position & getPosition() const
Definition NBNode.h:262
const EdgeVector & getEdges() const
Returns all edges which participate in this node (Edges that start or end at this node)
Definition NBNode.h:280
bool typeWasGuessed() const
return whether a priority road turns at this node
Definition NBNode.h:859
RoundaboutType getRoundaboutType() const
Returns roundabout type.
Definition NBNode.h:312
void removeDoubleEdges()
remove duble edges
Definition NBNode.cpp:1965
NBEdge * getConnectionTo(NBNode *n) const
get connection to certain node
Definition NBNode.cpp:2810
void replaceEdge(const std::string &edgeID, const EdgeVector &replacement)
replace the edge with the given edge list in all lines
Container for public transport stops during the net building process.
void replaceEdge(const std::string &edgeID, const std::vector< NBEdge * > &replacement)
replace the edge with the closes edge on the given edge list in all stops
const std::map< std::string, std::shared_ptr< NBPTStop > > & getStops() const
Returns an unmodifiable reference to the stored pt stops.
A class representing a single street sign.
Definition NBSign.h:41
@ SIGN_TYPE_ALLWAY_STOP
Definition NBSign.h:48
@ SIGN_TYPE_YIELD
Definition NBSign.h:46
@ SIGN_TYPE_STOP
Definition NBSign.h:47
@ SIGN_TYPE_PRIORITY
Definition NBSign.h:50
@ SIGN_TYPE_RIGHT_BEFORE_LEFT
Definition NBSign.h:51
@ SIGN_TYPE_LEFT_BEFORE_RIGHT
Definition NBSign.h:52
The base class for traffic light logic definitions.
A container for traffic light definitions and built programs.
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane, bool incoming)
Replaces occurrences of the removed edge/lane in all definitions by the given edge.
A storage for available edgeTypes of edges.
Definition NBTypeCont.h:52
bool getEdgeTypeShallBeDiscarded(const std::string &edgeType) const
Returns the information whether edges of this edgeType shall be discarded.
bool knows(const std::string &edgeType) const
Returns whether the named edgeType is in the container.
Allows to store the object; used as context while traveling the rtree in TraCI.
Definition Named.h:89
Base class for objects which have an id.
Definition Named.h:53
virtual void setID(const std::string &newID)
resets the id
Definition Named.h:81
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
Definition Named.h:66
const std::string & getID() const
Returns the id.
Definition Named.h:73
A RT-tree for efficient storing of SUMO's Named objects.
Definition NamedRTree.h:61
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
Definition NamedRTree.h:79
int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor &c) const
Find all within search rectangle.
Definition NamedRTree.h:112
A storage for options typed value containers)
Definition OptionsCont.h:92
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
std::string getValueString(const std::string &name) const
Returns the string-value of the named option (all options)
static OptionsCont & getOptions()
Retrieves the options.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position (in radians bet...
Definition Position.h:283
A list of positions.
double length2D() const
Returns the length.
void append(const PositionVector &v, double sameThreshold=2.0)
double length() const
Returns the length.
double distance2D(const Position &p, bool perpendicular=false) const
closest 2D-distance to point p (or -1 if perpendicular is true and the point is beyond this vector)
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
std::pair< PositionVector, PositionVector > splitAt(double where, bool use2D=false) const
Returns the two lists made when this list vector is splitted at the given point.
void move2side(double amount, double maxExtension=100)
move position vector to side using certain amount
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
void extrapolate(const double val, const bool onlyFirst=false, const bool onlyLast=false)
extrapolate position vector
double getOverlapWith(const PositionVector &poly, double zThreshold) const
Returns the maximum overlaps between this and the given polygon (when not separated by at least zThre...
Position positionAtOffset2D(double pos, double lateralOffset=0, bool extrapolateBeyond=false) const
Returns the position at the given length.
bool partialWithin(const AbstractPoly &poly, double offset=0) const
Returns the information whether this polygon lies partially within the given polygon.
double getMaxGrade(double &maxJump) const
double area() const
Returns the area (0 for non-closed)
bool intersects(const Position &p1, const Position &p2) const
Returns the information whether this list of points interesects the given line.
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
static std::string getEdgeIDFromLane(const std::string laneID)
return edge id when given the lane ID
std::vector< std::string > getVector()
return vector of strings
static long long int toLong(const std::string &sData)
converts a string into the long value described by it by calling the char-type converter,...
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
unsigned node
#define M_PI
Definition odrSpiral.cpp:45
A structure which describes a connection between edges or lanes.
Definition NBEdge.h:201
NBEdge * toEdge
The edge the connections yields in.
Definition NBEdge.h:213
PositionVector viaShape
shape of via
Definition NBEdge.h:282
std::string getDescription(const NBEdge *parent) const
get string describing this connection
Definition NBEdge.cpp:104
PositionVector shape
shape of Connection
Definition NBEdge.h:270
std::string oppositeID
An opposite lane ID, if given.
Definition NBEdge.h:179
bool operator()(const std::pair< NBEdge *, int > &a, const std::pair< NBEdge *, int > &b) const
A structure representing a connection between two lanes.
Definition NBEdgeCont.h:641
A structure which describes changes of lane number or speed along the road.
Definition NBEdgeCont.h:189
int offsetFactor
direction in which to apply the offset (used by netgenerate for lefthand networks)
Definition NBEdgeCont.h:209
double offset
lateral offset to edge geometry
Definition NBEdgeCont.h:207
double pos
The position of this change.
Definition NBEdgeCont.h:193
std::vector< int > lanes
The lanes after this change.
Definition NBEdgeCont.h:191