Plumb sim flags through headless properly. Make the Go experiment print

comparison results ASAP.
This commit is contained in:
Dustin Carlino 2020-09-15 13:47:04 -07:00
parent 716f1f023f
commit 9e38eedaaf
2 changed files with 30 additions and 34 deletions

View File

@ -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))
}
}

View File

@ -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::<u16>().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"));