oops. border could have been represented in sidewalkspot. merge the madness.

This commit is contained in:
Dustin Carlino 2018-11-12 16:53:47 -08:00
parent 257d051585
commit 7f62537085
5 changed files with 79 additions and 121 deletions

View File

@ -1,8 +1,8 @@
use abstutil;
use control::ControlMap;
use map_model::{BuildingID, BusRoute, BusStopID, LaneID, LaneType, Map, RoadID};
use spawn::WalkingEndpoint;
use std::collections::{BTreeSet, VecDeque};
use walking::SidewalkSpot;
use {
BorderSpawnOverTime, CarID, Event, MapEdits, OriginDestination, PedestrianID, RouteID,
Scenario, SeedParkedCars, Sim, SpawnOverTime, Tick, WeightedUsizeChoice,
@ -364,7 +364,7 @@ impl Sim {
)
}
pub fn spawn_specific_pedestrian(&mut self, from: WalkingEndpoint, to: WalkingEndpoint) {
pub fn spawn_specific_pedestrian(&mut self, from: SidewalkSpot, to: SidewalkSpot) {
self.spawner
.start_trip_just_walking(self.time.next(), from, to, &mut self.trips_state);
}

View File

@ -2,7 +2,6 @@ use abstutil;
use geom::{GPSBounds, LonLat, Polygon, Pt2D};
use map_model::{BuildingID, IntersectionID, LaneType, Map, RoadID};
use rand::Rng;
use spawn::WalkingEndpoint;
use std::collections::{BTreeSet, HashMap, HashSet};
use std::fs::File;
use std::io::{Error, Write};
@ -262,21 +261,19 @@ impl Scenario {
);
} else {
let goal = match s.goal {
OriginDestination::Neighborhood(ref n) => {
WalkingEndpoint::Spot(SidewalkSpot::building(
*sim.rng.choose(&bldgs_per_neighborhood[n]).unwrap(),
map,
))
}
OriginDestination::Neighborhood(ref n) => SidewalkSpot::building(
*sim.rng.choose(&bldgs_per_neighborhood[n]).unwrap(),
map,
),
// TODO get only element, and dont do this computation every iter
OriginDestination::Border(i) => {
WalkingEndpoint::end_at_border(i, LaneType::Sidewalk, map)
SidewalkSpot::end_at_border(i, LaneType::Sidewalk, map)
}
};
sim.spawner.start_trip_just_walking(
spawn_time,
WalkingEndpoint::Spot(SidewalkSpot::building(from_bldg, map)),
SidewalkSpot::building(from_bldg, map),
goal,
&mut sim.trips_state,
);
@ -300,22 +297,20 @@ impl Scenario {
let spawn_time = Tick(sim.rng.gen_range(s.start_tick.0, s.stop_tick.0));
// TODO Refactor this bit
let goal = match s.goal {
OriginDestination::Neighborhood(ref n) => {
WalkingEndpoint::Spot(SidewalkSpot::building(
*sim.rng.choose(&bldgs_per_neighborhood[n]).unwrap(),
map,
))
}
OriginDestination::Neighborhood(ref n) => SidewalkSpot::building(
*sim.rng.choose(&bldgs_per_neighborhood[n]).unwrap(),
map,
),
// TODO dont do this computation every iter
OriginDestination::Border(i) => {
WalkingEndpoint::end_at_border(i, LaneType::Sidewalk, map)
SidewalkSpot::end_at_border(i, LaneType::Sidewalk, map)
}
};
sim.spawner.start_trip_just_walking(
spawn_time,
// TODO dont do this computation every iter
WalkingEndpoint::start_at_border(s.start_from_border, LaneType::Sidewalk, map),
SidewalkSpot::start_at_border(s.start_from_border, LaneType::Sidewalk, map),
goal,
&mut sim.trips_state,
);

View File

@ -1,11 +1,7 @@
use abstutil::elapsed_seconds;
use dimensioned::si;
use driving::{CreateCar, DrivingSimState};
use kinematics::Vehicle;
use map_model::{
BuildingID, BusRoute, BusStopID, IntersectionID, LaneID, LaneType, Map, Path, Pathfinder,
RoadID,
};
use map_model::{BuildingID, BusRoute, BusStopID, LaneID, LaneType, Map, Path, Pathfinder, RoadID};
use parking::ParkingSimState;
use rand::{Rng, XorShiftRng};
use router::Router;
@ -19,52 +15,9 @@ use {
PedestrianID, RouteID, Tick, TripID, WeightedUsizeChoice,
};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum WalkingEndpoint {
Spot(SidewalkSpot),
// The creator of this case can decide whehter it's a start/goal border and pick the distance
// accordingly
Border(IntersectionID, LaneID, Distance),
}
// TODO distance is f64
impl PartialEq for WalkingEndpoint {
fn eq(&self, other: &WalkingEndpoint) -> bool {
match (self, other) {
(WalkingEndpoint::Spot(s1), WalkingEndpoint::Spot(s2)) => s1 == s2,
(WalkingEndpoint::Border(i1, l1, d1), WalkingEndpoint::Border(i2, l2, d2)) => {
i1 == i2 && l1 == l2 && d1 == d2
}
_ => false,
}
}
}
impl Eq for WalkingEndpoint {}
impl WalkingEndpoint {
pub fn get_position(&self) -> (LaneID, Distance) {
match self {
WalkingEndpoint::Spot(s) => (s.sidewalk, s.dist_along),
WalkingEndpoint::Border(_, l, d) => (*l, *d),
}
}
pub fn start_at_border(i: IntersectionID, lt: LaneType, map: &Map) -> WalkingEndpoint {
// TODO multiple driving lanes to start?
let l = map.get_i(i).get_outgoing_lanes(map, lt)[0];
WalkingEndpoint::Border(i, l, 0.0 * si::M)
}
pub fn end_at_border(i: IntersectionID, lt: LaneType, map: &Map) -> WalkingEndpoint {
// TODO multiple driving lanes to end?
let l = map.get_i(i).get_incoming_lanes(map, lt)[0];
WalkingEndpoint::Border(i, l, map.get_l(l).length())
}
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
enum Command {
Walk(Tick, TripID, PedestrianID, WalkingEndpoint, WalkingEndpoint),
Walk(Tick, TripID, PedestrianID, SidewalkSpot, SidewalkSpot),
Drive(Tick, TripID, ParkedCar, BuildingID),
}
@ -82,11 +35,12 @@ impl Command {
parking_sim: &ParkingSimState,
) -> (LaneID, Distance, LaneID, Distance) {
match self {
Command::Walk(_, _, _, start, goal) => {
let (lane1, dist1) = start.get_position();
let (lane2, dist2) = goal.get_position();
(lane1, dist1, lane2, dist2)
}
Command::Walk(_, _, _, start, goal) => (
start.sidewalk,
start.dist_along,
goal.sidewalk,
goal.dist_along,
),
Command::Drive(_, _, parked_car, goal_bldg) => {
let goal_lane = find_driving_lane_near_building(*goal_bldg, map);
(
@ -404,24 +358,22 @@ impl Spawner {
at,
ped_id,
vec![
TripLeg::Walk(WalkingEndpoint::Spot(parking_spot.clone())),
TripLeg::Walk(parking_spot.clone()),
TripLeg::Drive(parked, goal_bldg),
TripLeg::Walk(WalkingEndpoint::Spot(SidewalkSpot::building(
goal_bldg, map,
))),
TripLeg::Walk(SidewalkSpot::building(goal_bldg, map)),
],
),
ped_id,
WalkingEndpoint::Spot(SidewalkSpot::building(start_bldg, map)),
WalkingEndpoint::Spot(parking_spot),
SidewalkSpot::building(start_bldg, map),
parking_spot,
));
}
pub fn start_trip_just_walking(
&mut self,
at: Tick,
start: WalkingEndpoint,
goal: WalkingEndpoint,
start: SidewalkSpot,
goal: SidewalkSpot,
trips: &mut TripManager,
) {
let ped_id = PedestrianID(self.ped_id_counter);
@ -456,16 +408,14 @@ impl Spawner {
at,
ped_id,
vec![
TripLeg::Walk(WalkingEndpoint::Spot(SidewalkSpot::bus_stop(stop1, map))),
TripLeg::Walk(SidewalkSpot::bus_stop(stop1, map)),
TripLeg::RideBus(route, stop2),
TripLeg::Walk(WalkingEndpoint::Spot(SidewalkSpot::building(
goal_bldg, map,
))),
TripLeg::Walk(SidewalkSpot::building(goal_bldg, map)),
],
),
ped_id,
WalkingEndpoint::Spot(SidewalkSpot::building(start_bldg, map)),
WalkingEndpoint::Spot(SidewalkSpot::bus_stop(stop1, map)),
SidewalkSpot::building(start_bldg, map),
SidewalkSpot::bus_stop(stop1, map),
));
ped_id
}
@ -484,7 +434,7 @@ impl Spawner {
at.next(),
trip,
ped,
WalkingEndpoint::Spot(SidewalkSpot::bus_stop(stop, map)),
SidewalkSpot::bus_stop(stop, map),
walk_to,
));
}
@ -502,7 +452,7 @@ impl Spawner {
at.next(),
trip,
ped,
WalkingEndpoint::Spot(SidewalkSpot::parking_spot(p.spot, map, parking_sim)),
SidewalkSpot::parking_spot(p.spot, map, parking_sim),
walk_to,
));
}

