57 #ifdef CHECK_MEMORY_LEAKS
59 #endif // CHECK_MEMORY_LEAKS
84 assert(myTransitions.size() > virtEdge);
86 NBEdge* succEdge = myTransitions[virtEdge];
87 std::vector<unsigned int> lanes;
91 std::map<NBEdge*, std::vector<unsigned int> >::iterator i =
myConnections.find(succEdge);
99 std::vector<unsigned int>::iterator j = find(lanes.begin(), lanes.end(), lane);
100 if (j == lanes.end()) {
102 lanes.push_back(lane);
115 if (outgoing.size() == 0) {
119 assert(outgoing.size() > 0);
124 if (outgoing.back()->getJunctionPriority(to) == 1) {
130 if (outgoing.back()->getPriority() > tmp[0]->getPriority()) {
133 if (outgoing.back()->getNumLanes() > tmp[0]->getNumLanes()) {
142 NBEdge* edge = *(tmp.begin());
155 return myDirs.empty();
161 return find(myDirs.begin(), myDirs.end(), d) != myDirs.end();
181 std::string type,
SUMOReal speed,
unsigned int nolanes,
183 const std::string& streetName,
198 init(nolanes,
false);
203 std::string type,
SUMOReal speed,
unsigned int nolanes,
206 const std::string& streetName,
211 myFrom(from), myTo(to),
212 myStartAngle(0), myEndAngle(0), myTotalAngle(0),
213 myPriority(priority), mySpeed(speed),
214 myTurnDestination(0),
215 myFromJunctionPriority(-1), myToJunctionPriority(-1),
216 myGeom(geom), myLaneSpreadFunction(spread), myEndOffset(offset), myLaneWidth(laneWidth),
217 myLoadedLength(UNSPECIFIED_LOADED_LENGTH), myAmLeftHand(false),
218 myAmInnerEdge(false), myAmMacroscopicConnector(false),
219 myStreetName(streetName),
220 mySignalOffset(UNSPECIFIED_SIGNAL_OFFSET) {
221 init(nolanes, tryIgnoreNodePositions);
228 myType(tpl->getTypeID()),
229 myFrom(from), myTo(to),
230 myStartAngle(0), myEndAngle(0), myTotalAngle(0),
231 myPriority(tpl->getPriority()), mySpeed(tpl->getSpeed()),
232 myTurnDestination(0),
233 myFromJunctionPriority(-1), myToJunctionPriority(-1),
235 myLaneSpreadFunction(tpl->getLaneSpreadFunction()),
236 myEndOffset(tpl->getEndOffset()),
237 myLaneWidth(tpl->getLaneWidth()),
238 myLoadedLength(UNSPECIFIED_LOADED_LENGTH),
240 myAmInnerEdge(false),
241 myAmMacroscopicConnector(false),
242 myStreetName(tpl->getStreetName()),
243 mySignalOffset(to == tpl->myTo ? tpl->mySignalOffset : UNSPECIFIED_SIGNAL_OFFSET) {
250 if (to == tpl->
myTo) {
259 SUMOReal speed,
unsigned int nolanes,
int priority,
261 const std::string& streetName,
263 bool tryIgnoreNodePositions) {
285 init(nolanes, tryIgnoreNodePositions);
292 if (from == 0 || to == 0) {
293 throw ProcessError(
"At least one of edge's '" +
myID +
"' nodes is not known.");
315 throw ProcessError(
"At least one of edge's '" +
myID +
"' nodes is not known.");
321 if (!tryIgnoreNodePositions ||
myGeom.size() < 2) {
336 WRITE_ERROR(
"Edge's '" +
myID +
"' from- and to-node are at the same position.");
344 assert(
myGeom.size() >= 2);
346 for (
unsigned int i = 0; i < noLanes; i++) {
361 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
362 myLanes[i].shape.reshiftRotate(xoff, yoff, 0);
407 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
411 if (shape.size() >= 2) {
422 assert(shape.size() >= 2);
423 assert(shape.
length() > 0);
428 Line lc(shape[0], shape[-1]);
429 Line lo(old[0], old[-1]);
438 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
439 assert(
myLanes[i].shape.length() > 0);
440 avgLength +=
myLanes[i].shape.length();
456 assert(pbv.size() > 0);
460 ns[0].set(ns[0].x(), ns[0].y(), startNode->
getPosition().
z());
465 assert(pbv.size() > 0);
516 NBEdge* currentEdge =
this;
517 for (
int i = 1; i < (
int)
myGeom.size() - 1; i++) {
519 if (i != (
int)
myGeom.size() - 2) {
520 std::string nodename =
myID +
"_in_between#" +
toString(i);
522 throw ProcessError(
"Error on adding in-between node '" + nodename +
"'.");
530 currentEdge->
myTo = newTo;
533 std::string edgename =
myID +
"[" +
toString(i - 1) +
"]";
537 if (!ec.
insert(currentEdge,
true)) {
538 throw ProcessError(
"Error on adding splitted edge '" + edgename +
"'.");
563 std::vector<SUMOReal> angles;
565 for (
int i = 0; i < (
int)
myGeom.size() - 1; ++i) {
570 for (
int i = 0; i < (
int)angles.size() - 1; ++i) {
573 if (maxAngle > 0 && relAngle > maxAngle) {
579 if (i == 0 || i == (
int)angles.size() - 2) {
580 const bool start = i == 0;
584 if (minRadius > 0 && r < minRadius) {
587 (start ?
"start" :
"end") +
" of edge " +
getID());
593 (start ?
"start" :
"end") +
" of edge " +
getID());
630 bool mayUseSameDestination,
631 bool mayDefinitelyPass) {
644 setConnection(from, dest, toLane, type, mayUseSameDestination, mayDefinitelyPass);
651 NBEdge* dest,
unsigned int toLane,
653 bool invalidatePrevious,
654 bool mayDefinitelyPass) {
655 if (invalidatePrevious) {
659 for (
unsigned int i = 0; i < no && ok; i++) {
669 bool mayUseSameDestination,
670 bool mayDefinitelyPass) {
698 if ((*i).toEdge == destEdge && ((*i).fromLane == -1 || (*i).toLane == -1)) {
705 if (mayDefinitelyPass) {
725 std::vector<NBEdge::Connection>
727 std::vector<NBEdge::Connection> ret;
729 if ((*i).fromLane == static_cast<int>(lane)) {
764 if (find(outgoing.begin(), outgoing.end(), (*i).toEdge) == outgoing.end()) {
765 outgoing.push_back((*i).toEdge);
770 unsigned int size = (
unsigned int) outgoing.size();
772 edges->reserve(size);
773 for (EdgeVector::const_iterator i = outgoing.begin(); i != outgoing.end(); i++) {
776 edges->push_back(outedge);
788 if (find(ret.begin(), ret.end(), (*i).toEdge) == ret.end()) {
789 ret.push_back((*i).toEdge);
798 std::vector<int> ret;
801 if ((*i).toEdge == currentOutgoing) {
802 ret.push_back((*i).fromLane);
825 for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
830 for (EdgeVector::iterator j = connected.begin(); j != connected.end(); j++) {
844 && (fromLane < 0 || c.
fromLane == fromLane)
845 && (toLane < 0 || c.
toLane == toLane)) {
866 if (reallowSetting) {
879 if ((*i).toEdge == which) {
891 std::map<int, int> laneMap;
895 bool wasConnected =
false;
897 if ((*i).toEdge != which) {
901 if ((*i).fromLane != -1) {
902 int fromLane = (*i).fromLane;
903 laneMap[(*i).toLane] = fromLane;
904 if (minLane == -1 || minLane > fromLane) {
907 if (maxLane == -1 || maxLane < fromLane) {
918 std::vector<NBEdge::Connection> conns = origConns;
919 for (std::vector<NBEdge::Connection>::iterator i = conns.begin(); i != conns.end(); ++i) {
920 if ((*i).toEdge == which) {
923 int fromLane = (*i).fromLane;
925 if (laneMap.find(fromLane) == laneMap.end()) {
926 if (fromLane >= 0 && fromLane <= minLane) {
929 if (fromLane >= 0 && fromLane >= maxLane) {
933 toUse = laneMap[fromLane];
955 return (common > 0 && (!buildCrossingsAndWalkingAreas || common !=
SVC_PEDESTRIAN));
961 unsigned int index = 0;
977 std::vector<Connection>::iterator i =
myConnections.begin() + index;
997 if ((*i).fromLane == (
int)lane &&
canMoveConnection(*i, lane - 1, buildCrossingsAndWalkingAreas)) {
1010 std::string innerID =
":" + n.
getID();
1012 unsigned int edgeIndex = linkIndex;
1013 unsigned int internalLaneIndex = 0;
1020 if (con.
toEdge != toEdge) {
1023 edgeIndex = linkIndex;
1024 toEdge = (*i).toEdge;
1025 internalLaneIndex = 0;
1028 std::vector<unsigned int> foeInternalLinks;
1036 std::pair<SUMOReal, std::vector<unsigned int> > crossingPositions(-1, std::vector<unsigned int>());
1037 std::set<std::string> tmpFoeIncomingLanes;
1042 unsigned int index = 0;
1044 for (EdgeVector::const_iterator i2 = incoming.begin(); i2 != incoming.end(); ++i2) {
1045 const std::vector<Connection>& elv = (*i2)->getConnections();
1046 for (std::vector<NBEdge::Connection>::const_iterator k2 = elv.begin(); k2 != elv.end(); k2++) {
1047 if ((*k2).toEdge == 0) {
1050 bool needsCont = n.
needsCont(
this, con.
toEdge, *i2, (*k2).toEdge, *k2);
1053 crossingPositions.second.push_back(index);
1056 if (dv.size() > 0) {
1060 if (crossingPositions.first < 0 || crossingPositions.first > minDV) {
1061 crossingPositions.first = minDV;
1067 if (n.
foes(
this, con.
toEdge, *i2, (*k2).toEdge)) {
1068 foeInternalLinks.push_back(index);
1073 tmpFoeIncomingLanes.insert((*i2)->getID() +
"_" +
toString((*k2).fromLane));
1079 const std::vector<NBNode::Crossing>& crossings = n.
getCrossings();
1080 for (std::vector<NBNode::Crossing>::const_iterator it_c = crossings.begin(); it_c != crossings.end(); ++it_c) {
1081 for (EdgeVector::const_iterator it_e = (*it_c).edges.begin(); it_e != (*it_c).edges.end(); ++it_e) {
1082 const NBEdge* edge = *it_e;
1084 if (
this == edge || con.
toEdge == edge) {
1085 foeInternalLinks.push_back(index);
1116 assert(shape.size() >= 2);
1118 if (crossingPositions.first >= 0) {
1119 std::pair<PositionVector, PositionVector> split = shape.
splitAt(crossingPositions.first);
1120 con.
id = innerID +
"_" +
toString(edgeIndex);
1121 con.
shape = split.first;
1124 con.
viaID = innerID +
"_" +
toString(splitIndex + noInternalNoSplits);
1130 con.
id = innerID +
"_" +
toString(edgeIndex);
1135 ++internalLaneIndex;
1167 assert(atNode ==
myTo);
1192 std::vector<SUMOReal> offsets;
1193 for (
unsigned int i = 0; i <
myLanes.size(); ++i) {
1194 offsets.push_back(0);
1197 for (
int i = (
int)
myLanes.size() - 2; i >= 0; --i) {
1199 offsets[i] = offset;
1206 for (
unsigned int i = 0; i <
myLanes.size(); ++i) {
1212 for (
unsigned int i = 0; i <
myLanes.size(); ++i) {
1213 offsets[i] += offset;
1220 for (
unsigned int i = 0; i <
myLanes.size(); ++i) {
1224 WRITE_WARNING(
"In edge '" +
getID() +
"': lane shape could not be determined (" + e.what() +
")");
1234 bool haveWarned =
false;
1235 for (
int i = 0; i < (
int)
myGeom.size(); i++) {
1239 std::pair<SUMOReal, SUMOReal> offsets =
laneOffset(from, to, offset,
false);
1242 Position(from.
x() - offsets.first, from.
y() - offsets.second, from.
z()));
1243 }
else if (i == static_cast<int>(
myGeom.size() - 1)) {
1246 std::pair<SUMOReal, SUMOReal> offsets =
laneOffset(from, to, offset,
false);
1249 Position(to.
x() - offsets.first, to.
y() - offsets.second, to.
z()));
1254 std::pair<SUMOReal, SUMOReal> offsets =
laneOffset(from, me, offset,
false);
1255 std::pair<SUMOReal, SUMOReal> offsets2 =
laneOffset(me, to, offset,
false);
1257 Position(from.
x() - offsets.first, from.
y() - offsets.second),
1258 Position(me.
x() - offsets.first, me.
y() - offsets.second));
1261 Position(me.
x() - offsets2.first, me.
y() - offsets2.second),
1262 Position(to.
x() - offsets2.first, to.
y() - offsets2.second));
1264 if (angle < 10. || angle > 350.) {
1267 Position(me.
x() - offsets.first, me.
y() - offsets.second, me.
z()));
1292 std::pair<SUMOReal, SUMOReal>
1296 return std::pair<SUMOReal, SUMOReal>(-offsets.first, -offsets.second);
1298 return std::pair<SUMOReal, SUMOReal>(offsets.first, offsets.second);
1331 fromCenter.
x(), fromCenter.
y(),
1332 referencePosStart.x(), referencePosStart.y());
1335 referencePosEnd.x(), referencePosEnd.y(),
1336 toCenter.
x(), toCenter.
y());
1346 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1347 if ((*i).permissions !=
SVCAll) {
1357 std::vector<Lane>::const_iterator i =
myLanes.begin();
1360 for (; i !=
myLanes.end(); ++i) {
1361 if (i->permissions != firstLanePermissions) {
1371 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1372 if (i->width !=
myLanes.begin()->width) {
1382 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1393 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1394 if (i->endOffset !=
myLanes.begin()->endOffset) {
1418 for (EdgeVector::const_iterator i = o.begin(); i != o.end(); ++i) {
1456 std::vector<unsigned int> connNumbersPerLane(
myLanes.size(), 0);
1458 if ((*i).toEdge == 0 || (*i).fromLane < 0 || (*i).toLane < 0) {
1461 if ((*i).fromLane >= 0) {
1462 ++connNumbersPerLane[(*i).fromLane];
1473 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1475 if (i > 0 && connNumbersPerLane[i - 1] > 1) {
1477 }
else if (i <
myLanes.size() - 1 && connNumbersPerLane[i + 1] > 1) {
1493 if (outgoing->size() == 0) {
1505 std::vector<int> availableLanes;
1506 for (
int i = 0; i < (
int)
myLanes.size(); ++i) {
1511 availableLanes.push_back(i);
1515 unsigned int size = (
unsigned int) outgoing->size();
1516 std::vector<SUMOReal> resultingLanes;
1517 resultingLanes.reserve(size);
1521 for (i = 0; i < size; i++) {
1528 if (res > availableLanes.size()) {
1529 res = (
SUMOReal) availableLanes.size();
1532 resultingLanes.push_back(res);
1533 sumResulting += res;
1534 if (minResulting > res && res > 0) {
1543 sumResulting += minResulting / (
SUMOReal) 2.;
1544 unsigned int noVirtual = (
unsigned int)(sumResulting / minResulting);
1547 transition.reserve(size);
1548 for (i = 0; i < size; i++) {
1551 assert(i < resultingLanes.size());
1553 for (
SUMOReal j = 0; j < tmpNo; j++) {
1554 assert(outgoing->size() > i);
1555 transition.push_back((*outgoing)[i]);
1561 Bresenham::compute(&adder, static_cast<unsigned int>(availableLanes.size()), noVirtual);
1562 const std::map<NBEdge*, std::vector<unsigned int> >& l2eConns = adder.
getBuiltConnections();
1564 for (std::map<
NBEdge*, std::vector<unsigned int> >::const_iterator i = l2eConns.begin(); i != l2eConns.end(); ++i) {
1565 const std::vector<unsigned int> lanes = (*i).second;
1566 for (std::vector<unsigned int>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
1567 const int fromIndex = availableLanes[*j];
1568 if ((
getPermissions(fromIndex) & (*i).first->getPermissions()) == 0) {
1587 std::vector<unsigned int>*
1590 std::vector<unsigned int>* priorities =
new std::vector<unsigned int>();
1591 if (outgoing->size() == 0) {
1594 priorities->reserve(outgoing->size());
1595 EdgeVector::const_iterator i;
1596 for (i = outgoing->begin(); i != outgoing->end(); i++) {
1597 int prio = (*i)->getJunctionPriority(
myTo);
1598 assert((prio + 1) * 2 > 0);
1599 prio = (prio + 1) * 2;
1600 priorities->push_back(prio);
1608 i = find(outgoing->begin(), outgoing->end(), *(tmp.begin()));
1609 unsigned int dist = (
unsigned int) distance(outgoing->begin(), i);
1611 assert(priorities->size() > 0);
1612 (*priorities)[0] = (*priorities)[0] / 2;
1617 if (mainDirections.
empty()) {
1618 assert(dist < priorities->size());
1619 (*priorities)[dist] = (*priorities)[dist] * 2;
1622 (*priorities)[dist] = (*priorities)[dist] * 2;
1631 unsigned int sum = 0;
1632 for (std::vector<unsigned int>::iterator i = priorities->begin(); i != priorities->end(); i++) {
1671 if (thisFromAngle2 < otherToAngle2) {
1672 std::swap(thisFromAngle2, otherToAngle2);
1674 if (thisFromAngle2 - otherToAngle2 > 170 && thisFromAngle2 - otherToAngle2 < 190) {
1685 if (pos < tolerance) {
1699 for (
unsigned int i = 0; i < lanes; i++) {
1701 for (std::vector<NBEdge::Connection>::iterator j = elv.begin(); j != elv.end(); j++) {
1703 assert(el.
tlID ==
"");
1751 assert(fromLane < 0 || fromLane < (
int)
myLanes.size());
1753 if (fromLane >= 0 && toLane >= 0) {
1755 std::vector<Connection>::iterator i =
1763 connection.
tlID = tlID;
1770 unsigned int no = 0;
1771 bool hadError =
false;
1773 if ((*i).toEdge != toEdge) {
1776 if (fromLane >= 0 && fromLane != (*i).fromLane) {
1779 if (toLane >= 0 && toLane != (*i).toLane) {
1782 if ((*i).tlID ==
"") {
1784 (*i).tlLinkNo = tlIndex;
1787 if ((*i).tlID != tlID && static_cast<int>((*i).tlLinkNo) == tlIndex) {
1788 WRITE_WARNING(
"The lane " + toString<int>((*i).fromLane) +
" on edge " +
getID() +
" already had a traffic light signal.");
1793 if (hadError && no == 0) {
1794 WRITE_WARNING(
"Could not set any signal of the traffic light '" + tlID +
"' (unknown group)");
1887 if (find(conn.begin(), conn.end(), possContinuation)
1904 if (conns.size() !=
myLanes.size()) {
1920 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1943 if ((*i).toEdge == e && (*i).tlID !=
"") {
1959 assert(lane <
myLanes.size());
1973 assert(distances.size() > 0);
1980 unsigned int newLaneNo = (
unsigned int)
myLanes.size() + by;
1981 while (
myLanes.size() < newLaneNo) {
1986 for (EdgeVector::const_iterator i = incs.begin(); i != incs.end(); ++i) {
1987 (*i)->invalidateConnections(
true);
1995 unsigned int newLaneNo = (
unsigned int)
myLanes.size() - by;
1996 while (
myLanes.size() > newLaneNo) {
2001 for (EdgeVector::const_iterator i = incs.begin(); i != incs.end(); ++i) {
2002 (*i)->invalidateConnections(
true);
2008 assert(outs.size() == 1);
2029 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2033 assert(lane < (
int)
myLanes.size());
2034 myLanes[lane].permissions |= vclass;
2042 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2046 assert(lane < (
int)
myLanes.size());
2047 myLanes[lane].permissions &= ~vclass;
2055 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2059 assert(lane < (
int)
myLanes.size());
2060 myLanes[lane].preferred |= vclass;
2070 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2076 assert(lane < (
int)
myLanes.size());
2100 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2106 assert(lane < (
int)
myLanes.size());
2107 myLanes[lane].endOffset = offset;
2116 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2122 assert(lane < (
int)
myLanes.size());
2130 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2135 assert(lane < (
int)
myLanes.size());
2136 myLanes[lane].permissions = permissions;
2144 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2149 assert(lane < (
int)
myLanes.size());
2150 myLanes[lane].preferred = permissions;
2159 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2164 assert(lane < (
int)
myLanes.size());
2165 return myLanes[lane].permissions;
2178 for (std::vector<Lane>::iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
2179 (*i).permissions =
SVCAll;
2202 for (
int i = start; i != end; i += direction) {
2221 std::cout <<
getID() <<
" angle=" <<
getAngleAtNode(node) <<
" convAngle=" << angle <<
"\n";
2254 for (EdgeVector::const_iterator it = incoming.begin(); it != incoming.end(); ++it) {
2255 (*it)->shiftToLanesToEdge(
this, 1);
2267 if ((*it).toEdge == to && (*it).toLane >= 0) {
2268 (*it).toLane += laneOff;