Skip to content

Commit

Permalink
Not real leaders
Browse files Browse the repository at this point in the history
But now we _do_ need to pay attention to people waiting right at the
intersection already
  • Loading branch information
dabreegster committed Apr 28, 2022
1 parent 97db9ff commit 4a6561e
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions sim/src/mechanics/intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ struct State {
// uber-turn at nearby intersections.
uber_turn_neighbors: Vec<IntersectionID>,

// The original turn requested is stored here, but the agent may change their mind about the
// lanes by the time they arrive
// This is keyed by the lane the agent is approaching from. Note that:
// 1) the turn in the request may change by the time the leader arrives -- they might decide to
// aim for a different destination lane
// 2) If another agent pulls out on a driveway before this agent, they become the leader and
// overwrite this one
#[serde(
serialize_with = "serialize_btreemap",
deserialize_with = "deserialize_btreemap"
)]
leader_eta: BTreeMap<AgentID, (TurnID, Time)>,
leader_eta: BTreeMap<LaneID, (Request, Time)>,

signal: Option<SignalState>,
}
Expand Down Expand Up @@ -406,7 +409,7 @@ impl IntersectionSimState {
.get_mut(&turn.parent)
.unwrap()
.leader_eta
.remove(&req.agent)
.remove(&req.turn.src)
{
// When they're late, it's because of a slow laggy head. Conflicting turns would've
// been blocked anyway. Uncomment to debug
Expand Down Expand Up @@ -671,7 +674,11 @@ impl IntersectionSimState {
// And it's idempotent -- can call to update an ETA.
pub fn approaching_leader(&mut self, agent: AgentID, turn: TurnID, eta: Time) {
let state = self.state.get_mut(&turn.parent).unwrap();
state.leader_eta.insert(agent, (turn, eta));
// If there was a previous entry here for turn.src, then this leader is spawning in front
// of the previous leader on a driveway
state
.leader_eta
.insert(turn.src, (Request { agent, turn }, eta));
}
}

Expand Down Expand Up @@ -875,11 +882,11 @@ impl IntersectionSimState {

let turn = map.get_t(req.turn);
let expected_finish = now + turn.geom.length() / speed;
for (_other_agent, (other_turn, eta)) in &self.state[&req.turn.parent].leader_eta {
for (_, (other_req, eta)) in &self.state[&req.turn.parent].leader_eta {
if expected_finish < *eta {
continue;
}
let other_turn = map.get_t(*other_turn);
let other_turn = map.get_t(other_req.turn);
if other_turn.conflicts_with(turn) {
// Now we need to prioritize between the two. First use the stop sign priority
let their_priority = sign.get_priority(other_turn.id, map);
Expand Down Expand Up @@ -911,10 +918,10 @@ impl IntersectionSimState {
our_rank > their_rank
};
if should_yield {
/*info!(
info!(
"{} is yielding to approaching {}",
req.agent, other_agent
);*/
req.agent, other_req.agent
);
return false;
} else {
/*info!(
Expand Down

0 comments on commit 4a6561e

Please sign in to comment.