simplify rules for starting a turn through a stop sign. should retain priority, but be opportunistic when higher-ranked agents are actually blocked

This commit is contained in:
Dustin Carlino 2019-08-12 14:33:56 -07:00
parent 784e076aff
commit 6950c22394

View File

@ -202,27 +202,6 @@ impl State {
true true
} }
fn is_ready_at_stop_sign(
&self,
sign: &ControlStopSign,
req: &Request,
now: Duration,
map: &Map,
) -> bool {
if self.any_accepted_conflict_with(req.turn, map) {
return false;
}
let our_priority = sign.turns[&req.turn];
let our_time = self.waiting[req];
if our_priority == TurnPriority::Stop && now < our_time + WAIT_AT_STOP_SIGN {
return false;
}
true
}
fn stop_sign_policy( fn stop_sign_policy(
&self, &self,
sign: &ControlStopSign, sign: &ControlStopSign,
@ -250,25 +229,18 @@ impl State {
return false; return false;
} }
let our_turn = map.get_t(req.turn); // Once upon a time, we'd make sure that this request doesn't conflict with another in
for (r, time) in &self.waiting { // self.waiting:
// If the turns don't conflict, then don't even worry. // 1) Higher-ranking turns get to go first.
if !our_turn.conflicts_with(map.get_t(r.turn)) { // 2) Equal-ranking turns that started waiting before us get to go first.
continue; // But the exceptions started stacking -- if the other agent is blocked or the turns don't
} // even conflict, then allow it. Except determining if the other agent is blocked or not is
// If the other can't go yet, then proceed. // tough and kind of recursive.
if !self.is_ready_at_stop_sign(sign, r, now, map) { //
continue; // So instead, don't do any of that! The WAIT_AT_STOP_SIGN scheduling above and the fact
} // that events are processed in time order mean that case #2 is magically handled anyway.
// If a case #1 could've started by now, then they would have. Since they didn't, they must
// If there's a higher rank turn waiting, don't allow // be blocked.
if sign.turns[&r.turn] > our_priority {
return false;
// If there's an equal rank turn queued before ours, don't allow
} else if sign.turns[&r.turn] == our_priority && *time < our_time {
return false;
}
}
// TODO Make sure we can optimistically finish this turn before an approaching // TODO Make sure we can optimistically finish this turn before an approaching
// higher-priority vehicle wants to begin. // higher-priority vehicle wants to begin.