mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 15:33:44 +03:00
Make it easier to test scenario modifiers by specifying them on the CLI
This commit is contained in:
parent
ab270ce9f5
commit
84a65c293b
@ -10,6 +10,10 @@ pub fn to_json<T: Serialize>(obj: &T) -> String {
|
||||
serde_json::to_string_pretty(obj).unwrap()
|
||||
}
|
||||
|
||||
pub fn to_json_terse<T: Serialize>(obj: &T) -> String {
|
||||
serde_json::to_string(obj).unwrap()
|
||||
}
|
||||
|
||||
pub fn from_json<T: DeserializeOwned>(raw: &Vec<u8>) -> Result<T, Box<dyn Error>> {
|
||||
serde_json::from_slice(raw).map_err(|x| x.into())
|
||||
}
|
||||
|
@ -98,7 +98,8 @@ particular order:
|
||||
- Use the `--disable_block_the_box` flag to workaround short roads.
|
||||
- If you notice problems forming from cars stacking up behind slower cyclists,
|
||||
there's no over-taking implemented yet. Use the scenario modifiers to convert
|
||||
all biking trip to driving.
|
||||
all biking trip to driving:
|
||||
`--scenario_modifiers='[{"ChangeMode":{"to_mode":"Drive","pct_ppl":100,"departure_filter":[0.0,86400.0],"from_modes":["Bike"]}}]'`
|
||||
- If all else fails, use the scenario modifiers to bluntly cancel some
|
||||
percentage of all trips.
|
||||
|
||||
|
@ -3,7 +3,7 @@ extern crate log;
|
||||
|
||||
use abstutil::{CmdArgs, Timer};
|
||||
use geom::Duration;
|
||||
use sim::SimFlags;
|
||||
use sim::{ScenarioModifier, SimFlags};
|
||||
|
||||
use crate::app::Flags;
|
||||
|
||||
@ -113,10 +113,15 @@ pub fn main() {
|
||||
let map_name = parts[parts.len() - 2].to_string();
|
||||
let scenario = abstutil::basename(parts[parts.len() - 1]);
|
||||
flags.sim_flags.load = abstutil::path_map(&map_name);
|
||||
|
||||
let modifiers: Vec<ScenarioModifier> = args
|
||||
.optional_parse("--scenario_modifiers", |s| {
|
||||
abstutil::from_json(&s.to_string().into_bytes())
|
||||
})
|
||||
.unwrap_or_else(Vec::new);
|
||||
|
||||
mode = Some(sandbox::GameplayMode::PlayScenario(
|
||||
map_name,
|
||||
scenario,
|
||||
Vec::new(),
|
||||
map_name, scenario, modifiers,
|
||||
));
|
||||
}
|
||||
let start_with_edits = args.optional("--edits");
|
||||
|
@ -233,6 +233,12 @@ impl State for EditScenarioModifiers {
|
||||
return Transition::Pop;
|
||||
}
|
||||
"Apply" => {
|
||||
info!("To apply these modifiers in the future:");
|
||||
info!(
|
||||
"--scenario_modifiers='{}'",
|
||||
abstutil::to_json_terse(&self.modifiers)
|
||||
);
|
||||
|
||||
return Transition::Multi(vec![
|
||||
Transition::Pop,
|
||||
Transition::Replace(SandboxMode::new(
|
||||
@ -342,18 +348,6 @@ impl ChangeMode {
|
||||
modifiers,
|
||||
panel: Panel::new(Widget::col(vec![
|
||||
Line("Change trip mode").small_heading().draw(ctx),
|
||||
Widget::row(vec![
|
||||
"Change to trip type:".draw_text(ctx),
|
||||
Widget::dropdown(
|
||||
ctx,
|
||||
"to_mode",
|
||||
TripMode::Bike,
|
||||
TripMode::all()
|
||||
.into_iter()
|
||||
.map(|m| Choice::new(m.ongoing_verb(), m))
|
||||
.collect(),
|
||||
),
|
||||
]),
|
||||
Widget::row(vec![
|
||||
"Percent of people to modify:"
|
||||
.draw_text(ctx)
|
||||
@ -370,6 +364,19 @@ impl ChangeMode {
|
||||
"Departing until:".draw_text(ctx),
|
||||
AreaSlider::new(ctx, 0.25 * ctx.canvas.window_width, 0.3).named("depart to"),
|
||||
]),
|
||||
Widget::horiz_separator(ctx, 0.5),
|
||||
Widget::row(vec![
|
||||
"Change to trip type:".draw_text(ctx),
|
||||
Widget::dropdown(
|
||||
ctx,
|
||||
"to_mode",
|
||||
TripMode::Bike,
|
||||
TripMode::all()
|
||||
.into_iter()
|
||||
.map(|m| Choice::new(m.ongoing_verb(), m))
|
||||
.collect(),
|
||||
),
|
||||
]),
|
||||
Widget::row(vec![
|
||||
Btn::text_bg2("Apply").build_def(ctx, Key::Enter),
|
||||
Btn::text_bg2("Discard changes").build_def(ctx, Key::Escape),
|
||||
|
@ -2,7 +2,7 @@ use std::collections::BTreeSet;
|
||||
|
||||
use rand::Rng;
|
||||
use rand_xorshift::XorShiftRng;
|
||||
use serde::Deserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use abstutil::Timer;
|
||||
use geom::{Duration, Time};
|
||||
@ -11,7 +11,7 @@ use map_model::Map;
|
||||
use crate::{IndividTrip, PersonID, Scenario, SpawnTrip, TripMode};
|
||||
|
||||
/// Transforms an existing Scenario before instantiating it.
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Deserialize)]
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Serialize, Deserialize)]
|
||||
pub enum ScenarioModifier {
|
||||
RepeatDays(usize),
|
||||
CancelPeople(usize),
|
||||
|
Loading…
Reference in New Issue
Block a user