SUMO - Simulation of Urban MObility
NBEdge.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
20 // Methods for the representation of a single edge
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <vector>
30 #include <string>
31 #include <algorithm>
32 #include "NBEdgeCont.h"
33 #include "NBNode.h"
34 #include "NBNodeCont.h"
35 #include "NBContHelper.h"
36 #include "NBHelpers.h"
38 #include <cmath>
39 #include <iomanip>
40 #include "NBTypeCont.h"
41 #include <utils/geom/GeomHelper.h>
45 #include <utils/common/ToString.h>
47 #include <utils/common/StdDefs.h>
48 #include "NBEdge.h"
51 
52 //#define DEBUG_CONNECTION_GUESSING
53 //#define DEBUG_ANGLES
54 //#define DEBUG_NODE_BORDER
55 //#define DEBUGCOND (getID() == "disabled")
56 //#define DEBUGCOND (getID() == "22762377#1" || getID() == "146511467")
57 //#define DEBUGCOND2(obj) ((obj != 0 && (obj)->getID() == "disabled"))
58 
59 // ===========================================================================
60 // static members
61 // ===========================================================================
62 const double NBEdge::UNSPECIFIED_WIDTH = -1;
63 const double NBEdge::UNSPECIFIED_OFFSET = 0;
64 const double NBEdge::UNSPECIFIED_SPEED = -1;
65 const double NBEdge::UNSPECIFIED_CONTPOS = -1;
67 
68 const double NBEdge::UNSPECIFIED_SIGNAL_OFFSET = -1;
69 const double NBEdge::UNSPECIFIED_LOADED_LENGTH = -1;
70 const double NBEdge::ANGLE_LOOKAHEAD = 10.0;
73 
74 // ===========================================================================
75 // method definitions
76 // ===========================================================================
77 std::string
79  return id + "_" + toString(internalLaneIndex);
80 }
81 
82 
83 std::string
85  return Named::getIDSecure(parent) + "_" + toString(fromLane) + "->" + Named::getIDSecure(toEdge) + "_" + toString(toLane);
86 }
87 
88 
89 NBEdge::Connection::Connection(int fromLane_, NBEdge* toEdge_, int toLane_) :
90  fromLane(fromLane_),
91  toEdge(toEdge_),
92  toLane(toLane_),
93  tlLinkIndex(-1),
94  mayDefinitelyPass(false),
95  keepClear(true),
99  id(toEdge_ == 0 ? "" : toEdge->getFromNode()->getID()),
100  haveVia(false),
102  uncontrolled(false) {
103 }
104 
105 
106 NBEdge::Connection::Connection(int fromLane_, NBEdge* toEdge_, int toLane_, bool mayDefinitelyPass_, bool keepClear_, double contPos_,
107  double visibility_, double speed_, bool haveVia_, bool uncontrolled_, const PositionVector& customShape_) :
108  fromLane(fromLane_),
109  toEdge(toEdge_),
110  toLane(toLane_),
111  tlLinkIndex(-1),
112  mayDefinitelyPass(mayDefinitelyPass_),
113  keepClear(keepClear_),
114  contPos(contPos_),
115  visibility(visibility_),
116  speed(speed_),
117  customShape(customShape_),
118  id(toEdge_ == 0 ? "" : toEdge->getFromNode()->getID()),
120  haveVia(haveVia_),
122  uncontrolled(uncontrolled_) {
123 }
124 
125 
126 NBEdge::Lane::Lane(NBEdge* e, const std::string& origID_) :
127  speed(e->getSpeed()),
128  permissions(SVCAll),
129  preferred(0),
130  endOffset(e->getEndOffset()),
131  stopOffsets(e->getStopOffsets()),
132  width(e->getLaneWidth()),
133  accelRamp(false),
134  connectionsDone(false) {
135  if (origID_ != "") {
137  }
138 }
139 
140 
141 /* -------------------------------------------------------------------------
142  * NBEdge::ToEdgeConnectionsAdder-methods
143  * ----------------------------------------------------------------------- */
144 void
145 NBEdge::ToEdgeConnectionsAdder::execute(const int lane, const int virtEdge) {
146  // check
147  assert((int)myTransitions.size() > virtEdge);
148  // get the approached edge
149  NBEdge* succEdge = myTransitions[virtEdge];
150  std::vector<int> lanes;
151 
152  // check whether the currently regarded, approached edge has already
153  // a connection starting at the edge which is currently being build
154  std::map<NBEdge*, std::vector<int> >::iterator i = myConnections.find(succEdge);
155  if (i != myConnections.end()) {
156  // if there were already lanes assigned, get them
157  lanes = (*i).second;
158  }
159 
160  // check whether the current lane was already used to connect the currently
161  // regarded approached edge
162  std::vector<int>::iterator j = find(lanes.begin(), lanes.end(), lane);
163  if (j == lanes.end()) {
164  // if not, add it to the list
165  lanes.push_back(lane);
166  }
167  // set information about connecting lanes
168  myConnections[succEdge] = lanes;
169 }
170 
171 
172 
173 /* -------------------------------------------------------------------------
174  * NBEdge::MainDirections-methods
175  * ----------------------------------------------------------------------- */
177  NBEdge* parent, NBNode* to, int indexOfStraightest) {
178  if (outgoing.size() == 0) {
179  return;
180  }
181  // check whether the right turn has a higher priority
182  assert(outgoing.size() > 0);
183  const LinkDirection straightestDir = to->getDirection(parent, outgoing[indexOfStraightest]);
184 #ifdef DEBUG_CONNECTION_GUESSING
185  if (DEBUGCOND2(parent)) {
186  std::cout << " MainDirections edge=" << parent->getID() << " straightest=" << outgoing[indexOfStraightest]->getID() << " dir=" << toString(straightestDir) << "\n";
187  }
188 #endif
189  if (NBNode::isTrafficLight(to->getType()) &&
190  (straightestDir == LINKDIR_STRAIGHT || straightestDir == LINKDIR_PARTLEFT || straightestDir == LINKDIR_PARTRIGHT)) {
191  myDirs.push_back(MainDirections::DIR_FORWARD);
192  return;
193  }
194  if (outgoing[0]->getJunctionPriority(to) == 1) {
195  myDirs.push_back(MainDirections::DIR_RIGHTMOST);
196  }
197  // check whether the left turn has a higher priority
198  if (outgoing.back()->getJunctionPriority(to) == 1) {
199  // ok, the left turn belongs to the higher priorised edges on the junction
200  // let's check, whether it has also a higher priority (lane number/speed)
201  // than the current
202  EdgeVector tmp(outgoing);
203  sort(tmp.begin(), tmp.end(), NBContHelper::edge_similar_direction_sorter(parent));
204  if (outgoing.back()->getPriority() > tmp[0]->getPriority()) {
205  myDirs.push_back(MainDirections::DIR_LEFTMOST);
206  } else {
207  if (outgoing.back()->getNumLanes() > tmp[0]->getNumLanes()) {
208  myDirs.push_back(MainDirections::DIR_LEFTMOST);
209  }
210  }
211  }
212  // check whether the forward direction has a higher priority
213  // try to get the forward direction
214  EdgeVector tmp(outgoing);
215  sort(tmp.begin(), tmp.end(), NBContHelper::edge_similar_direction_sorter(parent));
216  NBEdge* edge = *(tmp.begin());
217  // check whether it has a higher priority and is going straight
218  if (edge->getJunctionPriority(to) == 1 && to->getDirection(parent, edge) == LINKDIR_STRAIGHT) {
219  myDirs.push_back(MainDirections::DIR_FORWARD);
220  }
221 }
222 
223 
225 
226 
227 bool
229  return myDirs.empty();
230 }
231 
232 
233 bool
235  return find(myDirs.begin(), myDirs.end(), d) != myDirs.end();
236 }
237 
238 
239 /* -------------------------------------------------------------------------
240  * NBEdge::connections_relative_edgelane_sorter-methods
241  * ----------------------------------------------------------------------- */
242 int
244  if (c1.toEdge != c2.toEdge) {
246  }
247  return c1.toLane < c2.toLane;
248 }
249 
250 
251 /* -------------------------------------------------------------------------
252  * NBEdge-methods
253  * ----------------------------------------------------------------------- */
254 NBEdge::NBEdge(const std::string& id, NBNode* from, NBNode* to,
255  std::string type, double speed, int nolanes,
256  int priority, double laneWidth, double endOffset,
257  const std::string& streetName,
258  LaneSpreadFunction spread) :
259  Named(StringUtils::convertUmlaute(id)),
260  myStep(INIT),
261  myType(StringUtils::convertUmlaute(type)),
262  myFrom(from), myTo(to),
264  myPriority(priority), mySpeed(speed),
268  myLaneSpreadFunction(spread), myEndOffset(endOffset),
269  myStopOffsets(),
270  myLaneWidth(laneWidth),
273  myStreetName(streetName),
275  myIndex(-1) {
276  init(nolanes, false, "");
277 }
278 
279 
280 NBEdge::NBEdge(const std::string& id, NBNode* from, NBNode* to,
281  std::string type, double speed, int nolanes,
282  int priority, double laneWidth, double endOffset,
283  PositionVector geom,
284  const std::string& streetName,
285  const std::string& origID,
286  LaneSpreadFunction spread, bool tryIgnoreNodePositions) :
287  Named(StringUtils::convertUmlaute(id)),
288  myStep(INIT),
289  myType(StringUtils::convertUmlaute(type)),
290  myFrom(from), myTo(to),
292  myPriority(priority), mySpeed(speed),
296  myGeom(geom), myLaneSpreadFunction(spread), myEndOffset(endOffset),
297  myStopOffsets(),
298  myLaneWidth(laneWidth),
301  myStreetName(streetName),
303  myIndex(-1) {
304  init(nolanes, tryIgnoreNodePositions, origID);
305 }
306 
307 
308 NBEdge::NBEdge(const std::string& id, NBNode* from, NBNode* to, const NBEdge* tpl, const PositionVector& geom, int numLanes) :
309  Named(StringUtils::convertUmlaute(id)),
310  myStep(INIT),
311  myType(tpl->getTypeID()),
312  myFrom(from), myTo(to),
314  myPriority(tpl->getPriority()), mySpeed(tpl->getSpeed()),
318  myGeom(geom),
320  myEndOffset(tpl->getEndOffset()),
322  myLaneWidth(tpl->getLaneWidth()),
324  myAmInnerEdge(false),
326  myStreetName(tpl->getStreetName()),
328  init(numLanes > 0 ? numLanes : tpl->getNumLanes(), myGeom.size() > 0, "");
329  for (int i = 0; i < getNumLanes(); i++) {
330  const int tplIndex = MIN2(i, tpl->getNumLanes() - 1);
331  setSpeed(i, tpl->getLaneSpeed(tplIndex));
332  setPermissions(tpl->getPermissions(tplIndex), i);
333  setLaneWidth(i, tpl->myLanes[tplIndex].width);
334  myLanes[i].updateParameter(tpl->myLanes[tplIndex].getParametersMap());
335  if (to == tpl->myTo) {
336  setEndOffset(i, tpl->myLanes[tplIndex].endOffset);
337  setStopOffsets(i, tpl->myLanes[tplIndex].stopOffsets);
338  }
339  }
340 }
341 
342 
343 void
344 NBEdge::reinit(NBNode* from, NBNode* to, const std::string& type,
345  double speed, int nolanes, int priority,
346  PositionVector geom, double laneWidth, double endOffset,
347  const std::string& streetName,
348  LaneSpreadFunction spread,
349  bool tryIgnoreNodePositions) {
350  if (myFrom != from) {
351  myFrom->removeEdge(this, false);
352  }
353  if (myTo != to) {
354  myTo->removeEdge(this, false);
355  }
357  myFrom = from;
358  myTo = to;
359  myPriority = priority;
360  //?myTurnDestination(0),
361  //?myFromJunctionPriority(-1), myToJunctionPriority(-1),
362  myGeom = geom;
363  myLaneSpreadFunction = spread;
365  myStreetName = streetName;
366  //?, myAmTurningWithAngle(0), myAmTurningOf(0),
367  //?myAmInnerEdge(false), myAmMacroscopicConnector(false)
368 
369  // preserve lane-specific settings (geometry must be recomputed)
370  // if new lanes are added they copy the values from the leftmost lane (if specified)
371  const std::vector<Lane> oldLanes = myLanes;
372  init(nolanes, tryIgnoreNodePositions, oldLanes.empty() ? "" : oldLanes[0].getParameter(SUMO_PARAM_ORIGID));
373  for (int i = 0; i < (int)nolanes; ++i) {
374  PositionVector newShape = myLanes[i].shape;
375  myLanes[i] = oldLanes[MIN2(i, (int)oldLanes.size() - 1)];
376  myLanes[i].shape = newShape;
377  }
378  // however, if the new edge defaults are explicityly given, they override the old settings
379  if (endOffset != UNSPECIFIED_OFFSET) {
380  setEndOffset(-1, endOffset);
381  }
382  if (laneWidth != UNSPECIFIED_WIDTH) {
383  setLaneWidth(-1, laneWidth);
384  }
385  if (speed != UNSPECIFIED_SPEED) {
386  setSpeed(-1, speed);
387  }
388 }
389 
390 
391 void
393  // connections may still be valid
394  if (from == 0 || to == 0) {
395  throw ProcessError("At least one of edge's '" + myID + "' nodes is not known.");
396  }
397  if (myFrom != from) {
398  myFrom->removeEdge(this, false);
399  }
400  if (myTo != to) {
401  myTo->removeEdge(this, false);
402  }
403  // remove first from both nodes and then add to the new nodes
404  // (otherwise reversing does not work)
405  if (myFrom != from) {
406  myFrom = from;
407  myFrom->addOutgoingEdge(this);
408  }
409  if (myTo != to) {
410  myTo = to;
411  myTo->addIncomingEdge(this);
412  }
413  computeAngle();
414 }
415 
416 
417 void
418 NBEdge::init(int noLanes, bool tryIgnoreNodePositions, const std::string& origID) {
419  if (noLanes == 0) {
420  throw ProcessError("Edge '" + myID + "' needs at least one lane.");
421  }
422  if (myFrom == 0 || myTo == 0) {
423  throw ProcessError("At least one of edge's '" + myID + "' nodes is not known.");
424  }
426  throw ProcessError("Invalid edge id '" + myID + "'.");
427  }
428  // revisit geometry
429  // should have at least two points at the end...
430  // and in dome cases, the node positions must be added
432  if (!tryIgnoreNodePositions || myGeom.size() < 2) {
433  if (myGeom.size() == 0) {
434  myGeom.push_back(myFrom->getPosition());
435  myGeom.push_back(myTo->getPosition());
436  } else {
439  }
440  }
441  if (myGeom.size() < 2) {
442  myGeom.clear();
443  myGeom.push_back(myFrom->getPosition());
444  myGeom.push_back(myTo->getPosition());
445  }
446  if (myGeom.size() == 2 && myGeom[0] == myGeom[1]) {
447  WRITE_WARNING("Edge's '" + myID + "' from- and to-node are at the same position.");
449  }
450  //
451  myFrom->addOutgoingEdge(this);
452  myTo->addIncomingEdge(this);
453  // prepare container
455  assert(myGeom.size() >= 2);
456  if ((int)myLanes.size() > noLanes) {
457  // remove connections starting at the removed lanes
458  for (int lane = noLanes; lane < (int)myLanes.size(); ++lane) {
459  removeFromConnections(0, lane, -1);
460  }
461  // remove connections targeting the removed lanes
462  const EdgeVector& incoming = myFrom->getIncomingEdges();
463  for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
464  for (int lane = noLanes; lane < (int)myLanes.size(); ++lane) {
465  (*i)->removeFromConnections(this, -1, lane);
466  }
467  }
468  }
469  myLanes.clear();
470  for (int i = 0; i < noLanes; i++) {
471  myLanes.push_back(Lane(this, origID));
472  }
474  computeAngle();
475 
476 #ifdef DEBUG_CONNECTION_GUESSING
477  if (DEBUGCOND) {
478  std::cout << "init edge=" << getID() << "\n";
479  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
480  std::cout << " conn " << getID() << "_" << (*i).fromLane << " to " << Named::getIDSecure((*i).toEdge) << "_" << (*i).toLane << "\n";
481  (*i).shape.mirrorX();
482  (*i).viaShape.mirrorX();
483  }
484  }
485 #endif
486 }
487 
488 
490 
491 
492 // ----------- Applying offset
493 void
494 NBEdge::reshiftPosition(double xoff, double yoff) {
495  myGeom.add(xoff, yoff, 0);
496  for (int i = 0; i < (int)myLanes.size(); i++) {
497  myLanes[i].shape.add(xoff, yoff, 0);
498  }
499  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
500  (*i).customShape.add(xoff, yoff, 0);
501  }
502  computeAngle(); // update angles because they are numerically sensitive (especially where based on centroids)
503 }
504 
505 
506 void
508  myGeom.mirrorX();
509  for (int i = 0; i < (int)myLanes.size(); i++) {
510  myLanes[i].shape.mirrorX();
511  }
512  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
513  (*i).shape.mirrorX();
514  (*i).viaShape.mirrorX();
515  }
516  computeAngle(); // update angles because they are numerically sensitive (especially where based on centroids)
517 }
518 
519 
520 // ----------- Edge geometry access and computation
521 const PositionVector
523  return myGeom.getSubpartByIndex(1, (int)myGeom.size() - 2);
524 }
525 
526 
527 bool
529  return myGeom.size() == 2 && hasDefaultGeometryEndpoints();
530 }
531 
532 
533 bool
535  return myGeom.front() == myFrom->getPosition() &&
536  myGeom.back() == myTo->getPosition();
537 }
538 
539 
540 bool
542  // do not extend past the node position
543  if (node == myFrom) {
544  return myGeom.front() == node->getPosition();
545  } else {
546  assert(node == myTo);
547  return myGeom.back() == node->getPosition();
548  }
549 }
550 
551 void
552 NBEdge::setGeometry(const PositionVector& s, bool inner) {
553  Position begin = myGeom.front(); // may differ from node position
554  Position end = myGeom.back(); // may differ from node position
555  myGeom = s;
556  if (inner) {
557  myGeom.insert(myGeom.begin(), begin);
558  myGeom.push_back(end);
559  }
561  computeAngle();
562 }
563 
564 
565 void
566 NBEdge::extendGeometryAtNode(const NBNode* node, double maxExtent) {
567  //std::cout << "extendGeometryAtNode edge=" << getID() << " node=" << node->getID() << " nodePos=" << node->getPosition() << " extent=" << maxExtent << " geom=" << myGeom;
568  if (node == myFrom) {
569  myGeom.extrapolate(maxExtent, true);
570  double offset = myGeom.nearest_offset_to_point2D(node->getPosition());
571  //std::cout << " geom2=" << myGeom << " offset=" << offset;
572  if (offset != GeomHelper::INVALID_OFFSET) {
574  }
575  } else {
576  assert(node == myTo);
577  myGeom.extrapolate(maxExtent, false, true);
578  double offset = myGeom.nearest_offset_to_point2D(node->getPosition());
579  //std::cout << " geom2=" << myGeom << " offset=" << offset;
580  if (offset != GeomHelper::INVALID_OFFSET) {
581  myGeom = myGeom.getSubpart2D(0, MAX2(offset, 2 * POSITION_EPS));
582  }
583  }
584  //std::cout << " geom3=" << myGeom << "\n";
585 }
586 
587 
588 void
589 NBEdge::shortenGeometryAtNode(const NBNode* node, double reduction) {
590  //std::cout << "shortenGeometryAtNode edge=" << getID() << " node=" << node->getID() << " nodePos=" << node->getPosition() << " reduction=" << reduction << " geom=" << myGeom;
591  reduction = MIN2(reduction, myGeom.length2D() - 2 * POSITION_EPS);
592  if (node == myFrom) {
593  myGeom = myGeom.getSubpart2D(reduction, myGeom.length2D());
594  } else {
595  myGeom = myGeom.getSubpart2D(0, myGeom.length2D() - reduction);
596  }
598  //std::cout << " geom2=" << myGeom << "\n";
599 }
600 
601 
602 void
603 NBEdge::setNodeBorder(const NBNode* node, const Position& p, const Position& p2, bool rectangularCut) {
604  PositionVector border;
605  if (rectangularCut) {
606  const double extend = 100;
607  border = myGeom.getOrthogonal(p, extend, node == myTo);
608  } else {
609  border.push_back(p);
610  border.push_back(p2);
611  }
612  if (border.size() == 2) {
613  double edgeWidth = 0;
614  for (int i = 0; i < (int)myLanes.size(); i++) {
615  edgeWidth += getLaneWidth(i);
616  }
617  border.extrapolate2D(getTotalWidth());
618  if (node == myFrom) {
619  myFromBorder = border;
620  } else {
621  assert(node == myTo);
622  myToBorder = border;
623  }
624  }
625 #ifdef DEBUG_NODE_BORDER
627  if (DEBUGCOND) std::cout << "setNodeBorder edge=" << getID() << " node=" << node->getID()
628  << " rect=" << rectangularCut
629  << " p=" << p << " p2=" << p2
630  << " border=" << border
631  << " myGeom=" << myGeom
632  << "\n";
633 
634 #endif
635 }
636 
637 
638 void
640  if (node == myFrom) {
641  myFromBorder.clear();
642  } else {
643  assert(node == myTo);
644  myToBorder.clear();
645  }
646 }
647 
648 
649 bool
650 NBEdge::isBidiRail(bool ignoreSpread) const {
651  return (isRailway(getPermissions())
652  && (ignoreSpread || myLaneSpreadFunction == LANESPREAD_CENTER)
657 }
658 
659 
660 bool
662  if (!isRailway(getPermissions())) {
663  return false;
664  }
665  for (NBEdge* out : myTo->getOutgoingEdges()) {
666  if (isRailway(out->getPermissions()) &&
667  out != getTurnDestination(true)) {
668  return true;
669  }
670  }
671  return true;
672 }
673 
674 
677  PositionVector shape = old;
678  shape = startShapeAt(shape, myFrom, myFromBorder);
679  if (shape.size() < 2) {
680  // only keep the last snippet
681  const double oldLength = old.length();
682  shape = old.getSubpart(oldLength - 2 * POSITION_EPS, oldLength);
683  }
684  shape = startShapeAt(shape.reverse(), myTo, myToBorder).reverse();
685  // sanity checks
686  if (shape.length() < POSITION_EPS) {
687  if (old.length() < 2 * POSITION_EPS) {
688  shape = old;
689  } else {
690  const double midpoint = old.length() / 2;
691  // EPS*2 because otherwhise shape has only a single point
692  shape = old.getSubpart(midpoint - POSITION_EPS, midpoint + POSITION_EPS);
693  assert(shape.size() >= 2);
694  assert(shape.length() > 0);
695  }
696  } else {
697  // @note If the node shapes are overlapping we may get a shape which goes in the wrong direction
698  // in this case the result shape should shortened
699  if (DEG2RAD(135) < fabs(GeomHelper::angleDiff(shape.beginEndAngle(), old.beginEndAngle()))) {
700  // eliminate intermediate points
701  PositionVector tmp;
702  tmp.push_back(shape[0]);
703  tmp.push_back(shape[-1]);
704  // 3D geometry may be messed up since positions were extrapolated rather than interpolated due to cutting in the wrong direction
705  // make the edge level with one of the intersections (try to pick one that needs to be flat as well)
706  if (myTo->geometryLike()) {
707  tmp[0].setz(myFrom->getPosition().z());
708  tmp[1].setz(myFrom->getPosition().z());
709  } else {
710  tmp[0].setz(myTo->getPosition().z());
711  tmp[1].setz(myTo->getPosition().z());
712  }
713  shape = tmp;
714  if (tmp.length() < POSITION_EPS) {
715  // fall back to original shape
716  if (old.length() < 2 * POSITION_EPS) {
717  shape = old;
718  } else {
719  const double midpoint = old.length() / 2;
720  // EPS*2 because otherwhise shape has only a single point
721  shape = old.getSubpart(midpoint - POSITION_EPS, midpoint + POSITION_EPS);
722  assert(shape.size() >= 2);
723  assert(shape.length() > 0);
724  }
725  } else {
726  const double midpoint = shape.length() / 2;
727  // cut to size and reverse
728  shape = shape.getSubpart(midpoint - POSITION_EPS, midpoint + POSITION_EPS);
729  if (shape.length() < POSITION_EPS) {
730  assert(false);
731  // the shape has a sharp turn near the midpoint
732  }
733  shape = shape.reverse();
734  }
735  }
736  }
737  return shape;
738 }
739 
740 
741 void
743  for (int i = 0; i < (int)myLanes.size(); i++) {
744  myLanes[i].shape = cutAtIntersection(myLanes[i].shape);
745  }
746  // recompute edge's length as the average of lane lenghts
747  double avgLength = 0;
748  for (int i = 0; i < (int)myLanes.size(); i++) {
749  avgLength += myLanes[i].shape.length();
750  }
751  myLength = avgLength / (double) myLanes.size();
752  computeAngle(); // update angles using the finalized node and lane shapes
753 }
754 
755 
757 NBEdge::startShapeAt(const PositionVector& laneShape, const NBNode* startNode, PositionVector nodeShape) const {
758  if (nodeShape.size() == 0) {
759  nodeShape = startNode->getShape();
760  nodeShape.closePolygon();
761  }
762  PositionVector lb(laneShape.begin(), laneShape.begin() + 2);
763  // this doesn't look reasonable @todo use lb.extrapolateFirstBy(100.0);
764  lb.extrapolate(100.0);
765  if (nodeShape.intersects(laneShape)) {
766  // shape intersects directly
767  std::vector<double> pbv = laneShape.intersectsAtLengths2D(nodeShape);
768  assert(pbv.size() > 0);
769  // ensure that the subpart has at least two points
770  double pb = MIN2(laneShape.length2D() - POSITION_EPS - NUMERICAL_EPS, VectorHelper<double>::maxValue(pbv));
771  if (pb < 0) {
772  return laneShape;
773  }
774  PositionVector ns = laneShape.getSubpart2D(pb, laneShape.length2D());
775  //PositionVector ns = pb < (laneShape.length() - POSITION_EPS) ? laneShape.getSubpart2D(pb, laneShape.length()) : laneShape;
776  if (!startNode->geometryLike() || pb < 1) {
777  // make "real" intersections and small intersections flat
778  ns[0].setz(startNode->getPosition().z());
779  // cutting and patching z-coordinate may cause steep grades which should be smoothed
780  const double dZ = ns.size() >= 2 ? fabs(ns[0].z() - ns[1].z()) : 0;
781  if (dZ > 0) {
782  ns = ns.smoothedZFront(MIN2(ns.length2D(),
783  dZ * 4 * OptionsCont::getOptions().getFloat("geometry.max-grade")));
784  }
785  }
786  assert(ns.size() >= 2);
787  return ns;
788  } else if (nodeShape.intersects(lb)) {
789  // extension of first segment intersects
790  std::vector<double> pbv = lb.intersectsAtLengths2D(nodeShape);
791  assert(pbv.size() > 0);
792  double pb = VectorHelper<double>::maxValue(pbv);
793  assert(pb >= 0);
794  PositionVector result = laneShape.getSubpartByIndex(1, (int)laneShape.size() - 1);
795  Position np = PositionVector::positionAtOffset2D(lb[0], lb[1], pb);
796  if (!startNode->geometryLike()) {
797  // make "real" intersections flat
798  np.setz(startNode->getPosition().z());
799  }
800  result.push_front_noDoublePos(np);
801  const double dZ = result.size() >= 2 ? fabs(result[0].z() - result[1].z()) : 0;
802  if (dZ > 0) {
803  result = result.smoothedZFront(MIN2(result.length2D(),
804  dZ * 4 * OptionsCont::getOptions().getFloat("geometry.max-grade")));
805  }
806  return result;
807  //if (result.size() >= 2) {
808  // return result;
809  //} else {
810  // WRITE_WARNING(error + " (resulting shape is too short)");
811  // return laneShape;
812  //}
813  } else {
814  // could not find proper intersection. Probably the edge is very short
815  // and lies within nodeShape
816  // @todo enable warning WRITE_WARNING(error + " (laneShape lies within nodeShape)");
817  return laneShape;
818  }
819 }
820 
821 
822 const PositionVector&
823 NBEdge::getLaneShape(int i) const {
824  return myLanes[i].shape;
825 }
826 
827 
828 void
830  myLaneSpreadFunction = spread;
831 }
832 
833 
834 void
835 NBEdge::addGeometryPoint(int index, const Position& p) {
836  if (index >= 0) {
837  myGeom.insert_noDoublePos(myGeom.begin() + index, p);
838  } else {
839  myGeom.insert_noDoublePos(myGeom.end() + index, p);
840  }
841 }
842 
843 
844 bool
846  // check whether there any splits to perform
847  if (myGeom.size() < 3) {
848  return false;
849  }
850  // ok, split
851  NBNode* newFrom = myFrom;
852  NBNode* myLastNode = myTo;
853  NBNode* newTo = 0;
854  NBEdge* currentEdge = this;
855  for (int i = 1; i < (int) myGeom.size() - 1; i++) {
856  // build the node first
857  if (i != (int)myGeom.size() - 2) {
858  std::string nodename = myID + "_in_between#" + toString(i);
859  if (!nc.insert(nodename, myGeom[i])) {
860  throw ProcessError("Error on adding in-between node '" + nodename + "'.");
861  }
862  newTo = nc.retrieve(nodename);
863  } else {
864  newTo = myLastNode;
865  }
866  if (i == 1) {
867  currentEdge->myTo->removeEdge(this);
868  currentEdge->myTo = newTo;
869  newTo->addIncomingEdge(currentEdge);
870  } else {
871  std::string edgename = myID + "[" + toString(i - 1) + "]";
872  // @bug lane-specific width, speed, overall offset and restrictions are ignored
873  currentEdge = new NBEdge(edgename, newFrom, newTo, myType, mySpeed, (int) myLanes.size(),
875  if (!ec.insert(currentEdge, true)) {
876  throw ProcessError("Error on adding splitted edge '" + edgename + "'.");
877  }
878  }
879  newFrom = newTo;
880  }
881  myGeom.clear();
882  myGeom.push_back(myFrom->getPosition());
883  myGeom.push_back(myTo->getPosition());
884  myStep = INIT;
885  return true;
886 }
887 
888 
889 void
890 NBEdge::reduceGeometry(const double minDist) {
891  myGeom.removeDoublePoints(minDist, true);
892 }
893 
894 
895 void
896 NBEdge::checkGeometry(const double maxAngle, const double minRadius, bool fix) {
897  if (myGeom.size() < 3) {
898  return;
899  }
900  //std::cout << "checking geometry of " << getID() << " geometry = " << toString(myGeom) << "\n";
901  std::vector<double> angles; // absolute segment angles
902  //std::cout << " absolute angles:";
903  for (int i = 0; i < (int)myGeom.size() - 1; ++i) {
904  angles.push_back(myGeom.angleAt2D(i));
905  //std::cout << " " << angles.back();
906  }
907  //std::cout << "\n relative angles: ";
908  for (int i = 0; i < (int)angles.size() - 1; ++i) {
909  const double relAngle = fabs(GeomHelper::angleDiff(angles[i], angles[i + 1]));
910  //std::cout << relAngle << " ";
911  if (maxAngle > 0 && relAngle > maxAngle) {
912  WRITE_WARNING("Found angle of " + toString(RAD2DEG(relAngle)) + " degrees at edge '" + getID() + "', segment " + toString(i));
913  }
914  if (relAngle < DEG2RAD(1)) {
915  continue;
916  }
917  if (i == 0 || i == (int)angles.size() - 2) {
918  const bool start = i == 0;
919  const double dist = (start ? myGeom[0].distanceTo2D(myGeom[1]) : myGeom[-2].distanceTo2D(myGeom[-1]));
920  const double r = tan(0.5 * (M_PI - relAngle)) * dist;
921  //std::cout << (start ? " start" : " end") << " length=" << dist << " radius=" << r << " ";
922  if (minRadius > 0 && r < minRadius) {
923  if (fix) {
924  WRITE_MESSAGE("Removing sharp turn with radius " + toString(r) + " at the " +
925  (start ? "start" : "end") + " of edge '" + getID() + "'.");
926  myGeom.erase(myGeom.begin() + (start ? 1 : i + 1));
927  checkGeometry(maxAngle, minRadius, fix);
928  return;
929  } else {
930  WRITE_WARNING("Found sharp turn with radius " + toString(r) + " at the " +
931  (start ? "start" : "end") + " of edge '" + getID() + "'.");
932  }
933  }
934  }
935  }
936  //std::cout << "\n";
937 }
938 
939 
940 // ----------- Setting and getting connections
941 bool
944  return true;
945  }
946  // check whether the node was merged and now a connection between
947  // not matching edges is tried to be added
948  // This happens f.e. within the ptv VISSIM-example "Beijing"
949  if (dest != 0 && myTo != dest->myFrom) {
950  return false;
951  }
952  if (dest == 0) {
954  myConnections.push_back(Connection(-1, dest, -1));
955  } else if (find_if(myConnections.begin(), myConnections.end(), connections_toedge_finder(dest)) == myConnections.end()) {
956  myConnections.push_back(Connection(-1, dest, -1));
957  }
958  if (myStep < EDGE2EDGES) {
959  myStep = EDGE2EDGES;
960  }
961  return true;
962 }
963 
964 
965 bool
967  int toLane, Lane2LaneInfoType type,
968  bool mayUseSameDestination,
969  bool mayDefinitelyPass,
970  bool keepClear,
971  double contPos,
972  double visibility,
973  double speed,
974  const PositionVector& customShape,
975  bool uncontrolled) {
977  return true;
978  }
979  // check whether the node was merged and now a connection between
980  // not matching edges is tried to be added
981  // This happens f.e. within the ptv VISSIM-example "Beijing"
982  if (myTo != dest->myFrom) {
983  return false;
984  }
985  if (!addEdge2EdgeConnection(dest)) {
986  return false;
987  }
988  return setConnection(from, dest, toLane, type, mayUseSameDestination, mayDefinitelyPass, keepClear, contPos, visibility, speed, customShape, uncontrolled);
989 }
990 
991 
992 bool
994  NBEdge* dest, int toLane,
995  int no, Lane2LaneInfoType type,
996  bool invalidatePrevious,
997  bool mayDefinitelyPass) {
998  if (invalidatePrevious) {
999  invalidateConnections(true);
1000  }
1001  bool ok = true;
1002  for (int i = 0; i < no && ok; i++) {
1003  ok &= addLane2LaneConnection(fromLane + i, dest, toLane + i, type, false, mayDefinitelyPass);
1004  }
1005  return ok;
1006 }
1007 
1008 
1009 bool
1010 NBEdge::setConnection(int lane, NBEdge* destEdge,
1011  int destLane, Lane2LaneInfoType type,
1012  bool mayUseSameDestination,
1013  bool mayDefinitelyPass,
1014  bool keepClear,
1015  double contPos,
1016  double visibility,
1017  double speed,
1018  const PositionVector& customShape,
1019  bool uncontrolled) {
1021  return false;
1022  }
1023  // some kind of a misbehaviour which may occure when the junction's outgoing
1024  // edge priorities were not properly computed, what may happen due to
1025  // an incomplete or not proper input
1026  // what happens is that under some circumstances a single lane may set to
1027  // be approached more than once by the one of our lanes.
1028  // This must not be!
1029  // we test whether it is the case and do nothing if so - the connection
1030  // will be refused
1031  //
1032  if (!mayUseSameDestination && hasConnectionTo(destEdge, destLane)) {
1033  return false;
1034  }
1035  if (find_if(myConnections.begin(), myConnections.end(), connections_finder(lane, destEdge, destLane)) != myConnections.end()) {
1036  return true;
1037  }
1038  if ((int)myLanes.size() <= lane || destEdge->getNumLanes() <= (int)destLane) {
1039  // problem might be corrigible in post-processing
1040  WRITE_WARNING("Could not set connection from '" + getLaneIDInsecure(lane) + "' to '" + destEdge->getLaneIDInsecure(destLane) + "'.");
1041  return false;
1042  }
1043  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end();) {
1044  if ((*i).toEdge == destEdge && ((*i).fromLane == -1 || (*i).toLane == -1)) {
1045  i = myConnections.erase(i);
1046  } else {
1047  ++i;
1048  }
1049  }
1050  myConnections.push_back(Connection(lane, destEdge, destLane));
1051  if (mayDefinitelyPass) {
1052  myConnections.back().mayDefinitelyPass = true;
1053  }
1054  myConnections.back().keepClear = keepClear;
1055  myConnections.back().contPos = contPos;
1056  myConnections.back().visibility = visibility;
1057  myConnections.back().speed = speed;
1058  myConnections.back().customShape = customShape;
1059  myConnections.back().uncontrolled = uncontrolled;
1060  if (type == L2L_USER) {
1062  } else {
1063  // check whether we have to take another look at it later
1064  if (type == L2L_COMPUTED) {
1065  // yes, the connection was set using an algorithm which requires a recheck
1067  } else {
1068  // ok, let's only not recheck it if we did no add something that has to be rechecked
1069  if (myStep != LANES2LANES_RECHECK) {
1071  }
1072  }
1073  }
1074  return true;
1075 }
1076 
1077 
1078 void
1080  myConnections.push_back(connection);
1081 }
1082 
1083 
1084 std::vector<NBEdge::Connection>
1086  std::vector<NBEdge::Connection> ret;
1087  for (std::vector<Connection>::const_iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
1088  if ((*i).fromLane == lane) {
1089  ret.push_back(*i);
1090  }
1091  }
1092  return ret;
1093 }
1094 
1095 
1097 NBEdge::getConnection(int fromLane, const NBEdge* to, int toLane) const {
1098  for (std::vector<Connection>::const_iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
1099  if (
1100  (*i).fromLane == fromLane
1101  && (*i).toEdge == to
1102  && (*i).toLane == toLane) {
1103  return *i;
1104  }
1105  }
1106  throw ProcessError("Connection from " + getID() + "_" + toString(fromLane)
1107  + " to " + to->getID() + "_" + toString(toLane) + " not found");
1108 }
1109 
1111 NBEdge::getConnectionRef(int fromLane, const NBEdge* to, int toLane) {
1112  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
1113  if (
1114  (*i).fromLane == fromLane
1115  && (*i).toEdge == to
1116  && (*i).toLane == toLane) {
1117  return *i;
1118  }
1119  }
1120  throw ProcessError("Connection from " + getID() + "_" + toString(fromLane)
1121  + " to " + to->getID() + "_" + toString(toLane) + " not found");
1122 }
1123 
1124 
1125 bool
1126 NBEdge::hasConnectionTo(NBEdge* destEdge, int destLane, int fromLane) const {
1127  return destEdge != 0 && find_if(myConnections.begin(), myConnections.end(), connections_toedgelane_finder(destEdge, destLane, fromLane)) != myConnections.end();
1128 }
1129 
1130 
1131 bool
1133  if (e == myTurnDestination) {
1134  return true;
1135  }
1136  return
1137  find_if(myConnections.begin(), myConnections.end(), connections_toedge_finder(e))
1138  !=
1139  myConnections.end();
1140 
1141 }
1142 
1143 
1144 const EdgeVector*
1146  // check whether connections exist and if not, use edges from the node
1147  EdgeVector outgoing;
1148  if (myConnections.size() == 0) {
1149  outgoing = myTo->getOutgoingEdges();
1150  } else {
1151  for (std::vector<Connection>::const_iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
1152  if (find(outgoing.begin(), outgoing.end(), (*i).toEdge) == outgoing.end()) {
1153  outgoing.push_back((*i).toEdge);
1154  }
1155  }
1156  }
1157  for (std::vector<Connection>::iterator it = myConnectionsToDelete.begin(); it != myConnectionsToDelete.end(); ++it) {
1158  if (it->fromLane < 0 && it->toLane < 0) {
1159  // found an edge that shall not be connected
1160  EdgeVector::iterator forbidden = find(outgoing.begin(), outgoing.end(), it->toEdge);
1161  if (forbidden != outgoing.end()) {
1162  outgoing.erase(forbidden);
1163  }
1164  }
1165  }
1166  // allocate the sorted container
1167  int size = (int) outgoing.size();
1168  EdgeVector* edges = new EdgeVector();
1169  edges->reserve(size);
1170  for (EdgeVector::const_iterator i = outgoing.begin(); i != outgoing.end(); i++) {
1171  NBEdge* outedge = *i;
1172  if (outedge != 0 && outedge != myTurnDestination) {
1173  edges->push_back(outedge);
1174  }
1175  }
1176  sort(edges->begin(), edges->end(), NBContHelper::relative_outgoing_edge_sorter(this));
1177  return edges;
1178 }
1179 
1180 
1181 EdgeVector
1183  EdgeVector ret;
1184  for (std::vector<Connection>::const_iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
1185  if (find(ret.begin(), ret.end(), (*i).toEdge) == ret.end()) {
1186  ret.push_back((*i).toEdge);
1187  }
1188  }
1189  return ret;
1190 }
1191 
1192 
1193 EdgeVector
1195  EdgeVector ret;
1196  const EdgeVector& candidates = myFrom->getIncomingEdges();
1197  for (EdgeVector::const_iterator i = candidates.begin(); i != candidates.end(); i++) {
1198  if ((*i)->isConnectedTo(this)) {
1199  ret.push_back(*i);
1200  }
1201  }
1202  return ret;
1203 }
1204 
1205 
1206 std::vector<int>
1207 NBEdge::getConnectionLanes(NBEdge* currentOutgoing) const {
1208  std::vector<int> ret;
1209  if (currentOutgoing != myTurnDestination) {
1210  for (std::vector<Connection>::const_iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
1211  if ((*i).toEdge == currentOutgoing) {
1212  ret.push_back((*i).fromLane);
1213  }
1214  }
1215  }
1216  return ret;
1217 }
1218 
1219 
1220 void
1223 }
1224 
1225 
1226 void
1228  sort(myConnections.begin(), myConnections.end(), connections_sorter);
1229 }
1230 
1231 
1232 void
1234  EdgeVector connected = getConnectedEdges();
1235  for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
1236  NBEdge* inc = *i;
1237  // We have to do this
1238  inc->myStep = EDGE2EDGES;
1239  // add all connections
1240  for (EdgeVector::iterator j = connected.begin(); j != connected.end(); j++) {
1241  inc->addEdge2EdgeConnection(*j);
1242  }
1243  inc->removeFromConnections(this);
1244  }
1245 }
1246 
1247 
1248 void
1249 NBEdge::removeFromConnections(NBEdge* toEdge, int fromLane, int toLane, bool tryLater, const bool adaptToLaneRemoval) {
1250  // remove from "myConnections"
1251  const int fromLaneRemoved = adaptToLaneRemoval && fromLane >= 0 ? fromLane : -1;
1252  const int toLaneRemoved = adaptToLaneRemoval && toLane >= 0 ? toLane : -1;
1253  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end();) {
1254  Connection& c = *i;
1255  if ((toEdge == 0 || c.toEdge == toEdge)
1256  && (fromLane < 0 || c.fromLane == fromLane)
1257  && (toLane < 0 || c.toLane == toLane)) {
1258  if (myTo->isTLControlled()) {
1259  std::set<NBTrafficLightDefinition*> tldefs = myTo->getControllingTLS();
1260  for (std::set<NBTrafficLightDefinition*>::iterator it = tldefs.begin(); it != tldefs.end(); it++) {
1261  (*it)->removeConnection(NBConnection(this, c.fromLane, c.toEdge, c.toLane));
1262  }
1263  }
1264  i = myConnections.erase(i);
1265  tryLater = false;
1266  } else {
1267  if (fromLaneRemoved >= 0 && c.fromLane > fromLaneRemoved) {
1268  if (myTo->isTLControlled()) {
1269  std::set<NBTrafficLightDefinition*> tldefs = myTo->getControllingTLS();
1270  for (std::set<NBTrafficLightDefinition*>::iterator it = tldefs.begin(); it != tldefs.end(); it++) {
1271  for (NBConnectionVector::iterator tlcon = (*it)->getControlledLinks().begin(); tlcon != (*it)->getControlledLinks().end(); ++tlcon) {
1272  NBConnection& tc = *tlcon;
1273  if (tc.getTo() == c.toEdge && tc.getFromLane() == c.fromLane && tc.getToLane() == c.toLane) {
1274  tc.shiftLaneIndex(this, -1);
1275  }
1276  }
1277  }
1278  }
1279  c.fromLane--;
1280  }
1281  if (toLaneRemoved >= 0 && c.toLane > toLaneRemoved) {
1282  c.toLane--;
1283  }
1284  ++i;
1285  }
1286  }
1287  // check whether it was the turn destination
1288  if (myTurnDestination == toEdge && fromLane < 0) {
1289  myTurnDestination = 0;
1290  }
1291  if (myPossibleTurnDestination == toEdge && fromLane < 0) {
1293  }
1294  if (tryLater) {
1295  myConnectionsToDelete.push_back(Connection(fromLane, toEdge, toLane));
1296  }
1297 }
1298 
1299 
1300 bool
1302  // iterate over connections
1303  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); i++) {
1304  if (((*i).toEdge == connectionToRemove.toEdge) && ((*i).fromLane == connectionToRemove.fromLane) && ((*i).toLane == connectionToRemove.toLane)) {
1305  // remove connection
1306  myConnections.erase(i);
1307  return true;
1308  }
1309  }
1310  assert(false);
1311  return false;
1312 }
1313 
1314 
1315 void
1316 NBEdge::invalidateConnections(bool reallowSetting) {
1317  myTurnDestination = 0;
1318  myConnections.clear();
1319  if (reallowSetting) {
1320  myStep = INIT;
1321  } else {
1323  }
1324 }
1325 
1326 
1327 void
1328 NBEdge::replaceInConnections(NBEdge* which, NBEdge* by, int laneOff) {
1329  // replace in "_connectedEdges"
1330  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
1331  if ((*i).toEdge == which) {
1332  (*i).toEdge = by;
1333  (*i).toLane += laneOff;
1334  }
1335  }
1336  // check whether it was the turn destination
1337  if (myTurnDestination == which) {
1338  myTurnDestination = by;
1339  }
1340 }
1341 
1342 void
1343 NBEdge::replaceInConnections(NBEdge* which, const std::vector<NBEdge::Connection>& origConns) {
1344  std::map<int, int> laneMap;
1345  int minLane = -1;
1346  int maxLane = -1;
1347  // get lanes used to approach the edge to remap
1348  bool wasConnected = false;
1349  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
1350  if ((*i).toEdge != which) {
1351  continue;
1352  }
1353  wasConnected = true;
1354  if ((*i).fromLane != -1) {
1355  int fromLane = (*i).fromLane;
1356  laneMap[(*i).toLane] = fromLane;
1357  if (minLane == -1 || minLane > fromLane) {
1358  minLane = fromLane;
1359  }
1360  if (maxLane == -1 || maxLane < fromLane) {
1361  maxLane = fromLane;
1362  }
1363  }
1364  }
1365  if (!wasConnected) {
1366  return;
1367  }
1368  // add new connections
1369  std::vector<NBEdge::Connection> conns = origConns;
1370  for (std::vector<NBEdge::Connection>::iterator i = conns.begin(); i != conns.end(); ++i) {
1371  if ((*i).toEdge == which || (*i).toEdge == this) {
1372  continue;
1373  }
1374  if (which->getStep() == EDGE2EDGES) {
1375  // do not set lane-level connections
1376  replaceInConnections(which, (*i).toEdge, 0);
1377  continue;
1378  }
1379  int fromLane = (*i).fromLane;
1380  int toUse = -1;
1381  if (laneMap.find(fromLane) == laneMap.end()) {
1382  if (fromLane >= 0 && fromLane <= minLane) {
1383  toUse = minLane;
1384  }
1385  if (fromLane >= 0 && fromLane >= maxLane) {
1386  toUse = maxLane;
1387  }
1388  } else {
1389  toUse = laneMap[fromLane];
1390  }
1391  if (toUse == -1) {
1392  toUse = 0;
1393  }
1394  setConnection(toUse, i->toEdge, i->toLane, L2L_COMPUTED, false, i->mayDefinitelyPass, i->keepClear,
1395  i->contPos, i->visibility, i->speed, i->customShape, i->uncontrolled);
1396  }
1397  // remove the remapped edge from connections
1398  removeFromConnections(which);
1399 }
1400 
1401 
1402 void
1404  myStep = src->myStep;
1406 }
1407 
1408 
1409 bool
1410 NBEdge::canMoveConnection(const Connection& con, int newFromLane) const {
1411  // only allow using newFromLane if at least 1 vClass is permitted to use
1412  // this connection. If the connection shall be moved to a sidewalk, only create the connection if there is no walking area
1413  const SVCPermissions common = (getPermissions(newFromLane) & con.toEdge->getPermissions(con.toLane));
1414  return (common > 0 && common != SVC_PEDESTRIAN);
1415 }
1416 
1417 
1418 void
1420  int index = 0;
1421  for (int i = 0; i < (int)myConnections.size(); ++i) {
1422  if (myConnections[i].fromLane == (int)(lane) && canMoveConnection(myConnections[i], lane + 1)) {
1423  index = i;
1424  }
1425  }
1426  std::vector<Connection>::iterator i = myConnections.begin() + index;
1427  Connection c = *i;
1428  myConnections.erase(i);
1429  setConnection(lane + 1, c.toEdge, c.toLane, L2L_VALIDATED, false);
1430 }
1431 
1432 
1433 void
1435  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
1436  if ((*i).fromLane == (int)lane && canMoveConnection(*i, lane - 1)) {
1437  Connection c = *i;
1438  i = myConnections.erase(i);
1439  setConnection(lane - 1, c.toEdge, c.toLane, L2L_VALIDATED, false);
1440  return;
1441  }
1442  }
1443 }
1444 
1445 
1446 void
1447 NBEdge::buildInnerEdges(const NBNode& n, int noInternalNoSplits, int& linkIndex, int& splitIndex) {
1448  const int numPoints = OptionsCont::getOptions().getInt("junctions.internal-link-detail");
1449  const bool joinTurns = OptionsCont::getOptions().getBool("junctions.join-turns");
1450  const double limitTurnSpeed = OptionsCont::getOptions().getFloat("junctions.limit-turn-speed");
1451  const double limitTurnSpeedMinAngle = DEG2RAD(OptionsCont::getOptions().getFloat("junctions.limit-turn-speed.min-angle"));
1452  const double limitTurnSpeedMinAngleRail = DEG2RAD(OptionsCont::getOptions().getFloat("junctions.limit-turn-speed.min-angle.railway"));
1453  const double limitTurnSpeedWarnStraight = OptionsCont::getOptions().getFloat("junctions.limit-turn-speed.warn.straight");
1454  const double limitTurnSpeedWarnTurn = OptionsCont::getOptions().getFloat("junctions.limit-turn-speed.warn.turn");
1455  const bool fromRail = isRailway(getPermissions());
1456  std::string innerID = ":" + n.getID();
1457  NBEdge* toEdge = 0;
1458  int edgeIndex = linkIndex;
1459  int internalLaneIndex = 0;
1460  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
1461  Connection& con = *i;
1462  con.haveVia = false; // reset first since this may be called multiple times
1463  if (con.toEdge == 0) {
1464  continue;
1465  }
1466  LinkDirection dir = n.getDirection(this, con.toEdge);
1467  const bool isRightTurn = (dir == LINKDIR_RIGHT || dir == LINKDIR_PARTRIGHT);
1468  const bool isTurn = (isRightTurn || dir == LINKDIR_LEFT || dir == LINKDIR_PARTLEFT);
1469 
1470  // put turning internal lanes on separate edges
1471  if (con.toEdge != toEdge || (isTurn && !joinTurns)) {
1472  // skip indices to keep some correspondence between edge ids and link indices:
1473  // internalEdgeIndex + internalLaneIndex = linkIndex
1474  edgeIndex = linkIndex;
1475  toEdge = (*i).toEdge;
1476  internalLaneIndex = 0;
1477  }
1478  PositionVector shape = n.computeInternalLaneShape(this, con, numPoints, myTo);
1479  std::vector<int> foeInternalLinks;
1480 
1481  if (dir != LINKDIR_STRAIGHT && shape.length() < POSITION_EPS && !(isBidiRail() && getTurnDestination(true) == con.toEdge)) {
1482  WRITE_WARNING("Connection '" + getID() + "_" + toString(con.fromLane) + "->" + con.toEdge->getID() + "_" + toString(con.toLane) + "' is only " + toString(shape.length()) + " short.");
1483  }
1484 
1485  // crossingPosition, list of foe link indices
1486  std::pair<double, std::vector<int> > crossingPositions(-1, std::vector<int>());
1487  std::set<std::string> tmpFoeIncomingLanes;
1488  switch (dir) {
1489  case LINKDIR_RIGHT:
1490  case LINKDIR_PARTRIGHT:
1491  case LINKDIR_LEFT:
1492  case LINKDIR_PARTLEFT:
1493  case LINKDIR_TURN: {
1494  int index = 0;
1495  const std::vector<NBEdge*>& incoming = n.getIncomingEdges();
1496  for (EdgeVector::const_iterator i2 = incoming.begin(); i2 != incoming.end(); ++i2) {
1497  const std::vector<Connection>& elv = (*i2)->getConnections();
1498  for (std::vector<NBEdge::Connection>::const_iterator k2 = elv.begin(); k2 != elv.end(); k2++) {
1499  if ((*k2).toEdge == 0) {
1500  continue;
1501  }
1502  // vehicles are typically less wide than the lane
1503  // they drive on but but bicycle lanes should be kept clear for their whole width
1504  double width2 = (*k2).toEdge->getLaneWidth((*k2).toLane);
1505  if ((*k2).toEdge->getPermissions((*k2).toLane) != SVC_BICYCLE) {
1506  width2 *= 0.5;
1507  }
1508  const bool foes = n.foes(this, con.toEdge, *i2, (*k2).toEdge);
1509  bool needsCont = n.needsCont(this, *i2, con, *k2);
1510  const bool oppositeLeftIntersect = !foes && bothLeftIntersect(n, shape, dir, *i2, *k2, numPoints, width2);
1511  const bool bothPrio = getJunctionPriority(&n) > 0 && (*i2)->getJunctionPriority(&n) > 0;
1512  //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";
1513  // compute the crossing point
1514  if (needsCont || (bothPrio && oppositeLeftIntersect)) {
1515  crossingPositions.second.push_back(index);
1516  const PositionVector otherShape = n.computeInternalLaneShape(*i2, *k2, numPoints);
1517  const double minDV = firstIntersection(shape, otherShape, width2);
1518  if (minDV < shape.length() - POSITION_EPS && minDV > POSITION_EPS) { // !!!?
1519  assert(minDV >= 0);
1520  if (crossingPositions.first < 0 || crossingPositions.first > minDV) {
1521  crossingPositions.first = minDV;
1522  }
1523  }
1524  }
1525  const bool rightTurnConflict = NBNode::rightTurnConflict(
1526  this, con.toEdge, con.fromLane, (*i2), (*k2).toEdge, (*k2).fromLane);
1527  // compute foe internal lanes
1528  if (foes || rightTurnConflict || oppositeLeftIntersect) {
1529  foeInternalLinks.push_back(index);
1530  }
1531  // only warn once per pair of intersecting turns
1532  // do not warn if only bicycles pedestrians or delivery vehicles are involved as this is a typical occurence
1534  if (oppositeLeftIntersect && getID() > (*i2)->getID()
1535  && (getPermissions(con.fromLane) & warn) != 0
1536  && (con.toEdge->getPermissions(con.toLane) & warn) != 0
1537  && ((*i2)->getPermissions((*k2).fromLane) & warn) != 0
1538  && ((*k2).toEdge->getPermissions((*k2).toLane) & warn) != 0
1539  // do not warn for unregulated nodes
1540  && n.getType() != NODETYPE_NOJUNCTION
1541  ) {
1542  WRITE_WARNING("Intersecting left turns at junction '" + n.getID() + "' from lane '" + getLaneID(con.fromLane) + "' and lane '" + (*i2)->getLaneID((*k2).fromLane) + "'. (increase junction radius to avoid this)");
1543  }
1544  // compute foe incoming lanes
1545  const bool signalised = hasSignalisedConnectionTo(con.toEdge);
1546  if ((n.forbids(*i2, (*k2).toEdge, this, con.toEdge, signalised) || rightTurnConflict) && (needsCont || dir == LINKDIR_TURN)) {
1547  tmpFoeIncomingLanes.insert((*i2)->getID() + "_" + toString((*k2).fromLane));
1548  }
1549  if (bothPrio && oppositeLeftIntersect && getID() < (*i2)->getID()) {
1550  //std::cout << " c1=" << con.getDescription(this) << " c2=" << (*k2).getDescription(*i2) << " bothPrio=" << bothPrio << " oppositeLeftIntersect=" << oppositeLeftIntersect << "\n";
1551  // break symmetry using edge id
1552  tmpFoeIncomingLanes.insert(innerID + "_" + toString(index) + "_0");
1553  }
1554  index++;
1555  }
1556  }
1557  // foe pedestrian crossings
1558  std::vector<NBNode::Crossing*> crossings = n.getCrossings();
1559  for (auto c : crossings) {
1560  const NBNode::Crossing& crossing = *c;
1561  for (EdgeVector::const_iterator it_e = crossing.edges.begin(); it_e != crossing.edges.end(); ++it_e) {
1562  const NBEdge* edge = *it_e;
1563  // compute foe internal lanes
1564  if (this == edge || con.toEdge == edge) {
1565  foeInternalLinks.push_back(index);
1566  if (con.toEdge == edge &&
1567  ((isRightTurn && getJunctionPriority(&n) > 0) || (isTurn && n.isTLControlled()))) {
1568  // build internal junctions (not for left turns at uncontrolled intersections)
1569  PositionVector crossingShape = crossing.shape;
1570  crossingShape.extrapolate(5.0); // sometimes shapes miss each other by a small margin
1571  const double minDV = firstIntersection(shape, crossingShape, crossing.width / 2);
1572  if (minDV < shape.length() - POSITION_EPS && minDV > POSITION_EPS) {
1573  assert(minDV >= 0);
1574  if (crossingPositions.first < 0 || crossingPositions.first > minDV) {
1575  crossingPositions.first = minDV;
1576  }
1577  }
1578  }
1579  }
1580  }
1581  index++;
1582  }
1583 
1584  if (dir == LINKDIR_TURN && crossingPositions.first < 0 && crossingPositions.second.size() != 0 && shape.length() > 2. * POSITION_EPS) {
1585  // let turnarounds wait in the middle if no other crossing point was found and it has a sensible length
1586  // (if endOffset is used, the crossing point is in the middle of the part within the junction shape)
1587  crossingPositions.first = (double)(shape.length() + getEndOffset(con.fromLane)) / 2.;
1588  }
1589  }
1590  break;
1591  default:
1592  break;
1593  }
1594  if (con.contPos != UNSPECIFIED_CONTPOS) {
1595  // apply custom internal junction position
1596  if (con.contPos <= 0 || con.contPos >= shape.length()) {
1597  // disable internal junction
1598  crossingPositions.first = -1;
1599  } else {
1600  // set custom position
1601  crossingPositions.first = con.contPos;
1602  }
1603  }
1604 
1605  // @todo compute the maximum speed allowed based on angular velocity
1606  // see !!! for an explanation (with a_lat_mean ~0.3)
1607  /*
1608  double vmax = (double) 0.3 * (double) 9.80778 *
1609  getLaneShape(con.fromLane).back().distanceTo(
1610  con.toEdge->getLaneShape(con.toLane).front())
1611  / (double) 2.0 / (double) M_PI;
1612  vmax = MIN2(vmax, ((getSpeed() + con.toEdge->getSpeed()) / (double) 2.0));
1613  */
1614  if (con.speed == UNSPECIFIED_SPEED) {
1615  con.vmax = (myLanes[con.fromLane].speed + con.toEdge->getLanes()[con.toLane].speed) / (double) 2.0;
1616  if (limitTurnSpeed > 0) {
1617  // see [Odhams and Cole, Models of Driver Speed Choice in Curves, 2004]
1618  const double angleRaw = fabs(GeomHelper::angleDiff(
1619  getLaneShape(con.fromLane).angleAt2D(-2),
1620  con.toEdge->getLaneShape(con.toLane).angleAt2D(0)));
1621  const double angle = MAX2(0.0, angleRaw - (fromRail ? limitTurnSpeedMinAngleRail : limitTurnSpeedMinAngle));
1622  const double length = shape.length2D();
1623  // do not trust the radius of tiny junctions
1624  // formula adapted from [Odhams, Andre and Cole, David, Models of Driver Speed Choice in Curves, 2004]
1625  if (angle > 0 && length > 1) {
1626  // permit higher turning speed on wide lanes
1627  const double radius = length / angle + getLaneWidth(con.fromLane) / 4;
1628  const double limit = sqrt(limitTurnSpeed * radius);
1629  const double reduction = con.vmax - limit;
1630  // always treat connctions at roundabout as turns when warning
1631  const bool atRoundabout = getJunctionPriority(myTo) == ROUNDABOUT || con.toEdge->getJunctionPriority(myFrom) == ROUNDABOUT;
1632  int dir2 = atRoundabout ? LINKDIR_LEFT : dir;
1633  if ((dir2 == LINKDIR_STRAIGHT && reduction > limitTurnSpeedWarnStraight)
1634  || (dir2 != LINKDIR_TURN && reduction > limitTurnSpeedWarnTurn)) {
1635  std::string dirType = std::string(dir == LINKDIR_STRAIGHT ? "straight" : "turning");
1636  if (atRoundabout) {
1637  dirType = "roundabout";
1638  }
1639  WRITE_WARNING("Speed of " + dirType + " connection '" + con.getDescription(this)
1640  + "' reduced by " + toString(reduction) + " due to turning radius of " + toString(radius)
1641  + " (length=" + toString(length) + " angle=" + toString(RAD2DEG(angleRaw)) + ")");
1642  }
1643  con.vmax = MIN2(con.vmax, limit);
1644  // value is saved in <net> attribute. Must be set again when importing from .con.xml
1645  // con.speed = con.vmax;
1646  }
1647  assert(con.vmax > 0);
1648  //if (getID() == "-1017000.0.00") {
1649  // std::cout << con.getDescription(this) << " angleRaw=" << angleRaw << " angle=" << RAD2DEG(angle) << " length=" << length << " radius=" << length / angle
1650  // << " vmaxTurn=" << sqrt(limitTurnSpeed * length / angle) << " vmax=" << con.vmax << "\n";
1651  //}
1652  }
1653  } else {
1654  con.vmax = con.speed;
1655  }
1656  //
1657  assert(shape.size() >= 2);
1658  // get internal splits if any
1659  con.id = innerID + "_" + toString(edgeIndex);
1660  if (crossingPositions.first >= 0) {
1661  std::pair<PositionVector, PositionVector> split = shape.splitAt(crossingPositions.first);
1662  con.shape = split.first;
1663  con.foeIncomingLanes = std::vector<std::string>(tmpFoeIncomingLanes.begin(), tmpFoeIncomingLanes.end());
1664  con.foeInternalLinks = foeInternalLinks; // resolve link indices to lane ids later
1665  con.viaID = innerID + "_" + toString(splitIndex + noInternalNoSplits);
1666  ++splitIndex;
1667  con.viaShape = split.second;
1668  con.haveVia = true;
1669  } else {
1670  con.shape = shape;
1671  }
1672  con.internalLaneIndex = internalLaneIndex;
1673  ++internalLaneIndex;
1674  ++linkIndex;
1675  }
1676 }
1677 
1678 
1679 double
1680 NBEdge::firstIntersection(const PositionVector& v1, const PositionVector& v2, double width2) {
1681  double intersect = std::numeric_limits<double>::max();
1682  if (v2.length() < POSITION_EPS) {
1683  return intersect;
1684  }
1685  PositionVector v2Right = v2;
1686  v2Right.move2side(width2);
1687 
1688  PositionVector v2Left = v2;
1689  v2Left.move2side(-width2);
1690 
1691  // intersect center line of v1 with left and right border of v2
1692  for (double cand : v1.intersectsAtLengths2D(v2Right)) {
1693  intersect = MIN2(intersect, cand);
1694  }
1695  for (double cand : v1.intersectsAtLengths2D(v2Left)) {
1696  intersect = MIN2(intersect, cand);
1697  }
1698  //std::cout << " v1=" << v1 << " v2Right=" << v2Right << " v2Left=" << v2Left << "\n";
1699  //std::cout << " intersectsRight=" << toString(v1.intersectsAtLengths2D(v2Right)) << "\n";
1700  //std::cout << " intersectsLeft=" << toString(v1.intersectsAtLengths2D(v2Left)) << "\n";
1701  return intersect;
1702 }
1703 
1704 
1705 bool
1706 NBEdge::bothLeftIntersect(const NBNode& n, const PositionVector& shape, LinkDirection dir, NBEdge* otherFrom, const NBEdge::Connection& otherCon, int numPoints, double width2) const {
1707  if (otherFrom == this) {
1708  // not an opposite pair
1709  return false;
1710  }
1711  LinkDirection dir2 = n.getDirection(otherFrom, otherCon.toEdge);
1712  const bool bothLeft = (dir == LINKDIR_LEFT || dir == LINKDIR_PARTLEFT) && (dir2 == LINKDIR_LEFT || dir2 == LINKDIR_PARTLEFT);
1713  if (bothLeft) {
1714  const PositionVector otherShape = n.computeInternalLaneShape(otherFrom, otherCon, numPoints);
1715  const double minDV = firstIntersection(shape, otherShape, width2);
1716  if (minDV < shape.length() - POSITION_EPS && minDV > POSITION_EPS) {
1717  return true;
1718  } else {
1719  return false;
1720  }
1721  } else {
1722  return false;
1723  }
1724 }
1725 
1726 
1727 // -----------
1728 int
1729 NBEdge::getJunctionPriority(const NBNode* const node) const {
1730  if (node == myFrom) {
1731  return myFromJunctionPriority;
1732  } else {
1733  return myToJunctionPriority;
1734  }
1735 }
1736 
1737 
1738 void
1739 NBEdge::setJunctionPriority(const NBNode* const node, int prio) {
1740  if (node == myFrom) {
1741  myFromJunctionPriority = prio;
1742  } else {
1743  myToJunctionPriority = prio;
1744  }
1745 }
1746 
1747 
1748 double
1749 NBEdge::getAngleAtNode(const NBNode* const atNode) const {
1750  // myStartAngle, myEndAngle are in [0,360] and this returns results in [-180,180]
1751  if (atNode == myFrom) {
1753  } else {
1754  assert(atNode == myTo);
1756  }
1757 }
1758 
1759 
1760 double
1761 NBEdge::getAngleAtNodeToCenter(const NBNode* const atNode) const {
1762  if (atNode == myFrom) {
1763  double res = myStartAngle - 180;
1764  if (res < 0) {
1765  res += 360;
1766  }
1767  return res;
1768  } else {
1769  assert(atNode == myTo);
1770  return myEndAngle;
1771  }
1772 }
1773 
1774 
1775 void
1776 NBEdge::setTurningDestination(NBEdge* e, bool onlyPossible) {
1777  if (!onlyPossible) {
1778  myTurnDestination = e;
1779  }
1781 }
1782 
1783 
1784 double
1785 NBEdge::getLaneSpeed(int lane) const {
1786  return myLanes[lane].speed;
1787 }
1788 
1789 
1790 void
1792  // vissim needs this
1793  if (myFrom == myTo) {
1794  return;
1795  }
1796  // compute lane offset, first
1797  std::vector<double> offsets(myLanes.size(), 0.);
1798  double offset = 0;
1799  for (int i = (int)myLanes.size() - 2; i >= 0; --i) {
1800  offset += (getLaneWidth(i) + getLaneWidth(i + 1)) / 2. + SUMO_const_laneOffset;
1801  offsets[i] = offset;
1802  }
1804  double laneWidth = myLanes.back().width != UNSPECIFIED_WIDTH ? myLanes.back().width : SUMO_const_laneWidth;
1805  offset = (laneWidth + SUMO_const_laneOffset) / 2.; // @note: offset for half of the center-line marking of the road
1806  } else {
1807  double width = 0;
1808  for (int i = 0; i < (int)myLanes.size(); ++i) {
1809  width += getLaneWidth(i);
1810  }
1811  width += SUMO_const_laneOffset * double(myLanes.size() - 1);
1812  offset = -width / 2. + getLaneWidth((int)myLanes.size() - 1) / 2.;
1813  }
1814  for (int i = 0; i < (int)myLanes.size(); ++i) {
1815  offsets[i] += offset;
1816  }
1817 
1818  // build the shape of each lane
1819  for (int i = 0; i < (int)myLanes.size(); ++i) {
1820  if (myLanes[i].customShape.size() != 0) {
1821  myLanes[i].shape = myLanes[i].customShape;
1822  continue;
1823  }
1824  try {
1825  myLanes[i].shape = computeLaneShape(i, offsets[i]);
1826  } catch (InvalidArgument& e) {
1827  WRITE_WARNING("In edge '" + getID() + "': lane shape could not be determined (" + e.what() + ").");
1828  myLanes[i].shape = myGeom;
1829  }
1830  }
1831 }
1832 
1833 
1835 NBEdge::computeLaneShape(int lane, double offset) const {
1836  PositionVector shape = myGeom;
1837  try {
1838  shape.move2side(offset);
1839  } catch (InvalidArgument& e) {
1840  WRITE_WARNING("In lane '" + getLaneID(lane) + "': Could not build shape (" + e.what() + ").");
1841  }
1842  return shape;
1843 }
1844 
1845 
1846 void
1848  // taking the angle at the first might be unstable, thus we take the angle
1849  // at a certain distance. (To compare two edges, additional geometry
1850  // segments are considered to resolve ambiguities)
1851  const bool hasFromShape = myFrom->getShape().size() > 0;
1852  const bool hasToShape = myTo->getShape().size() > 0;
1853  Position fromCenter = (hasFromShape ? myFrom->getShape().getCentroid() : myFrom->getPosition());
1854  Position toCenter = (hasToShape ? myTo->getShape().getCentroid() : myTo->getPosition());
1855  PositionVector shape = myGeom;
1856  if ((hasFromShape || hasToShape) && getNumLanes() > 0) {
1858  shape = myLanes[getNumLanes() - 1].shape ;
1859  } else {
1860  shape = myLanes[getNumLanes() / 2].shape;
1861  if (getNumLanes() % 2 == 0) {
1862  // there is no center lane. shift to get the center
1863  shape.move2side(getLaneWidth(getNumLanes() / 2) * 0.5);
1864  }
1865  }
1866  }
1867 
1868  // if the junction shape is suspicious we cannot trust the angle to the centroid
1869  if (hasFromShape && (myFrom->getShape().distance2D(shape[0]) > 2 * POSITION_EPS
1870  || myFrom->getShape().around(shape[-1])
1871  || !(myFrom->getShape().around(fromCenter)))) {
1872  fromCenter = myFrom->getPosition();
1873  }
1874  if (hasToShape && (myTo->getShape().distance2D(shape[-1]) > 2 * POSITION_EPS
1875  || myTo->getShape().around(shape[0])
1876  || !(myTo->getShape().around(toCenter)))) {
1877  toCenter = myTo->getPosition();
1878  }
1879 
1880  const double angleLookahead = MIN2(shape.length2D() / 2, ANGLE_LOOKAHEAD);
1881  const Position referencePosStart = shape.positionAtOffset2D(angleLookahead);
1882  myStartAngle = GeomHelper::legacyDegree(fromCenter.angleTo2D(referencePosStart), true);
1883  const Position referencePosEnd = shape.positionAtOffset2D(shape.length() - angleLookahead);
1884  myEndAngle = GeomHelper::legacyDegree(referencePosEnd.angleTo2D(toCenter), true);
1886 #ifdef DEBUG_ANGLES
1887  if (DEBUGCOND) std::cout << "computeAngle edge=" << getID() << " fromCenter=" << fromCenter << " toCenter=" << toCenter
1888  << " refStart=" << referencePosStart << " refEnd=" << referencePosEnd << " shape=" << shape
1889  << " hasFromShape=" << hasFromShape
1890  << " hasToShape=" << hasToShape
1891  << " numLanes=" << getNumLanes()
1892  << " shapeLane=" << getNumLanes() / 2
1893  << " startA=" << myStartAngle << " endA=" << myEndAngle << " totA=" << myTotalAngle << "\n";
1894 #endif
1895 }
1896 
1897 
1898 double
1900  const double angleLookahead = MIN2(myGeom.length2D() / 2, ANGLE_LOOKAHEAD);
1901  const Position referencePosStart = myGeom.positionAtOffset2D(angleLookahead);
1902  return GeomHelper::legacyDegree(myGeom.front().angleTo2D(referencePosStart), true);
1903 }
1904 
1905 
1906 double
1908  const double angleLookahead = MIN2(myGeom.length2D() / 2, ANGLE_LOOKAHEAD);
1909  const Position referencePosEnd = myGeom.positionAtOffset2D(myGeom.length() - angleLookahead);
1910  return GeomHelper::legacyDegree(referencePosEnd.angleTo2D(myGeom.back()), true);
1911 }
1912 
1913 
1914 bool
1916  for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
1917  if ((*i).permissions != SVCAll) {
1918  return true;
1919  }
1920  }
1921  return false;
1922 }
1923 
1924 
1925 bool
1927  std::vector<Lane>::const_iterator i = myLanes.begin();
1928  SVCPermissions firstLanePermissions = i->permissions;
1929  i++;
1930  for (; i != myLanes.end(); ++i) {
1931  if (i->permissions != firstLanePermissions) {
1932  return true;
1933  }
1934  }
1935  return false;
1936 }
1937 
1938 
1939 bool
1941  for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
1942  if (i->speed != getSpeed()) {
1943  return true;
1944  }
1945  }
1946  return false;
1947 }
1948 
1949 
1950 bool
1952  for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
1953  if (i->width != myLanes.begin()->width) {
1954  return true;
1955  }
1956  }
1957  return false;
1958 }
1959 
1960 
1961 bool
1963  for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
1964  if (i->endOffset != myLanes.begin()->endOffset) {
1965  return true;
1966  }
1967  }
1968  return false;
1969 }
1970 
1971 
1972 bool
1974  for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
1975  if (!i->stopOffsets.empty()) {
1976  const std::pair<const int, double>& offsets = *(i->stopOffsets.begin());
1977  if (myStopOffsets.empty() || offsets != *(myStopOffsets.begin())) {
1978  return true;
1979  }
1980  }
1981  }
1982  return false;
1983 }
1984 
1985 
1986 bool
1988  for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
1989  if (i->accelRamp) {
1990  return true;
1991  }
1992  }
1993  return false;
1994 }
1995 
1996 
1997 bool
1999  for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
2000  if (i->customShape.size() > 0) {
2001  return true;
2002  }
2003  }
2004  return false;
2005 }
2006 
2007 
2008 bool
2010  for (std::vector<Lane>::const_iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
2011  if (i->getParametersMap().size() > 0) {
2012  return true;
2013  }
2014  }
2015  return false;
2016 }
2017 
2018 bool
2020  return (hasLaneSpecificPermissions()
2025  || hasAccelLane()
2026  || hasCustomLaneShape()
2027  || hasLaneParams()
2028  || (!myLanes.empty() && myLanes.back().oppositeID != ""));
2029 }
2030 
2031 
2032 
2033 bool
2034 NBEdge::computeEdge2Edges(bool noLeftMovers) {
2035  // return if this relationship has been build in previous steps or
2036  // during the import
2037  if (myStep >= EDGE2EDGES) {
2038  return true;
2039  }
2040  const EdgeVector& o = myTo->getOutgoingEdges();
2041  const bool fromRail = isRailway(getPermissions());
2042  for (EdgeVector::const_iterator i = o.begin(); i != o.end(); ++i) {
2043  if (noLeftMovers && myTo->isLeftMover(this, *i)) {
2044  continue;
2045  }
2046  // avoid sharp railway turns
2047  if (fromRail && isRailway((*i)->getPermissions()) &&
2048  fabs(NBHelpers::normRelAngle(getAngleAtNode(myTo), (*i)->getAngleAtNode(myTo))) > 90) {
2049  continue;
2050  };
2051  myConnections.push_back(Connection(-1, *i, -1));
2052  }
2053  myStep = EDGE2EDGES;
2054  return true;
2055 }
2056 
2057 
2058 bool
2060  // return if this relationship has been build in previous steps or
2061  // during the import
2062  if (myStep >= LANES2EDGES) {
2063  return true;
2064  }
2065  assert(myStep == EDGE2EDGES);
2066  // get list of possible outgoing edges sorted by direction clockwise
2067  // the edge in the backward direction (turnaround) is not in the list
2068  const EdgeVector* edges = getConnectedSorted();
2069  if (myConnections.size() != 0 && edges->size() == 0) {
2070  // dead end per definition!?
2071  myConnections.clear();
2072  } else {
2073  // divide the lanes on reachable edges
2074  divideOnEdges(edges);
2075  }
2076  delete edges;
2077  myStep = LANES2EDGES;
2078  return true;
2079 }
2080 
2081 
2082 bool
2084 #ifdef DEBUG_CONNECTION_GUESSING
2085  if (DEBUGCOND) {
2086  std::cout << "recheckLanes (initial) edge=" << getID() << "\n";
2087  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
2088  std::cout << " conn " << getID() << "_" << (*i).fromLane << " to " << Named::getIDSecure((*i).toEdge) << "_" << (*i).toLane << "\n";
2089  (*i).shape.mirrorX();
2090  (*i).viaShape.mirrorX();
2091  }
2092  }
2093 #endif
2094  std::vector<int> connNumbersPerLane(myLanes.size(), 0);
2095  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end();) {
2096  if ((*i).toEdge == 0 || (*i).fromLane < 0 || (*i).toLane < 0) {
2097  i = myConnections.erase(i);
2098  } else {
2099  if ((*i).fromLane >= 0) {
2100  ++connNumbersPerLane[(*i).fromLane];
2101  }
2102  ++i;
2103  }
2104  }
2106  // check #1:
2107  // If there is a lane with no connections and any neighbour lane has
2108  // more than one connections, try to move one of them.
2109  // This check is only done for edges which connections were assigned
2110  // using the standard algorithm.
2111  for (int i = 0; i < (int)myLanes.size(); i++) {
2112  if (connNumbersPerLane[i] == 0 && !isForbidden(getPermissions((int)i))) {
2113  if (i > 0 && connNumbersPerLane[i - 1] > 1 && getPermissions(i) == getPermissions(i - 1)) {
2114  moveConnectionToLeft(i - 1);
2115  } else if (i < (int)myLanes.size() - 1 && connNumbersPerLane[i + 1] > 1 && getPermissions(i) == getPermissions(i + 1)) {
2116  moveConnectionToRight(i + 1);
2117  }
2118  }
2119  }
2120  // check restrictions
2121  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end();) {
2122  Connection& c = *i;
2124  if (common == SVC_PEDESTRIAN || getPermissions(c.fromLane) == SVC_PEDESTRIAN) {
2125  // these are computed in NBNode::buildWalkingAreas
2126  i = myConnections.erase(i);
2127  } else if (common == 0) {
2128  // no common permissions.
2129  // try to find a suitable target lane to the right
2130  const int origToLane = c.toLane;
2131  c.toLane = -1; // ignore this connection when calling hasConnectionTo
2132  int toLane = origToLane;
2133  while (toLane > 0
2134  && (getPermissions(c.fromLane) & c.toEdge->getPermissions(toLane)) == 0
2135  && !hasConnectionTo(c.toEdge, toLane)
2136  ) {
2137  toLane--;
2138  }
2139  if ((getPermissions(c.fromLane) & c.toEdge->getPermissions(toLane)) != 0
2140  && !hasConnectionTo(c.toEdge, toLane)) {
2141  c.toLane = toLane;
2142  ++i;
2143  } else {
2144  // try to find a suitable target lane to the left
2145  int toLane = origToLane;
2146  while (toLane < (int)c.toEdge->getNumLanes() - 1
2147  && (getPermissions(c.fromLane) & c.toEdge->getPermissions(toLane)) == 0
2148  && !hasConnectionTo(c.toEdge, toLane)
2149  ) {
2150  toLane++;
2151  }
2152  if ((getPermissions(c.fromLane) & c.toEdge->getPermissions(toLane)) != 0
2153  && !hasConnectionTo(c.toEdge, toLane)) {
2154  c.toLane = toLane;
2155  ++i;
2156  } else {
2157  // no alternative target found
2158  i = myConnections.erase(i);
2159  }
2160  }
2162  && isTurningDirectionAt(c.toEdge)) {
2163  // do not allow sharp rail turns
2164  i = myConnections.erase(i);
2165  } else {
2166  ++i;
2167  }
2168  }
2169  }
2170  // check delayed removals
2171  for (std::vector<Connection>::iterator it = myConnectionsToDelete.begin(); it != myConnectionsToDelete.end(); ++it) {
2172  removeFromConnections(it->toEdge, it->fromLane, it->toLane);
2173  }
2174  // check involuntary dead end at "real" junctions
2175  if (getPermissions() != SVC_PEDESTRIAN) {
2176  if (myConnections.empty() && myTo->getOutgoingEdges().size() > 1) {
2177  WRITE_WARNING("Edge '" + getID() + "' is not connected to outgoing edges at junction '" + myTo->getID() + "'.");
2178  }
2179  const EdgeVector& incoming = myFrom->getIncomingEdges();
2180  if (incoming.size() > 1) {
2181  for (int i = 0; i < (int)myLanes.size(); i++) {
2182  if (getPermissions(i) != 0 && getPermissions(i) != SVC_PEDESTRIAN) {
2183  bool connected = false;
2184  for (std::vector<NBEdge*>::const_iterator in = incoming.begin(); in != incoming.end(); ++in) {
2185  if ((*in)->hasConnectionTo(this, i)) {
2186  connected = true;
2187  break;
2188  }
2189  }
2190  if (!connected) {
2191  WRITE_WARNING("Lane '" + getID() + "_" + toString(i) + "' is not connected from any incoming edge at junction '" + myFrom->getID() + "'.");
2192  }
2193  }
2194  }
2195  }
2196  }
2197 #ifdef DEBUG_CONNECTION_GUESSING
2198  if (DEBUGCOND) {
2199  std::cout << "recheckLanes (final) edge=" << getID() << "\n";
2200  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
2201  std::cout << " conn " << getID() << "_" << (*i).fromLane << " to " << Named::getIDSecure((*i).toEdge) << "_" << (*i).toLane << "\n";
2202  (*i).shape.mirrorX();
2203  (*i).viaShape.mirrorX();
2204  }
2205  }
2206 #endif
2207  return true;
2208 }
2209 
2210 
2211 void
2213  if (outgoing->size() == 0) {
2214  // we have to do this, because the turnaround may have been added before
2215  myConnections.clear();
2216  return;
2217  }
2218  // precompute edge priorities; needed as some kind of assumptions for
2219  // priorities of directions (see preparePriorities)
2220  std::vector<int>* priorities = prepareEdgePriorities(outgoing);
2221  // compute the indices of lanes that should have connections (excluding
2222  // forbidden lanes and pedestrian lanes that will be connected via walkingAreas)
2223 
2224 
2225 #ifdef DEBUG_CONNECTION_GUESSING
2226  if (DEBUGCOND) {
2227  std::cout << " divideOnEdges " << getID() << " outgoing=" << toString(*outgoing) << " prios=" << toString(*priorities) << "\n";
2228  }
2229 #endif
2230 
2231  // build connections for miv lanes
2232  std::vector<int> availableLanes;
2233  for (int i = 0; i < (int)myLanes.size(); ++i) {
2234  if ((getPermissions(i) & SVC_PASSENGER) != 0) {
2235  availableLanes.push_back(i);
2236  }
2237  }
2238  if (availableLanes.size() > 0) {
2239  divideSelectedLanesOnEdges(outgoing, availableLanes, priorities);
2240  }
2241  // build connections for miscellaneous further modes (more than bike,peds,bus and without passenger)
2242  availableLanes.clear();
2243  for (int i = 0; i < (int)myLanes.size(); ++i) {
2244  const SVCPermissions perms = getPermissions(i);
2245  if ((perms & ~(SVC_PEDESTRIAN | SVC_BICYCLE | SVC_BUS)) == 0 || (perms & SVC_PASSENGER) != 0 || isForbidden(perms)) {
2246  continue;
2247  }
2248  availableLanes.push_back(i);
2249  }
2250  if (availableLanes.size() > 0) {
2251  divideSelectedLanesOnEdges(outgoing, availableLanes, priorities);
2252  }
2253  // build connections for busses (possibly combined with bicycles)
2254  availableLanes.clear();
2255  for (int i = 0; i < (int)myLanes.size(); ++i) {
2256  const SVCPermissions perms = getPermissions(i);
2257  if (perms != SVC_BUS && perms != (SVC_BUS | SVC_BICYCLE)) {
2258  continue;
2259  }
2260  availableLanes.push_back(i);
2261  }
2262  if (availableLanes.size() > 0) {
2263  divideSelectedLanesOnEdges(outgoing, availableLanes, priorities);
2264  }
2265  // build connections for bicycles (possibly combined with pedestrians)
2266  availableLanes.clear();
2267  for (int i = 0; i < (int)myLanes.size(); ++i) {
2268  const SVCPermissions perms = getPermissions(i);
2269  if (perms != SVC_BICYCLE && perms != (SVC_BICYCLE | SVC_PEDESTRIAN)) {
2270  continue;
2271  }
2272  availableLanes.push_back(i);
2273  }
2274  if (availableLanes.size() > 0) {
2275  divideSelectedLanesOnEdges(outgoing, availableLanes, priorities);
2276  }
2277  // clean up unassigned fromLanes
2278  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end();) {
2279  if ((*i).fromLane == -1) {
2280  i = myConnections.erase(i);
2281  } else {
2282  ++i;
2283  }
2284  }
2286 
2287  delete priorities;
2288 }
2289 
2290 
2291 void
2292 NBEdge::divideSelectedLanesOnEdges(const EdgeVector* outgoing, const std::vector<int>& availableLanes, const std::vector<int>* priorities) {
2293  //std::cout << "divideSelectedLanesOnEdges " << getID() << " out=" << toString(*outgoing) << " prios=" << toString(*priorities) << " avail=" << toString(availableLanes) << "\n";
2294  // compute the sum of priorities (needed for normalisation)
2295  int prioSum = computePrioritySum(*priorities);
2296  // compute the resulting number of lanes that should be used to
2297  // reach the following edge
2298  const int numOutgoing = (int) outgoing->size();
2299  std::vector<double> resultingLanes;
2300  resultingLanes.reserve(numOutgoing);
2301  double sumResulting = 0.; // the sum of resulting lanes
2302  double minResulting = 10000.; // the least number of lanes to reach an edge
2303  for (int i = 0; i < numOutgoing; i++) {
2304  // res will be the number of lanes which are meant to reach the
2305  // current outgoing edge
2306  double res =
2307  (double)(*priorities)[i] *
2308  (double) availableLanes.size() / (double) prioSum;
2309  // do not let this number be greater than the number of available lanes
2310  if (res > availableLanes.size()) {
2311  res = (double) availableLanes.size();
2312  }
2313  // add it to the list
2314  resultingLanes.push_back(res);
2315  sumResulting += res;
2316  if (minResulting > res && res > 0) {
2317  // prevent minResulting from becoming 0
2318  minResulting = res;
2319  }
2320  }
2321  // compute the number of virtual edges
2322  // a virtual edge is used as a replacement for a real edge from now on
2323  // it shall allow to divide the existing lanes on this structure without
2324  // regarding the structure of outgoing edges
2325  int numVirtual = 0;
2326  // compute the transition from virtual to real edges
2327  EdgeVector transition;
2328  transition.reserve(numOutgoing);
2329  for (int i = 0; i < numOutgoing; i++) {
2330  // tmpNo will be the number of connections from this edge
2331  // to the next edge
2332  assert(i < (int)resultingLanes.size());
2333  const int tmpNum = (int)std::ceil(resultingLanes[i] / minResulting);
2334  numVirtual += tmpNum;
2335  for (double j = 0; j < tmpNum; j++) {
2336  transition.push_back((*outgoing)[i]);
2337  }
2338  }
2339 #ifdef DEBUG_CONNECTION_GUESSING
2340  if (DEBUGCOND) {
2341  std::cout << " prioSum=" << prioSum << " sumResulting=" << sumResulting << " minResulting=" << minResulting << " numVirtual=" << numVirtual << " availLanes=" << toString(availableLanes) << " resLanes=" << toString(resultingLanes) << " transition=" << toString(transition) << "\n";
2342  }
2343 #endif
2344 
2345  // assign lanes to edges
2346  // (conversion from virtual to real edges is done)
2347  ToEdgeConnectionsAdder adder(transition);
2348  Bresenham::compute(&adder, static_cast<int>(availableLanes.size()), numVirtual);
2349  const std::map<NBEdge*, std::vector<int> >& l2eConns = adder.getBuiltConnections();
2350  for (EdgeVector::const_iterator i = outgoing->begin(); i != outgoing->end(); ++i) {
2351  NBEdge* target = (*i);
2352  assert(l2eConns.find(target) != l2eConns.end());
2353  const std::vector<int> lanes = (l2eConns.find(target))->second;
2354  for (std::vector<int>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
2355  const int fromIndex = availableLanes[*j];
2356  if ((getPermissions(fromIndex) & target->getPermissions()) == 0) {
2357  // exclude connection if fromLane and toEdge have no common permissions
2358  continue;
2359  }
2360  if ((getPermissions(fromIndex) & target->getPermissions()) == SVC_PEDESTRIAN) {
2361  // exclude connection if the only commonly permitted class are pedestrians
2362  // these connections are later built in NBNode::buildWalkingAreas
2363  continue;
2364  }
2365  // avoid building more connections than the edge has viable lanes (earlier
2366  // ones have precedence). This is necessary when running divideSelectedLanesOnEdges more than once.
2367  // @todo To decide which target lanes are still available we need to do a
2368  // preliminary lane-to-lane assignment in regard to permissions (rather than to ordering)
2369  const int numConsToTarget = (int)count_if(myConnections.begin(), myConnections.end(), connections_toedge_finder(target, true));
2370  int targetLanes = (int)target->getNumLanes();
2371  if (target->getPermissions(0) == SVC_PEDESTRIAN) {
2372  --targetLanes;
2373  }
2374  if (numConsToTarget >= targetLanes) {
2375  // let bicycles move onto the road to allow continuation
2376  // the speed limit is taken from rural roads (which allow cycles)
2377  // (pending implementation of #1859)
2378  if (getPermissions(fromIndex) == SVC_BICYCLE && getSpeed() <= (101 / 3.6)) {
2379  for (int ii = 0; ii < (int)myLanes.size(); ++ii) {
2380  if (myLanes[ii].permissions != SVC_PEDESTRIAN) {
2381  myLanes[ii].permissions |= SVC_BICYCLE;
2382  }
2383  }
2384  }
2385  continue;
2386  }
2387  if (myLanes[fromIndex].connectionsDone) {
2388  // we already have complete information about connections from
2389  // this lane. do not add anything else
2390  continue;
2391  }
2392  myConnections.push_back(Connection(fromIndex, target, -1));
2393 #ifdef DEBUG_CONNECTION_GUESSING
2394  if (DEBUGCOND) {
2395  std::cout << " request connection from " << getID() << "_" << fromIndex << " to " << target->getID() << "\n";
2396  }
2397 #endif
2398  }
2399  }
2400 
2401  addStraightConnections(outgoing, availableLanes, priorities);
2402 }
2403 
2404 
2405 void
2406 NBEdge::addStraightConnections(const EdgeVector* outgoing, const std::vector<int>& availableLanes, const std::vector<int>* priorities) {
2407  // ensure sufficient straight connections for the (hightest-priority straight target)
2408  const int numOutgoing = (int) outgoing->size();
2409  NBEdge* target = 0;
2410  NBEdge* rightOfTarget = 0;
2411  NBEdge* leftOfTarget = 0;
2412  int maxPrio = 0;
2413  for (int i = 0; i < numOutgoing; i++) {
2414  if (maxPrio < (*priorities)[i]) {
2415  const LinkDirection dir = myTo->getDirection(this, (*outgoing)[i]);
2416  if (dir == LINKDIR_STRAIGHT) {
2417  maxPrio = (*priorities)[i];
2418  target = (*outgoing)[i];
2419  rightOfTarget = i == 0 ? outgoing->back() : (*outgoing)[i - 1];
2420  leftOfTarget = i + 1 == numOutgoing ? outgoing->front() : (*outgoing)[i + 1];
2421  }
2422  }
2423  }
2424  if (target == 0) {
2425  return;
2426  }
2427  int numConsToTarget = (int)count_if(myConnections.begin(), myConnections.end(), connections_toedge_finder(target, true));
2428  int targetLanes = (int)target->getNumLanes();
2429  if (target->getPermissions(0) == SVC_PEDESTRIAN) {
2430  --targetLanes;
2431  }
2432  const int numDesiredConsToTarget = MIN2(targetLanes, (int)availableLanes.size());
2433 #ifdef DEBUG_CONNECTION_GUESSING
2434  if (DEBUGCOND) {
2435  std::cout << " checking extra lanes for target=" << target->getID() << " cons=" << numConsToTarget << " desired=" << numDesiredConsToTarget << "\n";
2436  }
2437 #endif
2438  std::vector<int>::const_iterator it_avail = availableLanes.begin();
2439  while (numConsToTarget < numDesiredConsToTarget && it_avail != availableLanes.end()) {
2440  const int fromIndex = *it_avail;
2441  if (
2442  // not yet connected
2443  (count_if(myConnections.begin(), myConnections.end(), connections_finder(fromIndex, target, -1)) == 0)
2444  // matching permissions
2445  && ((getPermissions(fromIndex) & target->getPermissions()) != 0)
2446  // more than pedestrians
2447  && ((getPermissions(fromIndex) & target->getPermissions()) != SVC_PEDESTRIAN)
2448  // lane not yet fully defined
2449  && !myLanes[fromIndex].connectionsDone
2450  ) {
2451 #ifdef DEBUG_CONNECTION_GUESSING
2452  if (DEBUGCOND) {
2453  std::cout << " candidate from " << getID() << "_" << fromIndex << " to " << target->getID() << "\n";
2454  }
2455 #endif
2456  // prevent same-edge conflicts
2457  if (
2458  // no outgoing connections to the right from further left
2459  ((it_avail + 1) == availableLanes.end() || count_if(myConnections.begin(), myConnections.end(), connections_conflict_finder(fromIndex, rightOfTarget, false)) == 0)
2460  // no outgoing connections to the left from further right
2461  && (it_avail == availableLanes.begin() || count_if(myConnections.begin(), myConnections.end(), connections_conflict_finder(fromIndex, leftOfTarget, true)) == 0)) {
2462 #ifdef DEBUG_CONNECTION_GUESSING
2463  if (DEBUGCOND) {
2464  std::cout << " request additional connection from " << getID() << "_" << fromIndex << " to " << target->getID() << "\n";
2465  }
2466 #endif
2467  myConnections.push_back(Connection(fromIndex, target, -1));
2468  numConsToTarget++;
2469  } else {
2470 #ifdef DEBUG_CONNECTION_GUESSING
2471  if (DEBUGCOND) std::cout
2472  << " fail check1="
2473  << ((it_avail + 1) == availableLanes.end() || count_if(myConnections.begin(), myConnections.end(), connections_conflict_finder(fromIndex, rightOfTarget, false)) == 0)
2474  << " check2=" << (it_avail == availableLanes.begin() || count_if(myConnections.begin(), myConnections.end(), connections_conflict_finder(fromIndex, leftOfTarget, true)) == 0)
2475  << " rightOfTarget=" << rightOfTarget->getID()
2476  << " leftOfTarget=" << leftOfTarget->getID()
2477  << "\n";
2478 #endif
2479 
2480  }
2481  }
2482  ++it_avail;
2483  }
2484 }
2485 
2486 
2487 std::vector<int>*
2489  // copy the priorities first
2490  std::vector<int>* priorities = new std::vector<int>();
2491  if (outgoing->size() == 0) {
2492  return priorities;
2493  }
2494  priorities->reserve(outgoing->size());
2495  EdgeVector::const_iterator i;
2496  for (i = outgoing->begin(); i != outgoing->end(); i++) {
2497  //int prio = (*i)->getJunctionPriority(myTo);
2498  int prio = NBNode::isTrafficLight(myTo->getType()) ? 0 : (*i)->getJunctionPriority(myTo);
2499  assert((prio + 1) * 2 > 0);
2500  prio = (prio + 1) * 2;
2501  priorities->push_back(prio);
2502  }
2503  // when the right turning direction has not a higher priority, divide
2504  // the importance by 2 due to the possibility to leave the junction
2505  // faster from this lane
2506  EdgeVector tmp(*outgoing);
2507  sort(tmp.begin(), tmp.end(), NBContHelper::straightness_sorter(myTo, this));
2508  i = find(outgoing->begin(), outgoing->end(), *(tmp.begin()));
2509  int dist = (int) distance(outgoing->begin(), i);
2510  MainDirections mainDirections(*outgoing, this, myTo, dist);
2511 #ifdef DEBUG_CONNECTION_GUESSING
2512  if (DEBUGCOND) std::cout << " prepareEdgePriorities " << getID()
2513  << " outgoing=" << toString(*outgoing)
2514  << " priorities1=" << toString(*priorities)
2515  << " tmp=" << toString(tmp)
2516  << " mainDirs=" << toString(mainDirections.myDirs)
2517  << " dist=" << dist
2518  << "\n";
2519 #endif
2520  if (dist != 0 && !mainDirections.includes(MainDirections::DIR_RIGHTMOST)) {
2521  assert(priorities->size() > 0);
2522  (*priorities)[0] /= 2;
2523 #ifdef DEBUG_CONNECTION_GUESSING
2524  if (DEBUGCOND) {
2525  std::cout << " priorities2=" << toString(*priorities) << "\n";
2526  }
2527 #endif
2528  }
2529  // HEURISTIC:
2530  // when no higher priority exists, let the forward direction be
2531  // the main direction
2532  if (mainDirections.empty()) {
2533  assert(dist < (int)priorities->size());
2534  (*priorities)[dist] *= 2;
2535 #ifdef DEBUG_CONNECTION_GUESSING
2536  if (DEBUGCOND) {
2537  std::cout << " priorities3=" << toString(*priorities) << "\n";
2538  }
2539 #endif
2540  }
2542  (*priorities)[dist] += 1;
2543  } else {
2544  // try to ensure separation of left turns
2545  if (mainDirections.includes(MainDirections::DIR_RIGHTMOST) && mainDirections.includes(MainDirections::DIR_LEFTMOST)) {
2546  (*priorities)[0] /= 4;
2547  (*priorities)[(int)priorities->size() - 1] /= 2;
2548 #ifdef DEBUG_CONNECTION_GUESSING
2549  if (DEBUGCOND) {
2550  std::cout << " priorities6=" << toString(*priorities) << "\n";
2551  }
2552 #endif
2553  }
2554  }
2555  if (mainDirections.includes(MainDirections::DIR_FORWARD)) {
2556  if (myLanes.size() > 2) {
2557  (*priorities)[dist] *= 2;
2558 #ifdef DEBUG_CONNECTION_GUESSING
2559  if (DEBUGCOND) {
2560  std::cout << " priorities4=" << toString(*priorities) << "\n";
2561  }
2562 #endif
2563  } else {
2564  (*priorities)[dist] *= 3;
2565 #ifdef DEBUG_CONNECTION_GUESSING
2566  if (DEBUGCOND) {
2567  std::cout << " priorities5=" << toString(*priorities) << "\n";
2568  }
2569 #endif
2570  }
2571  }
2572  // return
2573  return priorities;
2574 }
2575 
2576 
2577 int
2578 NBEdge::computePrioritySum(const std::vector<int>& priorities) {
2579  int sum = 0;
2580  for (std::vector<int>::const_iterator i = priorities.begin(); i != priorities.end(); i++) {
2581  sum += *i;
2582  }
2583  return sum;
2584 }
2585 
2586 
2587 void
2588 NBEdge::appendTurnaround(bool noTLSControlled, bool onlyDeadends, bool checkPermissions) {
2589  // do nothing if no turnaround is known
2591  return;
2592  }
2593  // do nothing if the destination node is controlled by a tls and no turnarounds
2594  // shall be appended for such junctions
2595  if (noTLSControlled && myTo->isTLControlled()) {
2596  return;
2597  }
2598  if (onlyDeadends && myTo->getOutgoingEdges().size() > 1) {
2599  return;
2600  }
2601  const int fromLane = (int)myLanes.size() - 1;
2602  const int toLane = (int)myTurnDestination->getNumLanes() - 1;
2603  if (checkPermissions) {
2604  if ((getPermissions(fromLane) & myTurnDestination->getPermissions(toLane)) == 0) {
2605  // exclude connection if fromLane and toEdge have no common permissions
2606  return;
2607  }
2608  if ((getPermissions(fromLane) & myTurnDestination->getPermissions(toLane)) == SVC_PEDESTRIAN) {
2609  // exclude connection if the only commonly permitted class are pedestrians
2610  // these connections are later built in NBNode::buildWalkingAreas
2611  return;
2612  }
2613  }
2614  // avoid railway turn-arounds
2617  // except at dead-ends on bidi-edges where they model a reversal in train direction
2618  // @todo #4382: once the network fringe is tagged, it also should not receive turn-arounds)
2619  if (isBidiRail() && isRailDeadEnd()) {
2620  // add a slow connection because direction-reversal implies stopping
2622  return;
2623  } else {
2624  return;
2625  }
2626  };
2627  setConnection(fromLane, myTurnDestination, toLane, L2L_VALIDATED);
2628 }
2629 
2630 
2631 bool
2632 NBEdge::isTurningDirectionAt(const NBEdge* const edge) const {
2633  // maybe it was already set as the turning direction
2634  if (edge == myTurnDestination) {
2635  return true;
2636  } else if (myTurnDestination != 0) {
2637  // otherwise - it's not if a turning direction exists
2638  return false;
2639  }
2640  return edge == myPossibleTurnDestination;
2641 }
2642 
2643 
2644 NBNode*
2645 NBEdge::tryGetNodeAtPosition(double pos, double tolerance) const {
2646  // return the from-node when the position is at the begin of the edge
2647  if (pos < tolerance) {
2648  return myFrom;
2649  }
2650  // return the to-node when the position is at the end of the edge
2651  if (pos > myLength - tolerance) {
2652  return myTo;
2653  }
2654  return 0;
2655 }
2656 
2657 
2658 void
2660  int lanes = e->getNumLanes();
2661  for (int i = 0; i < lanes; i++) {
2662  std::vector<NBEdge::Connection> elv = e->getConnectionsFromLane(i);
2663  for (std::vector<NBEdge::Connection>::iterator j = elv.begin(); j != elv.end(); j++) {
2664  NBEdge::Connection el = *j;
2665  assert(el.tlID == "");
2666  addLane2LaneConnection(i + laneOff, el.toEdge, el.toLane, L2L_COMPUTED);
2667  }
2668  }
2669 }
2670 
2671 
2672 bool
2675 }
2676 
2677 
2678 double
2680  return (double) SUMO_const_laneWidthAndOffset * myLanes.size();
2681 }
2682 
2683 
2684 bool
2685 NBEdge::mayBeTLSControlled(int fromLane, NBEdge* toEdge, int toLane) const {
2687  tpl.fromLane = fromLane;
2688  tpl.to = toEdge;
2689  tpl.toLane = toLane;
2690  std::vector<TLSDisabledConnection>::const_iterator i = find_if(myTLSDisabledConnections.begin(), myTLSDisabledConnections.end(), tls_disable_finder(tpl));
2691  return i == myTLSDisabledConnections.end();
2692 }
2693 
2694 
2695 bool
2696 NBEdge::setControllingTLInformation(const NBConnection& c, const std::string& tlID) {
2697  const int fromLane = c.getFromLane();
2698  NBEdge* toEdge = c.getTo();
2699  const int toLane = c.getToLane();
2700  const int tlIndex = c.getTLIndex();
2701  // check whether the connection was not set as not to be controled previously
2703  tpl.fromLane = fromLane;
2704  tpl.to = toEdge;
2705  tpl.toLane = toLane;
2706  std::vector<TLSDisabledConnection>::iterator i = find_if(myTLSDisabledConnections.begin(), myTLSDisabledConnections.end(), tls_disable_finder(tpl));
2707  if (i != myTLSDisabledConnections.end()) {
2708  return false;
2709  }
2710 
2711  assert(fromLane < 0 || fromLane < (int) myLanes.size());
2712  // try to use information about the connections if given
2713  if (fromLane >= 0 && toLane >= 0) {
2714  // find the specified connection
2715  std::vector<Connection>::iterator i =
2716  find_if(myConnections.begin(), myConnections.end(), connections_finder(fromLane, toEdge, toLane));
2717  // ok, we have to test this as on the removal of self-loop edges some connections
2718  // will be reassigned
2719  if (i != myConnections.end()) {
2720  // get the connection
2721  Connection& connection = *i;
2722  // set the information about the tl
2723  connection.tlID = tlID;
2724  connection.tlLinkIndex = tlIndex;
2725  return true;
2726  }
2727  }
2728  // if the original connection was not found, set the information for all
2729  // connections
2730  int no = 0;
2731  bool hadError = false;
2732  for (std::vector<Connection>::iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
2733  if ((*i).toEdge != toEdge) {
2734  continue;
2735  }
2736  if (fromLane >= 0 && fromLane != (*i).fromLane) {
2737  continue;
2738  }
2739  if (toLane >= 0 && toLane != (*i).toLane) {
2740  continue;
2741  }
2742  if ((*i).tlID == "") {
2743  (*i).tlID = tlID;
2744  (*i).tlLinkIndex = tlIndex;
2745  no++;
2746  } else {
2747  if ((*i).tlID != tlID && (*i).tlLinkIndex == tlIndex) {
2748  WRITE_WARNING("The lane '" + toString<int>((*i).fromLane) + "' on edge '" + getID() + "' already had a traffic light signal.");
2749  hadError = true;
2750  }
2751  }
2752  }
2753  if (hadError && no == 0) {
2754  WRITE_WARNING("Could not set any signal of the tlLogic '" + tlID + "' (unknown group)");
2755  }
2756  return true;
2757 }
2758 
2759 
2760 void
2762  for (std::vector<Connection>::iterator it = myConnections.begin(); it != myConnections.end(); it++) {
2763  it->tlID = "";
2764  }
2765 }
2766 
2767 
2768 void
2769 NBEdge::disableConnection4TLS(int fromLane, NBEdge* toEdge, int toLane) {
2771  c.fromLane = fromLane;
2772  c.to = toEdge;
2773  c.toLane = toLane;
2774  myTLSDisabledConnections.push_back(c);
2775 }
2776 
2777 
2780  PositionVector ret;
2781  double width;
2782  int lane;
2783  if (myFrom == (&n)) {
2784  // outgoing
2786  ret = myLanes[lane].shape;
2787  } else {
2788  // incoming
2790  ret = myLanes[lane].shape.reverse();
2791  }
2792  width = getLaneWidth(lane);
2793  ret.move2side(width * 0.5);
2794  return ret;
2795 }
2796 
2797 
2800  PositionVector ret;
2801  double width;
2802  int lane;
2803  if (myFrom == (&n)) {
2804  // outgoing
2806  ret = myLanes[lane].shape;
2807  } else {
2808  // incoming
2810  ret = myLanes[lane].shape.reverse();
2811  }
2812  width = getLaneWidth(lane);
2813  ret.move2side(-width * 0.5);
2814  return ret;
2815 }
2816 
2817 
2818 bool
2819 NBEdge::expandableBy(NBEdge* possContinuation, std::string& reason) const {
2820  // ok, the number of lanes must match
2821  if (myLanes.size() != possContinuation->myLanes.size()) {
2822  reason = "laneNumber";
2823  return false;
2824  }
2825  // the priority, too (?)
2826  if (getPriority() != possContinuation->getPriority()) {
2827  reason = "priority";
2828  return false;
2829  }
2830  // the speed allowed
2831  if (mySpeed != possContinuation->mySpeed) {
2832  reason = "speed";
2833  return false;
2834  }
2835  // spreadtype should match or it will look ugly
2836  if (myLaneSpreadFunction != possContinuation->myLaneSpreadFunction) {
2837  reason = "spreadType";
2838  return false;
2839  }
2840  // do not create self loops
2841  if (myFrom == possContinuation->myTo) {
2842  reason = "loop";
2843  return false;
2844  }
2845  // matching lanes must have identical properties
2846  for (int i = 0; i < (int)myLanes.size(); i++) {
2847  if (myLanes[i].speed != possContinuation->myLanes[i].speed) {
2848  reason = "lane " + toString(i) + " speed";
2849  return false;
2850  } else if (myLanes[i].permissions != possContinuation->myLanes[i].permissions) {
2851  reason = "lane " + toString(i) + " permissions";
2852  return false;
2853  } else if (myLanes[i].width != possContinuation->myLanes[i].width) {
2854  reason = "lane " + toString(i) + " width";
2855  return false;
2856  }
2857  }
2858  // conserve bidi-rails
2859  if (isBidiRail() != possContinuation->isBidiRail()) {
2860  reason = "bidi-rail";
2861  return false;
2862  }
2863 
2864  // the vehicle class constraints, too
2872  // also, check whether the connections - if any exit do allow to join
2873  // both edges
2874  // This edge must have a one-to-one connection to the following lanes
2875  switch (myStep) {
2877  break;
2878  case INIT:
2879  break;
2880  case EDGE2EDGES: {
2881  // the following edge must be connected
2882  const EdgeVector& conn = getConnectedEdges();
2883  if (find(conn.begin(), conn.end(), possContinuation) == conn.end()) {
2884  reason = "disconnected";
2885  return false;
2886  }
2887  }
2888  break;
2889  case LANES2EDGES:
2890  case LANES2LANES_RECHECK:
2891  case LANES2LANES_DONE:
2892  case LANES2LANES_USER: {
2893  // the possible continuation must be connected
2894  if (find_if(myConnections.begin(), myConnections.end(), connections_toedge_finder(possContinuation)) == myConnections.end()) {
2895  reason = "disconnected";
2896  return false;
2897  }
2898  // all lanes must go to the possible continuation
2899  std::vector<int> conns = getConnectionLanes(possContinuation);
2900  const int offset = MAX2(0, getFirstNonPedestrianLaneIndex(NBNode::FORWARD, true));
2901  if (conns.size() != myLanes.size() - offset) {
2902  reason = "some lanes disconnected";
2903  return false;
2904  }
2905  }
2906  break;
2907  default:
2908  break;
2909  }
2910  return true;
2911 }
2912 
2913 
2914 void
2916  // append geometry
2917  myGeom.append(e->myGeom);
2918  for (int i = 0; i < (int)myLanes.size(); i++) {
2919  myLanes[i].shape.append(e->myLanes[i].shape);
2920  if (myLanes[i].knowsParameter(SUMO_PARAM_ORIGID) || e->myLanes[i].knowsParameter(SUMO_PARAM_ORIGID)
2921  || OptionsCont::getOptions().getBool("output.original-names")) {
2922  const std::string origID = myLanes[i].getParameter(SUMO_PARAM_ORIGID, getID());
2923  const std::string origID2 = e->myLanes[i].getParameter(SUMO_PARAM_ORIGID, e->getID());
2924  if (origID != origID2) {
2925  myLanes[i].setParameter(SUMO_PARAM_ORIGID, origID + " " + origID2);
2926  }
2927  }
2928  myLanes[i].connectionsDone = e->myLanes[i].connectionsDone;
2929  }
2930  // recompute length
2931  myLength += e->myLength;
2932  // copy the connections and the building step if given
2933  myStep = e->myStep;
2937  // set the node
2938  myTo = e->myTo;
2939  myToBorder = e->myToBorder;
2942  } else {
2943  mySignalOffset += e->getLength();
2944  }
2945  computeAngle(); // myEndAngle may be different now
2946 }
2947 
2948 
2949 bool
2951  for (std::vector<Connection>::const_iterator i = myConnections.begin(); i != myConnections.end(); ++i) {
2952  if ((*i).toEdge == e && (*i).tlID != "") {
2953  return true;
2954  }
2955  }
2956  return false;
2957 }
2958 
2959 
2960 NBEdge*
2961 NBEdge::getTurnDestination(bool possibleDestination) const {
2962  if (myTurnDestination == 0 && possibleDestination) {
2964  }
2965  return myTurnDestination;
2966 }
2967 
2968 
2969 std::string
2970 NBEdge::getLaneID(int lane) const {
2971  return myID + "_" + toString(lane);
2972 }
2973 
2974 
2975 std::string
2976 NBEdge::getLaneIDInsecure(int lane) const {
2977  return myID + "_" + toString(lane);
2978 }
2979 
2980 
2981 bool
2982 NBEdge::isNearEnough2BeJoined2(NBEdge* e, double threshold) const {
2983  std::vector<double> distances = myGeom.distances(e->getGeometry());
2984  assert(distances.size() > 0);
2985  return VectorHelper<double>::maxValue(distances) < threshold;
2986 }
2987 
2988 
2989 void
2990 NBEdge::addLane(int index, bool recomputeShape, bool recomputeConnections, bool shiftIndices) {
2991  assert(index <= (int)myLanes.size());
2992  myLanes.insert(myLanes.begin() + index, Lane(this, ""));
2993  // copy attributes
2994  if (myLanes.size() > 1) {
2995  int templateIndex = index > 0 ? index - 1 : index + 1;
2996  myLanes[index].speed = myLanes[templateIndex].speed;
2997  myLanes[index].permissions = myLanes[templateIndex].permissions;
2998  myLanes[index].preferred = myLanes[templateIndex].preferred;
2999  myLanes[index].endOffset = myLanes[templateIndex].endOffset;
3000  myLanes[index].width = myLanes[templateIndex].width;
3001  myLanes[index].updateParameter(myLanes[templateIndex].getParametersMap());
3002  }
3003  const EdgeVector& incs = myFrom->getIncomingEdges();
3004  if (recomputeShape) {
3006  }
3007  if (recomputeConnections) {
3008  for (EdgeVector::const_iterator i = incs.begin(); i != incs.end(); ++i) {
3009  (*i)->invalidateConnections(true);
3010  }
3011  invalidateConnections(true);
3012  } else if (shiftIndices) {
3013  // shift outgoing connections above the added lane to the left
3014  for (Connection& c : myConnections) {
3015  if (c.fromLane >= index) {
3016  c.fromLane += 1;
3017  }
3018  }
3019  // shift incoming connections above the added lane to the left
3020  for (NBEdge* inc : myFrom->getIncomingEdges()) {
3021  for (Connection& c : inc->myConnections) {
3022  if (c.toEdge == this && c.toLane >= index) {
3023  c.toLane += 1;
3024  }
3025  }
3026  }
3027  myFrom->shiftTLConnectionLaneIndex(this, +1, index - 1);
3028  myTo->shiftTLConnectionLaneIndex(this, +1, index - 1);
3029  }
3030 }
3031 
3032 void
3034  int newLaneNo = (int)myLanes.size() + by;
3035  while ((int)myLanes.size() < newLaneNo) {
3036  // recompute shapes on last addition
3037  const bool recompute = ((int)myLanes.size() == newLaneNo - 1) && myStep < LANES2LANES_USER;
3038  addLane((int)myLanes.size(), recompute, recompute, false);
3039  }
3040 }
3041 
3042 
3043 void
3044 NBEdge::deleteLane(int index, bool recompute, bool shiftIndices) {
3045  assert(index < (int)myLanes.size());
3046  myLanes.erase(myLanes.begin() + index);
3047  if (recompute) {
3049  const EdgeVector& incs = myFrom->getIncomingEdges();
3050  for (EdgeVector::const_iterator i = incs.begin(); i != incs.end(); ++i) {
3051  (*i)->invalidateConnections(true);
3052  }
3053  invalidateConnections(true);
3054  } else if (shiftIndices) {
3055  removeFromConnections(0, index, -1, false, true);
3056  for (NBEdge* inc : myFrom->getIncomingEdges()) {
3057  inc->removeFromConnections(this, -1, index, false, true);
3058  }
3059  }
3060 }
3061 
3062 
3063 void
3065  int newLaneNo = (int) myLanes.size() - by;
3066  assert(newLaneNo > 0);
3067  while ((int)myLanes.size() > newLaneNo) {
3068  // recompute shapes on last removal
3069  const bool recompute = (int)myLanes.size() == newLaneNo + 1 && myStep < LANES2LANES_USER;
3070  deleteLane((int)myLanes.size() - 1, recompute, false);
3071  }
3072 }
3073 
3074 
3075 void
3077  assert(myTo->getOutgoingEdges().size() == 0);
3079 }
3080 
3081 
3082 void
3084  if (lane < 0) { // all lanes are meant...
3085  for (int i = 0; i < (int)myLanes.size(); i++) {
3086  allowVehicleClass(i, vclass);
3087  }
3088  } else {
3089  assert(lane < (int)myLanes.size());
3090  myLanes[lane].permissions |= vclass;
3091  }
3092 }
3093 
3094 
3095 void
3097  if (lane < 0) { // all lanes are meant...
3098  for (int i = 0; i < (int)myLanes.size(); i++) {
3099  disallowVehicleClass((int) i, vclass);
3100  }
3101  } else {
3102  assert(lane < (int)myLanes.size());
3103  myLanes[lane].permissions &= ~vclass;
3104  }
3105 }
3106 
3107 
3108 void
3110  if (lane < 0) { // all lanes are meant...
3111  for (int i = 0; i < (int)myLanes.size(); i++) {
3112  allowVehicleClass(i, vclass);
3113  }
3114  } else {
3115  assert(lane < (int)myLanes.size());
3116  myLanes[lane].preferred |= vclass;
3117  }
3118 }
3119 
3120 
3121 void
3122 NBEdge::setLaneWidth(int lane, double width) {
3123  if (lane < 0) {
3124  // all lanes are meant...
3125  myLaneWidth = width;
3126  for (int i = 0; i < (int)myLanes.size(); i++) {
3127  // ... do it for each lane
3128  setLaneWidth(i, width);
3129  }
3130  return;
3131  }
3132  assert(lane < (int)myLanes.size());
3133  myLanes[lane].width = width;
3134 }
3135 
3136 
3137 double
3138 NBEdge::getLaneWidth(int lane) const {
3139  return myLanes[lane].width != UNSPECIFIED_WIDTH
3140  ? myLanes[lane].width
3142 }
3143 
3144 
3145 double
3147  double result = 0;
3148  for (int i = 0; i < (int)myLanes.size(); i++) {
3149  result += getLaneWidth(i);
3150  }
3151  return result;
3152 }
3153 
3154 double
3155 NBEdge::getEndOffset(int lane) const {
3156  return myLanes[lane].endOffset != UNSPECIFIED_OFFSET ? myLanes[lane].endOffset : getEndOffset();
3157 }
3158 
3159 
3160 const std::map<SVCPermissions, double>&
3161 NBEdge::getStopOffsets(int lane) const {
3162  if (lane == -1) {
3163  return myStopOffsets;
3164  } else {
3165  return myLanes[lane].stopOffsets;
3166  }
3167 }
3168 
3169 void
3170 NBEdge::setEndOffset(int lane, double offset) {
3171  if (lane < 0) {
3172  // all lanes are meant...
3173  myEndOffset = offset;
3174  for (int i = 0; i < (int)myLanes.size(); i++) {
3175  // ... do it for each lane
3176  setEndOffset(i, offset);
3177  }
3178  return;
3179  }
3180  assert(lane < (int)myLanes.size());
3181  myLanes[lane].endOffset = offset;
3182 }
3183 
3184 
3185 bool
3186 NBEdge::setStopOffsets(int lane, std::map<int, double> offsets, bool overwrite) {
3187  if (lane < 0) {
3188  if (!overwrite && myStopOffsets.size() != 0) {
3189  return false;
3190  }
3191  // all lanes are meant...
3192  if (offsets.size() != 0 && 0 > offsets.begin()->second) {
3193  // Edge length unknown at parsing time, thus check here.
3194  std::stringstream ss;
3195  ss << "Ignoring invalid stopOffset for edge " << getID() << " (negative offset).";
3196  WRITE_WARNING(ss.str());
3197  return false;
3198  } else {
3199  myStopOffsets = offsets;
3200  }
3201  } else {
3202  assert(lane < (int)myLanes.size());
3203  if (myLanes[lane].stopOffsets.size() == 0 || overwrite) {
3204  if (offsets.size() != 0 && 0 > offsets.begin()->second) {
3205  // Edge length unknown at parsing time, thus check here.
3206  std::stringstream ss;
3207  ss << "Ignoring invalid stopOffset for lane " << lane << " on edge " << getID() << " (negative offset).";
3208  WRITE_WARNING(ss.str());
3209  return false;
3210  } else {
3211  myLanes[lane].stopOffsets = offsets;
3212  }
3213  }
3214  }
3215  return true;
3216 }
3217 
3218 
3219 void
3220 NBEdge::setSpeed(int lane, double speed) {
3221  if (lane < 0) {
3222  // all lanes are meant...
3223  mySpeed = speed;
3224  for (int i = 0; i < (int)myLanes.size(); i++) {
3225  // ... do it for each lane
3226  setSpeed(i, speed);
3227  }
3228  return;
3229  }
3230  assert(lane < (int)myLanes.size());
3231  myLanes[lane].speed = speed;
3232 }
3233 
3234 void
3235 NBEdge::setAcceleration(int lane, bool accelRamp) {
3236  assert(lane >= 0);
3237  assert(lane < (int)myLanes.size());
3238  myLanes[lane].accelRamp = accelRamp;
3239 }
3240 
3241 
3242 void
3243 NBEdge::setLaneShape(int lane, const PositionVector& shape) {
3244  assert(lane >= 0);
3245  assert(lane < (int)myLanes.size());
3246  myLanes[lane].customShape = shape;
3247 }
3248 
3249 
3250 void
3251 NBEdge::setPermissions(SVCPermissions permissions, int lane) {
3252  if (lane < 0) {
3253  for (int i = 0; i < (int)myLanes.size(); i++) {
3254  // ... do it for each lane
3255  setPermissions(permissions, i);
3256  }
3257  } else {
3258  assert(lane < (int)myLanes.size());
3259  myLanes[lane].permissions = permissions;
3260  }
3261 }
3262 
3263 
3264 void
3266  if (lane < 0) {
3267  for (int i = 0; i < (int)myLanes.size(); i++) {
3268  // ... do it for each lane
3269  setPreferredVehicleClass(permissions, i);
3270  }
3271  } else {
3272  assert(lane < (int)myLanes.size());
3273  myLanes[lane].preferred = permissions;
3274  }
3275 }
3276 
3277 
3279 NBEdge::getPermissions(int lane) const {
3280  if (lane < 0) {
3281  SVCPermissions result = 0;
3282  for (int i = 0; i < (int)myLanes.size(); i++) {
3283  result |= getPermissions(i);
3284  }
3285  return result;
3286  } else {
3287  assert(lane < (int)myLanes.size());
3288  return myLanes[lane].permissions;
3289  }
3290 }
3291 
3292 
3293 void
3295  myLoadedLength = val;
3296 }
3297 
3298 
3299 void
3301  for (std::vector<Lane>::iterator i = myLanes.begin(); i != myLanes.end(); ++i) {
3302  (*i).permissions = SVCAll;
3303  (*i).preferred = 0;
3304  }
3305 }
3306 
3307 
3308 bool
3310  if (c1.fromLane != c2.fromLane) {
3311  return c1.fromLane < c2.fromLane;
3312  }
3313  if (c1.toEdge != c2.toEdge) {
3314  return false; // do not change ordering among toEdges as this is determined by angle in an earlier step
3315  }
3316  return c1.toLane < c2.toLane;
3317 }
3318 
3319 
3320 int
3321 NBEdge::getFirstNonPedestrianLaneIndex(int direction, bool exclusive) const {
3322  assert(direction == NBNode::FORWARD || direction == NBNode::BACKWARD);
3323  const int start = (direction == NBNode::FORWARD ? 0 : (int)myLanes.size() - 1);
3324  const int end = (direction == NBNode::FORWARD ? (int)myLanes.size() : - 1);
3325  for (int i = start; i != end; i += direction) {
3326  // SVCAll, does not count as a sidewalk, green verges (permissions = 0) do not count as road
3327  // in the exclusive case, lanes that allow pedestrians along with any other class also count as road
3328  if ((exclusive && myLanes[i].permissions != SVC_PEDESTRIAN && myLanes[i].permissions != 0)
3329  || (myLanes[i].permissions == SVCAll || ((myLanes[i].permissions & SVC_PEDESTRIAN) == 0 && myLanes[i].permissions != 0))) {
3330  return i;
3331  }
3332  }
3333  return -1;
3334 }
3335 
3336 
3337 int
3338 NBEdge::getFirstAllowedLaneIndex(int direction) const {
3339  assert(direction == NBNode::FORWARD || direction == NBNode::BACKWARD);
3340  const int start = (direction == NBNode::FORWARD ? 0 : (int)myLanes.size() - 1);
3341  const int end = (direction == NBNode::FORWARD ? (int)myLanes.size() : - 1);
3342  for (int i = start; i != end; i += direction) {
3343  if (myLanes[i].permissions != 0) {
3344  return i;
3345  }
3346  }
3347  return end - direction;
3348 }
3349 
3350 
3351 std::set<SVCPermissions>
3352 NBEdge::getPermissionVariants(int iStart, int iEnd) const {
3353  std::set<SVCPermissions> result;
3354  if (iStart < 0 || iStart >= getNumLanes() || iEnd > getNumLanes()) {
3355  throw ProcessError("invalid indices iStart " + toString(iStart) + " iEnd " + toString(iEnd) + " for edge with " + toString(getNumLanes()) + " lanes.");
3356  }
3357  for (int i = iStart; i < iEnd; ++i) {
3358  result.insert(getPermissions(i));
3359  }
3360  return result;
3361 }
3362 
3363 
3364 double
3366  double angle = getAngleAtNode(node) + (getFromNode() == node ? 180.0 : 0.0);
3367  if (angle < 0) {
3368  angle += 360.0;
3369  }
3370  if (angle >= 360) {
3371  angle -= 360.0;
3372  }
3373  if (gDebugFlag1) {
3374  std::cout << getID() << " angle=" << getAngleAtNode(node) << " convAngle=" << angle << "\n";
3375  }
3376  return angle;
3377 }
3378 
3379 
3382  int index = getFirstNonPedestrianLaneIndex(direction);
3383  if (index < 0) {
3384  throw ProcessError("Edge " + getID() + " allows pedestrians on all lanes");
3385  }
3386  return myLanes[index];
3387 }
3388 
3389 std::string
3391  // see IntermodalEdge::getSidewalk()
3392  for (int i = 0; i < (int)myLanes.size(); i++) {
3393  if (myLanes[i].permissions == SVC_PEDESTRIAN) {
3394  return getLaneID(i);
3395  }
3396  }
3397  for (int i = 0; i < (int)myLanes.size(); i++) {
3398  if ((myLanes[i].permissions & SVC_PEDESTRIAN) != 0) {
3399  return getLaneID(i);
3400  }
3401  }
3402  return getLaneID(0);
3403 }
3404 
3405 void
3406 NBEdge::addSidewalk(double width) {
3408 }
3409 
3410 
3411 void
3412 NBEdge::restoreSidewalk(std::vector<NBEdge::Lane> oldLanes, PositionVector oldGeometry, std::vector<NBEdge::Connection> oldConnections) {
3413  restoreRestrictedLane(SVC_PEDESTRIAN, oldLanes, oldGeometry, oldConnections);
3414 }
3415 
3416 
3417 void
3418 NBEdge::addBikeLane(double width) {
3420 }
3421 
3422 
3423 void
3424 NBEdge::restoreBikelane(std::vector<NBEdge::Lane> oldLanes, PositionVector oldGeometry, std::vector<NBEdge::Connection> oldConnections) {
3425  restoreRestrictedLane(SVC_BICYCLE, oldLanes, oldGeometry, oldConnections);
3426 }
3427 
3428 
3429 void
3431  if (myLanes[0].permissions == vclass) {
3432  WRITE_WARNING("Edge '" + getID() + "' already has a dedicated lane for " + toString(vclass) + "s. Not adding another one.");
3433  return;
3434  }
3436  myGeom.move2side(width / 2);
3437  }
3438  // disallow pedestrians on all lanes to ensure that sidewalks are used and
3439  // crossings can be guessed
3440  disallowVehicleClass(-1, vclass);
3441  // add new lane
3442  myLanes.insert(myLanes.begin(), Lane(this, myLanes[0].getParameter(SUMO_PARAM_ORIGID)));
3443  myLanes[0].permissions = vclass;
3444  myLanes[0].width = width;
3445  // shift outgoing connections to the left
3446  for (std::vector<Connection>::iterator it = myConnections.begin(); it != myConnections.end(); ++it) {
3447  Connection& c = *it;
3448  if (c.fromLane >= 0) {
3449  c.fromLane += 1;
3450  }
3451  }
3452  // shift incoming connections to the left
3453  const EdgeVector& incoming = myFrom->getIncomingEdges();
3454  for (EdgeVector::const_iterator it = incoming.begin(); it != incoming.end(); ++it) {
3455  (*it)->shiftToLanesToEdge(this, 1);
3456  }
3458  myTo->shiftTLConnectionLaneIndex(this, 1);
3460 }
3461 
3462 
3463 void
3464 NBEdge::restoreRestrictedLane(SUMOVehicleClass vclass, std::vector<NBEdge::Lane> oldLanes, PositionVector oldGeometry, std::vector<NBEdge::Connection> oldConnections) {
3465  // check that previously lane was transformed
3466  if (myLanes[0].permissions != vclass) {
3467  WRITE_WARNING("Edge '" + getID() + "' don't have a dedicated lane for " + toString(vclass) + "s. Cannot be restored");
3468  return;
3469  }
3470  // restore old values
3471  myGeom = oldGeometry;
3472  myLanes = oldLanes;
3473  myConnections = oldConnections;
3474  // shift incoming connections to the right
3475  const EdgeVector& incoming = myFrom->getIncomingEdges();
3476  for (EdgeVector::const_iterator it = incoming.begin(); it != incoming.end(); ++it) {
3477  (*it)->shiftToLanesToEdge(this, 0);
3478  }
3479  // Shift TL conections
3481  myTo->shiftTLConnectionLaneIndex(this, 0);
3483 }
3484 
3485 
3486 void
3489  for (std::vector<Connection>::iterator it = myConnections.begin(); it != myConnections.end(); ++it) {
3490  if ((*it).toEdge == to && (*it).toLane >= 0) {
3491  (*it).toLane += laneOff;
3492  }
3493  }
3494 }
3495 
3496 
3497 void
3500  const int i = (node == myTo ? -1 : 0);
3501  const int i2 = (node == myTo ? 0 : -1);
3502  const double dist = myGeom[i].distanceTo2D(node->getPosition());
3503  const double neededOffset = (getTotalWidth() + getNumLanes() * SUMO_const_laneOffset) / 2;
3504  const double dist2 = MIN2(myGeom.distance2D(other->getGeometry()[i2]),
3505  other->getGeometry().distance2D(myGeom[i]));
3506  const double neededOffset2 = neededOffset + (other->getTotalWidth() + other->getNumLanes() * SUMO_const_laneOffset) / 2;
3507  if (dist < neededOffset && dist2 < neededOffset2) {
3508  PositionVector tmp = myGeom;
3509  // @note this doesn't work well for vissim networks
3510  //tmp.move2side(MIN2(neededOffset - dist, neededOffset2 - dist2));
3511  try {
3512  tmp.move2side(neededOffset - dist);
3513  myGeom[i] = tmp[i];
3514  } catch (InvalidArgument&) {
3515  WRITE_WARNING("Could not avoid overlapping shape at node '" + node->getID() + "' for edge '" + getID() + "'");
3516  }
3517  }
3518  }
3519 }
3520 
3521 
3522 double
3524  double result = getLoadedLength();
3525  if (OptionsCont::getOptions().getBool("no-internal-links") && !hasLoadedLength()) {
3526  // use length to junction center even if a modified geometry was given
3528  geom.push_back_noDoublePos(getToNode()->getCenter());
3529  geom.push_front_noDoublePos(getFromNode()->getCenter());
3530  result = geom.length();
3531  }
3532  return MAX2(result, POSITION_EPS);
3533 }
3534 
3535 void
3536 NBEdge::setOrigID(const std::string origID) {
3537  if (origID != "") {
3538  for (int i = 0; i < (int)myLanes.size(); i++) {
3539  myLanes[i].setParameter(SUMO_PARAM_ORIGID, origID);
3540  }
3541  } else {
3542  // do not record empty origID parameter
3543  for (int i = 0; i < (int)myLanes.size(); i++) {
3544  myLanes[i].unsetParameter(SUMO_PARAM_ORIGID);
3545  }
3546  }
3547 }
3548 
3549 
3550 const EdgeVector&
3552  // @todo cache successors instead of recomputing them every time
3553  mySuccessors.clear();
3554  //std::cout << "getSuccessors edge=" << getID() << " svc=" << toString(vClass) << " cons=" << myConnections.size() << "\n";
3555  for (const Connection& con : myConnections) {
3556  if (con.fromLane >= 0 && con.toLane >= 0 && con.toEdge != nullptr &&
3557  (getPermissions(con.fromLane)
3558  & con.toEdge->getPermissions(con.toLane) & vClass) != 0
3559  && find(mySuccessors.begin(), mySuccessors.end(), con.toEdge) == mySuccessors.end()) {
3560  mySuccessors.push_back(con.toEdge);
3561  //std::cout << " succ=" << con.toEdge->getID() << "\n";
3562  }
3563  }
3564  return mySuccessors;
3565 }
3566 
3567 
3568 const NBConstEdgePairVector&
3570  // @todo cache successors instead of recomputing them every time
3571  myViaSuccessors.clear();
3572  for (const Connection& con : myConnections) {
3573  std::pair<const NBEdge*, const NBEdge*> pair(con.toEdge, nullptr);
3574  if (con.fromLane >= 0 && con.toLane >= 0 && con.toEdge != nullptr &&
3575  (getPermissions(con.fromLane)
3576  & con.toEdge->getPermissions(con.toLane) & vClass) != 0
3577  && find(myViaSuccessors.begin(), myViaSuccessors.end(), pair) == myViaSuccessors.end()) {
3578  myViaSuccessors.push_back(pair);
3579  }
3580  }
3581  return myViaSuccessors;
3582 }
3583 
3584 
3585 void
3586 NBEdge::debugPrintConnections(bool outgoing, bool incoming) const {
3587  if (outgoing) {
3588  for (const Connection& c : myConnections) {
3589  std::cout << " " << getID() << "_" << c.fromLane << "->" << c.toEdge->getID() << "_" << c.toLane << "\n";
3590  }
3591  }
3592  if (incoming) {
3593  for (NBEdge* inc : myFrom->getIncomingEdges()) {
3594  for (Connection& c : inc->myConnections) {
3595  if (c.toEdge == this) {
3596  std::cout << " " << inc->getID() << "_" << c.fromLane << "->" << c.toEdge->getID() << "_" << c.toLane << "\n";
3597  }
3598  }
3599  }
3600  }
3601 }
3602 
3603 
3604 int
3605 NBEdge::getLaneIndexFromLaneID(const std::string laneID) {
3606  return TplConvert::_2int(laneID.substr(laneID.rfind("_") + 1).c_str());
3607 }
3608 
3609 /****************************************************************************/
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
return true if certain connection must be controlled by TLS
Definition: NBEdge.cpp:2685
LaneSpreadFunction getLaneSpreadFunction() const
Returns how this edge&#39;s lanes&#39; lateral offset is computed.
Definition: NBEdge.h:699
bool gDebugFlag1
global utility flags for debugging
Definition: StdDefs.cpp:32
bool around(const Position &p, double offset=0) const
Returns the information whether the position vector describes a polygon lying around the given point...
std::string id
id of Connection
Definition: NBEdge.h:215
void moveConnectionToRight(int lane)
Definition: NBEdge.cpp:1434
void invalidateConnections(bool reallowSetting=false)
invalidate current connections of edge
Definition: NBEdge.cpp:1316
bool bothLeftIntersect(const NBNode &n, const PositionVector &shape, LinkDirection dir, NBEdge *otherFrom, const NBEdge::Connection &otherCon, int numPoints, double width2) const
determine conflict between opposite left turns
Definition: NBEdge.cpp:1706
bool expandableBy(NBEdge *possContinuation, std::string &reason) const
Check if Node is expandable.
Definition: NBEdge.cpp:2819
void init(int noLanes, bool tryIgnoreNodePositions, const std::string &origID)
Initialization routines common to all constructors.
Definition: NBEdge.cpp:418
The link is a partial left direction.
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:108
void appendTurnaround(bool noTLSControlled, bool onlyDeadends, bool checkPermissions)
Add a connection to the previously computed turnaround, if wished.
Definition: NBEdge.cpp:2588
static const bool UNSPECIFIED_CONNECTION_UNCONTROLLED
TLS-controlled despite its node controlled not specified.
Definition: NBEdge.h:280
std::vector< Lane > myLanes
Lane information.
Definition: NBEdge.h:1505
double vmax
maximum velocity
Definition: NBEdge.h:221
double getLength() const
Returns the computed length of the edge.
Definition: NBEdge.h:483
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:1761
bool setControllingTLInformation(const NBConnection &c, const std::string &tlID)
Returns if the link could be set as to be controlled.
Definition: NBEdge.cpp:2696
double length2D() const
Returns the length.
void divideOnEdges(const EdgeVector *outgoing)
divides the lanes on the outgoing edges
Definition: NBEdge.cpp:2212
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:160
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:3338
int toLane
The lane the connections yields in.
Definition: NBEdge.h:188
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:1608
void debugPrintConnections(bool outgoing=true, bool incoming=false) const
debugging helper to print all connections
Definition: NBEdge.cpp:3586
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
static const double UNSPECIFIED_LOADED_LENGTH
no length override given
Definition: NBEdge.h:268
is a pedestrian
std::vector< TLSDisabledConnection > myTLSDisabledConnections
vector with the disabled connections
Definition: NBEdge.h:1524
const std::map< int, double > & getStopOffsets() const
Returns the stopOffset to the end of the edge.
Definition: NBEdge.h:557
~NBEdge()
Destructor.
Definition: NBEdge.cpp:489
void append(const PositionVector &v, double sameThreshold=2.0)
PositionVector getOrthogonal(const Position &p, double extend, bool before, double length=1.0) const
return orthogonal through p (extending this vector if necessary)
LaneSpreadFunction myLaneSpreadFunction
The information about how to spread the lanes.
Definition: NBEdge.h:1488
double z() const
Returns the z-position.
Definition: Position.h:66
void sortOutgoingConnectionsByAngle()
sorts the outgoing connections by their angle relative to their junction
Definition: NBEdge.cpp:1221
std::string viaID
if Connection have a via, ID of it
Definition: NBEdge.h:227
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) ...
NBEdge * toEdge
The edge the connections yields in.
Definition: NBEdge.h:185
EdgeVector getIncomingEdges() const
Returns the list of incoming edges unsorted.
Definition: NBEdge.cpp:1194
void mirrorX()
mirror coordinates along the x-axis
Definition: NBEdge.cpp:507
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
NBNode * myTo
Definition: NBEdge.h:1446
static const double UNSPECIFIED_VISIBILITY_DISTANCE
unspecified foe visibility for connections
Definition: NBEdge.h:265
void setEndOffset(int lane, double offset)
set lane specific end-offset (negative lane implies set for all lanes)
Definition: NBEdge.cpp:3170
bool setConnection(int lane, NBEdge *destEdge, int destLane, Lane2LaneInfoType type, bool mayUseSameDestination=false, bool mayDefinitelyPass=false, bool keepClear=true, double contPos=UNSPECIFIED_CONTPOS, double visibility=UNSPECIFIED_VISIBILITY_DISTANCE, double speed=UNSPECIFIED_SPEED, const PositionVector &customShape=PositionVector::EMPTY, const bool uncontrolled=UNSPECIFIED_CONNECTION_UNCONTROLLED)
Adds a connection to a certain lane of a certain edge.
Definition: NBEdge.cpp:1010
The relationships between edges are computed/loaded.
Definition: NBEdge.h:88
double getLaneSpeed(int lane) const
get lane speed
Definition: NBEdge.cpp:1785
bool hasPermissions() const
whether at least one lane has restrictions
Definition: NBEdge.cpp:1915
bool isConnectedTo(const NBEdge *e) const
Returns the information whethe a connection to the given edge has been added (or computed) ...
Definition: NBEdge.cpp:1132
void reduceGeometry(const double minDist)
Removes points with a distance lesser than the given.
Definition: NBEdge.cpp:890
bool hasSignalisedConnectionTo(const NBEdge *const e) const
Check if edge has signalised connections.
Definition: NBEdge.cpp:2950
NBEdge(const std::string &id, NBNode *from, NBNode *to, std::string type, double speed, int nolanes, int priority, double width, double endOffset, const std::string &streetName="", LaneSpreadFunction spread=LANESPREAD_RIGHT)
Constructor.
Definition: NBEdge.cpp:254
std::vector< std::pair< const NBEdge *, const NBEdge * > > NBConstEdgePairVector
Definition: NBCont.h:43
static double normRelAngle(double angle1, double angle2)
ensure that reverse relAngles (>=179.999) always count as turnarounds (-180)
Definition: NBHelpers.cpp:60
double myLaneWidth
This width of this edge&#39;s lanes.
Definition: NBEdge.h:1500
std::map< int, double > myStopOffsets
A vClass specific stop offset - assumed of length 0 (unspecified) or 1. For the latter case the int i...
Definition: NBEdge.h:1497
double myEndOffset
This edges&#39;s offset to the intersection begin (will be applied to all lanes)
Definition: NBEdge.h:1491
void addLane(int index, bool recomputeShape, bool recomputeConnections, bool shiftIndices)
add lane
Definition: NBEdge.cpp:2990
void setSpeed(int lane, double speed)
set lane specific speed (negative lane implies set for all lanes)
Definition: NBEdge.cpp:3220
Holds (- relative to the edge it is build from -!!!) the list of main directions a vehicle that drive...
Definition: NBEdge.h:1334
PositionVector computeInternalLaneShape(NBEdge *fromE, const NBEdge::Connection &con, int numPoints, NBNode *recordError=0) const
Compute the shape for an internal lane.
Definition: NBNode.cpp:658
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
double getSignalOffset() const
Returns the offset of a traffic signal from the end of this edge.
Definition: NBEdge.h:572
Some static methods for string processing.
Definition: StringUtils.h:38
static const double ANGLE_LOOKAHEAD
the distance at which to take the default angle
Definition: NBEdge.h:274
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
Definition: NBEdge.cpp:1729
void moveConnectionToLeft(int lane)
Definition: NBEdge.cpp:1419
std::vector< Crossing * > getCrossings() const
return this junctions pedestrian crossings
Definition: NBNode.cpp:2223
int getPriority() const
Returns the priority of the edge.
Definition: NBEdge.h:422
void removeEdge(NBEdge *edge, bool removeFromConnections=true)
Removes edge from this node and optionally removes connections as well.
Definition: NBNode.cpp:1392
const std::string & getTypeID() const
get ID of type
Definition: NBEdge.h:999
vehicle is a bicycle
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.
const double SUMO_const_laneWidth
Definition: StdDefs.h:43
bool empty() const
returns the information whether no following street has a higher priority
Definition: NBEdge.cpp:228
void addIncomingEdge(NBEdge *edge)
adds an incoming edge
Definition: NBNode.cpp:425
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
The representation of a single edge during network building.
Definition: NBEdge.h:65
void reinitNodes(NBNode *from, NBNode *to)
Resets nodes but keeps all other values the same (used when joining)
Definition: NBEdge.cpp:392
void clearControllingTLInformation()
clears tlID for all connections
Definition: NBEdge.cpp:2761
vehicle is a small delivery vehicle
void setNodeBorder(const NBNode *node, const Position &p, const Position &p2, bool rectangularCut)
Set Node border.
Definition: NBEdge.cpp:603
Lane2LaneInfoType
Modes of setting connections between lanes.
Definition: NBEdge.h:103
std::vector< int > * prepareEdgePriorities(const EdgeVector *outgoing)
recomputes the edge priorities and manipulates them for a distribution of lanes on edges which is mor...
Definition: NBEdge.cpp:2488
Lane(NBEdge *e, const std::string &_origID)
constructor
Definition: NBEdge.cpp:126
const double SUMO_const_laneWidthAndOffset
Definition: StdDefs.h:47
The link is a 180 degree turn.
bool hasLaneSpecificSpeed() const
whether lanes differ in speed
Definition: NBEdge.cpp:1940
static const double UNSPECIFIED_SIGNAL_OFFSET
unspecified signal offset
Definition: NBEdge.h:271
bool isBidiRail(bool ignoreSpread=false) const
whether this edge is part of a bidirectional railway
Definition: NBEdge.cpp:650
std::vector< Direction > myDirs
list of the main direction within the following junction relative to the edge
Definition: NBEdge.h:1340
void markAsInLane2LaneState()
mark edge as in lane to state lane
Definition: NBEdge.cpp:3076
static const double UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:256
void removeFromConnections(NBEdge *toEdge, int fromLane=-1, int toLane=-1, bool tryLater=false, const bool adaptToLaneRemoval=false)
Removes the specified connection(s)
Definition: NBEdge.cpp:1249
double getMaxLaneOffset()
get max lane offset
Definition: NBEdge.cpp:2679
TLS Disabled Connections.
Definition: NBEdge.h:1517
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position ...
Definition: Position.h:253
Lanes to lanes - relationships are computed; should be recheked.
Definition: NBEdge.h:92
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
T MAX2(T a, T b)
Definition: StdDefs.h:68
bool hasLoadedLength() const
Returns whether a length was set explicitly.
Definition: NBEdge.h:502
NBEdge * getTurnDestination(bool possibleDestination=false) const
Definition: NBEdge.cpp:2961
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:3251
PositionVector shape
The crossing&#39;s shape.
Definition: NBNode.h:133
int myFromJunctionPriority
The priority normalised for the node the edge is outgoing of.
Definition: NBEdge.h:1479
void setLoadedLength(double val)
set loaded lenght
Definition: NBEdge.cpp:3294
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:62
const std::vector< NBEdge::Lane > & getLanes() const
Returns the lane definitions.
Definition: NBEdge.h:584
void computeLaneShapes()
compute lane shapes
Definition: NBEdge.cpp:1791
bool mayDefinitelyPass
Information about being definitely free to drive (on-ramps)
Definition: NBEdge.h:197
PositionVector reverse() const
reverse position vector
double endOffset
This lane&#39;s offset to the intersection begin.
Definition: NBEdge.h:133
PositionVector myGeom
The geometry for the edge.
Definition: NBEdge.h:1485
double visibility
custom foe visiblity for connection
Definition: NBEdge.h:206
bool isForbidden(SVCPermissions permissions)
Returns whether an edge with the given permission is a forbidden edge.
void remapConnections(const EdgeVector &incoming)
Remaps the connection in a way that allows the removal of it.
Definition: NBEdge.cpp:1233
const double SUMO_const_laneOffset
Definition: StdDefs.h:44
#define RAD2DEG(x)
Definition: GeomHelper.h:39
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const std::string & getID() const
Returns the id.
Definition: Named.h:69
void insert_noDoublePos(const std::vector< Position >::iterator &at, const Position &p)
insert in front a non double position
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
const SVCPermissions SVCAll
all VClasses are allowed
std::vector< int > getConnectionLanes(NBEdge *currentOutgoing) const
Returns the list of lanes that may be used to reach the given edge.
Definition: NBEdge.cpp:1207
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 myFromBorder
intersection borders (because the node shape might be invalid)
Definition: NBEdge.h:1537
void restoreBikelane(std::vector< NBEdge::Lane > oldLanes, PositionVector oldGeometry, std::vector< NBEdge::Connection > oldConnections)
restore an previously added BikeLane
Definition: NBEdge.cpp:3424
bool isRailDeadEnd() const
whether this edge is a railway edge that does not continue
Definition: NBEdge.cpp:661
bool setStopOffsets(int lane, std::map< int, double > offsets, bool overwrite=false)
set lane and vehicle class specific stopOffset (negative lane implies set for all lanes) ...
Definition: NBEdge.cpp:3186
void addSidewalk(double width)
add a pedestrian sidewalk of the given width and shift existing connctions
Definition: NBEdge.cpp:3406
void addOutgoingEdge(NBEdge *edge)
adds an outgoing edge
Definition: NBNode.cpp:435
void setGeometry(const PositionVector &g, bool inner=false)
(Re)sets the edge&#39;s geometry
Definition: NBEdge.cpp:552
std::string getDescription(const NBEdge *parent) const
get string describing this connection
Definition: NBEdge.cpp:84
bool hasLaneSpecificStopOffsets() const
whether lanes differ in stopOffsets
Definition: NBEdge.cpp:1973
bool includes(Direction d) const
returns the information whether the street in the given direction has a higher priority ...
Definition: NBEdge.cpp:234
double getShapeStartAngle() const
Returns the angle at the start of the edge.
Definition: NBEdge.cpp:1899
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:253
The link is a (hard) left direction.
PositionVector customShape
custom shape for connection
Definition: NBEdge.h:212
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:242
The connection was computed and validated.
Definition: NBEdge.h:109
bool hasDefaultGeometryEndpoints() const
Returns whether the geometry is terminated by the node positions This default may be violated by init...
Definition: NBEdge.cpp:534
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
void shortenGeometryAtNode(const NBNode *node, double reduction)
linearly extend the geometry at the given node
Definition: NBEdge.cpp:589
void setLaneShape(int lane, const PositionVector &shape)
sets a custom lane shape
Definition: NBEdge.cpp:3243
void setAcceleration(int lane, bool accelRamp)
marks one lane as acceleration lane
Definition: NBEdge.cpp:3235
static bool rightTurnConflict(const NBEdge *from, const NBEdge *to, int fromLane, const NBEdge *prohibitorFrom, const NBEdge *prohibitorTo, int prohibitorFromLane, bool lefthand=false)
return whether the given laneToLane connection is a right turn which must yield to a bicycle crossing...
Definition: NBNode.cpp:1486
static double legacyDegree(const double angle, const bool positive=false)
Definition: GeomHelper.cpp:203
const EdgeVector & getOutgoingEdges() const
Returns this node&#39;s outgoing edges (The edges which start at this node)
Definition: NBNode.h:254
PositionVector cutAtIntersection(const PositionVector &old) const
cut shape at the intersection shapes
Definition: NBEdge.cpp:676
The edge has been loaded, nothing is computed yet.
Definition: NBEdge.h:86
NBNode * tryGetNodeAtPosition(double pos, double tolerance=5.0) const
Returns the node at the given edges length (using an epsilon)
Definition: NBEdge.cpp:2645
int getFirstNonPedestrianLaneIndex(int direction, bool exclusive=false) const
return the first lane with permissions other than SVC_PEDESTRIAN and 0
Definition: NBEdge.cpp:3321
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
int myToJunctionPriority
The priority normalised for the node the edge is incoming in.
Definition: NBEdge.h:1482
The link is a straight direction.
PositionVector shape
shape of Connection
Definition: NBEdge.h:218
static const double UNSPECIFIED_SPEED
unspecified lane speed
Definition: NBEdge.h:259
void restoreSidewalk(std::vector< NBEdge::Lane > oldLanes, PositionVector oldGeometry, std::vector< NBEdge::Connection > oldConnections)
restore an previously added sidewalk
Definition: NBEdge.cpp:3412
bool addLane2LaneConnection(int fromLane, NBEdge *dest, int toLane, Lane2LaneInfoType type, bool mayUseSameDestination=false, bool mayDefinitelyPass=false, bool keepClear=true, double contPos=UNSPECIFIED_CONTPOS, double visibility=UNSPECIFIED_VISIBILITY_DISTANCE, double speed=UNSPECIFIED_SPEED, const PositionVector &customShape=PositionVector::EMPTY, const bool uncontrolled=UNSPECIFIED_CONNECTION_UNCONTROLLED)
Adds a connection between the specified this edge&#39;s lane and an approached one.
Definition: NBEdge.cpp:966
bool keepClear
whether the junction must be kept clear when using this connection
Definition: NBEdge.h:200
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:3430
std::vector< Connection > getConnectionsFromLane(int lane) const
Returns connections from a given lane.
Definition: NBEdge.cpp:1085
An (internal) definition of a single lane of an edge.
Definition: NBEdge.h:116
bool addEdge2EdgeConnection(NBEdge *dest)
Adds a connection to another edge.
Definition: NBEdge.cpp:942
void extrapolate2D(const double val, const bool onlyFirst=false)
extrapolate position vector in two dimensions (Z is ignored)
void incLaneNo(int by)
increment lane
Definition: NBEdge.cpp:3033
bool isTLControlled() const
Returns whether this node is controlled by any tls.
Definition: NBNode.h:297
bool myAmMacroscopicConnector
Information whether this edge is a (macroscopic) connector.
Definition: NBEdge.h:1514
void push_front_noDoublePos(const Position &p)
insert in front a non double position
void removeDoublePoints(double minDist=POSITION_EPS, bool assertLength=false)
Removes positions if too near.
bool computeLanes2Edges()
computes the edge, step2: computation of which lanes approach the edges)
Definition: NBEdge.cpp:2059
NBEdge * myTurnDestination
The turn destination edge (if a connection exists)
Definition: NBEdge.h:1473
double myStartAngle
The angles of the edge.
Definition: NBEdge.h:1453
bool hasLaneSpecificWidth() const
whether lanes differ in width
Definition: NBEdge.cpp:1951
double speed
custom speed for connection
Definition: NBEdge.h:209
Lanes to lanes - relationships are loaded; no recheck is necessary/wished.
Definition: NBEdge.h:96
bool knowsParameter(const std::string &key) const
Returns whether the parameter is known.
bool hasLaneSpecificEndOffset() const
whether lanes differ in offset
Definition: NBEdge.cpp:1962
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
Definition: NBEdgeCont.cpp:152
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
static const int FORWARD
edge directions (for pedestrian related stuff)
Definition: NBNode.h:201
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:541
void decLaneNo(int by)
decrement lane
Definition: NBEdge.cpp:3064
std::string tlID
The id of the traffic light that controls this connection.
Definition: NBEdge.h:191
#define DEBUGCOND2(LANE)
double beginEndAngle() const
returns the angle in radians of the line connecting the first and the last position ...
std::string getLaneID(int lane) const
get Lane ID (Secure)
Definition: NBEdge.cpp:2970
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:415
int fromLane
The lane the connections starts at.
Definition: NBEdge.h:182
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
int operator()(const Connection &c1, const Connection &c2) const
comparing operation
Definition: NBEdge.cpp:243
A list of positions.
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:993
void setOrigID(const std::string origID)
set origID for all lanes
Definition: NBEdge.cpp:3536
const PositionVector getInnerGeometry() const
Returns the geometry of the edge without the endpoints.
Definition: NBEdge.cpp:522
void moveOutgoingConnectionsFrom(NBEdge *e, int laneOff)
move outgoing connection
Definition: NBEdge.cpp:2659
static int computePrioritySum(const std::vector< int > &priorities)
computes the sum of the given list&#39;s entries (sic!)
Definition: NBEdge.cpp:2578
static bool connections_sorter(const Connection &c1, const Connection &c2)
connections_sorter sort by fromLane, toEdge and toLane
Definition: NBEdge.cpp:3309
void resetNodeBorder(const NBNode *node)
Definition: NBEdge.cpp:639
static const double UNSPECIFIED_CONTPOS
unspecified internal junction position
Definition: NBEdge.h:262
bool needsLaneSpecificOutput() const
whether at least one lane has values differing from the edges values
Definition: NBEdge.cpp:2019
void deleteLane(int index, bool recompute, bool shiftIndices)
delete lane
Definition: NBEdge.cpp:3044
bool hasConnectionTo(NBEdge *destEdge, int destLane, int fromLane=-1) const
Retrieves info about a connection to a certain lane of a certain edge.
Definition: NBEdge.cpp:1126
NBEdge * myPossibleTurnDestination
The edge that would be the turn destination if there was one.
Definition: NBEdge.h:1476
bool hasDefaultGeometry() const
Returns whether the geometry consists only of the node positions.
Definition: NBEdge.cpp:528
static int getLaneIndexFromLaneID(const std::string laneID)
Definition: NBEdge.cpp:3605
int myPriority
The priority of the edge.
Definition: NBEdge.h:1459
static double firstIntersection(const PositionVector &v1, const PositionVector &v2, double width2)
compute the first intersection point between the given lane geometries considering their rspective wi...
Definition: NBEdge.cpp:1680
bool geometryLike() const
whether this is structurally similar to a geometry node
Definition: NBNode.cpp:2790
NBConstEdgePairVector myViaSuccessors
Definition: NBEdge.h:1549
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:61
T MIN2(T a, T b)
Definition: StdDefs.h:62
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
The link is a (hard) right direction.
Connection(int fromLane_, NBEdge *toEdge_, int toLane_)
Constructor.
Definition: NBEdge.cpp:89
std::string getSidewalkID()
get the lane id for the canonical sidewalk lane
Definition: NBEdge.cpp:3390
EdgeBuildingStep myStep
The building step.
Definition: NBEdge.h:1440
#define POSITION_EPS
Definition: config.h:172
EdgeBuildingStep getStep() const
The building step of this edge.
Definition: NBEdge.h:518
const std::string & getStreetName() const
Returns the street name of this edge.
Definition: NBEdge.h:538
double getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge&#39;s geometry at the given node.
Definition: NBEdge.cpp:1749
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 ...
void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
Class to sort edges by their angle.
Definition: NBEdge.h:1728
void buildInnerEdges(const NBNode &n, int noInternalNoSplits, int &linkIndex, int &splitIndex)
Definition: NBEdge.cpp:1447
double myTotalAngle
Definition: NBEdge.h:1455
PositionVector getCWBoundaryLine(const NBNode &n) const
get the outer boundary of this edge when going clock-wise around the given node
Definition: NBEdge.cpp:2779
PositionVector getSubpart(double beginOffset, double endOffset) const
get subpart of a position vector
double getEndOffset() const
Returns the offset to the destination node.
Definition: NBEdge.h:550
#define DEG2RAD(x)
Definition: GeomHelper.h:38
PositionVector smoothedZFront(double dist=std::numeric_limits< double >::max()) const
returned vector that is smoothed at the front (within dist)
static const double INVALID_OFFSET
a value to signify offsets outside the range of [0, Line.length()]
Definition: GeomHelper.h:52
std::vector< Connection > myConnections
List of connections to following edges.
Definition: NBEdge.h:1467
PositionVector startShapeAt(const PositionVector &laneShape, const NBNode *startNode, PositionVector nodeShape) const
Definition: NBEdge.cpp:757
std::string getLaneIDInsecure(int lane) const
get Lane ID (Insecure)
Definition: NBEdge.cpp:2976
void execute(const int lane, const int virtEdge)
executes a bresenham - step
Definition: NBEdge.cpp:145
PositionVector getSubpartByIndex(int beginIndex, int count) const
get subpart of a position vector using index and a cout
The connection was given by the user.
Definition: NBEdge.h:107
The link is a partial right direction.
double speed
The speed allowed on this lane.
Definition: NBEdge.h:124
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
std::set< SVCPermissions > getPermissionVariants(int iStart, int iEnd) const
return all permission variants within the specified lane range [iStart, iEnd[
Definition: NBEdge.cpp:3352
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:3279
bool lanesWereAssigned() const
Check if lanes were assigned.
Definition: NBEdge.cpp:2673
double getFinalLength() const
get length that will be assigned to the lanes in the final network
Definition: NBEdge.cpp:3523
void move2side(double amount)
move position vector to side using certain ammount
vehicle is a passenger car (a "normal" car)
bool myAmInnerEdge
Information whether this is a junction-inner edge.
Definition: NBEdge.h:1511
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:1543
int tlLinkIndex
The index of this connection within the controlling traffic light.
Definition: NBEdge.h:194
bool hasLaneSpecificPermissions() const
whether lanes differ in allowed vehicle classes
Definition: NBEdge.cpp:1926
Base class for objects which have an id.
Definition: Named.h:49
double myEndAngle
Definition: NBEdge.h:1454
bool recheckLanes()
recheck whether all lanes within the edge are all right and optimises the connections once again ...
Definition: NBEdge.cpp:2083
bool hasLaneParams() const
whether one of the lanes has parameters set
Definition: NBEdge.cpp:2009
void reinit(NBNode *from, NBNode *to, const std::string &type, double speed, int nolanes, int priority, PositionVector geom, double width, double endOffset, const std::string &streetName, LaneSpreadFunction spread=LANESPREAD_RIGHT, bool tryIgnoreNodePositions=false)
Resets initial values.
Definition: NBEdge.cpp:344
double mySpeed
The maximal speed.
Definition: NBEdge.h:1462
static std::string convertUmlaute(std::string str)
Converts german "Umlaute" to their latin-version.
Definition: StringUtils.cpp:84
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing, bool leftHand=false) const
Returns the representation of the described stream&#39;s direction.
Definition: NBNode.cpp:1696
static bool isValidNetID(const std::string &value)
whether the given string is a valid id for a network element
const PositionVector & getShape() const
retrieve the junction shape
Definition: NBNode.cpp:1911
double getSpeed() const
Returns the speed allowed on this edge.
Definition: NBEdge.h:509
int getToLane() const
returns the to-lane
#define DEBUGCOND(PEDID)
NBEdge * getTo() const
returns the to-edge (end of the connection)
int internalLaneIndex
The lane index of this internal lane within the internal edge.
Definition: NBEdge.h:239
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition: NBEdge.h:617
void extendGeometryAtNode(const NBNode *node, double maxExtent)
linearly extend the geometry at the given node
Definition: NBEdge.cpp:566
PositionVector getSubpart2D(double beginOffset, double endOffset) const
get subpart of a position vector in two dimensions (Z is ignored)
Connection getConnection(int fromLane, const NBEdge *to, int toLane) const
Returns the specified connection This method goes through "myConnections" and returns the specified o...
Definition: NBEdge.cpp:1097
vehicle is a bus
double getLaneWidth() const
Returns the default width of lanes of this edge.
Definition: NBEdge.h:525
void setTurningDestination(NBEdge *e, bool onlyPossible=false)
Sets the turing destination at the given edge.
Definition: NBEdge.cpp:1776
static const int BACKWARD
Definition: NBNode.h:202
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
Definition: TplConvert.h:149
std::string myID
The name of the object.
Definition: Named.h:121
void extrapolate(const double val, const bool onlyFirst=false, const bool onlyLast=false)
extrapolate position vector
double width
This crossing&#39;s width.
Definition: NBNode.h:137
double length() const
Returns the length.
void computeEdgeShape()
Recomputeds the lane shapes to terminate at the node shape For every lane the intersection with the f...
Definition: NBEdge.cpp:742
void addStraightConnections(const EdgeVector *outgoing, const std::vector< int > &availableLanes, const std::vector< int > *priorities)
add some straight connections
Definition: NBEdge.cpp:2406
void disableConnection4TLS(int fromLane, NBEdge *toEdge, int toLane)
disable connections for TLS
Definition: NBEdge.cpp:2769
PositionVector viaShape
shape of via
Definition: NBEdge.h:230
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:384
bool hasAccelLane() const
whether one of the lanes is an acceleration lane
Definition: NBEdge.cpp:1987
EdgeVector mySuccessors
Definition: NBEdge.h:1546
const PositionVector & getLaneShape(int i) const
Returns the shape of the nth lane.
Definition: NBEdge.cpp:823
const EdgeVector & getIncomingEdges() const
Returns this node&#39;s incoming edges (The edges which yield in this node)
Definition: NBNode.h:249
PositionVector myToBorder
Definition: NBEdge.h:1538
#define M_PI
Definition: odrSpiral.cpp:40
double getCrossingAngle(NBNode *node)
return the angle for computing pedestrian crossings at the given node
Definition: NBEdge.cpp:3365
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:302
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:34
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:1598
double getTotalWidth() const
Returns the combined width of all lanes of this edge.
Definition: NBEdge.cpp:3146
static const int UNSPECIFIED_INTERNAL_LANE_INDEX
internal lane computation not yet done
Definition: NBEdge.h:277
void setPreferredVehicleClass(SVCPermissions permissions, int lane=-1)
set preferred Vehicle Class
Definition: NBEdge.cpp:3265
double mySignalOffset
the offset of a traffic light signal from the end of this edge (-1 for None)
Definition: NBEdge.h:1533
The edge has been loaded and connections shall not be added.
Definition: NBEdge.h:84
bool hasCustomLaneShape() const
whether one of the lanes has a custom shape
Definition: NBEdge.cpp:1998
std::vector< Connection > myConnectionsToDelete
List of connections marked for delayed removal.
Definition: NBEdge.h:1470
double contPos
custom position for internal junction on this connection
Definition: NBEdge.h:203
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 ...
std::vector< std::string > foeIncomingLanes
FOE Incomings lanes.
Definition: NBEdge.h:236
bool uncontrolled
check if Connection is uncontrolled
Definition: NBEdge.h:242
void setJunctionPriority(const NBNode *const node, int prio)
Sets the junction priority of the edge.
Definition: NBEdge.cpp:1739
SumoXMLNodeType getType() const
Returns the type of this node.
Definition: NBNode.h:266
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
double angleAt2D(int pos) const
get angle in certain position of position vector
void addBikeLane(double width)
add a bicycle lane of the given width and shift existing connctions
Definition: NBEdge.cpp:3418
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:79
const EdgeVector * getConnectedSorted()
Returns the list of outgoing edges without the turnaround sorted in clockwise direction.
Definition: NBEdge.cpp:1145
void restoreRestrictedLane(SUMOVehicleClass vclass, std::vector< NBEdge::Lane > oldLanes, PositionVector oldGeometry, std::vector< NBEdge::Connection > oldConnections)
restore a restricted lane
Definition: NBEdge.cpp:3464
void sortOutgoingConnectionsByIndex()
sorts the outgoing connections by their from-lane-index and their to-lane-index
Definition: NBEdge.cpp:1227
bool needsCont(const NBEdge *fromE, const NBEdge *otherFromE, const NBEdge::Connection &c, const NBEdge::Connection &otherC) const
whether an internal junction should be built at from and respect other
Definition: NBNode.cpp:751
const std::string SUMO_PARAM_ORIGID
std::string myType
The type of the edge.
Definition: NBEdge.h:1443
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge&#39;s lateral offset shal...
void append(NBEdge *continuation)
append another edge
Definition: NBEdge.cpp:2915
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
Definition: NBEdge.cpp:2632
The connection was computed.
Definition: NBEdge.h:105
const double SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
Definition: StdDefs.h:52
const Position & getPosition() const
Definition: NBNode.h:241
EdgeVector edges
The edges being crossed.
Definition: NBNode.h:131
int getFromLane() const
returns the from-lane
Represents a single node (junction) during network building.
Definition: NBNode.h:68
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
MainDirections(const EdgeVector &outgoing, NBEdge *parent, NBNode *to, int indexOfStraightest)
constructor
Definition: NBEdge.cpp:176
void dismissVehicleClassInformation()
dimiss vehicle class information
Definition: NBEdge.cpp:3300
Lanes to lanes - relationships are computed; no recheck is necessary/wished.
Definition: NBEdge.h:94
A definition of a pedestrian crossing.
Definition: NBNode.h:125
const NBConstEdgePairVector & getViaSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges for the given vClass.
Definition: NBEdge.cpp:3569
void replaceInConnections(NBEdge *which, NBEdge *by, int laneOff)
replace in current connections of edge
Definition: NBEdge.cpp:1328
EdgeVector getConnectedEdges() const
Returns the list of outgoing edges unsorted.
Definition: NBEdge.cpp:1182
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:233
static void compute(BresenhamCallBack *callBack, const int val1, const int val2)
Definition: Bresenham.cpp:34
Direction
enum of possible directions
Definition: NBEdge.h:1337
const EdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges for the given vClass.
Definition: NBEdge.cpp:3551
void preferVehicleClass(int lane, SUMOVehicleClass vclass)
prefer certain vehicle class
Definition: NBEdge.cpp:3109
void checkGeometry(const double maxAngle, const double minRadius, bool fix)
Check the angles of successive geometry segments.
Definition: NBEdge.cpp:896
#define NUMERICAL_EPS
Definition: config.h:148
void push_back_noDoublePos(const Position &p)
insert in back a non double position
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:1579
void allowVehicleClass(int lane, SUMOVehicleClass vclass)
set allowed class for the given lane or for all lanes if -1 is given
Definition: NBEdge.cpp:3083
int getTLIndex() const
returns the index within the controlling tls or InvalidTLIndex if this link is unontrolled ...
Definition: NBConnection.h:94
void insertConnection(NBEdge::Connection connection)
insert a previously created NBEdge::connection
Definition: NBEdge.cpp:1079
void addGeometryPoint(int index, const Position &p)
Adds a further geometry point.
Definition: NBEdge.cpp:835
void shiftToLanesToEdge(NBEdge *to, int laneOff)
modifify the toLane for all connections to the given edge
Definition: NBEdge.cpp:3487
void computeAngle()
computes the angle of this edge and stores it in myAngle
Definition: NBEdge.cpp:1847
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:429
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:60
bool computeEdge2Edges(bool noLeftMovers)
computes the edge (step1: computation of approached edges)
Definition: NBEdge.cpp:2034
std::string getInternalLaneID() const
get ID of internal lane
Definition: NBEdge.cpp:78
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:2799
static T maxValue(const std::vector< T > &v)
Definition: VectorHelper.h:91
static double angleDiff(const double angle1, const double angle2)
Returns the difference of the second angle to the first angle in radiants.
Definition: GeomHelper.cpp:167
bool haveVia
check if Connection have a Via
Definition: NBEdge.h:224
double getLoadedLength() const
Returns the length was set explicitly or the computed length if it wasn&#39;t set.
Definition: NBEdge.h:492
void add(double xoff, double yoff, double zoff)
void setLaneSpreadFunction(LaneSpreadFunction spread)
(Re)sets how the lanes lateral offset shall be computed
Definition: NBEdge.cpp:829
double myLength
The length of the edge.
Definition: NBEdge.h:1449
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:243
void divideSelectedLanesOnEdges(const EdgeVector *outgoing, const std::vector< int > &availableLanes, const std::vector< int > *priorities)
divide selected lanes on edges
Definition: NBEdge.cpp:2292
PositionVector computeLaneShape(int lane, double offset) const
Computes the shape for the given lane.
Definition: NBEdge.cpp:1835
double getShapeEndAngle() const
Returns the angle at the end of the edge.
Definition: NBEdge.cpp:1907
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
double myLoadedLength
An optional length to use (-1 if not valid)
Definition: NBEdge.h:1508
void closePolygon()
ensures that the last position equals the first
Lanes to edges - relationships are computed/loaded.
Definition: NBEdge.h:90
std::string myStreetName
The street name (or whatever arbitrary string you wish to attach)
Definition: NBEdge.h:1527
NBNode * myFrom
The source and the destination node.
Definition: NBEdge.h:1446
bool canMoveConnection(const Connection &con, int newFromLane) const
whether the connection can originate on newFromLane
Definition: NBEdge.cpp:1410
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:1111
bool isNearEnough2BeJoined2(NBEdge *e, double threshold) const
Check if edge is near enought to be joined to another edge.
Definition: NBEdge.cpp:2982
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:436
std::vector< int > foeInternalLinks
FOE Internal links.
Definition: NBEdge.h:233
~MainDirections()
destructor
Definition: NBEdge.cpp:224
static bool isTrafficLight(SumoXMLNodeType type)
return whether the given type is a traffic light
Definition: NBNode.cpp:3010
void shiftPositionAtNode(NBNode *node, NBEdge *opposite)
shift geometry at the given node to avoid overlap
Definition: NBEdge.cpp:3498
bool intersects(const Position &p1, const Position &p2) const
Returns the information whether this list of points interesects the given line.
void disallowVehicleClass(int lane, SUMOVehicleClass vclass)
set disallowed class for the given lane or for all lanes if -1 is given
Definition: NBEdge.cpp:3096
void copyConnectionsFrom(NBEdge *src)
copy connections from antoher edge
Definition: NBEdge.cpp:1403
A class that being a bresenham-callback assigns the incoming lanes to the edges.
Definition: NBEdge.h:1294
void setLaneWidth(int lane, double width)
set lane specific width (negative lane implies set for all lanes)
Definition: NBEdge.cpp:3122
void reshiftPosition(double xoff, double yoff)
Applies an offset to the edge.
Definition: NBEdge.cpp:494
const std::map< NBEdge *, std::vector< int > > & getBuiltConnections() const
get built connections
Definition: NBEdge.h:1314
void setz(double z)
set position z
Definition: Position.h:81
NBEdge::Lane getFirstNonPedestrianLane(int direction) const
get first non-pedestrian lane
Definition: NBEdge.cpp:3381
bool splitGeometry(NBEdgeCont &ec, NBNodeCont &nc)
Splits this edge at geometry points.
Definition: NBEdge.cpp:845