From bf9d34d1a30c05b9119815bf10f55f316873e848 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sat, 21 Nov 2020 10:12:29 -0800 Subject: [PATCH] Drop results farther than 15 minutes away. #393 It'd be more efficient to terminate the Dijkstra's search directly, but petgraph doesn't have an option for that, so we'll have to implement Dijkstra's manually (shouldn't be hard). --- game/src/devtools/fifteen_min/isochrone.rs | 4 +++- map_model/src/connectivity.rs | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/game/src/devtools/fifteen_min/isochrone.rs b/game/src/devtools/fifteen_min/isochrone.rs index a4a8e8e935..b6bf6afdf3 100644 --- a/game/src/devtools/fifteen_min/isochrone.rs +++ b/game/src/devtools/fifteen_min/isochrone.rs @@ -28,7 +28,9 @@ impl Isochrone { ); // Calculate the cost from the start building to every other building in the map - for (b, cost) in connectivity::all_costs_from(&app.primary.map, start) { + for (b, cost) in + connectivity::all_costs_from(&app.primary.map, start, Duration::minutes(15)) + { // What grid cell does the building belong to? let pt = app.primary.map.get_b(b).polygon.center(); let idx = grid.idx( diff --git a/map_model/src/connectivity.rs b/map_model/src/connectivity.rs index 3a27851848..00d526c145 100644 --- a/map_model/src/connectivity.rs +++ b/map_model/src/connectivity.rs @@ -47,8 +47,12 @@ pub fn find_scc(map: &Map, constraints: PathConstraints) -> (HashSet, Ha } /// Starting from one building, calculate the cost to all others. If a destination isn't reachable, -/// it won't be included in the results. -pub fn all_costs_from(map: &Map, start: BuildingID) -> HashMap { +/// it won't be included in the results. Ignore results greater than the time_limit away. +pub fn all_costs_from( + map: &Map, + start: BuildingID, + time_limit: Duration, +) -> HashMap { // TODO This is hardcoded to walking; take a PathConstraints. let graph = build_graph_for_pedestrians(map); let start = WalkingNode::closest(map.get_b(start).sidewalk_pos, map); @@ -60,7 +64,10 @@ pub fn all_costs_from(map: &Map, start: BuildingID) -> HashMap