diff --git a/Cargo.lock b/Cargo.lock index 0fa82949d3..d8572687aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1280,6 +1280,7 @@ dependencies = [ "sim", "structopt", "svg_face", + "synthpop", "wasm-bindgen", "widgetry", ] @@ -1862,6 +1863,7 @@ dependencies = [ "serde_json", "sim", "structopt", + "synthpop", ] [[package]] diff --git a/game/Cargo.toml b/game/Cargo.toml index 80e38b964f..e7b6e402dd 100644 --- a/game/Cargo.toml +++ b/game/Cargo.toml @@ -48,6 +48,7 @@ serde = "1.0.123" serde_json = "1.0.61" svg_face = "0.1.3" sim = { path = "../sim" } +synthpop = { path = "../synthpop" } structopt = "0.3.23" wasm-bindgen = { version = "0.2.70", optional = true } widgetry = { path = "../widgetry" } diff --git a/game/src/challenges/mod.rs b/game/src/challenges/mod.rs index d910294282..130397aa8c 100644 --- a/game/src/challenges/mod.rs +++ b/game/src/challenges/mod.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use geom::{Duration, Percent}; -use sim::OrigPersonID; +use synthpop::OrigPersonID; use widgetry::{EventCtx, Key, Line, Panel, SimpleState, State, Text, TextExt, Widget}; use crate::app::App; diff --git a/game/src/challenges/prebake.rs b/game/src/challenges/prebake.rs index fed7f7019f..0b3c7d56d5 100644 --- a/game/src/challenges/prebake.rs +++ b/game/src/challenges/prebake.rs @@ -87,7 +87,7 @@ fn prebake(map: &Map, scenario: Scenario, timer: &mut Timer) -> PrebakeSummary { let mut sim = Sim::new(map, opts); // Bit of an abuse of this, but just need to fix the rng seed. let mut rng = SimFlags::for_test("prebaked").make_rng(); - scenario.instantiate(&mut sim, map, &mut rng, timer); + sim.instantiate(&scenario, map, &mut rng, timer); // Run until a few hours after the end of the day. Some trips start close to midnight, and we // want prebaked data for them too. diff --git a/game/src/devtools/scenario.rs b/game/src/devtools/scenario.rs index 7f3fdac6e3..9f8456eb99 100644 --- a/game/src/devtools/scenario.rs +++ b/game/src/devtools/scenario.rs @@ -1,6 +1,6 @@ use abstutil::prettyprint_usize; use map_gui::tools::ColorDiscrete; -use sim::Scenario; +use sim::{count_parked_cars_per_bldg, Scenario}; use widgetry::mapspace::ToggleZoomed; use widgetry::{ Color, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel, State, Text, @@ -28,7 +28,7 @@ impl ScenarioManager { ], ); let mut total_cars_needed = 0; - for (b, count) in scenario.count_parked_cars_per_bldg().consume() { + for (b, count) in count_parked_cars_per_bldg(&scenario).consume() { total_cars_needed += count; let color = if count == 0 { continue; diff --git a/game/src/sandbox/gameplay/commute.rs b/game/src/sandbox/gameplay/commute.rs index eb4c0ee721..7a81894260 100644 --- a/game/src/sandbox/gameplay/commute.rs +++ b/game/src/sandbox/gameplay/commute.rs @@ -1,7 +1,8 @@ use std::collections::BTreeMap; use geom::{Duration, Time}; -use sim::{OrigPersonID, PersonID, TripID}; +use sim::{PersonID, TripID}; +use synthpop::OrigPersonID; use widgetry::{ Color, EventCtx, GfxCtx, HorizontalAlignment, Image, Line, Outcome, Panel, State, Text, TextExt, VerticalAlignment, Widget, diff --git a/game/src/sandbox/gameplay/freeform/mod.rs b/game/src/sandbox/gameplay/freeform/mod.rs index 4129a203bf..95f8b053e5 100644 --- a/game/src/sandbox/gameplay/freeform/mod.rs +++ b/game/src/sandbox/gameplay/freeform/mod.rs @@ -11,7 +11,7 @@ use geom::{Distance, Duration}; use map_gui::tools::{grey_out_map, open_browser, CityPicker, PopupMsg, PromptInput, URLManager}; use map_gui::ID; use map_model::{IntersectionID, Position}; -use sim::{IndividTrip, PersonSpec, Scenario, TripEndpoint, TripMode, TripPurpose}; +use sim::{rand_dist, IndividTrip, PersonSpec, Scenario, TripEndpoint, TripMode, TripPurpose}; use widgetry::{ lctrl, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel, SimpleState, State, Text, VerticalAlignment, Widget, @@ -373,7 +373,7 @@ pub fn spawn_agents_around(i: IntersectionID, app: &mut App) { TripPurpose::Shopping, TripEndpoint::SuddenlyAppear(Position::new( lane.id, - Scenario::rand_dist(&mut rng, Distance::ZERO, lane.length()), + rand_dist(&mut rng, Distance::ZERO, lane.length()), )), TripEndpoint::Bldg(map.all_buildings().choose(&mut rng).unwrap().id), mode, @@ -389,7 +389,7 @@ pub fn spawn_agents_around(i: IntersectionID, app: &mut App) { TripPurpose::Shopping, TripEndpoint::SuddenlyAppear(Position::new( lane.id, - Scenario::rand_dist(&mut rng, 0.1 * lane.length(), 0.9 * lane.length()), + rand_dist(&mut rng, 0.1 * lane.length(), 0.9 * lane.length()), )), TripEndpoint::Bldg(map.all_buildings().choose(&mut rng).unwrap().id), TripMode::Walk, @@ -400,8 +400,8 @@ pub fn spawn_agents_around(i: IntersectionID, app: &mut App) { } let retry_if_no_room = false; - scenario.instantiate_without_retries( - &mut app.primary.sim, + app.primary.sim.instantiate_without_retries( + &scenario, map, &mut rng, retry_if_no_room, diff --git a/game/src/sandbox/gameplay/freeform/spawner.rs b/game/src/sandbox/gameplay/freeform/spawner.rs index f0fb415cfd..5ba5cce6e7 100644 --- a/game/src/sandbox/gameplay/freeform/spawner.rs +++ b/game/src/sandbox/gameplay/freeform/spawner.rs @@ -112,8 +112,8 @@ impl State for AgentSpawner { }); } let mut rng = app.primary.current_flags.sim_flags.make_rng(); - scenario.instantiate( - &mut app.primary.sim, + app.primary.sim.instantiate( + &scenario, map, &mut rng, &mut Timer::new("spawn trip"), diff --git a/game/src/sandbox/gameplay/mod.rs b/game/src/sandbox/gameplay/mod.rs index 01d8a83556..1f73ca47ae 100644 --- a/game/src/sandbox/gameplay/mod.rs +++ b/game/src/sandbox/gameplay/mod.rs @@ -8,7 +8,8 @@ use abstio::MapName; use abstutil::Timer; use geom::Duration; use map_model::{EditCmd, EditIntersection, MapEdits}; -use sim::{OrigPersonID, Scenario, ScenarioGenerator, ScenarioModifier}; +use sim::{ScenarioGenerator, ScenarioModifier}; +use synthpop::{OrigPersonID, Scenario}; use widgetry::{ lctrl, EventCtx, GeomBatch, GfxCtx, Key, Line, Outcome, Panel, State, TextExt, Widget, }; diff --git a/game/src/sandbox/gameplay/tutorial.rs b/game/src/sandbox/gameplay/tutorial.rs index 9ac58b4935..06157e2db5 100644 --- a/game/src/sandbox/gameplay/tutorial.rs +++ b/game/src/sandbox/gameplay/tutorial.rs @@ -1101,8 +1101,8 @@ impl TutorialState { }); } let mut rng = app.primary.current_flags.sim_flags.make_rng(); - scenario.instantiate( - &mut app.primary.sim, + app.primary.sim.instantiate( + &scenario, map, &mut rng, &mut Timer::new("spawn trip"), diff --git a/game/src/sandbox/mod.rs b/game/src/sandbox/mod.rs index c84b1cfe38..41e31d4093 100644 --- a/game/src/sandbox/mod.rs +++ b/game/src/sandbox/mod.rs @@ -550,8 +550,8 @@ impl State for SandboxLoader { } } - scenario.instantiate( - &mut app.primary.sim, + app.primary.sim.instantiate( + &scenario, &app.primary.map, &mut app.primary.current_flags.sim_flags.make_rng(), timer, diff --git a/headless/src/main.rs b/headless/src/main.rs index 7ded8b9757..bc52c7ddb5 100644 --- a/headless/src/main.rs +++ b/headless/src/main.rs @@ -193,7 +193,7 @@ fn handle_command( let mut scenario = Scenario::empty(map, "one-shot"); scenario.people = ExternalPerson::import(map, vec![input], false)?; let mut rng = XorShiftRng::seed_from_u64(load.rng_seed); - scenario.instantiate(sim, map, &mut rng, &mut Timer::throwaway()); + sim.instantiate(&scenario, map, &mut rng, &mut Timer::throwaway()); Ok(format!( "{} created", sim.get_all_people().last().unwrap().id @@ -516,7 +516,7 @@ impl LoadSim { let mut rng = XorShiftRng::seed_from_u64(self.rng_seed); let mut sim = Sim::new(&map, self.opts.clone()); - scenario.instantiate(&mut sim, &map, &mut rng, timer); + sim.instantiate(&scenario, &map, &mut rng, timer); (map, sim) } diff --git a/importer/Cargo.toml b/importer/Cargo.toml index 79098dbc51..17a4581c1a 100644 --- a/importer/Cargo.toml +++ b/importer/Cargo.toml @@ -29,6 +29,7 @@ rand_xorshift = "0.3.0" serde = "1.0.123" serde_json = "1.0.61" sim = { path = "../sim" } +synthpop = { path = "../synthpop" } structopt = "0.3.23" # These are all transitive dependencies, specified here only to enable certain diff --git a/importer/src/seattle.rs b/importer/src/seattle.rs index 6b8796a5ae..e6d67d837b 100644 --- a/importer/src/seattle.rs +++ b/importer/src/seattle.rs @@ -7,7 +7,8 @@ use abstutil::Timer; use geom::{Polygon, Ring}; use kml::ExtraShapes; use map_model::{BuildingID, BuildingType, Map}; -use sim::Scenario; +use sim::count_parked_cars_per_bldg; +use synthpop::Scenario; use crate::configuration::ImporterConfiguration; use crate::utils::{download, download_kml}; @@ -128,7 +129,7 @@ pub async fn ensure_popdat_exists( } pub fn adjust_private_parking(map: &mut Map, scenario: &Scenario) { - for (b, count) in scenario.count_parked_cars_per_bldg().consume() { + for (b, count) in count_parked_cars_per_bldg(scenario).consume() { map.hack_override_offstreet_spots_individ(b, count); } map.save(); diff --git a/importer/src/soundcast/popdat.rs b/importer/src/soundcast/popdat.rs index 9335bdd994..b2d0cd3c73 100644 --- a/importer/src/soundcast/popdat.rs +++ b/importer/src/soundcast/popdat.rs @@ -7,7 +7,7 @@ use abstutil::{prettyprint_usize, Counter, Timer}; use geom::{Distance, Duration, LonLat, Time}; use kml::{ExtraShape, ExtraShapes}; use map_model::{osm, Map}; -use sim::{OrigPersonID, TripMode, TripPurpose}; +use synthpop::{OrigPersonID, TripMode, TripPurpose}; #[derive(Serialize, Deserialize)] pub struct PopDat { diff --git a/importer/src/soundcast/trips.rs b/importer/src/soundcast/trips.rs index 23edc5088c..e898e96640 100644 --- a/importer/src/soundcast/trips.rs +++ b/importer/src/soundcast/trips.rs @@ -5,7 +5,9 @@ use geom::{LonLat, PolyLine}; use map_model::{ osm, BuildingID, IntersectionID, Map, Path, PathConstraints, PathRequest, PathStep, }; -use sim::{IndividTrip, MapBorders, OrigPersonID, PersonSpec, Scenario, TripEndpoint, TripMode}; +use synthpop::{ + IndividTrip, MapBorders, OrigPersonID, PersonSpec, Scenario, TripEndpoint, TripMode, +}; use crate::soundcast::popdat::{Endpoint, OrigTrip, PopDat}; diff --git a/importer/src/uk.rs b/importer/src/uk.rs index 1c6ec76c8f..3db05acb34 100644 --- a/importer/src/uk.rs +++ b/importer/src/uk.rs @@ -12,7 +12,7 @@ use geom::{GPSBounds, Polygon}; use map_model::raw::RawMap; use map_model::Map; use popdat::od::DesireLine; -use sim::{Scenario, TripEndpoint, TripMode}; +use synthpop::{Scenario, TripEndpoint, TripMode}; use crate::configuration::ImporterConfiguration; use crate::utils::download; diff --git a/sim/src/lib.rs b/sim/src/lib.rs index b4d6084d33..3646e70451 100644 --- a/sim/src/lib.rs +++ b/sim/src/lib.rs @@ -46,7 +46,10 @@ pub(crate) use self::pandemic::PandemicModel; pub(crate) use self::recorder::TrafficRecorder; pub(crate) use self::router::{ActionAtEnd, Router}; pub(crate) use self::scheduler::{Command, Scheduler}; -pub use self::sim::{AgentProperties, AlertHandler, DelayCause, Sim, SimCallback, SimOptions}; +pub use self::sim::{ + count_parked_cars_per_bldg, rand_dist, AgentProperties, AlertHandler, DelayCause, Sim, + SimCallback, SimOptions, +}; pub(crate) use self::transit::TransitSimState; pub use self::trips::{CommutersVehiclesCounts, Person, PersonState, TripInfo, TripResult}; pub(crate) use self::trips::{TripLeg, TripManager}; diff --git a/sim/src/sim/mod.rs b/sim/src/sim/mod.rs index 7794dba0e7..6fbd728e3f 100644 --- a/sim/src/sim/mod.rs +++ b/sim/src/sim/mod.rs @@ -19,6 +19,8 @@ use map_model::{ use synthpop::OrigPersonID; pub use self::queries::{AgentProperties, DelayCause}; +// TODO Super weird for both of these to wind up here +pub use self::scenario::{count_parked_cars_per_bldg, rand_dist}; use crate::{ AgentID, AlertLocation, Analytics, CarID, Command, CreateCar, DrivingSimState, Event, IntersectionSimState, PandemicModel, ParkedCar, ParkingSim, ParkingSimState, ParkingSpot, diff --git a/tests/src/main.rs b/tests/src/main.rs index 2aa0ad2b9f..e286891f78 100644 --- a/tests/src/main.rs +++ b/tests/src/main.rs @@ -104,7 +104,7 @@ fn smoke_test() -> Result<()> { let mut sim = sim::Sim::new(&map, opts); // Bit of an abuse of this, but just need to fix the rng seed. let mut rng = sim::SimFlags::for_test("smoke_test").make_rng(); - scenario.instantiate(&mut sim, &map, &mut rng, &mut timer); + sim.instantiate(&scenario, &map, &mut rng, &mut timer); sim.timed_step(&map, Duration::hours(1), &mut None, &mut timer); #[allow(clippy::collapsible_if)] @@ -222,7 +222,7 @@ fn test_lane_changing(map: &Map) -> Result<()> { opts.alerts = sim::AlertHandler::Silence; let mut sim = sim::Sim::new(map, opts); let mut rng = sim::SimFlags::for_test("test_lane_changing").make_rng(); - scenario.instantiate(&mut sim, map, &mut rng, &mut Timer::throwaway()); + sim.instantiate(&scenario, map, &mut rng, &mut Timer::throwaway()); while !sim.is_done() { sim.tiny_step(map, &mut None); }