Skip to content

Commit

Permalink
Figure out travel time for bikes. #393
Browse files Browse the repository at this point in the history
Something's wrong with the results, but it's a start.
  • Loading branch information
dabreegster committed Nov 21, 2020
1 parent 32a9915 commit 594b376
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
7 changes: 5 additions & 2 deletions game/src/devtools/fifteen_min/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ impl State<App> for Viewer {
self.hovering_on_bldg.as_ref().map(|h| ID::Building(h.id));
}

if ctx.normal_left_click() {
if let Some(ref hover) = self.hovering_on_bldg {
// Don't call normal_left_click unless we're hovering on something in map-space; otherwise
// panel.event never sees clicks.
if let Some(ref hover) = self.hovering_on_bldg {
if ctx.normal_left_click() {
let start = app.primary.map.get_b(hover.id);
self.isochrone = Isochrone::new(ctx, app, start.id, self.isochrone.constraints);
self.highlight_start = draw_star(ctx, start.polygon.center());
Expand Down Expand Up @@ -218,6 +220,7 @@ fn build_panel(ctx: &mut EventCtx, app: &App, start: &Building, isochrone: &Isoc
// Start of toolbar
rows.push(Widget::horiz_separator(ctx, 0.3).margin_above(10));

// TODO Why does this look backwards?
rows.push(Checkbox::toggle(
ctx,
"walking / biking",
Expand Down
36 changes: 34 additions & 2 deletions map_model/src/connectivity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use petgraph::graphmap::DiGraphMap;

use geom::Duration;

pub use crate::pathfind::{build_graph_for_pedestrians, driving_cost, WalkingNode};
pub use crate::pathfind::{
build_graph_for_pedestrians, build_graph_for_vehicles, driving_cost, WalkingNode,
};
use crate::{BuildingID, LaneID, Map, PathConstraints};

/// Calculate the srongy connected components (SCC) of the part of the map accessible by constraints
Expand Down Expand Up @@ -73,7 +75,37 @@ pub fn all_costs_from(
}
}
} else {
// TODO
// TODO We have a graph of LaneIDs, but mapping a building to one isn't straightforward. In
// the common case it'll be fine, but some buildings are isolated from the graph by some
// sidewalks.
let mut bldg_to_lane = HashMap::new();
for b in map.all_buildings() {
if constraints == PathConstraints::Car {
if let Some((pos, _)) = b.driving_connection(map) {
bldg_to_lane.insert(b.id, pos.lane());
}
} else if constraints == PathConstraints::Bike {
if let Some((pos, _)) = b.biking_connection(map) {
bldg_to_lane.insert(b.id, pos.lane());
}
}
}

if let Some(start_lane) = bldg_to_lane.get(&start) {
let graph = build_graph_for_vehicles(map, constraints);
let cost_per_lane =
petgraph::algo::dijkstra(&graph, *start_lane, None, |(_, _, turn)| {
driving_cost(map.get_l(turn.src), map.get_t(*turn), constraints, map)
});
for (b, lane) in bldg_to_lane {
if let Some(seconds) = cost_per_lane.get(&lane) {
let duration = Duration::seconds(*seconds as f64);
if duration <= time_limit {
results.insert(b, duration);
}
}
}
}
}

results
Expand Down
1 change: 1 addition & 0 deletions map_model/src/pathfind/driving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ fn make_input_graph(
input_graph
}

/// Roughly equivalent to seconds
pub fn driving_cost(lane: &Lane, turn: &Turn, constraints: PathConstraints, map: &Map) -> f64 {
// TODO Could cost turns differently.

Expand Down
2 changes: 1 addition & 1 deletion map_model/src/pathfind/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use abstutil::Timer;
use geom::{Distance, PolyLine, EPSILON_DIST};

pub use self::ch::ContractionHierarchyPathfinder;
pub use self::dijkstra::build_graph_for_pedestrians;
pub use self::dijkstra::{build_graph_for_pedestrians, build_graph_for_vehicles};
pub use self::driving::driving_cost;
pub use self::walking::{walking_cost, WalkingNode};
use crate::{
Expand Down

0 comments on commit 594b376

Please sign in to comment.