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) {
253 init(nolanes, tryIgnoreNodePositions);
260 if (from == 0 || to == 0) {
261 throw ProcessError(
"At least one of edge's '" +
myID +
"' nodes is not known.");
282 throw ProcessError(
"At least one of edge's '" +
myID +
"' nodes is not known.");
288 if (!tryIgnoreNodePositions ||
myGeom.
size() < 2) {
303 WRITE_ERROR(
"Edge's '" +
myID +
"' from- and to-node are at the same position.");
317 for (
unsigned int i = 0; i < noLanes; i++) {
331 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
332 myLanes[i].shape.reshiftRotate(xoff, yoff, 0);
375 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
379 if (shape.
size() >= 2) {
384 WRITE_MESSAGE(
"Lane '" +
myID +
"' has calculated shape length near zero. Revert it back to old shape.");
389 Line lc(shape[0], shape[-1]);
390 Line lo(old[0], old[-1]);
398 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
399 assert(
myLanes[i].shape.length() > 0);
400 avgLength +=
myLanes[i].shape.length();
408 const std::string error =
"Could not find a way to attach lane '" +
getLaneID(laneIndex) +
409 "' at node shape of '" + startNode->
getID() +
"'.";
417 assert(pbv.size() > 0);
420 if (pb <= laneShape.
length()) {
428 assert(pbv.size() > 0);
478 NBEdge* currentEdge =
this;
481 if (i != static_cast<int>(
myGeom.
size() - 2)) {
482 std::string nodename =
myID +
"_in_between#" +
toString(i);
484 throw ProcessError(
"Error on adding in-between node '" + nodename +
"'.");
492 currentEdge->
myTo = newTo;
495 std::string edgename =
myID +
"[" +
toString(i - 1) +
"]";
499 if (!ec.
insert(currentEdge,
true)) {
500 throw ProcessError(
"Error on adding splitted edge '" + edgename +
"'.");
541 bool mayUseSameDestination,
542 bool mayDefinitelyPass) {
555 setConnection(from, dest, toLane, type, mayUseSameDestination, mayDefinitelyPass);
562 NBEdge* dest,
unsigned int toLane,
564 bool invalidatePrevious,
565 bool mayDefinitelyPass) {
566 if (invalidatePrevious) {
570 for (
unsigned int i = 0; i < no && ok; i++) {
580 bool mayUseSameDestination,
581 bool mayDefinitelyPass) {
605 if ((*i).toEdge == destEdge && ((*i).fromLane == -1 || (*i).toLane == -1)) {
612 if (mayDefinitelyPass) {
632 std::vector<NBEdge::Connection>
634 std::vector<NBEdge::Connection> ret;
636 if ((*i).fromLane == static_cast<int>(lane)) {
671 if (find(outgoing.begin(), outgoing.end(), (*i).toEdge) == outgoing.end()) {
672 outgoing.push_back((*i).toEdge);
677 unsigned int size = (
unsigned int) outgoing.size();
679 edges->reserve(size);
680 for (EdgeVector::const_iterator i = outgoing.begin(); i != outgoing.end(); i++) {
683 edges->push_back(outedge);
695 if (find(ret.begin(), ret.end(), (*i).toEdge) == ret.end()) {
696 ret.push_back((*i).toEdge);
705 std::vector<int> ret;
708 if ((*i).toEdge == currentOutgoing) {
709 ret.push_back((*i).fromLane);
732 for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
737 for (EdgeVector::iterator j = connected.begin(); j != connected.end(); j++) {
751 && (fromLane < 0 || c.
fromLane == fromLane)
752 && (toLane < 0 || c.
toLane == toLane)) {
769 if (reallowSetting) {
782 if ((*i).toEdge == which) {
794 std::map<int, int> laneMap;
798 bool wasConnected =
false;
800 if ((*i).toEdge != which) {
804 if ((*i).fromLane != -1) {
805 int fromLane = (*i).fromLane;
806 laneMap[(*i).toLane] = fromLane;
807 if (minLane == -1 || minLane > fromLane) {
810 if (maxLane == -1 || maxLane < fromLane) {
821 std::vector<NBEdge::Connection> conns = origConns;
822 for (std::vector<NBEdge::Connection>::iterator i = conns.begin(); i != conns.end(); ++i) {
823 if ((*i).toEdge == which) {
826 int fromLane = (*i).fromLane;
828 if (laneMap.find(fromLane) == laneMap.end()) {
829 if (fromLane >= 0 && fromLane <= minLane) {
832 if (fromLane >= 0 && fromLane >= maxLane) {
836 toUse = laneMap[fromLane];
855 unsigned int index = 0;
869 std::vector<Connection>::iterator i =
myConnections.begin() + index;
889 if ((*i).fromLane == static_cast<int>(lane)) {
910 std::string innerID =
":" + n.
getID();
921 std::pair<SUMOReal, std::vector<unsigned int> > crossingPositions(-1, std::vector<unsigned int>());
922 std::string foeInternalLanes;
923 std::set<std::string> tmpFoeIncomingLanes;
928 unsigned int index = 0;
930 for (EdgeVector::const_iterator i2 = incoming.begin(); i2 != incoming.end(); ++i2) {
931 const std::vector<Connection>& elv = (*i2)->getConnections();
932 for (std::vector<NBEdge::Connection>::const_iterator k2 = elv.begin(); k2 != elv.end(); k2++) {
933 if ((*k2).toEdge == 0) {
936 bool needsCont = n.
needsCont(
this, con.
toEdge, *i2, (*k2).toEdge, *k2);
939 crossingPositions.second.push_back(index);
944 if (minDV < shape.
length() - .1 && minDV > .1) {
946 if (crossingPositions.first < 0 || crossingPositions.first > minDV) {
947 crossingPositions.first = minDV;
953 if (n.
foes(
this, con.
toEdge, *i2, (*k2).toEdge)) {
954 if (foeInternalLanes.length() != 0) {
955 foeInternalLanes +=
" ";
957 foeInternalLanes += (
":" + n.
getID() +
"_" +
toString(index) +
"_0");
961 if ((e == *i2 && needsCont && !n.
forbids(
this, con.
toEdge, *i2, (*k2).toEdge,
true))
963 tmpFoeIncomingLanes.insert((*i2)->getID() +
"_" +
toString((*k2).fromLane));
968 if (dir ==
LINKDIR_TURN && crossingPositions.first < 0 && crossingPositions.second.size() != 0) {
991 assert(shape.
size() >= 2);
993 if (crossingPositions.first >= 0) {
994 std::pair<PositionVector, PositionVector> split = shape.
splitAt(crossingPositions.first);
997 con.
shape = split.first;
1001 for (std::set<std::string>::iterator q = tmpFoeIncomingLanes.begin(); q != tmpFoeIncomingLanes.end(); ++q) {
1007 con.
viaID = innerID +
"_" +
toString(splitNo + noInternalNoSplits);
1049 assert(atNode ==
myTo);
1074 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1078 WRITE_WARNING(
"In edge '" +
getID() +
"': lane shape could not be determined (" + e.what() +
")");
1088 bool haveWarned =
false;
1089 for (
int i = 0; i < (
int) myGeom.size(); i++) {
1096 Position(from.
x() - offsets.first, from.
y() - offsets.second, from.
z()));
1097 }
else if (i == static_cast<int>(myGeom.size() - 1)) {
1103 Position(to.
x() - offsets.first, to.
y() - offsets.second, to.
z()));
1111 Position(from.
x() - offsets.first, from.
y() - offsets.second),
1112 Position(me.
x() - offsets.first, me.
y() - offsets.second));
1115 Position(me.
x() - offsets2.first, me.
y() - offsets2.second),
1116 Position(to.
x() - offsets2.first, to.
y() - offsets2.second));
1118 if (angle < 10. || angle > 350.) {
1121 Position(me.
x() - offsets.first, me.
y() - offsets.second, me.
z()));
1130 WRITE_WARNING(
"In lane '" + getLaneID(lane) +
"': Could not build shape.");
1140 std::pair<SUMOReal, SUMOReal>
1143 return laneOffset(from, to, lanewidth, lane,
1144 myLanes.size(), myLaneSpreadFunction, myAmLeftHand);
1148 std::pair<SUMOReal, SUMOReal>
1150 SUMOReal lanewidth,
unsigned int lane,
1152 std::pair<SUMOReal, SUMOReal> offsets =
1157 xoff += (offsets.first * (
SUMOReal) lane);
1158 yoff += (offsets.second * (
SUMOReal) lane);
1164 return std::pair<SUMOReal, SUMOReal>(-xoff, -yoff);
1166 return std::pair<SUMOReal, SUMOReal>(xoff, yoff);
1173 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1184 std::vector<Lane>::const_iterator i =
myLanes.begin();
1187 for (; i !=
myLanes.end(); ++i) {
1188 if (i->permissions != firstLanePermissions) {
1198 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1209 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1220 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1245 for (EdgeVector::const_iterator i = o.begin(); i != o.end(); ++i) {
1283 std::vector<unsigned int> connNumbersPerLane(
myLanes.size(), 0);
1285 if ((*i).toEdge == 0 || (*i).fromLane < 0 || (*i).toLane < 0) {
1288 if ((*i).fromLane >= 0) {
1289 ++connNumbersPerLane[(*i).fromLane];
1300 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1301 if (connNumbersPerLane[i] == 0) {
1302 if (i > 0 && connNumbersPerLane[i - 1] > 1) {
1304 }
else if (i <
myLanes.size() - 1 && connNumbersPerLane[i + 1] > 1) {
1316 if (outgoing->size() == 0) {
1329 unsigned int size = (
unsigned int) outgoing->size();
1330 std::vector<SUMOReal> resultingLanes;
1331 resultingLanes.reserve(size);
1335 for (i = 0; i < size; i++) {
1346 resultingLanes.push_back(res);
1347 sumResulting += res;
1348 if (minResulting > res) {
1356 sumResulting += minResulting / (
SUMOReal) 2.;
1357 unsigned int noVirtual = (
unsigned int)(sumResulting / minResulting);
1360 transition.reserve(size);
1361 for (i = 0; i < size; i++) {
1364 assert(i < resultingLanes.size());
1366 for (
SUMOReal j = 0; j < tmpNo; j++) {
1367 assert(outgoing->size() > i);
1368 transition.push_back((*outgoing)[i]);
1376 const std::map<NBEdge*, std::vector<unsigned int> >& l2eConns = adder.
getBuiltConnections();
1378 for (std::map<
NBEdge*, std::vector<unsigned int> >::const_iterator i = l2eConns.begin(); i != l2eConns.end(); ++i) {
1379 const std::vector<unsigned int> lanes = (*i).second;
1380 for (std::vector<unsigned int>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
1392 std::vector<unsigned int>*
1395 std::vector<unsigned int>* priorities =
new std::vector<unsigned int>();
1396 if (outgoing->size() == 0) {
1399 priorities->reserve(outgoing->size());
1400 EdgeVector::const_iterator i;
1401 for (i = outgoing->begin(); i != outgoing->end(); i++) {
1402 int prio = (*i)->getJunctionPriority(
myTo);
1403 assert((prio + 1) * 2 > 0);
1404 prio = (prio + 1) * 2;
1405 priorities->push_back(prio);
1413 i = find(outgoing->begin(), outgoing->end(), *(tmp.begin()));
1414 unsigned int dist = (
unsigned int) distance(outgoing->begin(), i);
1416 assert(priorities->size() > 0);
1417 (*priorities)[0] = (*priorities)[0] / 2;
1422 if (mainDirections.
empty()) {
1423 assert(dist < priorities->size());
1424 (*priorities)[dist] = (*priorities)[dist] * 2;
1427 (*priorities)[dist] = (*priorities)[dist] * 2;
1436 unsigned int sum = 0;
1437 for (std::vector<unsigned int>::iterator i = priorities->begin(); i != priorities->end(); i++) {
1476 if (thisFromAngle2 < otherToAngle2) {
1477 std::swap(thisFromAngle2, otherToAngle2);
1479 if (thisFromAngle2 - otherToAngle2 > 170 && thisFromAngle2 - otherToAngle2 < 190) {
1490 if (pos < tolerance) {
1504 for (
unsigned int i = 0; i < lanes; i++) {
1506 for (std::vector<NBEdge::Connection>::iterator j = elv.begin(); j != elv.end(); j++) {
1508 assert(el.
tlID ==
"");
1593 assert(fromLane < 0 || fromLane < (
int)
myLanes.size());
1595 if (fromLane >= 0 && toLane >= 0) {
1597 std::vector<Connection>::iterator i =
1605 connection.
tlID = tlID;
1612 unsigned int no = 0;
1613 bool hadError =
false;
1615 if ((*i).toEdge != toEdge) {
1618 if (fromLane >= 0 && fromLane != (*i).fromLane) {
1621 if (toLane >= 0 && toLane != (*i).toLane) {
1624 if ((*i).tlID ==
"") {
1626 (*i).tlLinkNo = tlIndex;
1629 if ((*i).tlID != tlID && static_cast<int>((*i).tlLinkNo) == tlIndex) {
1630 WRITE_WARNING(
"The lane " + toString<int>((*i).fromLane) +
" on edge " +
getID() +
" already had a traffic light signal.");
1635 if (hadError && no == 0) {
1636 WRITE_WARNING(
"Could not set any signal of the traffic light '" + tlID +
"' (unknown group)");
1729 if (find(conn.begin(), conn.end(), possContinuation)
1746 if (conns.size() !=
myLanes.size()) {
1762 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1782 if ((*i).toEdge == e && (*i).tlID !=
"") {
1798 assert(lane <
myLanes.size());
1806 assert(distances.size() > 0);
1813 unsigned int newLaneNo = (
unsigned int)
myLanes.size() + by;
1814 while (
myLanes.size() < newLaneNo) {
1819 for (EdgeVector::const_iterator i = incs.begin(); i != incs.end(); ++i) {
1820 (*i)->invalidateConnections(
true);
1828 unsigned int newLaneNo = (
unsigned int)
myLanes.size() - by;
1829 while (
myLanes.size() > newLaneNo) {
1834 for (EdgeVector::const_iterator i = incs.begin(); i != incs.end(); ++i) {
1835 (*i)->invalidateConnections(
true);
1841 assert(outs.size() == 1);
1862 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1866 assert(lane < (
int)
myLanes.size());
1867 myLanes[lane].permissions |= vclass;
1875 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1879 assert(lane < (
int)
myLanes.size());
1880 myLanes[lane].permissions &= ~vclass;
1888 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1892 assert(lane < (
int)
myLanes.size());
1893 myLanes[lane].preferred |= vclass;
1903 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1909 assert(lane < (
int)
myLanes.size());
1919 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1925 assert(lane < (
int)
myLanes.size());
1926 myLanes[lane].offset = offset;
1935 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1941 assert(lane < (
int)
myLanes.size());
1949 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1954 assert(lane < (
int)
myLanes.size());
1955 myLanes[lane].permissions = permissions;
1963 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1968 assert(lane < (
int)
myLanes.size());
1969 myLanes[lane].preferred = permissions;
1978 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1983 assert(lane < (
int)
myLanes.size());
1984 return myLanes[lane].permissions;
1997 for (std::vector<Lane>::iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {