57 #ifdef CHECK_MEMORY_LEAKS
59 #endif // CHECK_MEMORY_LEAKS
80 std::vector<unsigned int> lanes;
84 std::map<NBEdge*, std::vector<unsigned int> >::iterator i =
myConnections.find(succEdge);
92 std::vector<unsigned int>::iterator j = find(lanes.begin(), lanes.end(), lane);
93 if (j == lanes.end()) {
95 lanes.push_back(lane);
108 if (outgoing.size() == 0) {
112 assert(outgoing.size() > 0);
117 if (outgoing.back()->getJunctionPriority(to) == 1) {
123 if (outgoing.back()->getPriority() > tmp[0]->getPriority()) {
126 if (outgoing.back()->getNumLanes() > tmp[0]->getNumLanes()) {
135 NBEdge* edge = *(tmp.begin());
148 return myDirs.empty();
154 return find(myDirs.begin(), myDirs.end(), d) != myDirs.end();
163 std::string type,
SUMOReal speed,
unsigned int nolanes,
165 const std::string& streetName,
178 init(nolanes,
false);
183 std::string type,
SUMOReal speed,
unsigned int nolanes,
186 const std::string& streetName,
191 myFrom(from), myTo(to), myAngle(0),
192 myPriority(priority), mySpeed(speed),
193 myTurnDestination(0),
194 myFromJunctionPriority(-1), myToJunctionPriority(-1),
195 myGeom(geom), myLaneSpreadFunction(spread), myOffset(offset), myWidth(width),
196 myLoadedLength(UNSPECIFIED_LOADED_LENGTH), myAmLeftHand(false),
197 myAmInnerEdge(false), myAmMacroscopicConnector(false),
198 myStreetName(streetName) {
199 init(nolanes, tryIgnoreNodePositions);
206 myType(tpl->getTypeID()),
207 myFrom(from), myTo(to), myAngle(0),
208 myPriority(tpl->getPriority()), mySpeed(tpl->getSpeed()),
209 myTurnDestination(0),
210 myFromJunctionPriority(-1), myToJunctionPriority(-1),
211 myLaneSpreadFunction(tpl->getLaneSpreadFunction()),
212 myOffset(tpl->getOffset()),
213 myWidth(tpl->getWidth()),
214 myLoadedLength(UNSPECIFIED_LOADED_LENGTH), myAmLeftHand(false),
215 myAmInnerEdge(false), myAmMacroscopicConnector(false),
216 myStreetName(tpl->getStreetName()) {
227 SUMOReal speed,
unsigned int nolanes,
int priority,
229 const std::string& streetName,
231 bool tryIgnoreNodePositions) {
254 init(nolanes, tryIgnoreNodePositions);
264 throw ProcessError(
"At least one of edge's '" +
myID +
"' nodes is not known.");
270 if (!tryIgnoreNodePositions ||
myGeom.
size() < 2) {
285 WRITE_ERROR(
"Edge's '" +
myID +
"' from- and to-node are at the same position.");
299 for (
unsigned int i = 0; i < noLanes; i++) {
313 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
314 myLanes[i].shape.reshiftRotate(xoff, yoff, 0);
357 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
361 if (shape.
size() >= 2) {
366 WRITE_MESSAGE(
"Lane '" +
myID +
"' has calculated shape length near zero. Revert it back to old shape.");
371 Line lc(shape[0], shape[-1]);
372 Line lo(old[0], old[-1]);
380 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
381 assert(
myLanes[i].shape.length() > 0);
382 avgLength +=
myLanes[i].shape.length();
390 const std::string error =
"Could not find a way to attach lane '" +
getLaneID(laneIndex) +
391 "' at node shape of '" + startNode->
getID() +
"'.";
399 assert(pbv.size() > 0);
402 if (pb <= laneShape.
length()) {
410 assert(pbv.size() > 0);
460 NBEdge* currentEdge =
this;
463 if (i != static_cast<int>(
myGeom.
size() - 2)) {
464 std::string nodename =
myID +
"_in_between#" +
toString(i);
466 throw ProcessError(
"Error on adding in-between node '" + nodename +
"'.");
474 currentEdge->
myTo = newTo;
477 std::string edgename =
myID +
"[" +
toString(i - 1) +
"]";
481 if (!ec.
insert(currentEdge,
true)) {
482 throw ProcessError(
"Error on adding splitted edge '" + edgename +
"'.");
523 bool mayUseSameDestination,
524 bool mayDefinitelyPass) {
537 setConnection(from, dest, toLane, type, mayUseSameDestination, mayDefinitelyPass);
544 NBEdge* dest,
unsigned int toLane,
546 bool invalidatePrevious,
547 bool mayDefinitelyPass) {
548 if (invalidatePrevious) {
552 for (
unsigned int i = 0; i < no && ok; i++) {
562 bool mayUseSameDestination,
563 bool mayDefinitelyPass) {
587 if ((*i).toEdge == destEdge && ((*i).fromLane == -1 || (*i).toLane == -1)) {
594 if (mayDefinitelyPass) {
614 std::vector<NBEdge::Connection>
616 std::vector<NBEdge::Connection> ret;
618 if ((*i).fromLane == static_cast<int>(lane)) {
653 if (find(outgoing.begin(), outgoing.end(), (*i).toEdge) == outgoing.end()) {
654 outgoing.push_back((*i).toEdge);
659 unsigned int size = (
unsigned int) outgoing.size();
661 edges->reserve(size);
662 for (EdgeVector::const_iterator i = outgoing.begin(); i != outgoing.end(); i++) {
665 edges->push_back(outedge);
677 if (find(ret.begin(), ret.end(), (*i).toEdge) == ret.end()) {
678 ret.push_back((*i).toEdge);
687 std::vector<int> ret;
690 if ((*i).toEdge == currentOutgoing) {
691 ret.push_back((*i).fromLane);
714 for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
719 for (EdgeVector::iterator j = connected.begin(); j != connected.end(); j++) {
733 && (fromLane < 0 || c.
fromLane == fromLane)
734 && (toLane < 0 || c.
toLane == toLane)) {
751 if (reallowSetting) {
764 if ((*i).toEdge == which) {
776 std::map<int, int> laneMap;
780 bool wasConnected =
false;
782 if ((*i).toEdge != which) {
786 if((*i).fromLane!=-1) {
787 int fromLane = (*i).fromLane;
788 laneMap[(*i).toLane] = fromLane;
789 if(minLane==-1||minLane>fromLane) {
792 if(maxLane==-1||maxLane<fromLane) {
803 std::vector<NBEdge::Connection> conns = origConns;
804 for(std::vector<NBEdge::Connection>::iterator i=conns.begin(); i!=conns.end(); ++i) {
805 if((*i).toEdge==which) {
808 int fromLane = (*i).fromLane;
810 if(laneMap.find(fromLane)==laneMap.end()) {
811 if(fromLane>=0 && fromLane<=minLane) {
814 if(fromLane>=0 && fromLane>=maxLane) {
818 toUse = laneMap[fromLane];
837 unsigned int index = 0;
851 std::vector<Connection>::iterator i =
myConnections.begin() + index;
871 if ((*i).fromLane == static_cast<int>(lane)) {
892 std::string innerID =
":" + n.
getID();
894 if ((*i).toEdge == 0) {
901 std::pair<SUMOReal, std::vector<unsigned int> > crossingPositions(-1, std::vector<unsigned int>());
902 std::string foeInternalLanes;
903 std::set<std::string> tmpFoeIncomingLanes;
908 unsigned int index = 0;
910 for (EdgeVector::const_iterator i2 = incoming.begin(); i2 != incoming.end(); ++i2) {
911 const std::vector<Connection> &elv = (*i2)->getConnections();
912 for (std::vector<NBEdge::Connection>::const_iterator k2 = elv.begin(); k2 != elv.end(); k2++) {
913 if ((*k2).toEdge == 0) {
916 bool needsCont = n.
needsCont(
this, (*i).toEdge, *i2, (*k2).toEdge, *k2);
919 crossingPositions.second.push_back(index);
924 if (minDV < shape.
length() - .1 && minDV > .1) {
926 if (crossingPositions.first < 0 || crossingPositions.first > minDV) {
927 crossingPositions.first = minDV;
933 if (n.
foes(
this, (*i).toEdge, *i2, (*k2).toEdge)) {
934 if (foeInternalLanes.length() != 0) {
935 foeInternalLanes +=
" ";
937 foeInternalLanes += (
":" + n.
getID() +
"_" +
toString(index) +
"_0");
941 if (e == *i2 && needsCont && !n.
forbids(
this, (*i).toEdge, *i2, (*k2).toEdge,
true) ) {
942 tmpFoeIncomingLanes.insert((*i2)->getID() +
"_" +
toString((*k2).fromLane));
947 if (dir ==
LINKDIR_TURN && crossingPositions.first < 0 && crossingPositions.second.size() != 0) {
962 (*i).toEdge->getLaneShape((*i).toLane).getBegin())
967 Position end = (*i).toEdge->getLaneShape((*i).toLane).getBegin();
970 assert(shape.
size() >= 2);
972 if (crossingPositions.first >= 0) {
973 std::pair<PositionVector, PositionVector> split = shape.
splitAt(crossingPositions.first);
974 (*i).id = innerID +
"_" +
toString(lno);
976 (*i).shape = split.first;
977 (*i).foeInternalLanes = foeInternalLanes;
979 for (std::set<std::string>::iterator q = tmpFoeIncomingLanes.begin(); q != tmpFoeIncomingLanes.end(); ++q) {
980 if ((*i).foeIncomingLanes.length() != 0) {
981 (*i).foeIncomingLanes +=
" ";
983 (*i).foeIncomingLanes += *q;
985 (*i).viaID = innerID +
"_" +
toString(splitNo + noInternalNoSplits);
987 (*i).viaShape = split.second;
991 (*i).id = innerID +
"_" +
toString(lno);
1027 assert(atNode ==
myTo);
1052 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1056 WRITE_WARNING(
"In edge '" +
getID() +
"': lane shape could not been determined (" + e.what() +
")");
1066 bool haveWarned =
false;
1067 for (
int i = 0; i < (
int) myGeom.size(); i++) {
1074 Position(from.
x() - offsets.first, from.
y() - offsets.second, from.
z()));
1075 }
else if (i == static_cast<int>(myGeom.size() - 1)) {
1081 Position(to.
x() - offsets.first, to.
y() - offsets.second, to.
z()));
1089 Position(from.
x() - offsets.first, from.
y() - offsets.second),
1090 Position(me.
x() - offsets.first, me.
y() - offsets.second));
1093 Position(me.
x() - offsets2.first, me.
y() - offsets2.second),
1094 Position(to.
x() - offsets2.first, to.
y() - offsets2.second));
1096 if (angle < 10. || angle > 350.) {
1099 Position(me.
x() - offsets.first, me.
y() - offsets.second, me.
z()));
1108 WRITE_WARNING(
"In lane '" + getLaneID(lane) +
"': Could not build shape.");
1118 std::pair<SUMOReal, SUMOReal>
1121 return laneOffset(from, to, lanewidth, lane,
1122 myLanes.size(), myLaneSpreadFunction, myAmLeftHand);
1126 std::pair<SUMOReal, SUMOReal>
1128 SUMOReal lanewidth,
unsigned int lane,
1130 std::pair<SUMOReal, SUMOReal> offsets =
1135 xoff += (offsets.first * (
SUMOReal) lane);
1136 yoff += (offsets.second * (
SUMOReal) lane);
1142 return std::pair<SUMOReal, SUMOReal>(-xoff, -yoff);
1144 return std::pair<SUMOReal, SUMOReal>(xoff, yoff);
1151 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1162 std::vector<Lane>::const_iterator i =
myLanes.begin();
1165 for (; i !=
myLanes.end(); ++i) {
1166 if (i->permissions != firstLanePermissions) {
1176 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1187 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1198 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1223 for (EdgeVector::const_iterator i = o.begin(); i != o.end(); ++i) {
1261 std::vector<unsigned int> connNumbersPerLane(
myLanes.size(), 0);
1263 if ((*i).toEdge == 0 || (*i).fromLane < 0 || (*i).toLane < 0) {
1266 if ((*i).fromLane >= 0) {
1267 ++connNumbersPerLane[(*i).fromLane];
1278 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1279 if (connNumbersPerLane[i] == 0) {
1280 if (i > 0 && connNumbersPerLane[i - 1] > 1) {
1282 }
else if (i <
myLanes.size() - 1 && connNumbersPerLane[i + 1] > 1) {
1294 if (outgoing->size() == 0) {
1307 unsigned int size = (
unsigned int) outgoing->size();
1308 std::vector<SUMOReal> resultingLanes;
1309 resultingLanes.reserve(size);
1313 for (i = 0; i < size; i++) {
1324 resultingLanes.push_back(res);
1325 sumResulting += res;
1326 if (minResulting > res) {
1334 sumResulting += minResulting / (
SUMOReal) 2.;
1335 unsigned int noVirtual = (
unsigned int)(sumResulting / minResulting);
1338 transition.reserve(size);
1339 for (i = 0; i < size; i++) {
1342 assert(i < resultingLanes.size());
1344 for (
SUMOReal j = 0; j < tmpNo; j++) {
1345 assert(outgoing->size() > i);
1346 transition.push_back((*outgoing)[i]);
1354 const std::map<NBEdge*, std::vector<unsigned int> > &l2eConns = adder.
getBuiltConnections();
1356 for (std::map<
NBEdge*, std::vector<unsigned int> >::const_iterator i = l2eConns.begin(); i != l2eConns.end(); ++i) {
1357 const std::vector<unsigned int> lanes = (*i).second;
1358 for (std::vector<unsigned int>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
1370 std::vector<unsigned int> *
1373 std::vector<unsigned int> *priorities =
new std::vector<unsigned int>();
1374 if (outgoing->size() == 0) {
1377 priorities->reserve(outgoing->size());
1378 EdgeVector::const_iterator i;
1379 for (i = outgoing->begin(); i != outgoing->end(); i++) {
1380 int prio = (*i)->getJunctionPriority(
myTo);
1381 assert((prio + 1) * 2 > 0);
1382 prio = (prio + 1) * 2;
1383 priorities->push_back(prio);
1391 i = find(outgoing->begin(), outgoing->end(), *(tmp.begin()));
1392 unsigned int dist = (
unsigned int) distance(outgoing->begin(), i);
1394 assert(priorities->size() > 0);
1395 (*priorities)[0] = (*priorities)[0] / 2;
1400 if (mainDirections.
empty()) {
1401 assert(dist < priorities->size());
1402 (*priorities)[dist] = (*priorities)[dist] * 2;
1405 (*priorities)[dist] = (*priorities)[dist] * 2;
1414 unsigned int sum = 0;
1415 for (std::vector<unsigned int>::iterator i = priorities->begin(); i != priorities->end(); i++) {
1454 if (thisFromAngle2 < otherToAngle2) {
1455 std::swap(thisFromAngle2, otherToAngle2);
1457 if (thisFromAngle2 - otherToAngle2 > 170 && thisFromAngle2 - otherToAngle2 < 190) {
1468 if (pos < tolerance) {
1482 for (
unsigned int i = 0; i < lanes; i++) {
1484 for (std::vector<NBEdge::Connection>::iterator j = elv.begin(); j != elv.end(); j++) {
1486 assert(el.
tlID ==
"");
1571 assert(fromLane < 0 || fromLane < (
int)
myLanes.size());
1573 if (fromLane >= 0 && toLane >= 0) {
1575 std::vector<Connection>::iterator i =
1583 connection.
tlID = tlID;
1590 unsigned int no = 0;
1591 bool hadError =
false;
1593 if ((*i).toEdge != toEdge) {
1596 if (fromLane >= 0 && fromLane != (*i).fromLane) {
1599 if (toLane >= 0 && toLane != (*i).toLane) {
1602 if ((*i).tlID ==
"") {
1604 (*i).tlLinkNo = tlIndex;
1607 if ((*i).tlID != tlID && (*i).tlLinkNo == tlIndex) {
1608 WRITE_WARNING(
"The lane " + toString<int>((*i).fromLane) +
" on edge " +
getID() +
" already had a traffic light signal.");
1613 if (hadError && no == 0) {
1614 WRITE_WARNING(
"Could not set any signal of the traffic light '" + tlID +
"' (unknown group)");
1707 if (find(conn.begin(), conn.end(), possContinuation)
1724 if (conns.size() !=
myLanes.size()) {
1740 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1760 if ((*i).toEdge == e && (*i).tlID !=
"") {
1776 assert(lane <
myLanes.size());
1784 assert(distances.size() > 0);
1791 unsigned int newLaneNo = (
unsigned int)
myLanes.size() + by;
1792 while (
myLanes.size() < newLaneNo) {
1797 for (EdgeVector::const_iterator i = incs.begin(); i != incs.end(); ++i) {
1798 (*i)->invalidateConnections(
true);
1806 unsigned int newLaneNo = (
unsigned int)
myLanes.size() - by;
1807 while (
myLanes.size() > newLaneNo) {
1812 for (EdgeVector::const_iterator i = incs.begin(); i != incs.end(); ++i) {
1813 (*i)->invalidateConnections(
true);
1819 assert(outs.size() == 1);
1840 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1844 assert(lane < (
int)
myLanes.size());
1845 myLanes[lane].permissions |= vclass;
1853 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1857 assert(lane < (
int)
myLanes.size());
1858 myLanes[lane].permissions &= ~vclass;
1866 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1870 assert(lane < (
int)
myLanes.size());
1871 myLanes[lane].preferred |= vclass;
1881 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1887 assert(lane < (
int)
myLanes.size());
1897 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1903 assert(lane < (
int)
myLanes.size());
1904 myLanes[lane].offset = offset;
1913 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1919 assert(lane < (
int)
myLanes.size());
1927 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1932 assert(lane < (
int)
myLanes.size());
1933 myLanes[lane].permissions = permissions;
1941 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1946 assert(lane < (
int)
myLanes.size());
1947 myLanes[lane].preferred = permissions;
1956 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1961 assert(lane < (
int)
myLanes.size());
1962 return myLanes[lane].permissions;
1975 for (std::vector<Lane>::iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {