Fix a treachurous bug that was crashing the simulation, first uncovered

by chance in #870.

A vehicle exits a driveway and blocks a lane on its way out. When we try
to clear the static blockage, the queue calculation recurses to resolve
distances on the queue where that vehicle is entering. But since we
temporarily don't have the car in the list of cars (for the borrow
checker), it was crashing.

One of those "2 hours to figure out, 30 seconds to fix" bugs.
This commit is contained in:
Dustin Carlino 2022-04-23 20:03:28 +01:00
parent b867859dde
commit 9b4abae174
4 changed files with 25 additions and 3 deletions

View File

@ -25,7 +25,7 @@ pub fn prebake_all() {
let mut summaries = Vec::new(); let mut summaries = Vec::new();
for name in vec![ for name in vec![
//MapName::seattle("arboretum"), MapName::seattle("arboretum"),
MapName::seattle("montlake"), MapName::seattle("montlake"),
//MapName::seattle("lakeslice"), //MapName::seattle("lakeslice"),
//MapName::seattle("phinney"), //MapName::seattle("phinney"),

View File

@ -5200,6 +5200,11 @@
"uncompressed_size_bytes": 49839934, "uncompressed_size_bytes": 49839934,
"compressed_size_bytes": 19580571 "compressed_size_bytes": 19580571
}, },
"data/system/us/seattle/prebaked_results/arboretum/weekday.bin": {
"checksum": "e2569e2629949dad887eb75f7184c910",
"uncompressed_size_bytes": 16719161,
"compressed_size_bytes": 6419906
},
"data/system/us/seattle/prebaked_results/montlake/car vs bike contention.bin": { "data/system/us/seattle/prebaked_results/montlake/car vs bike contention.bin": {
"checksum": "ce3dcac62c670a2260cd9258fd1d29b7", "checksum": "ce3dcac62c670a2260cd9258fd1d29b7",
"uncompressed_size_bytes": 4288, "uncompressed_size_bytes": 4288,

View File

@ -428,13 +428,23 @@ impl DrivingSimState {
for lane in blocked_starts { for lane in blocked_starts {
// Calculate the exact positions along this blocked queue (which is ***NOT*** // Calculate the exact positions along this blocked queue (which is ***NOT***
// the same queue that the unparking car is in!). Use that to update the // the same queue that the unparking car is in!). Use that to update the
// follower. Note that it's fine that the current car isn't currently in // follower.
// self.cars; the static blockage doesn't need it. //
// It SHOULD be fine that the current car isn't currently in self.cars; the
// static blockage doesn't need it. But calculating positions on one queue may
// recurse to the queue where the current car is. So temporarily make the car
// visible in this query.
self.cars.insert(car.vehicle.id, car.clone());
let dists = self.queues[&Traversable::Lane(*lane)].get_car_positions( let dists = self.queues[&Traversable::Lane(*lane)].get_car_positions(
now, now,
&self.cars, &self.cars,
&self.queues, &self.queues,
); );
// Undo the above hack.
self.cars.remove(&car.vehicle.id);
let idx = dists.iter().position(|entry| matches!(entry.member, Queued::StaticBlockage { cause, ..} if cause == car.vehicle.id)).unwrap(); let idx = dists.iter().position(|entry| matches!(entry.member, Queued::StaticBlockage { cause, ..} if cause == car.vehicle.id)).unwrap();
self.update_follower(idx, &dists, now, ctx); self.update_follower(idx, &dists, now, ctx);

View File

@ -1,4 +1,11 @@
[ [
{
"map": "arboretum (in seattle (us))",
"scenario": "weekday",
"finished_trips": 76640,
"cancelled_trips": 0,
"total_trip_duration_seconds": 43692260.45700034
},
{ {
"map": "montlake (in seattle (us))", "map": "montlake (in seattle (us))",
"scenario": "weekday", "scenario": "weekday",