make interactively spawned peds use transit if possible, to figure out

why the walking-with-transit graph is not working... argh which is
because map initialization order has so many funky dependencies
This commit is contained in:
Dustin Carlino 2019-06-17 14:38:13 -07:00
parent 4951eea644
commit b4de820f56
3 changed files with 52 additions and 19 deletions

View File

@ -200,15 +200,36 @@ impl AgentSpawner {
let sim = &mut ui.primary.sim;
match (self.from.clone(), self.maybe_goal.take().unwrap().0) {
(Source::Walking(from), Goal::Building(to)) => {
sim.schedule_trip(
sim.time(),
TripSpec::JustWalking {
start: SidewalkSpot::building(from, map),
goal: SidewalkSpot::building(to, map),
ped_speed: Scenario::rand_ped_speed(&mut rng),
},
map,
);
let start = SidewalkSpot::building(from, map);
let goal = SidewalkSpot::building(to, map);
let ped_speed = Scenario::rand_ped_speed(&mut rng);
if let Some((stop1, stop2, route)) =
map.should_use_transit(start.sidewalk_pos, goal.sidewalk_pos)
{
sim.schedule_trip(
sim.time(),
TripSpec::UsingTransit {
start,
goal,
route,
stop1,
stop2,
ped_speed,
},
map,
);
} else {
sim.schedule_trip(
sim.time(),
TripSpec::JustWalking {
start,
goal,
ped_speed,
},
map,
);
}
}
(Source::Walking(from), Goal::Border(to)) => {
if let Some(goal) = SidewalkSpot::end_at_border(to, map) {

View File

@ -109,9 +109,12 @@ impl Map {
m.traffic_signals = traffic_signals;
}
timer.start("setup Pathfinder");
m.pathfinder = Some(Pathfinder::new(&m, timer));
timer.stop("setup Pathfinder");
// Here's a fun one: we can't set up walking_using_transit yet, because we haven't
// finalized bus stops and routes. We need the bus graph in place for that. So setup
// pathfinding in two stages.
timer.start("setup (most of) Pathfinder");
m.pathfinder = Some(Pathfinder::new_without_transit(&m, timer));
timer.stop("setup (most of) Pathfinder");
{
let (stops, routes) =
@ -125,6 +128,12 @@ impl Map {
m.bus_routes = make::verify_bus_routes(&m, routes, timer);
}
timer.start("setup rest of Pathfinder");
let mut pathfinder = m.pathfinder.take().unwrap();
pathfinder.setup_walking_with_transit(&m);
m.pathfinder = Some(pathfinder);
timer.stop("setup rest of Pathfinder");
timer.stop("finalize Map");
m
}

View File

@ -321,11 +321,12 @@ pub struct Pathfinder {
bike_graph: VehiclePathfinder,
bus_graph: VehiclePathfinder,
walking_graph: SidewalkPathfinder,
walking_with_transit_graph: SidewalkPathfinder,
// TODO Option just during initialization! Ewww.
walking_with_transit_graph: Option<SidewalkPathfinder>,
}
impl Pathfinder {
pub fn new(map: &Map, timer: &mut Timer) -> Pathfinder {
pub fn new_without_transit(map: &Map, timer: &mut Timer) -> Pathfinder {
timer.start("prepare pathfinding for cars");
let car_graph = VehiclePathfinder::new(map, vec![LaneType::Driving]);
timer.stop("prepare pathfinding for cars");
@ -342,19 +343,19 @@ impl Pathfinder {
let walking_graph = SidewalkPathfinder::new(map, false);
timer.stop("prepare pathfinding for pedestrians");
timer.start("prepare pathfinding for pedestrians using transit");
let walking_with_transit_graph = SidewalkPathfinder::new(map, true);
timer.stop("prepare pathfinding for pedestrians using transit");
Pathfinder {
car_graph,
bike_graph,
bus_graph,
walking_graph,
walking_with_transit_graph,
walking_with_transit_graph: None,
}
}
pub fn setup_walking_with_transit(&mut self, map: &Map) {
self.walking_with_transit_graph = Some(SidewalkPathfinder::new(map, true));
}
pub fn pathfind(&self, req: PathRequest, map: &Map) -> Option<Path> {
// Weird case, but it can happen for walking from a building path to a bus stop that're
// actually at the same spot.
@ -392,6 +393,8 @@ impl Pathfinder {
end: Position,
) -> Option<(BusStopID, BusStopID, BusRouteID)> {
self.walking_with_transit_graph
.as_ref()
.unwrap()
.should_use_transit(map, start, end)
}