diff --git a/src/microsim/MSLane.cpp b/src/microsim/MSLane.cpp index 044bcc5..25e5aef 100644 --- a/src/microsim/MSLane.cpp +++ b/src/microsim/MSLane.cpp @@ -81,7 +81,7 @@ //#define DEBUG_PEDESTRIAN_COLLISIONS //#define DEBUG_LANE_SORTER //#define DEBUG_NO_CONNECTION -//#define DEBUG_SURROUNDING +#define DEBUG_SURROUNDING //#define DEBUG_EXTRAPOLATE_DEPARTPOS //#define DEBUG_COND (false) @@ -3790,7 +3790,35 @@ MSLane::addLeaders(const MSVehicle* vehicle, double vehPos, MSLeaderDistanceInfo dist = MAX2(dist, myMaxSpeed * 20); } if (seen > dist) { + if (isInternal() && myLinks.front()->isExitLink()) { #ifdef DEBUG_SURROUNDING + if (DEBUG_COND || DEBUG_COND2(vehicle)) gDebugFlag1 = true; +#endif + // check for link leaders + const MSLink* exitLink = myLinks.front(); + const MSLink::LinkLeaders linkLeaders = exitLink->getLeaderInfo(vehicle, seen); + if (linkLeaders.size() > 0) { + const MSLink::LinkLeader ll = linkLeaders[0]; + MSVehicle* veh = ll.vehAndGap.first; + // in the context of lane changing all junction leader candidates must be respected + if (veh != 0 && (vehicle->isLeader(exitLink, veh, ll.vehAndGap.second) + || (MSGlobals::gComputeLC + && veh->getPosition().distanceTo2D(vehicle->getPosition()) - veh->getVehicleType().getMinGap() - vehicle->getVehicleType().getLength() + < veh->getCarFollowModel().brakeGap(veh->getSpeed())))) { + // add link leader to all sublanes and return + for (int i = 0; i < result.numSublanes(); ++i) { + result.addLeader(veh, ll.vehAndGap.second, 0); + } +#ifdef DEBUG_SURROUNDING + if (DEBUG_COND2(vehicle)) { + std::cout << SIMTIME << " lc=" << MSGlobals::gComputeLC << " ego=" << vehicle->getID() << " lane=" << getID() << " linkleader=" << veh->getID() << " gap=" << ll.vehAndGap.second << "\n"; + } +#endif + } + } + } +#ifdef DEBUG_SURROUNDING + gDebugFlag1 = false; if (DEBUG_COND || DEBUG_COND2(vehicle)) { std::cout << " aborting forward search. dist=" << dist << " seen=" << seen << "\n"; }