diff --git a/headless/examples/go_client.go b/headless/examples/go_client.go index 3c0990a257..173dc129d0 100644 --- a/headless/examples/go_client.go +++ b/headless/examples/go_client.go @@ -40,7 +40,6 @@ func main() { } numSucceededLast := 0 - var results1 results var results2 results for pct := int64(100); pct >= 0; pct -= 10 { results, err := run(pct) @@ -55,39 +54,36 @@ func main() { } numSucceededLast = numSucceeded - if *comparePct1 == pct { - results1 = *results - } if *comparePct2 == pct { results2 = *results } - } + if *comparePct1 == pct { + results1 := results + fmt.Printf("\nBaseline cancelled %v%%, experimental cancelled %v%%\n", *comparePct1, *comparePct2) + var faster []float64 + var slower []float64 - if results1.successTime != nil && results2.successTime != nil { - fmt.Printf("\nBaseline cancelled %v%%, experimental cancelled %v%%\n", *comparePct1, *comparePct2) - var faster []float64 - var slower []float64 + for id, experimental_dt := range results2.successTime { + baseline_dt := results1.successTime[id] + if baseline_dt == 0.0 { + // This means the trip didn't finish in hoursToSimulate in the baseline + //fmt.Printf("Trip %v present in experimental, but not baseline\n", id) + continue + } - for id, experimental_dt := range results2.successTime { - baseline_dt := results1.successTime[id] - if baseline_dt == 0.0 { - // This means the trip didn't finish in hoursToSimulate in the baseline - //fmt.Printf("Trip %v present in experimental, but not baseline\n", id) - continue + if false && baseline_dt != experimental_dt { + fmt.Printf(" Trip %v: %v baseline, %v experimental\n", id, baseline_dt, experimental_dt) + } + if baseline_dt > experimental_dt { + faster = append(faster, baseline_dt-experimental_dt) + } else if baseline_dt < experimental_dt { + slower = append(slower, experimental_dt-baseline_dt) + } } - if false && baseline_dt != experimental_dt { - fmt.Printf(" Trip %v: %v baseline, %v experimental\n", id, baseline_dt, experimental_dt) - } - if baseline_dt > experimental_dt { - faster = append(faster, baseline_dt-experimental_dt) - } else if baseline_dt < experimental_dt { - slower = append(slower, experimental_dt-baseline_dt) - } + fmt.Printf("%v trips faster, average %v\n", len(faster), avg(faster)) + fmt.Printf("%v trips slower, average %v\n\n", len(slower), avg(slower)) } - - fmt.Printf("%v trips faster, average %v\n", len(faster), avg(faster)) - fmt.Printf("%v trips slower, average %v\n", len(slower), avg(slower)) } } diff --git a/headless/src/main.rs b/headless/src/main.rs index f8aaa01a87..e9acb65fd1 100644 --- a/headless/src/main.rs +++ b/headless/src/main.rs @@ -18,8 +18,8 @@ use map_model::{ }; use serde::Serialize; use sim::{ - AlertHandler, ExternalPerson, GetDrawAgents, PersonID, Scenario, Sim, SimFlags, SimOptions, - TripID, TripMode, VehicleType, + ExternalPerson, GetDrawAgents, PersonID, Scenario, Sim, SimFlags, SimOptions, TripID, TripMode, + VehicleType, }; use std::collections::{BTreeMap, HashMap}; use std::convert::TryFrom; @@ -35,12 +35,10 @@ lazy_static::lazy_static! { #[tokio::main] async fn main() { let mut args = CmdArgs::new(); - let mut sim_flags = SimFlags::from_args(&mut args); + let sim_flags = SimFlags::from_args(&mut args); let port = args.required("--port").parse::().unwrap(); args.done(); - // Less spam - sim_flags.opts.alerts = AlertHandler::Silence; let (map, sim, _) = sim_flags.load(&mut Timer::new("setup headless")); *MAP.write().unwrap() = map; *SIM.write().unwrap() = sim; @@ -98,9 +96,11 @@ fn handle_command( Ok(format!("sim reloaded")) } "/sim/load" => { - let mut flags: SimFlags = abstutil::from_json(body)?; - flags.opts.alerts = AlertHandler::Silence; - *FLAGS.write().unwrap() = flags; + let flags: SimFlags = abstutil::from_json(body)?; + // Only a few fields from SimFlags can be specified through the API. For the rest + // (namely SimOptions), keep the ones from the command line. + FLAGS.write().unwrap().load = flags.load; + FLAGS.write().unwrap().modifiers = flags.modifiers; // Also reset let (new_map, new_sim, _) = FLAGS.read().unwrap().load(&mut Timer::new("reset sim"));