repeat a weekday scenario many times to experiment with longer-term pandemic modelling

This commit is contained in:
Dustin Carlino 2020-04-06 15:20:29 -07:00
parent 7ff9a90516
commit 22ea48a355
3 changed files with 32 additions and 1 deletions

View File

@ -203,6 +203,14 @@ fn make_change_traffic(btn: ScreenRectangle) -> Box<dyn State> {
quiet, so you may need to fast-forward to morning rush hour. Data \
comes from Puget Sound Regional Council's Soundcast model.",
));
list.push(
Choice::new("5 weekdays repeated", "5 weekdays repeated".to_string())
.tooltip(
"Same as the weekday traffic pattern, but blindly repeated 5 \
times. This isn't realistic; people don't take exactly the \
same trips every day.",
),
);
} else {
list.push(Choice::new(name.clone(), name));
}

View File

@ -142,6 +142,10 @@ impl GameplayMode {
let mut s = Scenario::empty(map, "just buses");
s.only_seed_buses = None;
s
} else if name == "5 weekdays repeated" {
let s: Scenario =
abstutil::read_binary(abstutil::path_scenario(map.get_name(), "weekday"), timer);
s.repeat_days(5)
} else {
let path = abstutil::path_scenario(map.get_name(), &name);
match abstutil::maybe_read_binary(path.clone(), timer) {

View File

@ -3,7 +3,7 @@ use crate::{
BIKE_LENGTH, MAX_CAR_LENGTH, MIN_CAR_LENGTH,
};
use abstutil::Timer;
use geom::{Distance, Speed, Time};
use geom::{Distance, Duration, Speed, Time};
use map_model::{BuildingID, BusRouteID, BusStopID, Map, Position, RoadID};
use rand::seq::SliceRandom;
use rand::Rng;
@ -156,6 +156,25 @@ impl Scenario {
Speed::meters_per_second(1.34),
)
}
pub fn repeat_days(mut self, days: usize) -> Scenario {
self.scenario_name = format!("{} repeated for {} days", self.scenario_name, days);
for person in &mut self.people {
let mut trips = Vec::new();
let mut offset = Duration::ZERO;
for _ in 0..days {
for trip in &person.trips {
trips.push(IndividTrip {
depart: trip.depart + offset,
trip: trip.trip.clone(),
});
}
offset += Duration::hours(24);
}
person.trips = trips;
}
self
}
}
fn seed_parked_cars(