Skip to content

Commit

Permalink
MSCFModel_CC: make isPlatoonLaneChangeSafe return 0 if true or otherw…
Browse files Browse the repository at this point in the history
…ise the type of blockage
  • Loading branch information
michele-segata authored and namdre committed May 2, 2024
1 parent 280bd4e commit 646a4a9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
37 changes: 28 additions & 9 deletions src/microsim/cfmodels/MSCFModel_CC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ MSCFModel_CC::setLeader(MSVehicle* veh, MSVehicle* const leader) const {
vars->leaderVehicle = leader;
}

bool
MSCFModel_CC::isPlatoonLaneChangeSafe(MSVehicle* const veh, bool left) const {
int
MSCFModel_CC::isPlatoonLaneChangeSafe(const MSVehicle* veh, bool left) const {
CC_VehicleVariables* vars = (CC_VehicleVariables*) veh->getCarFollowVariables();
int result = 0;
std::pair<int, int> state = libsumo::Vehicle::getLaneChangeState(veh->getID(), left ? +1 : -1);
// bit 1: query lateral direction (left:0, right:1)
// bit 2: query longitudinal direction (followers:0, leaders:1)
Expand All @@ -132,13 +133,31 @@ MSCFModel_CC::isPlatoonLaneChangeSafe(MSVehicle* const veh, bool left) const {
leaders = libsumo::Vehicle::getNeighbors(m->second, left ? 0b110 : 0b111);
noNeighbors = followers.empty() && leaders.empty();
if (mState.second & LCA_BLOCKED || !noNeighbors) {
return false;
if (mState.second & LCA_BLOCKED) {
result = mState.second;
}
else {
if (!followers.empty())
result |= left ? LCA_BLOCKED_BY_LEFT_FOLLOWER : LCA_BLOCKED_BY_RIGHT_FOLLOWER;
if (!leaders.empty())
result |= left ? LCA_BLOCKED_BY_LEFT_LEADER : LCA_BLOCKED_BY_RIGHT_LEADER;
}
break;
}
}
} else {
return false;
}
return true;
else {
if (state.second & LCA_BLOCKED) {
result = state.second;
}
else {
if (!followers.empty())
result |= left ? LCA_BLOCKED_BY_LEFT_FOLLOWER : LCA_BLOCKED_BY_RIGHT_FOLLOWER;
if (!leaders.empty())
result |= left ? LCA_BLOCKED_BY_LEFT_LEADER : LCA_BLOCKED_BY_RIGHT_LEADER;
}
}
return result;
}

void
Expand All @@ -157,7 +176,7 @@ MSCFModel_CC::performAutoLaneChange(MSVehicle* const veh) const {
int traciState = state.first;
if (traciState & LCA_LEFT && traciState & LCA_SPEEDGAIN) {
// we can gain by moving left. check that all vehicles can move left
if (isPlatoonLaneChangeSafe(veh, true)) {
if (isPlatoonLaneChangeSafe(veh, true) == 0) {
changeWholePlatoonLane(veh, +1);
}
}
Expand All @@ -166,7 +185,7 @@ MSCFModel_CC::performAutoLaneChange(MSVehicle* const veh) const {
traciState = state.first;
if (traciState & LCA_RIGHT && traciState & LCA_KEEPRIGHT) {
// we should move back right. check that all vehicles can move right
if (isPlatoonLaneChangeSafe(veh, false)) {
if (isPlatoonLaneChangeSafe(veh, false) == 0) {
changeWholePlatoonLane(veh, -1);
}
}
Expand All @@ -182,7 +201,7 @@ MSCFModel_CC::performPlatoonLaneChange(MSVehicle* const veh) const {
return;
}
bool left = currentLane < vars->platoonFixedLane;
if (isPlatoonLaneChangeSafe(veh, left)) {
if (isPlatoonLaneChangeSafe(veh, left) == 0) {
changeWholePlatoonLane(veh, left ? +1 : -1);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/cfmodels/MSCFModel_CC.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class MSCFModel_CC : public MSCFModel {
*/
double getACCAcceleration(const MSVehicle* veh) const;

bool isPlatoonLaneChangeSafe(MSVehicle* const veh, bool left) const;
int isPlatoonLaneChangeSafe(const MSVehicle* veh, bool left) const;

void setLeader(MSVehicle* veh, MSVehicle* const leader) const;

Expand Down

0 comments on commit 646a4a9

Please sign in to comment.