simplify stuff in analytics, removing a major bottleneck in the everyone_weekday scenario

This commit is contained in:
Dustin Carlino 2020-04-25 21:42:29 -07:00
parent 1ecea0a88f
commit 3f48b4bf22
8 changed files with 21 additions and 53 deletions

View File

@ -237,8 +237,8 @@ aad8ff309a1b38dc85a5d8a4b37f3c87 data/system/scenarios/downtown/weekday.bin
112a8e8a1f8e41f566a03ab83d14fe22 data/system/scenarios/caphill/weekday.bin 112a8e8a1f8e41f566a03ab83d14fe22 data/system/scenarios/caphill/weekday.bin
be38f2352b6ac6071707361472888c4c data/system/scenarios/montlake/everyone_weekday.bin be38f2352b6ac6071707361472888c4c data/system/scenarios/montlake/everyone_weekday.bin
fa8391c0e45db61fabdd466ad81b83fa data/system/scenarios/montlake/weekday.bin fa8391c0e45db61fabdd466ad81b83fa data/system/scenarios/montlake/weekday.bin
80cb748e090072b559b08bdd4bc8c30c data/system/prebaked_results/signal_single/tutorial lvl1.bin f9c2c0d6b2beb8260ee35e0e3ec23a3e data/system/prebaked_results/signal_single/tutorial lvl1.bin
ec841305a2dbc37649045f31afce09bd data/system/prebaked_results/signal_single/tutorial lvl2.bin ff80c3565b243cdbf7a0f0c3fa0f559a data/system/prebaked_results/signal_single/tutorial lvl2.bin
2da75e16bd2620e8ed1f8db58e852538 data/system/prebaked_results/montlake/car vs bike contention.bin 9020e5c837e3b41279bd1d0e91838bcd data/system/prebaked_results/montlake/car vs bike contention.bin
06eb9683f2decdcb2ee11b00d4fc2720 data/system/prebaked_results/montlake/weekday.bin 764a4782af23dfbdf6f4dc15623ade3a data/system/prebaked_results/montlake/weekday.bin
02ae8e1b35219ab4934969c07187842b data/system/prebaked_results/montlake/car vs bus contention.bin a800719d76a09b1a257fc9d831a336e6 data/system/prebaked_results/montlake/car vs bus contention.bin

View File

