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)]
struct Record {
#[serde(rename = "RAUMID")]
// Corresponds with spatial_name from planning_areas
#[serde(rename = "RAUMID")]
raumid: String,
#[serde(rename = "E_E")]
// The total residents in that area
#[serde(rename = "E_E")]
e_e: String,
}

View File

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

View File

@ -227,7 +227,6 @@ impl Sim {
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) {
// Spawn one bus for the first leg.
let (req, path) = self.transit.create_empty_route(route, map);
@ -248,6 +247,7 @@ impl Sim {
let start = req.start.lane();
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));
return;
}
@ -267,6 +267,10 @@ impl Sim {
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) {
@ -562,6 +566,9 @@ impl Sim {
&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.