73 #ifdef CHECK_MEMORY_LEAKS
75 #endif // CHECK_MEMORY_LEAKS
91 myShape(shape), myNumericalID(numericalID),
92 myVehicles(), myLength(length), myWidth(width), myEdge(edge), myMaxSpeed(maxSpeed),
93 myPermissions(permissions),
94 myLogicalPredecessorLane(0),
95 myBruttoVehicleLengthSum(0), myNettoVehicleLengthSum(0), myInlappingVehicleEnd(10000), myInlappingVehicle(0),
96 myLengthGeometryFactor(myShape.length() / myLength) {}
100 for (MSLinkCont::iterator i =
myLinks.begin(); i !=
myLinks.end(); ++i) {
117 (*veh)->addReminder(rem);
156 if (leader.first != 0) {
158 vIn = leader.first->getSpeed();
159 leaderDecel = leader.first->getCarFollowModel().getMaxDecel();
165 const SUMOReal vHlp = 0.5 * (vIn + mspeed);
169 for (
int i = 0; i <= 10; i++) {
180 }
else if (x > maxPos) {
199 if (leader.first != 0) {
201 vIn = leader.first->getSpeed();
207 const SUMOReal vHlp = 0.5 * (mspeed + vIn);
211 }
else if (xIn > maxPos) {
225 MSLane::VehCont::iterator predIt =
myVehicles.begin();
228 MSLane::VehCont::iterator maxIt =
myVehicles.begin();
247 const SUMOReal lhs = nettoGap / tau + tauDecel - fSpeed - fSpeed * fSpeed / (2 * tauDecel) + leaderSpeed * leaderSpeed / (2 * tauDecel);
248 if (lhs >= sqrt(tauDecel * tauDecel + leaderSpeed * leaderSpeed)) {
250 const SUMOReal currentMaxSpeed = lhs - tauDecel;
251 if (
MIN2(currentMaxSpeed, mspeed) > maxSpeed) {
252 maxSpeed = currentMaxSpeed;
271 bool adaptableSpeed =
true;
281 if (adaptableSpeed) {
285 if (leaderPos - frontGapNeeded >= 0) {
294 MSLane::VehCont::iterator predIt =
myVehicles.begin();
302 if (adaptableSpeed && leader != 0) {
314 frontMax = leaderRearPos - frontGapNeeded;
322 if (frontMax > 0 && backMin +
POSITION_EPS < frontMax) {
339 bool patchSpeed =
true;
375 for (
unsigned int i = 0; i < 10; i++) {
407 if (nspeed < speed) {
409 speed =
MIN2(nspeed, speed);
412 if (errorMsg !=
"") {
413 WRITE_ERROR(
"Vehicle '" + aVehicle->
getID() +
"' will not be able to depart using the given velocity (" + errorMsg +
")!");
430 aVehicle->
getID() +
"'. Inserting at lane end instead.");
436 std::vector<MSLane*>::const_iterator ri = bestLaneConts.begin();
441 unsigned int nRouteSuccs = 1;
442 MSLane* currentLane =
this;
445 while (seen < dist && ri != bestLaneConts.end()) {
447 MSLinkCont::const_iterator link =
succLinkSec(*aVehicle, nRouteSuccs, *currentLane, bestLaneConts);
453 patchSpeed,
"arrival speed too low")) {
461 patchSpeed,
"junction too close")) {
469 || !(*link)->havePriority()) {
471 std::string errorMsg =
"";
472 const LinkState state = (*link)->getState();
478 errorMsg =
"unpriorised junction too close";
481 patchSpeed, errorMsg)) {
488 nextLane = (*link)->getViaLaneOrLane();
508 if (
checkFailure(aVehicle, speed, dist, nspeed, patchSpeed,
"")) {
515 if (nspeed < speed) {
521 WRITE_ERROR(
"Vehicle '" + aVehicle->
getID() +
"' will not be able to depart using the given velocity (slow lane ahead)!");
531 if ((*link)->hasApproachingFoe(arrivalTime, leaveTime, speed, cfModel.
getMaxDecel())) {
539 currentLane = nextLane;
540 #ifdef HAVE_INTERNAL_LANES
541 if ((*link)->getViaLane() == 0) {
559 if (gap < frontGapNeeded) {
571 if (gap < backGapNeeded) {
584 if (missingRearGap > 0) {
586 const SUMOReal neededStartPos = pos + missingRearGap;
589 pos = neededStartPos;
616 if (leftVehicleLength > myLength) {
634 std::pair<MSVehicle*, SUMOReal>
640 return std::make_pair(last, pos);
646 return std::make_pair<MSVehicle*, SUMOReal>(0, 0);
657 if ((*veh)->getLane() ==
this) {
658 (*veh)->planMove(t, pred, cumulatedVehLength);
672 VehCont::iterator lastVeh =
myVehicles.end() - 1;
673 for (VehCont::iterator veh =
myVehicles.begin(); veh != lastVeh;) {
674 VehCont::iterator pred = veh + 1;
675 if ((*veh)->hasInfluencer() && (*veh)->getInfluencer().isVTDControlled()) {
679 if ((*pred)->hasInfluencer() && (*pred)->getInfluencer().isVTDControlled()) {
683 SUMOReal gap = (*pred)->getPositionOnLane() - (*pred)->getVehicleType().getLength() - (*veh)->getPositionOnLane() - (*veh)->getVehicleType().getMinGap();
688 + (*pred)->getID() +
"', lane='" +
getID() +
"', gap=" +
toString(gap)
701 + (*pred)->getID() +
"', lane='" +
getID() +
"', gap=" +
toString(gap)
741 }
else if (target != 0 && moved) {
752 into.push_back(target);
755 if (shadowLane != 0) {
756 into.push_back(shadowLane);
768 WRITE_WARNING(
"Teleporting vehicle '" + veh->
getID() +
"'; beyond end of lane, targetLane='" +
getID() +
"', time=" +
779 i = VehCont::reverse_iterator(
myVehicles.erase(i.base()));
790 const bool minorLink = !wrongLane && (link !=
myLinks.end()) && !((*link)->havePriority());
791 const std::string reason = (wrongLane ?
" (wrong lane)" : (minorLink ?
" (yield)" :
" (jam)"));
798 + (r2 ?
" (highway)" :
"")
802 }
else if (minorLink) {
829 DictType::iterator it =
myDict.find(
id);
832 myDict.insert(DictType::value_type(
id, ptr));
841 DictType::iterator it =
myDict.find(
id);
852 for (DictType::iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
861 for (DictType::iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
862 into.push_back((*i).first);
867 template<
class RTREE>
void
869 for (DictType::iterator i =
myDict.begin(); i !=
myDict.end(); ++i) {
875 into.Insert(cmin, cmax, l);
879 template void MSLane::fill<NamedRTree>(
NamedRTree& into);
899 return (link !=
myLinks.end());
948 MSLinkCont::const_iterator
950 const MSLane& succLinkSource,
const std::vector<MSLane*>& conts) {
953 if (nRouteEdge == 0) {
955 return succLinkSource.
myLinks.end();
959 assert(succLinkSource.
myLinks.size() == 1);
961 return succLinkSource.
myLinks.begin();
971 MSLinkCont::const_iterator link;
972 if (nRouteSuccs < conts.size()) {
974 for (link = succLinkSource.
myLinks.begin(); link != succLinkSource.
myLinks.end(); ++link) {
975 if ((*link)->getLane() != 0 && (*link)->getLane()->myEdge == nRouteEdge && (*link)->getLane()->allowsVehicleClass(veh.
getVehicleType().
getVehicleClass())) {
977 if ((*link)->getLane() == conts[nRouteSuccs]) {
984 return succLinkSource.
myLinks.end();
988 WRITE_WARNING(
"Could not find connection between '" + succLinkSource.
getID() +
"' and '" + conts[nRouteSuccs]->getID() +
991 return succLinkSource.
myLinks.end();
1012 if (remVehicle == *it) {
1060 std::map<MSEdge*, std::vector<MSLane*> >::const_iterator i =
myApproachingLanes.find(edge);
1064 const std::vector<MSLane*>& lanes = (*i).second;
1065 return find(lanes.begin(), lanes.end(), lane) != lanes.end();
1071 inline int operator()(
const std::pair<const MSVehicle* , SUMOReal>& p1,
const std::pair<const MSVehicle* , SUMOReal>& p2)
const {
1072 return p1.second < p2.second;
1082 std::set<MSLane*> visited;
1083 std::vector<MSLane::IncomingLaneInfo> newFound;
1085 while (toExamine.size() != 0) {
1086 for (std::vector<MSLane::IncomingLaneInfo>::iterator i = toExamine.begin(); i != toExamine.end(); ++i) {
1087 MSLane* next = (*i).lane;
1093 result =
MAX2(result, missingRearGap);
1095 if ((*i).length < dist) {
1096 const std::vector<MSLane::IncomingLaneInfo>& followers = next->
getIncomingLanes();
1097 for (std::vector<MSLane::IncomingLaneInfo>::const_iterator j = followers.begin(); j != followers.end(); ++j) {
1098 if (visited.find((*j).lane) == visited.end()) {
1099 visited.insert((*j).lane);
1101 ili.
lane = (*j).lane;
1102 ili.
length = (*j).length + (*i).length;
1104 newFound.push_back(ili);
1111 swap(newFound, toExamine);
1117 std::pair<MSVehicle* const, SUMOReal>
1122 std::pair<MSVehicle*, SUMOReal> result(static_cast<MSVehicle*>(0), -1);
1124 std::set<MSLane*> visited;
1125 std::vector<MSLane::IncomingLaneInfo> newFound;
1127 while (toExamine.size() != 0) {
1128 for (std::vector<MSLane::IncomingLaneInfo>::iterator i = toExamine.begin(); i != toExamine.end(); ++i) {
1129 MSLane* next = (*i).lane;
1134 if (missingRearGap > missingRearGapMax) {
1135 missingRearGapMax = missingRearGap;
1137 result.second = agap;
1140 if ((*i).length < dist) {
1141 const std::vector<MSLane::IncomingLaneInfo>& followers = next->
getIncomingLanes();
1142 for (std::vector<MSLane::IncomingLaneInfo>::const_iterator j = followers.begin(); j != followers.end(); ++j) {
1143 if (visited.find((*j).lane) == visited.end()) {
1144 visited.insert((*j).lane);
1146 ili.
lane = (*j).lane;
1147 ili.
length = (*j).length + (*i).length;
1149 newFound.push_back(ili);
1156 swap(newFound, toExamine);
1162 std::pair<MSVehicle* const, SUMOReal>
1164 const std::vector<MSLane*>& bestLaneConts)
const {
1166 return std::make_pair(static_cast<MSVehicle*>(0), -1);
1168 unsigned int view = 1;
1173 const MSLane* nextLane =
this;
1177 MSLinkCont::const_iterator link =
succLinkSec(veh, view, *nextLane, bestLaneConts);
1182 #ifdef HAVE_INTERNAL_LANES
1185 if (linkLeaders.size() > 0) {
1188 return linkLeaders[0].vehAndGap;
1190 bool nextInternal = (*link)->getViaLane() != 0;
1192 nextLane = (*link)->getViaLaneOrLane();
1193 if (nextLane == 0) {
1213 #ifdef HAVE_INTERNAL_LANES
1214 if (!nextInternal) {
1220 }
while (seen <= dist);
1221 return std::make_pair(static_cast<MSVehicle*>(0), -1);
1233 for (std::vector<MSEdge*>::iterator i = pred.begin(); i != pred.end();) {
1242 if (pred.size() != 0) {
1244 MSEdge* best = *pred.begin();
1264 std::vector<const MSLane*>
1266 std::vector<const MSLane*> result;
1267 for (MSLinkCont::const_iterator i =
myLinks.begin(); i !=
myLinks.end(); ++i) {
1268 assert((*i)->getLane() != 0);
1269 result.push_back((*i)->getLane());
1291 for (MSLinkCont::const_iterator i =
myLinks.begin(); i !=
myLinks.end(); ++i) {
1292 if ((*i)->getLane()->getEdge().isCrossing()) {
1293 return (
int)(i -
myLinks.begin());
1343 wtime += (*i)->getWaitingSeconds();
1356 for (VehCont::const_iterator i = vehs.begin(); i != vehs.end(); ++i) {
1357 v += (*i)->getSpeed();
1369 for (MSLane::VehCont::const_iterator i = vehs.begin(); i != vehs.end(); ++i) {
1370 ret += (*i)->getCO2Emissions();
1381 for (MSLane::VehCont::const_iterator i = vehs.begin(); i != vehs.end(); ++i) {
1382 ret += (*i)->getCOEmissions();
1393 for (MSLane::VehCont::const_iterator i = vehs.begin(); i != vehs.end(); ++i) {
1394 ret += (*i)->getPMxEmissions();
1405 for (MSLane::VehCont::const_iterator i = vehs.begin(); i != vehs.end(); ++i) {
1406 ret += (*i)->getNOxEmissions();
1417 for (MSLane::VehCont::const_iterator i = vehs.begin(); i != vehs.end(); ++i) {
1418 ret += (*i)->getHCEmissions();
1429 for (MSLane::VehCont::const_iterator i = vehs.begin(); i != vehs.end(); ++i) {
1430 ret += (*i)->getFuelConsumption();
1441 if (vehs.size() == 0) {
1445 for (MSLane::VehCont::const_iterator i = vehs.begin(); i != vehs.end(); ++i) {
1446 SUMOReal sv = (*i)->getHarmonoise_NoiseEmissions();
1447 ret += (
SUMOReal) pow(10., (sv / 10.));
1467 myLaneDir(e->getLanes()[0]->
getShape().getBegLine().atan2PositiveAngle())
1476 if (ae1 != 0 && ae1->size() != 0) {
1480 if (ae2 != 0 && ae2->size() != 0) {
1499 for (std::vector<std::string>::const_iterator it = vehIds.begin(); it != vehIds.end(); ++it) {