57 #ifdef CHECK_MEMORY_LEAKS
59 #endif // CHECK_MEMORY_LEAKS
83 assert(myTransitions.size() > virtEdge);
85 NBEdge* succEdge = myTransitions[virtEdge];
86 std::vector<unsigned int> lanes;
90 std::map<NBEdge*, std::vector<unsigned int> >::iterator i =
myConnections.find(succEdge);
98 std::vector<unsigned int>::iterator j = find(lanes.begin(), lanes.end(), lane);
99 if (j == lanes.end()) {
101 lanes.push_back(lane);
114 if (outgoing.size() == 0) {
118 assert(outgoing.size() > 0);
123 if (outgoing.back()->getJunctionPriority(to) == 1) {
129 if (outgoing.back()->getPriority() > tmp[0]->getPriority()) {
132 if (outgoing.back()->getNumLanes() > tmp[0]->getNumLanes()) {
141 NBEdge* edge = *(tmp.begin());
154 return myDirs.empty();
160 return find(myDirs.begin(), myDirs.end(), d) != myDirs.end();
180 std::string type,
SUMOReal speed,
unsigned int nolanes,
182 const std::string& streetName,
196 init(nolanes,
false);
201 std::string type,
SUMOReal speed,
unsigned int nolanes,
204 const std::string& streetName,
209 myFrom(from), myTo(to),
210 myStartAngle(0), myEndAngle(0), myTotalAngle(0),
211 myPriority(priority), mySpeed(speed),
212 myTurnDestination(0),
213 myFromJunctionPriority(-1), myToJunctionPriority(-1),
214 myGeom(geom), myLaneSpreadFunction(spread), myOffset(offset), myLaneWidth(laneWidth),
215 myLoadedLength(UNSPECIFIED_LOADED_LENGTH), myAmLeftHand(false),
216 myAmInnerEdge(false), myAmMacroscopicConnector(false),
217 myStreetName(streetName) {
218 init(nolanes, tryIgnoreNodePositions);
225 myType(tpl->getTypeID()),
226 myFrom(from), myTo(to),
227 myStartAngle(0), myEndAngle(0), myTotalAngle(0),
228 myPriority(tpl->getPriority()), mySpeed(tpl->getSpeed()),
229 myTurnDestination(0),
230 myFromJunctionPriority(-1), myToJunctionPriority(-1),
231 myLaneSpreadFunction(tpl->getLaneSpreadFunction()),
232 myOffset(tpl->getOffset()),
233 myLaneWidth(tpl->getLaneWidth()),
234 myLoadedLength(UNSPECIFIED_LOADED_LENGTH), myAmLeftHand(false),
235 myAmInnerEdge(false), myAmMacroscopicConnector(false),
236 myStreetName(tpl->getStreetName()) {
247 SUMOReal speed,
unsigned int nolanes,
int priority,
249 const std::string& streetName,
251 bool tryIgnoreNodePositions) {
273 init(nolanes, tryIgnoreNodePositions);
280 if (from == 0 || to == 0) {
281 throw ProcessError(
"At least one of edge's '" +
myID +
"' nodes is not known.");
302 throw ProcessError(
"At least one of edge's '" +
myID +
"' nodes is not known.");
308 if (!tryIgnoreNodePositions ||
myGeom.size() < 2) {
323 WRITE_ERROR(
"Edge's '" +
myID +
"' from- and to-node are at the same position.");
331 assert(
myGeom.size() >= 2);
333 for (
unsigned int i = 0; i < noLanes; i++) {
348 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
349 myLanes[i].shape.reshiftRotate(xoff, yoff, 0);
393 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
397 if (shape.size() >= 2) {
408 assert(shape.size() >= 2);
409 assert(shape.
length() > 0);
414 Line lc(shape[0], shape[-1]);
415 Line lo(old[0], old[-1]);
424 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
425 assert(
myLanes[i].shape.length() > 0);
426 avgLength +=
myLanes[i].shape.length();
441 assert(pbv.size() > 0);
445 ns[0].set(ns[0].x(), ns[0].y(), startNode->
getPosition().
z());
450 assert(pbv.size() > 0);
501 NBEdge* currentEdge =
this;
502 for (
int i = 1; i < (
int)
myGeom.size() - 1; i++) {
504 if (i != (
int)
myGeom.size() - 2) {
505 std::string nodename =
myID +
"_in_between#" +
toString(i);
507 throw ProcessError(
"Error on adding in-between node '" + nodename +
"'.");
515 currentEdge->
myTo = newTo;
518 std::string edgename =
myID +
"[" +
toString(i - 1) +
"]";
522 if (!ec.
insert(currentEdge,
true)) {
523 throw ProcessError(
"Error on adding splitted edge '" + edgename +
"'.");
548 std::vector<SUMOReal> angles;
550 for (
int i = 0; i < (
int)
myGeom.size() - 1; ++i) {
555 for (
int i = 0; i < (
int)angles.size() - 1; ++i) {
558 if (maxAngle > 0 && relAngle > maxAngle) {
564 if (i == 0 || i == (
int)angles.size() - 2) {
565 const bool start = i == 0;
569 if (minRadius > 0 && r < minRadius) {
572 (start ?
"start" :
"end") +
" of edge " +
getID());
578 (start ?
"start" :
"end") +
" of edge " +
getID());
615 bool mayUseSameDestination,
616 bool mayDefinitelyPass) {
629 setConnection(from, dest, toLane, type, mayUseSameDestination, mayDefinitelyPass);
636 NBEdge* dest,
unsigned int toLane,
638 bool invalidatePrevious,
639 bool mayDefinitelyPass) {
640 if (invalidatePrevious) {
644 for (
unsigned int i = 0; i < no && ok; i++) {
654 bool mayUseSameDestination,
655 bool mayDefinitelyPass) {
683 if ((*i).toEdge == destEdge && ((*i).fromLane == -1 || (*i).toLane == -1)) {
690 if (mayDefinitelyPass) {
710 std::vector<NBEdge::Connection>
712 std::vector<NBEdge::Connection> ret;
714 if ((*i).fromLane == static_cast<int>(lane)) {
749 if (find(outgoing.begin(), outgoing.end(), (*i).toEdge) == outgoing.end()) {
750 outgoing.push_back((*i).toEdge);
755 unsigned int size = (
unsigned int) outgoing.size();
757 edges->reserve(size);
758 for (EdgeVector::const_iterator i = outgoing.begin(); i != outgoing.end(); i++) {
761 edges->push_back(outedge);
773 if (find(ret.begin(), ret.end(), (*i).toEdge) == ret.end()) {
774 ret.push_back((*i).toEdge);
783 std::vector<int> ret;
786 if ((*i).toEdge == currentOutgoing) {
787 ret.push_back((*i).fromLane);
810 for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
815 for (EdgeVector::iterator j = connected.begin(); j != connected.end(); j++) {
829 && (fromLane < 0 || c.
fromLane == fromLane)
830 && (toLane < 0 || c.
toLane == toLane)) {
851 if (reallowSetting) {
864 if ((*i).toEdge == which) {
876 std::map<int, int> laneMap;
880 bool wasConnected =
false;
882 if ((*i).toEdge != which) {
886 if ((*i).fromLane != -1) {
887 int fromLane = (*i).fromLane;
888 laneMap[(*i).toLane] = fromLane;
889 if (minLane == -1 || minLane > fromLane) {
892 if (maxLane == -1 || maxLane < fromLane) {
903 std::vector<NBEdge::Connection> conns = origConns;
904 for (std::vector<NBEdge::Connection>::iterator i = conns.begin(); i != conns.end(); ++i) {
905 if ((*i).toEdge == which) {
908 int fromLane = (*i).fromLane;
910 if (laneMap.find(fromLane) == laneMap.end()) {
911 if (fromLane >= 0 && fromLane <= minLane) {
914 if (fromLane >= 0 && fromLane >= maxLane) {
918 toUse = laneMap[fromLane];
937 unsigned int index = 0;
951 std::vector<Connection>::iterator i =
myConnections.begin() + index;
971 if ((*i).fromLane == static_cast<int>(lane)) {
984 std::string innerID =
":" + n.
getID();
986 unsigned int edgeIndex = linkIndex;
987 unsigned int internalLaneIndex = 0;
995 if (con.
toEdge != toEdge) {
997 edgeIndex = linkIndex;
998 toEdge = (*i).toEdge;
999 internalLaneIndex = 0;
1002 std::vector<unsigned int> foeInternalLinks;
1005 std::pair<SUMOReal, std::vector<unsigned int> > crossingPositions(-1, std::vector<unsigned int>());
1006 std::set<std::string> tmpFoeIncomingLanes;
1011 unsigned int index = 0;
1013 for (EdgeVector::const_iterator i2 = incoming.begin(); i2 != incoming.end(); ++i2) {
1014 const std::vector<Connection>& elv = (*i2)->getConnections();
1015 for (std::vector<NBEdge::Connection>::const_iterator k2 = elv.begin(); k2 != elv.end(); k2++) {
1016 if ((*k2).toEdge == 0) {
1019 bool needsCont = n.
needsCont(
this, con.
toEdge, *i2, (*k2).toEdge, *k2);
1022 crossingPositions.second.push_back(index);
1025 if (dv.size() > 0) {
1027 if (minDV < shape.
length() - .1 && minDV > .1) {
1029 if (crossingPositions.first < 0 || crossingPositions.first > minDV) {
1030 crossingPositions.first = minDV;
1036 if (n.
foes(
this, con.
toEdge, *i2, (*k2).toEdge)) {
1037 foeInternalLinks.push_back(index);
1042 tmpFoeIncomingLanes.insert((*i2)->getID() +
"_" +
toString((*k2).fromLane));
1047 if (dir ==
LINKDIR_TURN && crossingPositions.first < 0 && crossingPositions.second.size() != 0) {
1070 assert(shape.size() >= 2);
1072 if (crossingPositions.first >= 0) {
1073 std::pair<PositionVector, PositionVector> split = shape.
splitAt(crossingPositions.first);
1074 con.
id = innerID +
"_" +
toString(edgeIndex);
1075 con.
shape = split.first;
1078 con.
viaID = innerID +
"_" +
toString(splitIndex + noInternalNoSplits);
1084 con.
id = innerID +
"_" +
toString(edgeIndex);
1089 ++internalLaneIndex;
1121 assert(atNode ==
myTo);
1146 std::vector<SUMOReal> offsets;
1147 for (
unsigned int i = 0; i <
myLanes.size(); ++i) {
1148 offsets.push_back(0);
1151 for (
int i = (
int)
myLanes.size() - 2; i >= 0; --i) {
1153 offsets[i] = offset;
1161 for (
unsigned int i = 0; i <
myLanes.size(); ++i) {
1167 for (
unsigned int i = 0; i <
myLanes.size(); ++i) {
1168 offsets[i] += offset;
1175 for (
unsigned int i = 0; i <
myLanes.size(); ++i) {
1179 WRITE_WARNING(
"In edge '" +
getID() +
"': lane shape could not be determined (" + e.what() +
")");
1189 bool haveWarned =
false;
1190 for (
int i = 0; i < (
int)
myGeom.size(); i++) {
1194 std::pair<SUMOReal, SUMOReal> offsets =
laneOffset(from, to, offset,
false);
1197 Position(from.
x() - offsets.first, from.
y() - offsets.second, from.
z()));
1198 }
else if (i == static_cast<int>(
myGeom.size() - 1)) {
1201 std::pair<SUMOReal, SUMOReal> offsets =
laneOffset(from, to, offset,
false);
1204 Position(to.
x() - offsets.first, to.
y() - offsets.second, to.
z()));
1209 std::pair<SUMOReal, SUMOReal> offsets =
laneOffset(from, me, offset,
false);
1210 std::pair<SUMOReal, SUMOReal> offsets2 =
laneOffset(me, to, offset,
false);
1212 Position(from.
x() - offsets.first, from.
y() - offsets.second),
1213 Position(me.
x() - offsets.first, me.
y() - offsets.second));
1216 Position(me.
x() - offsets2.first, me.
y() - offsets2.second),
1217 Position(to.
x() - offsets2.first, to.
y() - offsets2.second));
1219 if (angle < 10. || angle > 350.) {
1222 Position(me.
x() - offsets.first, me.
y() - offsets.second, me.
z()));
1247 std::pair<SUMOReal, SUMOReal>
1251 return std::pair<SUMOReal, SUMOReal>(-offsets.first, -offsets.second);
1253 return std::pair<SUMOReal, SUMOReal>(offsets.first, offsets.second);
1266 referencePosStart.
x(), referencePosStart.
y());
1269 referencePosEnd.x(), referencePosEnd.y(),
1279 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1290 std::vector<Lane>::const_iterator i =
myLanes.begin();
1293 for (; i !=
myLanes.end(); ++i) {
1294 if (i->permissions != firstLanePermissions) {
1304 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1305 if (i->width !=
myLanes.begin()->width) {
1315 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1326 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1327 if (i->offset !=
myLanes.begin()->offset) {
1351 for (EdgeVector::const_iterator i = o.begin(); i != o.end(); ++i) {
1389 std::vector<unsigned int> connNumbersPerLane(
myLanes.size(), 0);
1391 if ((*i).toEdge == 0 || (*i).fromLane < 0 || (*i).toLane < 0) {
1394 if ((*i).fromLane >= 0) {
1395 ++connNumbersPerLane[(*i).fromLane];
1406 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1407 if (connNumbersPerLane[i] == 0) {
1408 if (i > 0 && connNumbersPerLane[i - 1] > 1) {
1410 }
else if (i <
myLanes.size() - 1 && connNumbersPerLane[i + 1] > 1) {
1426 if (outgoing->size() == 0) {
1439 unsigned int size = (
unsigned int) outgoing->size();
1440 std::vector<SUMOReal> resultingLanes;
1441 resultingLanes.reserve(size);
1445 for (i = 0; i < size; i++) {
1456 resultingLanes.push_back(res);
1457 sumResulting += res;
1458 if (minResulting > res) {
1466 sumResulting += minResulting / (
SUMOReal) 2.;
1467 unsigned int noVirtual = (
unsigned int)(sumResulting / minResulting);
1470 transition.reserve(size);
1471 for (i = 0; i < size; i++) {
1474 assert(i < resultingLanes.size());
1476 for (
SUMOReal j = 0; j < tmpNo; j++) {
1477 assert(outgoing->size() > i);
1478 transition.push_back((*outgoing)[i]);
1486 const std::map<NBEdge*, std::vector<unsigned int> >& l2eConns = adder.
getBuiltConnections();
1488 for (std::map<
NBEdge*, std::vector<unsigned int> >::const_iterator i = l2eConns.begin(); i != l2eConns.end(); ++i) {
1489 const std::vector<unsigned int> lanes = (*i).second;
1490 for (std::vector<unsigned int>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
1502 std::vector<unsigned int>*
1505 std::vector<unsigned int>* priorities =
new std::vector<unsigned int>();
1506 if (outgoing->size() == 0) {
1509 priorities->reserve(outgoing->size());
1510 EdgeVector::const_iterator i;
1511 for (i = outgoing->begin(); i != outgoing->end(); i++) {
1512 int prio = (*i)->getJunctionPriority(
myTo);
1513 assert((prio + 1) * 2 > 0);
1514 prio = (prio + 1) * 2;
1515 priorities->push_back(prio);
1523 i = find(outgoing->begin(), outgoing->end(), *(tmp.begin()));
1524 unsigned int dist = (
unsigned int) distance(outgoing->begin(), i);
1526 assert(priorities->size() > 0);
1527 (*priorities)[0] = (*priorities)[0] / 2;
1532 if (mainDirections.
empty()) {
1533 assert(dist < priorities->size());
1534 (*priorities)[dist] = (*priorities)[dist] * 2;
1537 (*priorities)[dist] = (*priorities)[dist] * 2;
1546 unsigned int sum = 0;
1547 for (std::vector<unsigned int>::iterator i = priorities->begin(); i != priorities->end(); i++) {
1586 if (thisFromAngle2 < otherToAngle2) {
1587 std::swap(thisFromAngle2, otherToAngle2);
1589 if (thisFromAngle2 - otherToAngle2 > 170 && thisFromAngle2 - otherToAngle2 < 190) {
1600 if (pos < tolerance) {
1614 for (
unsigned int i = 0; i < lanes; i++) {
1616 for (std::vector<NBEdge::Connection>::iterator j = elv.begin(); j != elv.end(); j++) {
1618 assert(el.
tlID ==
"");
1665 assert(fromLane < 0 || fromLane < (
int)
myLanes.size());
1667 if (fromLane >= 0 && toLane >= 0) {
1669 std::vector<Connection>::iterator i =
1677 connection.
tlID = tlID;
1684 unsigned int no = 0;
1685 bool hadError =
false;
1687 if ((*i).toEdge != toEdge) {
1690 if (fromLane >= 0 && fromLane != (*i).fromLane) {
1693 if (toLane >= 0 && toLane != (*i).toLane) {
1696 if ((*i).tlID ==
"") {
1698 (*i).tlLinkNo = tlIndex;
1701 if ((*i).tlID != tlID && static_cast<int>((*i).tlLinkNo) == tlIndex) {
1702 WRITE_WARNING(
"The lane " + toString<int>((*i).fromLane) +
" on edge " +
getID() +
" already had a traffic light signal.");
1707 if (hadError && no == 0) {
1708 WRITE_WARNING(
"Could not set any signal of the traffic light '" + tlID +
"' (unknown group)");
1801 if (find(conn.begin(), conn.end(), possContinuation)
1818 if (conns.size() !=
myLanes.size()) {
1834 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1854 if ((*i).toEdge == e && (*i).tlID !=
"") {
1870 assert(lane <
myLanes.size());
1884 assert(distances.size() > 0);
1891 unsigned int newLaneNo = (
unsigned int)
myLanes.size() + by;
1892 while (
myLanes.size() < newLaneNo) {
1897 for (EdgeVector::const_iterator i = incs.begin(); i != incs.end(); ++i) {
1898 (*i)->invalidateConnections(
true);
1906 unsigned int newLaneNo = (
unsigned int)
myLanes.size() - by;
1907 while (
myLanes.size() > newLaneNo) {
1912 for (EdgeVector::const_iterator i = incs.begin(); i != incs.end(); ++i) {
1913 (*i)->invalidateConnections(
true);
1919 assert(outs.size() == 1);
1940 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1944 assert(lane < (
int)
myLanes.size());
1945 myLanes[lane].permissions |= vclass;
1953 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1957 assert(lane < (
int)
myLanes.size());
1958 myLanes[lane].permissions &= ~vclass;
1966 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1970 assert(lane < (
int)
myLanes.size());
1971 myLanes[lane].preferred |= vclass;
1981 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1987 assert(lane < (
int)
myLanes.size());
2011 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2017 assert(lane < (
int)
myLanes.size());
2018 myLanes[lane].offset = offset;
2027 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2033 assert(lane < (
int)
myLanes.size());
2041 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2046 assert(lane < (
int)
myLanes.size());
2047 myLanes[lane].permissions = permissions;
2055 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2060 assert(lane < (
int)
myLanes.size());
2061 myLanes[lane].preferred = permissions;
2070 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2075 assert(lane < (
int)
myLanes.size());
2076 return myLanes[lane].permissions;
2089 for (std::vector<Lane>::iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {