Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NBEdge.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/****************************************************************************/
23// Methods for the representation of a single edge
24/****************************************************************************/
25#include <config.h>
26
27#include <vector>
28#include <string>
29#include <algorithm>
30#include <cmath>
31#include <iomanip>
40#include "NBEdgeCont.h"
41#include "NBNode.h"
42#include "NBNodeCont.h"
43#include "NBContHelper.h"
44#include "NBHelpers.h"
46#include "NBOwnTLDef.h"
47#include "NBTypeCont.h"
48#include "NBEdge.h"
49
50//#define ADDITIONAL_WARNINGS
51//#define DEBUG_CONNECTION_GUESSING
52//#define DEBUG_CONNECTION_CHECKING
53//#define DEBUG_ANGLES
54//#define DEBUG_NODE_BORDER
55//#define DEBUG_REPLACECONNECTION
56//#define DEBUG_JUNCTIONPRIO
57//#define DEBUG_TURNSIGNS
58//#define DEBUG_CUT_LANES
59#define DEBUGID ""
60#define DEBUGCOND (getID() == DEBUGID)
61//#define DEBUGCOND (StringUtils::startsWith(getID(), DEBUGID))
62//#define DEBUGCOND (getID() == "22762377#1" || getID() == "146511467")
63#define DEBUGCOND2(obj) ((obj != 0 && (obj)->getID() == DEBUGID))
64//#define DEBUGCOND (true)
65
66// ===========================================================================
67// static members
68// ===========================================================================
69const double NBEdge::UNSPECIFIED_WIDTH = -1;
70const double NBEdge::UNSPECIFIED_OFFSET = 0;
71const double NBEdge::UNSPECIFIED_SPEED = -1;
72const double NBEdge::UNSPECIFIED_FRICTION = 1.;
73const double NBEdge::UNSPECIFIED_CONTPOS = -1;
75
76const double NBEdge::UNSPECIFIED_SIGNAL_OFFSET = -1;
77const double NBEdge::UNSPECIFIED_LOADED_LENGTH = -1;
78const double NBEdge::ANGLE_LOOKAHEAD = 10.0;
81
83
85
86ConstRouterEdgePairVector NBEdge::Connection::myViaSuccessors = ConstRouterEdgePairVector({ std::pair<NBRouterEdge*, NBRouterEdge*>(nullptr, nullptr) });
87
88// ===========================================================================
89// method definitions
90// ===========================================================================
91std::string
95
96
97std::string
99 return viaID + "_" + toString(internalViaLaneIndex);
100}
101
102
103std::string
105 return (Named::getIDSecure(parent) + "_" + toString(fromLane) + "->" + Named::getIDSecure(toEdge) + "_" + toString(toLane)
106 + (permissions == SVC_UNSPECIFIED ? "" : " (" + getVehicleClassNames(permissions) + ")"));
107}
108
109
110NBEdge::Connection::Connection(int fromLane_, NBEdge* toEdge_, int toLane_, const bool mayDefinitelyPass_) :
111 fromLane(fromLane_),
112 toEdge(toEdge_),
113 toLane(toLane_),
114 mayDefinitelyPass(mayDefinitelyPass_),
115 customLength(myDefaultConnectionLength),
116 id(toEdge_ == nullptr ? "" : toEdge->getFromNode()->getID()) {
117}
118
119
120NBEdge::Lane::Lane(NBEdge* e, const std::string& origID_) :
121 speed(e->getSpeed()),
122 friction(e->getFriction()),
123 permissions(SVCAll),
124 preferred(0),
125 changeLeft(SVCAll),
126 changeRight(SVCAll),
127 endOffset(e->getEndOffset()),
128 laneStopOffset(e->getEdgeStopOffset()),
129 width(e->getLaneWidth()),
130 accelRamp(false),
131 connectionsDone(false) {
132 if (origID_ != "") {
134 }
135}
136
137
138/* -------------------------------------------------------------------------
139 * NBEdge::ToEdgeConnectionsAdder-methods
140 * ----------------------------------------------------------------------- */
141void
142NBEdge::ToEdgeConnectionsAdder::execute(const int lane, const int virtEdge) {
143 // check
144 assert((int)myTransitions.size() > virtEdge);
145 // get the approached edge
146 NBEdge* succEdge = myTransitions[virtEdge];
147 std::vector<int> lanes;
148
149 // check whether the currently regarded, approached edge has already
150 // a connection starting at the edge which is currently being build
151 std::map<NBEdge*, std::vector<int> >::iterator i = myConnections.find(succEdge);
152 if (i != myConnections.end()) {
153 // if there were already lanes assigned, get them
154 lanes = (*i).second;
155 }
156
157 // check whether the current lane was already used to connect the currently
158 // regarded approached edge
159 std::vector<int>::iterator j = std::find(lanes.begin(), lanes.end(), lane);
160 if (j == lanes.end()) {
161 // if not, add it to the list
162 lanes.push_back(lane);
163 }
164 // set information about connecting lanes
165 myConnections[succEdge] = lanes;
166}
167
168
169
170/* -------------------------------------------------------------------------
171 * NBEdge::MainDirections-methods
172 * ----------------------------------------------------------------------- */
173NBEdge::MainDirections::MainDirections(const EdgeVector& outgoing, NBEdge* parent, NBNode* to, const std::vector<int>& availableLanes) : myStraightest(-1) {
175 const NBEdge* straight = nullptr;
176 for (const NBEdge* const out : outgoing) {
177 const SVCPermissions outPerms = out->getPermissions();
178 for (const int l : availableLanes) {
179 if ((parent->myLanes[l].permissions & outPerms) != 0) {
180 if (straight == nullptr || sorter(out, straight)) {
181 straight = out;
182 }
183 break;
184 }
185 }
186 }
187 if (straight == nullptr) {
188 return;
189 }
190 myStraightest = (int)std::distance(outgoing.begin(), std::find(outgoing.begin(), outgoing.end(), straight));
191
192 // check whether the right turn has a higher priority
193 assert(outgoing.size() > 0);
194 const LinkDirection straightestDir = to->getDirection(parent, straight);
195#ifdef DEBUG_CONNECTION_GUESSING
196 if (DEBUGCOND2(parent)) {
197 std::cout << " MainDirections edge=" << parent->getID() << " straightest=" << straight->getID() << " dir=" << toString(straightestDir) << "\n";
198 }
199#endif
200 if (NBNode::isTrafficLight(to->getType()) &&
201 (straightestDir == LinkDirection::STRAIGHT || straightestDir == LinkDirection::PARTLEFT || straightestDir == LinkDirection::PARTRIGHT)) {
203 return;
204 }
205 if (outgoing[0]->getJunctionPriority(to) == 1) {
207 }
208 // check whether the left turn has a higher priority
209 if (outgoing.back()->getJunctionPriority(to) == 1) {
210 // ok, the left turn belongs to the higher priorised edges on the junction
211 // let's check, whether it has also a higher priority (lane number/speed)
212 // than the current
213 if (outgoing.back()->getPriority() > straight->getPriority() ||
214 outgoing.back()->getNumLanes() > straight->getNumLanes()) {
216 }
217 }
218 // check whether the forward direction has a higher priority
219 // check whether it has a higher priority and is going straight
220 if (straight->getJunctionPriority(to) == 1 && to->getDirection(parent, straight) == LinkDirection::STRAIGHT) {
222 }
223}
224
225
227
228
229bool
231 return myDirs.empty();
232}
233
234
235bool
237 return std::find(myDirs.begin(), myDirs.end(), d) != myDirs.end();
238}
239
240
241/* -------------------------------------------------------------------------
242 * NBEdge::connections_relative_edgelane_sorter-methods
243 * ----------------------------------------------------------------------- */
244int
246 if (c1.toEdge != c2.toEdge) {
248 }
249 return c1.toLane < c2.toLane;
250}
251
252
253/* -------------------------------------------------------------------------
254 * NBEdge-methods
255 * ----------------------------------------------------------------------- */
256NBEdge::NBEdge(const std::string& id, NBNode* from, NBNode* to,
257 std::string type, double speed, double friction, int nolanes,
258 int priority, double laneWidth, double endOffset,
259 LaneSpreadFunction spread, const std::string& streetName) :
260 Named(StringUtils::convertUmlaute(id)),
262 myType(StringUtils::convertUmlaute(type)),
263 myFrom(from), myTo(to),
265 myPriority(priority), mySpeed(speed), myFriction(friction),
266 myDistance(0),
267 myTurnDestination(nullptr),
270 myLaneSpreadFunction(spread), myEndOffset(endOffset),
271 myLaneWidth(laneWidth),
273 myAmInTLS(false), myAmMacroscopicConnector(false),
274 myStreetName(streetName),
276 mySignalNode(nullptr),
277 myIsOffRamp(false),
278 myIsBidi(false),
279 myIndex(-1) {
280 init(nolanes, false, "");
281}
282
283
284NBEdge::NBEdge(const std::string& id, NBNode* from, NBNode* to,
285 std::string type, double speed, double friction, int nolanes,
286 int priority, double laneWidth, double endOffset,
287 PositionVector geom,
288 LaneSpreadFunction spread,
289 const std::string& streetName,
290 const std::string& origID,
291 bool tryIgnoreNodePositions) :
292 Named(StringUtils::convertUmlaute(id)),
293 myStep(EdgeBuildingStep::INIT),
294 myType(StringUtils::convertUmlaute(type)),
295 myFrom(from), myTo(to),
296 myStartAngle(0), myEndAngle(0), myTotalAngle(0),
297 myPriority(priority), mySpeed(speed), myFriction(friction),
298 myDistance(0),
299 myTurnDestination(nullptr),
300 myPossibleTurnDestination(nullptr),
301 myFromJunctionPriority(-1), myToJunctionPriority(-1),
302 myGeom(geom), myLaneSpreadFunction(spread), myEndOffset(endOffset),
303 myLaneWidth(laneWidth),
304 myLoadedLength(UNSPECIFIED_LOADED_LENGTH),
305 myAmInTLS(false), myAmMacroscopicConnector(false),
306 myStreetName(streetName),
307 mySignalPosition(Position::INVALID),
308 mySignalNode(nullptr),
309 myIsOffRamp(false),
310 myIsBidi(false),
311 myIndex(-1) {
312 init(nolanes, tryIgnoreNodePositions, origID);
313}
314
315
316NBEdge::NBEdge(const std::string& id, NBNode* from, NBNode* to, const NBEdge* tpl, const PositionVector& geom, int numLanes) :
317 Named(StringUtils::convertUmlaute(id)),
318 myStep(EdgeBuildingStep::INIT),
319 myType(tpl->getTypeID()),
320 myFrom(from), myTo(to),
321 myStartAngle(0), myEndAngle(0), myTotalAngle(0),
322 myPriority(tpl->getPriority()), mySpeed(tpl->getSpeed()),
323 myFriction(tpl->getFriction()),
324 myDistance(0),
325 myTurnDestination(nullptr),
326 myPossibleTurnDestination(nullptr),
327 myFromJunctionPriority(-1), myToJunctionPriority(-1),
328 myGeom(geom),
329 myLaneSpreadFunction(tpl->getLaneSpreadFunction()),
330 myEndOffset(tpl->getEndOffset()),
331 myEdgeStopOffset(tpl->getEdgeStopOffset()),
332 myLaneWidth(tpl->getLaneWidth()),
333 myLoadedLength(UNSPECIFIED_LOADED_LENGTH),
334 myAmInTLS(false),
335 myAmMacroscopicConnector(false),
336 myStreetName(tpl->getStreetName()),
337 mySignalPosition(to == tpl->myTo ? tpl->mySignalPosition : Position::INVALID),
338 mySignalNode(to == tpl->myTo ? tpl->mySignalNode : nullptr),
339 myIsOffRamp(false),
340 myIsBidi(tpl->myIsBidi),
341 myRoundaboutGuessExcluded(tpl->myRoundaboutGuessExcluded),
342 myIndex(-1) {
343 init(numLanes > 0 ? numLanes : tpl->getNumLanes(), myGeom.size() > 0, "");
344 for (int i = 0; i < getNumLanes(); i++) {
345 const int tplIndex = MIN2(i, tpl->getNumLanes() - 1);
346 setSpeed(i, tpl->getLaneSpeed(tplIndex));
347 setFriction(i, tpl->getLaneFriction(tplIndex));
348 setPermissions(tpl->getPermissions(tplIndex), i);
349 setLaneWidth(i, tpl->myLanes[tplIndex].width);
350 setLaneType(i, tpl->myLanes[tplIndex].type);
351 myLanes[i].updateParameters(tpl->myLanes[tplIndex].getParametersMap());
352 if (to == tpl->myTo) {
353 setEndOffset(i, tpl->myLanes[tplIndex].endOffset);
354 setEdgeStopOffset(i, tpl->myLanes[tplIndex].laneStopOffset);
355 }
356 }
357 if (tpl->myLoadedLength > 0 && to == tpl->getFromNode() && from == tpl->getToNode() && geom == tpl->getGeometry().reverse()) {
359 }
361}
362
363
365 Named("DUMMY"),
366 myStep(EdgeBuildingStep::INIT),
367 myFrom(nullptr), myTo(nullptr),
368 myStartAngle(0), myEndAngle(0), myTotalAngle(0),
369 myPriority(0), mySpeed(0), myFriction(UNSPECIFIED_FRICTION),
370 myDistance(0),
371 myTurnDestination(nullptr),
372 myPossibleTurnDestination(nullptr),
373 myFromJunctionPriority(-1), myToJunctionPriority(-1),
374 myLaneSpreadFunction(LaneSpreadFunction::RIGHT),
375 myEndOffset(0),
376 myEdgeStopOffset(StopOffset()),
377 myLaneWidth(0),
378 myLoadedLength(UNSPECIFIED_LOADED_LENGTH),
379 myAmInTLS(false),
380 myAmMacroscopicConnector(false),
381 mySignalPosition(Position::INVALID),
382 mySignalNode(nullptr) {
383}
384
385
386void
387NBEdge::reinit(NBNode* from, NBNode* to, const std::string& type,
388 double speed, double friction, int nolanes, int priority,
389 PositionVector geom, double laneWidth, double endOffset,
390 const std::string& streetName,
391 LaneSpreadFunction spread,
392 bool tryIgnoreNodePositions) {
393 if (myFrom != from) {
394 myFrom->removeEdge(this, false);
395 }
396 if (myTo != to) {
397 myTo->removeEdge(this, false);
398 }
400 myFrom = from;
401 myTo = to;
402 myPriority = priority;
403 //?myTurnDestination(0),
404 //?myFromJunctionPriority(-1), myToJunctionPriority(-1),
405 myGeom = geom;
406 myLaneSpreadFunction = spread;
408 myStreetName = streetName;
409 //?, myAmTurningWithAngle(0), myAmTurningOf(0),
410 //?myAmInTLS(false), myAmMacroscopicConnector(false)
411
412 // preserve lane-specific settings (geometry must be recomputed)
413 // if new lanes are added they copy the values from the leftmost lane (if specified)
414 const std::vector<Lane> oldLanes = myLanes;
415 init(nolanes, tryIgnoreNodePositions, oldLanes.empty() ? "" : oldLanes[0].getParameter(SUMO_PARAM_ORIGID));
416 for (int i = 0; i < (int)nolanes; ++i) {
417 PositionVector newShape = myLanes[i].shape;
418 myLanes[i] = oldLanes[MIN2(i, (int)oldLanes.size() - 1)];
419 myLanes[i].shape = newShape;
420 }
421 // however, if the new edge defaults are explicityly given, they override the old settings
422 if (endOffset != UNSPECIFIED_OFFSET) {
423 setEndOffset(-1, endOffset);
424 }
425 if (laneWidth != UNSPECIFIED_WIDTH) {
426 setLaneWidth(-1, laneWidth);
427 }
428 if (speed != UNSPECIFIED_SPEED) {
429 setSpeed(-1, speed);
430 }
431 if (friction != UNSPECIFIED_FRICTION) {
432 setFriction(-1, friction);
433 }
434}
435
436
437void
439 // connections may still be valid
440 if (from == nullptr || to == nullptr) {
441 throw ProcessError(TLF("At least one of edge's '%' nodes is not known.", myID));
442 }
443 if (myFrom != from) {
444 myFrom->removeEdge(this, false);
445 }
446 if (myTo != to) {
447 myTo->removeEdge(this, false);
448 }
449 // remove first from both nodes and then add to the new nodes
450 // (otherwise reversing does not work)
451 if (myFrom != from) {
452 myFrom = from;
453 myFrom->addOutgoingEdge(this);
454 }
455 if (myTo != to) {
456 myTo = to;
457 myTo->addIncomingEdge(this);
458 }
459 computeAngle();
460}
461
462
463void
464NBEdge::init(int noLanes, bool tryIgnoreNodePositions, const std::string& origID) {
465 if (noLanes == 0) {
466 throw ProcessError(TLF("Edge '%' needs at least one lane.", myID));
467 }
468 if (myFrom == nullptr || myTo == nullptr) {
469 throw ProcessError(TLF("At least one of edge's '%' nodes is not known.", myID));
470 }
472 throw ProcessError(TLF("Invalid edge id '%'.", myID));
473 }
474 // revisit geometry
475 // should have at least two points at the end...
476 // and in dome cases, the node positions must be added
477 // attempt symmetrical removal for forward and backward direction
478 // (very important for bidiRail)
479 if (myFrom->getID() < myTo->getID()) {
480 PositionVector reverse = myGeom.reverse();
481 reverse.removeDoublePoints(POSITION_EPS, true);
482 myGeom = reverse.reverse();
483 } else {
484 myGeom.removeDoublePoints(POSITION_EPS, true);
485 }
486
487 if (!tryIgnoreNodePositions || myGeom.size() < 2) {
488 if (myGeom.size() == 0) {
489 myGeom.push_back(myFrom->getPosition());
490 myGeom.push_back(myTo->getPosition());
491 } else {
494 }
495 }
496 if (myGeom.size() < 2) {
497 myGeom.clear();
498 myGeom.push_back(myFrom->getPosition());
499 myGeom.push_back(myTo->getPosition());
500 }
501 if (myGeom.size() == 2 && myGeom[0] == myGeom[1]) {
502 WRITE_WARNINGF(TL("Edge's '%' from- and to-node are at the same position."), myID);
503 int patchIndex = myFrom->getID() < myTo->getID() ? 1 : 0;
504 myGeom[patchIndex].add(Position(POSITION_EPS, POSITION_EPS));
505 }
506 // avoid degeneration of near-0-length geometrie when shifting later
508 //
509 myFrom->addOutgoingEdge(this);
510 myTo->addIncomingEdge(this);
511 // prepare container
512 assert(myGeom.size() >= 2);
514 if ((int)myLanes.size() > noLanes) {
515 // remove connections starting at the removed lanes
516 for (int lane = noLanes; lane < (int)myLanes.size(); ++lane) {
517 removeFromConnections(nullptr, lane, -1);
518 }
519 // remove connections targeting the removed lanes
520 const EdgeVector& incoming = myFrom->getIncomingEdges();
521 for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
522 for (int lane = noLanes; lane < (int)myLanes.size(); ++lane) {
523 (*i)->removeFromConnections(this, -1, lane);
524 }
525 }
526 }
527 myLanes.clear();
528 for (int i = 0; i < noLanes; i++) {
529 myLanes.push_back(Lane(this, origID));
530 }
532 computeAngle();
533
534#ifdef DEBUG_CONNECTION_GUESSING
535 if (DEBUGCOND) {
536 std::cout << "init edge=" << getID() << "\n";
537 for (Connection& c : myConnections) {
538 std::cout << " conn " << c.getDescription(this) << "\n";
539 }
541 std::cout << " connToDelete " << c.getDescription(this) << "\n";
542 }
543 }
544#endif
545}
546
547
549
550
551// ----------- Applying offset
552void
553NBEdge::reshiftPosition(double xoff, double yoff) {
554 myGeom.add(xoff, yoff, 0);
555 for (Lane& lane : myLanes) {
556 lane.customShape.add(xoff, yoff, 0);
557 }
558 computeLaneShapes(); // old shapes are dubious if computed with large coordinates
559 for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
560 (*i).customShape.add(xoff, yoff, 0);
561 }
563 mySignalPosition.add(xoff, yoff);
564 }
565 myFromBorder.add(xoff, yoff, 0);
566 myToBorder.add(xoff, yoff, 0);
568 computeAngle(); // update angles because they are numerically sensitive (especially where based on centroids)
569}
570
571
572void
575 for (Lane& lane : myLanes) {
576 lane.customShape.round(gPrecision);
577 }
578 for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
579 (*i).customShape.round(gPrecision);
580 }
581}
582
583
584void
587 // lane speeds are not used for computation but are compared to mySpeed in hasLaneSpecificSpeed
588 for (Lane& l : myLanes) {
589 l.speed = roundDecimalToEven(l.speed, gPrecision);
590 }
591}
592
593void
595 myGeom.mirrorX();
596 for (int i = 0; i < (int)myLanes.size(); i++) {
597 myLanes[i].shape.mirrorX();
598 myLanes[i].customShape.mirrorX();
599 }
600 for (Connection& c : myConnections) {
601 c.shape.mirrorX();
602 c.viaShape.mirrorX();
603 c.customShape.mirrorX();
604 }
607 }
608 computeAngle(); // update angles because they are numerically sensitive (especially where based on centroids)
609}
610
611
612// ----------- Edge geometry access and computation
613const PositionVector
615 return myGeom.getSubpartByIndex(1, (int)myGeom.size() - 2);
616}
617
618
619bool
621 return myGeom.size() == 2 && hasDefaultGeometryEndpoints();
622}
623
624
625bool
627 return myGeom.front().almostSame(myFrom->getPosition(), 0.01) &&
628 myGeom.back().almostSame(myTo->getPosition(), 0.01);
629}
630
631
632bool
634 // do not extend past the node position
635 if (node == myFrom) {
636 return myGeom.front() == node->getPosition();
637 } else {
638 assert(node == myTo);
639 return myGeom.back() == node->getPosition();
640 }
641}
642
645 return node == myFrom ? myGeom.front() : myGeom.back();
646}
647
648void
650 assert(myGeom.size() >= 2);
651 if (node == myFrom) {
652 myGeom[0] = myFrom->getPosition();
653 } else if (node == myTo) {
654 myGeom[-1] = myTo->getPosition();
655 } else {
656 assert(false);
657 }
658}
659
660void
661NBEdge::setGeometry(const PositionVector& s, bool inner) {
662 Position begin = myGeom.front(); // may differ from node position
663 Position end = myGeom.back(); // may differ from node position
664 myGeom = s;
665 if (inner) {
666 myGeom.insert(myGeom.begin(), begin);
667 myGeom.push_back(end);
668 }
669 // ensure non-zero length (see ::init)
670 if (myGeom.size() == 2 && myGeom[0] == myGeom[1]) {
671 WRITE_WARNINGF(TL("Edge's '%' from- and to-node are at the same position."), myID);
672 int patchIndex = myFrom->getID() < myTo->getID() ? 1 : 0;
673 myGeom[patchIndex].add(Position(POSITION_EPS, POSITION_EPS));
674 }
676 computeAngle();
678}
679
680
681void
682NBEdge::extendGeometryAtNode(const NBNode* node, double maxExtent) {
683 //std::cout << "extendGeometryAtNode edge=" << getID() << " node=" << node->getID() << " nodePos=" << node->getPosition() << " extent=" << maxExtent << " geom=" << myGeom;
684 if (node == myFrom) {
685 myGeom.extrapolate(maxExtent, true);
686 double offset = myGeom.nearest_offset_to_point2D(node->getPosition());
687 //std::cout << " geom2=" << myGeom << " offset=" << offset;
688 if (offset != GeomHelper::INVALID_OFFSET) {
689 myGeom = myGeom.getSubpart2D(MIN2(offset, myGeom.length2D() - 2 * POSITION_EPS), myGeom.length2D());
690 }
691 } else {
692 assert(node == myTo);
693 myGeom.extrapolate(maxExtent, false, true);
694 double offset = myGeom.nearest_offset_to_point2D(node->getPosition());
695 //std::cout << " geom2=" << myGeom << " offset=" << offset;
696 if (offset != GeomHelper::INVALID_OFFSET) {
697 myGeom = myGeom.getSubpart2D(0, MAX2(offset, 2 * POSITION_EPS));
698 }
699 }
700 //std::cout << " geom3=" << myGeom << "\n";
701}
702
703
704void
705NBEdge::shortenGeometryAtNode(const NBNode* node, double reduction) {
706 //std::cout << "shortenGeometryAtNode edge=" << getID() << " node=" << node->getID() << " nodePos=" << node->getPosition() << " reduction=" << reduction << " geom=" << myGeom;
707 reduction = MIN2(reduction, myGeom.length2D() - 2 * POSITION_EPS);
708 if (node == myFrom) {
709 myGeom = myGeom.getSubpart2D(reduction, myGeom.length2D());
710 } else {
711 myGeom = myGeom.getSubpart2D(0, myGeom.length2D() - reduction);
712 }
714 //std::cout << " geom2=" << myGeom << "\n";
715}
716
717
718void
719NBEdge::setNodeBorder(const NBNode* node, const Position& p, const Position& p2, bool rectangularCut) {
720 PositionVector border;
721 if (rectangularCut) {
722 const double extend = 100;
723 border = myGeom.getOrthogonal(p, extend, node == myTo);
724 } else {
725 border.push_back(p);
726 border.push_back(p2);
727 }
728 if (border.size() == 2) {
730 if (node == myFrom) {
731 myFromBorder = border;
732 } else {
733 assert(node == myTo);
734 myToBorder = border;
735 }
736 }
737#ifdef DEBUG_NODE_BORDER
739 if (DEBUGCOND) std::cout << "setNodeBorder edge=" << getID() << " node=" << node->getID()
740 << " rect=" << rectangularCut
741 << " p=" << p << " p2=" << p2
742 << " border=" << border
743 << " myGeom=" << myGeom
744 << "\n";
745
746#endif
747}
748
749
750const PositionVector&
752 if (node == myFrom) {
753 return myFromBorder;
754 } else {
755 assert(node == myTo);
756 return myToBorder;
757 }
758}
759
760
761void
763 if (node == myFrom) {
764 myFromBorder.clear();
765 } else {
766 assert(node == myTo);
767 myToBorder.clear();
768 }
769}
770
771
772bool
782
783
784bool
785NBEdge::isBidiEdge(bool checkPotential) const {
786 return myPossibleTurnDestination != nullptr
788 && (myIsBidi || myPossibleTurnDestination->myIsBidi || checkPotential)
791 // geometry check a) full overlap geometry
794 || (checkPotential && getGeometry().size() == 2 && myPossibleTurnDestination->getGeometry().size() == 2)))
795 // b) TWLT (Two-Way-Left-Turn-lane)
796 || (myLanes.back().shape.reverse().almostSame(myPossibleTurnDestination->myLanes.back().shape, POSITION_EPS))
797 );
798
799}
800
801
802bool
804 if (!isRailway(getPermissions())) {
805 return false;
806 }
807 for (NBEdge* out : myTo->getOutgoingEdges()) {
808 if (isRailway(out->getPermissions() & getPermissions()) &&
809 out != getTurnDestination(true)) {
810 return false;
811 }
812 }
813 return true;
814}
815
816
819 PositionVector shape = old;
820 shape = startShapeAt(shape, myFrom, myFromBorder);
821#ifdef DEBUG_CUT_LANES
822 if (DEBUGCOND) {
823 std::cout << getID() << " cutFrom=" << shape << "\n";
824 }
825#endif
826 if (shape.size() < 2) {
827 // only keep the last snippet
828 const double oldLength = old.length();
829 shape = old.getSubpart(oldLength - 2 * POSITION_EPS, oldLength);
830#ifdef DEBUG_CUT_LANES
831 if (DEBUGCOND) {
832 std::cout << getID() << " cutFromFallback=" << shape << "\n";
833 }
834#endif
835 }
836 shape = startShapeAt(shape.reverse(), myTo, myToBorder).reverse();
837#ifdef DEBUG_CUT_LANES
838 if (DEBUGCOND) {
839 std::cout << getID() << " cutTo=" << shape << "\n";
840 }
841#endif
842 // sanity checks
843 if (shape.length() < POSITION_EPS) {
844 if (old.length() < 2 * POSITION_EPS) {
845 shape = old;
846 } else {
847 const double midpoint = old.length() / 2;
848 // EPS*2 because otherwhise shape has only a single point
849 shape = old.getSubpart(midpoint - POSITION_EPS, midpoint + POSITION_EPS);
850 assert(shape.size() >= 2);
851 assert(shape.length() > 0);
852#ifdef DEBUG_CUT_LANES
853 if (DEBUGCOND) {
854 std::cout << getID() << " fallBackShort=" << shape << "\n";
855 }
856#endif
857 }
858 } else {
859 // @note If the node shapes are overlapping we may get a shape which goes in the wrong direction
860 // in this case the result shape should shortened
861 if (DEG2RAD(135) < fabs(GeomHelper::angleDiff(shape.beginEndAngle(), old.beginEndAngle()))) {
862 // eliminate intermediate points
863 PositionVector tmp;
864 tmp.push_back(shape[0]);
865 tmp.push_back(shape[-1]);
866 shape = tmp;
867 if (tmp.length() < POSITION_EPS) {
868 // fall back to original shape
869 if (old.length() < 2 * POSITION_EPS) {
870 shape = old;
871 } else {
872 const double midpoint = old.length() / 2;
873 // EPS*2 because otherwhise shape has only a single point
874 shape = old.getSubpart(midpoint - POSITION_EPS, midpoint + POSITION_EPS);
875 assert(shape.size() >= 2);
876 assert(shape.length() > 0);
877 }
878#ifdef DEBUG_CUT_LANES
879 if (DEBUGCOND) {
880 std::cout << getID() << " fallBackReversed=" << shape << "\n";
881 }
882#endif
883 } else {
884 const double midpoint = shape.length() / 2;
885 // cut to size and reverse
886 shape = shape.getSubpart(midpoint - POSITION_EPS, midpoint + POSITION_EPS);
887 if (shape.length() < POSITION_EPS) {
888 assert(false);
889 // the shape has a sharp turn near the midpoint
890 }
891 shape = shape.reverse();
892#ifdef DEBUG_CUT_LANES
893 if (DEBUGCOND) {
894 std::cout << getID() << " fallBackReversed2=" << shape << " mid=" << midpoint << "\n";
895 }
896#endif
897 }
898 // make short edge flat (length <= 2 * POSITION_EPS)
899 const double z = (shape[0].z() + shape[1].z()) / 2;
900 shape[0].setz(z);
901 shape[1].setz(z);
902 }
903 }
904 return shape;
905}
906
907
908void
909NBEdge::computeEdgeShape(double smoothElevationThreshold) {
910 if (smoothElevationThreshold > 0 && myGeom.hasElevation()) {
912 // cutting and patching z-coordinate may cause steep grades which should be smoothed
913 if (!myFrom->geometryLike()) {
914 cut[0].setz(myFrom->getPosition().z());
915 const double d = cut[0].distanceTo2D(cut[1]);
916 const double dZ = fabs(cut[0].z() - cut[1].z());
917 if (dZ / smoothElevationThreshold > d) {
918 cut = cut.smoothedZFront(MIN2(cut.length2D() / 2, dZ / smoothElevationThreshold));
919 }
920 }
921 if (!myTo->geometryLike()) {
922 cut[-1].setz(myTo->getPosition().z());
923 const double d = cut[-1].distanceTo2D(cut[-2]);
924 const double dZ = fabs(cut[-1].z() - cut[-2].z());
925 if (dZ / smoothElevationThreshold > d) {
926 cut = cut.reverse().smoothedZFront(MIN2(cut.length2D() / 2, dZ / smoothElevationThreshold)).reverse();
927 }
928 }
929 cut[0] = myGeom[0];
930 cut[-1] = myGeom[-1];
931 if (cut != myGeom) {
932 myGeom = cut;
934 }
935 }
936 for (int i = 0; i < (int)myLanes.size(); i++) {
937 myLanes[i].shape = cutAtIntersection(myLanes[i].shape);
938 }
939 // recompute edge's length as the average of lane lengths
940 double avgLength = 0;
941 for (int i = 0; i < (int)myLanes.size(); i++) {
942 avgLength += myLanes[i].shape.length();
943 }
944 myLength = avgLength / (double) myLanes.size();
945 computeAngle(); // update angles using the finalized node and lane shapes
946}
947
948
950NBEdge::startShapeAt(const PositionVector& laneShape, const NBNode* startNode, PositionVector nodeShape) {
951 if (nodeShape.size() == 0) {
952 nodeShape = startNode->getShape();
953 nodeShape.closePolygon();
954 }
955 PositionVector lb = laneShape;
956 lb.extrapolate2D(100.0);
957 if (nodeShape.intersects(laneShape)) {
958 // shape intersects directly
959 std::vector<double> pbv = laneShape.intersectsAtLengths2D(nodeShape);
960 assert(pbv.size() > 0);
961 // ensure that the subpart has at least two points
962 double pb = MIN2(laneShape.length2D() - POSITION_EPS - NUMERICAL_EPS, VectorHelper<double>::maxValue(pbv));
963 if (pb < 0) {
964 return laneShape;
965 }
966 PositionVector ns = laneShape.getSubpart2D(pb, laneShape.length2D());
967 //PositionVector ns = pb < (laneShape.length() - POSITION_EPS) ? laneShape.getSubpart2D(pb, laneShape.length()) : laneShape;
968 const double delta = ns[0].z() - laneShape[0].z();
969 //std::cout << "a) startNode=" << startNode->getID() << " z=" << startNode->getPosition().z() << " oldZ=" << laneShape[0].z() << " cutZ=" << ns[0].z() << " delta=" << delta << "\n";
970 if (fabs(delta) > 2 * POSITION_EPS && (!startNode->geometryLike() || pb < 1)) {
971 // make "real" intersections and small intersections flat
972 //std::cout << "a) startNode=" << startNode->getID() << " z=" << startNode->getPosition().z() << " oldZ=" << laneShape[0].z() << " cutZ=" << ns[0].z() << " delta=" << delta << "\n";
973 ns[0].setz(startNode->getPosition().z());
974 }
975 assert(ns.size() >= 2);
976 return ns;
977 } else if (nodeShape.intersects(lb)) {
978 // extension of first segment intersects
979 std::vector<double> pbv = lb.intersectsAtLengths2D(nodeShape);
980 assert(pbv.size() > 0);
981 double pb = VectorHelper<double>::maxValue(pbv);
982 assert(pb >= 0);
983 PositionVector result = laneShape.getSubpartByIndex(1, (int)laneShape.size() - 1);
984 Position np = lb.positionAtOffset2D(pb);
985 const double delta = np.z() - laneShape[0].z();
986 //std::cout << "b) startNode=" << startNode->getID() << " z=" << startNode->getPosition().z() << " oldZ=" << laneShape[0].z() << " cutZ=" << np.z() << " delta=" << delta << "\n";
987 if (fabs(delta) > 2 * POSITION_EPS && !startNode->geometryLike()) {
988 // avoid z-overshoot when extrapolating
989 //std::cout << "b) startNode=" << startNode->getID() << " z=" << startNode->getPosition().z() << " oldZ=" << laneShape[0].z() << " cutZ=" << np.z() << " delta=" << delta << "\n";
990 np.setz(startNode->getPosition().z());
991 }
992 result.push_front_noDoublePos(np);
993 return result;
994 //if (result.size() >= 2) {
995 // return result;
996 //} else {
997 // WRITE_WARNING(error + " (resulting shape is too short)");
998 // return laneShape;
999 //}
1000 } else {
1001 // could not find proper intersection. Probably the edge is very short
1002 // and lies within nodeShape
1003 // @todo enable warning WRITE_WARNING(error + " (laneShape lies within nodeShape)");
1004 return laneShape;
1005 }
1006}
1007
1008
1009const PositionVector&
1011 return myLanes[i].shape;
1012}
1013
1014
1015void
1019
1020
1025
1026
1027void
1029 if (index >= 0) {
1030 myGeom.insert(myGeom.begin() + index, p);
1031 } else {
1032 myGeom.insert(myGeom.end() + index, p);
1033 }
1034}
1035
1036
1037void
1038NBEdge::reduceGeometry(const double minDist) {
1039 // attempt symmetrical removal for forward and backward direction
1040 // (very important for bidiRail)
1041 if (myFrom->getID() < myTo->getID()) {
1042 PositionVector reverse = myGeom.reverse();
1043 reverse.removeDoublePoints(minDist, true, 0, 0, true);
1044 myGeom = reverse.reverse();
1045 for (Lane& lane : myLanes) {
1046 reverse = lane.customShape.reverse();
1047 reverse.removeDoublePoints(minDist, true, 0, 0, true);
1048 lane.customShape = reverse.reverse();
1049 }
1050 } else {
1051 myGeom.removeDoublePoints(minDist, true, 0, 0, true);
1052 for (Lane& lane : myLanes) {
1053 lane.customShape.removeDoublePoints(minDist, true, 0, 0, true);
1054 }
1055 }
1056}
1057
1058
1059void
1060NBEdge::checkGeometry(const double maxAngle, bool fixAngle, const double minRadius, bool fix, bool silent) {
1061 if (myGeom.size() < 3) {
1062 return;
1063 }
1064 //std::cout << "checking geometry of " << getID() << " geometry = " << toString(myGeom) << "\n";
1065 std::vector<double> angles; // absolute segment angles
1066 //std::cout << " absolute angles:";
1067 for (int i = 0; i < (int)myGeom.size() - 1; ++i) {
1068 angles.push_back(myGeom.angleAt2D(i));
1069 //std::cout << " " << angles.back();
1070 }
1071 //std::cout << "\n relative angles: ";
1072 NBEdge* bidi = const_cast<NBEdge*>(getBidiEdge());
1073 for (int i = 0; i < (int)angles.size() - 1; ++i) {
1074 const double relAngle = fabs(GeomHelper::angleDiff(angles[i], angles[i + 1]));
1075 //std::cout << relAngle << " ";
1076 if (maxAngle > 0 && relAngle > maxAngle) {
1077 if (fixAngle) {
1078 WRITE_MESSAGEF(TL("Removing sharp angle of % degrees at edge '%', segment %."),
1079 toString(relAngle), getID(), i);
1080 myGeom.erase(myGeom.begin() + i + 1);
1081 if (bidi != nullptr) {
1082 bidi->myGeom = myGeom.reverse();
1083 }
1084 checkGeometry(maxAngle, fixAngle, minRadius, fix, silent);
1085 return;
1086 } else if (!silent) {
1087 WRITE_WARNINGF(TL("Found angle of % degrees at edge '%', segment %."), RAD2DEG(relAngle), getID(), i);
1088 }
1089 }
1090 if (relAngle < DEG2RAD(1)) {
1091 continue;
1092 }
1093 if (i == 0 || i == (int)angles.size() - 2) {
1094 const bool start = i == 0;
1095 const double dist = (start ? myGeom[0].distanceTo2D(myGeom[1]) : myGeom[-2].distanceTo2D(myGeom[-1]));
1096 const double r = tan(0.5 * (M_PI - relAngle)) * dist;
1097 //std::cout << (start ? " start" : " end") << " length=" << dist << " radius=" << r << " ";
1098 if (minRadius > 0 && r < minRadius) {
1099 if (fix) {
1100 WRITE_MESSAGEF(TL("Removing sharp turn with radius % at the % of edge '%'."),
1101 toString(r), start ? TL("start") : TL("end"), getID());
1102 myGeom.erase(myGeom.begin() + (start ? 1 : i + 1));
1103 if (bidi != nullptr) {
1104 bidi->myGeom = myGeom.reverse();
1105 }
1106 checkGeometry(maxAngle, fixAngle, minRadius, fix, silent);
1107 return;
1108 } else if (!silent) {
1109 WRITE_WARNINGF(TL("Found sharp turn with radius % at the % of edge '%'."),
1110 toString(r), start ? TL("start") : TL("end"), getID());
1111 }
1112 }
1113 }
1114 }
1115 //std::cout << "\n";
1116}
1117
1118
1119// ----------- Setting and getting connections
1120bool
1121NBEdge::addEdge2EdgeConnection(NBEdge* dest, bool overrideRemoval, SVCPermissions permissions) {
1123 return true;
1124 }
1125 // check whether the node was merged and now a connection between
1126 // not matching edges is tried to be added
1127 // This happens f.e. within the ptv VISSIM-example "Beijing"
1128 if (dest != nullptr && myTo != dest->myFrom) {
1129 return false;
1130 }
1131 if (dest == nullptr) {
1133 myConnections.push_back(Connection(-1, dest, -1));
1135 } else if (find_if(myConnections.begin(), myConnections.end(), connections_toedge_finder(dest)) == myConnections.end()) {
1136 myConnections.push_back(Connection(-1, dest, -1));
1137 myConnections.back().permissions = permissions;
1138 }
1139 if (overrideRemoval) {
1140 // override earlier delete decision
1141 for (std::vector<Connection>::iterator it = myConnectionsToDelete.begin(); it != myConnectionsToDelete.end();) {
1142 if (it->toEdge == dest) {
1143 it = myConnectionsToDelete.erase(it);
1144 } else {
1145 it++;
1146 }
1147 }
1148 }
1151 }
1152 return true;
1153}
1154
1155
1156bool
1158 int toLane, Lane2LaneInfoType type,
1159 bool mayUseSameDestination,
1160 bool mayDefinitelyPass,
1161 KeepClear keepClear,
1162 double contPos,
1163 double visibility,
1164 double speed,
1165 double friction,
1166 double length,
1167 const PositionVector& customShape,
1168 bool uncontrolled,
1169 SVCPermissions permissions,
1170 bool indirectLeft,
1171 const std::string& edgeType,
1172 SVCPermissions changeLeft,
1173 SVCPermissions changeRight,
1174 bool postProcess) {
1176 return true;
1177 }
1178 // check whether the node was merged and now a connection between
1179 // not matching edges is tried to be added
1180 // This happens f.e. within the ptv VISSIM-example "Beijing"
1181 if (myTo != dest->myFrom) {
1182 return false;
1183 }
1184 if (!addEdge2EdgeConnection(dest)) {
1185 return false;
1186 }
1187 return setConnection(from, dest, toLane, type, mayUseSameDestination, mayDefinitelyPass, keepClear, contPos, visibility, speed, friction, length,
1188 customShape, uncontrolled, permissions, indirectLeft, edgeType, changeLeft, changeRight, postProcess);
1189}
1190
1191
1192bool
1194 NBEdge* dest, int toLane,
1195 int no, Lane2LaneInfoType type,
1196 bool invalidatePrevious,
1197 bool mayDefinitelyPass) {
1198 if (invalidatePrevious) {
1200 }
1201 bool ok = true;
1202 for (int i = 0; i < no && ok; i++) {
1203 ok &= addLane2LaneConnection(fromLane + i, dest, toLane + i, type, false, mayDefinitelyPass);
1204 }
1205 return ok;
1206}
1207
1208
1209bool
1210NBEdge::setConnection(int lane, NBEdge* destEdge,
1211 int destLane, Lane2LaneInfoType type,
1212 bool mayUseSameDestination,
1213 bool mayDefinitelyPass,
1214 KeepClear keepClear,
1215 double contPos,
1216 double visibility,
1217 double speed,
1218 double friction,
1219 double length,
1220 const PositionVector& customShape,
1221 bool uncontrolled,
1222 SVCPermissions permissions,
1223 bool indirectLeft,
1224 const std::string& edgeType,
1225 SVCPermissions changeLeft,
1226 SVCPermissions changeRight,
1227 bool postProcess) {
1229 return false;
1230 }
1231 // some kind of a misbehavior which may occur when the junction's outgoing
1232 // edge priorities were not properly computed, what may happen due to
1233 // an incomplete or not proper input
1234 // what happens is that under some circumstances a single lane may set to
1235 // be approached more than once by the one of our lanes.
1236 // This must not be!
1237 // we test whether it is the case and do nothing if so - the connection
1238 // will be refused
1239 //
1240 if (!mayUseSameDestination && hasConnectionTo(destEdge, destLane)) {
1241 return false;
1242 }
1243 if (find_if(myConnections.begin(), myConnections.end(), connections_finder(lane, destEdge, destLane)) != myConnections.end()) {
1244 return true;
1245 }
1246 if ((int)myLanes.size() <= lane || destEdge->getNumLanes() <= (int)destLane) {
1247 // problem might be corrigible in post-processing
1248 WRITE_WARNINGF(TL("Could not set connection from '%' to '%'."), getLaneID(lane), destEdge->getLaneID(destLane));
1249 return false;
1250 }
1251 for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end();) {
1252 if ((*i).toEdge == destEdge && ((*i).fromLane == -1 || (*i).toLane == -1)) {
1253 if (permissions == SVC_UNSPECIFIED) {
1254 // @note: in case we were to add multiple connections from the
1255 // same lane the second one wouldn't get the special permissions!
1256 permissions = (*i).permissions;
1257 }
1258 i = myConnections.erase(i);
1259 } else {
1260 ++i;
1261 }
1262 }
1263 myConnections.push_back(Connection(lane, destEdge, destLane));
1264 if (mayDefinitelyPass) {
1265 myConnections.back().mayDefinitelyPass = true;
1266 }
1267 myConnections.back().keepClear = keepClear;
1268 myConnections.back().contPos = contPos;
1269 myConnections.back().visibility = visibility;
1270 myConnections.back().permissions = permissions;
1271 myConnections.back().indirectLeft = indirectLeft;
1272 myConnections.back().edgeType = edgeType;
1273 myConnections.back().changeLeft = changeLeft;
1274 myConnections.back().changeRight = changeRight;
1275 myConnections.back().speed = speed;
1276 myConnections.back().friction = friction;
1277 myConnections.back().customLength = length;
1278 myConnections.back().customShape = customShape;
1279 myConnections.back().uncontrolled = uncontrolled;
1280 if (type == Lane2LaneInfoType::USER) {
1282 } else {
1283 // check whether we have to take another look at it later
1284 if (type == Lane2LaneInfoType::COMPUTED) {
1285 // yes, the connection was set using an algorithm which requires a recheck
1287 } else {
1288 // ok, let's only not recheck it if we did no add something that has to be rechecked
1291 }
1292 }
1293 }
1294 if (postProcess) {
1295 // override earlier delete decision
1296 for (std::vector<Connection>::iterator it = myConnectionsToDelete.begin(); it != myConnectionsToDelete.end();) {
1297 if ((it->fromLane < 0 || it->fromLane == lane)
1298 && (it->toEdge == nullptr || it->toEdge == destEdge)
1299 && (it->toLane < 0 || it->toLane == destLane)) {
1300 it = myConnectionsToDelete.erase(it);
1301 } else {
1302 it++;
1303 }
1304 }
1305 }
1306 return true;
1307}
1308
1309
1310std::vector<NBEdge::Connection>
1311NBEdge::getConnectionsFromLane(int lane, const NBEdge* to, int toLane) const {
1312 std::vector<NBEdge::Connection> ret;
1313 for (const Connection& c : myConnections) {
1314 if ((lane < 0 || c.fromLane == lane)
1315 && (to == nullptr || to == c.toEdge)
1316 && (toLane < 0 || toLane == c.toLane)) {
1317 ret.push_back(c);
1318 }
1319 }
1320 return ret;
1321}
1322
1323
1324const NBEdge::Connection&
1325NBEdge::getConnection(int fromLane, const NBEdge* to, int toLane) const {
1326 for (const Connection& c : myConnections) {
1327 if (c.fromLane == fromLane && c.toEdge == to && c.toLane == toLane) {
1328 return c;
1329 }
1330 }
1331 throw ProcessError("Connection from " + getID() + "_" + toString(fromLane)
1332 + " to " + to->getID() + "_" + toString(toLane) + " not found");
1333}
1334
1335
1337NBEdge::getConnectionRef(int fromLane, const NBEdge* to, int toLane) {
1338 for (Connection& c : myConnections) {
1339 if (c.fromLane == fromLane && c.toEdge == to && c.toLane == toLane) {
1340 return c;
1341 }
1342 }
1343 throw ProcessError("Connection from " + getID() + "_" + toString(fromLane)
1344 + " to " + to->getID() + "_" + toString(toLane) + " not found");
1345}
1346
1347
1348bool
1349NBEdge::hasConnectionTo(const NBEdge* destEdge, int destLane, int fromLane) const {
1350 return destEdge != nullptr && find_if(myConnections.begin(), myConnections.end(), connections_toedgelane_finder(destEdge, destLane, fromLane)) != myConnections.end();
1351}
1352
1353
1354bool
1355NBEdge::isConnectedTo(const NBEdge* e, const bool ignoreTurnaround) const {
1356 if (!ignoreTurnaround && (e == myTurnDestination)) {
1357 return true;
1358 }
1359 return
1360 find_if(myConnections.begin(), myConnections.end(), connections_toedge_finder(e))
1361 !=
1362 myConnections.end();
1363
1364}
1365
1366
1367const EdgeVector*
1369 // check whether connections exist and if not, use edges from the node
1370 EdgeVector outgoing;
1371 if (myConnections.size() == 0) {
1372 outgoing = myTo->getOutgoingEdges();
1373 } else {
1374 for (std::vector<Connection>::const_iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
1375 if (find(outgoing.begin(), outgoing.end(), (*i).toEdge) == outgoing.end()) {
1376 outgoing.push_back((*i).toEdge);
1377 }
1378 }
1379 }
1380 for (std::vector<Connection>::iterator it = myConnectionsToDelete.begin(); it != myConnectionsToDelete.end(); ++it) {
1381 if (it->fromLane < 0 && it->toLane < 0) {
1382 // found an edge that shall not be connected
1383 EdgeVector::iterator forbidden = std::find(outgoing.begin(), outgoing.end(), it->toEdge);
1384 if (forbidden != outgoing.end()) {
1385 outgoing.erase(forbidden);
1386 }
1387 }
1388 }
1389 // allocate the sorted container
1390 int size = (int) outgoing.size();
1391 EdgeVector* edges = new EdgeVector();
1392 edges->reserve(size);
1393 for (EdgeVector::const_iterator i = outgoing.begin(); i != outgoing.end(); i++) {
1394 NBEdge* outedge = *i;
1395 if (outedge != nullptr && outedge != myTurnDestination) {
1396 edges->push_back(outedge);
1397 }
1398 }
1399 std::sort(edges->begin(), edges->end(), NBContHelper::relative_outgoing_edge_sorter(this));
1400 return edges;
1401}
1402
1403
1406 EdgeVector ret;
1407 for (std::vector<Connection>::const_iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
1408 if (find(ret.begin(), ret.end(), (*i).toEdge) == ret.end()) {
1409 ret.push_back((*i).toEdge);
1410 }
1411 }
1412 return ret;
1413}
1414
1415
1418 EdgeVector ret;
1419 const EdgeVector& candidates = myFrom->getIncomingEdges();
1420 for (EdgeVector::const_iterator i = candidates.begin(); i != candidates.end(); i++) {
1421 if ((*i)->isConnectedTo(this)) {
1422 ret.push_back(*i);
1423 }
1424 }
1425 return ret;
1426}
1427
1428
1429std::vector<int>
1430NBEdge::getConnectionLanes(NBEdge* currentOutgoing, bool withBikes, bool withBusLanes) const {
1431 std::vector<int> ret;
1432 if (currentOutgoing != myTurnDestination) {
1433 for (const Connection& c : myConnections) {
1434 if (c.toEdge == currentOutgoing
1435 && (withBikes || getPermissions(c.fromLane) != SVC_BICYCLE)
1436 && (withBusLanes || getPermissions(c.fromLane) != SVC_BUS)) {
1437 ret.push_back(c.fromLane);
1438 }
1439 }
1440 }
1441 return ret;
1442}
1443
1444
1445void
1449
1450
1451void
1455
1456
1457void
1459 EdgeVector connected = getConnectedEdges();
1460 for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
1461 NBEdge* inc = *i;
1462 // We have to do this
1464 // add all connections
1465 for (EdgeVector::iterator j = connected.begin(); j != connected.end(); j++) {
1466 inc->addEdge2EdgeConnection(*j);
1467 }
1468 inc->removeFromConnections(this);
1469 }
1470}
1471
1472
1473void
1474NBEdge::removeFromConnections(NBEdge* toEdge, int fromLane, int toLane, bool tryLater, const bool adaptToLaneRemoval,
1475 const bool keepPossibleTurns) {
1476 // remove from "myConnections"
1477 const int fromLaneRemoved = adaptToLaneRemoval && fromLane >= 0 ? fromLane : -1;
1478 const int toLaneRemoved = adaptToLaneRemoval && toLane >= 0 ? toLane : -1;
1479 for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end();) {
1480 Connection& c = *i;
1481 if ((toEdge == nullptr || c.toEdge == toEdge)
1482 && (fromLane < 0 || c.fromLane == fromLane)
1483 && (toLane < 0 || c.toLane == toLane)) {
1484 if (myTo->isTLControlled()) {
1485 std::set<NBTrafficLightDefinition*> tldefs = myTo->getControllingTLS();
1486 for (std::set<NBTrafficLightDefinition*>::iterator it = tldefs.begin(); it != tldefs.end(); it++) {
1487 (*it)->removeConnection(NBConnection(this, c.fromLane, c.toEdge, c.toLane));
1488 }
1489 }
1490 i = myConnections.erase(i);
1491 tryLater = false;
1492 } else {
1493 if (fromLaneRemoved >= 0 && c.fromLane > fromLaneRemoved) {
1494 if (myTo->isTLControlled()) {
1495 std::set<NBTrafficLightDefinition*> tldefs = myTo->getControllingTLS();
1496 for (std::set<NBTrafficLightDefinition*>::iterator it = tldefs.begin(); it != tldefs.end(); it++) {
1497 for (NBConnectionVector::iterator tlcon = (*it)->getControlledLinks().begin(); tlcon != (*it)->getControlledLinks().end(); ++tlcon) {
1498 NBConnection& tc = *tlcon;
1499 if (tc.getTo() == c.toEdge && tc.getFromLane() == c.fromLane && tc.getToLane() == c.toLane) {
1500 tc.shiftLaneIndex(this, -1);
1501 }
1502 }
1503 }
1504 }
1505 //std::cout << getID() << " removeFromConnections fromLane=" << fromLane << " to=" << Named::getIDSecure(toEdge) << " toLane=" << toLane << " reduceFromLane=" << c.fromLane << " (to=" << c.toLane << ")\n";
1506 c.fromLane--;
1507 }
1508 if (toLaneRemoved >= 0 && c.toLane > toLaneRemoved && (toEdge == nullptr || c.toEdge == toEdge)) {
1509 //std::cout << getID() << " removeFromConnections fromLane=" << fromLane << " to=" << Named::getIDSecure(toEdge) << " toLane=" << toLane << " reduceToLane=" << c.toLane << " (from=" << c.fromLane << ")\n";
1510 c.toLane--;
1511 }
1512 ++i;
1513 }
1514 }
1515 // check whether it was the turn destination
1516 if (myTurnDestination == toEdge && fromLane < 0) {
1517 myTurnDestination = nullptr;
1518 }
1519 if (myPossibleTurnDestination == toEdge && fromLane < 0 && !keepPossibleTurns) {
1520 myPossibleTurnDestination = nullptr;
1521 }
1522 if (tryLater) {
1523 myConnectionsToDelete.push_back(Connection(fromLane, toEdge, toLane));
1524#ifdef DEBUG_CONNECTION_GUESSING
1525 if (DEBUGCOND) {
1526 std::cout << "removeFromConnections " << getID() << "_" << fromLane << "->" << toEdge->getID() << "_" << toLane << "\n";
1527 for (Connection& c : myConnections) {
1528 std::cout << " conn " << c.getDescription(this) << "\n";
1529 }
1531 std::cout << " connToDelete " << c.getDescription(this) << "\n";
1532 }
1533 }
1534#endif
1535 }
1536}
1537
1538
1539bool
1541 // iterate over connections
1542 for (auto i = myConnections.begin(); i != myConnections.end(); i++) {
1543 if ((i->toEdge == connectionToRemove.toEdge) && (i->fromLane == connectionToRemove.fromLane) && (i->toLane == connectionToRemove.toLane)) {
1544 // remove connection
1545 myConnections.erase(i);
1546 return true;
1547 }
1548 }
1549 // assert(false);
1550 return false;
1551}
1552
1553
1554void
1555NBEdge::invalidateConnections(bool reallowSetting) {
1556 myTurnDestination = nullptr;
1557 myConnections.clear();
1558 if (reallowSetting) {
1560 } else {
1562 }
1563}
1564
1565
1566void
1567NBEdge::replaceInConnections(NBEdge* which, NBEdge* by, int laneOff) {
1568 // replace in "_connectedEdges"
1569 for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
1570 if ((*i).toEdge == which) {
1571 (*i).toEdge = by;
1572 (*i).toLane += laneOff;
1573 }
1574 }
1575 // check whether it was the turn destination
1576 if (myTurnDestination == which) {
1577 myTurnDestination = by;
1578 }
1579}
1580
1581void
1582NBEdge::replaceInConnections(NBEdge* which, const std::vector<NBEdge::Connection>& origConns) {
1583 std::map<int, int> laneMap;
1584 int minLane = -1;
1585 int maxLane = -1;
1586 // get lanes used to approach the edge to remap
1587 bool wasConnected = false;
1588 for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
1589 if ((*i).toEdge != which) {
1590 continue;
1591 }
1592 wasConnected = true;
1593 if ((*i).fromLane != -1) {
1594 int fromLane = (*i).fromLane;
1595 laneMap[(*i).toLane] = fromLane;
1596 if (minLane == -1 || minLane > fromLane) {
1597 minLane = fromLane;
1598 }
1599 if (maxLane == -1 || maxLane < fromLane) {
1600 maxLane = fromLane;
1601 }
1602 }
1603 }
1604 if (!wasConnected) {
1605 return;
1606 }
1607 // add new connections
1608 std::vector<NBEdge::Connection> conns = origConns;
1609 EdgeVector origTargets = getSuccessors();
1610 for (std::vector<NBEdge::Connection>::iterator i = conns.begin(); i != conns.end(); ++i) {
1611 if ((*i).toEdge == which || (*i).toEdge == this
1612 // if we already have connections to the target edge, do not add new ones as they are probably from a circular replacement
1613 || std::find(origTargets.begin(), origTargets.end(), (*i).toEdge) != origTargets.end()) {
1614#ifdef DEBUG_REPLACECONNECTION
1615 if (DEBUGCOND) {
1616 std::cout << " replaceInConnections edge=" << getID() << " which=" << which->getID()
1617 << " origTargets=" << toString(origTargets) << " newTarget=" << i->toEdge->getID() << " skipped\n";
1618 }
1619#endif
1620 continue;
1621 }
1622 if (which->getStep() == EdgeBuildingStep::EDGE2EDGES) {
1623 // do not set lane-level connections
1624 replaceInConnections(which, (*i).toEdge, 0);
1625 continue;
1626 }
1627 int fromLane = (*i).fromLane;
1628 int toUse = -1;
1629 if (laneMap.find(fromLane) == laneMap.end()) {
1630 if (fromLane >= 0 && fromLane <= minLane) {
1631 toUse = minLane;
1632 // patch laneMap to avoid crossed-over connections
1633 for (auto& item : laneMap) {
1634 if (item.first < fromLane) {
1635 item.second = MIN2(item.second, minLane);
1636 }
1637 }
1638 }
1639 if (fromLane >= 0 && fromLane >= maxLane) {
1640 toUse = maxLane;
1641 // patch laneMap to avoid crossed-over connections
1642 for (auto& item : laneMap) {
1643 if (item.first > fromLane) {
1644 item.second = MAX2(item.second, maxLane);
1645 }
1646 }
1647 }
1648 } else {
1649 toUse = laneMap[fromLane];
1650 }
1651 if (toUse == -1) {
1652 toUse = 0;
1653 }
1654#ifdef DEBUG_REPLACECONNECTION
1655 if (DEBUGCOND) {
1656 std::cout << " replaceInConnections edge=" << getID() << " which=" << which->getID() << " origTargets=" << toString(origTargets)
1657 << " origFrom=" << fromLane << " laneMap=" << joinToString(laneMap, ":", ",") << " minLane=" << minLane << " maxLane=" << maxLane
1658 << " newTarget=" << i->toEdge->getID() << " fromLane=" << toUse << " toLane=" << i->toLane << "\n";
1659 }
1660#endif
1661 setConnection(toUse, i->toEdge, i->toLane, Lane2LaneInfoType::COMPUTED, false, i->mayDefinitelyPass, i->keepClear,
1662 i->contPos, i->visibility, i->speed, i->friction, i->customLength, i->customShape, i->uncontrolled);
1663 }
1664 // remove the remapped edge from connections
1665 removeFromConnections(which);
1666}
1667
1668
1669void
1674
1675
1676bool
1677NBEdge::canMoveConnection(const Connection& con, int newFromLane) const {
1678 // only allow using newFromLane if at least 1 vClass is permitted to use
1679 // this connection. If the connection shall be moved to a sidewalk, only create the connection if there is no walking area
1680 const SVCPermissions common = (getPermissions(newFromLane) & con.toEdge->getPermissions(con.toLane));
1681 return (common > 0 && common != SVC_PEDESTRIAN);
1682}
1683
1684
1685void
1687#ifdef DEBUG_CONNECTION_CHECKING
1688 std::cout << " moveConnectionToLeft " << getID() << " lane=" << lane << "\n";
1689#endif
1690 int index = 0;
1691 for (int i = 0; i < (int)myConnections.size(); ++i) {
1692 if (myConnections[i].fromLane == (int)(lane) && canMoveConnection(myConnections[i], lane + 1)) {
1693 index = i;
1694 }
1695 }
1696 std::vector<Connection>::iterator i = myConnections.begin() + index;
1697 Connection c = *i;
1698 myConnections.erase(i);
1700}
1701
1702
1703void
1705#ifdef DEBUG_CONNECTION_CHECKING
1706 std::cout << " moveConnectionToRight " << getID() << " lane=" << lane << "\n";
1707#endif
1708 for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
1709 if ((*i).fromLane == (int)lane && canMoveConnection(*i, lane - 1)) {
1710 Connection c = *i;
1711 i = myConnections.erase(i);
1713 return;
1714 }
1715 }
1716}
1717
1718
1719double
1720NBEdge::buildInnerEdges(const NBNode& n, int noInternalNoSplits, int& linkIndex, int& splitIndex) {
1722 const int numPoints = oc.getInt("junctions.internal-link-detail");
1723 const bool joinTurns = oc.getBool("junctions.join-turns");
1724 const double limitTurnSpeed = oc.getFloat("junctions.limit-turn-speed");
1725 const double limitTurnSpeedMinAngle = DEG2RAD(oc.getFloat("junctions.limit-turn-speed.min-angle"));
1726 const double limitTurnSpeedMinAngleRail = DEG2RAD(oc.getFloat("junctions.limit-turn-speed.min-angle.railway"));
1727 const double limitTurnSpeedWarnStraight = oc.getFloat("junctions.limit-turn-speed.warn.straight");
1728 const double limitTurnSpeedWarnTurn = oc.getFloat("junctions.limit-turn-speed.warn.turn");
1729 const bool higherSpeed = oc.getBool("junctions.higher-speed");
1730 const double interalJunctionVehicleWidth = oc.getFloat("internal-junctions.vehicle-width");
1731 const double defaultContPos = oc.getFloat("default.connection.cont-pos");
1732 const bool fromRail = isRailway(getPermissions());
1733 std::string innerID = ":" + n.getID();
1734 NBEdge* toEdge = nullptr;
1735 int edgeIndex = linkIndex;
1736 int internalLaneIndex = 0;
1737 int numLanes = 0; // number of lanes that share the same edge
1738 double lengthSum = 0; // total shape length of all lanes that share the same edge
1739 int avoidedIntersectingLeftOriginLane = std::numeric_limits<int>::max();
1740 bool averageLength = true;
1741 double maxCross = 0.;
1742 for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
1743 Connection& con = *i;
1744 con.haveVia = false; // reset first since this may be called multiple times
1745 if (con.toEdge == nullptr) {
1746 continue;
1747 }
1748 LinkDirection dir = n.getDirection(this, con.toEdge);
1749 const bool isRightTurn = (dir == LinkDirection::RIGHT || dir == LinkDirection::PARTRIGHT);
1750 const bool isTurn = (isRightTurn || dir == LinkDirection::LEFT || dir == LinkDirection::PARTLEFT);
1751 // put turning internal lanes on separate edges
1752 if (con.toEdge != toEdge) {
1753 // skip indices to keep some correspondence between edge ids and link indices:
1754 // internalEdgeIndex + internalLaneIndex = linkIndex
1755 edgeIndex = linkIndex;
1756 toEdge = con.toEdge;
1757 internalLaneIndex = 0;
1758 maxCross = MAX2(maxCross, assignInternalLaneLength(i, numLanes, lengthSum, averageLength));
1759 numLanes = 0;
1760 lengthSum = 0;
1761 }
1762 averageLength = !isTurn || joinTurns; // legacy behavior
1763 SVCPermissions conPermissions = getPermissions(con.fromLane) & con.toEdge->getPermissions(con.toLane);
1764 const int conShapeFlag = (conPermissions & ~SVC_PEDESTRIAN) != 0 ? 0 : NBNode::SCURVE_IGNORE;
1765 PositionVector shape = n.computeInternalLaneShape(this, con, numPoints, myTo, conShapeFlag);
1766 std::vector<int> foeInternalLinks;
1767
1768 if (dir != LinkDirection::STRAIGHT && shape.length() < POSITION_EPS && !(isBidiRail() && getTurnDestination(true) == con.toEdge)) {
1769 WRITE_WARNINGF(TL("Connection '%_%->%_%' is only %m short."), getID(), con.fromLane, con.toEdge->getID(), con.toLane, shape.length());
1770 }
1771
1772 // crossingPosition, list of foe link indices
1773 std::pair<double, std::vector<int> > crossingPositions(-1, std::vector<int>());
1774 std::set<std::string> tmpFoeIncomingLanes;
1776 int index = 0;
1777 std::vector<PositionVector> otherShapes;
1778 const double width1 = MIN2(interalJunctionVehicleWidth / 2, getLaneWidth(con.fromLane) / 2);
1779 const double width1OppositeLeft = 0; // using width1 changes a lot of curves even though they are rarely responsible for collisions
1780 for (const NBEdge* i2 : n.getIncomingEdges()) {
1781 for (const Connection& k2 : i2->getConnections()) {
1782 if (k2.toEdge == nullptr) {
1783 continue;
1784 }
1785 // vehicles are typically less wide than the lane
1786 // they drive on but but bicycle lanes should be kept clear for their whole width
1787 double width2 = k2.toEdge->getLaneWidth(k2.toLane);
1788 if (k2.toEdge->getPermissions(k2.toLane) != SVC_BICYCLE) {
1789 width2 *= 0.5;
1790 }
1791 const bool foes = n.foes(this, con.toEdge, i2, k2.toEdge);
1792 LinkDirection dir2 = n.getDirection(i2, k2.toEdge);
1793 bool needsCont = !isRailway(conPermissions) && (n.needsCont(this, i2, con, k2) || (con.contPos != UNSPECIFIED_CONTPOS && !con.indirectLeft));
1794 const bool avoidIntersectCandidate = !foes && bothLeftTurns(dir, i2, dir2);
1795 bool oppositeLeftIntersect = avoidIntersectCandidate && haveIntersection(n, shape, i2, k2, numPoints, width1OppositeLeft, width2);
1796 int shapeFlag = 0;
1798 // do not warn if only bicycles, pedestrians or delivery vehicles are involved as this is a typical occurrence
1799 if (con.customShape.size() == 0
1800 && k2.customShape.size() == 0
1801 && (oppositeLeftIntersect || (avoidedIntersectingLeftOriginLane < con.fromLane && avoidIntersectCandidate))
1802 && ((i2->getPermissions(k2.fromLane) & warn) != 0
1803 && (k2.toEdge->getPermissions(k2.toLane) & warn) != 0)) {
1804 // recompute with different curve parameters (unless
1805 // the other connection is "unimportant"
1807 PositionVector origShape = shape;
1808 shape = n.computeInternalLaneShape(this, con, numPoints, myTo, shapeFlag);
1809 oppositeLeftIntersect = haveIntersection(n, shape, i2, k2, numPoints, width1OppositeLeft, width2, shapeFlag);
1810 if (oppositeLeftIntersect
1811 && (conPermissions & (SVCAll & ~(SVC_BICYCLE | SVC_PEDESTRIAN))) == 0) {
1812 shape = origShape;
1813 } else {
1814 // recompute previously computed crossing positions
1815 if (avoidedIntersectingLeftOriginLane == std::numeric_limits<int>::max()
1816 || avoidedIntersectingLeftOriginLane < con.fromLane) {
1817 for (const PositionVector& otherShape : otherShapes) {
1818 const bool secondIntersection = con.indirectLeft && this == i2 && con.fromLane == k2.fromLane;
1819 const double minDV = firstIntersection(shape, otherShape, width1OppositeLeft, width2,
1820 "Could not compute intersection of conflicting internal lanes at node '" + myTo->getID() + "'", secondIntersection);
1821 if (minDV < shape.length() - POSITION_EPS && minDV > POSITION_EPS) { // !!!?
1822 assert(minDV >= 0);
1823 if (crossingPositions.first < 0 || crossingPositions.first > minDV) {
1824 crossingPositions.first = minDV;
1825 }
1826 }
1827 }
1828 }
1829 // make sure connections further to the left do not get a wider angle
1830 avoidedIntersectingLeftOriginLane = con.fromLane;
1831 }
1832 }
1833 const bool bothPrio = getJunctionPriority(&n) > 0 && i2->getJunctionPriority(&n) > 0;
1834 //std::cout << "n=" << n.getID() << " e1=" << getID() << " prio=" << getJunctionPriority(&n) << " e2=" << i2->getID() << " prio2=" << i2->getJunctionPriority(&n) << " both=" << bothPrio << " bothLeftIntersect=" << bothLeftIntersect(n, shape, dir, i2, k2, numPoints, width2) << " needsCont=" << needsCont << "\n";
1835 // the following special case might get obsolete once we have solved #9745
1836 const bool isBicycleLeftTurn = k2.indirectLeft || (dir2 == LinkDirection::LEFT && (i2->getPermissions(k2.fromLane) & k2.toEdge->getPermissions(k2.toLane)) == SVC_BICYCLE);
1837 // compute the crossing point
1838 if ((needsCont || (bothPrio && oppositeLeftIntersect && !isRailway(conPermissions))) && (!con.indirectLeft || dir2 == LinkDirection::STRAIGHT) && !isBicycleLeftTurn) {
1839 crossingPositions.second.push_back(index);
1840 const PositionVector otherShape = n.computeInternalLaneShape(i2, k2, numPoints, 0, shapeFlag);
1841 otherShapes.push_back(otherShape);
1842 const bool secondIntersection = con.indirectLeft && this == i2 && con.fromLane == k2.fromLane;
1843 const double minDV = firstIntersection(shape, otherShape, width1, width2,
1844 "Could not compute intersection of conflicting internal lanes at node '" + myTo->getID() + "'", secondIntersection);
1845 if (minDV < shape.length() - POSITION_EPS && minDV > POSITION_EPS) { // !!!?
1846 assert(minDV >= 0);
1847 if (crossingPositions.first < 0 || crossingPositions.first > minDV) {
1848 crossingPositions.first = minDV;
1849 }
1850 }
1851 }
1852 const bool rightTurnConflict = NBNode::rightTurnConflict(
1853 this, con.toEdge, con.fromLane, i2, k2.toEdge, k2.fromLane);
1854 const bool indirectTurnConflit = con.indirectLeft && this == i2 && (dir2 == LinkDirection::STRAIGHT ||
1855 (con.fromLane < k2.fromLane && (dir2 == LinkDirection::RIGHT || dir2 == LinkDirection::PARTRIGHT)));
1856 const bool mergeConflict = myTo->mergeConflict(this, con, i2, k2, true);
1857 const bool mergeResponse = myTo->mergeConflict(this, con, i2, k2, false);
1858 const bool bidiConflict = myTo->bidiConflict(this, con, i2, k2, true);
1859 // compute foe internal lanes
1860 if (foes || rightTurnConflict || oppositeLeftIntersect || mergeConflict || indirectTurnConflit || bidiConflict) {
1861 foeInternalLinks.push_back(index);
1862 }
1863 // only warn once per pair of intersecting turns
1864 if (oppositeLeftIntersect && getID() > i2->getID()
1865 && (getPermissions(con.fromLane) & warn) != 0
1866 && (con.toEdge->getPermissions(con.toLane) & warn) != 0
1867 && (i2->getPermissions(k2.fromLane) & warn) != 0
1868 && (k2.toEdge->getPermissions(k2.toLane) & warn) != 0
1869 // do not warn for unregulated nodes
1871 ) {
1872 WRITE_WARNINGF(TL("Intersecting left turns at junction '%' from lane '%' and lane '%' (increase junction radius to avoid this)."),
1873 n.getID(), getLaneID(con.fromLane), i2->getLaneID(k2.fromLane));
1874 }
1875 // compute foe incoming lanes
1876 const bool signalised = hasSignalisedConnectionTo(con.toEdge);
1877 if ((n.forbids(i2, k2.toEdge, this, con.toEdge, signalised) || rightTurnConflict || indirectTurnConflit || mergeResponse)
1878 && (needsCont || dir == LinkDirection::TURN || (!signalised && this != i2 && !con.indirectLeft))) {
1879 tmpFoeIncomingLanes.insert(i2->getID() + "_" + toString(k2.fromLane));
1880 }
1881 if (bothPrio && oppositeLeftIntersect && getID() < i2->getID()) {
1882 //std::cout << " c1=" << con.getDescription(this) << " c2=" << k2.getDescription(i2) << " bothPrio=" << bothPrio << " oppositeLeftIntersect=" << oppositeLeftIntersect << "\n";
1883 // break symmetry using edge id
1884 // only store link index and resolve actual lane id later (might be multi-lane internal edge)
1885 tmpFoeIncomingLanes.insert(":" + toString(index));
1886 }
1887 index++;
1888 }
1889 }
1890 if (dir == LinkDirection::TURN && crossingPositions.first < 0 && crossingPositions.second.size() != 0 && shape.length() > 2. * POSITION_EPS) {
1891 // let turnarounds wait in the middle if no other crossing point was found and it has a sensible length
1892 // (if endOffset is used, the crossing point is in the middle of the part within the junction shape)
1893 crossingPositions.first = (double)(shape.length() + getEndOffset(con.fromLane)) / 2.;
1894 }
1895 // foe pedestrian crossings
1896 std::vector<NBNode::Crossing*> crossings = n.getCrossings();
1897 for (auto c : crossings) {
1898 const NBNode::Crossing& crossing = *c;
1899 for (EdgeVector::const_iterator it_e = crossing.edges.begin(); it_e != crossing.edges.end(); ++it_e) {
1900 const NBEdge* edge = *it_e;
1901 // compute foe internal lanes
1902 if ((this == edge || con.toEdge == edge) && !isRailway(conPermissions)) {
1903 foeInternalLinks.push_back(index);
1904 if (con.toEdge == edge &&
1905 ((isRightTurn && getJunctionPriority(&n) > 0) || (isTurn && con.tlID != ""))) {
1906 // build internal junctions (not for left turns at uncontrolled intersections)
1907 PositionVector crossingShape = crossing.shape;
1908 crossingShape.extrapolate(5.0); // sometimes shapes miss each other by a small margin
1909 const double minDV = firstIntersection(shape, crossingShape, 0, crossing.width / 2);
1910 if (minDV < shape.length() - POSITION_EPS && minDV > POSITION_EPS) {
1911 assert(minDV >= 0);
1912 if (crossingPositions.first < 0 || crossingPositions.first > minDV) {
1913 crossingPositions.first = minDV;
1914 }
1915 }
1916 } else if (this == edge && crossing.priority && !myTo->isTLControlled()) {
1917 crossingPositions.first = 0;
1918 }
1919 }
1920 }
1921 index++;
1922 }
1923
1924 }
1925 if (con.contPos == UNSPECIFIED_CONTPOS) {
1926 con.contPos = defaultContPos;
1927 }
1928 if (con.contPos != UNSPECIFIED_CONTPOS) {
1929 // apply custom internal junction position
1930 if (con.contPos <= 0 || con.contPos >= shape.length()) {
1931 // disable internal junction
1932 crossingPositions.first = -1;
1933 } else {
1934 // set custom position
1935 crossingPositions.first = con.contPos;
1936 }
1937 }
1938
1939 // @todo compute the maximum speed allowed based on angular velocity
1940 // see !!! for an explanation (with a_lat_mean ~0.3)
1941 /*
1942 double vmax = (double) 0.3 * (double) 9.80778 *
1943 getLaneShape(con.fromLane).back().distanceTo(
1944 con.toEdge->getLaneShape(con.toLane).front())
1945 / (double) 2.0 / (double) M_PI;
1946 vmax = MIN2(vmax, ((getSpeed() + con.toEdge->getSpeed()) / (double) 2.0));
1947 */
1948 if (con.speed == UNSPECIFIED_SPEED) {
1949 if (higherSpeed) {
1950 con.vmax = MAX2(myLanes[con.fromLane].speed, con.toEdge->getLanes()[con.toLane].speed);
1951 } else {
1952 con.vmax = (myLanes[con.fromLane].speed + con.toEdge->getLanes()[con.toLane].speed) / (double) 2.0;
1953 }
1954 if (limitTurnSpeed > 0) {
1955 // see [Odhams and Cole, Models of Driver Speed Choice in Curves, 2004]
1956 const double angleRaw = fabs(GeomHelper::angleDiff(
1958 con.toEdge->getLaneShape(con.toLane).angleAt2D(0)));
1959 const double angle = MAX2(0.0, angleRaw - (fromRail ? limitTurnSpeedMinAngleRail : limitTurnSpeedMinAngle));
1960 const double length = shape.length2D();
1961 // do not trust the radius of tiny junctions
1962 // formula adapted from [Odhams, Andre and Cole, David, Models of Driver Speed Choice in Curves, 2004]
1963 if (angle > 0 && length > 1) {
1964 // permit higher turning speed on wide lanes
1965 const double radius = length / angle + getLaneWidth(con.fromLane) / 4;
1966 const double limit = sqrt(limitTurnSpeed * radius);
1967 const double reduction = con.vmax - limit;
1968 // always treat connctions at roundabout as turns when warning
1970 const LinkDirection dir2 = atRoundabout ? LinkDirection::LEFT : dir;
1971 if ((dir2 == LinkDirection::STRAIGHT && reduction > limitTurnSpeedWarnStraight)
1972 || (dir2 != LinkDirection::TURN && reduction > limitTurnSpeedWarnTurn)) {
1973 std::string dirType = std::string(dir == LinkDirection::STRAIGHT ? "straight" : "turning");
1974 if (atRoundabout) {
1975 dirType = "roundabout";
1976 }
1977 WRITE_WARNINGF(TL("Speed of % connection '%' reduced by % due to turning radius of % (length=%, angle=%)."),
1978 dirType, con.getDescription(this), reduction, radius, length, RAD2DEG(angleRaw));
1979 }
1980 con.vmax = MIN2(con.vmax, limit);
1981 // value is saved in <net> attribute. Must be set again when importing from .con.xml
1982 // con.speed = con.vmax;
1983 }
1984 assert(con.vmax > 0);
1985 //if (getID() == "-1017000.0.00") {
1986 // std::cout << con.getDescription(this) << " angleRaw=" << angleRaw << " angle=" << RAD2DEG(angle) << " length=" << length << " radius=" << length / angle
1987 // << " vmaxTurn=" << sqrt(limitTurnSpeed * length / angle) << " vmax=" << con.vmax << "\n";
1988 //}
1989 } else if (fromRail && dir == LinkDirection::TURN) {
1990 con.vmax = 0.01;
1991 }
1992 } else {
1993 con.vmax = con.speed;
1994 }
1995 if (con.friction == UNSPECIFIED_FRICTION) {
1996 con.friction = (myLanes[con.fromLane].friction + con.toEdge->getLanes()[con.toLane].friction) / 2.;
1997 }
1998 //
1999 assert(shape.size() >= 2);
2000 // get internal splits if any
2001 con.id = innerID + "_" + toString(edgeIndex);
2002 const double shapeLength = shape.length();
2003 double firstLength = shapeLength;
2004 con.internalViaLaneIndex = 0; // reset to default for netedit
2005 if (crossingPositions.first > 0 && crossingPositions.first < shapeLength) {
2006 std::pair<PositionVector, PositionVector> split = shape.splitAt(crossingPositions.first);
2007 con.shape = split.first;
2008 con.foeIncomingLanes = std::vector<std::string>(tmpFoeIncomingLanes.begin(), tmpFoeIncomingLanes.end());
2009 con.foeInternalLinks = foeInternalLinks; // resolve link indices to lane ids later
2010 if (i != myConnections.begin() && (i - 1)->toEdge == con.toEdge && (i - 1)->haveVia) {
2011 --splitIndex;
2012 con.internalViaLaneIndex = (i - 1)->internalViaLaneIndex + 1;
2013 }
2014 con.viaID = innerID + "_" + toString(splitIndex + noInternalNoSplits);
2015 ++splitIndex;
2016 con.viaShape = split.second;
2017 con.haveVia = true;
2018 firstLength = con.shape.length();
2019 } else {
2020 con.shape = shape;
2021 }
2022 con.internalLaneIndex = internalLaneIndex;
2023 ++internalLaneIndex;
2024 ++linkIndex;
2025 ++numLanes;
2027 // split length proportionally
2028 lengthSum += (shapeLength != 0 ? firstLength / shapeLength : 1) * con.customLength;
2029 } else {
2030 lengthSum += firstLength;
2031 }
2032 }
2033 return MAX2(maxCross, assignInternalLaneLength(myConnections.end(), numLanes, lengthSum, averageLength));
2034}
2035
2036
2037double
2038NBEdge::assignInternalLaneLength(std::vector<Connection>::iterator i, int numLanes, double lengthSum, bool averageLength) {
2039 // assign average length to all lanes of the same internal edge if averageLength is set
2040 // the lengthSum only covers the part up to the first internal junction
2041 // TODO This code assumes that either all connections in question have a via or none
2042 double maxCross = 0.;
2043 assert(i - myConnections.begin() >= numLanes);
2044 for (int prevIndex = 1; prevIndex <= numLanes; prevIndex++) {
2045 //std::cout << " con=" << (*(i - prevIndex)).getDescription(this) << " numLanes=" << numLanes << " avgLength=" << lengthSum / numLanes << "\n";
2046 Connection& c = (*(i - prevIndex));
2047 const double minLength = c.customLength != UNSPECIFIED_LOADED_LENGTH ? pow(10, -gPrecision) : POSITION_EPS;
2048 c.length = MAX2(minLength, averageLength ? lengthSum / numLanes : c.shape.length());
2049 if (c.haveVia) {
2050 c.viaLength = MAX2(minLength, c.viaShape.length());
2051 }
2053 if (c.haveVia) {
2054 // split length proportionally
2055 const double a = c.viaLength / (c.shape.length() + c.viaLength);
2056 c.viaLength = MAX2(minLength, a * c.customLength);
2057 }
2058 if (!averageLength) {
2059 c.length = MAX2(minLength, c.customLength - c.viaLength);
2060 }
2061 }
2062 if (c.haveVia) {
2063 // we need to be able to leave from the internal junction by accelerating from 0
2064 maxCross = MAX2(maxCross, sqrt(2. * c.viaLength)); // t = sqrt(2*s/a) and we assume 'a' is at least 1 (default value for tram in SUMOVTypeParameter)
2065 }
2066 // we need to be able to cross the junction in one go but not if we have an indirect left turn
2067 if (c.indirectLeft) {
2068 maxCross = MAX2(maxCross, MAX2(c.length, c.viaLength) / MAX2(c.vmax, NBOwnTLDef::MIN_SPEED_CROSSING_TIME));
2069 } else {
2070 maxCross = MAX2(maxCross, (c.length + c.viaLength) / MAX2(c.vmax, NBOwnTLDef::MIN_SPEED_CROSSING_TIME));
2071 }
2072 }
2073 return maxCross;
2074}
2075
2076
2077double
2078NBEdge::firstIntersection(const PositionVector& v1, const PositionVector& v2, double width1, double width2, const std::string& error, bool secondIntersection) {
2079 double intersect = std::numeric_limits<double>::max();
2080 if (v2.length() < POSITION_EPS) {
2081 return intersect;
2082 }
2083 try {
2084 PositionVector v1Right = v1;
2085 v1Right.move2side(width1);
2086
2087 PositionVector v1Left = v1;
2088 v1Left.move2side(-width1);
2089
2090 PositionVector v2Right = v2;
2091 v2Right.move2side(width2);
2092
2093 PositionVector v2Left = v2;
2094 v2Left.move2side(-width2);
2095
2096 // intersect all border combinations
2097 bool skip = secondIntersection;
2098 for (double cand : v1Left.intersectsAtLengths2D(v2Right)) {
2099 if (skip) {
2100 skip = false;
2101 continue;
2102 }
2103 intersect = MIN2(intersect, cand);
2104 }
2105 skip = secondIntersection;
2106 for (double cand : v1Left.intersectsAtLengths2D(v2Left)) {
2107 if (skip) {
2108 skip = false;
2109 continue;
2110 }
2111 intersect = MIN2(intersect, cand);
2112 }
2113 skip = secondIntersection;
2114 for (double cand : v1Right.intersectsAtLengths2D(v2Right)) {
2115 if (skip) {
2116 skip = false;
2117 continue;
2118 }
2119 intersect = MIN2(intersect, cand);
2120 }
2121 skip = secondIntersection;
2122 for (double cand : v1Right.intersectsAtLengths2D(v2Left)) {
2123 if (skip) {
2124 skip = false;
2125 continue;
2126 }
2127 intersect = MIN2(intersect, cand);
2128 }
2129 } catch (InvalidArgument&) {
2130 if (error != "") {
2131 WRITE_WARNING(error);
2132 }
2133 }
2134 //std::cout << " v1=" << v1 << " v2Right=" << v2Right << " v2Left=" << v2Left << "\n";
2135 //std::cout << " intersectsRight=" << toString(v1.intersectsAtLengths2D(v2Right)) << "\n";
2136 //std::cout << " intersectsLeft=" << toString(v1.intersectsAtLengths2D(v2Left)) << "\n";
2137 return intersect;
2138}
2139
2140
2141bool
2142NBEdge::bothLeftTurns(LinkDirection dir, const NBEdge* otherFrom, LinkDirection dir2) const {
2143 if (otherFrom == this) {
2144 // not an opposite pair
2145 return false;
2146 }
2147 return (dir == LinkDirection::LEFT || dir == LinkDirection::PARTLEFT) && (dir2 == LinkDirection::LEFT || dir2 == LinkDirection::PARTLEFT);
2148}
2149
2150bool
2151NBEdge::haveIntersection(const NBNode& n, const PositionVector& shape, const NBEdge* otherFrom, const NBEdge::Connection& otherCon, int numPoints,
2152 double width1, double width2, int shapeFlag) const {
2153 const PositionVector otherShape = n.computeInternalLaneShape(otherFrom, otherCon, numPoints, 0, shapeFlag);
2154 const double minDV = firstIntersection(shape, otherShape, width1, width2);
2155 return minDV < shape.length() - POSITION_EPS && minDV > POSITION_EPS;
2156}
2157
2158
2159// -----------
2160int
2162 if (node == myFrom) {
2164 } else {
2165 return myToJunctionPriority;
2166 }
2167}
2168
2169
2170void
2171NBEdge::setJunctionPriority(const NBNode* const node, int prio) {
2172 if (node == myFrom) {
2174#ifdef DEBUG_JUNCTIONPRIO
2175 setParameter("fromPrio", toString(prio));
2176#endif
2177 } else {
2178 myToJunctionPriority = prio;
2179#ifdef DEBUG_JUNCTIONPRIO
2180 setParameter("toPrio", toString(prio));
2181#endif
2182 }
2183}
2184
2185
2186double
2187NBEdge::getAngleAtNode(const NBNode* const atNode) const {
2188 if (atNode == myFrom) {
2190 }
2191 assert(atNode == myTo);
2193}
2194
2195
2196double
2197NBEdge::getAngleAtNodeNormalized(const NBNode* const atNode) const {
2198 double res;
2199 if (atNode == myFrom) {
2201 } else {
2202 assert(atNode == myTo);
2204 }
2205 if (res < 0) {
2206 res += 360;
2207 }
2208 return res;
2209}
2210
2211
2212double
2213NBEdge::getAngleAtNodeToCenter(const NBNode* const atNode) const {
2214 if (atNode == myFrom) {
2215 double res = myStartAngle - 180;
2216 if (res < 0) {
2217 res += 360;
2218 }
2219 return res;
2220 } else {
2221 assert(atNode == myTo);
2222 return myEndAngle;
2223 }
2224}
2225
2226
2227void
2229 if (!onlyPossible) {
2231 }
2233}
2234
2235
2236double
2237NBEdge::getLaneSpeed(int lane) const {
2238 return myLanes[lane].speed;
2239}
2240
2241
2242double
2244 return myLanes[lane].friction;
2245}
2246
2247
2248void
2252
2253
2254void
2256 for (Lane& lane : myLanes) {
2257 if (lane.changeLeft != SVCAll) {
2258 lane.changeLeft = ignoring;
2259 }
2260 if (lane.changeRight != SVCAll) {
2261 lane.changeRight = ignoring;
2262 }
2263 }
2264 for (Connection& con : myConnections) {
2265 if (con.changeLeft != SVC_UNSPECIFIED && con.changeLeft != SVCAll) {
2266 con.changeLeft = ignoring;
2267 }
2268 if (con.changeRight != SVC_UNSPECIFIED && con.changeRight != SVCAll) {
2269 con.changeRight = ignoring;
2270 }
2271 }
2272}
2273
2274
2275void
2277 // vissim needs this
2278 if (myFrom == myTo) {
2279 return;
2280 }
2281 // compute lane offset, first
2282 std::vector<double> offsets(myLanes.size(), 0.);
2283 double offset = 0;
2284 for (int i = (int)myLanes.size() - 2; i >= 0; --i) {
2285 offset += (getLaneWidth(i) + getLaneWidth(i + 1)) / 2.;
2286 offsets[i] = offset;
2287 }
2289 double width = 0;
2290 for (int i = 0; i < (int)myLanes.size(); ++i) {
2291 width += getLaneWidth(i);
2292 }
2293 offset = -width / 2. + getLaneWidth((int)myLanes.size() - 1) / 2.;
2294 } else {
2295 double laneWidth = myLanes.back().width != UNSPECIFIED_WIDTH ? myLanes.back().width : SUMO_const_laneWidth;
2296 offset = laneWidth / 2.;
2297 }
2299 for (NBEdge* e : myTo->getOutgoingEdges()) {
2300 if (e->getToNode() == myFrom && getInnerGeometry().reverse() == e->getInnerGeometry()) {
2301 offset += (e->getTotalWidth() - getTotalWidth()) / 2;
2302 break;
2303 }
2304 }
2305 }
2306
2307 for (int i = 0; i < (int)myLanes.size(); ++i) {
2308 offsets[i] += offset;
2309 }
2310
2311 // build the shape of each lane
2312 for (int i = 0; i < (int)myLanes.size(); ++i) {
2313 if (myLanes[i].customShape.size() != 0) {
2314 myLanes[i].shape = myLanes[i].customShape;
2315 continue;
2316 }
2317 try {
2318 myLanes[i].shape = computeLaneShape(i, offsets[i]);
2319 } catch (InvalidArgument& e) {
2320 WRITE_WARNINGF(TL("In lane '%': lane shape could not be determined (%)."), getLaneID(i), e.what());
2321 myLanes[i].shape = myGeom;
2322 }
2323 }
2324}
2325
2326
2328NBEdge::computeLaneShape(int lane, double offset) const {
2329 PositionVector shape = myGeom;
2330 try {
2331 shape.move2side(offset);
2332 } catch (InvalidArgument& e) {
2333 WRITE_WARNINGF(TL("In lane '%': Could not build shape (%)."), getLaneID(lane), e.what());
2334 }
2335 return shape;
2336}
2337
2338
2339void
2341 // taking the angle at the first might be unstable, thus we take the angle
2342 // at a certain distance. (To compare two edges, additional geometry
2343 // segments are considered to resolve ambiguities)
2344 const bool hasFromShape = myFrom->getShape().size() > 0;
2345 const bool hasToShape = myTo->getShape().size() > 0;
2346 Position fromCenter = (hasFromShape ? myFrom->getShape().getCentroid() : myFrom->getPosition());
2347 Position toCenter = (hasToShape ? myTo->getShape().getCentroid() : myTo->getPosition());
2348 PositionVector shape = myGeom;
2349 if ((hasFromShape || hasToShape) && getNumLanes() > 0) {
2351 shape = myLanes[getNumLanes() - 1].shape ;
2352 } else {
2353 shape = myLanes[getNumLanes() / 2].shape;
2354 if (getNumLanes() % 2 == 0) {
2355 // there is no center lane. shift to get the center
2356 shape.move2side(getLaneWidth(getNumLanes() / 2) * 0.5);
2357 }
2358 }
2359 }
2360
2361 // if the junction shape is suspicious we cannot trust the angle to the centroid
2362 const bool suspiciousFromShape = hasFromShape && (myFrom->getShape().distance2D(shape[0]) > 2 * POSITION_EPS
2363 || myFrom->getShape().around(shape[-1])
2364 || !(myFrom->getShape().around(fromCenter)));
2365 const bool suspiciousToShape = hasToShape && (myTo->getShape().distance2D(shape[-1]) > 2 * POSITION_EPS
2366 || myTo->getShape().around(shape[0])
2367 || !(myTo->getShape().around(toCenter)));
2368
2369 const double angleLookahead = MIN2(shape.length2D() / 2, ANGLE_LOOKAHEAD);
2370 const Position referencePosStart = shape.positionAtOffset2D(angleLookahead);
2371 const Position referencePosEnd = shape.positionAtOffset2D(shape.length2D() - angleLookahead);
2372
2373 myStartAngle = GeomHelper::legacyDegree(fromCenter.angleTo2D(referencePosStart), true);
2374 const double myStartAngle2 = GeomHelper::legacyDegree(myFrom->getPosition().angleTo2D(referencePosStart), true);
2375 const double myStartAngle3 = getAngleAtNode(myFrom);
2376 myEndAngle = GeomHelper::legacyDegree(referencePosEnd.angleTo2D(toCenter), true);
2377 const double myEndAngle2 = GeomHelper::legacyDegree(referencePosEnd.angleTo2D(myTo->getPosition()), true);
2378 const double myEndAngle3 = getAngleAtNode(myTo);
2379
2380#ifdef DEBUG_ANGLES
2381 if (DEBUGCOND) {
2382 if (suspiciousFromShape) {
2383 std::cout << "suspiciousFromShape len=" << shape.length() << " startA=" << myStartAngle << " startA2=" << myStartAngle2 << " startA3=" << myStartAngle3
2384 << " rel=" << NBHelpers::normRelAngle(myStartAngle, myStartAngle2)
2385 << " fromCenter=" << fromCenter
2386 << " fromPos=" << myFrom->getPosition()
2387 << " refStart=" << referencePosStart
2388 << "\n";
2389 }
2390 if (suspiciousToShape) {
2391 std::cout << "suspiciousToShape len=" << shape.length() << " endA=" << myEndAngle << " endA2=" << myEndAngle2 << " endA3=" << myEndAngle3
2392 << " rel=" << NBHelpers::normRelAngle(myEndAngle, myEndAngle2)
2393 << " toCenter=" << toCenter
2394 << " toPos=" << myTo->getPosition()
2395 << " refEnd=" << referencePosEnd
2396 << "\n";
2397 }
2398 }
2399#endif
2400
2401 if (suspiciousFromShape && shape.length() > 1) {
2402 myStartAngle = myStartAngle2;
2403 } else if (suspiciousToShape && fabs(NBHelpers::normRelAngle(myStartAngle, myStartAngle3)) > 90
2404 // don't trust footpath angles
2405 && (getPermissions() & ~SVC_PEDESTRIAN) != 0) {
2406 myStartAngle = myStartAngle3;
2407 if (myStartAngle < 0) {
2408 myStartAngle += 360;
2409 }
2410 }
2411
2412 if (suspiciousToShape && shape.length() > 1) {
2413 myEndAngle = myEndAngle2;
2414 } else if (suspiciousToShape && fabs(NBHelpers::normRelAngle(myEndAngle, myEndAngle3)) > 90
2415 // don't trust footpath angles
2416 && (getPermissions() & ~SVC_PEDESTRIAN) != 0) {
2417 myEndAngle = myEndAngle3;
2418 if (myEndAngle < 0) {
2419 myEndAngle += 360;
2420 }
2421 }
2422
2424#ifdef DEBUG_ANGLES
2425 if (DEBUGCOND) std::cout << "computeAngle edge=" << getID()
2426 << " fromCenter=" << fromCenter << " toCenter=" << toCenter
2427 << " refStart=" << referencePosStart << " refEnd=" << referencePosEnd << " shape=" << shape
2428 << " hasFromShape=" << hasFromShape
2429 << " hasToShape=" << hasToShape
2430 << " numLanes=" << getNumLanes()
2431 << " shapeLane=" << getNumLanes() / 2
2432 << " startA=" << myStartAngle << " endA=" << myEndAngle << " totA=" << myTotalAngle << "\n";
2433#endif
2434}
2435
2436
2437double
2439 const double angleLookahead = MIN2(myGeom.length2D() / 2, ANGLE_LOOKAHEAD);
2440 const Position referencePosStart = myGeom.positionAtOffset2D(angleLookahead);
2441 return GeomHelper::legacyDegree(myGeom.front().angleTo2D(referencePosStart), true);
2442}
2443
2444
2445double
2447 const double angleLookahead = MIN2(myGeom.length2D() / 2, ANGLE_LOOKAHEAD);
2448 const Position referencePosEnd = myGeom.positionAtOffset2D(myGeom.length2D() - angleLookahead);
2449 return GeomHelper::legacyDegree(referencePosEnd.angleTo2D(myGeom.back()), true);
2450}
2451
2452
2453bool
2455 for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
2456 if ((*i).permissions != SVCAll) {
2457 return true;
2458 }
2459 }
2460 return false;
2461}
2462
2463
2464bool
2466 std::vector<Lane>::const_iterator i = myLanes.begin();
2467 SVCPermissions firstLanePermissions = i->permissions;
2468 i++;
2469 for (; i != myLanes.end(); ++i) {
2470 if (i->permissions != firstLanePermissions) {
2471 return true;
2472 }
2473 }
2474 return false;
2475}
2476
2477
2478bool
2480 for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
2481 if (i->speed != getSpeed()) {
2482 return true;
2483 }
2484 }
2485 return false;
2486}
2487
2488bool
2490 for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
2491 if (i->friction != myLanes.begin()->friction) {
2492 return true;
2493 }
2494 }
2495 return false;
2496}
2497
2498bool
2500 for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
2501 if (i->width != myLanes.begin()->width) {
2502 return true;
2503 }
2504 }
2505 return false;
2506}
2507
2508
2509bool
2511 for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
2512 if (i->type != myLanes.begin()->type) {
2513 return true;
2514 }
2515 }
2516 return false;
2517}
2518
2519
2520bool
2522 for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
2523 if (i->endOffset != myLanes.begin()->endOffset) {
2524 return true;
2525 }
2526 }
2527 return false;
2528}
2529
2530
2531bool
2533 for (const auto& lane : myLanes) {
2534 if (lane.laneStopOffset.isDefined()) {
2535 if (myEdgeStopOffset.isDefined() || (myEdgeStopOffset != lane.laneStopOffset)) {
2536 return true;
2537 }
2538 }
2539 }
2540 return false;
2541}
2542
2543
2544bool
2546 for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
2547 if (i->accelRamp) {
2548 return true;
2549 }
2550 }
2551 return false;
2552}
2553
2554
2555bool
2557 for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
2558 if (i->customShape.size() > 0) {
2559 return true;
2560 }
2561 }
2562 return false;
2563}
2564
2565
2566bool
2568 for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
2569 if (i->getParametersMap().size() > 0) {
2570 return true;
2571 }
2572 }
2573 return false;
2574}
2575
2576bool
2578 for (const Lane& lane : myLanes) {
2579 if (lane.changeLeft != SVCAll || lane.changeRight != SVCAll) {
2580 return true;
2581 }
2582 }
2583 return false;
2584}
2585
2586bool
2594 || hasAccelLane()
2596 || hasLaneParams()
2598 || (!myLanes.empty() && myLanes.back().oppositeID != ""));
2599}
2600
2601
2602
2603bool
2604NBEdge::computeEdge2Edges(bool noLeftMovers) {
2605#ifdef DEBUG_CONNECTION_GUESSING
2606 if (DEBUGCOND) {
2607 std::cout << "computeEdge2Edges edge=" << getID() << " step=" << (int)myStep << " noLeftMovers=" << noLeftMovers << "\n";
2608 for (Connection& c : myConnections) {
2609 std::cout << " conn " << c.getDescription(this) << "\n";
2610 }
2612 std::cout << " connToDelete " << c.getDescription(this) << "\n";
2613 }
2614 }
2615#endif
2616 // return if this relationship has been build in previous steps or
2617 // during the import
2619 return true;
2620 }
2621 const bool fromRail = isRailway(getPermissions());
2622 for (NBEdge* out : myTo->getOutgoingEdges()) {
2623 if (noLeftMovers && myTo->isLeftMover(this, out)) {
2624 continue;
2625 }
2626 // avoid sharp railway turns
2627 if (fromRail && isRailway(out->getPermissions())) {
2628 const double angle = fabs(NBHelpers::normRelAngle(getAngleAtNode(myTo), out->getAngleAtNode(myTo)));
2629 if (angle > 150) {
2630 continue;
2631 } else if (angle > 90) {
2632 // possibly the junction is large enough to achieve a plausible radius:
2633 const PositionVector& fromShape = myLanes.front().shape;
2634 const PositionVector& toShape = out->getLanes().front().shape;
2635 PositionVector shape = myTo->computeSmoothShape(fromShape, toShape, 5, getTurnDestination() == out, 5, 5);
2636 const double radius = shape.length2D() / DEG2RAD(angle);
2637 const double minRadius = (getPermissions() & SVC_TRAM) != 0 ? 20 : 80;
2638 //std::cout << getID() << " to=" << out->getID() << " radius=" << radius << " minRadius=" << minRadius << "\n";
2639 if (radius < minRadius) {
2640 continue;
2641 }
2642 }
2643 }
2644 if (out == myTurnDestination) {
2645 // will be added by appendTurnaround
2646 continue;
2647 }
2648 if ((getPermissions() & out->getPermissions() & ~SVC_PEDESTRIAN) == 0) {
2649 // no common permissions
2650 continue;
2651 }
2652 myConnections.push_back(Connection(-1, out, -1));
2653 }
2655 return true;
2656}
2657
2658
2659bool
2661#ifdef DEBUG_CONNECTION_GUESSING
2662 if (DEBUGCOND) {
2663 std::cout << "computeLanes2Edges edge=" << getID() << " step=" << (int)myStep << "\n";
2664 for (Connection& c : myConnections) {
2665 std::cout << " conn " << c.getDescription(this) << "\n";
2666 }
2668 std::cout << " connToDelete " << c.getDescription(this) << "\n";
2669 }
2670 }
2671#endif
2672 // return if this relationship has been build in previous steps or
2673 // during the import
2676 for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end();) {
2677 if ((*i).toEdge == nullptr) {
2678 WRITE_WARNINGF("Inconsistent connection definitions at edge '%'.", getID());
2679 i = myConnections.erase(i);
2680 } else {
2681 i++;
2682 }
2683 }
2684 }
2685 return true;
2686 }
2688 // get list of possible outgoing edges sorted by direction clockwise
2689 // the edge in the backward direction (turnaround) is not in the list
2690 const EdgeVector* edges = getConnectedSorted();
2691 if (myConnections.size() != 0 && edges->size() == 0) {
2692 // dead end per definition!?
2693 myConnections.clear();
2694 } else {
2695 // divide the lanes on reachable edges
2696 divideOnEdges(edges);
2697 }
2698 delete edges;
2700 return true;
2701}
2702
2703
2704std::vector<LinkDirection>
2705NBEdge::decodeTurnSigns(int turnSigns, int shift) {
2706 std::vector<LinkDirection> result;
2707 for (int i = 0; i < 8; i++) {
2708 // see LinkDirection in SUMOXMLDefinitions.h
2709 if ((turnSigns & (1 << (i + shift))) != 0) {
2710 result.push_back((LinkDirection)(1 << i));
2711 }
2712 }
2713 return result;
2714}
2715
2716void
2717NBEdge::updateTurnPermissions(SVCPermissions& perm, LinkDirection dir, SVCPermissions spec, std::vector<LinkDirection> dirs) {
2718 if (dirs.size() > 0) {
2719 if (std::find(dirs.begin(), dirs.end(), dir) == dirs.end()) {
2720 perm &= ~spec;
2721 } else {
2722 perm |= spec;
2723 }
2724 }
2725}
2726
2727bool
2729#ifdef DEBUG_TURNSIGNS
2730 std::cout << "applyTurnSigns edge=" << getID() << "\n";
2731#endif
2732 // build a map of target edges and lanes
2733 std::vector<const NBEdge*> targets;
2734 std::map<const NBEdge*, std::vector<int> > toLaneMap;
2735 for (const Connection& c : myConnections) {
2736 if (myLanes[c.fromLane].turnSigns != 0) {
2737 if (std::find(targets.begin(), targets.end(), c.toEdge) == targets.end()) {
2738 targets.push_back(c.toEdge);
2739 }
2740 toLaneMap[c.toEdge].push_back(c.toLane);
2741 }
2742 }
2743 // might be unsorted due to bike lane connections
2744 for (auto& item : toLaneMap) {
2745 std::sort(item.second.begin(), item.second.end());
2746 }
2747
2748 // check number of distinct signed directions and count the number of signs for each direction
2749 std::map<LinkDirection, int> signCons;
2750 int allDirs = 0;
2751 for (const Lane& lane : myLanes) {
2752 allDirs |= lane.turnSigns;
2753 for (LinkDirection dir : decodeTurnSigns(lane.turnSigns)) {
2754 signCons[dir]++;
2755 }
2756 }
2757 allDirs |= allDirs >> TURN_SIGN_SHIFT_BUS;
2758 allDirs |= allDirs >> TURN_SIGN_SHIFT_TAXI;
2759 allDirs |= allDirs >> TURN_SIGN_SHIFT_BICYCLE;
2760
2761 if ((allDirs & (int)LinkDirection::NODIR) != 0) {
2762 targets.push_back(nullptr); // dead end
2763 }
2764
2765 SVCPermissions defaultPermissions = SVC_PASSENGER | SVC_DELIVERY;
2766 // build a mapping from sign directions to targets
2767 std::vector<LinkDirection> signedDirs = decodeTurnSigns(allDirs);
2768 std::map<LinkDirection, const NBEdge*> dirMap;
2769#ifdef DEBUG_TURNSIGNS
2770 std::cout << " numDirs=" << signedDirs.size() << " numTargets=" << targets.size() << "\n";
2771#endif
2772 if (signedDirs.size() > targets.size()) {
2773 WRITE_WARNINGF(TL("Cannot apply turn sign information for edge '%' because there are % signed directions but only % targets"), getID(), signedDirs.size(), targets.size());
2774 return false;
2775 } else if (signedDirs.size() < targets.size()) {
2776 // we need to drop some targets (i.e. turn-around)
2777 // use sumo-directions as a guide
2778 std::vector<LinkDirection> sumoDirs;
2779 for (const NBEdge* to : targets) {
2780 sumoDirs.push_back(myTo->getDirection(this, to));
2781 }
2782 // remove targets to the left
2783 bool checkMore = true;
2784 while (signedDirs.size() < targets.size() && checkMore) {
2785 checkMore = false;
2786 //std::cout << getID() << " sumoDirs=" << joinToString(sumoDirs, ",") << " signedDirs=" << joinToString(signedDirs, ",") << "\n";
2787 if (sumoDirs.back() != signedDirs.back()) {
2788 targets.pop_back();
2789 sumoDirs.pop_back();
2790 checkMore = true;
2791 }
2792 }
2793 // remove targets to the right
2794 checkMore = true;
2795 while (signedDirs.size() < targets.size() && checkMore) {
2796 checkMore = false;
2797 if (sumoDirs.front() != signedDirs.front()) {
2798 targets.erase(targets.begin());
2799 sumoDirs.erase(sumoDirs.begin());
2800 checkMore = true;
2801 }
2802 }
2803 // remove targets by permissions
2804 int i = 0;
2805 while (signedDirs.size() < targets.size() && i < (int)targets.size()) {
2806 if (targets[i] != nullptr && (targets[i]->getPermissions() & defaultPermissions) == 0) {
2807 targets.erase(targets.begin() + i);
2808 sumoDirs.erase(sumoDirs.begin() + i);
2809 } else {
2810 i++;
2811 }
2812 }
2813 if (signedDirs.size() != targets.size()) {
2814 WRITE_WARNINGF(TL("Cannot apply turn sign information for edge '%' because there are % signed directions and % targets (after target pruning)"), getID(), signedDirs.size(), targets.size());
2815 return false;
2816 }
2817 }
2818 // directions and connections are both sorted from right to left
2819 for (int i = 0; i < (int)signedDirs.size(); i++) {
2820 dirMap[signedDirs[i]] = targets[i];
2821 }
2822 // check whether we have enough target lanes for a each signed direction
2823 for (auto item : signCons) {
2824 const LinkDirection dir = item.first;
2825 if (dir == LinkDirection::NODIR) {
2826 continue;
2827 }
2828 const NBEdge* to = dirMap[dir];
2829 int candidates = to->getNumLanesThatAllow(defaultPermissions, false);
2830 if (candidates == 0) {
2831 WRITE_WARNINGF(TL("Cannot apply turn sign information for edge '%' because the target edge '%' has no suitable lanes"), getID(), to->getID());
2832 return false;
2833 }
2834 std::vector<int>& knownTargets = toLaneMap[to];
2835 if ((int)knownTargets.size() < item.second) {
2836 if (candidates < item.second) {
2837 WRITE_WARNINGF(TL("Cannot apply turn sign information for edge '%' because there are % signed connections with directions '%' but target edge '%' has only % suitable lanes"),
2838 getID(), item.second, toString(dir), to->getID(), candidates);
2839 return false;
2840 }
2841 int i;
2842 int iInc;
2843 int iEnd;
2844 if (dir > LinkDirection::STRAIGHT) {
2845 // set more targets on the left
2846 i = to->getNumLanes() - 1;
2847 iInc = -1;
2848 iEnd = -1;
2849 } else {
2850 // set more targets on the right
2851 i = 0;
2852 iInc = 1;
2853 iEnd = to->getNumLanes();
2854 }
2855 while ((int)knownTargets.size() < item.second && i != iEnd) {
2856 if ((to->getPermissions(i) & defaultPermissions) != 0) {
2857 if (std::find(knownTargets.begin(), knownTargets.end(), i) == knownTargets.end()) {
2858 knownTargets.push_back(i);
2859 }
2860 }
2861 i += iInc;
2862 }
2863 if ((int)knownTargets.size() != item.second) {
2864 WRITE_WARNINGF(TL("Cannot apply turn sign information for edge '%' because not enough target lanes could be determined for direction '%'"), getID(), toString(dir));
2865 return false;
2866 }
2867 std::sort(knownTargets.begin(), knownTargets.end());
2868 }
2869 }
2870 std::map<const NBEdge*, int> toLaneIndex;
2871 for (int i = 0; i < getNumLanes(); i++) {
2872 const int turnSigns = myLanes[i].turnSigns;
2873 // no turnSigns are given for bicycle lanes and sidewalks
2874 if (turnSigns != 0) {
2875 // clear existing connections
2876 for (auto it = myConnections.begin(); it != myConnections.end();) {
2877 if (it->fromLane == i) {
2878 it = myConnections.erase(it);
2879 } else {
2880 it++;
2881 }
2882 }
2883 // add new connections
2884 int allSigns = (turnSigns
2885 | turnSigns >> TURN_SIGN_SHIFT_BUS
2886 | turnSigns >> TURN_SIGN_SHIFT_TAXI
2887 | turnSigns >> TURN_SIGN_SHIFT_BICYCLE);
2888 std::vector<LinkDirection> all = decodeTurnSigns(turnSigns);
2889 std::vector<LinkDirection> bus = decodeTurnSigns(turnSigns, TURN_SIGN_SHIFT_BUS);
2890 std::vector<LinkDirection> taxi = decodeTurnSigns(turnSigns, TURN_SIGN_SHIFT_TAXI);
2891 std::vector<LinkDirection> bike = decodeTurnSigns(turnSigns, TURN_SIGN_SHIFT_BICYCLE);
2892 //std::cout << " allSigns=" << allSigns << " turnSigns=" << turnSigns << " bus=" << bus.size() << "\n";
2893 SVCPermissions fromP = getPermissions(i);
2894 if ((fromP & SVC_PASSENGER) != 0) {
2895 // if the source permits passenger traffic, the target should too
2896 fromP = SVC_PASSENGER;
2897 }
2898 for (LinkDirection dir : decodeTurnSigns(allSigns)) {
2899 SVCPermissions perm = 0;
2900 updateTurnPermissions(perm, dir, SVCAll, all);
2901 updateTurnPermissions(perm, dir, SVC_BUS, bus);
2902 updateTurnPermissions(perm, dir, SVC_TAXI, taxi);
2903 updateTurnPermissions(perm, dir, SVC_BICYCLE, bike);
2904 if (perm == SVCAll) {
2905 perm = SVC_UNSPECIFIED;
2906 }
2907 //std::cout << " lane=" << i << " dir=" << toString(dir) << " perm=" << getVehicleClassNames(perm) << "\n";
2908 NBEdge* to = const_cast<NBEdge*>(dirMap[dir]);
2909 if (to != nullptr) {
2910 if (toLaneIndex.count(to) == 0) {
2911 // initialize to rightmost feasible lane
2912 int toLane = toLaneMap[to][0];
2913 while ((to->getPermissions(toLane) & fromP) == 0 && (toLane + 1 < to->getNumLanes())) {
2914 toLane++;
2915 /*
2916 if (toLane == to->getNumLanes()) {
2917 SOFT_ASSERT(false);
2918 #ifdef DEBUG_TURNSIGNS
2919 std::cout << " could not find passenger lane for target=" << to->getID() << "\n";
2920 #endif
2921 return false;
2922 }
2923 */
2924 }
2925#ifdef DEBUG_TURNSIGNS
2926 std::cout << " target=" << to->getID() << " initial toLane=" << toLane << "\n";
2927#endif
2928 toLaneIndex[to] = toLane;
2929 }
2930#ifdef DEBUG_TURNSIGNS
2931 //std::cout << " set fromLane=" << i << " to=" << to->getID() << " toLane=" << toLaneIndex[to] << "\n";
2932#endif
2933 setConnection(i, to, toLaneIndex[to], Lane2LaneInfoType::VALIDATED, true,
2938 perm);
2939 if (toLaneIndex[to] < to->getNumLanes() - 1
2940 && (to->getPermissions(toLaneIndex[to] + 1) & fromP) != 0) {
2941 toLaneIndex[to]++;
2942 } else if (toLaneIndex[to] < to->getNumLanes() - 2
2943 && (to->getPermissions(toLaneIndex[to] + 2) & fromP) != 0) {
2944 // skip forbidden lane
2945 toLaneIndex[to] += 2;
2946 }
2947 }
2948 }
2949 }
2950 }
2953 return true;
2954}
2955
2956
2957bool
2959#ifdef DEBUG_CONNECTION_GUESSING
2960 if (DEBUGCOND) {
2961 std::cout << "recheckLanes (initial) edge=" << getID() << "\n";
2962 for (Connection& c : myConnections) {
2963 std::cout << " conn " << c.getDescription(this) << "\n";
2964 }
2966 std::cout << " connToDelete " << c.getDescription(this) << "\n";
2967 }
2968 }
2969#endif
2970 // check delayed removals
2971 for (std::vector<Connection>::iterator it = myConnectionsToDelete.begin(); it != myConnectionsToDelete.end(); ++it) {
2972 removeFromConnections(it->toEdge, it->fromLane, it->toLane, false, false, true);
2973 }
2974 std::vector<int> connNumbersPerLane(myLanes.size(), 0);
2975 for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end();) {
2976 if ((*i).toEdge == nullptr || (*i).fromLane < 0 || (*i).toLane < 0) {
2977 i = myConnections.erase(i);
2978 } else {
2979 if ((*i).fromLane >= 0) {
2980 ++connNumbersPerLane[(*i).fromLane];
2981 }
2982 ++i;
2983 }
2984 }
2986#ifdef DEBUG_TURNSIGNS
2987 if (myLanes.back().turnSigns != 0) {
2988 std::cout << getID() << " hasTurnSigns\n";
2989 if (myTurnSignTarget != myTo->getID()) {
2990 std::cout << " tst=" << myTurnSignTarget << " to=" << myTo->getID() << "\n";
2991 }
2992 }
2993#endif
2994 if (myLanes.back().turnSigns == 0 || myTurnSignTarget != myTo->getID() || !applyTurnSigns()) {
2995 // check #1:
2996 // If there is a lane with no connections and any neighbour lane has
2997 // more than one connections, try to move one of them.
2998 // This check is only done for edges which connections were assigned
2999 // using the standard algorithm.
3000 for (int i = 0; i < (int)myLanes.size(); i++) {
3001 if (connNumbersPerLane[i] == 0 && !isForbidden(getPermissions(i) & ~SVC_PEDESTRIAN)) {
3002 // dead-end lane found
3003 bool hasDeadEnd = true;
3004 // find lane with two connections or more to the right of the current lane
3005 for (int i2 = i - 1; hasDeadEnd && i2 >= 0; i2--) {
3006 if (getPermissions(i) != getPermissions(i2)) {
3007 break;
3008 }
3009 if (connNumbersPerLane[i2] > 1) {
3010 connNumbersPerLane[i2]--;
3011 for (int i3 = i2; i3 != i; i3++) {
3015 }
3016 hasDeadEnd = false;
3017 }
3018 }
3019 if (hasDeadEnd) {
3020 // find lane with two connections or more to the left of the current lane
3021 for (int i2 = i + 1; hasDeadEnd && i2 < getNumLanes(); i2++) {
3022 if (getPermissions(i) != getPermissions(i2)) {
3023 break;
3024 }
3025 if (connNumbersPerLane[i2] > 1) {
3026 connNumbersPerLane[i2]--;
3027 for (int i3 = i2; i3 != i; i3--) {
3031 }
3032 hasDeadEnd = false;
3033 }
3034 }
3035 }
3036 if (hasDeadEnd && myTo->getOutgoingEdges().size() > 1) {
3037 int passengerLanes = 0;
3038 int passengerTargetLanes = 0;
3039 for (const Lane& lane : myLanes) {
3040 if ((lane.permissions & SVC_PASSENGER) != 0) {
3041 passengerLanes++;
3042 }
3043 }
3044 for (const NBEdge* out : myTo->getOutgoingEdges()) {
3045 if (!isTurningDirectionAt(out)) {
3046 for (const Lane& lane : out->getLanes()) {
3047 if ((lane.permissions & SVC_PASSENGER) != 0) {
3048 passengerTargetLanes++;
3049 }
3050 }
3051 }
3052 }
3053 if (passengerLanes > 0 && passengerLanes <= passengerTargetLanes) {
3054 // no need for dead-ends
3055 if (i > 0) {
3056 // check if a connection to the right has a usable target to the left of its target
3057 std::vector<Connection> rightCons = getConnectionsFromLane(i - 1);
3058 if (rightCons.size() > 0) {
3059 const Connection& rc = rightCons.back();
3060 NBEdge* to = rc.toEdge;
3061 int toLane = rc.toLane + 1;
3062 if (toLane < to->getNumLanes()
3063 && (getPermissions(i) & ~SVC_PEDESTRIAN & to->getPermissions(toLane)) != 0
3064 && !hasConnectionTo(to, toLane)) {
3065#ifdef DEBUG_CONNECTION_CHECKING
3066 std::cout << " recheck1 setConnection " << getID() << "_" << i << "->" << to->getID() << "_" << toLane << "\n";
3067#endif
3069 hasDeadEnd = false;
3072 }
3073 if (hasDeadEnd) {
3074 // check if a connection to the right has a usable target to the right of its target
3075 toLane = rc.toLane - 1;
3076 if (toLane >= 0
3077 && (getPermissions(i) & ~SVC_PEDESTRIAN & to->getPermissions(rc.toLane)) != 0
3078 && (getPermissions(rc.fromLane) & ~SVC_PEDESTRIAN & to->getPermissions(toLane)) != 0
3079 && !hasConnectionTo(to, toLane)) {
3080 // shift the right lane connection target right and connect the dead lane to the old target
3081 getConnectionRef(rc.fromLane, to, rc.toLane).toLane = toLane;
3082#ifdef DEBUG_CONNECTION_CHECKING
3083 std::cout << " recheck2 setConnection " << getID() << "_" << i << "->" << to->getID() << "_" << (toLane + 1) << "\n";
3084#endif
3085 setConnection(i, to, toLane + 1, Lane2LaneInfoType::COMPUTED);
3086 hasDeadEnd = false;
3089 }
3090 }
3091 }
3092 }
3093 if (hasDeadEnd && i < getNumLanes() - 1) {
3094 // check if a connection to the left has a usable target to the right of its target
3095 std::vector<Connection> leftCons = getConnectionsFromLane(i + 1);
3096 if (leftCons.size() > 0) {
3097 NBEdge* to = leftCons.front().toEdge;
3098 int toLane = leftCons.front().toLane - 1;
3099 if (toLane >= 0
3100 && (getPermissions(i) & ~SVC_PEDESTRIAN & to->getPermissions(toLane)) != 0
3101 && !hasConnectionTo(to, toLane)) {
3102#ifdef DEBUG_CONNECTION_CHECKING
3103 std::cout << " recheck3 setConnection " << getID() << "_" << i << "->" << to->getID() << "_" << toLane << "\n";
3104#endif
3106 hasDeadEnd = false;
3109 }
3110 }
3111 }
3112#ifdef ADDITIONAL_WARNINGS
3113 if (hasDeadEnd) {
3114 WRITE_WARNING("Found dead-end lane " + getLaneID(i));
3115 }
3116#endif
3117 }
3118 }
3119 }
3120 }
3122 }
3123 }
3124 // check involuntary dead end at "real" junctions
3125 if (getPermissions() != SVC_PEDESTRIAN) {
3126 if (myConnections.empty() && myTo->getOutgoingEdges().size() > 1 && (getPermissions() & ~SVC_PEDESTRIAN) != 0) {
3127 WRITE_WARNINGF(TL("Edge '%' is not connected to outgoing edges at junction '%'."), getID(), myTo->getID());
3128 }
3129 const EdgeVector& incoming = myFrom->getIncomingEdges();
3130 if (incoming.size() > 1) {
3131 for (int i = 0; i < (int)myLanes.size(); i++) {
3132 if (getPermissions(i) != 0 && getPermissions(i) != SVC_PEDESTRIAN) {
3133 bool connected = false;
3134 for (std::vector<NBEdge*>::const_iterator in = incoming.begin(); in != incoming.end(); ++in) {
3135 if ((*in)->hasConnectionTo(this, i)) {
3136 connected = true;
3137 break;
3138 }
3139 }
3140 if (!connected) {
3141 WRITE_WARNINGF(TL("Lane '%' is not connected from any incoming edge at junction '%'."), getLaneID(i), myFrom->getID());
3142 }
3143 }
3144 }
3145 }
3146 }
3147 // avoid deadend due to change prohibitions
3148 if (getNumLanes() > 1 && myConnections.size() > 0) {
3149 for (int i = 0; i < (int)myLanes.size(); i++) {
3150 Lane& lane = myLanes[i];
3151 if ((connNumbersPerLane[i] == 0 || ((lane.accelRamp || (i > 0 && myLanes[i - 1].accelRamp && connNumbersPerLane[i - 1] > 0))
3152 && getSuccessors(SVC_PASSENGER).size() > 1))
3154 const bool forbiddenLeft = lane.changeLeft != SVCAll && lane.changeLeft != SVC_IGNORING && lane.changeLeft != SVC_UNSPECIFIED;
3155 const bool forbiddenRight = lane.changeRight != SVCAll && lane.changeRight != SVC_IGNORING && lane.changeRight != SVC_UNSPECIFIED;
3156 if (forbiddenLeft && (i == 0 || forbiddenRight)) {
3158 WRITE_WARNINGF(TL("Ignoring changeLeft prohibition for '%' to avoid dead-end"), getLaneID(i));
3159 } else if (forbiddenRight && (i == getNumLanes() - 1 || (i > 0 && myLanes[i - 1].accelRamp))) {
3161 WRITE_WARNINGF(TL("Ignoring changeRight prohibition for '%' to avoid dead-end"), getLaneID(i));
3162 }
3163 }
3164 }
3165 }
3166#ifdef ADDITIONAL_WARNINGS
3167 // check for connections with bad access permissions
3168 for (const Connection& c : myConnections) {
3169 SVCPermissions fromP = getPermissions(c.fromLane);
3170 SVCPermissions toP = c.toEdge->getPermissions(c.toLane);
3171 if ((fromP & SVC_PASSENGER) != 0
3172 && toP == SVC_BICYCLE) {
3173 bool hasAlternative = false;
3174 for (const Connection& c2 : myConnections) {
3175 if (c.fromLane == c2.fromLane && c.toEdge == c2.toEdge
3176 && (c.toEdge->getPermissions(c2.toLane) & SVC_PASSENGER) != 0) {
3177 hasAlternative = true;
3178 }
3179 }
3180 if (!hasAlternative) {
3181 WRITE_WARNING("Road lane ends on bikeLane for connection " + c.getDescription(this));
3182 }
3183 }
3184 }
3185
3186#endif
3187#ifdef DEBUG_CONNECTION_GUESSING
3188 if (DEBUGCOND) {
3189 std::cout << "recheckLanes (final) edge=" << getID() << "\n";
3190 for (Connection& c : myConnections) {
3191 std::cout << " conn " << c.getDescription(this) << "\n";
3192 }
3193 }
3194#endif
3197 }
3198 return true;
3199}
3200
3201
3202void NBEdge::recheckOpposite(const NBEdgeCont& ec, bool fixOppositeLengths) {
3203 if (getNumLanes() == 0) {
3204 return;
3205 }
3206 const int leftmostLane = getNumLanes() - 1;
3207 // check oppositeID stored in other lanes
3208 for (int i = 0; i < leftmostLane; i++) {
3209 const std::string& oppositeID = getLanes()[i].oppositeID;
3210 NBEdge* oppEdge = ec.retrieve(oppositeID.substr(0, oppositeID.rfind("_")));
3211 if (oppositeID != "" && oppositeID != "-") {
3212 if (getLanes().back().oppositeID == "" && oppEdge != nullptr) {
3213 getLaneStruct(leftmostLane).oppositeID = oppositeID;
3214 WRITE_WARNINGF(TL("Moving opposite lane '%' from invalid lane '%' to lane index %."), oppositeID, getLaneID(i), leftmostLane);
3215 } else {
3216 WRITE_WARNINGF(TL("Removing opposite lane '%' for invalid lane '%'."), oppositeID, getLaneID(i));
3217 }
3218 getLaneStruct(i).oppositeID = "";
3219 }
3220 }
3221 const std::string& oppositeID = getLanes().back().oppositeID;
3222 if (oppositeID != "" && oppositeID != "-") {
3223 NBEdge* oppEdge = ec.retrieve(oppositeID.substr(0, oppositeID.rfind("_")));
3224 if (oppEdge == nullptr) {
3225 WRITE_WARNINGF(TL("Removing unknown opposite lane '%' for edge '%'."), oppositeID, getID());
3226 getLaneStruct(leftmostLane).oppositeID = "";
3227 } else {
3228 if (oppEdge->getFromNode() != getToNode() || oppEdge->getToNode() != getFromNode()) {
3229 WRITE_WARNINGF(TL("Opposite lane '%' does not reverse-connect the same nodes as edge '%'!"), oppositeID, getID());
3231 } else {
3232 if (oppEdge->getLaneID(oppEdge->getNumLanes() - 1) != oppositeID) {
3233 const std::string oppEdgeLeftmost = oppEdge->getLaneID(oppEdge->getNumLanes() - 1);
3234 WRITE_WARNINGF(TL("Adapting invalid opposite lane '%' for edge '%' to '%'."), oppositeID, getID(), oppEdgeLeftmost);
3235 getLaneStruct(leftmostLane).oppositeID = oppEdgeLeftmost;
3236 }
3237 NBEdge::Lane& oppLane = oppEdge->getLaneStruct(oppEdge->getNumLanes() - 1);
3238 const std::string leftmostID = getLaneID(leftmostLane);
3239 if (oppLane.oppositeID == "") {
3240 WRITE_WARNINGF(TL("Adapting missing opposite lane '%' for edge '%'."), leftmostID, oppEdge->getID());
3241 oppLane.oppositeID = leftmostID;
3242 } else if (oppLane.oppositeID != leftmostID && oppLane.oppositeID != "-") {
3243 const std::string oppOpp = oppLane.oppositeID.substr(0, oppLane.oppositeID.rfind("_"));
3244 NBEdge* oppOppEdge = ec.retrieve(oppOpp);
3245 if (oppOppEdge == nullptr) {
3246 WRITE_WARNINGF(TL("Adapting invalid opposite lane '%' for edge '%' to '%'."), oppLane.oppositeID, oppEdge->getID(), leftmostID);
3247 oppLane.oppositeID = leftmostID;
3248 } else {
3249 if (oppEdge->getFromNode() != oppOppEdge->getToNode() || oppEdge->getToNode() != oppOppEdge->getFromNode()) {
3250 WRITE_ERRORF(TL("Opposite edge '%' does not reverse-connect the same nodes as edge '%'!"), oppEdge->getID(), oppOppEdge->getID());
3251 } else {
3252 WRITE_WARNINGF(TL("Adapting inconsistent opposite lanes for edges '%', '%' and '%'."), getID(), oppEdge->getID(), oppOpp);
3253 }
3254 oppLane.oppositeID = leftmostID;
3255 NBEdge::Lane& oppOppLane = oppOppEdge->getLaneStruct(oppOppEdge->getNumLanes() - 1);
3256 if (oppOppLane.oppositeID == oppEdge->getLaneID(oppEdge->getNumLanes() - 1)) {
3257 oppOppLane.oppositeID = "";
3258 }
3259 }
3260 }
3261 if (fabs(oppEdge->getLoadedLength() - getLoadedLength()) > NUMERICAL_EPS) {
3262 if (fixOppositeLengths) {
3263 const double avgLength = 0.5 * (getFinalLength() + oppEdge->getFinalLength());
3264 WRITE_WARNINGF(TL("Averaging edge lengths for lane '%' (length %) and edge '%' (length %)."),
3265 oppositeID, oppEdge->getLoadedLength(), getID(), getLoadedLength());
3266 setLoadedLength(avgLength);
3267 oppEdge->setLoadedLength(avgLength);
3268 } else {
3269 WRITE_ERROR("Opposite lane '" + oppositeID + "' (length " + toString(oppEdge->getLoadedLength()) +
3270 ") differs in length from edge '" + getID() + "' (length " +
3271 toString(getLoadedLength()) + "). Set --opposites.guess.fix-lengths to fix this.");
3273 }
3274 }
3275 }
3276 }
3277 }
3278 // check for matching bidi lane shapes (at least for the simple case of 1-lane edges)
3279 const NBEdge* bidi = getBidiEdge();
3280 if (bidi != nullptr && getNumLanes() == 1 && bidi->getNumLanes() == 1 && getID() < bidi->getID()) {
3282 }
3283 // check for valid offset and speed
3284 const double startOffset = isBidiRail() ? getTurnDestination(true)->getEndOffset() : 0;
3285 int i = 0;
3286 for (const NBEdge::Lane& l : getLanes()) {
3287 if (startOffset + l.endOffset > getLength()) {
3288 WRITE_WARNINGF(TL("Invalid endOffset % at lane '%' with length % (startOffset %)."),
3289 toString(l.endOffset), getLaneID(i), toString(l.shape.length()), toString(startOffset));
3290 } else if (l.speed < 0.) {
3291 WRITE_WARNINGF(TL("Negative allowed speed (%) on lane '%', use --speed.minimum to prevent this."), toString(l.speed), getLaneID(i));
3292 } else if (l.speed == 0.) {
3293 WRITE_WARNINGF(TL("Lane '%' has a maximum allowed speed of 0."), getLaneID(i));
3294 }
3295 i++;
3296 }
3297}
3298
3300 // check restrictions
3301 for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end();) {
3302 Connection& c = *i;
3304 if (common == SVC_PEDESTRIAN || getPermissions(c.fromLane) == SVC_PEDESTRIAN) {
3305 // these are computed in NBNode::buildWalkingAreas
3306#ifdef DEBUG_CONNECTION_CHECKING
3307 std::cout << " remove pedCon " << c.getDescription(this) << "\n";
3308#endif
3309 i = myConnections.erase(i);
3310 } else if (common == 0) {
3311 // no common permissions.
3312 // try to find a suitable target lane to the right
3313 const int origToLane = c.toLane;
3314 c.toLane = -1; // ignore this connection when calling hasConnectionTo
3315 int toLane = origToLane;
3316 while (toLane > 0
3317 && (getPermissions(c.fromLane) & c.toEdge->getPermissions(toLane)) == 0
3318 && !hasConnectionTo(c.toEdge, toLane)
3319 ) {
3320 toLane--;
3321 }
3322 if ((getPermissions(c.fromLane) & c.toEdge->getPermissions(toLane)) != 0
3323 && !hasConnectionTo(c.toEdge, toLane)) {
3324 c.toLane = toLane;
3325 ++i;
3326 } else {
3327 // try to find a suitable target lane to the left
3328 toLane = origToLane;
3329 while (toLane < (int)c.toEdge->getNumLanes() - 1
3330 && (getPermissions(c.fromLane) & c.toEdge->getPermissions(toLane)) == 0
3331 && !hasConnectionTo(c.toEdge, toLane)
3332 ) {
3333 toLane++;
3334 }
3335 if ((getPermissions(c.fromLane) & c.toEdge->getPermissions(toLane)) != 0
3336 && !hasConnectionTo(c.toEdge, toLane)) {
3337 c.toLane = toLane;
3338 ++i;
3339 } else {
3340 // no alternative target found
3341#ifdef DEBUG_CONNECTION_CHECKING
3342 std::cout << " remove " << c.getDescription(this) << " with no alternative target\n";
3343#endif
3344 i = myConnections.erase(i);
3345 }
3346 }
3349 // do not allow sharp rail turns
3350#ifdef DEBUG_CONNECTION_CHECKING
3351 std::cout << " remove " << c.getDescription(this) << " (rail turnaround)\n";
3352#endif
3353 i = myConnections.erase(i);
3354 } else {
3355 ++i;
3356 }
3357 }
3358}
3359
3360void
3362 if (outgoing->size() == 0) {
3363 // we have to do this, because the turnaround may have been added before
3364 myConnections.clear();
3365 return;
3366 }
3367
3368#ifdef DEBUG_CONNECTION_GUESSING
3369 if (DEBUGCOND) {
3370 std::cout << " divideOnEdges " << getID() << " outgoing=" << toString(*outgoing) << "\n";
3371 }
3372#endif
3373
3374 // build connections for miv lanes
3375 std::vector<int> availableLanes;
3376 for (int i = 0; i < (int)myLanes.size(); ++i) {
3377 if ((getPermissions(i) & SVC_PASSENGER) != 0) {
3378 availableLanes.push_back(i);
3379 }
3380 }
3381 if (availableLanes.size() > 0) {
3382 divideSelectedLanesOnEdges(outgoing, availableLanes);
3383 }
3384 // build connections for miscellaneous further modes (more than bike,peds,bus and without passenger)
3385 availableLanes.clear();
3386 for (int i = 0; i < (int)myLanes.size(); ++i) {
3387 const SVCPermissions perms = getPermissions(i);
3388 if ((perms & ~(SVC_PEDESTRIAN | SVC_BICYCLE | SVC_BUS)) == 0 || (perms & SVC_PASSENGER) != 0 || isForbidden(perms)) {
3389 continue;
3390 }
3391 availableLanes.push_back(i);
3392 }
3393 if (availableLanes.size() > 0) {
3394 divideSelectedLanesOnEdges(outgoing, availableLanes);
3395 }
3396 // build connections for busses from lanes that were excluded in the previous step
3397 availableLanes.clear();
3398 for (int i = 0; i < (int)myLanes.size(); ++i) {
3399 const SVCPermissions perms = getPermissions(i);
3400 if ((perms & SVC_BUS) == 0 || (perms & ~(SVC_PEDESTRIAN | SVC_BICYCLE | SVC_BUS)) != 0 || (perms & SVC_PASSENGER) != 0) {
3401 continue;
3402 }
3403 availableLanes.push_back(i);
3404 }
3405 if (availableLanes.size() > 0) {
3406 divideSelectedLanesOnEdges(outgoing, availableLanes);
3407 }
3408 // build connections for bicycles (possibly combined with pedestrians)
3409 availableLanes.clear();
3410 for (int i = 0; i < (int)myLanes.size(); ++i) {
3411 const SVCPermissions perms = getPermissions(i);
3412 if (perms != SVC_BICYCLE && perms != (SVC_BICYCLE | SVC_PEDESTRIAN)) {
3413 continue;
3414 }
3415 availableLanes.push_back(i);
3416 }
3417 if (availableLanes.size() > 0) {
3418 divideSelectedLanesOnEdges(outgoing, availableLanes);
3419 }
3420 // clean up unassigned fromLanes
3421 bool explicitTurnaround = false;
3422 SVCPermissions turnaroundPermissions = SVC_UNSPECIFIED;
3423 for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end();) {
3424 if ((*i).fromLane == -1) {
3425 if ((*i).toEdge == myTurnDestination && myTurnDestination != nullptr) {
3426 explicitTurnaround = true;
3427 turnaroundPermissions = (*i).permissions;
3428 }
3429 if ((*i).permissions != SVC_UNSPECIFIED) {
3430 for (Connection& c : myConnections) {
3431 if (c.toLane == -1 && c.toEdge == (*i).toEdge) {
3432 // carry over loaded edge2edge permissions
3433 c.permissions = (*i).permissions;
3434 }
3435 }
3436 }
3437 i = myConnections.erase(i);
3438 } else {
3439 ++i;
3440 }
3441 }
3442 if (explicitTurnaround) {
3444 myConnections.back().permissions = turnaroundPermissions;
3445 }
3447}
3448
3449
3450void
3451NBEdge::divideSelectedLanesOnEdges(const EdgeVector* outgoing, const std::vector<int>& availableLanes) {
3452 const std::vector<int>& priorities = prepareEdgePriorities(outgoing, availableLanes);
3453 if (priorities.empty()) {
3454 return;
3455 }
3456#ifdef DEBUG_CONNECTION_GUESSING
3457 if (DEBUGCOND) {
3458 std::cout << "divideSelectedLanesOnEdges " << getID() << " out=" << toString(*outgoing) << " prios=" << toString(priorities) << " avail=" << toString(availableLanes) << "\n";
3459 }
3460#endif
3461 // compute the resulting number of lanes that should be used to reach the following edge
3462 const int numOutgoing = (int)outgoing->size();
3463 std::vector<int> resultingLanesFactor;
3464 resultingLanesFactor.reserve(numOutgoing);
3465 int minResulting = std::numeric_limits<int>::max();
3466 for (int i = 0; i < numOutgoing; i++) {
3467 // res / minResulting will be the number of lanes which are meant to reach the current outgoing edge
3468 const int res = priorities[i] * (int)availableLanes.size();
3469 resultingLanesFactor.push_back(res);
3470 if (minResulting > res && res > 0) {
3471 // prevent minResulting from becoming 0
3472 minResulting = res;
3473 }
3474 }
3475 // compute the number of virtual edges
3476 // a virtual edge is used as a replacement for a real edge from now on
3477 // it shall allow to divide the existing lanes on this structure without
3478 // regarding the structure of outgoing edges
3479 int numVirtual = 0;
3480 // compute the transition from virtual to real edges
3481 EdgeVector transition;
3482 transition.reserve(numOutgoing);
3483 for (int i = 0; i < numOutgoing; i++) {
3484 // tmpNum will be the number of connections from this edge to the next edge
3485 assert(i < (int)resultingLanesFactor.size());
3486 const int tmpNum = (resultingLanesFactor[i] + minResulting - 1) / minResulting; // integer division rounding up
3487 numVirtual += tmpNum;
3488 for (int j = 0; j < tmpNum; j++) {
3489 transition.push_back((*outgoing)[i]);
3490 }
3491 }
3492#ifdef DEBUG_CONNECTION_GUESSING
3493 if (DEBUGCOND) {
3494 std::cout << " minResulting=" << minResulting << " numVirtual=" << numVirtual << " availLanes=" << toString(availableLanes) << " resLanes=" << toString(resultingLanesFactor) << " transition=" << toString(transition) << "\n";
3495 }
3496#endif
3497
3498 // assign lanes to edges
3499 // (conversion from virtual to real edges is done)
3500 ToEdgeConnectionsAdder adder(transition);
3501 Bresenham::compute(&adder, static_cast<int>(availableLanes.size()), numVirtual);
3502 const std::map<NBEdge*, std::vector<int> >& l2eConns = adder.getBuiltConnections();
3503 for (NBEdge* const target : *outgoing) {
3504 assert(l2eConns.find(target) != l2eConns.end());
3505 for (const int j : l2eConns.find(target)->second) {
3506 const int fromIndex = availableLanes[j];
3507 if ((getPermissions(fromIndex) & target->getPermissions()) == 0) {
3508 // exclude connection if fromLane and toEdge have no common permissions
3509 continue;
3510 }
3511 if ((getPermissions(fromIndex) & target->getPermissions()) == SVC_PEDESTRIAN) {
3512 // exclude connection if the only commonly permitted class are pedestrians
3513 // these connections are later built in NBNode::buildWalkingAreas
3514 continue;
3515 }
3516 // avoid building more connections than the edge has viable lanes (earlier
3517 // ones have precedence). This is necessary when running divideSelectedLanesOnEdges more than once.
3518 // @todo To decide which target lanes are still available we need to do a
3519 // preliminary lane-to-lane assignment in regard to permissions (rather than to ordering)
3520 const int numConsToTarget = (int)count_if(myConnections.begin(), myConnections.end(), connections_toedge_finder(target, true));
3521 int targetLanes = target->getNumLanes();
3522 if (target->getPermissions(0) == SVC_PEDESTRIAN) {
3523 --targetLanes;
3524 }
3525 if (numConsToTarget >= targetLanes) {
3526 continue;
3527 }
3528 if (myLanes[fromIndex].connectionsDone) {
3529 // we already have complete information about connections from
3530 // this lane. do not add anything else
3531#ifdef DEBUG_CONNECTION_GUESSING
3532 if (DEBUGCOND) {
3533 std::cout << " connectionsDone from " << getID() << "_" << fromIndex << ": ";
3534 for (const Connection& c : getConnectionsFromLane(fromIndex)) {
3535 std::cout << c.getDescription(this) << ", ";
3536 }
3537 std::cout << "\n";
3538 }
3539#endif
3540 continue;
3541 }
3542 myConnections.push_back(Connection(fromIndex, target, -1));
3543#ifdef DEBUG_CONNECTION_GUESSING
3544 if (DEBUGCOND) {
3545 std::cout << " request connection from " << getID() << "_" << fromIndex << " to " << target->getID() << "\n";
3546 }
3547#endif
3548 }
3549 }
3550
3551 addStraightConnections(outgoing, availableLanes, priorities);
3552}
3553
3554
3555void
3556NBEdge::addStraightConnections(const EdgeVector* outgoing, const std::vector<int>& availableLanes, const std::vector<int>& priorities) {
3557 // ensure sufficient straight connections for the (highest-priority) straight target
3558 const int numOutgoing = (int) outgoing->size();
3559 NBEdge* target = nullptr;
3560 NBEdge* rightOfTarget = nullptr;
3561 NBEdge* leftOfTarget = nullptr;
3562 int maxPrio = 0;
3563 for (int i = 0; i < numOutgoing; i++) {
3564 if (maxPrio < priorities[i]) {
3565 const LinkDirection dir = myTo->getDirection(this, (*outgoing)[i]);
3566 if (dir == LinkDirection::STRAIGHT) {
3567 maxPrio = priorities[i];
3568 target = (*outgoing)[i];
3569 rightOfTarget = i == 0 ? outgoing->back() : (*outgoing)[i - 1];
3570 leftOfTarget = i + 1 == numOutgoing ? outgoing->front() : (*outgoing)[i + 1];
3571 }
3572 }
3573 }
3574 if (target == nullptr) {
3575 return;
3576 }
3577 int numConsToTarget = (int)count_if(myConnections.begin(), myConnections.end(), connections_toedge_finder(target, true));
3578 int targetLanes = (int)target->getNumLanes();
3579 if (target->getPermissions(0) == SVC_PEDESTRIAN) {
3580 --targetLanes;
3581 }
3582 const int numDesiredConsToTarget = MIN2(targetLanes, (int)availableLanes.size());
3583#ifdef DEBUG_CONNECTION_GUESSING
3584 if (DEBUGCOND) {
3585 std::cout << " checking extra lanes for target=" << target->getID() << " cons=" << numConsToTarget << " desired=" << numDesiredConsToTarget << "\n";
3586 }
3587#endif
3588 std::vector<int>::const_iterator it_avail = availableLanes.begin();
3589 while (numConsToTarget < numDesiredConsToTarget && it_avail != availableLanes.end()) {
3590 const int fromIndex = *it_avail;
3591 if (
3592 // not yet connected
3593 (count_if(myConnections.begin(), myConnections.end(), connections_finder(fromIndex, target, -1)) == 0)
3594 // matching permissions
3595 && ((getPermissions(fromIndex) & target->getPermissions()) != 0)
3596 // more than pedestrians
3597 && ((getPermissions(fromIndex) & target->getPermissions()) != SVC_PEDESTRIAN)
3598 // lane not yet fully defined
3599 && !myLanes[fromIndex].connectionsDone
3600 ) {
3601#ifdef DEBUG_CONNECTION_GUESSING
3602 if (DEBUGCOND) {
3603 std::cout << " candidate from " << getID() << "_" << fromIndex << " to " << target->getID() << "\n";
3604 }
3605#endif
3606 // prevent same-edge conflicts
3607 if (
3608 // no outgoing connections to the right from further left
3609 ((it_avail + 1) == availableLanes.end() || count_if(myConnections.begin(), myConnections.end(), connections_conflict_finder(fromIndex, rightOfTarget, false)) == 0)
3610 // no outgoing connections to the left from further right
3611 && (it_avail == availableLanes.begin() || count_if(myConnections.begin(), myConnections.end(), connections_conflict_finder(fromIndex, leftOfTarget, true)) == 0)) {
3612#ifdef DEBUG_CONNECTION_GUESSING
3613 if (DEBUGCOND) {
3614 std::cout << " request additional connection from " << getID() << "_" << fromIndex << " to " << target->getID() << "\n";
3615 }
3616#endif
3617 myConnections.push_back(Connection(fromIndex, target, -1));
3618 numConsToTarget++;
3619 } else {
3620#ifdef DEBUG_CONNECTION_GUESSING
3621 if (DEBUGCOND) std::cout
3622 << " fail check1="
3623 << ((it_avail + 1) == availableLanes.end() || count_if(myConnections.begin(), myConnections.end(), connections_conflict_finder(fromIndex, rightOfTarget, false)) == 0)
3624 << " check2=" << (it_avail == availableLanes.begin() || count_if(myConnections.begin(), myConnections.end(), connections_conflict_finder(fromIndex, leftOfTarget, true)) == 0)
3625 << " rightOfTarget=" << rightOfTarget->getID()
3626 << " leftOfTarget=" << leftOfTarget->getID()
3627 << "\n";
3628#endif
3629
3630 }
3631 }
3632 ++it_avail;
3633 }
3634}
3635
3636
3637const std::vector<int>
3638NBEdge::prepareEdgePriorities(const EdgeVector* outgoing, const std::vector<int>& availableLanes) {
3639 std::vector<int> priorities;
3640 MainDirections mainDirections(*outgoing, this, myTo, availableLanes);
3641 const int dist = mainDirections.getStraightest();
3642 if (dist == -1) {
3643 return priorities;
3644 }
3645 // copy the priorities first
3646 priorities.reserve(outgoing->size());
3647 for (const NBEdge* const out : *outgoing) {
3648 int prio = NBNode::isTrafficLight(myTo->getType()) ? 0 : out->getJunctionPriority(myTo);
3649 assert((prio + 1) * 2 > 0);
3650 prio = (prio + 1) * 2;
3651 priorities.push_back(prio);
3652 }
3653 // when the right turning direction has not a higher priority, divide
3654 // the importance by 2 due to the possibility to leave the junction
3655 // faster from this lane
3656#ifdef DEBUG_CONNECTION_GUESSING
3657 if (DEBUGCOND) std::cout << " prepareEdgePriorities " << getID()
3658 << " outgoing=" << toString(*outgoing)
3659 << " priorities1=" << toString(priorities)
3660 << " dist=" << dist
3661 << "\n";
3662#endif
3663 if (dist != 0 && !mainDirections.includes(MainDirections::Direction::RIGHTMOST)) {
3664 assert(priorities.size() > 0);
3665 priorities[0] /= 2;
3666#ifdef DEBUG_CONNECTION_GUESSING
3667 if (DEBUGCOND) {
3668 std::cout << " priorities2=" << toString(priorities) << "\n";
3669 }
3670#endif
3671 }
3672 // HEURISTIC:
3673 // when no higher priority exists, let the forward direction be
3674 // the main direction
3675 if (mainDirections.empty()) {
3676 assert(dist < (int)priorities.size());
3677 priorities[dist] *= 2;
3678#ifdef DEBUG_CONNECTION_GUESSING
3679 if (DEBUGCOND) {
3680 std::cout << " priorities3=" << toString(priorities) << "\n";
3681 }
3682#endif
3683 }
3685 priorities[dist] += 1;
3686 } else {
3687 // try to ensure separation of left turns
3689 priorities[0] /= 4;
3690 priorities[(int)priorities.size() - 1] /= 2;
3691#ifdef DEBUG_CONNECTION_GUESSING
3692 if (DEBUGCOND) {
3693 std::cout << " priorities6=" << toString(priorities) << "\n";
3694 }
3695#endif
3696 } else if (mainDirections.includes(MainDirections::Direction::RIGHTMOST)
3697 && outgoing->size() > 2
3698 && availableLanes.size() == 2
3699 && (*outgoing)[dist]->getPriority() == (*outgoing)[0]->getPriority()) {
3700 priorities[0] /= 4;
3701 priorities.back() /= 2;
3702#ifdef DEBUG_CONNECTION_GUESSING
3703 if (DEBUGCOND) {
3704 std::cout << " priorities7=" << toString(priorities) << "\n";
3705 }
3706#endif
3707 }
3708 }
3709 if (mainDirections.includes(MainDirections::Direction::FORWARD)) {
3710 if (myLanes.size() > 2) {
3711 priorities[dist] *= 2;
3712#ifdef DEBUG_CONNECTION_GUESSING
3713 if (DEBUGCOND) {
3714 std::cout << " priorities4=" << toString(priorities) << "\n";
3715 }
3716#endif
3717 } else {
3718 priorities[dist] *= 3;
3719#ifdef DEBUG_CONNECTION_GUESSING
3720 if (DEBUGCOND) {
3721 std::cout << " priorities5=" << toString(priorities) << "\n";
3722 }
3723#endif
3724 }
3725 }
3726 return priorities;
3727}
3728
3729
3730void
3731NBEdge::appendTurnaround(bool noTLSControlled, bool noFringe, bool onlyDeadends, bool onlyTurnlane, bool noGeometryLike, bool checkPermissions) {
3732 // do nothing if no turnaround is known
3734 return;
3735 }
3736 // do nothing if the destination node is controlled by a tls and no turnarounds
3737 // shall be appended for such junctions
3738 if (noTLSControlled && myTo->isTLControlled()) {
3739 return;
3740 }
3741 if (noFringe && myTo->getFringeType() == FringeType::OUTER) {
3742 return;
3743 }
3744 bool isDeadEnd = true;
3745 for (const Connection& c : myConnections) {
3746 if ((c.toEdge->getPermissions(c.toLane)
3747 & getPermissions(c.fromLane)
3748 & SVC_PASSENGER) != 0
3749 || (c.toEdge->getPermissions() & getPermissions()) == getPermissions()) {
3750 isDeadEnd = false;
3751 break;
3752 }
3753 }
3754 if (onlyDeadends && !isDeadEnd) {
3755 return;
3756 }
3757 const int fromLane = getFirstAllowedLaneIndex(NBNode::BACKWARD);
3758 if (onlyTurnlane) {
3759 for (const Connection& c : getConnectionsFromLane(fromLane)) {
3760 LinkDirection dir = myTo->getDirection(this, c.toEdge);
3761 if (dir != LinkDirection::LEFT && dir != LinkDirection::PARTLEFT) {
3762 return;
3763 }
3764 }
3765 }
3767 if (checkPermissions) {
3768 if ((getPermissions(fromLane) & myTurnDestination->getPermissions(toLane)) == 0) {
3769 // exclude connection if fromLane and toEdge have no common permissions
3770 return;
3771 }
3772 if ((getPermissions(fromLane) & myTurnDestination->getPermissions(toLane)) == SVC_PEDESTRIAN) {
3773 // exclude connection if the only commonly permitted class are pedestrians
3774 // these connections are later built in NBNode::buildWalkingAreas
3775 return;
3776 }
3777 }
3778 // avoid railway turn-arounds
3781 // except at dead-ends on bidi-edges where they model a reversal in train direction
3782 // @todo #4382: once the network fringe is tagged, it also should not receive turn-arounds)
3783 if (isBidiRail() && isRailDeadEnd()) {
3784 // add a slow connection because direction-reversal implies stopping
3786 return;
3787 } else {
3788 return;
3789 }
3790 };
3791 if (noGeometryLike && !isDeadEnd) {
3792 // ignore paths and service entrances if this edge is for passenger traffic
3793 if (myTo->geometryLike() || ((getPermissions() & SVC_PASSENGER) != 0
3794 && !onlyTurnlane
3795 && myTo->geometryLike(
3798 // make sure the turnDestination has other incoming edges
3800 if (turnIncoming.size() > 1) {
3801 // this edge is always part of incoming
3802 return;
3803 }
3804 }
3805 }
3807}
3808
3809
3810bool
3811NBEdge::isTurningDirectionAt(const NBEdge* const edge) const {
3812 // maybe it was already set as the turning direction
3813 if (edge == myTurnDestination) {
3814 return true;
3815 } else if (myTurnDestination != nullptr) {
3816 // otherwise - it's not if a turning direction exists
3817 return false;
3818 }
3819 return edge == myPossibleTurnDestination;
3820}
3821
3822
3823NBNode*
3824NBEdge::tryGetNodeAtPosition(double pos, double tolerance) const {
3825 // return the from-node when the position is at the begin of the edge
3826 if (pos < tolerance) {
3827 return myFrom;
3828 }
3829 // return the to-node when the position is at the end of the edge
3830 if (pos > myLength - tolerance) {
3831 return myTo;
3832 }
3833 return nullptr;
3834}
3835
3836
3837void
3839 int lanes = e->getNumLanes();
3840 for (int i = 0; i < lanes; i++) {
3841 for (const NBEdge::Connection& el : e->getConnectionsFromLane(i)) {
3842 assert(el.tlID == "");
3843 addLane2LaneConnection(i + laneOff, el.toEdge, el.toLane, Lane2LaneInfoType::COMPUTED);
3844 }
3845 }
3846}
3847
3848
3849bool
3853
3854
3855double
3857 return SUMO_const_laneWidth * (double)myLanes.size();
3858}
3859
3860
3861bool
3862NBEdge::mayBeTLSControlled(int fromLane, NBEdge* toEdge, int toLane) const {
3863 for (const Connection& c : myConnections) {
3864 if (c.fromLane == fromLane && c.toEdge == toEdge && c.toLane == toLane && c.uncontrolled) {
3865 return false;
3866 }
3867 }
3868 return true;
3869}
3870
3871
3872bool
3873NBEdge::setControllingTLInformation(const NBConnection& c, const std::string& tlID) {
3874 const int fromLane = c.getFromLane();
3875 NBEdge* toEdge = c.getTo();
3876 const int toLane = c.getToLane();
3877 const int tlIndex = c.getTLIndex();
3878 const int tlIndex2 = c.getTLIndex2();
3879 // check whether the connection was not set as not to be controled previously
3880 if (!mayBeTLSControlled(fromLane, toEdge, toLane)) {
3881 return false;
3882 }
3883
3884 assert(fromLane < 0 || fromLane < (int) myLanes.size());
3885 // try to use information about the connections if given
3886 if (fromLane >= 0 && toLane >= 0) {
3887 // find the specified connection
3888 std::vector<Connection>::iterator i =
3889 find_if(myConnections.begin(), myConnections.end(), connections_finder(fromLane, toEdge, toLane));
3890 // ok, we have to test this as on the removal of self-loop edges some connections
3891 // will be reassigned
3892 if (i != myConnections.end()) {
3893 // get the connection
3894 Connection& connection = *i;
3895 // set the information about the tl
3896 connection.tlID = tlID;
3897 connection.tlLinkIndex = tlIndex;
3898 connection.tlLinkIndex2 = tlIndex2;
3899 return true;
3900 }
3901 }
3902 // if the original connection was not found, set the information for all
3903 // connections
3904 int no = 0;
3905 bool hadError = false;
3906 for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
3907 if ((*i).toEdge != toEdge) {
3908 continue;
3909 }
3910 if (fromLane >= 0 && fromLane != (*i).fromLane) {
3911 continue;
3912 }
3913 if (toLane >= 0 && toLane != (*i).toLane) {
3914 continue;
3915 }
3916 if ((*i).tlID == "") {
3917 (*i).tlID = tlID;
3918 (*i).tlLinkIndex = tlIndex;
3919 (*i).tlLinkIndex2 = tlIndex2;
3920 no++;
3921 } else {
3922 if ((*i).tlID != tlID && (*i).tlLinkIndex == tlIndex) {
3923 WRITE_WARNINGF(TL("The lane '%' on edge '%' already had a traffic light signal."), i->fromLane, getID());
3924 hadError = true;
3925 }
3926 }
3927 }
3928 if (hadError && no == 0) {
3929 WRITE_WARNINGF(TL("Could not set any signal of the tlLogic '%' (unknown group)."), tlID);
3930 }
3931 return true;
3932}
3933
3934
3935void
3937 for (std::vector<Connection>::iterator it = myConnections.begin(); it != myConnections.end(); it++) {
3938 it->tlID = "";
3939 }
3940}
3941
3942
3945 PositionVector ret;
3946 int lane;
3947 if (myFrom == (&n)) {
3948 // outgoing
3950 ret = myLanes[lane].shape;
3951 } else {
3952 // incoming
3954 ret = myLanes[lane].shape.reverse();
3955 }
3956 ret.move2side(getLaneWidth(lane) / 2.);
3957 return ret;
3958}
3959
3960
3963 PositionVector ret;
3964 int lane;
3965 if (myFrom == (&n)) {
3966 // outgoing
3968 ret = myLanes[lane].shape;
3969 } else {
3970 // incoming
3972 ret = myLanes[lane].shape.reverse();
3973 }
3974 ret.move2side(-getLaneWidth(lane) / 2.);
3975 return ret;
3976}
3977
3978
3979bool
3980NBEdge::expandableBy(NBEdge* possContinuation, std::string& reason) const {
3981 // ok, the number of lanes must match
3982 if (myLanes.size() != possContinuation->myLanes.size()) {
3983 reason = "laneNumber";
3984 return false;
3985 }
3986 // do not create self loops
3987 if (myFrom == possContinuation->myTo) {
3988 reason = "loop";
3989 return false;
3990 }
3991 // conserve bidi-rails
3992 if (isBidiRail() != possContinuation->isBidiRail()) {
3993 reason = "bidi-rail";
3994 return false;
3995 }
3996 // also, check whether the connections - if any exit do allow to join
3997 // both edges
3998 // This edge must have a one-to-one connection to the following lanes
3999 switch (myStep) {
4001 break;
4003 break;
4005 // the following edge must be connected
4006 const EdgeVector& conn = getConnectedEdges();
4007 if (find(conn.begin(), conn.end(), possContinuation) == conn.end()) {
4008 reason = "disconnected";
4009 return false;
4010 }
4011 }
4012 break;
4017 // the possible continuation must be connected
4018 if (find_if(myConnections.begin(), myConnections.end(), connections_toedge_finder(possContinuation)) == myConnections.end()) {
4019 reason = "disconnected";
4020 return false;
4021 }
4022 // all lanes must go to the possible continuation
4023 std::vector<int> conns = getConnectionLanes(possContinuation);
4024 const int offset = MAX2(0, getFirstNonPedestrianLaneIndex(NBNode::FORWARD, true));
4025 if (conns.size() < myLanes.size() - offset) {
4026 reason = "some lanes disconnected";
4027 return false;
4028 }
4029 }
4030 break;
4031 default:
4032 break;
4033 }
4034 const double minLength = OptionsCont::getOptions().getFloat("geometry.remove.min-length");
4035 if (minLength > 0 && (possContinuation->getLoadedLength() < minLength || getLoadedLength() < minLength)) {
4036 return true;
4037 }
4038 const double maxJunctionSize = OptionsCont::getOptions().getFloat("geometry.remove.max-junction-size");
4039 if (maxJunctionSize >= 0) {
4040 const double junctionSize = myGeom.back().distanceTo2D(possContinuation->myGeom.front());
4041 if (junctionSize > maxJunctionSize + POSITION_EPS) {
4042 reason = "junction size (" + toString(junctionSize) + ") > max-junction-size (" + toString(maxJunctionSize) + ")";
4043 return false;
4044 }
4045 }
4046 // the priority, too (?)
4047 if (getPriority() != possContinuation->getPriority()) {
4048 reason = "priority";
4049 return false;
4050 }
4051 // the speed allowed
4052 if (mySpeed != possContinuation->mySpeed) {
4053 reason = "speed";
4054 return false;
4055 }
4056 // the routingType
4057 if (myRoutingType != possContinuation->myRoutingType) {
4058 reason = "routingType";
4059 return false;
4060 }
4061 // spreadtype should match or it will look ugly
4062 if (myLaneSpreadFunction != possContinuation->myLaneSpreadFunction) {
4063 reason = "spreadType";
4064 return false;
4065 }
4066 // matching lanes must have identical properties
4067 for (int i = 0; i < (int)myLanes.size(); i++) {
4068 if (myLanes[i].speed != possContinuation->myLanes[i].speed) {
4069 reason = "lane " + toString(i) + " speed";
4070 return false;
4071 } else if (myLanes[i].permissions != possContinuation->myLanes[i].permissions) {
4072 reason = "lane " + toString(i) + " permissions";
4073 return false;
4074 } else if (myLanes[i].changeLeft != possContinuation->myLanes[i].changeLeft || myLanes[i].changeRight != possContinuation->myLanes[i].changeRight) {
4075 reason = "lane " + toString(i) + " change restrictions";
4076 return false;
4077 } else if (myLanes[i].width != possContinuation->myLanes[i].width &&
4078 fabs(myLanes[i].width - possContinuation->myLanes[i].width) > OptionsCont::getOptions().getFloat("geometry.remove.width-tolerance")) {
4079 reason = "lane " + toString(i) + " width";
4080 return false;
4081 }
4082 }
4083 // if given identically osm names
4084 if (!OptionsCont::getOptions().isDefault("output.street-names") && myStreetName != possContinuation->getStreetName()
4085 && ((myStreetName != "" && possContinuation->getStreetName() != "")
4086 // only permit merging a short unnamed road with a longer named road
4087 || (myStreetName != "" && myLength <= possContinuation->getLength())
4088 || (myStreetName == "" && myLength >= possContinuation->getLength()))) {
4089 return false;
4090 }
4091
4092 return true;
4093}
4094
4095
4096void
4099 // append geometry
4100 myGeom.append(e->myGeom);
4101 for (int i = 0; i < (int)myLanes.size(); i++) {
4102 myLanes[i].customShape.append(e->myLanes[i].customShape);
4103 if (myLanes[i].hasParameter(SUMO_PARAM_ORIGID) || e->myLanes[i].hasParameter(SUMO_PARAM_ORIGID)
4104 || OptionsCont::getOptions().getBool("output.original-names")) {
4105 const std::string origID = myLanes[i].getParameter(SUMO_PARAM_ORIGID, getID());
4106 const std::string origID2 = e->myLanes[i].getParameter(SUMO_PARAM_ORIGID, e->getID());
4107 if (origID != origID2) {
4108 myLanes[i].setParameter(SUMO_PARAM_ORIGID, origID + " " + origID2);
4109 }
4110 }
4111 myLanes[i].connectionsDone = e->myLanes[i].connectionsDone;
4112 myLanes[i].turnSigns = e->myLanes[i].turnSigns;
4113 }
4114 if (e->getLength() > myLength) {
4115 // possibly some lane attributes differ (when using option geometry.remove.min-length)
4116 // make sure to use the attributes from the longer edge
4117 for (int i = 0; i < (int)myLanes.size(); i++) {
4118 myLanes[i].width = e->myLanes[i].width;
4119 }
4120 // defined name prevails over undefined name of shorter road
4121 if (myStreetName == "") {
4123 }
4124 }
4125 // recompute length
4126 myLength += e->myLength;
4127 if (myLoadedLength > 0 || e->myLoadedLength > 0) {
4129 }
4130 // copy the connections and the building step if given
4131 myStep = e->myStep;
4137 // set the node
4138 myTo = e->myTo;
4144 }
4145 computeAngle(); // myEndAngle may be different now
4146}
4147
4148
4149void
4150NBEdge::updateRemovedNodes(const std::string& removed) {
4151 std::string result = getParameter(SUMO_PARAM_REMOVED_NODES);
4152 if (!result.empty() && !removed.empty()) {
4153 result += " ";
4154 }
4155 result += removed;
4156 if (!result.empty()) {
4158 }
4159}
4160
4161
4162bool
4164 for (std::vector<Connection>::const_iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
4165 if ((*i).toEdge == e && (*i).tlID != "") {
4166 return true;
4167 }
4168 }
4169 return false;
4170}
4171
4172
4173NBEdge*
4174NBEdge::getTurnDestination(bool possibleDestination) const {
4175 if (myTurnDestination == nullptr && possibleDestination) {
4177 }
4178 return myTurnDestination;
4179}
4180
4181
4182std::string
4183NBEdge::getLaneID(int lane) const {
4184 return myID + "_" + toString(lane);
4185}
4186
4187
4188bool
4189NBEdge::isNearEnough2BeJoined2(NBEdge* e, double threshold) const {
4190 std::vector<double> distances = myGeom.distances(e->getGeometry());
4191 assert(distances.size() > 0);
4192 return VectorHelper<double>::maxValue(distances) < threshold;
4193}
4194
4195
4196void
4197NBEdge::addLane(int index, bool recomputeShape, bool recomputeConnections, bool shiftIndices) {
4198 assert(index <= (int)myLanes.size());
4199 myLanes.insert(myLanes.begin() + index, Lane(this, ""));
4200 // copy attributes
4201 if (myLanes.size() > 1) {
4202 int templateIndex = index > 0 ? index - 1 : index + 1;
4203 myLanes[index].speed = myLanes[templateIndex].speed;
4204 myLanes[index].friction = myLanes[templateIndex].friction;
4205 myLanes[index].permissions = myLanes[templateIndex].permissions;
4206 myLanes[index].preferred = myLanes[templateIndex].preferred;
4207 myLanes[index].endOffset = myLanes[templateIndex].endOffset;
4208 myLanes[index].width = myLanes[templateIndex].width;
4209 myLanes[index].updateParameters(myLanes[templateIndex].getParametersMap());
4210 }
4211 const EdgeVector& incs = myFrom->getIncomingEdges();
4212 if (recomputeShape) {
4214 }
4215 if (recomputeConnections) {
4216 for (EdgeVector::const_iterator i = incs.begin(); i != incs.end(); ++i) {
4217 (*i)->invalidateConnections(true);
4218 }
4220 } else if (shiftIndices) {
4221 // shift outgoing connections above the added lane to the left
4222 for (Connection& c : myConnections) {
4223 if (c.fromLane >= index) {
4224 c.fromLane += 1;
4225 }
4226 }
4227 // shift incoming connections above the added lane to the left
4228 for (NBEdge* inc : myFrom->getIncomingEdges()) {
4229 for (Connection& c : inc->myConnections) {
4230 if (c.toEdge == this && c.toLane >= index) {
4231 c.toLane += 1;
4232 }
4233 }
4234 }
4235 myFrom->shiftTLConnectionLaneIndex(this, +1, index - 1);
4236 myTo->shiftTLConnectionLaneIndex(this, +1, index - 1);
4237 }
4238}
4239
4240void
4242 int newLaneNo = (int)myLanes.size() + by;
4243 while ((int)myLanes.size() < newLaneNo) {
4244 // recompute shapes on last addition
4245 const bool recompute = ((int)myLanes.size() == newLaneNo - 1) && myStep < EdgeBuildingStep::LANES2LANES_USER;
4246 addLane((int)myLanes.size(), recompute, recompute, false);
4247 }
4248}
4249
4250
4251void
4252NBEdge::deleteLane(int index, bool recompute, bool shiftIndices) {
4253 assert(index < (int)myLanes.size());
4254 myLanes.erase(myLanes.begin() + index);
4255 if (recompute) {
4257 const EdgeVector& incs = myFrom->getIncomingEdges();
4258 for (EdgeVector::const_iterator i = incs.begin(); i != incs.end(); ++i) {
4259 (*i)->invalidateConnections(true);
4260 }
4262 } else if (shiftIndices) {
4263 removeFromConnections(nullptr, index, -1, false, true);
4264 for (NBEdge* inc : myFrom->getIncomingEdges()) {
4265 inc->removeFromConnections(this, -1, index, false, true);
4266 }
4267 }
4268}
4269
4270
4271void
4273 int newLaneNo = (int) myLanes.size() - by;
4274 assert(newLaneNo > 0);
4275 while ((int)myLanes.size() > newLaneNo) {
4276 // recompute shapes on last removal
4277 const bool recompute = (int)myLanes.size() == newLaneNo + 1 && myStep < EdgeBuildingStep::LANES2LANES_USER;
4278 deleteLane((int)myLanes.size() - 1, recompute, false);
4279 }
4280}
4281
4282
4283void
4288
4289
4290void
4292 if (lane < 0) { // all lanes are meant...
4293 for (int i = 0; i < (int)myLanes.size(); i++) {
4294 allowVehicleClass(i, vclass);
4295 }
4296 } else {
4297 assert(lane < (int)myLanes.size());
4298 myLanes[lane].permissions |= vclass;
4299 }
4300}
4301
4302
4303void
4305 if (lane < 0) { // all lanes are meant...
4306 for (int i = 0; i < (int)myLanes.size(); i++) {
4307 disallowVehicleClass((int) i, vclass);
4308 }
4309 } else {
4310 assert(lane < (int)myLanes.size());
4311 myLanes[lane].permissions &= ~vclass;
4312 }
4313}
4314
4315
4316void
4318 if (lane < 0) { // all lanes are meant...
4319 for (int i = 0; i < (int)myLanes.size(); i++) {
4320 preferVehicleClass(i, vclasses);
4321 }
4322 } else {
4323 assert(lane < (int)myLanes.size());
4324 myLanes[lane].permissions |= vclasses;
4325 myLanes[lane].preferred |= vclasses;
4326 }
4327}
4328
4329
4330void
4331NBEdge::setLaneWidth(int lane, double width) {
4332 if (lane < 0) {
4333 // all lanes are meant...
4334 myLaneWidth = width;
4335 for (int i = 0; i < (int)myLanes.size(); i++) {
4336 // ... do it for each lane
4337 setLaneWidth(i, width);
4338 }
4339 return;
4340 }
4341 assert(lane < (int)myLanes.size());
4342 myLanes[lane].width = width;
4343}
4344
4345void
4346NBEdge::setLaneType(int lane, const std::string& type) {
4347 if (lane < 0) {
4348 for (int i = 0; i < (int)myLanes.size(); i++) {
4349 // ... do it for each lane
4350 setLaneType(i, type);
4351 }
4352 return;
4353 }
4354 assert(lane < (int)myLanes.size());
4355 myLanes[lane].type = type;
4356}
4357
4358
4359double
4360NBEdge::getLaneWidth(int lane) const {
4361 return myLanes[lane].width != UNSPECIFIED_WIDTH
4362 ? myLanes[lane].width
4364}
4365
4366double
4368 const NBNode& node,
4369 const NBEdge::Connection& connection,
4370 const NBEdge::Lane& successor,
4371 bool isVia) const {
4372
4373 if (!isVia && node.isConstantWidthTransition() && getNumLanes() > connection.toEdge->getNumLanes()) {
4374 return getLaneWidth(connection.fromLane);
4375 }
4376
4377 return (isBikepath(getPermissions(connection.fromLane)) && (
4378 getLaneWidth(connection.fromLane) < successor.width || successor.width == UNSPECIFIED_WIDTH)) ?
4379 myLanes[connection.fromLane].width : successor.width; // getLaneWidth(connection.fromLane) never returns -1 (UNSPECIFIED_WIDTH)
4380}
4381
4382double
4384 double result = 0;
4385 for (int i = 0; i < (int)myLanes.size(); i++) {
4386 result += getLaneWidth(i);
4387 }
4388 return result;
4389}
4390
4391double
4392NBEdge::getEndOffset(int lane) const {
4393 return myLanes[lane].endOffset != UNSPECIFIED_OFFSET ? myLanes[lane].endOffset : getEndOffset();
4394}
4395
4396
4397const StopOffset&
4399 return myEdgeStopOffset;
4400}
4401
4402
4403const StopOffset&
4405 if (lane == -1) {
4406 return myEdgeStopOffset;
4407 } else {
4408 return myLanes[lane].laneStopOffset;
4409 }
4410}
4411
4412
4413void
4414NBEdge::setEndOffset(int lane, double offset) {
4415 if (lane < 0) {
4416 // all lanes are meant...
4417 myEndOffset = offset;
4418 for (int i = 0; i < (int)myLanes.size(); i++) {
4419 // ... do it for each lane
4420 setEndOffset(i, offset);
4421 }
4422 return;
4423 }
4424 assert(lane < (int)myLanes.size());
4425 myLanes[lane].endOffset = offset;
4426}
4427
4428
4429bool
4430NBEdge::setEdgeStopOffset(int lane, const StopOffset& offset, bool overwrite) {
4431 if (lane < 0) {
4432 if (!overwrite && myEdgeStopOffset.isDefined()) {
4433 return false;
4434 }
4435 // all lanes are meant...
4436 if (offset.getOffset() < 0) {
4437 // Edge length unknown at parsing time, thus check here.
4438 WRITE_WARNINGF(TL("Ignoring invalid stopOffset for edge '%' (negative offset)."), getID());
4439 return false;
4440 } else {
4441 myEdgeStopOffset = offset;
4442 }
4443 } else if (lane < (int)myLanes.size()) {
4444 if (!myLanes[lane].laneStopOffset.isDefined() || overwrite) {
4445 if (offset.getOffset() < 0) {
4446 // Edge length unknown at parsing time, thus check here.
4447 WRITE_WARNINGF(TL("Ignoring invalid stopOffset for lane '%' (negative offset)."), getLaneID(lane));
4448 } else {
4449 myLanes[lane].laneStopOffset = offset;
4450 }
4451 }
4452 } else {
4453 WRITE_WARNINGF(TL("Ignoring invalid stopOffset for lane '%' (invalid lane index)."), toString(lane));
4454 }
4455 return true;
4456}
4457
4458
4459void
4460NBEdge::setSpeed(int lane, double speed) {
4461 if (lane < 0) {
4462 // all lanes are meant...
4463 mySpeed = speed;
4464 for (int i = 0; i < (int)myLanes.size(); i++) {
4465 // ... do it for each lane
4466 setSpeed(i, speed);
4467 }
4468 return;
4469 }
4470 assert(lane < (int)myLanes.size());
4471 myLanes[lane].speed = speed;
4472}
4473
4474
4475void
4476NBEdge::setFriction(int lane, double friction) {
4477 if (lane < 0) {
4478 // all lanes are meant...
4479 myFriction = friction;
4480 for (int i = 0; i < (int)myLanes.size(); i++) {
4481 // ... do it for each lane
4482 setFriction(i, friction);
4483 }
4484 return;
4485 }
4486 assert(lane < (int)myLanes.size());
4487 myLanes[lane].friction = friction;
4488}
4489
4490
4491void
4492NBEdge::setAcceleration(int lane, bool accelRamp) {
4493 assert(lane >= 0);
4494 assert(lane < (int)myLanes.size());
4495 myLanes[lane].accelRamp = accelRamp;
4496}
4497
4498
4499void
4500NBEdge::setLaneShape(int lane, const PositionVector& shape) {
4501 assert(lane >= 0);
4502 assert(lane < (int)myLanes.size());
4503 myLanes[lane].customShape = shape;
4504}
4505
4506
4507void
4509 if (lane < 0) {
4510 for (int i = 0; i < (int)myLanes.size(); i++) {
4511 // ... do it for each lane
4512 setPermissions(permissions, i);
4513 }
4514 } else {
4515 assert(lane < (int)myLanes.size());
4516 myLanes[lane].permissions = permissions;
4517 }
4518}
4519
4520
4521void
4523 if (lane < 0) {
4524 for (int i = 0; i < (int)myLanes.size(); i++) {
4525 // ... do it for each lane
4526 setPreferredVehicleClass(permissions, i);
4527 }
4528 } else {
4529 assert(lane < (int)myLanes.size());
4530 myLanes[lane].preferred = permissions;
4531 }
4532}
4533
4534
4535void
4537 assert(lane >= 0);
4538 assert(lane < (int)myLanes.size());
4539 myLanes[lane].changeLeft = changeLeft;
4540 myLanes[lane].changeRight = changeRight;
4541}
4542
4543
4545NBEdge::getPermissions(int lane) const {
4546 if (lane < 0) {
4547 SVCPermissions result = 0;
4548 for (int i = 0; i < (int)myLanes.size(); i++) {
4549 result |= getPermissions(i);
4550 }
4551 return result;
4552 } else {
4553 assert(lane < (int)myLanes.size());
4554 return myLanes[lane].permissions;
4555 }
4556}
4557
4558
4559void
4561 myLoadedLength = val;
4562}
4563
4564void
4566 myLength = val;
4567}
4568
4569
4570void
4572 for (std::vector<Lane>::iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
4573 (*i).permissions = SVCAll;
4574 (*i).preferred = 0;
4575 }
4576}
4577
4578
4579bool
4581 if (c1.fromLane != c2.fromLane) {
4582 return c1.fromLane < c2.fromLane;
4583 }
4584 if (c1.toEdge != c2.toEdge) {
4585 return false; // do not change ordering among toEdges as this is determined by angle in an earlier step
4586 }
4587 return c1.toLane < c2.toLane;
4588}
4589
4590
4591double
4595 } else {
4597 myLanes.back().shape.back() : myLanes[getNumLanes() / 2].shape.back();
4598 //std::cout << getID() << " signalPos=" << mySignalPosition << " laneEnd=" << laneEnd << " toShape=" << myTo->getShape() << " toBorder=" << myToBorder << "\n";
4599 return mySignalPosition.distanceTo2D(laneEnd);
4600 }
4601}
4602
4603
4604int
4605NBEdge::getFirstNonPedestrianLaneIndex(int direction, bool exclusive) const {
4606 assert(direction == NBNode::FORWARD || direction == NBNode::BACKWARD);
4607 const int start = (direction == NBNode::FORWARD ? 0 : (int)myLanes.size() - 1);
4608 const int end = (direction == NBNode::FORWARD ? (int)myLanes.size() : - 1);
4609 for (int i = start; i != end; i += direction) {
4610 // SVCAll, does not count as a sidewalk, green verges (permissions = 0) do not count as road
4611 // in the exclusive case, lanes that allow pedestrians along with any other class also count as road
4612 if ((exclusive && myLanes[i].permissions != SVC_PEDESTRIAN && myLanes[i].permissions != 0)
4613 || ((myLanes[i].permissions & SVC_PEDESTRIAN) == 0 && myLanes[i].permissions != 0)) {
4614 return i;
4615 }
4616 }
4617 return -1;
4618}
4619
4620int
4621NBEdge::getFirstNonPedestrianNonBicycleLaneIndex(int direction, bool exclusive) const {
4622 assert(direction == NBNode::FORWARD || direction == NBNode::BACKWARD);
4623 const int start = (direction == NBNode::FORWARD ? 0 : (int)myLanes.size() - 1);
4624 const int end = (direction == NBNode::FORWARD ? (int)myLanes.size() : - 1);
4625 for (int i = start; i != end; i += direction) {
4626 // SVCAll, does not count as a sidewalk, green verges (permissions = 0) do not count as road
4627 // in the exclusive case, lanes that allow pedestrians along with any other class also count as road
4628 SVCPermissions p = myLanes[i].permissions;
4629 if ((exclusive && p != SVC_PEDESTRIAN && p != SVC_BICYCLE && p != (SVC_PEDESTRIAN | SVC_BICYCLE) && p != 0)
4630 || (p == SVCAll || ((p & (SVC_PEDESTRIAN | SVC_BICYCLE)) == 0 && p != 0))) {
4631 return i;
4632 }
4633 }
4634 return -1;
4635}
4636
4637int
4639 for (int i = 0; i < (int)myLanes.size(); i++) {
4640 if (myLanes[i].permissions == permissions) {
4641 return i;
4642 }
4643 }
4644 return -1;
4645}
4646
4647int
4649 assert(direction == NBNode::FORWARD || direction == NBNode::BACKWARD);
4650 const int start = (direction == NBNode::FORWARD ? 0 : (int)myLanes.size() - 1);
4651 const int end = (direction == NBNode::FORWARD ? (int)myLanes.size() : - 1);
4652 for (int i = start; i != end; i += direction) {
4653 if (myLanes[i].permissions != 0) {
4654 return i;
4655 }
4656 }
4657 return end - direction;
4658}
4659
4660
4661std::set<SVCPermissions>
4662NBEdge::getPermissionVariants(int iStart, int iEnd) const {
4663 std::set<SVCPermissions> result;
4664 if (iStart < 0 || iStart >= getNumLanes() || iEnd > getNumLanes()) {
4665 throw ProcessError("invalid indices iStart " + toString(iStart) + " iEnd " + toString(iEnd) + " for edge with " + toString(getNumLanes()) + " lanes.");
4666 }
4667 for (int i = iStart; i < iEnd; ++i) {
4668 result.insert(getPermissions(i));
4669 }
4670 return result;
4671}
4672
4673int
4674NBEdge::getNumLanesThatAllow(SVCPermissions permissions, bool allPermissions) const {
4675 int result = 0;
4676 for (const Lane& lane : myLanes) {
4677 if ((allPermissions && (lane.permissions & permissions) == permissions)
4678 || (!allPermissions && (lane.permissions & permissions) != 0)) {
4679 result++;
4680 }
4681 }
4682 return result;
4683}
4684
4685bool
4687 assert(lane >= 0 && lane < getNumLanes());
4688 return myLanes[lane].changeLeft == SVC_UNSPECIFIED ? true : (myLanes[lane].changeLeft & vclass) == vclass;
4689}
4690
4691bool
4693 assert(lane >= 0 && lane < getNumLanes());
4694 return myLanes[lane].changeRight == SVC_UNSPECIFIED ? true : (myLanes[lane].changeRight & vclass) == vclass;
4695}
4696
4697double
4699 double angle = getAngleAtNode(node) + (getFromNode() == node ? 180.0 : 0.0);
4700 if (angle < 0) {
4701 angle += 360.0;
4702 }
4703 if (angle >= 360) {
4704 angle -= 360.0;
4705 }
4706 if (gDebugFlag1) {
4707 std::cout << getID() << " angle=" << getAngleAtNode(node) << " convAngle=" << angle << "\n";
4708 }
4709 return angle;
4710}
4711
4712
4715 int index = getFirstNonPedestrianLaneIndex(direction);
4716 if (index < 0) {
4717 throw ProcessError(TLF("Edge % allows pedestrians on all lanes", getID()));
4718 }
4719 return myLanes[index];
4720}
4721
4722std::string
4724 // see IntermodalEdge::getSidewalk()
4725 for (int i = 0; i < (int)myLanes.size(); i++) {
4726 if (myLanes[i].permissions == SVC_PEDESTRIAN) {
4727 return getLaneID(i);
4728 }
4729 }
4730 for (int i = 0; i < (int)myLanes.size(); i++) {
4731 if ((myLanes[i].permissions & SVC_PEDESTRIAN) != 0) {
4732 return getLaneID(i);
4733 }
4734 }
4735 return getLaneID(0);
4736}
4737
4738void
4739NBEdge::addSidewalk(double width) {
4741}
4742
4743
4744void
4745NBEdge::restoreSidewalk(std::vector<NBEdge::Lane> oldLanes, PositionVector oldGeometry, std::vector<NBEdge::Connection> oldConnections) {
4746 restoreRestrictedLane(SVC_PEDESTRIAN, oldLanes, oldGeometry, oldConnections);
4747}
4748
4749
4750void
4751NBEdge::addBikeLane(double width) {
4753}
4754
4755
4756void
4757NBEdge::restoreBikelane(std::vector<NBEdge::Lane> oldLanes, PositionVector oldGeometry, std::vector<NBEdge::Connection> oldConnections) {
4758 restoreRestrictedLane(SVC_BICYCLE, oldLanes, oldGeometry, oldConnections);
4759}
4760
4761bool
4763 for (const Lane& lane : myLanes) {
4764 if (lane.permissions == vclass) {
4765 return true;
4766 }
4767 }
4768 return false;
4769}
4770
4771
4772void
4774 if (hasRestrictedLane(vclass)) {
4775 WRITE_WARNINGF(TL("Edge '%' already has a dedicated lane for %s. Not adding another one."), getID(), toString(vclass));
4776 return;
4777 }
4779 myGeom.move2side(width / 2);
4780 }
4781 // disallow the designated vclass on all "old" lanes
4782 disallowVehicleClass(-1, vclass);
4783 // don't create a restricted vehicle lane to the right of a sidewalk
4784 const int newIndex = (vclass != SVC_PEDESTRIAN && myLanes[0].permissions == SVC_PEDESTRIAN) ? 1 : 0;
4785 if (newIndex == 0) {
4786 // disallow pedestrians on all "higher" lanes to ensure that sidewalk remains the rightmost lane
4788 }
4789 // add new lane
4790 myLanes.insert(myLanes.begin() + newIndex, Lane(this, myLanes[0].getParameter(SUMO_PARAM_ORIGID)));
4791 myLanes[newIndex].permissions = vclass;
4792 myLanes[newIndex].width = fabs(width);
4793 // shift outgoing connections to the left
4794 for (std::vector<Connection>::iterator it = myConnections.begin(); it != myConnections.end(); ++it) {
4795 Connection& c = *it;
4796 if (c.fromLane >= newIndex) {
4797 c.fromLane += 1;
4798 }
4799 }
4800 // shift incoming connections to the left
4801 const EdgeVector& incoming = myFrom->getIncomingEdges();
4802 for (EdgeVector::const_iterator it = incoming.begin(); it != incoming.end(); ++it) {
4803 (*it)->shiftToLanesToEdge(this, 1);
4804 }
4808}
4809
4810
4811void
4812NBEdge::restoreRestrictedLane(SUMOVehicleClass vclass, std::vector<NBEdge::Lane> oldLanes, PositionVector oldGeometry, std::vector<NBEdge::Connection> oldConnections) {
4813 // check that previously lane was transformed
4814 if (myLanes[0].permissions != vclass) {
4815 WRITE_WARNINGF(TL("Edge '%' doesn't have a dedicated lane for %s. Cannot be restored."), getID(), toString(vclass));
4816 return;
4817 }
4818 // restore old values
4819 myGeom = oldGeometry;
4820 myLanes = oldLanes;
4821 myConnections = oldConnections;
4822 // shift incoming connections to the right
4823 const EdgeVector& incoming = myFrom->getIncomingEdges();
4824 for (EdgeVector::const_iterator it = incoming.begin(); it != incoming.end(); ++it) {
4825 (*it)->shiftToLanesToEdge(this, 0);
4826 }
4827 // Shift TL conections
4831}
4832
4833
4834void
4837 for (std::vector<Connection>::iterator it = myConnections.begin(); it != myConnections.end(); ++it) {
4838 if ((*it).toEdge == to && (*it).toLane >= 0) {
4839 (*it).toLane += laneOff;
4840 }
4841 }
4842}
4843
4844
4845bool
4849 && !isRailway(other->getPermissions())
4850 && getBidiEdge() == nullptr) {
4851 const int i = (node == myTo ? -1 : 0);
4852 const int i2 = (node == myTo ? 0 : -1);
4853 const double dist = myGeom[i].distanceTo2D(node->getPosition());
4854 const double neededOffset = getTotalWidth() / 2;
4855 const double dist2 = MIN2(myGeom.distance2D(other->getGeometry()[i2]),
4856 other->getGeometry().distance2D(myGeom[i]));
4857 const double neededOffset2 = neededOffset + (other->getLaneSpreadFunction() == LaneSpreadFunction::CENTER
4858 ? (other->getTotalWidth()) / 2 : 0);
4859 const double missing = neededOffset - dist;
4860 const double missing2 = neededOffset2 - dist2;
4861 double shift = 0;
4862 if (missing > 0 && missing2 > 0) {
4863 shift = MIN2(missing, missing2);
4864 } else if (missing2) {
4865 shift = missing2;
4866 }
4867 if (shift > 0) {
4868 PositionVector tmp = myGeom;
4869 try {
4870 tmp.move2side(shift);
4871 tmp[i].round(gPrecision);
4872 myGeom[i] = tmp[i];
4873 computeAngle();
4874 return true;
4875 //std::cout << getID() << " shiftPositionAtNode needed=" << neededOffset << " dist=" << dist << " needed2=" << neededOffset2 << " dist2=" << dist2 << " by=" << (neededOffset - dist) << " other=" << other->getID() << "\n";
4876 } catch (InvalidArgument&) {
4877 WRITE_WARNINGF(TL("Could not avoid overlapping shape at node '%' for edge '%'."), node->getID(), getID());
4878 }
4879 }
4880 }
4881 return false;
4882}
4883
4884
4887 if (myLoadedLength > 0) {
4889 } else {
4890 return myGeom.positionAtOffset(offset);
4891 }
4892}
4893
4894
4895double
4897 double result = getLoadedLength();
4898 if (OptionsCont::getOptions().getBool("no-internal-links") && !hasLoadedLength()) {
4899 // use length to junction center even if a modified geometry was given
4901 geom.push_back_noDoublePos(getToNode()->getCenter());
4902 geom.push_front_noDoublePos(getFromNode()->getCenter());
4903 result = geom.length();
4904 }
4905 double avgEndOffset = 0;
4906 for (const Lane& lane : myLanes) {
4907 avgEndOffset += lane.endOffset;
4908 }
4909 if (isBidiRail()) {
4910 avgEndOffset += myPossibleTurnDestination->getEndOffset();
4911 }
4912 avgEndOffset /= (double)myLanes.size();
4913 return MAX2(result - avgEndOffset, POSITION_EPS);
4914}
4915
4916
4917void
4918NBEdge::setOrigID(const std::string origID, const bool append, const int laneIdx) {
4919 if (laneIdx == -1) {
4920 for (int i = 0; i < (int)myLanes.size(); i++) {
4921 setOrigID(origID, append, i);
4922 }
4923 } else {
4924 if (origID != "") {
4925 if (append) {
4926 std::vector<std::string> oldIDs = StringTokenizer(myLanes[laneIdx].getParameter(SUMO_PARAM_ORIGID)).getVector();
4927 if (std::find(oldIDs.begin(), oldIDs.end(), origID) == oldIDs.end()) {
4928 oldIDs.push_back(origID);
4929 }
4930 myLanes[laneIdx].setParameter(SUMO_PARAM_ORIGID, toString(oldIDs));
4931 } else {
4932 myLanes[laneIdx].setParameter(SUMO_PARAM_ORIGID, origID);
4933 }
4934 } else {
4935 // do not record empty origID parameter
4936 myLanes[laneIdx].unsetParameter(SUMO_PARAM_ORIGID);
4937 }
4938 }
4939}
4940
4941
4942const EdgeVector&
4944 // @todo cache successors instead of recomputing them every time
4945 mySuccessors.clear();
4946 //std::cout << "getSuccessors edge=" << getID() << " svc=" << toString(vClass) << " cons=" << myConnections.size() << "\n";
4947 for (const Connection& con : myConnections) {
4948 if (con.fromLane >= 0 && con.toLane >= 0 && con.toEdge != nullptr &&
4949 (vClass == SVC_IGNORING || (getPermissions(con.fromLane)
4950 & con.toEdge->getPermissions(con.toLane) & vClass) != 0)
4951 && std::find(mySuccessors.begin(), mySuccessors.end(), con.toEdge) == mySuccessors.end()) {
4952 mySuccessors.push_back(con.toEdge);
4953 //std::cout << " succ=" << con.toEdge->getID() << "\n";
4954 }
4955 }
4956 return mySuccessors;
4957}
4958
4959
4961NBEdge::getViaSuccessors(SUMOVehicleClass vClass, bool /*ignoreTransientPermissions*/) const {
4962 // @todo cache successors instead of recomputing them every time
4963 myViaSuccessors.clear();
4964 for (const Connection& con : myConnections) {
4965 std::pair<const NBEdge*, const Connection*> pair(con.toEdge, nullptr);
4966 // special case for Persons in Netedit
4967 if (vClass == SVC_PEDESTRIAN) {
4968 myViaSuccessors.push_back(pair); // Pedestrians have complete freedom of movement in all successors
4969 } else if ((con.fromLane >= 0) && (con.toLane >= 0) &&
4970 (con.toEdge != nullptr) &&
4971 ((getPermissions(con.fromLane) & con.toEdge->getPermissions(con.toLane) & vClass) == vClass)) {
4972 // ignore duplicates
4973 if (con.getLength() > 0) {
4974 pair.second = &con;
4975 }
4976 myViaSuccessors.push_back(pair);
4977 }
4978 }
4979 return myViaSuccessors;
4980}
4981
4982
4983void
4984NBEdge::debugPrintConnections(bool outgoing, bool incoming) const {
4985 if (outgoing) {
4986 for (const Connection& c : myConnections) {
4987 std::cout << " " << getID() << "_" << c.fromLane << "->" << c.toEdge->getID() << "_" << c.toLane << "\n";
4988 }
4989 }
4990 if (incoming) {
4991 for (NBEdge* inc : myFrom->getIncomingEdges()) {
4992 for (Connection& c : inc->myConnections) {
4993 if (c.toEdge == this) {
4994 std::cout << " " << inc->getID() << "_" << c.fromLane << "->" << c.toEdge->getID() << "_" << c.toLane << "\n";
4995 }
4996 }
4997 }
4998 }
4999}
5000
5001
5002int
5003NBEdge::getLaneIndexFromLaneID(const std::string laneID) {
5004 return StringUtils::toInt(laneID.substr(laneID.rfind("_") + 1));
5005}
5006
5007bool
5009 bool haveJoined = false;
5010 int i = 0;
5011 while (i < getNumLanes() - 1) {
5012 if ((getPermissions(i) == perms) && (getPermissions(i + 1) == perms)) {
5013 const double newWidth = getLaneWidth(i) + getLaneWidth(i + 1);
5014 const std::string newType = myLanes[i].type + "|" + myLanes[i + 1].type;
5015 deleteLane(i, false, true);
5016 setLaneWidth(i, newWidth);
5017 setLaneType(i, newType);
5018 haveJoined = true;
5019 } else {
5020 i++;
5021 }
5022 }
5023 return haveJoined;
5024}
5025
5026
5029 EdgeVector result;
5030 for (NBEdge* edge : edges) {
5031 if ((edge->getPermissions() & permissions) != 0) {
5032 result.push_back(edge);
5033 }
5034 }
5035 return result;
5036}
5037
5038NBEdge*
5040 EdgeVector cands = filterByPermissions(myTo->getOutgoingEdges(), permissions);
5041 if (cands.size() == 0) {
5042 return nullptr;
5043 }
5044 sort(cands.begin(), cands.end(), NBContHelper::edge_similar_direction_sorter(this));
5045 NBEdge* best = cands.front();
5046 if (isTurningDirectionAt(best)) {
5047 return nullptr;
5048 } else {
5049 return best;
5050 }
5051}
5052
5053NBEdge*
5055 EdgeVector cands = filterByPermissions(myFrom->getIncomingEdges(), permissions);
5056 if (cands.size() == 0) {
5057 return nullptr;
5058 }
5059 sort(cands.begin(), cands.end(), NBContHelper::edge_similar_direction_sorter(this, false));
5060 NBEdge* best = cands.front();
5061 if (best->isTurningDirectionAt(this)) {
5062 return nullptr;
5063 } else {
5064 return best;
5065 }
5066}
5067
5068
5069NBEdge*
5071 NBEdge* opposite = nullptr;
5072 if (getNumLanes() > 0) {
5073 NBEdge::Lane& lastLane = myLanes.back();
5074 const double lastWidth = getLaneWidth(getNumLanes() - 1);
5075 if (lastLane.oppositeID == "" || reguess) {
5076 for (NBEdge* cand : getToNode()->getOutgoingEdges()) {
5077 if (cand->getToNode() == getFromNode() && !cand->getLanes().empty()) {
5078 const NBEdge::Lane& candLastLane = cand->getLanes().back();
5079 if (candLastLane.oppositeID == "" || candLastLane.oppositeID == getLaneID(getNumLanes() - 1)) {
5080 const double lastWidthCand = cand->getLaneWidth(cand->getNumLanes() - 1);
5081 // in sharp corners, the difference may be higher
5082 // factor (sqrt(2) for 90 degree corners
5083 const double threshold = 1.42 * 0.5 * (lastWidth + lastWidthCand) + 0.5;
5084 const double distance = VectorHelper<double>::maxValue(lastLane.shape.distances(cand->getLanes().back().shape));
5085 //std::cout << " distance=" << distance << " threshold=" << threshold << " distances=" << toString(lastLane.shape.distances(cand->getLanes().back().shape)) << "\n";
5086 if (distance < threshold) {
5087 opposite = cand;
5088 }
5089 }
5090 }
5091 }
5092 if (opposite != nullptr) {
5093 lastLane.oppositeID = opposite->getLaneID(opposite->getNumLanes() - 1);
5094 }
5095 }
5096 }
5097 return opposite;
5098}
5099
5100double
5101NBEdge::getDistancAt(double pos) const {
5102 // negative values of myDistances indicate descending kilometrage
5103 return fabs(myDistance + pos);
5104}
5105
5106/****************************************************************************/
#define DEG2RAD(x)
Definition GeomHelper.h:35
#define RAD2DEG(x)
Definition GeomHelper.h:36
#define DEBUGCOND(PED)
#define DEBUGCOND2(LANE)
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_MESSAGEF(...)
Definition MsgHandler.h:301
#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::vector< std::pair< const NBRouterEdge *, const NBRouterEdge * > > ConstRouterEdgePairVector
Definition NBCont.h:46
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
const SVCPermissions SVCAll
all VClasses are allowed
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permissions is a (exclusive) railway edge.
const SVCPermissions SVC_UNSPECIFIED
permissions not specified
const std::string & getVehicleClassNames(SVCPermissions permissions, bool expand)
Returns the ids of the given classes, divided using a ' '.
bool isForbidden(SVCPermissions permissions)
Returns whether an edge with the given permissions is a forbidden edge.
bool isBikepath(SVCPermissions permissions)
Returns whether an edge with the given permissions is a bicycle edge.
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_IGNORING
vehicles ignoring classes
@ SVC_RAIL_CLASSES
classes which drive on tracks
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_DELIVERY
vehicle is a small delivery vehicle
@ SVC_TRAM
vehicle is a light rail
@ SVC_TAXI
vehicle is a taxi
@ SVC_BUS
vehicle is a bus
@ SVC_PEDESTRIAN
pedestrian
@ RIGHT
At the rightmost side of the lane.
const std::string SUMO_PARAM_ORIGID
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge's lateral offset shal...
const std::string SUMO_PARAM_REMOVED_NODES
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
@ PARTLEFT
The link is a partial left direction.
@ RIGHT
The link is a (hard) right direction.
@ TURN
The link is a 180 degree turn.
@ LEFT
The link is a (hard) left direction.
@ STRAIGHT
The link is a straight direction.
@ PARTRIGHT
The link is a partial right direction.
@ NODIR
The link has no direction (is a dead end link)
double roundDecimalToEven(double x, int precision)
round to the given number of decimal digits (bankers rounding)
Definition StdDefs.cpp:67
int gPrecision
the precision for floating point outputs
Definition StdDefs.cpp:27
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
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition ToString.h:322
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
static void compute(BresenhamCallBack *callBack, const int val1, const int val2)
Definition Bresenham.cpp:32
static const double INVALID_OFFSET
a value to signify offsets outside the range of [0, Line.length()]
Definition GeomHelper.h:50
static double legacyDegree(const double angle, const bool positive=false)
static double angleDiff(const double angle1, const double angle2)
Returns the difference of the second angle to the first angle in radiants.
int getFromLane() const
returns the from-lane
int getTLIndex2() const
int getTLIndex() const
returns the index within the controlling tls or InvalidTLIndex if this link is unontrolled
void shiftLaneIndex(NBEdge *edge, int offset, int threshold=-1)
patches lane indices refering to the given edge and above the threshold by the given offset
int getToLane() const
returns the to-lane
NBEdge * getTo() const
returns the to-edge (end of the connection)
Holds (- relative to the edge it is build from -!!!) the list of main directions a vehicle that drive...
Definition NBEdge.h:1639
bool empty() const
returns the information whether no following street has a higher priority
Definition NBEdge.cpp:230
bool includes(Direction d) const
returns the information whether the street in the given direction has a higher priority
Definition NBEdge.cpp:236
int getStraightest() const
returns the index of the straightmost among the given outgoing edges
Definition NBEdge.h:1656
MainDirections(const EdgeVector &outgoing, NBEdge *parent, NBNode *to, const std::vector< int > &availableLanes)
constructor
Definition NBEdge.cpp:173
std::vector< Direction > myDirs
list of the main direction within the following junction relative to the edge
Definition NBEdge.h:1671
~MainDirections()
destructor
Definition NBEdge.cpp:226
int myStraightest
the index of the straightmost among the given outgoing edges
Definition NBEdge.h:1668
Direction
enum of possible directions
Definition NBEdge.h:1642
A class that being a bresenham-callback assigns the incoming lanes to the edges.
Definition NBEdge.h:1599
const std::map< NBEdge *, std::vector< int > > & getBuiltConnections() const
get built connections
Definition NBEdge.h:1619
void execute(const int lane, const int virtEdge)
executes a bresenham - step
Definition NBEdge.cpp:142
Class to sort edges by their angle.
Definition NBEdge.h:2018
int operator()(const Connection &c1, const Connection &c2) const
comparing operation
Definition NBEdge.cpp:245
Storage for edges, including some functionality operating on multiple edges.
Definition NBEdgeCont.h:59
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
The representation of a single edge during network building.
Definition NBEdge.h:92
void reinit(NBNode *from, NBNode *to, const std::string &type, double speed, double friction, int nolanes, int priority, PositionVector geom, double width, double endOffset, const std::string &streetName, LaneSpreadFunction spread, bool tryIgnoreNodePositions=false)
Resets initial values.
Definition NBEdge.cpp:387
void updateRemovedNodes(const std::string &removed)
update parameter with removed nodes
Definition NBEdge.cpp:4150
void addGeometryPoint(int index, const Position &p)
Adds a further geometry point.
Definition NBEdge.cpp:1028
static std::vector< LinkDirection > decodeTurnSigns(int turnSigns, int shift=0)
decode bitset
Definition NBEdge.cpp:2705
void mirrorX()
mirror coordinates along the x-axis
Definition NBEdge.cpp:594
void setPreferredVehicleClass(SVCPermissions permissions, int lane=-1)
set preferred Vehicle Class
Definition NBEdge.cpp:4522
static const int TURN_SIGN_SHIFT_BUS
shift values for decoding turn signs
Definition NBEdge.h:379
double getLaneSpeed(int lane) const
get lane speed
Definition NBEdge.cpp:2237
static const int TURN_SIGN_SHIFT_BICYCLE
Definition NBEdge.h:381
NBEdge * guessOpposite(bool reguess=false)
set oppositeID and return opposite edge if found
Definition NBEdge.cpp:5070
void setPermittedChanging(int lane, SVCPermissions changeLeft, SVCPermissions changeRight)
set allowed classes for changing to the left and right from the given lane
Definition NBEdge.cpp:4536
double getLength() const
Returns the computed length of the edge.
Definition NBEdge.h:599
double myLaneWidth
This width of this edge's lanes.
Definition NBEdge.h:1834
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition NBEdge.cpp:4545
std::vector< Connection > myConnectionsToDelete
List of connections marked for delayed removal.
Definition NBEdge.h:1804
const EdgeVector * getConnectedSorted()
Returns the list of outgoing edges without the turnaround sorted in clockwise direction.
Definition NBEdge.cpp:1368
double getDistancAt(double pos) const
get distance at the given offset
Definition NBEdge.cpp:5101
double myEndOffset
This edges's offset to the intersection begin (will be applied to all lanes)
Definition NBEdge.h:1825
int myToJunctionPriority
The priority normalised for the node the edge is incoming in.
Definition NBEdge.h:1816
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
StopOffset myEdgeStopOffset
A vClass specific stop offset - assumed of length 0 (unspecified) or 1. For the latter case the int i...
Definition NBEdge.h:1831
@ 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
double getCrossingAngle(NBNode *node)
return the angle for computing pedestrian crossings at the given node
Definition NBEdge.cpp:4698
void addBikeLane(double width)
add a bicycle lane of the given width and shift existing connections
Definition NBEdge.cpp:4751
bool expandableBy(NBEdge *possContinuation, std::string &reason) const
Check if Node is expandable.
Definition NBEdge.cpp:3980
double getLaneFriction(int lane) const
get lane friction of specified lane
Definition NBEdge.cpp:2243
void recheckOpposite(const NBEdgeCont &ec, bool fixOppositeLengths)
recheck whether all opposite and bidi settings are consistent
Definition NBEdge.cpp:3202
const ConstRouterEdgePairVector & getViaSuccessors(SUMOVehicleClass vClass=SVC_IGNORING, bool ignoreTransientPermissions=false) const
Returns the following edges for the given vClass.
Definition NBEdge.cpp:4961
void init(int noLanes, bool tryIgnoreNodePositions, const std::string &origID)
Initialization routines common to all constructors.
Definition NBEdge.cpp:464
void setSpeed(int lane, double speed)
set lane specific speed (negative lane implies set for all lanes)
Definition NBEdge.cpp:4460
void reinitNodes(NBNode *from, NBNode *to)
Resets nodes but keeps all other values the same (used when joining)
Definition NBEdge.cpp:438
double mySpeed
The maximal speed.
Definition NBEdge.h:1790
bool hasLaneSpecificFriction() const
whether lanes differ in friction
Definition NBEdge.cpp:2489
double getLaneWidth() const
Returns the default width of lanes of this edge.
Definition NBEdge.h:648
PositionVector getCWBoundaryLine(const NBNode &n) const
get the outer boundary of this edge when going clock-wise around the given node
Definition NBEdge.cpp:3944
NBNode * getToNode() const
Returns the destination node of the edge.
Definition NBEdge.h:552
void checkGeometry(const double maxAngle, bool fixAngle, const double minRadius, bool fix, bool silent)
Check the angles of successive geometry segments.
Definition NBEdge.cpp:1060
std::vector< Connection > myConnections
List of connections to following edges.
Definition NBEdge.h:1801
Connection & getConnectionRef(int fromLane, const NBEdge *to, int toLane)
Returns reference to the specified connection This method goes through "myConnections" and returns th...
Definition NBEdge.cpp:1337
NBEdge()
constructor for dummy edge
Definition NBEdge.cpp:364
void divideOnEdges(const EdgeVector *outgoing)
divides the lanes on the outgoing edges
Definition NBEdge.cpp:3361
ConstRouterEdgePairVector myViaSuccessors
Definition NBEdge.h:1885
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
double buildInnerEdges(const NBNode &n, int noInternalNoSplits, int &linkIndex, int &splitIndex)
Definition NBEdge.cpp:1720
static const double UNSPECIFIED_FRICTION
unspecified lane friction
Definition NBEdge.h:355
void incLaneNo(int by)
increment lane
Definition NBEdge.cpp:4241
static EdgeVector filterByPermissions(const EdgeVector &edges, SVCPermissions permissions)
return only those edges that permit at least one of the give permissions
Definition NBEdge.cpp:5028
Lane & getLaneStruct(int lane)
Definition NBEdge.h:1459
const Connection & getConnection(int fromLane, const NBEdge *to, int toLane) const
Returns the specified connection (unmodifiable) This method goes through "myConnections" and returns ...
Definition NBEdge.cpp:1325
void addLane(int index, bool recomputeShape, bool recomputeConnections, bool shiftIndices)
add lane
Definition NBEdge.cpp:4197
bool hasLaneSpecificSpeed() const
whether lanes differ in speed
Definition NBEdge.cpp:2479
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
void removeInvalidConnections()
Definition NBEdge.cpp:3299
double getShapeStartAngle() const
Returns the angle at the start of the edge.
Definition NBEdge.cpp:2438
static const int UNSPECIFIED_INTERNAL_LANE_INDEX
internal lane computation not yet done
Definition NBEdge.h:373
void appendTurnaround(bool noTLSControlled, bool noFringe, bool onlyDeadends, bool onlyTurnlane, bool noGeometryLike, bool checkPermissions)
Add a connection to the previously computed turnaround, if wished and a turning direction exists (myT...
Definition NBEdge.cpp:3731
static bool connections_sorter(const Connection &c1, const Connection &c2)
connections_sorter sort by fromLane, toEdge and toLane
Definition NBEdge.cpp:4580
std::string myType
The type of the edge.
Definition NBEdge.h:1768
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition NBEdge.h:789
bool hasPermissions() const
whether at least one lane has restrictions
Definition NBEdge.cpp:2454
double myTotalAngle
Definition NBEdge.h:1783
LaneSpreadFunction getLaneSpreadFunction() const
Returns how this edge's lanes' lateral offset is computed.
Definition NBEdge.cpp:1022
bool hasDefaultGeometryEndpoints() const
Returns whether the geometry is terminated by the node positions This default may be violated by init...
Definition NBEdge.cpp:626
std::string myTurnSignTarget
node for which turnSign information applies
Definition NBEdge.h:1774
bool isBidiRail(bool ignoreSpread=false) const
whether this edge is part of a bidirectional railway
Definition NBEdge.cpp:773
static const bool UNSPECIFIED_CONNECTION_UNCONTROLLED
TLS-controlled despite its node controlled not specified.
Definition NBEdge.h:376
const EdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges for the given vClass.
Definition NBEdge.cpp:4943
void dismissVehicleClassInformation()
dimiss vehicle class information
Definition NBEdge.cpp:4571
bool computeEdge2Edges(bool noLeftMovers)
computes the edge (step1: computation of approached edges)
Definition NBEdge.cpp:2604
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
void moveConnectionToLeft(int lane)
moves a connection one place to the left;
Definition NBEdge.cpp:1686
void updateChangeRestrictions(SVCPermissions ignoring)
modify all existing restrictions on lane changing
Definition NBEdge.cpp:2255
void restoreBikelane(std::vector< NBEdge::Lane > oldLanes, PositionVector oldGeometry, std::vector< NBEdge::Connection > oldConnections)
restore an previously added BikeLane
Definition NBEdge.cpp:4757
Position getEndpointAtNode(const NBNode *node) const
Definition NBEdge.cpp:644
NBEdge * getStraightContinuation(SVCPermissions permissions) const
return the straightest follower edge for the given permissions or nullptr (never returns turn-arounds...
Definition NBEdge.cpp:5039
bool hasLoadedLength() const
Returns whether a length was set explicitly.
Definition NBEdge.h:618
void resetEndpointAtNode(const NBNode *node)
Definition NBEdge.cpp:649
void restoreSidewalk(std::vector< NBEdge::Lane > oldLanes, PositionVector oldGeometry, std::vector< NBEdge::Connection > oldConnections)
restore an previously added sidewalk
Definition NBEdge.cpp:4745
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 divideSelectedLanesOnEdges(const EdgeVector *outgoing, const std::vector< int > &availableLanes)
divide selected lanes on edges
Definition NBEdge.cpp:3451
bool setEdgeStopOffset(int lane, const StopOffset &offset, bool overwrite=false)
set lane and vehicle class specific stopOffset (negative lane implies set for all lanes)
Definition NBEdge.cpp:4430
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition NBEdge.h:736
bool hasLaneSpecificStopOffsets() const
whether lanes differ in stopOffsets
Definition NBEdge.cpp:2532
void setNodeBorder(const NBNode *node, const Position &p, const Position &p2, bool rectangularCut)
Set Node border.
Definition NBEdge.cpp:719
int getFirstNonPedestrianLaneIndex(int direction, bool exclusive=false) const
return the first lane with permissions other than SVC_PEDESTRIAN and 0
Definition NBEdge.cpp:4605
EdgeVector mySuccessors
Definition NBEdge.h:1882
void shiftToLanesToEdge(NBEdge *to, int laneOff)
modifify the toLane for all connections to the given edge
Definition NBEdge.cpp:4835
static double myDefaultConnectionLength
Definition NBEdge.h:1888
bool isNearEnough2BeJoined2(NBEdge *e, double threshold) const
Check if edge is near enough to be joined to another edge.
Definition NBEdge.cpp:4189
EdgeBuildingStep myStep
The building step.
Definition NBEdge.h:1765
void setLaneType(int lane, const std::string &type)
set lane specific type (negative lane implies set for all lanes)
Definition NBEdge.cpp:4346
bool computeLanes2Edges()
computes the edge, step2: computation of which lanes approach the edges)
Definition NBEdge.cpp:2660
EdgeBuildingStep
Current state of the edge within the building process.
Definition NBEdge.h:109
@ INIT_REJECT_CONNECTIONS
The edge has been loaded and connections shall not be added.
@ EDGE2EDGES
The relationships between edges are computed/loaded.
@ LANES2LANES_RECHECK
Lanes to lanes - relationships are computed; should be rechecked.
@ LANES2LANES_DONE
Lanes to lanes - relationships are computed; no recheck is necessary/wished.
@ LANES2EDGES
Lanes to edges - relationships are computed/loaded.
@ LANES2LANES_USER
Lanes to lanes - relationships are loaded; no recheck is necessary/wished.
@ INIT
The edge has been loaded, nothing is computed yet.
NBEdge * getStraightPredecessor(SVCPermissions permissions) const
return the straightest predecessor edge for the given permissions or nullptr (never returns turn-arou...
Definition NBEdge.cpp:5054
void remapConnections(const EdgeVector &incoming)
Remaps the connection in a way that allows the removal of it.
Definition NBEdge.cpp:1458
double getSpeed() const
Returns the speed allowed on this edge.
Definition NBEdge.h:625
~NBEdge()
Destructor.
Definition NBEdge.cpp:548
NBNode * myTo
Definition NBEdge.h:1771
double myEndAngle
Definition NBEdge.h:1782
const std::string & getID() const
Definition NBEdge.h:1559
int getFirstAllowedLaneIndex(int direction) const
return the first lane that permits at least 1 vClass or the last lane if search direction of there is...
Definition NBEdge.cpp:4648
bool allowsChangingRight(int lane, SUMOVehicleClass vclass) const
Returns whether the given vehicle class may change left from this lane.
Definition NBEdge.cpp:4692
static const double UNSPECIFIED_LOADED_LENGTH
no length override given
Definition NBEdge.h:364
void setLaneWidth(int lane, double width)
set lane specific width (negative lane implies set for all lanes)
Definition NBEdge.cpp:4331
void resetLaneShapes()
reset lane shapes to what they would be before cutting with the junction shapes
Definition NBEdge.cpp:2249
bool setControllingTLInformation(const NBConnection &c, const std::string &tlID)
Returns if the link could be set as to be controlled.
Definition NBEdge.cpp:3873
bool bothLeftTurns(LinkDirection dir, const NBEdge *otherFrom, LinkDirection dir2) const
determine conflict between opposite left turns
Definition NBEdge.cpp:2142
bool shiftPositionAtNode(NBNode *node, NBEdge *opposite)
shift geometry at the given node to avoid overlap and return whether geometry was changed
Definition NBEdge.cpp:4846
void setAcceleration(int lane, bool accelRamp)
marks one lane as acceleration lane
Definition NBEdge.cpp:4492
const StopOffset & getEdgeStopOffset() const
Returns the stopOffset to the end of the edge.
Definition NBEdge.cpp:4398
NBNode * tryGetNodeAtPosition(double pos, double tolerance=5.0) const
Returns the node at the given edges length (using an epsilon)
Definition NBEdge.cpp:3824
void setLaneSpreadFunction(LaneSpreadFunction spread)
(Re)sets how the lanes lateral offset shall be computed
Definition NBEdge.cpp:1016
void clearControllingTLInformation()
clears tlID for all connections
Definition NBEdge.cpp:3936
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
Definition NBEdge.cpp:3811
void addStraightConnections(const EdgeVector *outgoing, const std::vector< int > &availableLanes, const std::vector< int > &priorities)
add some straight connections
Definition NBEdge.cpp:3556
bool hasLaneSpecificPermissions() const
whether lanes differ in allowed vehicle classes
Definition NBEdge.cpp:2465
bool needsLaneSpecificOutput() const
whether at least one lane has values differing from the edges values
Definition NBEdge.cpp:2587
void computeAngle()
computes the angle of this edge and stores it in myAngle
Definition NBEdge.cpp:2340
void roundSpeed()
ensure consistency between input and output speed
Definition NBEdge.cpp:585
bool isBidiEdge(bool checkPotential=false) const
whether this edge is part of a bidirectional edge pair
Definition NBEdge.cpp:785
static const double UNSPECIFIED_SIGNAL_OFFSET
unspecified signal offset
Definition NBEdge.h:367
void addSidewalk(double width)
add a pedestrian sidewalk of the given width and shift existing connections
Definition NBEdge.cpp:4739
bool hasSignalisedConnectionTo(const NBEdge *const e) const
Check if edge has signalised connections.
Definition NBEdge.cpp:4163
std::vector< Lane > myLanes
Lane information.
Definition NBEdge.h:1839
int getNumLanes() const
Returns the number of lanes.
Definition NBEdge.h:526
std::vector< Connection > getConnectionsFromLane(int lane, const NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
Definition NBEdge.cpp:1311
bool hasAccelLane() const
whether one of the lanes is an acceleration lane
Definition NBEdge.cpp:2545
bool myIsBidi
whether this edge is part of a non-rail bidi edge pair
Definition NBEdge.h:1870
static double firstIntersection(const PositionVector &v1, const PositionVector &v2, double width1, double width2, const std::string &error="", bool secondIntersection=false)
compute the first intersection point between the given lane geometries considering their rspective wi...
Definition NBEdge.cpp:2078
PositionVector myToBorder
Definition NBEdge.h:1863
void extendGeometryAtNode(const NBNode *node, double maxExtent)
linearly extend the geometry at the given node
Definition NBEdge.cpp:682
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
static const double ANGLE_LOOKAHEAD
the distance at which to take the default angle
Definition NBEdge.h:370
int getNumLanesThatAllow(SVCPermissions permissions, bool allPermissions=true) const
Definition NBEdge.cpp:4674
void reduceGeometry(const double minDist)
Removes points with a distance lesser than the given.
Definition NBEdge.cpp:1038
static NBEdge DummyEdge
Dummy edge to use when a reference must be supplied in the no-arguments constructor (FOX technicality...
Definition NBEdge.h:343
bool joinLanes(SVCPermissions perms)
join adjacent lanes with the given permissions
Definition NBEdge.cpp:5008
void resetNodeBorder(const NBNode *node)
Definition NBEdge.cpp:762
void markAsInLane2LaneState()
mark edge as in lane to state lane
Definition NBEdge.cpp:4284
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
return true if certain connection must be controlled by TLS
Definition NBEdge.cpp:3862
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
double myLength
The length of the edge.
Definition NBEdge.h:1777
NBEdge::Lane getFirstNonPedestrianLane(int direction) const
get first non-pedestrian lane
Definition NBEdge.cpp:4714
void invalidateConnections(bool reallowSetting=false)
invalidate current connections of edge
Definition NBEdge.cpp:1555
const std::vector< int > prepareEdgePriorities(const EdgeVector *outgoing, const std::vector< int > &availableLanes)
recomputes the edge priorities and manipulates them for a distribution of lanes on edges which is mor...
Definition NBEdge.cpp:3638
int myIndex
the index of the edge in the list of all edges. Set by NBEdgeCont and requires re-set whenever the li...
Definition NBEdge.h:1879
double getTotalWidth() const
Returns the combined width of all lanes of this edge.
Definition NBEdge.cpp:4383
PositionVector cutAtIntersection(const PositionVector &old) const
cut shape at the intersection shapes
Definition NBEdge.cpp:818
Position geometryPositionAtOffset(double offset) const
return position taking into account loaded length
Definition NBEdge.cpp:4886
static const double UNSPECIFIED_VISIBILITY_DISTANCE
unspecified foe visibility for connections
Definition NBEdge.h:361
bool canMoveConnection(const Connection &con, int newFromLane) const
whether the connection can originate on newFromLane
Definition NBEdge.cpp:1677
double getInternalLaneWidth(const NBNode &node, const NBEdge::Connection &connection, const NBEdge::Lane &successor, bool isVia) const
Returns the width of the internal lane associated with the connection.
Definition NBEdge.cpp:4367
void allowVehicleClass(int lane, SUMOVehicleClass vclass)
set allowed class for the given lane or for all lanes if -1 is given
Definition NBEdge.cpp:4291
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
double getMaxLaneOffset()
get max lane offset
Definition NBEdge.cpp:3856
void deleteLane(int index, bool recompute, bool shiftIndices)
delete lane
Definition NBEdge.cpp:4252
NBEdge * myPossibleTurnDestination
The edge that would be the turn destination if there was one.
Definition NBEdge.h:1810
const PositionVector & getNodeBorder(const NBNode *node) const
Definition NBEdge.cpp:751
const NBNode * mySignalNode
Definition NBEdge.h:1858
bool hasLaneSpecificWidth() const
whether lanes differ in width
Definition NBEdge.cpp:2499
void moveConnectionToRight(int lane)
moves a connection one place to the right; @noteAttention! no checking for field validity
Definition NBEdge.cpp:1704
std::set< SVCPermissions > getPermissionVariants(int iStart, int iEnd) const
return all permission variants within the specified lane range [iStart, iEnd[
Definition NBEdge.cpp:4662
void reshiftPosition(double xoff, double yoff)
Applies an offset to the edge.
Definition NBEdge.cpp:553
static const int TURN_SIGN_SHIFT_TAXI
Definition NBEdge.h:380
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
bool myIsOffRamp
whether this edge is an Off-Ramp or leads to one
Definition NBEdge.h:1867
static const double UNSPECIFIED_SPEED
unspecified lane speed
Definition NBEdge.h:352
Lane2LaneInfoType
Modes of setting connections between lanes.
Definition NBEdge.h:130
@ USER
The connection was given by the user.
@ VALIDATED
The connection was computed and validated.
@ COMPUTED
The connection was computed.
double getFriction() const
Returns the friction on this edge.
Definition NBEdge.h:632
static PositionVector startShapeAt(const PositionVector &laneShape, const NBNode *startNode, PositionVector nodeShape)
Definition NBEdge.cpp:950
std::string getSidewalkID()
get the lane id for the canonical sidewalk lane
Definition NBEdge.cpp:4723
void computeLaneShapes()
compute lane shapes
Definition NBEdge.cpp:2276
double getAngleAtNodeToCenter(const NBNode *const node) const
Returns the angle of from the node shape center to where the edge meets the node shape.
Definition NBEdge.cpp:2213
int getSpecialLane(SVCPermissions permissions) const
return index of the first lane that allows the given permissions
Definition NBEdge.cpp:4638
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
bool hasLaneSpecificEndOffset() const
whether lanes differ in offset
Definition NBEdge.cpp:2521
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
Definition NBEdge.cpp:2161
double myDistance
The mileage/kilometrage at the start of this edge in a linear coordination system.
Definition NBEdge.h:1796
bool myAmMacroscopicConnector
Information whether this edge is a (macroscopic) connector.
Definition NBEdge.h:1848
EdgeVector getConnectedEdges() const
Returns the list of outgoing edges unsorted.
Definition NBEdge.cpp:1405
const std::string & getStreetName() const
Returns the street name of this edge.
Definition NBEdge.h:675
void setLaneShape(int lane, const PositionVector &shape)
sets a custom lane shape
Definition NBEdge.cpp:4500
double myLoadedLength
An optional length to use (-1 if not valid)
Definition NBEdge.h:1842
static void updateTurnPermissions(SVCPermissions &perm, LinkDirection dir, SVCPermissions spec, std::vector< LinkDirection > dirs)
Definition NBEdge.cpp:2717
void sortOutgoingConnectionsByAngle()
sorts the outgoing connections by their angle relative to their junction
Definition NBEdge.cpp:1446
bool applyTurnSigns()
apply loaded turn sign information
Definition NBEdge.cpp:2728
bool haveIntersection(const NBNode &n, const PositionVector &shape, const NBEdge *otherFrom, const NBEdge::Connection &otherCon, int numPoints, double width1, double width2, int shapeFlag=0) const
Definition NBEdge.cpp:2151
void preferVehicleClass(int lane, SVCPermissions vclasses)
prefer certain vehicle classes for the given lane or for all lanes if -1 is given (ensures also permi...
Definition NBEdge.cpp:4317
bool myRoundaboutGuessExcluded
True when way metadata excludes this edge from inferred roundabouts.
Definition NBEdge.h:1873
const NBEdge * getBidiEdge() const
Definition NBEdge.h:1545
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition NBEdge.h:545
double myStartAngle
The angles of the edge.
Definition NBEdge.h:1781
double getAngleAtNodeNormalized(const NBNode *const node) const
Returns the angle of the edge's geometry at the given node and disregards edge direction.
Definition NBEdge.cpp:2197
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 hasLaneSpecificType() const
whether lanes differ in type
Definition NBEdge.cpp:2510
PositionVector myFromBorder
intersection borders (because the node shape might be invalid)
Definition NBEdge.h:1862
double getSignalOffset() const
Returns the offset of a traffic signal from the end of this edge.
Definition NBEdge.cpp:4592
bool hasDefaultGeometry() const
Returns whether the geometry consists only of the node positions.
Definition NBEdge.cpp:620
void roundGeometry()
ensure consistency between input and output geometries
Definition NBEdge.cpp:573
std::string myRoutingType
The routing type of the edge.
Definition NBEdge.h:1876
std::vector< int > getConnectionLanes(NBEdge *currentOutgoing, bool withBikes=true, bool withBusLanes=true) const
Returns the list of lanes that may be used to reach the given edge.
Definition NBEdge.cpp:1430
bool myAmInTLS
Information whether this is lies within a joined tls.
Definition NBEdge.h:1845
void setTurningDestination(NBEdge *e, bool onlyPossible=false)
Sets the turing destination at the given edge.
Definition NBEdge.cpp:2228
bool hasDefaultGeometryEndpointAtNode(const NBNode *node) const
Returns whether the geometry is terminated by the node positions This default may be violated by init...
Definition NBEdge.cpp:633
NBEdge * myTurnDestination
The turn destination edge (if a connection exists)
Definition NBEdge.h:1807
int getPriority() const
Returns the priority of the edge.
Definition NBEdge.h:533
void computeEdgeShape(double smoothElevationThreshold=-1)
Recomputeds the lane shapes to terminate at the node shape For every lane the intersection with the f...
Definition NBEdge.cpp:909
double assignInternalLaneLength(std::vector< Connection >::iterator i, int numLanes, double lengthSum, bool averageLength)
assign length to all lanes of an internal edge
Definition NBEdge.cpp:2038
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
const StopOffset & getLaneStopOffset(int lane) const
Returns the stop offset to the specified lane's end.
Definition NBEdge.cpp:4404
void debugPrintConnections(bool outgoing=true, bool incoming=false) const
debugging helper to print all connections
Definition NBEdge.cpp:4984
Position mySignalPosition
the position of a traffic light signal on this edge
Definition NBEdge.h:1857
void replaceInConnections(NBEdge *which, NBEdge *by, int laneOff)
replace in current connections of edge
Definition NBEdge.cpp:1567
bool lanesWereAssigned() const
Check if lanes were assigned.
Definition NBEdge.cpp:3850
void restoreRestrictedLane(SUMOVehicleClass vclass, std::vector< NBEdge::Lane > oldLanes, PositionVector oldGeometry, std::vector< NBEdge::Connection > oldConnections)
restore a restricted lane
Definition NBEdge.cpp:4812
double getEndOffset() const
Returns the offset to the destination node.
Definition NBEdge.h:695
bool isRailDeadEnd() const
whether this edge is a railway edge that does not continue
Definition NBEdge.cpp:803
double myFriction
The current friction.
Definition NBEdge.h:1793
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
void sortOutgoingConnectionsByIndex()
sorts the outgoing connections by their from-lane-index and their to-lane-index
Definition NBEdge.cpp:1452
bool recheckLanes()
recheck whether all lanes within the edge are all right and optimises the connections once again
Definition NBEdge.cpp:2958
int myFromJunctionPriority
The priority normalised for the node the edge is outgoing of.
Definition NBEdge.h:1813
bool addLane2LaneConnections(int fromLane, NBEdge *dest, int toLane, int no, Lane2LaneInfoType type, bool invalidatePrevious=false, bool mayDefinitelyPass=false)
Builds no connections starting at the given lanes.
Definition NBEdge.cpp:1193
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
PositionVector computeLaneShape(int lane, double offset) const
Computes the shape for the given lane.
Definition NBEdge.cpp:2328
bool allowsChangingLeft(int lane, SUMOVehicleClass vclass) const
Returns whether the given vehicle class may change left from this lane.
Definition NBEdge.cpp:4686
static int getLaneIndexFromLaneID(const std::string laneID)
Definition NBEdge.cpp:5003
bool hasConnectionTo(const NBEdge *destEdge, int destLane, int fromLane=-1) const
Retrieves info about a connection to a certain lane of a certain edge.
Definition NBEdge.cpp:1349
bool hasCustomLaneShape() const
whether one of the lanes has a custom shape
Definition NBEdge.cpp:2556
bool hasLaneParams() const
whether one of the lanes has parameters set
Definition NBEdge.cpp:2567
const PositionVector & getLaneShape(int i) const
Returns the shape of the nth lane.
Definition NBEdge.cpp:1010
double getShapeEndAngle() const
Returns the angle at the end of the edge.
Definition NBEdge.cpp:2446
bool prohibitsChanging() const
whether one of the lanes prohibits lane changing
Definition NBEdge.cpp:2577
void setLoadedLength(double val)
set loaded length
Definition NBEdge.cpp:4560
PositionVector myGeom
The geometry for the edge.
Definition NBEdge.h:1819
const PositionVector getInnerGeometry() const
Returns the geometry of the edge without the endpoints.
Definition NBEdge.cpp:614
void decLaneNo(int by)
decrement lane
Definition NBEdge.cpp:4272
NBNode * myFrom
The source and the destination node.
Definition NBEdge.h:1771
void append(NBEdge *continuation)
append another edge
Definition NBEdge.cpp:4097
void setJunctionPriority(const NBNode *const node, int prio)
Sets the junction priority of the edge.
Definition NBEdge.cpp:2171
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition NBEdge.cpp:4896
void shortenGeometryAtNode(const NBNode *node, double reduction)
linearly extend the geometry at the given node
Definition NBEdge.cpp:705
void setGeometry(const PositionVector &g, bool inner=false)
(Re)sets the edge's geometry
Definition NBEdge.cpp:661
int myPriority
The priority of the edge.
Definition NBEdge.h:1787
std::string myStreetName
The street name (or whatever arbitrary string you wish to attach)
Definition NBEdge.h:1851
EdgeVector getIncomingEdges() const
Returns the list of incoming edges unsorted.
Definition NBEdge.cpp:1417
int getFirstNonPedestrianNonBicycleLaneIndex(int direction, bool exclusive=false) const
return the first lane with permissions other than SVC_PEDESTRIAN, SVC_BICYCLE and 0
Definition NBEdge.cpp:4621
static double normRelAngle(double angle1, double angle2)
ensure that reverse relAngles (>=179.999) always count as turnarounds (-180)
Definition NBHelpers.cpp:58
A definition of a pedestrian crossing.
Definition NBNode.h:137
PositionVector shape
The crossing's shape.
Definition NBNode.h:146
bool priority
whether the pedestrians have priority
Definition NBNode.h:160
EdgeVector edges
The edges being crossed.
Definition NBNode.h:144
double width
This crossing's width.
Definition NBNode.h:152
Represents a single node (junction) during network building.
Definition NBNode.h:66
void addIncomingEdge(NBEdge *edge)
adds an incoming edge
Definition NBNode.cpp:541
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing, bool leftHand=false) const
Returns the representation of the described stream's direction.
Definition NBNode.cpp:2507
static const int AVOID_INTERSECTING_LEFT_TURNS
Definition NBNode.h:228
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 needsCont(const NBEdge *fromE, const NBEdge *otherFromE, const NBEdge::Connection &c, const NBEdge::Connection &otherC, bool checkOnlyTLS=false) const
whether an internal junction should be built at from and respect other
Definition NBNode.cpp:986
FringeType getFringeType() const
Returns fringe type.
Definition NBNode.h:307
static const int BACKWARD
Definition NBNode.h:219
SumoXMLNodeType getType() const
Returns the type of this node.
Definition NBNode.h:287
bool isTrafficLight() const
Definition NBNode.h:841
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges (The edges which yield in this node)
Definition NBNode.h:270
static bool rightTurnConflict(const NBEdge *from, const NBEdge *to, int fromLane, const NBEdge *prohibitorFrom, const NBEdge *prohibitorTo, int prohibitorFromLane)
return whether the given laneToLane connection is a right turn which must yield to a bicycle crossing...
Definition NBNode.cpp:2192
const EdgeVector & getOutgoingEdges() const
Returns this node's outgoing edges (The edges which start at this node)
Definition NBNode.h:275
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
Definition NBNode.cpp:2337
bool bidiConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon, bool foes) const
whether the foe connections is oncoming on the same lane
Definition NBNode.cpp:2263
PositionVector computeSmoothShape(const PositionVector &begShape, const PositionVector &endShape, int numPoints, bool isTurnaround, double extrapolateBeg, double extrapolateEnd, NBNode *recordError=0, int shapeFlag=0) const
Compute a smooth curve between the given geometries.
Definition NBNode.cpp:596
bool isLeftMover(const NBEdge *const from, const NBEdge *const to) const
Computes whether the given connection is a left mover across the junction.
Definition NBNode.cpp:2318
bool mergeConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon, bool foes) const
whether multiple connections from the same edge target the same lane
Definition NBNode.cpp:2254
std::vector< Crossing * > getCrossings() const
return this junctions pedestrian crossings
Definition NBNode.cpp:3107
void addOutgoingEdge(NBEdge *edge)
adds an outgoing edge
Definition NBNode.cpp:551
const Position & getPosition() const
Definition NBNode.h:262
const PositionVector & getShape() const
retrieve the junction shape
Definition NBNode.cpp:2792
static const int FORWARD
edge directions (for pedestrian related stuff)
Definition NBNode.h:218
bool foes(const NBEdge *const from1, const NBEdge *const to1, const NBEdge *const from2, const NBEdge *const to2) const
Returns the information whether the given flows cross.
Definition NBNode.cpp:2347
PositionVector computeInternalLaneShape(const NBEdge *fromE, const NBEdge::Connection &con, int numPoints, NBNode *recordError=0, int shapeFlag=0) const
Compute the shape for an internal lane.
Definition NBNode.cpp:844
void shiftTLConnectionLaneIndex(NBEdge *edge, int offset, int threshold=-1)
patches loaded signal plans by modifying lane indices above threshold by the given offset
Definition NBNode.cpp:500
bool geometryLike() const
whether this is structurally similar to a geometry node
Definition NBNode.cpp:4033
bool isTLControlled() const
Returns whether this node is controlled by any tls.
Definition NBNode.h:338
static const int SCURVE_IGNORE
Definition NBNode.h:229
static const double MIN_SPEED_CROSSING_TIME
minimum speed for computing time to cross intersection
Definition NBOwnTLDef.h:152
Base class for objects which have an id.
Definition Named.h:53
std::string myID
The name of the object.
Definition Named.h:124
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 storage for options typed value containers)
Definition OptionsCont.h:92
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
bool hasParameter(const std::string &key) const
Returns whether the parameter is set.
void mergeParameters(const Parameterised::Map &mapArg, const std::string separator=" ", bool uniqueValues=true)
Adds or appends all given parameters from the map.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
void updateParameters(const Parameterised::Map &mapArg)
Adds or updates all given parameters from the map.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
static const Position INVALID
used to indicate that a position is valid
Definition Position.h:323
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition Position.h:273
void add(const Position &pos)
Adds the given position to this one.
Definition Position.h:129
void setz(double z)
set position z
Definition Position.h:77
double z() const
Returns the z-position.
Definition Position.h:62
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
void sety(double y)
set position y
Definition Position.h:72
double y() const
Returns the y-position.
Definition Position.h:57
A list of positions.
double length2D() const
Returns the length.
void append(const PositionVector &v, double sameThreshold=2.0)
double beginEndAngle() const
returns the angle in radians of the line connecting the first and the last position
double length() const
Returns the length.
void round(int precision, bool avoidDegeneration=true)
round all coordinates to the given precision
void ensureMinLength(int precision)
ensure minimum length so that the geometry will not degenerate to 0-length on writing with the given ...
void push_front_noDoublePos(const Position &p)
insert in front a non double position
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
void add(double xoff, double yoff, double zoff)
void closePolygon()
ensures that the last position equals the first
std::vector< double > intersectsAtLengths2D(const PositionVector &other) const
For all intersections between this vector and other, return the 2D-length of the subvector from this ...
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::vector< double > distances(const PositionVector &s, bool perpendicular=false) const
distances of all my points to s and all of s points to myself
PositionVector getOrthogonal(const Position &p, double extend, bool before, double length=1.0, double deg=90) const
return orthogonal through p (extending this vector if necessary)
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
bool almostSame(const PositionVector &v2, double maxDiv=POSITION_EPS) const
check if the two vectors have the same length and pairwise similar positions
PositionVector getSubpart2D(double beginOffset, double endOffset) const
get subpart of a position vector in two dimensions (Z is ignored)
PositionVector smoothedZFront(double dist=std::numeric_limits< double >::max()) const
returned vector that is smoothed at the front (within dist)
double angleAt2D(int pos) const
get angle in certain position of position vector (in radians between -M_PI and M_PI)
bool hasElevation() const
return whether two positions differ in z-coordinate
static const PositionVector EMPTY
empty Vector
void extrapolate(const double val, const bool onlyFirst=false, const bool onlyLast=false)
extrapolate position vector
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
void extrapolate2D(const double val, const bool onlyFirst=false)
extrapolate position vector in two dimensions (Z is ignored)
Position positionAtOffset2D(double pos, double lateralOffset=0, bool extrapolateBeyond=false) const
Returns the position at the given length.
void push_back_noDoublePos(const Position &p)
insert in back a non double position
void removeDoublePoints(double minDist=POSITION_EPS, bool assertLength=false, int beginOffset=0, int endOffset=0, bool resample=false)
Removes positions if too near.
bool intersects(const Position &p1, const Position &p2) const
Returns the information whether this list of points interesects the given line.
PositionVector reverse() const
reverse position vector
PositionVector getSubpartByIndex(int beginIndex, int count) const
get subpart of a position vector using index and a cout
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
bool around(const Position &p, double offset=0) const
Returns the information whether the position vector describes a polygon lying around the given point.
stop offset
bool isDefined() const
check if stopOffset was defined
double getOffset() const
get offset
std::vector< std::string > getVector()
return vector of strings
Some static methods for string processing.
Definition StringUtils.h:40
static bool isValidNetID(const std::string &value)
whether the given string is a valid id for a network element
static std::string convertUmlaute(std::string str)
Converts german "Umlaute" to their latin-version.
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
static T maxValue(const std::vector< T > &v)
unsigned node
#define M_PI
Definition odrSpiral.cpp:45
A structure which describes a connection between edges or lanes.
Definition NBEdge.h:201
bool indirectLeft
Whether this connection is an indirect left turn.
Definition NBEdge.h:261
int fromLane
The lane the connections starts at.
Definition NBEdge.h:210
std::string viaID
if Connection have a via, ID of it
Definition NBEdge.h:279
int toLane
The lane the connections yields in.
Definition NBEdge.h:216
std::vector< int > foeInternalLinks
FOE Internal links.
Definition NBEdge.h:288
Connection(int fromLane_, NBEdge *toEdge_, int toLane_, const bool mayDefinitelyPass_=false)
Constructor.
Definition NBEdge.cpp:110
std::string getInternalViaLaneID() const
get ID of internal lane (second part)
Definition NBEdge.cpp:98
double speed
custom speed for connection
Definition NBEdge.h:240
NBEdge * toEdge
The edge the connections yields in.
Definition NBEdge.h:213
double customLength
custom length for connection
Definition NBEdge.h:246
double vmax
maximum velocity
Definition NBEdge.h:273
PositionVector customShape
custom shape for connection
Definition NBEdge.h:249
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
double contPos
custom position for internal junction on this connection
Definition NBEdge.h:234
std::string getInternalLaneID() const
get ID of internal lane
Definition NBEdge.cpp:92
int internalLaneIndex
The lane index of this internal lane within the internal edge.
Definition NBEdge.h:294
std::string tlID
The id of the traffic light that controls this connection.
Definition NBEdge.h:219
int internalViaLaneIndex
Definition NBEdge.h:295
int tlLinkIndex2
The index of the internal junction within the controlling traffic light (optional)
Definition NBEdge.h:225
double length
computed length (average of all internal lane shape lengths that share an internal edge)
Definition NBEdge.h:310
PositionVector shape
shape of Connection
Definition NBEdge.h:270
std::string id
id of Connection
Definition NBEdge.h:267
std::vector< std::string > foeIncomingLanes
FOE Incomings lanes.
Definition NBEdge.h:291
bool haveVia
check if Connection have a Via
Definition NBEdge.h:276
int tlLinkIndex
The index of this connection within the controlling traffic light.
Definition NBEdge.h:222
double viaLength
the length of the via shape (maybe customized)
Definition NBEdge.h:285
static ConstRouterEdgePairVector myViaSuccessors
Definition NBEdge.h:314
An (internal) definition of a single lane of an edge.
Definition NBEdge.h:143
double width
This lane's width.
Definition NBEdge.h:176
std::string oppositeID
An opposite lane ID, if given.
Definition NBEdge.h:179
SVCPermissions changeRight
List of vehicle types that are allowed to change right from this lane.
Definition NBEdge.h:166
SVCPermissions changeLeft
List of vehicle types that are allowed to change Left from this lane.
Definition NBEdge.h:163
Lane(NBEdge *e, const std::string &_origID)
constructor
Definition NBEdge.cpp:120
bool accelRamp
Whether this lane is an acceleration lane.
Definition NBEdge.h:182
PositionVector shape
The lane's shape.
Definition NBEdge.h:148