View File

@ -1,7 +1,7 @@
use abstutil::{deserialize_btreemap, serialize_btreemap};
use map_model::{BuildingID, BusStopID};
use spawn::WalkingEndpoint;
use std::collections::{BTreeMap, VecDeque};
use walking::SidewalkSpot;
use {AgentID, CarID, ParkedCar, PedestrianID, RouteID, Tick, TripID};
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
@ -30,10 +30,7 @@ impl TripManager {
}
// Where are we walking next?
pub fn car_reached_parking_spot(
&mut self,
car: CarID,
) -> (TripID, PedestrianID, WalkingEndpoint) {
pub fn car_reached_parking_spot(&mut self, car: CarID) -> (TripID, PedestrianID, SidewalkSpot) {
let trip = &mut self.trips[self.active_trip_mode.remove(&AgentID::Car(car)).unwrap().0];
match trip.legs.pop_front().unwrap() {
@ -122,7 +119,7 @@ impl TripManager {
}
// Where to walk next?
pub fn ped_finished_bus_ride(&mut self, ped: PedestrianID) -> (TripID, WalkingEndpoint) {
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
@ -250,7 +247,7 @@ struct Trip {
// parking.
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
pub enum TripLeg {
Walk(WalkingEndpoint),
Walk(SidewalkSpot),
// Roads might be long -- what building do we ultimately want to park near?
Drive(ParkedCar, BuildingID),
RideBus(RouteID, BusStopID),

View File

@ -5,11 +5,11 @@ use geom::Pt2D;
use instrument::capture_backtrace;
use intersections::{IntersectionSimState, Request};
use map_model::{
BuildingID, BusStopID, Lane, LaneID, Map, Path, PathStep, Trace, Traversable, Turn, TurnID,
BuildingID, BusStopID, IntersectionID, Lane, LaneID, LaneType, Map, Path, PathStep, Trace,
Traversable, Turn, TurnID,
};
use multimap::MultiMap;
use parking::ParkingSimState;
use spawn::WalkingEndpoint;
use std;
use std::collections::{BTreeMap, HashSet};
use trips::TripManager;
@ -69,6 +69,26 @@ impl SidewalkSpot {
connection: SidewalkPOI::BusStop(stop),
}
}
pub fn start_at_border(i: IntersectionID, lt: LaneType, map: &Map) -> SidewalkSpot {
// TODO multiple driving lanes to start?
let l = map.get_i(i).get_outgoing_lanes(map, lt)[0];
SidewalkSpot {
sidewalk: l,
dist_along: 0.0 * si::M,
connection: SidewalkPOI::Border(i),
}
}
pub fn end_at_border(i: IntersectionID, lt: LaneType, map: &Map) -> SidewalkSpot {
// TODO multiple driving lanes to end?
let l = map.get_i(i).get_incoming_lanes(map, lt)[0];
SidewalkSpot {
sidewalk: l,
dist_along: map.get_l(l).length(),
connection: SidewalkPOI::Border(i),
}
}
}
// Point of interest, that is
@ -77,6 +97,7 @@ enum SidewalkPOI {
ParkingSpot(ParkingSpot),
Building(BuildingID),
BusStop(BusStopID),
Border(IntersectionID),
}
#[derive(Clone, Debug, Serialize, Deserialize)]
@ -112,7 +133,7 @@ struct Pedestrian {
path: Path,
front_path: Option<CrossingFrontPath>,
goal: WalkingEndpoint,
goal: SidewalkSpot,
// If false, don't react() and step(). Waiting for a bus.
active: bool,
@ -137,7 +158,7 @@ impl Pedestrian {
}
if self.path.is_last_step() {
let goal_dist = self.goal.get_position().1;
let goal_dist = self.goal.dist_along;
// Since the walking model doesn't really have granular speed, just see if we're
// reasonably close to the path.
// Later distance will be non-negative, so don't attempt abs() or anything
@ -147,13 +168,11 @@ impl Pedestrian {
goal_dist - self.dist_along
};
if dist_away <= 2.0 * SPEED * TIMESTEP {
return match self.goal {
WalkingEndpoint::Spot(ref spot) => match spot.connection {
SidewalkPOI::ParkingSpot(spot) => Action::StartParkedCar(spot),
SidewalkPOI::Building(id) => Action::StartCrossingPath(id),
SidewalkPOI::BusStop(stop) => Action::WaitAtBusStop(stop),
},
WalkingEndpoint::Border(_, _, _) => Action::VanishAtBorder,
return match self.goal.connection {
SidewalkPOI::ParkingSpot(spot) => Action::StartParkedCar(spot),
SidewalkPOI::Building(id) => Action::StartCrossingPath(id),
SidewalkPOI::BusStop(stop) => Action::WaitAtBusStop(stop),
SidewalkPOI::Border(_) => Action::VanishAtBorder,
};
}
return Action::Continue;
@ -474,29 +493,26 @@ impl WalkingSimState {
events: &mut Vec<Event>,
id: PedestrianID,
trip: TripID,
start: WalkingEndpoint,
goal: WalkingEndpoint,
start: SidewalkSpot,
goal: SidewalkSpot,
path: Path,
) {
let (start_lane, start_dist_along) = start.get_position();
let start_lane = start.sidewalk;
assert_eq!(
path.current_step().as_traversable(),
Traversable::Lane(start_lane)
);
assert_eq!(
path.last_step().as_traversable(),
Traversable::Lane(goal.get_position().0)
Traversable::Lane(goal.sidewalk)
);
let front_path = match start {
WalkingEndpoint::Spot(spot) => match spot.connection {
SidewalkPOI::Building(id) => Some(CrossingFrontPath {
bldg: id,
dist_along: 0.0 * si::M,
going_to_sidewalk: true,
}),
_ => None,
},
let front_path = match start.connection {
SidewalkPOI::Building(id) => Some(CrossingFrontPath {
bldg: id,
dist_along: 0.0 * si::M,
going_to_sidewalk: true,
}),
_ => None,
};
@ -507,7 +523,7 @@ impl WalkingSimState {
trip,
path,
on: Traversable::Lane(start_lane),
dist_along: start_dist_along,
dist_along: start.dist_along,
front_path,
goal,
moving: true,