mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
make tests build again. cleanup sim::load
This commit is contained in:
parent
dcce91b97a
commit
50451b6120
@ -454,11 +454,9 @@ impl PerMapUI {
|
||||
) -> (PerMapUI, PluginsPerMap) {
|
||||
let mut timer = abstutil::Timer::new("setup PerMapUI");
|
||||
let mut mem = MeasureMemory::new();
|
||||
let (map, sim) = sim::load(
|
||||
flags.sim_flags.clone(),
|
||||
Some(Duration::seconds(30.0)),
|
||||
&mut timer,
|
||||
);
|
||||
let (map, sim, _) = flags
|
||||
.sim_flags
|
||||
.load(Some(Duration::seconds(30.0)), &mut timer);
|
||||
mem.reset("Map and Sim", &mut timer);
|
||||
|
||||
timer.start("draw_map");
|
||||
|
@ -20,8 +20,9 @@ fn main() {
|
||||
// TODO not the ideal way to distinguish what thing we loaded
|
||||
let load = flags.sim_flags.load.clone();
|
||||
let mut timer = Timer::new("setup headless");
|
||||
let mut rng = flags.sim_flags.make_rng();
|
||||
let (map, mut sim) = sim::load(flags.sim_flags, Some(Duration::seconds(30.0)), &mut timer);
|
||||
let (map, mut sim, mut rng) = flags
|
||||
.sim_flags
|
||||
.load(Some(Duration::seconds(30.0)), &mut timer);
|
||||
|
||||
if load.contains("data/raw_maps/") || load.contains("data/maps/") {
|
||||
Scenario::small_run(&map).instantiate(&mut sim, &map, &mut rng, &mut timer);
|
||||
|
@ -10,7 +10,7 @@ mod trips;
|
||||
|
||||
pub use self::events::Event;
|
||||
pub use self::make::{
|
||||
load, ABTest, ABTestResults, BorderSpawnOverTime, OriginDestination, Scenario, SeedParkedCars,
|
||||
ABTest, ABTestResults, BorderSpawnOverTime, OriginDestination, Scenario, SeedParkedCars,
|
||||
SimFlags, SpawnOverTime, TripSpawner, TripSpec,
|
||||
};
|
||||
pub(crate) use self::mechanics::{
|
||||
|
@ -48,119 +48,120 @@ impl SimFlags {
|
||||
XorShiftRng::from_entropy()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Convenience method to setup everything.
|
||||
pub fn load(
|
||||
flags: SimFlags,
|
||||
savestate_every: Option<Duration>,
|
||||
timer: &mut abstutil::Timer,
|
||||
) -> (Map, Sim) {
|
||||
let mut rng = flags.make_rng();
|
||||
// Convenience method to setup everything.
|
||||
pub fn load(
|
||||
&self,
|
||||
savestate_every: Option<Duration>,
|
||||
timer: &mut abstutil::Timer,
|
||||
) -> (Map, Sim, XorShiftRng) {
|
||||
let mut rng = self.make_rng();
|
||||
|
||||
if flags.load.contains("data/save/") {
|
||||
assert_eq!(flags.edits_name, "no_edits");
|
||||
if self.load.contains("data/save/") {
|
||||
assert_eq!(self.edits_name, "no_edits");
|
||||
|
||||
timer.note(format!("Resuming from {}", flags.load));
|
||||
timer.start("read sim savestate");
|
||||
let sim: Sim = abstutil::read_json(&flags.load).expect("loading sim state failed");
|
||||
timer.stop("read sim savestate");
|
||||
timer.note(format!("Resuming from {}", self.load));
|
||||
timer.start("read sim savestate");
|
||||
let sim: Sim = abstutil::read_json(&self.load).expect("loading sim state failed");
|
||||
timer.stop("read sim savestate");
|
||||
|
||||
let edits: MapEdits = if sim.edits_name == "no_edits" {
|
||||
MapEdits::new(&sim.map_name)
|
||||
let edits: MapEdits = if sim.edits_name == "no_edits" {
|
||||
MapEdits::new(&sim.map_name)
|
||||
} else {
|
||||
abstutil::read_json(&format!(
|
||||
"../data/edits/{}/{}.json",
|
||||
sim.map_name, sim.edits_name
|
||||
))
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
// Try loading the pre-baked map first
|
||||
let map: Map = abstutil::read_binary(
|
||||
&format!("../data/maps/{}_{}.abst", sim.map_name, sim.edits_name),
|
||||
timer,
|
||||
)
|
||||
.unwrap_or_else(|_| {
|
||||
let map_path = format!("../data/raw_maps/{}.abst", sim.map_name);
|
||||
Map::new(&map_path, edits, timer)
|
||||
.expect(&format!("Couldn't load map from {}", map_path))
|
||||
});
|
||||
|
||||
(map, sim, rng)
|
||||
} else if self.load.contains("data/scenarios/") {
|
||||
timer.note(format!(
|
||||
"Seeding the simulation from scenario {}",
|
||||
self.load
|
||||
));
|
||||
let scenario: Scenario =
|
||||
abstutil::read_json(&self.load).expect("loading scenario failed");
|
||||
let edits = self.load_edits(&scenario.map_name);
|
||||
|
||||
// Try loading the pre-baked map first
|
||||
let map: Map = abstutil::read_binary(
|
||||
&format!(
|
||||
"../data/maps/{}_{}.abst",
|
||||
scenario.map_name, edits.edits_name
|
||||
),
|
||||
timer,
|
||||
)
|
||||
.unwrap_or_else(|_| {
|
||||
let map_path = format!("../data/raw_maps/{}.abst", scenario.map_name);
|
||||
Map::new(&map_path, edits, timer)
|
||||
.expect(&format!("Couldn't load map from {}", map_path))
|
||||
});
|
||||
let mut sim = Sim::new(
|
||||
&map,
|
||||
// TODO or the scenario name if no run name
|
||||
self.run_name.clone(),
|
||||
savestate_every,
|
||||
);
|
||||
scenario.instantiate(&mut sim, &map, &mut rng, timer);
|
||||
(map, sim, rng)
|
||||
} else if self.load.contains("data/raw_maps/") {
|
||||
// TODO relative dir is brittle; match more cautiously
|
||||
let map_name = self
|
||||
.load
|
||||
.trim_left_matches("../data/raw_maps/")
|
||||
.trim_right_matches(".abst")
|
||||
.to_string();
|
||||
timer.note(format!("Loading map {}", self.load));
|
||||
let edits = self.load_edits(&map_name);
|
||||
let map = Map::new(&self.load, edits, timer)
|
||||
.expect(&format!("Couldn't load map from {}", self.load));
|
||||
timer.start("create sim");
|
||||
let sim = Sim::new(&map, self.run_name.clone(), savestate_every);
|
||||
timer.stop("create sim");
|
||||
(map, sim, rng)
|
||||
} else if self.load.contains("data/maps/") {
|
||||
assert_eq!(self.edits_name, "no_edits");
|
||||
|
||||
timer.note(format!("Loading map {}", self.load));
|
||||
let map: Map = abstutil::read_binary(&self.load, timer)
|
||||
.expect(&format!("Couldn't load map from {}", self.load));
|
||||
timer.start("create sim");
|
||||
let sim = Sim::new(&map, self.run_name.clone(), savestate_every);
|
||||
timer.stop("create sim");
|
||||
(map, sim, rng)
|
||||
} else {
|
||||
abstutil::read_json(&format!(
|
||||
"../data/edits/{}/{}.json",
|
||||
sim.map_name, sim.edits_name
|
||||
))
|
||||
.unwrap()
|
||||
};
|
||||
panic!("Don't know how to load {}", self.load);
|
||||
}
|
||||
}
|
||||
|
||||
// Try loading the pre-baked map first
|
||||
let map: Map = abstutil::read_binary(
|
||||
&format!("../data/maps/{}_{}.abst", sim.map_name, sim.edits_name),
|
||||
timer,
|
||||
)
|
||||
.unwrap_or_else(|_| {
|
||||
let map_path = format!("../data/raw_maps/{}.abst", sim.map_name);
|
||||
Map::new(&map_path, edits, timer)
|
||||
.expect(&format!("Couldn't load map from {}", map_path))
|
||||
});
|
||||
|
||||
(map, sim)
|
||||
} else if flags.load.contains("data/scenarios/") {
|
||||
timer.note(format!(
|
||||
"Seeding the simulation from scenario {}",
|
||||
flags.load
|
||||
));
|
||||
let scenario: Scenario = abstutil::read_json(&flags.load).expect("loading scenario failed");
|
||||
let edits = load_edits(&scenario.map_name, &flags);
|
||||
|
||||
// Try loading the pre-baked map first
|
||||
let map: Map = abstutil::read_binary(
|
||||
&format!(
|
||||
"../data/maps/{}_{}.abst",
|
||||
scenario.map_name, edits.edits_name
|
||||
),
|
||||
timer,
|
||||
)
|
||||
.unwrap_or_else(|_| {
|
||||
let map_path = format!("../data/raw_maps/{}.abst", scenario.map_name);
|
||||
Map::new(&map_path, edits, timer)
|
||||
.expect(&format!("Couldn't load map from {}", map_path))
|
||||
});
|
||||
let mut sim = Sim::new(
|
||||
&map,
|
||||
// TODO or the scenario name if no run name
|
||||
flags.run_name,
|
||||
savestate_every,
|
||||
);
|
||||
scenario.instantiate(&mut sim, &map, &mut rng, timer);
|
||||
(map, sim)
|
||||
} else if flags.load.contains("data/raw_maps/") {
|
||||
// TODO relative dir is brittle; match more cautiously
|
||||
let map_name = flags
|
||||
.load
|
||||
.trim_left_matches("../data/raw_maps/")
|
||||
.trim_right_matches(".abst")
|
||||
.to_string();
|
||||
timer.note(format!("Loading map {}", flags.load));
|
||||
let edits = load_edits(&map_name, &flags);
|
||||
let map = Map::new(&flags.load, edits, timer)
|
||||
.expect(&format!("Couldn't load map from {}", flags.load));
|
||||
timer.start("create sim");
|
||||
let sim = Sim::new(&map, flags.run_name, savestate_every);
|
||||
timer.stop("create sim");
|
||||
(map, sim)
|
||||
} else if flags.load.contains("data/maps/") {
|
||||
assert_eq!(flags.edits_name, "no_edits");
|
||||
|
||||
timer.note(format!("Loading map {}", flags.load));
|
||||
let map: Map = abstutil::read_binary(&flags.load, timer)
|
||||
.expect(&format!("Couldn't load map from {}", flags.load));
|
||||
timer.start("create sim");
|
||||
let sim = Sim::new(&map, flags.run_name, savestate_every);
|
||||
timer.stop("create sim");
|
||||
(map, sim)
|
||||
} else {
|
||||
panic!("Don't know how to load {}", flags.load);
|
||||
fn load_edits(&self, map_name: &str) -> MapEdits {
|
||||
if self.edits_name == "no_edits" {
|
||||
return MapEdits::new(map_name);
|
||||
}
|
||||
if self.edits_name.contains("data/") || self.edits_name.contains(".json") {
|
||||
panic!(
|
||||
"{} should just be a plain name, not a full path",
|
||||
self.edits_name
|
||||
);
|
||||
}
|
||||
let edits: MapEdits = abstutil::read_json(&format!(
|
||||
"../data/edits/{}/{}.json",
|
||||
map_name, self.edits_name
|
||||
))
|
||||
.unwrap();
|
||||
edits
|
||||
}
|
||||
}
|
||||
|
||||
fn load_edits(map_name: &str, flags: &SimFlags) -> MapEdits {
|
||||
if flags.edits_name == "no_edits" {
|
||||
return MapEdits::new(map_name);
|
||||
}
|
||||
if flags.edits_name.contains("data/") || flags.edits_name.contains(".json") {
|
||||
panic!(
|
||||
"{} should just be a plain name, not a full path",
|
||||
flags.edits_name
|
||||
);
|
||||
}
|
||||
let edits: MapEdits = abstutil::read_json(&format!(
|
||||
"../data/edits/{}/{}.json",
|
||||
map_name, flags.edits_name
|
||||
))
|
||||
.unwrap();
|
||||
edits
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ mod scenario;
|
||||
mod spawn;
|
||||
|
||||
pub use self::a_b_test::{ABTest, ABTestResults};
|
||||
pub use self::load::{load, SimFlags};
|
||||
pub use self::load::SimFlags;
|
||||
pub use self::scenario::{
|
||||
BorderSpawnOverTime, OriginDestination, Scenario, SeedParkedCars, SpawnOverTime,
|
||||
};
|
||||
|
@ -71,6 +71,10 @@ impl Scenario {
|
||||
pub fn instantiate(&self, sim: &mut Sim, map: &Map, rng: &mut XorShiftRng, timer: &mut Timer) {
|
||||
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");
|
||||
let neighborhoods = FullNeighborhoodInfo::load_all(map);
|
||||
timer.stop("load full neighborhood info");
|
||||
|
@ -9,7 +9,7 @@ use derivative::Derivative;
|
||||
use ezgui::GfxCtx;
|
||||
use geom::{Distance, Duration, Pt2D};
|
||||
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 std::collections::{HashSet, VecDeque};
|
||||
@ -103,6 +103,11 @@ impl Sim {
|
||||
pub fn get_parked_cars_by_owner(&self, bldg: BuildingID) -> Vec<&ParkedCar> {
|
||||
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
|
||||
|
@ -11,6 +11,7 @@ gag = "0.1.10"
|
||||
geom = { path = "../geom" }
|
||||
map_model = { path = "../map_model" }
|
||||
rand = "0.6.5"
|
||||
rand_xorshift = "0.1.1"
|
||||
sim = { path = "../sim" }
|
||||
structopt = "0.2"
|
||||
termion = "1.5.1"
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::runner::TestRunner;
|
||||
use geom::{Duration, Line, PolyLine, Pt2D};
|
||||
//use rand;
|
||||
|
||||
#[allow(clippy::unreadable_literal)]
|
||||
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());
|
||||
});
|
||||
|
||||
/*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", |_| {
|
||||
/*
|
||||
// EPSILON_DIST needs to be tuned correctly, or this point seems like it's not on the line.
|
||||
|
@ -1,35 +1,40 @@
|
||||
use crate::runner::TestRunner;
|
||||
use abstutil::Timer;
|
||||
use geom::Duration;
|
||||
use sim;
|
||||
use sim::{DrivingGoal, Event, ParkingSpot, SidewalkSpot, SimFlags, TripSpec};
|
||||
|
||||
pub fn run(t: &mut TestRunner) {
|
||||
// TODO Lots of boilerplate between these two. Can we do better?
|
||||
|
||||
t.run_slow("park_on_goal_st", |h| {
|
||||
let (map, mut sim) = sim::load(
|
||||
sim::SimFlags::synthetic_test("parking_test", "park_on_goal_st"),
|
||||
None,
|
||||
&mut Timer::throwaway(),
|
||||
);
|
||||
let (map, mut sim, mut rng) = SimFlags::synthetic_test("parking_test", "park_on_goal_st")
|
||||
.load(None, &mut Timer::throwaway());
|
||||
let north_bldg = map.bldg("north").id;
|
||||
let south_bldg = map.bldg("south").id;
|
||||
let north_parking = map.parking_lane("north", 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
|
||||
sim.seed_specific_parked_cars(north_parking, north_bldg, (0..4).collect());
|
||||
sim.seed_specific_parked_cars(north_parking, north_bldg, (5..10).collect());
|
||||
// TODO I just want to say (south_bldg, north_bldg), not mode...
|
||||
sim.seed_trip_using_parked_car(south_bldg, north_bldg, car, &map);
|
||||
h.seed_parked_cars(&mut sim, &mut rng, north_parking, None, (0..4).collect());
|
||||
h.seed_parked_cars(&mut sim, &mut rng, north_parking, None, (5..10).collect());
|
||||
sim.schedule_trip(
|
||||
Duration::ZERO,
|
||||
TripSpec::UsingParkedCar(
|
||||
SidewalkSpot::building(south_bldg, &map),
|
||||
spot,
|
||||
DrivingGoal::ParkNear(north_bldg),
|
||||
),
|
||||
&map,
|
||||
);
|
||||
h.setup_done(&sim);
|
||||
|
||||
sim.run_until_expectations_met(
|
||||
&map,
|
||||
vec![sim::Event::CarReachedParkingSpot(
|
||||
vec![Event::CarReachedParkingSpot(
|
||||
car,
|
||||
sim::ParkingSpot::new(north_parking, 4),
|
||||
ParkingSpot::new(north_parking, 4),
|
||||
)],
|
||||
Duration::minutes(2),
|
||||
);
|
||||
@ -37,29 +42,35 @@ pub fn run(t: &mut TestRunner) {
|
||||
});
|
||||
|
||||
t.run_slow("wander_around_for_parking", |h| {
|
||||
let (map, mut sim) = sim::load(
|
||||
sim::SimFlags::synthetic_test("parking_test", "wander_around_for_parking"),
|
||||
None,
|
||||
&mut Timer::throwaway(),
|
||||
);
|
||||
let (map, mut sim, mut rng) =
|
||||
SimFlags::synthetic_test("parking_test", "wander_around_for_parking")
|
||||
.load(None, &mut Timer::throwaway());
|
||||
let north_bldg = map.bldg("north").id;
|
||||
let south_bldg = map.bldg("south").id;
|
||||
let north_parking = map.parking_lane("north", 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
|
||||
// the original spot
|
||||
sim.seed_specific_parked_cars(north_parking, north_bldg, (0..23).collect());
|
||||
// TODO I just want to say (south_bldg, north_bldg), not mode...
|
||||
sim.seed_trip_using_parked_car(south_bldg, north_bldg, car, &map);
|
||||
h.seed_parked_cars(&mut sim, &mut rng, north_parking, None, (0..23).collect());
|
||||
sim.schedule_trip(
|
||||
Duration::ZERO,
|
||||
TripSpec::UsingParkedCar(
|
||||
SidewalkSpot::building(south_bldg, &map),
|
||||
spot,
|
||||
DrivingGoal::ParkNear(north_bldg),
|
||||
),
|
||||
&map,
|
||||
);
|
||||
h.setup_done(&sim);
|
||||
|
||||
sim.run_until_expectations_met(
|
||||
&map,
|
||||
vec![sim::Event::CarReachedParkingSpot(
|
||||
vec![Event::CarReachedParkingSpot(
|
||||
car,
|
||||
sim::ParkingSpot::new(south_parking, 0),
|
||||
ParkingSpot::new(south_parking, 0),
|
||||
)],
|
||||
Duration::minutes(2),
|
||||
);
|
||||
|
@ -3,7 +3,9 @@
|
||||
use abstutil;
|
||||
use abstutil::Error;
|
||||
use gag::Redirect;
|
||||
use sim::Sim;
|
||||
use map_model::{BuildingID, LaneID};
|
||||
use rand_xorshift::XorShiftRng;
|
||||
use sim::{CarID, ParkingSpot, Sim};
|
||||
use std;
|
||||
use std::io::Write;
|
||||
use structopt::StructOpt;
|
||||
@ -265,6 +267,17 @@ impl TestHelper {
|
||||
}
|
||||
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)]
|
||||
|
@ -1,20 +1,14 @@
|
||||
use crate::runner::TestRunner;
|
||||
use abstutil::Timer;
|
||||
use geom::Duration;
|
||||
use sim;
|
||||
use sim::{Scenario, SimFlags};
|
||||
|
||||
pub fn run(t: &mut TestRunner) {
|
||||
t.run_slow("small_spawn_completes", |h| {
|
||||
let (map, mut sim) = sim::load(
|
||||
sim::SimFlags::for_test("aorta_model_completes"),
|
||||
Some(Duration::seconds(30.0)),
|
||||
&mut Timer::throwaway(),
|
||||
);
|
||||
sim.small_spawn(&map);
|
||||
let (map, mut sim, mut rng) = SimFlags::for_test("aorta_model_completes")
|
||||
.load(Some(Duration::seconds(30.0)), &mut Timer::throwaway());
|
||||
Scenario::small_run(&map).instantiate(&mut sim, &map, &mut rng, &mut Timer::throwaway());
|
||||
h.setup_done(&sim);
|
||||
sim.run_until_done(&map, |_| {}, Some(Duration::minutes(60)));
|
||||
});
|
||||
}
|
||||
|
||||
// TODO other tests (not completion) to add:
|
||||
// - different behavior (stopping or not) at stop signs
|
||||
|
@ -1,15 +1,12 @@
|
||||
use crate::runner::TestRunner;
|
||||
use abstutil::Timer;
|
||||
use sim;
|
||||
use sim::{Scenario, Sim, SimFlags};
|
||||
|
||||
pub fn run(t: &mut TestRunner) {
|
||||
t.run_slow("serialization", |_| {
|
||||
let (map, mut sim) = sim::load(
|
||||
sim::SimFlags::for_test("serialization"),
|
||||
None,
|
||||
&mut Timer::throwaway(),
|
||||
);
|
||||
sim.small_spawn(&map);
|
||||
let (map, mut sim, mut rng) =
|
||||
SimFlags::for_test("serialization").load(None, &mut Timer::throwaway());
|
||||
Scenario::small_run(&map).instantiate(&mut sim, &map, &mut rng, &mut Timer::throwaway());
|
||||
|
||||
// Does savestating produce the same string?
|
||||
let save1 = abstutil::to_json(&sim);
|
||||
@ -19,14 +16,11 @@ pub fn run(t: &mut TestRunner) {
|
||||
|
||||
t.run_slow("from_scratch", |_| {
|
||||
println!("Creating two simulations");
|
||||
let (map, mut sim1) = sim::load(
|
||||
sim::SimFlags::for_test("from_scratch_1"),
|
||||
None,
|
||||
&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);
|
||||
let (map, mut sim1, mut rng) =
|
||||
SimFlags::for_test("from_scratch_1").load(None, &mut Timer::throwaway());
|
||||
let mut sim2 = Sim::new(&map, "from_scratch_2".to_string(), None);
|
||||
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());
|
||||
|
||||
for _ in 1..600 {
|
||||
if sim1 != sim2 {
|
||||
@ -44,14 +38,11 @@ pub fn run(t: &mut TestRunner) {
|
||||
|
||||
t.run_slow("with_savestating", |_| {
|
||||
println!("Creating two simulations");
|
||||
let (map, mut sim1) = sim::load(
|
||||
sim::SimFlags::for_test("with_savestating_1"),
|
||||
None,
|
||||
&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);
|
||||
let (map, mut sim1, mut rng) =
|
||||
SimFlags::for_test("with_savestating_1").load(None, &mut Timer::throwaway());
|
||||
let mut sim2 = Sim::new(&map, "with_savestating_2".to_string(), None);
|
||||
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());
|
||||
|
||||
for _ in 1..600 {
|
||||
sim1.step(&map);
|
||||
@ -80,9 +71,8 @@ pub fn run(t: &mut TestRunner) {
|
||||
);
|
||||
}
|
||||
|
||||
let sim3: sim::Sim =
|
||||
sim::Sim::load_savestate(sim1_save.clone(), Some("with_savestating_3".to_string()))
|
||||
.unwrap();
|
||||
let sim3: Sim =
|
||||
Sim::load_savestate(sim1_save.clone(), Some("with_savestating_3".to_string())).unwrap();
|
||||
if sim3 != sim2 {
|
||||
panic!(
|
||||
"sim state differs between {} and {}",
|
||||
|
@ -1,16 +1,12 @@
|
||||
use crate::runner::TestRunner;
|
||||
use abstutil::Timer;
|
||||
use geom::Duration;
|
||||
use sim;
|
||||
use sim::{Event, SimFlags};
|
||||
use sim::{Event, SidewalkSpot, SimFlags, TripSpec};
|
||||
|
||||
pub fn run(t: &mut TestRunner) {
|
||||
t.run_slow("bus_reaches_stops", |h| {
|
||||
let (map, mut sim) = sim::load(
|
||||
SimFlags::for_test("bus_reaches_stops"),
|
||||
Some(Duration::seconds(30.0)),
|
||||
&mut Timer::throwaway(),
|
||||
);
|
||||
let (map, mut sim, _) = SimFlags::for_test("bus_reaches_stops")
|
||||
.load(Some(Duration::seconds(30.0)), &mut Timer::throwaway());
|
||||
let route = map.get_bus_route("49").unwrap();
|
||||
let buses = sim.seed_bus_route(route, &map, &mut Timer::throwaway());
|
||||
let bus = buses[0];
|
||||
@ -28,11 +24,8 @@ pub fn run(t: &mut TestRunner) {
|
||||
});
|
||||
|
||||
t.run_slow("ped_uses_bus", |h| {
|
||||
let (map, mut sim) = sim::load(
|
||||
SimFlags::for_test("ped_uses_bus"),
|
||||
Some(Duration::seconds(30.0)),
|
||||
&mut Timer::throwaway(),
|
||||
);
|
||||
let (map, mut sim, _) = SimFlags::for_test("ped_uses_bus")
|
||||
.load(Some(Duration::seconds(30.0)), &mut Timer::throwaway());
|
||||
let route = map.get_bus_route("49").unwrap();
|
||||
let buses = sim.seed_bus_route(route, &map, &mut Timer::throwaway());
|
||||
let bus = buses[0];
|
||||
@ -49,22 +42,33 @@ pub fn run(t: &mut TestRunner) {
|
||||
let goal_bldg = map
|
||||
.get_l(map.get_bs(ped_stop2).sidewalk_pos.lane())
|
||||
.building_paths[0];
|
||||
let ped =
|
||||
sim.seed_trip_using_bus(start_bldg, goal_bldg, route.id, ped_stop1, ped_stop2, &map);
|
||||
sim.schedule_trip(
|
||||
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);
|
||||
|
||||
sim.run_until_expectations_met(
|
||||
&map,
|
||||
vec![
|
||||
sim::Event::PedReachedBusStop(ped, ped_stop1),
|
||||
sim::Event::BusArrivedAtStop(bus, ped_stop1),
|
||||
sim::Event::PedEntersBus(ped, bus),
|
||||
sim::Event::BusDepartedFromStop(bus, ped_stop1),
|
||||
sim::Event::BusArrivedAtStop(bus, ped_stop2),
|
||||
sim::Event::PedLeavesBus(ped, bus),
|
||||
sim::Event::PedReachedBuilding(ped, goal_bldg),
|
||||
sim::Event::BusDepartedFromStop(bus, ped_stop2),
|
||||
sim::Event::BusArrivedAtStop(bus, route.stops[3]),
|
||||
Event::PedReachedBusStop(ped, ped_stop1),
|
||||
Event::BusArrivedAtStop(bus, ped_stop1),
|
||||
Event::PedEntersBus(ped, bus),
|
||||
Event::BusDepartedFromStop(bus, ped_stop1),
|
||||
Event::BusArrivedAtStop(bus, ped_stop2),
|
||||
Event::PedLeavesBus(ped, bus),
|
||||
Event::PedReachedBuilding(ped, goal_bldg),
|
||||
Event::BusDepartedFromStop(bus, ped_stop2),
|
||||
Event::BusArrivedAtStop(bus, route.stops[3]),
|
||||
],
|
||||
Duration::minutes(8),
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user