diff --git a/sim/src/events.rs b/sim/src/events.rs index 5b70db496d..4d8b1f8651 100644 --- a/sim/src/events.rs +++ b/sim/src/events.rs @@ -1,5 +1,5 @@ use crate::{AgentID, CarID, ParkingSpot, PedestrianID}; -use map_model::{BuildingID, BusStopID, IntersectionID, Traversable}; +use map_model::{BuildingID, BusStopID, IntersectionID, LaneID, Traversable}; use serde_derive::{Deserialize, Serialize}; #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -17,6 +17,8 @@ pub enum Event { PedEntersBus(PedestrianID, CarID), PedLeavesBus(PedestrianID, CarID), + BikeStoppedAtSidewalk(CarID, LaneID), + // TODO Remove this one AgentEntersTraversable(AgentID, Traversable), } diff --git a/sim/src/make/scenario.rs b/sim/src/make/scenario.rs index 80b0f0e91b..cf3bda093d 100644 --- a/sim/src/make/scenario.rs +++ b/sim/src/make/scenario.rs @@ -184,6 +184,16 @@ impl Scenario { max_speed: None, } } + + pub fn rand_bike(rng: &mut XorShiftRng) -> VehicleSpec { + let length = rand_dist(rng, MIN_BIKE_LENGTH, MAX_BIKE_LENGTH); + let max_speed = Some(Speed::miles_per_hour(10.0)); + VehicleSpec { + vehicle_type: VehicleType::Bike, + length, + max_speed, + } + } } impl SpawnOverTime { @@ -259,7 +269,7 @@ impl SpawnOverTime { spawn_time, TripSpec::UsingBike( SidewalkSpot::building(from_bldg, map), - rand_bike(rng), + Scenario::rand_bike(rng), goal, ), map, @@ -435,7 +445,7 @@ impl BorderSpawnOverTime { rng, timer, ) { - let bike = rand_bike(rng); + let bike = Scenario::rand_bike(rng); sim.schedule_trip( spawn_time, TripSpec::CarAppearing( @@ -626,13 +636,3 @@ fn rand_dist(rng: &mut XorShiftRng, low: Distance, high: Distance) -> Distance { fn rand_time(rng: &mut XorShiftRng, low: Duration, high: Duration) -> Duration { Duration::seconds(rng.gen_range(low.inner_seconds(), high.inner_seconds())) } - -fn rand_bike(rng: &mut XorShiftRng) -> VehicleSpec { - let length = rand_dist(rng, MIN_BIKE_LENGTH, MAX_BIKE_LENGTH); - let max_speed = Some(Speed::miles_per_hour(10.0)); - VehicleSpec { - vehicle_type: VehicleType::Bike, - length, - max_speed, - } -} diff --git a/sim/src/trips.rs b/sim/src/trips.rs index c17fc48703..89ce5ea71f 100644 --- a/sim/src/trips.rs +++ b/sim/src/trips.rs @@ -201,6 +201,10 @@ impl TripManager { map: &Map, scheduler: &mut Scheduler, ) { + self.events.push(Event::BikeStoppedAtSidewalk( + bike, + bike_rack.sidewalk_pos.lane(), + )); let trip = &mut self.trips[self.active_trip_mode.remove(&AgentID::Car(bike)).unwrap().0]; match trip.legs.pop_front() { diff --git a/tests/src/main.rs b/tests/src/main.rs index 666545b639..850ba2fb52 100644 --- a/tests/src/main.rs +++ b/tests/src/main.rs @@ -5,6 +5,7 @@ mod runner; mod sim_completion; mod sim_determinism; mod transit; +mod trips; use structopt::StructOpt; @@ -17,6 +18,7 @@ fn main() { sim_completion::run(t.suite("sim_completion")); sim_determinism::run(t.suite("sim_determinism")); transit::run(t.suite("transit")); + trips::run(t.suite("trips")); t.done(); } diff --git a/tests/src/trips.rs b/tests/src/trips.rs new file mode 100644 index 0000000000..8006b2ce35 --- /dev/null +++ b/tests/src/trips.rs @@ -0,0 +1,38 @@ +use crate::runner::TestRunner; +use abstutil::Timer; +use geom::Duration; +use map_model::{BuildingID, IntersectionID}; +use sim::{DrivingGoal, Event, Scenario, SidewalkSpot, SimFlags, TripSpec}; + +pub fn run(t: &mut TestRunner) { + t.run_slow("bike_from_border", |h| { + let (map, mut sim, mut rng) = SimFlags::for_test("bike_from_border") + .load(Some(Duration::seconds(30.0)), &mut Timer::throwaway()); + // TODO Hardcoding IDs is fragile + let goal_bldg = BuildingID(319); + let (ped, bike) = sim.schedule_trip( + Duration::ZERO, + TripSpec::UsingBike( + SidewalkSpot::start_at_border(IntersectionID(186), &map).unwrap(), + Scenario::rand_bike(&mut rng), + DrivingGoal::ParkNear(goal_bldg), + ), + &map, + ); + sim.spawn_all_trips(&map, &mut Timer::throwaway()); + h.setup_done(&sim); + + sim.run_until_expectations_met( + &map, + vec![ + Event::BikeStoppedAtSidewalk( + bike.unwrap(), + map.get_b(goal_bldg).front_path.sidewalk.lane(), + ), + Event::PedReachedBuilding(ped.unwrap(), goal_bldg), + ], + Duration::minutes(3), + ); + sim.run_until_done(&map, |_| {}, Some(Duration::minutes(4))); + }); +}