make tests build again. cleanup sim::load

This commit is contained in:
Dustin Carlino 2019-02-27 12:41:12 -08:00
parent dcce91b97a
commit 50451b6120
14 changed files with 224 additions and 250 deletions

View File

@ -454,11 +454,9 @@ impl PerMapUI {
) -> (PerMapUI, PluginsPerMap) { ) -> (PerMapUI, PluginsPerMap) {
let mut timer = abstutil::Timer::new("setup PerMapUI"); let mut timer = abstutil::Timer::new("setup PerMapUI");
let mut mem = MeasureMemory::new(); let mut mem = MeasureMemory::new();
let (map, sim) = sim::load( let (map, sim, _) = flags
flags.sim_flags.clone(), .sim_flags
Some(Duration::seconds(30.0)), .load(Some(Duration::seconds(30.0)), &mut timer);
&mut timer,
);
mem.reset("Map and Sim", &mut timer); mem.reset("Map and Sim", &mut timer);
timer.start("draw_map"); timer.start("draw_map");

View File

@ -20,8 +20,9 @@ fn main() {
// TODO not the ideal way to distinguish what thing we loaded // TODO not the ideal way to distinguish what thing we loaded
let load = flags.sim_flags.load.clone(); let load = flags.sim_flags.load.clone();
let mut timer = Timer::new("setup headless"); let mut timer = Timer::new("setup headless");
let mut rng = flags.sim_flags.make_rng(); let (map, mut sim, mut rng) = flags
let (map, mut sim) = sim::load(flags.sim_flags, Some(Duration::seconds(30.0)), &mut timer); .sim_flags
.load(Some(Duration::seconds(30.0)), &mut timer);
if load.contains("data/raw_maps/") || load.contains("data/maps/") { if load.contains("data/raw_maps/") || load.contains("data/maps/") {
Scenario::small_run(&map).instantiate(&mut sim, &map, &mut rng, &mut timer); Scenario::small_run(&map).instantiate(&mut sim, &map, &mut rng, &mut timer);

View File

@ -10,7 +10,7 @@ mod trips;
pub use self::events::Event; pub use self::events::Event;
pub use self::make::{ pub use self::make::{
load, ABTest, ABTestResults, BorderSpawnOverTime, OriginDestination, Scenario, SeedParkedCars, ABTest, ABTestResults, BorderSpawnOverTime, OriginDestination, Scenario, SeedParkedCars,
SimFlags, SpawnOverTime, TripSpawner, TripSpec, SimFlags, SpawnOverTime, TripSpawner, TripSpec,
}; };
pub(crate) use self::mechanics::{ pub(crate) use self::mechanics::{

View File

@ -48,22 +48,21 @@ impl SimFlags {
XorShiftRng::from_entropy() XorShiftRng::from_entropy()
} }
} }
}
// Convenience method to setup everything. // Convenience method to setup everything.
pub fn load( pub fn load(
flags: SimFlags, &self,
savestate_every: Option<Duration>, savestate_every: Option<Duration>,
timer: &mut abstutil::Timer, timer: &mut abstutil::Timer,
) -> (Map, Sim) { ) -> (Map, Sim, XorShiftRng) {
let mut rng = flags.make_rng(); let mut rng = self.make_rng();
if flags.load.contains("data/save/") { if self.load.contains("data/save/") {
assert_eq!(flags.edits_name, "no_edits"); assert_eq!(self.edits_name, "no_edits");
timer.note(format!("Resuming from {}", flags.load)); timer.note(format!("Resuming from {}", self.load));
timer.start("read sim savestate"); timer.start("read sim savestate");
let sim: Sim = abstutil::read_json(&flags.load).expect("loading sim state failed"); let sim: Sim = abstutil::read_json(&self.load).expect("loading sim state failed");
timer.stop("read sim savestate"); timer.stop("read sim savestate");
let edits: MapEdits = if sim.edits_name == "no_edits" { let edits: MapEdits = if sim.edits_name == "no_edits" {
@ -87,14 +86,15 @@ pub fn load(
.expect(&format!("Couldn't load map from {}", map_path)) .expect(&format!("Couldn't load map from {}", map_path))
}); });
(map, sim) (map, sim, rng)
} else if flags.load.contains("data/scenarios/") { } else if self.load.contains("data/scenarios/") {
timer.note(format!( timer.note(format!(
"Seeding the simulation from scenario {}", "Seeding the simulation from scenario {}",
flags.load self.load
)); ));
let scenario: Scenario = abstutil::read_json(&flags.load).expect("loading scenario failed"); let scenario: Scenario =
let edits = load_edits(&scenario.map_name, &flags); abstutil::read_json(&self.load).expect("loading scenario failed");
let edits = self.load_edits(&scenario.map_name);
// Try loading the pre-baked map first // Try loading the pre-baked map first
let map: Map = abstutil::read_binary( let map: Map = abstutil::read_binary(
@ -112,55 +112,56 @@ pub fn load(
let mut sim = Sim::new( let mut sim = Sim::new(
&map, &map,
// TODO or the scenario name if no run name // TODO or the scenario name if no run name
flags.run_name, self.run_name.clone(),
savestate_every, savestate_every,
); );
scenario.instantiate(&mut sim, &map, &mut rng, timer); scenario.instantiate(&mut sim, &map, &mut rng, timer);
(map, sim) (map, sim, rng)
} else if flags.load.contains("data/raw_maps/") { } else if self.load.contains("data/raw_maps/") {
// TODO relative dir is brittle; match more cautiously // TODO relative dir is brittle; match more cautiously
let map_name = flags let map_name = self
.load .load
.trim_left_matches("../data/raw_maps/") .trim_left_matches("../data/raw_maps/")
.trim_right_matches(".abst") .trim_right_matches(".abst")
.to_string(); .to_string();
timer.note(format!("Loading map {}", flags.load)); timer.note(format!("Loading map {}", self.load));
let edits = load_edits(&map_name, &flags); let edits = self.load_edits(&map_name);
let map = Map::new(&flags.load, edits, timer) let map = Map::new(&self.load, edits, timer)
.expect(&format!("Couldn't load map from {}", flags.load)); .expect(&format!("Couldn't load map from {}", self.load));
timer.start("create sim"); timer.start("create sim");
let sim = Sim::new(&map, flags.run_name, savestate_every); let sim = Sim::new(&map, self.run_name.clone(), savestate_every);
timer.stop("create sim"); timer.stop("create sim");
(map, sim) (map, sim, rng)
} else if flags.load.contains("data/maps/") { } else if self.load.contains("data/maps/") {
assert_eq!(flags.edits_name, "no_edits"); assert_eq!(self.edits_name, "no_edits");
timer.note(format!("Loading map {}", flags.load)); timer.note(format!("Loading map {}", self.load));
let map: Map = abstutil::read_binary(&flags.load, timer) let map: Map = abstutil::read_binary(&self.load, timer)
.expect(&format!("Couldn't load map from {}", flags.load)); .expect(&format!("Couldn't load map from {}", self.load));
timer.start("create sim"); timer.start("create sim");
let sim = Sim::new(&map, flags.run_name, savestate_every); let sim = Sim::new(&map, self.run_name.clone(), savestate_every);
timer.stop("create sim"); timer.stop("create sim");
(map, sim) (map, sim, rng)
} else { } else {
panic!("Don't know how to load {}", flags.load); panic!("Don't know how to load {}", self.load);
}
} }
}
fn load_edits(map_name: &str, flags: &SimFlags) -> MapEdits { fn load_edits(&self, map_name: &str) -> MapEdits {
if flags.edits_name == "no_edits" { if self.edits_name == "no_edits" {
return MapEdits::new(map_name); return MapEdits::new(map_name);
} }
if flags.edits_name.contains("data/") || flags.edits_name.contains(".json") { if self.edits_name.contains("data/") || self.edits_name.contains(".json") {
panic!( panic!(
"{} should just be a plain name, not a full path", "{} should just be a plain name, not a full path",
flags.edits_name self.edits_name
); );
} }
let edits: MapEdits = abstutil::read_json(&format!( let edits: MapEdits = abstutil::read_json(&format!(
"../data/edits/{}/{}.json", "../data/edits/{}/{}.json",
map_name, flags.edits_name map_name, self.edits_name
)) ))
.unwrap(); .unwrap();
edits edits
}
} }

View File

@ -4,7 +4,7 @@ mod scenario;
mod spawn; mod spawn;
pub use self::a_b_test::{ABTest, ABTestResults}; pub use self::a_b_test::{ABTest, ABTestResults};
pub use self::load::{load, SimFlags}; pub use self::load::SimFlags;
pub use self::scenario::{ pub use self::scenario::{
BorderSpawnOverTime, OriginDestination, Scenario, SeedParkedCars, SpawnOverTime, BorderSpawnOverTime, OriginDestination, Scenario, SeedParkedCars, SpawnOverTime,
}; };

View File

@ -71,6 +71,10 @@ impl Scenario {
pub fn instantiate(&self, sim: &mut Sim, map: &Map, rng: &mut XorShiftRng, timer: &mut Timer) { pub fn instantiate(&self, sim: &mut Sim, map: &Map, rng: &mut XorShiftRng, timer: &mut Timer) {
timer.start(&format!("Instantiating {}", self.scenario_name)); timer.start(&format!("Instantiating {}", self.scenario_name));
for route in map.get_all_bus_routes() {
sim.seed_bus_route(route, map, timer);
}
timer.start("load full neighborhood info"); timer.start("load full neighborhood info");
let neighborhoods = FullNeighborhoodInfo::load_all(map); let neighborhoods = FullNeighborhoodInfo::load_all(map);
timer.stop("load full neighborhood info"); timer.stop("load full neighborhood info");

View File

@ -9,7 +9,7 @@ use derivative::Derivative;
use ezgui::GfxCtx; use ezgui::GfxCtx;
use geom::{Distance, Duration, Pt2D}; use geom::{Distance, Duration, Pt2D};
use map_model::{ use map_model::{
BuildingID, IntersectionID, LaneID, LaneType, Map, Path, Trace, Traversable, Turn, BuildingID, BusRoute, IntersectionID, LaneID, LaneType, Map, Path, Trace, Traversable, Turn,
}; };
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use std::collections::{HashSet, VecDeque}; use std::collections::{HashSet, VecDeque};
@ -103,6 +103,11 @@ impl Sim {
pub fn get_parked_cars_by_owner(&self, bldg: BuildingID) -> Vec<&ParkedCar> { pub fn get_parked_cars_by_owner(&self, bldg: BuildingID) -> Vec<&ParkedCar> {
self.parking.get_parked_cars_by_owner(bldg) self.parking.get_parked_cars_by_owner(bldg)
} }
pub fn seed_bus_route(&mut self, route: &BusRoute, map: &Map, timer: &mut Timer) -> Vec<CarID> {
// TODO implement
Vec::new()
}
} }
// Drawing // Drawing

View File

@ -11,6 +11,7 @@ gag = "0.1.10"
geom = { path = "../geom" } geom = { path = "../geom" }
map_model = { path = "../map_model" } map_model = { path = "../map_model" }
rand = "0.6.5" rand = "0.6.5"
rand_xorshift = "0.1.1"
sim = { path = "../sim" } sim = { path = "../sim" }
structopt = "0.2" structopt = "0.2"
termion = "1.5.1" termion = "1.5.1"

View File

@ -1,6 +1,5 @@
use crate::runner::TestRunner; use crate::runner::TestRunner;
use geom::{Duration, Line, PolyLine, Pt2D}; use geom::{Duration, Line, PolyLine, Pt2D};
//use rand;
#[allow(clippy::unreadable_literal)] #[allow(clippy::unreadable_literal)]
pub fn run(t: &mut TestRunner) { pub fn run(t: &mut TestRunner) {
@ -15,53 +14,6 @@ pub fn run(t: &mut TestRunner) {
assert!(l.dist_along_of_point(pt).is_some()); assert!(l.dist_along_of_point(pt).is_some());
}); });
/*t.run_fast("shift_polyline_equivalence", |_| {
let scale = 1000.0;
let pt1 = Pt2D::new(rand::random::<f64>() * scale, rand::random::<f64>() * scale);
let pt2 = Pt2D::new(rand::random::<f64>() * scale, rand::random::<f64>() * scale);
let pt3 = Pt2D::new(rand::random::<f64>() * scale, rand::random::<f64>() * scale);
let pt4 = Pt2D::new(rand::random::<f64>() * scale, rand::random::<f64>() * scale);
let pt5 = Pt2D::new(rand::random::<f64>() * scale, rand::random::<f64>() * scale);
let width = 50.0;
let pt1_s = Line::new(pt1, pt2).shift_right(width).pt1();
let pt2_s = Line::new(pt1, pt2)
.shift_right(width)
.infinite()
.intersection(&Line::new(pt2, pt3).shift_right(width).infinite())
.unwrap();
let pt3_s = Line::new(pt2, pt3)
.shift_right(width)
.infinite()
.intersection(&Line::new(pt3, pt4).shift_right(width).infinite())
.unwrap();
let pt4_s = Line::new(pt3, pt4)
.shift_right(width)
.infinite()
.intersection(&Line::new(pt4, pt5).shift_right(width).infinite())
.unwrap();
let pt5_s = Line::new(pt4, pt5).shift_right(width).pt2();
assert_eq!(
PolyLine::new(vec![pt1, pt2, pt3, pt4, pt5]).shift_right(width),
PolyLine::new(vec![pt1_s, pt2_s, pt3_s, pt4_s, pt5_s])
);
});*/
/*t.run_fast("shift_short_polyline_equivalence", |_| {
let scale = 1000.0;
let pt1 = Pt2D::new(rand::random::<f64>() * scale, rand::random::<f64>() * scale);
let pt2 = Pt2D::new(rand::random::<f64>() * scale, rand::random::<f64>() * scale);
let width = 50.0;
let l = Line::new(pt1, pt2).shift_right(width);
assert_eq!(
PolyLine::new(vec![pt1, pt2]).shift_right(width),
l.to_polyline()
);
});*/
t.run_fast("trim_with_epsilon", |_| { t.run_fast("trim_with_epsilon", |_| {
/* /*
// EPSILON_DIST needs to be tuned correctly, or this point seems like it's not on the line. // EPSILON_DIST needs to be tuned correctly, or this point seems like it's not on the line.

View File

@ -1,35 +1,40 @@
use crate::runner::TestRunner; use crate::runner::TestRunner;
use abstutil::Timer; use abstutil::Timer;
use geom::Duration; use geom::Duration;
use sim; use sim::{DrivingGoal, Event, ParkingSpot, SidewalkSpot, SimFlags, TripSpec};
pub fn run(t: &mut TestRunner) { pub fn run(t: &mut TestRunner) {
// TODO Lots of boilerplate between these two. Can we do better? // TODO Lots of boilerplate between these two. Can we do better?
t.run_slow("park_on_goal_st", |h| { t.run_slow("park_on_goal_st", |h| {
let (map, mut sim) = sim::load( let (map, mut sim, mut rng) = SimFlags::synthetic_test("parking_test", "park_on_goal_st")
sim::SimFlags::synthetic_test("parking_test", "park_on_goal_st"), .load(None, &mut Timer::throwaway());
None,
&mut Timer::throwaway(),
);
let north_bldg = map.bldg("north").id; let north_bldg = map.bldg("north").id;
let south_bldg = map.bldg("south").id; let south_bldg = map.bldg("south").id;
let north_parking = map.parking_lane("north", 23).id; let north_parking = map.parking_lane("north", 23).id;
let south_parking = map.parking_lane("south", 23).id; let south_parking = map.parking_lane("south", 23).id;
let car = sim.seed_specific_parked_cars(south_parking, south_bldg, vec![2])[0]; let (spot, car) =
h.seed_parked_cars(&mut sim, &mut rng, south_parking, Some(south_bldg), vec![2])[0];
// Fill up some of the first spots, forcing parking to happen at spot 4 // Fill up some of the first spots, forcing parking to happen at spot 4
sim.seed_specific_parked_cars(north_parking, north_bldg, (0..4).collect()); h.seed_parked_cars(&mut sim, &mut rng, north_parking, None, (0..4).collect());
sim.seed_specific_parked_cars(north_parking, north_bldg, (5..10).collect()); h.seed_parked_cars(&mut sim, &mut rng, north_parking, None, (5..10).collect());
// TODO I just want to say (south_bldg, north_bldg), not mode... sim.schedule_trip(
sim.seed_trip_using_parked_car(south_bldg, north_bldg, car, &map); Duration::ZERO,
TripSpec::UsingParkedCar(
SidewalkSpot::building(south_bldg, &map),
spot,
DrivingGoal::ParkNear(north_bldg),
),
&map,
);
h.setup_done(&sim); h.setup_done(&sim);
sim.run_until_expectations_met( sim.run_until_expectations_met(
&map, &map,
vec![sim::Event::CarReachedParkingSpot( vec![Event::CarReachedParkingSpot(
car, car,
sim::ParkingSpot::new(north_parking, 4), ParkingSpot::new(north_parking, 4),
)], )],
Duration::minutes(2), Duration::minutes(2),
); );
@ -37,29 +42,35 @@ pub fn run(t: &mut TestRunner) {
}); });
t.run_slow("wander_around_for_parking", |h| { t.run_slow("wander_around_for_parking", |h| {
let (map, mut sim) = sim::load( let (map, mut sim, mut rng) =
sim::SimFlags::synthetic_test("parking_test", "wander_around_for_parking"), SimFlags::synthetic_test("parking_test", "wander_around_for_parking")
None, .load(None, &mut Timer::throwaway());
&mut Timer::throwaway(),
);
let north_bldg = map.bldg("north").id; let north_bldg = map.bldg("north").id;
let south_bldg = map.bldg("south").id; let south_bldg = map.bldg("south").id;
let north_parking = map.parking_lane("north", 23).id; let north_parking = map.parking_lane("north", 23).id;
let south_parking = map.parking_lane("south", 23).id; let south_parking = map.parking_lane("south", 23).id;
let car = sim.seed_specific_parked_cars(south_parking, south_bldg, vec![2])[0]; let (spot, car) =
h.seed_parked_cars(&mut sim, &mut rng, south_parking, Some(south_bldg), vec![2])[0];
// Fill up all of the north spots, forcing parking to happen on the south lane behind // Fill up all of the north spots, forcing parking to happen on the south lane behind
// the original spot // the original spot
sim.seed_specific_parked_cars(north_parking, north_bldg, (0..23).collect()); h.seed_parked_cars(&mut sim, &mut rng, north_parking, None, (0..23).collect());
// TODO I just want to say (south_bldg, north_bldg), not mode... sim.schedule_trip(
sim.seed_trip_using_parked_car(south_bldg, north_bldg, car, &map); Duration::ZERO,
TripSpec::UsingParkedCar(
SidewalkSpot::building(south_bldg, &map),
spot,
DrivingGoal::ParkNear(north_bldg),
),
&map,
);
h.setup_done(&sim); h.setup_done(&sim);
sim.run_until_expectations_met( sim.run_until_expectations_met(
&map, &map,
vec![sim::Event::CarReachedParkingSpot( vec![Event::CarReachedParkingSpot(
car, car,
sim::ParkingSpot::new(south_parking, 0), ParkingSpot::new(south_parking, 0),
)], )],
Duration::minutes(2), Duration::minutes(2),
); );

View File

@ -3,7 +3,9 @@
use abstutil; use abstutil;
use abstutil::Error; use abstutil::Error;
use gag::Redirect; use gag::Redirect;
use sim::Sim; use map_model::{BuildingID, LaneID};
use rand_xorshift::XorShiftRng;
use sim::{CarID, ParkingSpot, Sim};
use std; use std;
use std::io::Write; use std::io::Write;
use structopt::StructOpt; use structopt::StructOpt;
@ -265,6 +267,17 @@ impl TestHelper {
} }
self.debug_with_savestate = Some(sim.save()); self.debug_with_savestate = Some(sim.save());
} }
pub fn seed_parked_cars(
&self,
sim: &mut Sim,
rng: &mut XorShiftRng,
lane: LaneID,
owner: Option<BuildingID>,
spots: Vec<usize>,
) -> Vec<(ParkingSpot, CarID)> {
Vec::new()
}
} }
#[derive(PartialEq)] #[derive(PartialEq)]

View File

@ -1,20 +1,14 @@
use crate::runner::TestRunner; use crate::runner::TestRunner;
use abstutil::Timer; use abstutil::Timer;
use geom::Duration; use geom::Duration;
use sim; use sim::{Scenario, SimFlags};
pub fn run(t: &mut TestRunner) { pub fn run(t: &mut TestRunner) {
t.run_slow("small_spawn_completes", |h| { t.run_slow("small_spawn_completes", |h| {
let (map, mut sim) = sim::load( let (map, mut sim, mut rng) = SimFlags::for_test("aorta_model_completes")
sim::SimFlags::for_test("aorta_model_completes"), .load(Some(Duration::seconds(30.0)), &mut Timer::throwaway());
Some(Duration::seconds(30.0)), Scenario::small_run(&map).instantiate(&mut sim, &map, &mut rng, &mut Timer::throwaway());
&mut Timer::throwaway(),
);
sim.small_spawn(&map);
h.setup_done(&sim); h.setup_done(&sim);
sim.run_until_done(&map, |_| {}, Some(Duration::minutes(60))); sim.run_until_done(&map, |_| {}, Some(Duration::minutes(60)));
}); });
} }
// TODO other tests (not completion) to add:
// - different behavior (stopping or not) at stop signs

View File

@ -1,15 +1,12 @@
use crate::runner::TestRunner; use crate::runner::TestRunner;
use abstutil::Timer; use abstutil::Timer;
use sim; use sim::{Scenario, Sim, SimFlags};
pub fn run(t: &mut TestRunner) { pub fn run(t: &mut TestRunner) {
t.run_slow("serialization", |_| { t.run_slow("serialization", |_| {
let (map, mut sim) = sim::load( let (map, mut sim, mut rng) =
sim::SimFlags::for_test("serialization"), SimFlags::for_test("serialization").load(None, &mut Timer::throwaway());
None, Scenario::small_run(&map).instantiate(&mut sim, &map, &mut rng, &mut Timer::throwaway());
&mut Timer::throwaway(),
);
sim.small_spawn(&map);
// Does savestating produce the same string? // Does savestating produce the same string?
let save1 = abstutil::to_json(&sim); let save1 = abstutil::to_json(&sim);
@ -19,14 +16,11 @@ pub fn run(t: &mut TestRunner) {
t.run_slow("from_scratch", |_| { t.run_slow("from_scratch", |_| {
println!("Creating two simulations"); println!("Creating two simulations");
let (map, mut sim1) = sim::load( let (map, mut sim1, mut rng) =
sim::SimFlags::for_test("from_scratch_1"), SimFlags::for_test("from_scratch_1").load(None, &mut Timer::throwaway());
None, let mut sim2 = Sim::new(&map, "from_scratch_2".to_string(), None);
&mut Timer::throwaway(), Scenario::small_run(&map).instantiate(&mut sim1, &map, &mut rng, &mut Timer::throwaway());
); Scenario::small_run(&map).instantiate(&mut sim2, &map, &mut rng, &mut Timer::throwaway());
let mut sim2 = sim::Sim::new(&map, "from_scratch_2".to_string(), Some(42), None);
sim1.small_spawn(&map);
sim2.small_spawn(&map);
for _ in 1..600 { for _ in 1..600 {
if sim1 != sim2 { if sim1 != sim2 {
@ -44,14 +38,11 @@ pub fn run(t: &mut TestRunner) {
t.run_slow("with_savestating", |_| { t.run_slow("with_savestating", |_| {
println!("Creating two simulations"); println!("Creating two simulations");
let (map, mut sim1) = sim::load( let (map, mut sim1, mut rng) =
sim::SimFlags::for_test("with_savestating_1"), SimFlags::for_test("with_savestating_1").load(None, &mut Timer::throwaway());
None, let mut sim2 = Sim::new(&map, "with_savestating_2".to_string(), None);
&mut Timer::throwaway(), Scenario::small_run(&map).instantiate(&mut sim1, &map, &mut rng, &mut Timer::throwaway());
); Scenario::small_run(&map).instantiate(&mut sim2, &map, &mut rng, &mut Timer::throwaway());
let mut sim2 = sim::Sim::new(&map, "with_savestating_2".to_string(), Some(42), None);
sim1.small_spawn(&map);
sim2.small_spawn(&map);
for _ in 1..600 { for _ in 1..600 {
sim1.step(&map); sim1.step(&map);
@ -80,9 +71,8 @@ pub fn run(t: &mut TestRunner) {
); );
} }
let sim3: sim::Sim = let sim3: Sim =
sim::Sim::load_savestate(sim1_save.clone(), Some("with_savestating_3".to_string())) Sim::load_savestate(sim1_save.clone(), Some("with_savestating_3".to_string())).unwrap();
.unwrap();
if sim3 != sim2 { if sim3 != sim2 {
panic!( panic!(
"sim state differs between {} and {}", "sim state differs between {} and {}",

View File

@ -1,16 +1,12 @@
use crate::runner::TestRunner; use crate::runner::TestRunner;
use abstutil::Timer; use abstutil::Timer;
use geom::Duration; use geom::Duration;
use sim; use sim::{Event, SidewalkSpot, SimFlags, TripSpec};
use sim::{Event, SimFlags};
pub fn run(t: &mut TestRunner) { pub fn run(t: &mut TestRunner) {
t.run_slow("bus_reaches_stops", |h| { t.run_slow("bus_reaches_stops", |h| {
let (map, mut sim) = sim::load( let (map, mut sim, _) = SimFlags::for_test("bus_reaches_stops")
SimFlags::for_test("bus_reaches_stops"), .load(Some(Duration::seconds(30.0)), &mut Timer::throwaway());
Some(Duration::seconds(30.0)),
&mut Timer::throwaway(),
);
let route = map.get_bus_route("49").unwrap(); let route = map.get_bus_route("49").unwrap();
let buses = sim.seed_bus_route(route, &map, &mut Timer::throwaway()); let buses = sim.seed_bus_route(route, &map, &mut Timer::throwaway());
let bus = buses[0]; let bus = buses[0];
@ -28,11 +24,8 @@ pub fn run(t: &mut TestRunner) {
}); });
t.run_slow("ped_uses_bus", |h| { t.run_slow("ped_uses_bus", |h| {
let (map, mut sim) = sim::load( let (map, mut sim, _) = SimFlags::for_test("ped_uses_bus")
SimFlags::for_test("ped_uses_bus"), .load(Some(Duration::seconds(30.0)), &mut Timer::throwaway());
Some(Duration::seconds(30.0)),
&mut Timer::throwaway(),
);
let route = map.get_bus_route("49").unwrap(); let route = map.get_bus_route("49").unwrap();
let buses = sim.seed_bus_route(route, &map, &mut Timer::throwaway()); let buses = sim.seed_bus_route(route, &map, &mut Timer::throwaway());
let bus = buses[0]; let bus = buses[0];
@ -49,22 +42,33 @@ pub fn run(t: &mut TestRunner) {
let goal_bldg = map let goal_bldg = map
.get_l(map.get_bs(ped_stop2).sidewalk_pos.lane()) .get_l(map.get_bs(ped_stop2).sidewalk_pos.lane())
.building_paths[0]; .building_paths[0];
let ped = sim.schedule_trip(
sim.seed_trip_using_bus(start_bldg, goal_bldg, route.id, ped_stop1, ped_stop2, &map); Duration::ZERO,
TripSpec::UsingTransit(
SidewalkSpot::building(start_bldg, &map),
route.id,
ped_stop1,
ped_stop2,
SidewalkSpot::building(goal_bldg, &map),
),
&map,
);
// TODO ew
let ped = sim::PedestrianID::tmp_new(0);
h.setup_done(&sim); h.setup_done(&sim);
sim.run_until_expectations_met( sim.run_until_expectations_met(
&map, &map,
vec![ vec![
sim::Event::PedReachedBusStop(ped, ped_stop1), Event::PedReachedBusStop(ped, ped_stop1),
sim::Event::BusArrivedAtStop(bus, ped_stop1), Event::BusArrivedAtStop(bus, ped_stop1),
sim::Event::PedEntersBus(ped, bus), Event::PedEntersBus(ped, bus),
sim::Event::BusDepartedFromStop(bus, ped_stop1), Event::BusDepartedFromStop(bus, ped_stop1),
sim::Event::BusArrivedAtStop(bus, ped_stop2), Event::BusArrivedAtStop(bus, ped_stop2),
sim::Event::PedLeavesBus(ped, bus), Event::PedLeavesBus(ped, bus),
sim::Event::PedReachedBuilding(ped, goal_bldg), Event::PedReachedBuilding(ped, goal_bldg),
sim::Event::BusDepartedFromStop(bus, ped_stop2), Event::BusDepartedFromStop(bus, ped_stop2),
sim::Event::BusArrivedAtStop(bus, route.stops[3]), Event::BusArrivedAtStop(bus, route.stops[3]),
], ],
Duration::minutes(8), Duration::minutes(8),
); );