@ -16,8 +16,7 @@ pub struct Analytics {
pub(crate) test_expectations: VecDeque<Event>, pub(crate) test_expectations: VecDeque<Event>,
pub bus_arrivals: Vec<(Time, CarID, BusRouteID, BusStopID)>, pub bus_arrivals: Vec<(Time, CarID, BusRouteID, BusStopID)>,
pub bus_passengers_waiting: Vec<(Time, BusStopID, BusRouteID)>, pub bus_passengers_waiting: Vec<(Time, BusStopID, BusRouteID)>,
// TODO Scraping TripMode from TripPhaseStarting is frustrating. pub started_trips: BTreeMap<TripID, Time>,
pub started_trips: BTreeMap<TripID, (Time, TripMode)>,
// TODO Hack: No TripMode means aborted // TODO Hack: No TripMode means aborted
// Finish time, ID, mode (or None as aborted), trip duration // Finish time, ID, mode (or None as aborted), trip duration
pub finished_trips: Vec<(Time, TripID, Option<TripMode>, Duration)>, pub finished_trips: Vec<(Time, TripID, Option<TripMode>, Duration)>,
@ -117,23 +116,15 @@ impl Analytics {
} }
// Bus passengers // Bus passengers
if let Event::TripPhaseStarting(_, _, _, _, ref tpt) = ev { if let Event::TripPhaseStarting(_, _, _, ref tpt) = ev {
if let TripPhaseType::WaitingForBus(route, stop) = tpt { if let TripPhaseType::WaitingForBus(route, stop) = tpt {
self.bus_passengers_waiting.push((time, *stop, *route)); self.bus_passengers_waiting.push((time, *stop, *route));
} }
} }
// Started trips // Started trips
if let Event::TripPhaseStarting(id, _, mode, _, _) = ev { if let Event::TripPhaseStarting(id, _, _, _) = ev {
// TODO More efficiently self.started_trips.entry(id).or_insert(time);
if !self.started_trips.contains_key(&id)
&& !self
.finished_trips
.iter()
.any(|(_, trip, _, _)| *trip == id)
{
self.started_trips.insert(id, (time, mode));
}
} }
// Finished trips // Finished trips
@ -146,11 +137,9 @@ impl Analytics {
{ {
self.finished_trips self.finished_trips
.push((time, trip, Some(mode), total_time)); .push((time, trip, Some(mode), total_time));
} else if let Event::TripAborted(id, mode) = ev { } else if let Event::TripAborted(id) = ev {
self.started_trips.entry(id).or_insert(time);
self.finished_trips.push((time, id, None, Duration::ZERO)); self.finished_trips.push((time, id, None, Duration::ZERO));
if !self.started_trips.contains_key(&id) {
self.started_trips.insert(id, (time, mode));
}
} }
// Intersection delays // Intersection delays
@ -181,10 +170,10 @@ impl Analytics {
// TODO Kinda hacky, but these all consume the event, so kinda bundle em. // TODO Kinda hacky, but these all consume the event, so kinda bundle em.
match ev { match ev {
Event::TripPhaseStarting(id, _, _, maybe_req, phase_type) => { Event::TripPhaseStarting(id, _, maybe_req, phase_type) => {
self.trip_log.push((time, id, maybe_req, phase_type)); self.trip_log.push((time, id, maybe_req, phase_type));
} }
Event::TripAborted(id, _) => { Event::TripAborted(id) => {
self.trip_log.push((time, id, None, TripPhaseType::Aborted)); self.trip_log.push((time, id, None, TripPhaseType::Aborted));
} }
Event::TripFinished { trip, .. } => { Event::TripFinished { trip, .. } => {
@ -578,7 +567,7 @@ impl Analytics {
pub fn active_agents(&self, now: Time) -> Vec<(Time, usize)> { pub fn active_agents(&self, now: Time) -> Vec<(Time, usize)> {
let mut starts_stops: Vec<(Time, bool)> = Vec::new(); let mut starts_stops: Vec<(Time, bool)> = Vec::new();
for (_, (t, _)) in &self.started_trips { for t in self.started_trips.values() {
if *t <= now { if *t <= now {
starts_stops.push((*t, false)); starts_stops.push((*t, false));
} }

View File

@ -38,14 +38,8 @@ pub enum Event {
total_time: Duration, total_time: Duration,
blocked_time: Duration, blocked_time: Duration,
}, },
TripAborted(TripID, TripMode), TripAborted(TripID),
TripPhaseStarting( TripPhaseStarting(TripID, PersonID, Option<PathRequest>, TripPhaseType),
TripID,
PersonID,
TripMode,
Option<PathRequest>,
TripPhaseType,
),
// Just use for parking replanning. Not happy about copying the full path in here, but the way // Just use for parking replanning. Not happy about copying the full path in here, but the way
// to plumb info into Analytics is Event. // to plumb info into Analytics is Event.

View File

@ -181,7 +181,7 @@ impl PandemicModel {
panic!("{} left {:?}, but they weren't inside", person, loc); panic!("{} left {:?}, but they weren't inside", person, loc);
} }
} }
Event::TripPhaseStarting(_, p, _, _, tpt) => { Event::TripPhaseStarting(_, p, _, tpt) => {
let person = *p; let person = *p;
match tpt { match tpt {
TripPhaseType::WaitingForBus(_, stop) => { TripPhaseType::WaitingForBus(_, stop) => {

View File

@ -1,7 +1,6 @@
use crate::mechanics::Queue; use crate::mechanics::Queue;
use crate::{ use crate::{
Event, ParkingSimState, ParkingSpot, PersonID, SidewalkSpot, TripID, TripMode, TripPhaseType, Event, ParkingSimState, ParkingSpot, PersonID, SidewalkSpot, TripID, TripPhaseType, Vehicle,
Vehicle,
}; };
use geom::Distance; use geom::Distance;
use map_model::{ use map_model::{
@ -216,7 +215,6 @@ impl Router {
events.push(Event::TripPhaseStarting( events.push(Event::TripPhaseStarting(
t, t,
p, p,
TripMode::Drive,
Some(PathRequest { Some(PathRequest {
start: Position::new(current_lane, front), start: Position::new(current_lane, front),
end: new_pos, end: new_pos,
@ -240,7 +238,6 @@ impl Router {
events.push(Event::TripPhaseStarting( events.push(Event::TripPhaseStarting(
t, t,
p, p,
TripMode::Drive,
Some(PathRequest { Some(PathRequest {
start: Position::new(current_lane, front), start: Position::new(current_lane, front),
end: new_pos, end: new_pos,

View File

@ -449,12 +449,6 @@ impl Sim {
events.push(Event::TripPhaseStarting( events.push(Event::TripPhaseStarting(
trip, trip,
person, person,
// TODO sketchy...
if create_car.vehicle.id.1 == VehicleType::Car {
TripMode::Drive
} else {
TripMode::Bike
},
Some(create_car.req.clone()), Some(create_car.req.clone()),
if create_car.vehicle.id.1 == VehicleType::Car { if create_car.vehicle.id.1 == VehicleType::Car {
TripPhaseType::Driving TripPhaseType::Driving
@ -496,7 +490,6 @@ impl Sim {
events.push(Event::TripPhaseStarting( events.push(Event::TripPhaseStarting(
create_ped.trip, create_ped.trip,
create_ped.person, create_ped.person,
TripMode::Walk,
Some(create_ped.req.clone()), Some(create_ped.req.clone()),
TripPhaseType::Walking, TripPhaseType::Walking,
)); ));

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
CarID, Event, PedestrianID, PersonID, Router, Scheduler, TripID, TripManager, TripMode, CarID, Event, PedestrianID, PersonID, Router, Scheduler, TripID, TripManager, TripPhaseType,
TripPhaseType, WalkingSimState, WalkingSimState,
}; };
use abstutil::{deserialize_btreemap, serialize_btreemap}; use abstutil::{deserialize_btreemap, serialize_btreemap};
use geom::{Distance, Time}; use geom::{Distance, Time};
@ -187,7 +187,6 @@ impl TransitSimState {
self.events.push(Event::TripPhaseStarting( self.events.push(Event::TripPhaseStarting(
trip, trip,
person, person,
TripMode::Transit,
Some(PathRequest { Some(PathRequest {
start: map.get_bs(stop1).driving_pos, start: map.get_bs(stop1).driving_pos,
end: map.get_bs(stop2).driving_pos, end: map.get_bs(stop2).driving_pos,
@ -249,7 +248,6 @@ impl TransitSimState {
self.events.push(Event::TripPhaseStarting( self.events.push(Event::TripPhaseStarting(
trip, trip,
person, person,
TripMode::Transit,
Some(PathRequest { Some(PathRequest {
start: map.get_bs(stop1).driving_pos, start: map.get_bs(stop1).driving_pos,
end: map.get_bs(stop2).driving_pos, end: map.get_bs(stop2).driving_pos,

View File

@ -447,7 +447,6 @@ impl TripManager {
self.events.push(Event::TripPhaseStarting( self.events.push(Event::TripPhaseStarting(
trip.id, trip.id,
trip.person, trip.person,
trip.mode,
None, None,
TripPhaseType::WaitingForBus(route, stop), TripPhaseType::WaitingForBus(route, stop),
)); ));
@ -642,7 +641,7 @@ impl TripManager {
let trip = &mut self.trips[id.0]; let trip = &mut self.trips[id.0];
self.unfinished_trips -= 1; self.unfinished_trips -= 1;
trip.aborted = true; trip.aborted = true;
self.events.push(Event::TripAborted(trip.id, trip.mode)); self.events.push(Event::TripAborted(trip.id));
let person = trip.person; let person = trip.person;
// Maintain consistentency for anyone listening to events // Maintain consistentency for anyone listening to events
@ -893,7 +892,6 @@ impl TripManager {
self.events.push(Event::TripPhaseStarting( self.events.push(Event::TripPhaseStarting(
trip, trip,
person.id, person.id,
self.trips[trip.0].mode,
None, None,
TripPhaseType::DelayedStart, TripPhaseType::DelayedStart,
)); ));
@ -1174,7 +1172,6 @@ impl TripManager {
self.events.push(Event::TripPhaseStarting( self.events.push(Event::TripPhaseStarting(
trip, trip,
person.id, person.id,
self.trips[trip.0].mode,
None, None,
TripPhaseType::Remote, TripPhaseType::Remote,
)); ));