making a sample ped using the bus

This commit is contained in:
Dustin Carlino 2018-09-04 11:33:41 -07:00
parent a74bfe6c92
commit 55b02e6c5c
5 changed files with 86 additions and 4 deletions

View File

@ -697,6 +697,7 @@ step 2: move interactive and testish spawning stuff to init() or similar, leavin
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
- test a basic bus scenario
- make BusStop a lightweight, copyable address
## Everything as FSMs

View File

@ -131,6 +131,13 @@ impl Map {
dist_along: 25.0 * si::M,
});
}
if id == LaneID(325) {
bus_stops.push(BusStop {
sidewalk: id,
driving_lane: LaneID(323),
dist_along: 30.0 * si::M,
});
}
if id == LaneID(840) {
bus_stops.push(BusStop {
sidewalk: id,

View File

@ -3,7 +3,7 @@ use control::ControlMap;
use map_model::{BuildingID, BusStop, Edits, LaneID, Map};
use rand::Rng;
use std::collections::VecDeque;
use {CarID, Event, Sim, Tick};
use {CarID, Event, RouteID, Sim, Tick};
// Convenience method to setup everything.
pub fn load(
@ -97,13 +97,22 @@ impl Sim {
if self.seed_bus_route(
vec![
map.get_l(LaneID(309)).bus_stops[0].clone(),
map.get_l(LaneID(325)).bus_stops[0].clone(),
map.get_l(LaneID(840)).bus_stops[0].clone(),
],
map,
).len() != 2
).len() != 3
{
panic!("Two buses didn't fit");
panic!("Three buses didn't fit");
}
self.make_ped_using_bus(
map,
LaneID(550),
LaneID(727),
RouteID(0),
map.get_l(LaneID(325)).bus_stops[0].clone(),
map.get_l(LaneID(840)).bus_stops[0].clone(),
);
}
pub fn big_spawn(&mut self, map: &Map) {
@ -219,6 +228,30 @@ impl Sim {
);
}
pub fn make_ped_using_bus(
&mut self,
map: &Map,
from: LaneID,
to: LaneID,
route: RouteID,
stop1: BusStop,
stop2: BusStop,
) {
let start_bldg = pick_bldg_from_sidewalk(&mut self.rng, map, from);
let goal_bldg = pick_bldg_from_sidewalk(&mut self.rng, map, to);
self.spawner.start_trip_using_bus(
self.time.next(),
map,
start_bldg,
goal_bldg,
stop1,
stop2,
route,
&mut self.trips_state,
);
}
pub fn spawn_pedestrian(&mut self, map: &Map, sidewalk: LaneID) {
assert!(map.get_l(sidewalk).is_sidewalk());
let start_bldg = pick_bldg_from_sidewalk(&mut self.rng, map, sidewalk);

View File

@ -10,7 +10,7 @@ use std::time::Instant;
use transit::TransitSimState;
use trips::{TripLeg, TripManager};
use walking::{SidewalkSpot, WalkingSimState};
use {AgentID, CarID, Event, ParkedCar, ParkingSpot, PedestrianID, Tick, TripID};
use {AgentID, CarID, Event, ParkedCar, ParkingSpot, PedestrianID, RouteID, Tick, TripID};
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
enum Command {
@ -335,6 +335,43 @@ impl Spawner {
));
}
pub fn start_trip_using_bus(
&mut self,
at: Tick,
map: &Map,
start_bldg: BuildingID,
goal_bldg: BuildingID,
stop1: BusStop,
stop2: BusStop,
route: RouteID,
trips: &mut TripManager,
) {
if let Some(cmd) = self.commands.back() {
assert!(at >= cmd.at());
}
let ped_id = PedestrianID(self.ped_id_counter);
self.ped_id_counter += 1;
self.commands.push_back(Command::Walk(
at,
trips.new_trip(
map,
ped_id,
start_bldg,
goal_bldg,
vec![
TripLeg::Walk(SidewalkSpot::bus_stop(stop1.clone())),
TripLeg::RideBus(route, stop2),
TripLeg::Walk(SidewalkSpot::building(goal_bldg, map)),
],
),
ped_id,
SidewalkSpot::building(start_bldg, map),
SidewalkSpot::bus_stop(stop1),
));
}
// Trip transitions
pub fn ped_finished_bus_ride(
&mut self,

View File

@ -551,6 +551,10 @@ impl WalkingSimState {
.get_vec_mut(stop)
.unwrap()
.retain(|&p| p != id);
self.peds_per_sidewalk
.get_vec_mut(&stop.sidewalk)
.unwrap()
.retain(|&p| p != id);
}
}