mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
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).
This commit is contained in:
parent
5c6eacf781
commit
bf9d34d1a3
@ -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(
|
||||
|
@ -47,8 +47,12 @@ pub fn find_scc(map: &Map, constraints: PathConstraints) -> (HashSet<LaneID>, 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<BuildingID, Duration> {
|
||||
/// 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<BuildingID, Duration> {
|
||||
// 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<BuildingID, Durat
|
||||
let mut results = HashMap::new();
|
||||
for b in map.all_buildings() {
|
||||
if let Some(seconds) = cost_per_node.get(&WalkingNode::closest(b.sidewalk_pos, map)) {
|
||||
results.insert(b.id, Duration::seconds(*seconds as f64));
|
||||
let duration = Duration::seconds(*seconds as f64);
|
||||
if duration <= time_limit {
|
||||
results.insert(b.id, duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
results
|
||||
|
Loading…
Reference in New Issue
Block a user