-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check controlled state safely #115
Conversation
src/headless.cpp
Outdated
@@ -71,10 +71,7 @@ int main(int argc, char *argv[]) | |||
.distanceToExpertThreshold = 0.5 | |||
}, | |||
.maxNumControlledVehicles = 0, | |||
}, | |||
.enableBatchRenderer = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for catching it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only blocking comment is about the else if
.
src/sim.cpp
Outdated
// Technically there would never be a collision between (non valid expert) and (non expert). So one of the below checks would always be false. | ||
if(ctx.get<ControlledState>(candidateCollision.a).controlledState == ControlMode::EXPERT) | ||
if(controlledStateA.valid()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bodies of these if statements are identical save for the Loc
. It would be nice if you factored out the logic into a lambda:
auto isExpertAgentInInvalidState = [&](Loc loc) {
auto maybeControlledState = ctx.getCheck<ControlledState>(loc);
if (not maybeControlledState.valid()) {
return false;
}
if (maybeControlledState.value().controlledState != ControlMode::EXPERT) {
return false;
}
auto currStep = getCurrentStep(ctx.get<StepsRemaining>(loc));
return not ctx.get<Trajectory>(loc).valids[currStep];
};
then the if-statements would be
if(controlledStateA.valid()) | |
if(isExpertAgentInInvalidState(candidateCollision.a)) { | |
return; | |
} |
src/sim.cpp
Outdated
} | ||
else if(ctx.get<ControlledState>(candidateCollision.b).controlledState == ControlMode::EXPERT) | ||
else if(controlledStateB.valid()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be an else if
. For instance, if candidateCollision.a
is a non-expert agent and candidateCollision.b
is an expert-agent in an invalid state, this function will not be short-ciruited.
In the previous, we were checking the control state on entities to determine if they were non valid experts. However, that is error prone as not all entities have control states (physics entities like roads). This PR fixes that by using the safer
getCheck<>
.