prune unrouteable bus routes in map model layer

This commit is contained in:
Dustin Carlino 2018-10-06 11:58:48 -07:00
parent 7b3069a1a1
commit da550910c7
3 changed files with 35 additions and 3 deletions

View File

@ -5,7 +5,8 @@ use make::sidewalk_finder::find_sidewalk_points;
use multimap::MultiMap;
use ordered_float::NotNaN;
use std::collections::{BTreeMap, HashMap, HashSet};
use {BusRoute, BusStop, BusStopID, Lane, LaneID, Road};
use std::iter;
use {BusRoute, BusStop, BusStopID, Lane, LaneID, Map, Pathfinder, Road};
pub fn make_bus_stops(
lanes: &mut Vec<Lane>,
@ -78,3 +79,30 @@ pub fn make_bus_stops(
}
(bus_stops, routes)
}
pub fn verify_bus_routes(map: &Map, routes: Vec<BusRoute>) -> Vec<BusRoute> {
routes
.into_iter()
.filter(|r| {
let mut ok = true;
for (stop1, stop2) in r
.stops
.iter()
.zip(r.stops.iter().skip(1))
.chain(iter::once((r.stops.last().unwrap(), &r.stops[0])))
{
let bs1 = map.get_bs(*stop1);
let bs2 = map.get_bs(*stop2);
if Pathfinder::shortest_distance(map, bs1.driving_lane, bs2.driving_lane).is_none()
{
debug!(
"Removing route {} since {:?} and {:?} aren't connected",
r.name, bs1, bs2
);
ok = false;
break;
}
}
ok
}).collect()
}

View File

@ -7,7 +7,7 @@ mod trim_lines;
mod turns;
pub(crate) use self::buildings::make_all_buildings;
pub(crate) use self::bus_stops::make_bus_stops;
pub(crate) use self::bus_stops::{make_bus_stops, verify_bus_routes};
pub(crate) use self::lanes::get_lane_specs;
pub(crate) use self::parcels::make_all_parcels;
pub(crate) use self::trim_lines::trim_lines;

View File

@ -166,7 +166,6 @@ impl Map {
let (stops, routes) =
make::make_bus_stops(&mut m.lanes, &m.roads, &data.bus_routes, &bounds);
m.bus_stops = stops;
m.bus_routes = routes;
for i in &m.intersections {
for t in make::make_all_turns(i, &m) {
@ -205,6 +204,11 @@ impl Map {
});
}
{
let _guard = flame::start_guard(format!("verify {} bus routes", routes.len()));
m.bus_routes = make::verify_bus_routes(&m, routes);
}
m
}