diff --git a/data/MANIFEST.txt b/data/MANIFEST.txt index 8f0ac6e142..0c4b749446 100644 --- a/data/MANIFEST.txt +++ b/data/MANIFEST.txt @@ -221,9 +221,9 @@ dcf786ec9ad3284e6f70179e19795720 data/system/scenarios/downtown/weekday.bin 370928cacb5d28ce7adb845982dd58b3 data/system/scenarios/huge_seattle/weekday.bin 7292bd648e628e38b381e27dec613893 data/system/scenarios/caphill/weekday.bin c92d3580f01b37aad20dfede7270039d data/system/scenarios/montlake/weekday.bin -38dfab26d52367c16ab429ec710546c3 data/system/prebaked_results/23rd/weekday.bin +1a7506556b01f99e7cc9336727111459 data/system/prebaked_results/23rd/weekday.bin ad5d2c7a2c73ef5bf4a09ff11845c166 data/system/prebaked_results/signal_single/tutorial lvl1.bin 81081122aa46e8651d8f07bb606bc77a data/system/prebaked_results/signal_single/tutorial lvl2.bin e15dd2d01fccadb1f16c4ed9f732b377 data/system/prebaked_results/montlake/car vs bike contention.bin -b375f2ef55cefc0bad90fe630adb0061 data/system/prebaked_results/montlake/weekday.bin +2e7e97dc4a513c087e1e73ed9df65b56 data/system/prebaked_results/montlake/weekday.bin ba713f7f6ad0c0201f1447d77957ce75 data/system/prebaked_results/montlake/car vs bus contention.bin diff --git a/sim/src/mechanics/parking.rs b/sim/src/mechanics/parking.rs index 1bde8ebce4..1506346181 100644 --- a/sim/src/mechanics/parking.rs +++ b/sim/src/mechanics/parking.rs @@ -134,15 +134,25 @@ impl ParkingSimState { self.parked_cars.insert(p.vehicle.id, p); } - pub fn dynamically_reserve_car(&mut self, b: BuildingID) -> Option { + pub fn dynamically_reserve_car( + &mut self, + b: BuildingID, + closest_to: Pt2D, + map: &Map, + ) -> Option { + let mut candidates = Vec::new(); for c in self.owned_cars_per_building.get(b) { - if self.dynamically_reserved_cars.contains(c) { - continue; + if !self.dynamically_reserved_cars.contains(c) { + let pt = match self.parked_cars[c].spot { + ParkingSpot::Onstreet(l, _) => map.get_l(l).lane_center_pts.middle(), + ParkingSpot::Offstreet(b, _) => map.get_b(b).label_center, + }; + candidates.push((*c, pt.dist_to(closest_to))); } - self.dynamically_reserved_cars.insert(*c); - return Some(self.parked_cars[c].clone()); } - None + let (c, _) = candidates.into_iter().min_by_key(|(_, dist)| *dist)?; + self.dynamically_reserved_cars.insert(c); + Some(self.parked_cars[&c].clone()) } pub fn dynamically_return_car(&mut self, p: ParkedCar) { diff --git a/sim/src/sim.rs b/sim/src/sim.rs index 6bc7e18924..2f43ad8784 100644 --- a/sim/src/sim.rs +++ b/sim/src/sim.rs @@ -461,7 +461,11 @@ impl Sim { let ok = if let SidewalkPOI::DeferredParkingSpot(b, driving_goal) = create_ped.goal.connection.clone() { - if let Some(parked_car) = self.parking.dynamically_reserve_car(b) { + if let Some(parked_car) = self.parking.dynamically_reserve_car( + b, + create_ped.start.sidewalk_pos.pt(map), + map, + ) { create_ped.goal = SidewalkSpot::parking_spot(parked_car.spot, map, &self.parking); create_ped.req = PathRequest {