Import a scenario for São Miguel Paulista #861

This commit is contained in:
Dustin Carlino 2022-02-21 21:10:50 +00:00
parent 161269a952
commit cf27e48202
5 changed files with 47 additions and 6 deletions

View File

@ -5,12 +5,13 @@ use rand_xorshift::XorShiftRng;
use abstutil::{prettyprint_usize, Timer};
use geom::{Distance, Duration, FindClosest};
use map_model::{AmenityType, BuildingID, Map};
use synthpop::{IndividTrip, Scenario, TripEndpoint, TripMode, TripPurpose};
use synthpop::{IndividTrip, Scenario, ScenarioModifier, TripEndpoint, TripMode, TripPurpose};
pub fn run(
input_scenario: String,
should_add_return_trips: bool,
should_add_lunch_trips: bool,
modifiers: Vec<ScenarioModifier>,
rng_seed: u64,
) {
let mut rng = XorShiftRng::seed_from_u64(rng_seed);
@ -26,6 +27,10 @@ pub fn run(
add_lunch_trips(&mut scenario, &map, &mut rng, &mut timer);
}
for m in modifiers {
scenario = m.apply(&map, scenario);
}
scenario.save();
}

View File

@ -58,6 +58,9 @@ enum Command {
/// Before a person's final trp home, insert a round-trip to a nearby cafe or restaurant
#[structopt(long)]
add_lunch_trips: bool,
/// A JSON list of modifiers to transform the scenario. These can be generated with the GUI.
#[structopt(long, parse(try_from_str = parse_modifiers), default_value = "[]")]
scenario_modifiers: ModifierList,
/// A seed for generating random numbers
#[structopt(long, default_value = "42")]
rng_seed: u64,
@ -220,6 +223,13 @@ enum Command {
},
}
// See https://github.com/TeXitoi/structopt/issues/94
type ModifierList = Vec<synthpop::ScenarioModifier>;
fn parse_modifiers(x: &str) -> Result<ModifierList> {
abstutil::from_json(&x.to_string().into_bytes())
}
#[tokio::main]
async fn main() -> Result<()> {
let cmd = Command::from_args();
@ -245,8 +255,15 @@ async fn main() -> Result<()> {
input_scenario,
add_return_trips,
add_lunch_trips,
scenario_modifiers,
rng_seed,
} => augment_scenario::run(input_scenario, add_return_trips, add_lunch_trips, rng_seed),
} => augment_scenario::run(
input_scenario,
add_return_trips,
add_lunch_trips,
scenario_modifiers,
rng_seed,
),
Command::ClipOSM {
pbf_path,
clip_path,

View File

@ -3010,6 +3010,11 @@
"uncompressed_size_bytes": 958698,
"compressed_size_bytes": 326141
},
"data/system/br/sao_paulo/scenarios/sao_miguel_paulista/Full.bin": {
"checksum": "541fdf1f2ba80b4b6cb88f36b186a707",
"uncompressed_size_bytes": 6083724,
"compressed_size_bytes": 991711
},
"data/system/ca/montreal/maps/plateau.bin": {
"checksum": "b6487d9cd2c5507456363cf6c4fd77ce",
"uncompressed_size_bytes": 10354981,

View File

@ -16,10 +16,10 @@ rm -fv *.json
wget https://raw.githubusercontent.com/cyipt/actdev/main/data-small/$SITE/scenario_base.json
wget https://raw.githubusercontent.com/cyipt/actdev/main/data-small/$SITE/scenario_go_active.json
cargo run --release --bin cli -- import-traffic --map=data/system/gb/$CITY/maps/center.bin --input=scenario_base.json --skip_problems
cargo run --release --bin cli -- import-traffic --map=data/system/gb/$CITY/maps/center.bin --input=scenario_go_active.json --skip_problems
cargo run --release --bin cli -- import-scenario --map=data/system/gb/$CITY/maps/center.bin --input=scenario_base.json --skip_problems
cargo run --release --bin cli -- import-scenario --map=data/system/gb/$CITY/maps/center.bin --input=scenario_go_active.json --skip_problems
rm -fv *.json
cargo run --release --bin cli -- augment-scenario --input=data/system/gb/$CITY/scenarios/center/base.bin --add_return_trips --add_lunch_trips
cargo run --release --bin cli -- augment-scenario --input=data/system/gb/$CITY/scenarios/center/go_active.bin --add_return_trips --add_lunch_trips
cargo run --release --bin cli -- augment-scenario --input-scenario=data/system/gb/$CITY/scenarios/center/base.bin --add-return-trips --add-lunch-trips
cargo run --release --bin cli -- augment-scenario --input-scenario=data/system/gb/$CITY/scenarios/center/go_active.bin --add-return-trips --add-lunch-trips
# Generate the background traffic from OD data, and mix it in with the two actdev scenarios
./import.sh --scenario --city=gb/$CITY

View File

@ -0,0 +1,14 @@
#!/bin/bash
# Generates a scenario from external JSON data, for
# https://github.com/a-b-street/abstreet/issues/861.
#
# Along with actdev_scenario.sh, this should eventually be expressed as part of
# the Rust pipeline directly somehow, so that --scenario uses the original data
# (or a cached S3 version, rather)
set -e
wget https://github.com/spstreets/OD2017/releases/download/1/all_trips.json
cargo run --release --bin cli -- import-scenario --map=data/system/br/sao_paulo/maps/sao_miguel_paulista.bin --input=all_trips.json
# Cancel 80% of all driving trips, so the scenario doesn't gridlock
cargo run --release --bin cli -- augment-scenario --input-scenario=data/system/br/sao_paulo/scenarios/sao_miguel_paulista/Full.bin --scenario-modifiers='[{"ChangeMode":{"pct_ppl":80,"departure_filter":[0,864000000],"from_modes":["Drive"],"to_mode":null}}]'