improve error message for cars too close, and add error dumping to headless

This commit is contained in:
Dustin Carlino 2018-11-23 09:44:08 -08:00
parent b55d609c37
commit 9368c42c6e
3 changed files with 44 additions and 4 deletions

View File

@ -243,9 +243,21 @@ impl Car {
.unwrap(),
);
if self.debug {
let describe_accel = if safe_accel == vehicle.max_accel {
format!("max_accel ({})", safe_accel)
} else if safe_accel == vehicle.max_deaccel {
format!("max_deaccel ({})", safe_accel)
} else {
format!("{}", safe_accel)
};
let describe_speed = if Some(self.speed) == vehicle.max_speed {
format!("max_speed ({})", self.speed)
} else {
format!("{}", self.speed)
};
debug!(
"At {}, {} chose {}, with current speed {}",
time, self.id, safe_accel, self.speed
time, self.id, describe_accel, describe_speed
);
}
@ -381,7 +393,23 @@ impl SimQueue {
let ((dist1, c1), (dist2, c2)) = (slice[0], slice[1]);
let following_dist = cars[&c1].vehicle.following_dist();
if dist1 - dist2 < following_dist {
return Err(Error::new(format!("uh oh! on {:?}, reset to {:?} broke. min following distance is {}, but we have {} at {} and {} at {}. dist btwn is just {}. prev queue was {:?}", self.id, self.cars_queue, following_dist, c1, dist1, c2, dist2, dist1 - dist2, old_queue)));
let mut err = format!(
"On {:?}, {} and {} are {} apart -- that's {} too close\n",
self.id,
c1,
c2,
dist1 - dist2,
following_dist - (dist1 - dist2),
);
err.push_str(&format!("Old queue ({}):\n", old_queue.len()));
for (dist, id) in old_queue {
err.push_str(&format!("- {} at {}\n", id, dist));
}
err.push_str(&format!("New queue ({}):\n", self.cars_queue.len()));
for (dist, id) in &self.cars_queue {
err.push_str(&format!("- {} at {}\n", id, dist));
}
return Err(Error::new(err));
}
}
Ok(())

View File

@ -2,6 +2,7 @@ use abstutil::WeightedUsizeChoice;
use control::ControlMap;
use map_model::{BuildingID, BusRoute, Map, RoadID};
use std::collections::{BTreeSet, VecDeque};
use std::panic;
use {
BorderSpawnOverTime, CarID, Event, OriginDestination, Scenario, SeedParkedCars, Sim,
SpawnOverTime, Tick,
@ -14,7 +15,18 @@ impl Sim {
pub fn run_until_done(&mut self, map: &Map, control_map: &ControlMap, callback: Box<Fn(&Sim)>) {
let mut benchmark = self.start_benchmark();
loop {
self.step(&map, &control_map);
match panic::catch_unwind(panic::AssertUnwindSafe(|| {
self.step(&map, &control_map);
})) {
Ok(()) => {}
Err(err) => {
error!("********************************************************************************");
error!("Sim broke:");
self.dump_before_abort();
panic::resume_unwind(err);
}
}
if self.time.is_multiple_of(Tick::from_minutes(1)) {
let speed = self.measure_speed(&mut benchmark);
info!("{0}, speed = {1:.2}x", self.summary(), speed);

View File

@ -182,7 +182,7 @@ impl Vehicle {
if self.debug {
debug!(
"accel_to_stop_in_dist({}, {}) would normally recommend {} and take {} to finish",
" accel_to_stop_in_dist({}, {}) would normally recommend {} and take {} to finish",
speed, dist, normal_case, required_time
);
}