game/challenges/
prebake.rs

1use abstio::MapName;
2use abstutil::Timer;
3use sim::prebake::prebake;
4use sim::{ScenarioGenerator, SimFlags};
5use synthpop::Scenario;
6
7use crate::sandbox::TutorialState;
8
9pub fn prebake_all() {
10    let mut timer = Timer::new("prebake all challenge results");
11
12    {
13        let map =
14            map_model::Map::load_synchronously(MapName::seattle("montlake").path(), &mut timer);
15        for generator in TutorialState::scenarios_to_prebake(&map) {
16            let scenario = generator.generate(
17                &map,
18                &mut SimFlags::for_test("prebaked").make_rng(),
19                &mut timer,
20            );
21            // Don't record a summary for this
22            prebake(&map, scenario, &mut timer);
23        }
24    }
25
26    let mut summaries = Vec::new();
27    if false {
28        for name in vec![
29            //MapName::seattle("arboretum"),
30            MapName::seattle("montlake"),
31            //MapName::seattle("lakeslice"),
32            //MapName::seattle("phinney"),
33            //MapName::seattle("qa"),
34            //MapName::seattle("wallingford"),
35        ] {
36            let map = map_model::Map::load_synchronously(name.path(), &mut timer);
37            let scenario: Scenario =
38                abstio::read_binary(abstio::path_scenario(map.get_name(), "weekday"), &mut timer);
39            summaries.push(prebake(&map, scenario, &mut timer));
40        }
41    }
42
43    // Since adding off-map traffic, these all gridlock now
44    if false {
45        let pbury_map = map_model::Map::load_synchronously(
46            MapName::new("gb", "poundbury", "center").path(),
47            &mut timer,
48        );
49        for scenario_name in ["base", "go_active", "base_with_bg", "go_active_with_bg"] {
50            let scenario: Scenario = abstio::read_binary(
51                abstio::path_scenario(pbury_map.get_name(), scenario_name),
52                &mut timer,
53            );
54            summaries.push(prebake(&pbury_map, scenario, &mut timer));
55        }
56    }
57
58    // Started gridlocking with more realistic pedestrian crossing behavior
59    if false {
60        let tehran_map = map_model::Map::load_synchronously(
61            MapName::new("ir", "tehran", "parliament").path(),
62            &mut timer,
63        );
64        let scenario = ScenarioGenerator::proletariat_robot(
65            &tehran_map,
66            &mut SimFlags::for_test("prebaked").make_rng(),
67            &mut timer,
68        );
69        summaries.push(prebake(&tehran_map, scenario, &mut timer));
70    }
71
72    {
73        let map = map_model::Map::load_synchronously(
74            MapName::new("br", "sao_paulo", "sao_miguel_paulista").path(),
75            &mut timer,
76        );
77        let scenario: Scenario =
78            abstio::read_binary(abstio::path_scenario(map.get_name(), "Full"), &mut timer);
79        summaries.push(prebake(&map, scenario, &mut timer));
80    }
81
82    // Assume this is being run from the root directory (via import.sh). This other tests directory
83    // is the most appropriate place to keep this.
84    abstio::write_json(
85        "tests/goldenfiles/prebaked_summaries.json".to_string(),
86        &summaries,
87    );
88}