mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
properly implementing stuff in Sim so far... removing some half-baked summary stuff
This commit is contained in:
parent
c0c4dbd4d2
commit
41d23d2e54
@ -8,6 +8,7 @@ edition = "2018"
|
||||
aabb-quadtree = "0.1.0"
|
||||
abstutil = { path = "../abstutil" }
|
||||
counter = "0.4.3"
|
||||
derivative = "1.0.0"
|
||||
derive-new = "0.5.6"
|
||||
downcast = "0.9.2"
|
||||
ezgui = { path = "../ezgui" }
|
||||
|
@ -9,7 +9,7 @@ use serde_derive::{Deserialize, Serialize};
|
||||
use sim::{CarID, PedestrianID, VehicleType};
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub enum TripSpec {
|
||||
// Can be used to spawn from a border or anywhere for interactive debugging.
|
||||
CarAppearing(Position, VehicleSpec, DrivingGoal),
|
||||
@ -19,7 +19,7 @@ pub enum TripSpec {
|
||||
UsingTransit(SidewalkSpot, BusRouteID, BusStopID, BusStopID, SidewalkSpot),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, PartialEq)]
|
||||
pub struct TripSpawner {
|
||||
// TODO tmp pub
|
||||
pub(crate) car_id_counter: usize,
|
||||
|
@ -7,7 +7,7 @@ use serde_derive::{Deserialize, Serialize};
|
||||
use sim::{CarStatus, DrawCarInput};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Car {
|
||||
pub vehicle: Vehicle,
|
||||
pub state: CarState,
|
||||
@ -129,7 +129,7 @@ impl Car {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub enum CarState {
|
||||
// TODO These two should perhaps be collapsed to (TimeInterval, DistanceInterval, Traversable).
|
||||
Crossing(TimeInterval, DistanceInterval),
|
||||
|
@ -17,7 +17,7 @@ const WAITING: Color = Color::RED;
|
||||
const TIME_TO_UNPARK: Duration = Duration::const_seconds(10.0);
|
||||
const TIME_TO_PARK: Duration = Duration::const_seconds(15.0);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, PartialEq)]
|
||||
pub struct DrivingSimState {
|
||||
queues: BTreeMap<Traversable, Queue>,
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use serde_derive::{Deserialize, Serialize};
|
||||
use sim::AgentID;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, PartialEq)]
|
||||
pub struct IntersectionSimState {
|
||||
controllers: BTreeMap<IntersectionID, IntersectionController>,
|
||||
}
|
||||
@ -47,7 +47,7 @@ impl IntersectionSimState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, PartialEq)]
|
||||
struct IntersectionController {
|
||||
id: IntersectionID,
|
||||
accepted: BTreeSet<Request>,
|
||||
|
@ -5,7 +5,7 @@ use map_model::{Map, Traversable};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, PartialEq)]
|
||||
pub struct Queue {
|
||||
pub id: Traversable,
|
||||
pub cars: VecDeque<Car>,
|
||||
|
@ -15,7 +15,7 @@ const SPEED: Speed = Speed::const_meters_per_second(3.9);
|
||||
const TIME_TO_START_BIKING: Duration = Duration::const_seconds(30.0);
|
||||
const TIME_TO_FINISH_BIKING: Duration = Duration::const_seconds(45.0);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, PartialEq)]
|
||||
pub struct WalkingSimState {
|
||||
// BTreeMap not for deterministic simulation, but to make serialized things easier to compare.
|
||||
peds: BTreeMap<PedestrianID, Pedestrian>,
|
||||
@ -226,7 +226,7 @@ fn delete_ped_from_current_step(map: &mut MultiMap<Traversable, PedestrianID>, p
|
||||
.retain(|&p| p != ped.id);
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, PartialEq)]
|
||||
struct Pedestrian {
|
||||
id: PedestrianID,
|
||||
state: PedState,
|
||||
@ -295,7 +295,7 @@ impl Pedestrian {
|
||||
}
|
||||
|
||||
// crossing front path, bike parking, waiting at bus stop, etc
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, PartialEq)]
|
||||
enum PedState {
|
||||
// If we're past the TimeInterval, then blocked on a turn.
|
||||
// The bool is true when we've marked the turn finished. We might experience two turn sequences
|
||||
|
@ -200,7 +200,7 @@ pub enum SidewalkPOI {
|
||||
BikeRack(Position),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
pub struct TimeInterval {
|
||||
// TODO Private fields
|
||||
pub start: Duration,
|
||||
@ -226,7 +226,7 @@ impl TimeInterval {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
pub struct DistanceInterval {
|
||||
// TODO Private fields
|
||||
pub start: Distance,
|
||||
|
@ -30,6 +30,7 @@ impl Benchmark {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO This is totally unused, needs to be re-thought
|
||||
// TODO moving vs stuck shouldn't be an instantaneous judgment -- stuck is if there's an agent
|
||||
// directly in front limiting speed significantly, or if an intersection isn't allowing movement
|
||||
// yet
|
||||
@ -45,6 +46,7 @@ pub struct Summary {
|
||||
pub trips_with_ab_test_divergence: usize,
|
||||
}
|
||||
|
||||
// TODO This is totally unused, needs to be re-thought
|
||||
// As of a moment in time, not necessarily the end of the simulation
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ScoreSummary {
|
||||
|
@ -4,6 +4,7 @@ use crate::plugins::sim::new_des_model::{
|
||||
WalkingSimState,
|
||||
};
|
||||
use abstutil::Timer;
|
||||
use derivative::Derivative;
|
||||
use ezgui::GfxCtx;
|
||||
use geom::Duration;
|
||||
use map_model::{BuildingID, LaneID, Map, Traversable};
|
||||
@ -13,8 +14,8 @@ use std::collections::{HashSet, VecDeque};
|
||||
use std::panic;
|
||||
use std::time::Instant;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
//#[derivative(PartialEq)]
|
||||
#[derive(Serialize, Deserialize, Derivative)]
|
||||
#[derivative(PartialEq)]
|
||||
pub struct Sim {
|
||||
driving: DrivingSimState,
|
||||
parking: ParkingSimState,
|
||||
@ -29,9 +30,9 @@ pub struct Sim {
|
||||
pub(crate) map_name: String,
|
||||
pub(crate) edits_name: String,
|
||||
// Some tests deliberately set different scenario names for comparisons.
|
||||
//#[derivative(PartialEq = "ignore")]
|
||||
#[derivative(PartialEq = "ignore")]
|
||||
run_name: String,
|
||||
//#[derivative(PartialEq = "ignore")]
|
||||
#[derivative(PartialEq = "ignore")]
|
||||
savestate_every: Option<Duration>,
|
||||
}
|
||||
|
||||
@ -173,6 +174,14 @@ impl Sim {
|
||||
&mut self.trips,
|
||||
);
|
||||
|
||||
// Savestate? Do this AFTER incrementing the timestep. Otherwise we could repeatedly load a
|
||||
// savestate, run a step, and invalidly save over it.
|
||||
if let Some(t) = self.savestate_every {
|
||||
if self.time.is_multiple_of(t) {
|
||||
self.save();
|
||||
}
|
||||
}
|
||||
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
@ -323,50 +332,38 @@ impl Sim {
|
||||
}
|
||||
|
||||
impl Sim {
|
||||
// TODO Rethink this
|
||||
pub fn summarize(&self, lanes: &HashSet<LaneID>) -> Summary {
|
||||
/*let (cars_parked, open_parking_spots) = self.parking_state.count(lanes);
|
||||
let (moving_cars, stuck_cars, buses) = self.driving_state.count(lanes);
|
||||
let (moving_peds, stuck_peds) = self.walking_state.count(lanes);*/
|
||||
let (cars_parked, open_parking_spots) = (0, 0);
|
||||
let (moving_cars, stuck_cars, buses) = (0, 0, 0);
|
||||
let (moving_peds, stuck_peds) = (0, 0);
|
||||
|
||||
Summary {
|
||||
cars_parked,
|
||||
open_parking_spots,
|
||||
moving_cars,
|
||||
stuck_cars,
|
||||
buses,
|
||||
moving_peds,
|
||||
stuck_peds,
|
||||
// Something else has to calculate this
|
||||
cars_parked: 0,
|
||||
open_parking_spots: 0,
|
||||
moving_cars: 0,
|
||||
stuck_cars: 0,
|
||||
buses: 0,
|
||||
moving_peds: 0,
|
||||
stuck_peds: 0,
|
||||
trips_with_ab_test_divergence: 0,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO deprecate this, use the new Summary
|
||||
pub fn summary(&self) -> String {
|
||||
/*let (waiting_cars, active_cars) = self.driving_state.get_active_and_waiting_count();
|
||||
let (waiting_peds, active_peds) = self.walking_state.get_active_and_waiting_count();*/
|
||||
let (waiting_cars, active_cars) = (0, 0);
|
||||
let (waiting_peds, active_peds) = (0, 0);
|
||||
format!(
|
||||
"Time: {0}, {1} / {2} active cars waiting, {3} cars parked, {4} / {5} pedestrians waiting",
|
||||
"{}, {} active agents",
|
||||
self.time,
|
||||
waiting_cars,
|
||||
active_cars,
|
||||
0,
|
||||
//self.parking_state.total_count(),
|
||||
waiting_peds, active_peds,
|
||||
self.trips.active_agents().len()
|
||||
)
|
||||
}
|
||||
|
||||
// TODO Rethink this
|
||||
pub fn get_score(&self) -> ScoreSummary {
|
||||
panic!("TODO");
|
||||
/*let mut s = self.trips_state.get_score(self.time);
|
||||
if self.is_done() {
|
||||
s.completion_time = Some(self.time);
|
||||
ScoreSummary {
|
||||
pending_walking_trips: 0,
|
||||
total_walking_trips: 0,
|
||||
total_walking_trip_time: Duration::ZERO,
|
||||
pending_driving_trips: 0,
|
||||
total_driving_trips: 0,
|
||||
total_driving_trip_time: Duration::ZERO,
|
||||
completion_time: None,
|
||||
}
|
||||
s*/
|
||||
}
|
||||
}
|
||||
|
@ -353,11 +353,14 @@ impl TripManager {
|
||||
id
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn active_agents(&self) -> Vec<AgentID> {
|
||||
self.active_trip_mode.keys().cloned().collect()
|
||||
}
|
||||
|
||||
pub fn get_active_trips(&self) -> Vec<TripID> {
|
||||
self.active_trip_mode.values().cloned().collect()
|
||||
}
|
||||
|
||||
pub fn trip_to_agent(&self, id: TripID) -> Option<AgentID> {
|
||||
let trip = self.trips.get(id.0)?;
|
||||
match trip.legs.get(0)? {
|
||||
@ -375,10 +378,6 @@ impl TripManager {
|
||||
self.active_trip_mode.get(&id).cloned()
|
||||
}
|
||||
|
||||
pub fn get_active_trips(&self) -> Vec<TripID> {
|
||||
self.active_trip_mode.values().cloned().collect()
|
||||
}
|
||||
|
||||
pub fn tooltip_lines(&self, id: AgentID) -> Vec<String> {
|
||||
// Only called for agents that _should_ have trips
|
||||
let trip = &self.trips[self.active_trip_mode[&id].0];
|
||||
@ -387,7 +386,7 @@ impl TripManager {
|
||||
trip.id,
|
||||
trip.legs.back().unwrap()
|
||||
)]
|
||||
}*/
|
||||
}
|
||||
|
||||
pub fn is_done(&self) -> bool {
|
||||
// TODO Buses?
|
||||
|
@ -4,7 +4,7 @@ use serde_derive::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
// Segment, technically. Should rename.
|
||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
|
||||
pub struct Line(Pt2D, Pt2D);
|
||||
|
||||
impl Line {
|
||||
|
Loading…
Reference in New Issue
Block a user