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), myLaneWidth(laneWidth),
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 myLaneWidth(tpl->getLaneWidth()),
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.");
315 assert(
myGeom.size() >= 2);
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) {
390 assert(shape.size() >= 2);
391 assert(shape.
length() > 0);
396 Line lc(shape[0], shape[-1]);
397 Line lo(old[0], old[-1]);
406 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
407 assert(
myLanes[i].shape.length() > 0);
408 avgLength +=
myLanes[i].shape.length();
423 assert(pbv.size() > 0);
427 ns[0].set(ns[0].x(), ns[0].y(), startNode->
getPosition().
z());
432 assert(pbv.size() > 0);
483 NBEdge* currentEdge =
this;
484 for (
int i = 1; i < (
int)
myGeom.size() - 1; i++) {
486 if (i != static_cast<int>(
myGeom.size() - 2)) {
487 std::string nodename =
myID +
"_in_between#" +
toString(i);
489 throw ProcessError(
"Error on adding in-between node '" + nodename +
"'.");
497 currentEdge->
myTo = newTo;
500 std::string edgename =
myID +
"[" +
toString(i - 1) +
"]";
504 if (!ec.
insert(currentEdge,
true)) {
505 throw ProcessError(
"Error on adding splitted edge '" + edgename +
"'.");
552 bool mayUseSameDestination,
553 bool mayDefinitelyPass) {
566 setConnection(from, dest, toLane, type, mayUseSameDestination, mayDefinitelyPass);
573 NBEdge* dest,
unsigned int toLane,
575 bool invalidatePrevious,
576 bool mayDefinitelyPass) {
577 if (invalidatePrevious) {
581 for (
unsigned int i = 0; i < no && ok; i++) {
591 bool mayUseSameDestination,
592 bool mayDefinitelyPass) {
620 if ((*i).toEdge == destEdge && ((*i).fromLane == -1 || (*i).toLane == -1)) {
627 if (mayDefinitelyPass) {
647 std::vector<NBEdge::Connection>
649 std::vector<NBEdge::Connection> ret;
651 if ((*i).fromLane == static_cast<int>(lane)) {
686 if (find(outgoing.begin(), outgoing.end(), (*i).toEdge) == outgoing.end()) {
687 outgoing.push_back((*i).toEdge);
692 unsigned int size = (
unsigned int) outgoing.size();
694 edges->reserve(size);
695 for (EdgeVector::const_iterator i = outgoing.begin(); i != outgoing.end(); i++) {
698 edges->push_back(outedge);
710 if (find(ret.begin(), ret.end(), (*i).toEdge) == ret.end()) {
711 ret.push_back((*i).toEdge);
720 std::vector<int> ret;
723 if ((*i).toEdge == currentOutgoing) {
724 ret.push_back((*i).fromLane);
747 for (EdgeVector::const_iterator i = incoming.begin(); i != incoming.end(); i++) {
752 for (EdgeVector::iterator j = connected.begin(); j != connected.end(); j++) {
766 && (fromLane < 0 || c.
fromLane == fromLane)
767 && (toLane < 0 || c.
toLane == toLane)) {
788 if (reallowSetting) {
801 if ((*i).toEdge == which) {
813 std::map<int, int> laneMap;
817 bool wasConnected =
false;
819 if ((*i).toEdge != which) {
823 if ((*i).fromLane != -1) {
824 int fromLane = (*i).fromLane;
825 laneMap[(*i).toLane] = fromLane;
826 if (minLane == -1 || minLane > fromLane) {
829 if (maxLane == -1 || maxLane < fromLane) {
840 std::vector<NBEdge::Connection> conns = origConns;
841 for (std::vector<NBEdge::Connection>::iterator i = conns.begin(); i != conns.end(); ++i) {
842 if ((*i).toEdge == which) {
845 int fromLane = (*i).fromLane;
847 if (laneMap.find(fromLane) == laneMap.end()) {
848 if (fromLane >= 0 && fromLane <= minLane) {
851 if (fromLane >= 0 && fromLane >= maxLane) {
855 toUse = laneMap[fromLane];
874 unsigned int index = 0;
888 std::vector<Connection>::iterator i =
myConnections.begin() + index;
908 if ((*i).fromLane == static_cast<int>(lane)) {
929 std::string innerID =
":" + n.
getID();
940 std::pair<SUMOReal, std::vector<unsigned int> > crossingPositions(-1, std::vector<unsigned int>());
941 std::string foeInternalLanes;
942 std::set<std::string> tmpFoeIncomingLanes;
947 unsigned int index = 0;
949 for (EdgeVector::const_iterator i2 = incoming.begin(); i2 != incoming.end(); ++i2) {
950 const std::vector<Connection>& elv = (*i2)->getConnections();
951 for (std::vector<NBEdge::Connection>::const_iterator k2 = elv.begin(); k2 != elv.end(); k2++) {
952 if ((*k2).toEdge == 0) {
955 bool needsCont = n.
needsCont(
this, con.
toEdge, *i2, (*k2).toEdge, *k2);
958 crossingPositions.second.push_back(index);
963 if (minDV < shape.
length() - .1 && minDV > .1) {
965 if (crossingPositions.first < 0 || crossingPositions.first > minDV) {
966 crossingPositions.first = minDV;
972 if (n.
foes(
this, con.
toEdge, *i2, (*k2).toEdge)) {
973 if (foeInternalLanes.length() != 0) {
974 foeInternalLanes +=
" ";
976 foeInternalLanes += (
":" + n.
getID() +
"_" +
toString(index) +
"_0");
981 tmpFoeIncomingLanes.insert((*i2)->getID() +
"_" +
toString((*k2).fromLane));
986 if (dir ==
LINKDIR_TURN && crossingPositions.first < 0 && crossingPositions.second.size() != 0) {
1009 assert(shape.size() >= 2);
1011 if (crossingPositions.first >= 0) {
1012 std::pair<PositionVector, PositionVector> split = shape.
splitAt(crossingPositions.first);
1015 con.
shape = split.first;
1019 for (std::set<std::string>::iterator q = tmpFoeIncomingLanes.begin(); q != tmpFoeIncomingLanes.end(); ++q) {
1025 con.
viaID = innerID +
"_" +
toString(splitNo + noInternalNoSplits);
1067 assert(atNode ==
myTo);
1092 std::vector<SUMOReal> offsets;
1093 for (
unsigned int i = 0; i <
myLanes.size(); ++i) {
1094 offsets.push_back(0);
1097 for (
int i =
myLanes.size() - 2; i >= 0; --i) {
1099 offsets[i] = offset;
1107 for (
unsigned int i = 0; i <
myLanes.size(); ++i) {
1113 for (
unsigned int i = 0; i <
myLanes.size(); ++i) {
1114 offsets[i] += offset;
1121 for (
unsigned int i = 0; i <
myLanes.size(); ++i) {
1125 WRITE_WARNING(
"In edge '" +
getID() +
"': lane shape could not be determined (" + e.what() +
")");
1135 bool haveWarned =
false;
1136 for (
int i = 0; i < (
int)
myGeom.size(); i++) {
1140 std::pair<SUMOReal, SUMOReal> offsets =
laneOffset(from, to, offset,
false);
1143 Position(from.
x() - offsets.first, from.
y() - offsets.second, from.
z()));
1144 }
else if (i == static_cast<int>(
myGeom.size() - 1)) {
1147 std::pair<SUMOReal, SUMOReal> offsets =
laneOffset(from, to, offset,
false);
1150 Position(to.
x() - offsets.first, to.
y() - offsets.second, to.
z()));
1155 std::pair<SUMOReal, SUMOReal> offsets =
laneOffset(from, me, offset,
false);
1156 std::pair<SUMOReal, SUMOReal> offsets2 =
laneOffset(me, to, offset,
false);
1158 Position(from.
x() - offsets.first, from.
y() - offsets.second),
1159 Position(me.
x() - offsets.first, me.
y() - offsets.second));
1162 Position(me.
x() - offsets2.first, me.
y() - offsets2.second),
1163 Position(to.
x() - offsets2.first, to.
y() - offsets2.second));
1165 if (angle < 10. || angle > 350.) {
1168 Position(me.
x() - offsets.first, me.
y() - offsets.second, me.
z()));
1193 std::pair<SUMOReal, SUMOReal>
1197 return std::pair<SUMOReal, SUMOReal>(-offsets.first, -offsets.second);
1199 return std::pair<SUMOReal, SUMOReal>(offsets.first, offsets.second);
1206 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1217 std::vector<Lane>::const_iterator i =
myLanes.begin();
1220 for (; i !=
myLanes.end(); ++i) {
1221 if (i->permissions != firstLanePermissions) {
1231 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1242 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1253 for (std::vector<Lane>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
1278 for (EdgeVector::const_iterator i = o.begin(); i != o.end(); ++i) {
1316 std::vector<unsigned int> connNumbersPerLane(
myLanes.size(), 0);
1318 if ((*i).toEdge == 0 || (*i).fromLane < 0 || (*i).toLane < 0) {
1321 if ((*i).fromLane >= 0) {
1322 ++connNumbersPerLane[(*i).fromLane];
1333 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1334 if (connNumbersPerLane[i] == 0) {
1335 if (i > 0 && connNumbersPerLane[i - 1] > 1) {
1337 }
else if (i <
myLanes.size() - 1 && connNumbersPerLane[i + 1] > 1) {
1353 if (outgoing->size() == 0) {
1366 unsigned int size = (
unsigned int) outgoing->size();
1367 std::vector<SUMOReal> resultingLanes;
1368 resultingLanes.reserve(size);
1372 for (i = 0; i < size; i++) {
1383 resultingLanes.push_back(res);
1384 sumResulting += res;
1385 if (minResulting > res) {
1393 sumResulting += minResulting / (
SUMOReal) 2.;
1394 unsigned int noVirtual = (
unsigned int)(sumResulting / minResulting);
1397 transition.reserve(size);
1398 for (i = 0; i < size; i++) {
1401 assert(i < resultingLanes.size());
1403 for (
SUMOReal j = 0; j < tmpNo; j++) {
1404 assert(outgoing->size() > i);
1405 transition.push_back((*outgoing)[i]);
1413 const std::map<NBEdge*, std::vector<unsigned int> >& l2eConns = adder.
getBuiltConnections();
1415 for (std::map<
NBEdge*, std::vector<unsigned int> >::const_iterator i = l2eConns.begin(); i != l2eConns.end(); ++i) {
1416 const std::vector<unsigned int> lanes = (*i).second;
1417 for (std::vector<unsigned int>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
1429 std::vector<unsigned int>*
1432 std::vector<unsigned int>* priorities =
new std::vector<unsigned int>();
1433 if (outgoing->size() == 0) {
1436 priorities->reserve(outgoing->size());
1437 EdgeVector::const_iterator i;
1438 for (i = outgoing->begin(); i != outgoing->end(); i++) {
1439 int prio = (*i)->getJunctionPriority(
myTo);
1440 assert((prio + 1) * 2 > 0);
1441 prio = (prio + 1) * 2;
1442 priorities->push_back(prio);
1450 i = find(outgoing->begin(), outgoing->end(), *(tmp.begin()));
1451 unsigned int dist = (
unsigned int) distance(outgoing->begin(), i);
1453 assert(priorities->size() > 0);
1454 (*priorities)[0] = (*priorities)[0] / 2;
1459 if (mainDirections.
empty()) {
1460 assert(dist < priorities->size());
1461 (*priorities)[dist] = (*priorities)[dist] * 2;
1464 (*priorities)[dist] = (*priorities)[dist] * 2;
1473 unsigned int sum = 0;
1474 for (std::vector<unsigned int>::iterator i = priorities->begin(); i != priorities->end(); i++) {
1513 if (thisFromAngle2 < otherToAngle2) {
1514 std::swap(thisFromAngle2, otherToAngle2);
1516 if (thisFromAngle2 - otherToAngle2 > 170 && thisFromAngle2 - otherToAngle2 < 190) {
1527 if (pos < tolerance) {
1541 for (
unsigned int i = 0; i < lanes; i++) {
1543 for (std::vector<NBEdge::Connection>::iterator j = elv.begin(); j != elv.end(); j++) {
1545 assert(el.
tlID ==
"");
1592 assert(fromLane < 0 || fromLane < (
int)
myLanes.size());
1594 if (fromLane >= 0 && toLane >= 0) {
1596 std::vector<Connection>::iterator i =
1604 connection.
tlID = tlID;
1611 unsigned int no = 0;
1612 bool hadError =
false;
1614 if ((*i).toEdge != toEdge) {
1617 if (fromLane >= 0 && fromLane != (*i).fromLane) {
1620 if (toLane >= 0 && toLane != (*i).toLane) {
1623 if ((*i).tlID ==
"") {
1625 (*i).tlLinkNo = tlIndex;
1628 if ((*i).tlID != tlID && static_cast<int>((*i).tlLinkNo) == tlIndex) {
1629 WRITE_WARNING(
"The lane " + toString<int>((*i).fromLane) +
" on edge " +
getID() +
" already had a traffic light signal.");
1634 if (hadError && no == 0) {
1635 WRITE_WARNING(
"Could not set any signal of the traffic light '" + tlID +
"' (unknown group)");
1728 if (find(conn.begin(), conn.end(), possContinuation)
1745 if (conns.size() !=
myLanes.size()) {
1761 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1781 if ((*i).toEdge == e && (*i).tlID !=
"") {
1797 assert(lane <
myLanes.size());
1811 assert(distances.size() > 0);
1818 unsigned int newLaneNo = (
unsigned int)
myLanes.size() + by;
1819 while (
myLanes.size() < newLaneNo) {
1824 for (EdgeVector::const_iterator i = incs.begin(); i != incs.end(); ++i) {
1825 (*i)->invalidateConnections(
true);
1833 unsigned int newLaneNo = (
unsigned int)
myLanes.size() - by;
1834 while (
myLanes.size() > newLaneNo) {
1839 for (EdgeVector::const_iterator i = incs.begin(); i != incs.end(); ++i) {
1840 (*i)->invalidateConnections(
true);
1846 assert(outs.size() == 1);
1867 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1871 assert(lane < (
int)
myLanes.size());
1872 myLanes[lane].permissions |= vclass;
1880 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1884 assert(lane < (
int)
myLanes.size());
1885 myLanes[lane].permissions &= ~vclass;
1893 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1897 assert(lane < (
int)
myLanes.size());
1898 myLanes[lane].preferred |= vclass;
1908 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1914 assert(lane < (
int)
myLanes.size());
1931 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1937 assert(lane < (
int)
myLanes.size());
1938 myLanes[lane].offset = offset;
1947 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1953 assert(lane < (
int)
myLanes.size());
1961 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1966 assert(lane < (
int)
myLanes.size());
1967 myLanes[lane].permissions = permissions;
1975 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1980 assert(lane < (
int)
myLanes.size());
1981 myLanes[lane].preferred = permissions;
1990 for (
unsigned int i = 0; i <
myLanes.size(); i++) {
1995 assert(lane < (
int)
myLanes.size());
1996 return myLanes[lane].permissions;
2009 for (std::vector<Lane>::iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {