Reduce visibility of some sim crate stuff. #258

This commit is contained in:
Dustin Carlino 2020-11-19 14:53:27 -08:00
parent d33d051d47
commit 4690ea36cd
17 changed files with 44 additions and 58 deletions

View File

@ -14,7 +14,7 @@ type ZoneIdx = usize;
/// Some roads (grouped into zones) may have a cap on the number of vehicles that can enter per
/// hour. CapSimState enforces this, just for driving trips.
#[derive(Serialize, Deserialize, Clone)]
pub struct CapSimState {
pub(crate) struct CapSimState {
lane_to_zone: BTreeMap<LaneID, ZoneIdx>,
zones: Vec<Zone>,
avoid_congestion: Option<AvoidCongestion>,

View File

@ -17,7 +17,7 @@ use std::fmt;
use serde::{Deserialize, Serialize};
use abstutil::{deserialize_usize, serialize_usize};
use geom::{Distance, Pt2D, Speed, Time};
use geom::{Distance, Speed, Time};
use map_model::{
BuildingID, BusRouteID, BusStopID, DirectedRoadID, IntersectionID, LaneID, Map, ParkingLotID,
Path, PathConstraints, PathRequest, Position,
@ -66,21 +66,21 @@ mod transit;
mod trips;
// http://pccsc.net/bicycle-parking-info/ says 68 inches, which is 1.73m
pub const BIKE_LENGTH: Distance = Distance::const_meters(1.8);
pub(crate) const BIKE_LENGTH: Distance = Distance::const_meters(1.8);
// These two must be < PARKING_SPOT_LENGTH
pub const MIN_CAR_LENGTH: Distance = Distance::const_meters(4.5);
pub const MAX_CAR_LENGTH: Distance = Distance::const_meters(6.5);
pub(crate) const MIN_CAR_LENGTH: Distance = Distance::const_meters(4.5);
pub(crate) const MAX_CAR_LENGTH: Distance = Distance::const_meters(6.5);
// Note this is more than MAX_CAR_LENGTH
pub const BUS_LENGTH: Distance = Distance::const_meters(12.5);
pub const LIGHT_RAIL_LENGTH: Distance = Distance::const_meters(60.0);
pub(crate) const BUS_LENGTH: Distance = Distance::const_meters(12.5);
pub(crate) const LIGHT_RAIL_LENGTH: Distance = Distance::const_meters(60.0);
/// At all speeds (including at rest), cars must be at least this far apart, measured from front of
/// one car to the back of the other.
pub const FOLLOWING_DISTANCE: Distance = Distance::const_meters(1.0);
pub(crate) const FOLLOWING_DISTANCE: Distance = Distance::const_meters(1.0);
/// When spawning at borders, start the front of the vehicle this far along and gradually appear.
/// Getting too close to EPSILON_DIST can lead to get_draw_car having no geometry at all.
pub const SPAWN_DIST: Distance = Distance::const_meters(0.05);
pub(crate) const SPAWN_DIST: Distance = Distance::const_meters(0.05);
/// The numeric ID must be globally unique, without considering VehicleType. VehicleType is bundled
/// for convenient debugging.
@ -324,7 +324,7 @@ pub struct VehicleSpec {
}
impl VehicleSpec {
pub fn make(self, id: CarID, owner: Option<PersonID>) -> Vehicle {
pub(crate) fn make(self, id: CarID, owner: Option<PersonID>) -> Vehicle {
assert_eq!(id.1, self.vehicle_type);
Vehicle {
id,
@ -355,7 +355,7 @@ pub struct ParkedCar {
/// It'd be nice to inline the goal_pos like SidewalkSpot does, but DrivingGoal is persisted in
/// Scenarios, so this wouldn't survive map edits.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum DrivingGoal {
pub(crate) enum DrivingGoal {
ParkNear(BuildingID),
Border(IntersectionID, LaneID),
}
@ -404,24 +404,17 @@ impl DrivingGoal {
}
}
}
pub fn pt(&self, map: &Map) -> Pt2D {
match self {
DrivingGoal::ParkNear(b) => map.get_b(*b).polygon.center(),
DrivingGoal::Border(i, _) => map.get_i(*i).polygon.center(),
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct SidewalkSpot {
pub(crate) struct SidewalkSpot {
pub connection: SidewalkPOI,
pub sidewalk_pos: Position,
}
/// Point of interest, that is
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum SidewalkPOI {
pub(crate) enum SidewalkPOI {
/// Note that for offstreet parking, the path will be the same as the building's front path.
ParkingSpot(ParkingSpot),
/// Don't actually know where this goes yet!
@ -536,7 +529,7 @@ impl SidewalkSpot {
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Copy)]
pub struct TimeInterval {
pub(crate) struct TimeInterval {
// TODO Private fields
pub start: Time,
pub end: Time,
@ -569,7 +562,7 @@ impl TimeInterval {
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Copy)]
pub struct DistanceInterval {
pub(crate) struct DistanceInterval {
// TODO Private fields
pub start: Distance,
pub end: Distance,
@ -599,7 +592,7 @@ impl DistanceInterval {
}
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub struct CreatePedestrian {
pub(crate) struct CreatePedestrian {
pub id: PedestrianID,
pub start: SidewalkSpot,
pub speed: Speed,
@ -611,7 +604,7 @@ pub struct CreatePedestrian {
}
#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)]
pub struct CreateCar {
pub(crate) struct CreateCar {
pub vehicle: Vehicle,
pub router: Router,
pub req: PathRequest,

View File

@ -9,7 +9,7 @@ pub use self::generator::{BorderSpawnOverTime, ScenarioGenerator, SpawnOverTime}
pub use self::load::SimFlags;
pub use self::modifier::ScenarioModifier;
pub use self::scenario::{IndividTrip, PersonSpec, Scenario, TripPurpose};
pub use self::spawner::TripSpec;
pub(crate) use self::spawner::TripSpec;
mod activity_model;
mod external;

View File

@ -14,7 +14,7 @@ use crate::{
// TODO Some of these fields are unused now that we separately pass TripEndpoint
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub enum TripSpec {
pub(crate) enum TripSpec {
/// Can be used to spawn from a border or anywhere for interactive debugging.
VehicleAppearing {
start_pos: Position,

View File

@ -12,7 +12,7 @@ use crate::{
/// Represents a single vehicle. Note "car" is a misnomer; it could also be a bus or bike.
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Car {
pub(crate) struct Car {
pub vehicle: Vehicle,
pub state: CarState,
pub router: Router,
@ -252,7 +252,7 @@ impl Car {
/// See <https://dabreegster.github.io/abstreet/trafficsim/discrete_event.html> for details about the
/// state machine encoded here.
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum CarState {
pub(crate) enum CarState {
Crossing(TimeInterval, DistanceInterval),
Queued {
blocked_since: Time,

View File

@ -19,12 +19,12 @@ use crate::{
const TIME_TO_WAIT_AT_BUS_STOP: Duration = Duration::const_seconds(10.0);
// TODO Do something else.
pub(crate) const BLIND_RETRY_TO_CREEP_FORWARDS: Duration = Duration::const_seconds(0.1);
pub(crate) const BLIND_RETRY_TO_REACH_END_DIST: Duration = Duration::const_seconds(5.0);
pub const BLIND_RETRY_TO_CREEP_FORWARDS: Duration = Duration::const_seconds(0.1);
pub const BLIND_RETRY_TO_REACH_END_DIST: Duration = Duration::const_seconds(5.0);
/// Simulates vehicles!
#[derive(Serialize, Deserialize, Clone)]
pub struct DrivingSimState {
pub(crate) struct DrivingSimState {
// This spends some space to save time. If a simulation contains 1 million cars over the course
// of a day, but only 100,000 are ever active simultaneously, we store 900,000 `None`s. But we
// gain much faster lookup, which has shown dramatic speedups in the scenarios being run so

View File

@ -27,7 +27,7 @@ const WAIT_BEFORE_YIELD_AT_TRAFFIC_SIGNAL: Duration = Duration::const_seconds(0.
/// Most of the complexity comes from attempting to workaround
/// <https://dabreegster.github.io/abstreet/trafficsim/gridlock.html>.
#[derive(Serialize, Deserialize, Clone)]
pub struct IntersectionSimState {
pub(crate) struct IntersectionSimState {
state: BTreeMap<IntersectionID, State>,
use_freeform_policy_everywhere: bool,
dont_block_the_box: bool,

View File

@ -1,8 +1,8 @@
pub use self::driving::DrivingSimState;
pub use self::intersection::IntersectionSimState;
pub use self::parking::{ParkingSim, ParkingSimState};
pub use self::queue::Queue;
pub use self::walking::WalkingSimState;
pub(crate) use self::driving::DrivingSimState;
pub(crate) use self::intersection::IntersectionSimState;
pub(crate) use self::parking::{ParkingSim, ParkingSimState};
pub(crate) use self::queue::Queue;
pub(crate) use self::walking::WalkingSimState;
mod car;
mod driving;

View File

@ -13,7 +13,7 @@ use crate::{CarID, VehicleType, FOLLOWING_DISTANCE};
/// https://dabreegster.github.io/abstreet/trafficsim/discrete_event.html#exact-positions is
/// implemented.
#[derive(Serialize, Deserialize, Clone)]
pub struct Queue {
pub(crate) struct Queue {
pub id: Traversable,
pub cars: VecDeque<CarID>,
/// This car's back is still partly in this queue.

View File

@ -24,7 +24,7 @@ const TIME_TO_FINISH_BIKING: Duration = Duration::const_seconds(45.0);
/// just "ghost" through each other. There's no queueing or slowdown when many people are
/// overlapping. They're simply grouped together into a DrawPedCrowdInput for rendering.
#[derive(Serialize, Deserialize, Clone)]
pub struct WalkingSimState {
pub(crate) struct WalkingSimState {
peds: FixedMap<PedestrianID, Pedestrian>,
#[serde(
serialize_with = "serialize_multimap",
@ -413,10 +413,6 @@ impl WalkingSimState {
peds
}
pub fn does_ped_exist(&self, id: PedestrianID) -> bool {
self.peds.contains_key(&id)
}
pub fn get_draw_peds_on(
&self,
now: Time,

View File

@ -59,7 +59,7 @@ impl PandemicModel {
// Sorry, initialization order of simulations is still a bit messy. This'll be called at
// Time::START_OF_DAY after all of the people have been created from a Scenario.
pub fn initialize(&mut self, population: &Vec<Person>, _scheduler: &mut Scheduler) {
pub(crate) fn initialize(&mut self, population: &Vec<Person>, _scheduler: &mut Scheduler) {
assert!(!self.initialized);
self.initialized = true;
@ -154,7 +154,7 @@ impl PandemicModel {
+ self.count_dead()
}
pub fn handle_event(&mut self, now: Time, ev: &Event, scheduler: &mut Scheduler) {
pub(crate) fn handle_event(&mut self, now: Time, ev: &Event, scheduler: &mut Scheduler) {
assert!(self.initialized);
match ev {
@ -202,7 +202,7 @@ impl PandemicModel {
}
}
pub fn handle_cmd(&mut self, _now: Time, cmd: Cmd, _scheduler: &mut Scheduler) {
pub(crate) fn handle_cmd(&mut self, _now: Time, cmd: Cmd, _scheduler: &mut Scheduler) {
assert!(self.initialized);
// TODO Here we might enforce policies. Like severe -> become hospitalized

View File

@ -12,7 +12,7 @@ use crate::{
/// capture and reproduce behavior in a gridlock-prone chunk of the map, without simulating
/// everything.
#[derive(Clone)]
pub struct TrafficRecorder {
pub(crate) struct TrafficRecorder {
capture_points: BTreeSet<IntersectionID>,
// TODO The RNG will determine vehicle length, so this won't be a perfect capture. Hopefully
// good enough.

View File

@ -18,7 +18,7 @@ use crate::{
};
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct Router {
pub(crate) struct Router {
/// Front is always the current step
path: Path,
goal: Goal,
@ -26,7 +26,7 @@ pub struct Router {
}
#[derive(Debug)]
pub enum ActionAtEnd {
pub(crate) enum ActionAtEnd {
VanishAtBorder(IntersectionID),
StartParking(ParkingSpot),
GotoLaneEnd,

View File

@ -13,7 +13,7 @@ use crate::{
};
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub enum Command {
pub(crate) enum Command {
/// If true, retry when there's no room to spawn somewhere
SpawnCar(CreateCar, bool),
SpawnPed(CreatePedestrian),
@ -124,7 +124,7 @@ impl Ord for Item {
/// schedule Commands to happen at a specific time, and the Scheduler hands out the commands in
/// order.
#[derive(Clone, Serialize, Deserialize)]
pub struct Scheduler {
pub(crate) struct Scheduler {
items: BinaryHeap<Item>,
queued_commands: HashMap<CommandType, (Command, Time)>,

View File

@ -65,7 +65,7 @@ pub struct Sim {
alerts: AlertHandler,
}
pub struct Ctx<'a> {
pub(crate) struct Ctx<'a> {
pub parking: &'a mut ParkingSimState,
pub intersections: &'a mut IntersectionSimState,
pub cap: &'a mut CapSimState,

View File

@ -50,7 +50,7 @@ enum BusState {
/// Manages public transit vehicles (buses and trains) that follow a route. The transit model is
/// currently kind of broken, so not describing the state machine yet.
#[derive(Serialize, Deserialize, Clone)]
pub struct TransitSimState {
pub(crate) struct TransitSimState {
#[serde(
serialize_with = "serialize_btreemap",
deserialize_with = "deserialize_btreemap"

View File

@ -23,7 +23,7 @@ use crate::{
//
// Here be dragons, keep hands and feet inside the ride at all times...
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct TripManager {
pub(crate) struct TripManager {
trips: Vec<Trip>,
people: Vec<Person>,
// For quick lookup of active agents
@ -1088,9 +1088,6 @@ impl TripManager {
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 active_agents_and_trips(&self) -> &BTreeMap<AgentID, TripID> {
&self.active_trip_mode
}
@ -1410,7 +1407,7 @@ impl Trip {
/// These don't specify where the leg starts, since it might be unknown -- like when we drive and
/// don't know where we'll wind up parking.
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub enum TripLeg {
pub(crate) enum TripLeg {
Walk(SidewalkSpot),
/// A person may own many vehicles, so specify which they use
Drive(CarID, DrivingGoal),