guarantee protected turns actually get first dibs in the scheduler

This commit is contained in:
Dustin Carlino 2019-11-22 18:56:39 -08:00
parent 1145bbc8e6
commit 3ee73d40f0
3 changed files with 11 additions and 2 deletions

View File

@ -71,7 +71,8 @@ pub struct Turn {
// TODO Some turns might not actually have geometry. Currently encoded by two equal points.
// Represent more directly?
pub geom: PolyLine,
// Empty except for TurnType::Crosswalk.
// Empty except for TurnType::Crosswalk. Usually just one other ID, except for the case of 4
// duplicates at a degenerate intersection.
pub other_crosswalk_ids: BTreeSet<TurnID>,
// Just for convenient debugging lookup.

View File

@ -159,12 +159,19 @@ impl IntersectionSimState {
unreachable!()
};
protected.extend(yielding);
for req in protected {
// Use update because multiple agents could finish a turn at the same time, before the
// waiting one has a chance to try again.
scheduler.update(now, Command::update_agent(req.agent));
}
// Make sure the protected group gets first dibs. The scheduler arbitrarily (but
// deterministically) orders commands with the same time.
for req in yielding {
scheduler.update(
now + Duration::seconds(0.1),
Command::update_agent(req.agent),
);
}
}
// This is only triggered for traffic signals.

View File

@ -70,6 +70,7 @@ impl Ord for Item {
if ord != Ordering::Equal {
return ord;
}
// This is important! The tie-breaker if time is the same is ARBITRARY!
self.cmd_type.cmp(&other.cmd_type)
}
}