Skip to content

Commit

Permalink
ignoring leaders beyond red light for lane changing. fix #10665
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed May 4, 2022
1 parent 8d6d6c7 commit 3c8635a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/microsim/MSLane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2498,7 +2498,7 @@ MSLane::getLeader(const MSVehicle* veh, const double vehPos, const std::vector<M
if (seen > dist) {
return std::pair<MSVehicle* const, double>(static_cast<MSVehicle*>(nullptr), -1);
}
return getLeaderOnConsecutive(dist, seen, speed, *veh, bestLaneConts);
return getLeaderOnConsecutive(dist, seen, speed, *veh, bestLaneConts, false);
} else {
return std::make_pair(static_cast<MSVehicle*>(nullptr), -1);
}
Expand All @@ -2507,7 +2507,7 @@ MSLane::getLeader(const MSVehicle* veh, const double vehPos, const std::vector<M

std::pair<MSVehicle* const, double>
MSLane::getLeaderOnConsecutive(double dist, double seen, double speed, const MSVehicle& veh,
const std::vector<MSLane*>& bestLaneConts) const {
const std::vector<MSLane*>& bestLaneConts, bool abortClosed) const {
#ifdef DEBUG_CONTEXT
if (DEBUG_COND2(&veh)) {
std::cout << " getLeaderOnConsecutive lane=" << getID() << " ego=" << veh.getID() << " seen=" << seen << " dist=" << dist << " conts=" << toString(bestLaneConts) << "\n";
Expand Down Expand Up @@ -2542,7 +2542,7 @@ MSLane::getLeaderOnConsecutive(double dist, double seen, double speed, const MSV
nextLane->getVehiclesSecure(); // lock against running sim when called from GUI for time gap coloring
// get the next link used
std::vector<MSLink*>::const_iterator link = succLinkSec(veh, view, *nextLane, bestLaneConts);
if (nextLane->isLinkEnd(link)) {
if (nextLane->isLinkEnd(link) || (abortClosed && (*link)->haveRed())) {
#ifdef DEBUG_CONTEXT
if (DEBUG_COND2(&veh)) {
std::cout << " cannot continue after nextLane=" << nextLane->getID() << "\n";
Expand Down
3 changes: 2 additions & 1 deletion src/microsim/MSLane.h
Original file line number Diff line number Diff line change
Expand Up @@ -907,10 +907,11 @@ class MSLane : public Named, public Parameterised {
* @param[in] speed The speed of the vehicle used for determining whether a subsequent link will be opened at arrival time
* @param[in] veh The vehicle for which the information shall be computed
* @param[in] bestLaneConts The lanes the vehicle will use in future
* @param[in] abortClosed Whether the leader search should abort upon encountering a closed link
* @return
*/
std::pair<MSVehicle* const, double> getLeaderOnConsecutive(double dist, double seen,
double speed, const MSVehicle& veh, const std::vector<MSLane*>& bestLaneConts) const;
double speed, const MSVehicle& veh, const std::vector<MSLane*>& bestLaneConts, bool abortClosed) const;

/// @brief Returns the immediate leaders and the distance to them (as getLeaderOnConsecutive but for the sublane case)
void getLeadersOnConsecutive(double dist, double seen, double speed, const MSVehicle* ego,
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/MSLaneChanger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ MSLaneChanger::getRealLeader(const ChangerIt& target) const {
}
const std::vector<MSLane*>& bestLaneConts = vehicle->getBestLanesContinuation(targetLane);

std::pair<MSVehicle* const, double> result = target->lane->getLeaderOnConsecutive(dist, seen, speed, *vehicle, bestLaneConts);
std::pair<MSVehicle* const, double> result = target->lane->getLeaderOnConsecutive(dist, seen, speed, *vehicle, bestLaneConts, true);
#ifdef DEBUG_SURROUNDING_VEHICLES
if (DEBUG_COND) {
std::cout << " found consecutiveLeader=" << Named::getIDSecure(result.first) << "\n";
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/MSVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5925,7 +5925,7 @@ MSVehicle::getLeader(double dist) const {
}
const double seen = myLane->getLength() - getPositionOnLane();
const std::vector<MSLane*>& bestLaneConts = getBestLanesContinuation(myLane);
std::pair<const MSVehicle* const, double> result = myLane->getLeaderOnConsecutive(dist, seen, getSpeed(), *this, bestLaneConts);
std::pair<const MSVehicle* const, double> result = myLane->getLeaderOnConsecutive(dist, seen, getSpeed(), *this, bestLaneConts, false);
lane->releaseVehicles();
return result;
}
Expand Down

0 comments on commit 3c8635a

Please sign in to comment.