57 #ifdef CHECK_MEMORY_LEAKS
59 #endif // CHECK_MEMORY_LEAKS
81 std::vector<unsigned int> lanes;
85 std::map<NBEdge*, std::vector<unsigned int> >::iterator i =
myConnections.find(succEdge);
93 std::vector<unsigned int>::iterator j = find(lanes.begin(), lanes.end(), lane);
94 if (j == lanes.end()) {
96 lanes.push_back(lane);
109 if (outgoing.size() == 0) {
113 assert(outgoing.size() > 0);
118 if (outgoing.back()->getJunctionPriority(to) == 1) {
124 if (outgoing.back()->getPriority() > tmp[0]->getPriority()) {
127 if (outgoing.back()->getNumLanes() > tmp[0]->getNumLanes()) {
136 NBEdge* edge = *(tmp.begin());
149 return myDirs.empty();
155 return find(myDirs.begin(), myDirs.end(), d) != myDirs.end();
175 std::string type,
SUMOReal speed,
unsigned int nolanes,
177 const std::string& streetName,
191 init(nolanes,
false);
196 std::string type,
SUMOReal speed,
unsigned int nolanes,
199 const std::string& streetName,
204 myFrom(from), myTo(to),
205 myStartAngle(0), myEndAngle(0), myTotalAngle(0),
206 myPriority(priority), mySpeed(speed),
207 myTurnDestination(0),
208 myFromJunctionPriority(-1), myToJunctionPriority(-1),
209 myGeom(geom), myLaneSpreadFunction(spread), myOffset(offset), myLaneWidth(laneWidth),
210 myLoadedLength(UNSPECIFIED_LOADED_LENGTH), myAmLeftHand(false),
211 myAmInnerEdge(false), myAmMacroscopicConnector(false),
212 myStreetName(streetName) {
213 init(nolanes, tryIgnoreNodePositions);
220 myType(tpl->getTypeID()),
221 myFrom(from), myTo(to),
222 myStartAngle(0), myEndAngle(0), myTotalAngle(0),
223 myPriority(tpl->getPriority()), mySpeed(tpl->getSpeed()),
224 myTurnDestination(0),
225 myFromJunctionPriority(-1), myToJunctionPriority(-1),
226 myLaneSpreadFunction(tpl->getLaneSpreadFunction()),
227 myOffset(tpl->getOffset()),
228 myLaneWidth(tpl->getLaneWidth()),
229 myLoadedLength(UNSPECIFIED_LOADED_LENGTH), myAmLeftHand(false),
230 myAmInnerEdge(false), myAmMacroscopicConnector(false),
231 myStreetName(tpl->getStreetName()) {
242 SUMOReal speed,
unsigned int nolanes,
int priority,
244 const std::string& streetName,
246 bool tryIgnoreNodePositions) {
268 init(nolanes, tryIgnoreNodePositions);
275 if (from == 0 || to == 0) {
276 throw ProcessError(
"At least one of edge's '" +
myID +
"' nodes is not known.");
297 throw ProcessError(
"At least one of edge's '" +
myID +
"' nodes is not known.");
303 if (!tryIgnoreNodePositions ||
myGeom.size() < 2) {
318 WRITE_ERROR(
"Edge's '" +
myID +
"' from- and to-node are at the same position.");
326 assert(
myGeom.size() >= 2);
328 for (
unsigned int i = 0; i < noLanes; i++) {
343 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
344 myLanes[i].shape.reshiftRotate(xoff, yoff, 0);
388 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
392 if (shape.size() >= 2) {
403 assert(shape.size() >= 2);
404 assert(shape.
length() > 0);
409 Line lc(shape[0], shape[-1]);
410 Line lo(old[0], old[-1]);
419 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
420 assert(
myLanes[i].shape.length() > 0);
421 avgLength +=
myLanes[i].shape.length();
436 assert(pbv.size() > 0);
440 ns[0].set(ns[0].x(), ns[0].y(), startNode->
getPosition().
z());
445 assert(pbv.size() > 0);
496 NBEdge* currentEdge =
this;
497 for (
int i = 1; i < (
int)
myGeom.size() - 1; i++) {
499 if (i != (
int)
myGeom.size() - 2) {
500 std::string nodename =
myID +
"_in_between#" +
toString(i);
502 throw ProcessError(
"Error on adding in-between node '" + nodename +
"'.");
510 currentEdge->
myTo = newTo;
513 std::string edgename =
myID +
"[" +
toString(i - 1) +
"]";
517 if (!ec.
insert(currentEdge,
true)) {
518 throw ProcessError(
"Error on adding splitted edge '" + edgename +
"'.");
543 std::vector<SUMOReal> angles;
545 for (
int i = 0; i < (
int)
myGeom.size() - 1; ++i) {
550 for (
int i = 0; i < (
int)angles.size() - 1; ++i) {
553 if (maxAngle > 0 && relAngle > maxAngle) {
559 if (i == 0 || i == (
int)angles.size() - 2) {
560 const bool start = i == 0;
564 if (minRadius > 0 && r < minRadius) {
567 (start ?
"start" :
"end") +
" of edge " +
getID());
573 (start ?
"start" :
"end") +
" of edge " +
getID());
610 bool mayUseSameDestination,
611 bool mayDefinitelyPass) {
624 setConnection(from, dest, toLane, type, mayUseSameDestination, mayDefinitelyPass);
631 NBEdge* dest,
unsigned int toLane,
633 bool invalidatePrevious,
634 bool mayDefinitelyPass) {
635 if (invalidatePrevious) {
639 for (
unsigned int i = 0; i < no && ok; i++) {
649 bool mayUseSameDestination,
650 bool mayDefinitelyPass) {
678 if ((*i).toEdge == destEdge && ((*i).fromLane == -1 || (*i).toLane == -1)) {
685 if (mayDefinitelyPass) {
705 std::vector<NBEdge::Connection>
707 std::vector<NBEdge::Connection> ret;
709 if ((*i).fromLane == static_cast<int>(lane)) {
744 if (find(outgoing.begin(), outgoing.end(), (*i).toEdge) == outgoing.end()) {
745 outgoing.push_back((*i).toEdge);
750 unsigned int size = (
unsigned int) outgoing.size();
752 edges->reserve(size);
753 for (EdgeVector::const_iterator i = outgoing.begin(); i != outgoing.end(); i++) {
756 edges->push_back(outedge);
768 if (find(ret.begin(), ret.end(), (*i).toEdge) == ret.end()) {
769 ret.push_back((*i).toEdge);
778 std::vector<int> ret;
781 if ((*i).toEdge == currentOutgoing) {
782 ret.push_back((*i).fromLane);
805 for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
810 for (EdgeVector::iterator j = connected.begin(); j != connected.end(); j++) {
824 && (fromLane < 0 || c.
fromLane == fromLane)
825 && (toLane < 0 || c.
toLane == toLane)) {
846 if (reallowSetting) {
859 if ((*i).toEdge == which) {
871 std::map<int, int> laneMap;
875 bool wasConnected =
false;
877 if ((*i).toEdge != which) {
881 if ((*i).fromLane != -1) {
882 int fromLane = (*i).fromLane;
883 laneMap[(*i).toLane] = fromLane;
884 if (minLane == -1 || minLane > fromLane) {
887 if (maxLane == -1 || maxLane < fromLane) {
898 std::vector<NBEdge::Connection> conns = origConns;
899 for (std::vector<NBEdge::Connection>::iterator i = conns.begin(); i != conns.end(); ++i) {
900 if ((*i).toEdge == which) {
903 int fromLane = (*i).fromLane;
905 if (laneMap.find(fromLane) == laneMap.end()) {
906 if (fromLane >= 0 && fromLane <= minLane) {
909 if (fromLane >= 0 && fromLane >= maxLane) {
913 toUse = laneMap[fromLane];
932 unsigned int index = 0;
946 std::vector<Connection>::iterator i =
myConnections.begin() + index;
966 if ((*i).fromLane == static_cast<int>(lane)) {
987 std::string innerID =
":" + n.
getID();
998 std::pair<SUMOReal, std::vector<unsigned int> > crossingPositions(-1, std::vector<unsigned int>());
999 std::string foeInternalLanes;
1000 std::set<std::string> tmpFoeIncomingLanes;
1005 unsigned int index = 0;
1007 for (EdgeVector::const_iterator i2 = incoming.begin(); i2 != incoming.end(); ++i2) {
1008 const std::vector<Connection>& elv = (*i2)->getConnections();
1009 for (std::vector<NBEdge::Connection>::const_iterator k2 = elv.begin(); k2 != elv.end(); k2++) {
1010 if ((*k2).toEdge == 0) {
1013 bool needsCont = n.
needsCont(
this, con.
toEdge, *i2, (*k2).toEdge, *k2);
1016 crossingPositions.second.push_back(index);
1019 if (dv.size() > 0) {
1021 if (minDV < shape.
length() - .1 && minDV > .1) {
1023 if (crossingPositions.first < 0 || crossingPositions.first > minDV) {
1024 crossingPositions.first = minDV;
1030 if (n.
foes(
this, con.
toEdge, *i2, (*k2).toEdge)) {
1031 if (foeInternalLanes.length() != 0) {
1032 foeInternalLanes +=
" ";
1034 foeInternalLanes += (
":" + n.
getID() +
"_" +
toString(index) +
"_0");
1039 tmpFoeIncomingLanes.insert((*i2)->getID() +
"_" +
toString((*k2).fromLane));
1044 if (dir ==
LINKDIR_TURN && crossingPositions.first < 0 && crossingPositions.second.size() != 0) {
1067 assert(shape.size() >= 2);
1069 if (crossingPositions.first >= 0) {
1070 std::pair<PositionVector, PositionVector> split = shape.
splitAt(crossingPositions.first);
1073 con.
shape = split.first;
1077 for (std::set<std::string>::iterator q = tmpFoeIncomingLanes.begin(); q != tmpFoeIncomingLanes.end(); ++q) {
1083 con.
viaID = innerID +
"_" +
toString(splitNo + noInternalNoSplits);
1126 assert(atNode ==
myTo);
1151 std::vector<SUMOReal> offsets;
1152 for (
unsigned int i = 0; i <
myLanes.size(); ++i) {
1153 offsets.push_back(0);
1156 for (
int i = (
int)
myLanes.size() - 2; i >= 0; --i) {
1158 offsets[i] = offset;
1166 for (
unsigned int i = 0; i <
myLanes.size(); ++i) {
1172 for (
unsigned int i = 0; i <
myLanes.size(); ++i) {
1173 offsets[i] += offset;
1180 for (
unsigned int i = 0; i <
myLanes.size(); ++i) {
1184 WRITE_WARNING(
"In edge '" +
getID() +
"': lane shape could not be determined (" + e.what() +
")");
1194 bool haveWarned =
false;
1195 for (
int i = 0; i < (
int)
myGeom.size(); i++) {
1199 std::pair<SUMOReal, SUMOReal> offsets =
laneOffset(from, to, offset,
false);
1202 Position(from.
x() - offsets.first, from.
y() - offsets.second, from.
z()));
1203 }
else if (i == static_cast<int>(
myGeom.size() - 1)) {
1206 std::pair<SUMOReal, SUMOReal> offsets =
laneOffset(from, to, offset,
false);
1209 Position(to.
x() - offsets.first, to.
y() - offsets.second, to.
z()));
1214 std::pair<SUMOReal, SUMOReal> offsets =
laneOffset(from, me, offset,
false);
1215 std::pair<SUMOReal, SUMOReal> offsets2 =
laneOffset(me, to, offset,
false);
1217 Position(from.
x() - offsets.first, from.
y() - offsets.second),
1218 Position(me.
x() - offsets.first, me.
y() - offsets.second));
1221 Position(me.
x() - offsets2.first, me.
y() - offsets2.second),
1222 Position(to.
x() - offsets2.first, to.
y() - offsets2.second));
1224 if (angle < 10. || angle > 350.) {
1227 Position(me.
x() - offsets.first, me.
y() - offsets.second, me.
z()));
1252 std::pair<SUMOReal, SUMOReal>
1256 return std::pair<SUMOReal, SUMOReal>(-offsets.first, -offsets.second);
1258 return std::pair<SUMOReal, SUMOReal>(offsets.first, offsets.second);
1271 referencePosStart.
x(), referencePosStart.
y());
1274 referencePosEnd.x(), referencePosEnd.y(),
1284 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1295 std::vector<Lane>::const_iterator i =
myLanes.begin();
1298 for (; i !=
myLanes.end(); ++i) {
1299 if (i->permissions != firstLanePermissions) {
1309 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1310 if (i->width !=
myLanes.begin()->width) {
1320 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1331 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1332 if (i->offset !=
myLanes.begin()->offset) {
1356 for (EdgeVector::const_iterator i = o.begin(); i != o.end(); ++i) {
1394 std::vector<unsigned int> connNumbersPerLane(
myLanes.size(), 0);
1396 if ((*i).toEdge == 0 || (*i).fromLane < 0 || (*i).toLane < 0) {
1399 if ((*i).fromLane >= 0) {
1400 ++connNumbersPerLane[(*i).fromLane];
1411 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1412 if (connNumbersPerLane[i] == 0) {
1413 if (i > 0 && connNumbersPerLane[i - 1] > 1) {
1415 }
else if (i <
myLanes.size() - 1 && connNumbersPerLane[i + 1] > 1) {
1431 if (outgoing->size() == 0) {
1444 unsigned int size = (
unsigned int) outgoing->size();
1445 std::vector<SUMOReal> resultingLanes;
1446 resultingLanes.reserve(size);
1450 for (i = 0; i < size; i++) {
1461 resultingLanes.push_back(res);
1462 sumResulting += res;
1463 if (minResulting > res) {
1471 sumResulting += minResulting / (
SUMOReal) 2.;
1472 unsigned int noVirtual = (
unsigned int)(sumResulting / minResulting);
1475 transition.reserve(size);
1476 for (i = 0; i < size; i++) {
1479 assert(i < resultingLanes.size());
1481 for (
SUMOReal j = 0; j < tmpNo; j++) {
1482 assert(outgoing->size() > i);
1483 transition.push_back((*outgoing)[i]);
1491 const std::map<NBEdge*, std::vector<unsigned int> >& l2eConns = adder.
getBuiltConnections();
1493 for (std::map<
NBEdge*, std::vector<unsigned int> >::const_iterator i = l2eConns.begin(); i != l2eConns.end(); ++i) {
1494 const std::vector<unsigned int> lanes = (*i).second;
1495 for (std::vector<unsigned int>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
1507 std::vector<unsigned int>*
1510 std::vector<unsigned int>* priorities =
new std::vector<unsigned int>();
1511 if (outgoing->size() == 0) {
1514 priorities->reserve(outgoing->size());
1515 EdgeVector::const_iterator i;
1516 for (i = outgoing->begin(); i != outgoing->end(); i++) {
1517 int prio = (*i)->getJunctionPriority(
myTo);
1518 assert((prio + 1) * 2 > 0);
1519 prio = (prio + 1) * 2;
1520 priorities->push_back(prio);
1528 i = find(outgoing->begin(), outgoing->end(), *(tmp.begin()));
1529 unsigned int dist = (
unsigned int) distance(outgoing->begin(), i);
1531 assert(priorities->size() > 0);
1532 (*priorities)[0] = (*priorities)[0] / 2;
1537 if (mainDirections.
empty()) {
1538 assert(dist < priorities->size());
1539 (*priorities)[dist] = (*priorities)[dist] * 2;
1542 (*priorities)[dist] = (*priorities)[dist] * 2;
1551 unsigned int sum = 0;
1552 for (std::vector<unsigned int>::iterator i = priorities->begin(); i != priorities->end(); i++) {
1591 if (thisFromAngle2 < otherToAngle2) {
1592 std::swap(thisFromAngle2, otherToAngle2);
1594 if (thisFromAngle2 - otherToAngle2 > 170 && thisFromAngle2 - otherToAngle2 < 190) {
1605 if (pos < tolerance) {
1619 for (
unsigned int i = 0; i < lanes; i++) {
1621 for (std::vector<NBEdge::Connection>::iterator j = elv.begin(); j != elv.end(); j++) {
1623 assert(el.
tlID ==
"");
1670 assert(fromLane < 0 || fromLane < (
int)
myLanes.size());
1672 if (fromLane >= 0 && toLane >= 0) {
1674 std::vector<Connection>::iterator i =
1682 connection.
tlID = tlID;
1689 unsigned int no = 0;
1690 bool hadError =
false;
1692 if ((*i).toEdge != toEdge) {
1695 if (fromLane >= 0 && fromLane != (*i).fromLane) {
1698 if (toLane >= 0 && toLane != (*i).toLane) {
1701 if ((*i).tlID ==
"") {
1703 (*i).tlLinkNo = tlIndex;
1706 if ((*i).tlID != tlID && static_cast<int>((*i).tlLinkNo) == tlIndex) {
1707 WRITE_WARNING(
"The lane " + toString<int>((*i).fromLane) +
" on edge " +
getID() +
" already had a traffic light signal.");
1712 if (hadError && no == 0) {
1713 WRITE_WARNING(
"Could not set any signal of the traffic light '" + tlID +
"' (unknown group)");
1806 if (find(conn.begin(), conn.end(), possContinuation)
1823 if (conns.size() !=
myLanes.size()) {
1839 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1859 if ((*i).toEdge == e && (*i).tlID !=
"") {
1875 assert(lane <
myLanes.size());
1889 assert(distances.size() > 0);
1896 unsigned int newLaneNo = (
unsigned int)
myLanes.size() + by;
1897 while (
myLanes.size() < newLaneNo) {
1902 for (EdgeVector::const_iterator i = incs.begin(); i != incs.end(); ++i) {
1903 (*i)->invalidateConnections(
true);
1911 unsigned int newLaneNo = (
unsigned int)
myLanes.size() - by;
1912 while (
myLanes.size() > newLaneNo) {
1917 for (EdgeVector::const_iterator i = incs.begin(); i != incs.end(); ++i) {
1918 (*i)->invalidateConnections(
true);
1924 assert(outs.size() == 1);
1945 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1949 assert(lane < (
int)
myLanes.size());
1950 myLanes[lane].permissions |= vclass;
1958 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1962 assert(lane < (
int)
myLanes.size());
1963 myLanes[lane].permissions &= ~vclass;
1971 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1975 assert(lane < (
int)
myLanes.size());
1976 myLanes[lane].preferred |= vclass;
1986 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1992 assert(lane < (
int)
myLanes.size());
2016 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2022 assert(lane < (
int)
myLanes.size());
2023 myLanes[lane].offset = offset;
2032 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2038 assert(lane < (
int)
myLanes.size());
2046 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2051 assert(lane < (
int)
myLanes.size());
2052 myLanes[lane].permissions = permissions;
2060 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2065 assert(lane < (
int)
myLanes.size());
2066 myLanes[lane].preferred = permissions;
2075 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
2080 assert(lane < (
int)
myLanes.size());
2081 return myLanes[lane].permissions;
2094 for (std::vector<Lane>::iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {