When pathfinding with custom routing params (from the debug UI), only rebuild the one graph we need. #746

This commit is contained in:
Dustin Carlino 2021-09-02 11:03:53 -07:00
parent 8c2c0e2e65
commit add42b6f19
2 changed files with 29 additions and 8 deletions

View File

@ -825,10 +825,11 @@ impl Map {
self.name.map = format!("minified_{}", self.name.map);
// Don't need CHs or even the graph for anything except bikes.
self.pathfinder = Pathfinder::just_bikes(
self.pathfinder = Pathfinder::new_for_one_mode(
self,
self.routing_params().clone(),
crate::pathfind::CreateEngine::Dijkstra,
PathConstraints::Bike,
timer,
);
}

View File

@ -97,16 +97,34 @@ impl Pathfinder {
}
}
pub fn just_bikes(
/// Create a new Pathfinder with custom routing params that can only serve one mode.
pub fn new_for_one_mode(
map: &Map,
params: RoutingParams,
engine: CreateEngine,
constraints: PathConstraints,
timer: &mut Timer,
) -> Pathfinder {
let mut p = Pathfinder::empty();
timer.start("prepare pathfinding for bikes");
p.bike_graph = VehiclePathfinder::new(map, PathConstraints::Bike, &params, &engine);
timer.stop("prepare pathfinding for bikes");
timer.start("prepare pathfinding for just one mode");
match constraints {
PathConstraints::Pedestrian => {
p.walking_graph = SidewalkPathfinder::new(map, None, &engine);
}
PathConstraints::Car => {
p.car_graph = VehiclePathfinder::new(map, constraints, &params, &engine);
}
PathConstraints::Bike => {
p.bike_graph = VehiclePathfinder::new(map, constraints, &params, &engine);
}
PathConstraints::Bus => {
p.bus_graph = VehiclePathfinder::new(map, constraints, &params, &engine);
}
PathConstraints::Train => {
p.train_graph = VehiclePathfinder::new(map, constraints, &params, &engine);
}
}
timer.stop("prepare pathfinding for just one mode");
p.params = params;
p
}
@ -128,12 +146,14 @@ impl Pathfinder {
// If the params differ from the ones baked into the map, the CHs won't match. This
// should only be happening from the debug UI; be very obnoxious if we start calling it
// from the simulation or something else.
warn!("Pathfinding slowly for {} with custom params", req);
let tmp_pathfinder = Pathfinder::new(
let mut timer =
Timer::new(format!("Pathfinding slowly for {} with custom params", req));
let tmp_pathfinder = Pathfinder::new_for_one_mode(
map,
params.clone(),
CreateEngine::Dijkstra,
&mut Timer::throwaway(),
req.constraints,
&mut timer,
);
return tmp_pathfinder.pathfind_with_params(req, params, map);
}