restore an old debug tool to spot what agents are blocking an intersection. optional mode to avoid some gridlock... seemingly working for a few cases, but breaking other stuff, so disabled.

This commit is contained in:
Dustin Carlino 2020-02-18 08:40:05 -08:00
parent 696f78751b
commit 0f0924ac56
5 changed files with 71 additions and 8 deletions

View File

@ -176,6 +176,10 @@ fn launch_test(test: &ABTest, ui: &mut UI, ctx: &mut EventCtx) -> ABTestMode {
.sim_flags
.opts
.recalc_lanechanging,
clear_laggy_head_early: current_flags
.sim_flags
.opts
.clear_laggy_head_early,
},
},
..current_flags.clone()

View File

@ -13,6 +13,7 @@ use ezgui::{
Text, Wizard,
};
use geom::Duration;
use map_model::IntersectionID;
use sim::Sim;
use std::collections::HashSet;
@ -25,6 +26,8 @@ pub struct DebugMode {
layers: ShowLayers,
search_results: Option<SearchResults>,
all_routes: routes::AllRoutesViewer,
highlighted_agents: Option<(IntersectionID, Drawable)>,
}
impl DebugMode {
@ -56,6 +59,7 @@ impl DebugMode {
layers: ShowLayers::new(),
search_results: None,
all_routes: routes::AllRoutesViewer::Inactive,
highlighted_agents: None,
}
}
}
@ -186,6 +190,35 @@ impl State for DebugMode {
));
}
}
if let Some(ID::Intersection(id)) = ui.primary.current_selection {
if self
.highlighted_agents
.as_ref()
.map(|(i, _)| id != *i)
.unwrap_or(true)
{
let mut batch = GeomBatch::new();
for a in ui.primary.sim.get_accepted_agents(id) {
batch.push(
ui.cs.get("something associated with something else"),
ui.primary
.draw_map
.get_obj(
ID::from_agent(a),
ui,
&mut ui.primary.draw_map.agents.borrow_mut(),
ctx.prerender,
)
.unwrap()
.get_outline(&ui.primary.map),
);
}
self.highlighted_agents = Some((id, ctx.upload(batch)));
}
} else {
self.highlighted_agents = None;
}
self.objects.event(ctx, ui);
if let Some(debugger) = polygons::PolygonDebugger::new(ctx, ui) {
@ -277,6 +310,9 @@ impl State for DebugMode {
if let Some(ref results) = self.search_results {
g.redraw(&results.draw);
}
if let Some((_, ref draw)) = self.highlighted_agents {
g.redraw(draw);
}
self.objects.draw(g, ui);
self.all_routes.draw(g, ui);

View File

@ -29,6 +29,7 @@ impl SimFlags {
use_freeform_policy_everywhere: args.enabled("--freeform_policy"),
disable_block_the_box: args.enabled("--disable_block_the_box"),
recalc_lanechanging: !args.enabled("--dont_recalc_lc"),
clear_laggy_head_early: args.enabled("--clear_laggy_head_early"),
},
}
}

View File

@ -35,15 +35,21 @@ pub struct DrivingSimState {
events: Vec<Event>,
recalc_lanechanging: bool,
clear_laggy_head_early: bool,
}
impl DrivingSimState {
pub fn new(map: &Map, recalc_lanechanging: bool) -> DrivingSimState {
pub fn new(
map: &Map,
recalc_lanechanging: bool,
clear_laggy_head_early: bool,
) -> DrivingSimState {
let mut sim = DrivingSimState {
cars: BTreeMap::new(),
queues: BTreeMap::new(),
events: Vec::new(),
recalc_lanechanging,
clear_laggy_head_early,
};
for l in map.all_lanes() {
@ -378,7 +384,15 @@ impl DrivingSimState {
));
car.last_steps.push_front(last_step);
if goto.length(map) >= car.vehicle.length + FOLLOWING_DISTANCE {
// Bit unrealistic, but don't unblock shorter intermediate steps until we're all
// the way into a lane later.
// Don't mark turn_finished until our back is out of the turn.
// TODO Don't even bother updating laggy head (which will unblock intermediate
// steps and call turn_finished and such) if we're bound for a tiny lane. Unless
// we're trying the experimental clear_laggy_head_early strategy.
if goto.length(map) >= car.vehicle.length + FOLLOWING_DISTANCE
|| self.clear_laggy_head_early
{
// Optimistically assume we'll be out of the way ASAP.
// This is update, not push, because we might've scheduled a blind retry too
// late, and the car actually crosses an entire new traversable in the
@ -396,10 +410,6 @@ impl DrivingSimState {
Command::UpdateLaggyHead(car.vehicle.id),
);
}
// Bit unrealistic, but don't unblock shorter intermediate steps until we're all
// the way into a lane later.
// Don't mark turn_finished until our back is out of the turn.
self.queues
.get_mut(&goto)
@ -651,7 +661,13 @@ impl DrivingSimState {
{
let our_dist = dists.last().unwrap().1;
let car = &self.cars[&id];
if our_dist < our_len {
// TODO Not working yet -- causes something to spawn too close to short stuff.
let avoid_gridlock = self.clear_laggy_head_early
&& our_dist == on.length(map)
&& on.maybe_lane().is_some();
if our_dist < our_len && !avoid_gridlock {
let retry_at = car
.crossing_state_with_end_dist(
DistanceInterval::new_driving(our_dist, our_len),

View File

@ -64,6 +64,7 @@ pub struct SimOptions {
pub use_freeform_policy_everywhere: bool,
pub disable_block_the_box: bool,
pub recalc_lanechanging: bool,
pub clear_laggy_head_early: bool,
}
impl SimOptions {
@ -74,6 +75,7 @@ impl SimOptions {
use_freeform_policy_everywhere: false,
disable_block_the_box: false,
recalc_lanechanging: true,
clear_laggy_head_early: false,
}
}
}
@ -86,7 +88,11 @@ impl Sim {
scheduler.push(Time::START_OF_DAY + d, Command::Savestate(d));
}
Sim {
driving: DrivingSimState::new(map, opts.recalc_lanechanging),
driving: DrivingSimState::new(
map,
opts.recalc_lanechanging,
opts.clear_laggy_head_early,
),
parking: ParkingSimState::new(map, timer),
walking: WalkingSimState::new(),
intersections: IntersectionSimState::new(