making peds leave the bus

This commit is contained in:
Dustin Carlino 2018-09-04 11:02:35 -07:00
parent 7e8407466e
commit a74bfe6c92
6 changed files with 67 additions and 8 deletions

View File

@ -696,7 +696,6 @@ step 2: move interactive and testish spawning stuff to init() or similar, leavin
- i just physically want the code in a separate file. can we implement a trait in a second file? - i just physically want the code in a separate file. can we implement a trait in a second file?
step 3: enhance the trip stuff to have a concept of hardcoded legs, and make it choose how to use a bus step 3: enhance the trip stuff to have a concept of hardcoded legs, and make it choose how to use a bus
- seed a trip using a bus - seed a trip using a bus
- wire up the transitions to board and deboard the bus
- test a basic bus scenario - test a basic bus scenario

View File

@ -4,3 +4,7 @@
- Seattle Times Traffic Lab - Seattle Times Traffic Lab
- https://www.citylab.com/transportation/2018/08/is-it-time-to-rethink-what-a-bike-lane-is/568483/ - https://www.citylab.com/transportation/2018/08/is-it-time-to-rethink-what-a-bike-lane-is/568483/
## Similar projects
- Urban Footprint (https://news.ycombinator.com/item?id=17895739)

View File

@ -178,8 +178,13 @@ impl Sim {
); );
} }
self.transit_state self.transit_state.step(
.step(&mut events, &mut self.walking_state, &mut self.trips_state); self.time,
&mut events,
&mut self.walking_state,
&mut self.trips_state,
&mut self.spawner,
);
// TODO want to pass self as a lazy QueryCar trait, but intersection_state is mutably // TODO want to pass self as a lazy QueryCar trait, but intersection_state is mutably
// borrowed :( // borrowed :(

View File

@ -336,6 +336,23 @@ impl Spawner {
} }
// Trip transitions // Trip transitions
pub fn ped_finished_bus_ride(
&mut self,
at: Tick,
ped: PedestrianID,
stop: BusStop,
trips: &mut TripManager,
) {
let (trip, walk_to) = trips.ped_finished_bus_ride(ped);
self.commands.push_back(Command::Walk(
at.next(),
trip,
ped,
SidewalkSpot::bus_stop(stop),
walk_to,
));
}
pub fn car_reached_parking_spot( pub fn car_reached_parking_spot(
&mut self, &mut self,
at: Tick, at: Tick,

View File

@ -4,6 +4,7 @@ use driving::CarView;
use events::Event; use events::Event;
use map_model; use map_model;
use map_model::{BusStop, LaneID, Map}; use map_model::{BusStop, LaneID, Map};
use spawn::Spawner;
use std::collections::{BTreeMap, VecDeque}; use std::collections::{BTreeMap, VecDeque};
use trips::TripManager; use trips::TripManager;
use walking::WalkingSimState; use walking::WalkingSimState;
@ -188,9 +189,11 @@ impl TransitSimState {
pub fn step( pub fn step(
&mut self, &mut self,
now: Tick,
events: &mut Vec<Event>, events: &mut Vec<Event>,
walking_sim: &mut WalkingSimState, walking_sim: &mut WalkingSimState,
trips: &mut TripManager, trips: &mut TripManager,
spawner: &mut Spawner,
) { ) {
for b in self.buses.values_mut() { for b in self.buses.values_mut() {
if let BusState::AtStop(stop_idx, _) = b.state { if let BusState::AtStop(stop_idx, _) = b.state {
@ -214,10 +217,11 @@ impl TransitSimState {
// which is called by router! thats convoluted // which is called by router! thats convoluted
let car = b.car; let car = b.car;
b.passengers.retain(|p| { b.passengers.retain(|p| {
println!("TODO should {} leave bus {}?", p, car); if trips.should_ped_leave_bus(*p, &stop) {
if false {
events.push(Event::PedLeavesBus(*p, car)); events.push(Event::PedLeavesBus(*p, car));
// TODO call something on the spawner to join the walking sim again // TODO would be a little cleaner to return this info up to sim and have it
// plumb through to spawner? not sure
spawner.ped_finished_bus_ride(now, *p, stop.clone(), trips);
false false
} else { } else {
true true

View File

@ -82,14 +82,44 @@ impl TripManager {
return false; return false;
} }
// They're boarding!
self.active_trip_mode.remove(&AgentID::Pedestrian(ped));
// Could assert that the first leg is walking to the right bus stop // Could assert that the first leg is walking to the right bus stop
trip.legs.pop_front(); trip.legs.pop_front();
// Leave active_trip_mode as Pedestrian, since the transit sim tracks passengers as
// PedestrianIDs.
true true
} }
pub fn should_ped_leave_bus(&self, ped: PedestrianID, stop: &BusStop) -> bool {
let trip = &self.trips[self.active_trip_mode[&AgentID::Pedestrian(ped)].0];
match trip.legs[0] {
TripLeg::RideBus(_, ref until_stop) => stop == until_stop,
ref x => panic!("{} is on a bus stop, but first leg is {:?}", ped, x),
}
}
// Where to walk next?
pub fn ped_finished_bus_ride(&mut self, ped: PedestrianID) -> (TripID, SidewalkSpot) {
// The spawner will call agent_starting_trip_leg, so briefly remove the active PedestrianID.
let trip = &mut self.trips[self.active_trip_mode
.remove(&AgentID::Pedestrian(ped))
.unwrap()
.0];
match trip.legs.pop_front().unwrap() {
TripLeg::RideBus(_, _) => {}
x => panic!("First trip leg {:?} doesn't match ped_finished_bus_ride", x),
};
// TODO there are only some valid sequences of trips. it'd be neat to guarantee these are
// valid by construction with a fluent API.
let walk_to = match trip.legs[0] {
TripLeg::Walk(ref to) => to,
ref x => panic!("Next trip leg is {:?}, not walking", x),
};
(trip.id, walk_to.clone())
}
// Creation from the interactive part of spawner // Creation from the interactive part of spawner
pub fn new_trip( pub fn new_trip(
&mut self, &mut self,