spawn a new bus for every route every hour

This commit is contained in:
Dustin Carlino 2020-07-16 11:58:09 -07:00
parent 1d89d4b85f
commit 82dd1fd01a
3 changed files with 14 additions and 4 deletions

View File

@ -99,10 +99,10 @@ fn correlate_population(kml_path: &str, csv_path: &str) {
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
struct Record { struct Record {
#[serde(rename = "RAUMID")]
// Corresponds with spatial_name from planning_areas // Corresponds with spatial_name from planning_areas
#[serde(rename = "RAUMID")]
raumid: String, raumid: String,
#[serde(rename = "E_E")]
// The total residents in that area // The total residents in that area
#[serde(rename = "E_E")]
e_e: String, e_e: String,
} }

View File

@ -3,7 +3,7 @@ use crate::{
}; };
use derivative::Derivative; use derivative::Derivative;
use geom::{Duration, Histogram, Time}; use geom::{Duration, Histogram, Time};
use map_model::{IntersectionID, Path, PathRequest}; use map_model::{BusRouteID, IntersectionID, Path, PathRequest};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::cmp::Ordering; use std::cmp::Ordering;
use std::collections::btree_map::Entry; use std::collections::btree_map::Entry;
@ -23,6 +23,7 @@ pub enum Command {
Callback(Duration), Callback(Duration),
Pandemic(pandemic::Cmd), Pandemic(pandemic::Cmd),
FinishRemoteTrip(TripID), FinishRemoteTrip(TripID),
SeedBus(BusRouteID),
} }
impl Command { impl Command {
@ -46,6 +47,7 @@ impl Command {
Command::Callback(_) => CommandType::Callback, Command::Callback(_) => CommandType::Callback,
Command::Pandemic(ref p) => CommandType::Pandemic(p.clone()), Command::Pandemic(ref p) => CommandType::Pandemic(p.clone()),
Command::FinishRemoteTrip(t) => CommandType::FinishRemoteTrip(*t), Command::FinishRemoteTrip(t) => CommandType::FinishRemoteTrip(*t),
Command::SeedBus(r) => CommandType::SeedBus(*r),
} }
} }
} }
@ -62,6 +64,7 @@ pub enum CommandType {
Callback, Callback,
Pandemic(pandemic::Cmd), Pandemic(pandemic::Cmd),
FinishRemoteTrip(TripID), FinishRemoteTrip(TripID),
SeedBus(BusRouteID),
} }
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone)] #[derive(Serialize, Deserialize, PartialEq, Eq, Clone)]

View File

@ -227,7 +227,6 @@ impl Sim {
self.parking.add_parked_car(ParkedCar { vehicle, spot }); self.parking.add_parked_car(ParkedCar { vehicle, spot });
} }
// TODO Change this to be a periodic "start a bus at stop1 based on a schedule"
pub(crate) fn seed_bus_route(&mut self, route: &BusRoute, map: &Map, timer: &mut Timer) { pub(crate) fn seed_bus_route(&mut self, route: &BusRoute, map: &Map, timer: &mut Timer) {
// Spawn one bus for the first leg. // Spawn one bus for the first leg.
let (req, path) = self.transit.create_empty_route(route, map); let (req, path) = self.transit.create_empty_route(route, map);
@ -248,6 +247,7 @@ impl Sim {
let start = req.start.lane(); let start = req.start.lane();
if map.get_l(start).length() < vehicle.length { if map.get_l(start).length() < vehicle.length {
// TODO What do we actually do about this? :\
timer.error(format!("Can't start a bus on {}, too short", start)); timer.error(format!("Can't start a bus on {}, too short", start));
return; return;
} }
@ -267,6 +267,10 @@ impl Sim {
true, true,
), ),
); );
// TODO Change the rate of spawning based on a schedule from GTFS or player's choice
self.scheduler
.push(self.time + Duration::hours(1), Command::SeedBus(route.id));
} }
pub fn set_name(&mut self, name: String) { pub fn set_name(&mut self, name: String) {
@ -562,6 +566,9 @@ impl Sim {
&mut self.scheduler, &mut self.scheduler,
); );
} }
Command::SeedBus(r) => {
self.seed_bus_route(map.get_br(r), map, &mut Timer::throwaway());
}
} }
// Record events at precisely the time they occur. // Record events at precisely the time they occur.