Struct sim::Sim

source ·
pub struct Sim {
Show 17 fields driving: DrivingSimState, parking: ParkingSimState, walking: WalkingSimState, intersections: IntersectionSimState, transit: TransitSimState, trips: TripManager, pandemic: Option<PandemicModel>, scheduler: Scheduler, time: Time, pub(crate) map_name: MapName, pub(crate) edits_name: String, run_name: String, step_count: usize, highlighted_people: Option<BTreeSet<PersonID>>, analytics: Analytics, recorder: Option<TrafficRecorder>, alerts: AlertHandler,
}
Expand description

The Sim ties together all the pieces of the simulation. Its main property is the current time.

Fields§

§driving: DrivingSimState§parking: ParkingSimState§walking: WalkingSimState§intersections: IntersectionSimState§transit: TransitSimState§trips: TripManager§pandemic: Option<PandemicModel>§scheduler: Scheduler§time: Time§map_name: MapName§edits_name: String§run_name: String§step_count: usize§highlighted_people: Option<BTreeSet<PersonID>>§analytics: Analytics§recorder: Option<TrafficRecorder>§alerts: AlertHandler

Implementations§

source§

impl Sim

source

pub fn time(&self) -> Time

source

pub fn is_done(&self) -> bool

source

pub fn is_empty(&self) -> bool

source

pub fn num_trips(&self) -> (usize, usize)

(number of finished trips, number of unfinished trips)

source

pub fn num_agents(&self) -> Counter<AgentType>

source

pub fn num_commuters_vehicles(&self) -> CommutersVehiclesCounts

source

pub fn num_ppl(&self) -> (usize, usize, usize)

(total number of people, just in buildings, just off map)

source

pub fn debug_ped(&self, id: PedestrianID)

source

pub fn debug_car(&self, id: CarID)

source

pub fn debug_car_ui(&self, id: CarID) -> String

Return a short string to debug a car in the UI.

source

pub fn debug_agent_json(&self, id: AgentID) -> String

source

pub fn debug_intersection_json(&self, id: IntersectionID, map: &Map) -> String

source

pub fn debug_lane(&self, id: LaneID)

source

pub fn agent_properties(&self, map: &Map, id: AgentID) -> AgentProperties

Only call for active agents, will panic otherwise

source

pub fn num_transit_passengers(&self, car: CarID) -> usize

source

pub fn bus_route_id(&self, maybe_bus: CarID) -> Option<TransitRouteID>

source

pub fn active_agents(&self) -> Vec<AgentID>

source

pub fn num_active_agents(&self) -> usize

source

pub fn agent_to_trip(&self, id: AgentID) -> Option<TripID>

source

pub fn trip_to_agent(&self, id: TripID) -> TripResult<AgentID>

source

pub fn trip_info(&self, id: TripID) -> TripInfo

source

pub fn all_trip_info(&self) -> Vec<(TripID, TripInfo)>

source

pub fn finished_trip_details( &self, id: TripID ) -> Option<(Duration, Duration, Distance)>

If trip is finished, returns (total time, total waiting time, total distance)

source

pub fn trip_blocked_time(&self, id: TripID) -> Duration

source

pub fn trip_to_person(&self, id: TripID) -> Option<PersonID>

source

pub fn agent_to_person(&self, id: AgentID) -> Option<PersonID>

source

pub fn person_to_agent(&self, id: PersonID) -> Option<AgentID>

source

pub fn get_owner_of_car(&self, id: CarID) -> Option<PersonID>

source

pub fn lookup_parked_car(&self, id: CarID) -> Option<&ParkedCar>

source

pub fn all_parked_car_positions(&self, map: &Map) -> Vec<(Position, Position)>

For every parked car, (position of parking spot, position of owner)

source

pub fn lookup_person(&self, id: PersonID) -> Option<&Person>

source

pub fn get_person(&self, id: PersonID) -> &Person

source

pub fn find_person_by_orig_id(&self, id: OrigPersonID) -> Option<PersonID>

source

pub fn get_all_people(&self) -> &Vec<Person>

source

pub fn lookup_car_id(&self, idx: usize) -> Option<CarID>

source

pub fn get_path(&self, id: AgentID) -> Option<&Path>

source

pub fn get_all_driving_paths(&self) -> Vec<&Path>

source

pub fn trace_route(&self, id: AgentID, map: &Map) -> Option<PolyLine>

source

pub fn get_canonical_pt_per_trip( &self, trip: TripID, map: &Map ) -> TripResult<Pt2D>

source

pub fn get_canonical_pt_per_person( &self, p: PersonID, map: &Map ) -> Option<Pt2D>

source

pub fn canonical_pt_for_agent(&self, id: AgentID, map: &Map) -> Option<Pt2D>

source

pub fn get_accepted_agents(&self, id: IntersectionID) -> Vec<(AgentID, TurnID)>

source

pub fn get_waiting_agents( &self, id: IntersectionID ) -> Vec<(AgentID, TurnID, Time)>

source

pub fn get_blocked_by_graph( &self, map: &Map ) -> BTreeMap<AgentID, (Duration, DelayCause)>

For every agent that’s currently not moving, figure out how long they’ve been waiting and why they’re blocked.

source

pub fn status_of_buses( &self, route: TransitRouteID, map: &Map ) -> Vec<(CarID, Option<usize>, f64, Pt2D)>

(bus, stop index it’s coming from, percent to next stop, location)

source

pub fn get_analytics(&self) -> &Analytics

source

pub fn delayed_intersections( &self, threshold: Duration ) -> Vec<(IntersectionID, Time)>

For intersections with an agent waiting beyond some threshold, return when they started waiting. Sorted by earliest waiting (likely the root cause of gridlock).

source

pub fn bldg_to_people(&self, b: BuildingID) -> Vec<PersonID>

source

pub fn get_pandemic_model(&self) -> Option<&PandemicModel>

source

pub fn get_end_of_day(&self) -> Time

source

pub fn current_stage_and_remaining_time( &self, i: IntersectionID ) -> (usize, Duration)

source

pub fn all_arrivals_at_border( &self, i: IntersectionID ) -> Vec<(AgentType, Vec<(Time, usize)>)>

source

pub fn target_lane_penalty(&self, lane: &Lane) -> (usize, usize)

(number of vehicles in the lane, penalty if a bike or other slow vehicle is present)

source

pub fn get_people_waiting_at_stop( &self, at: TransitStopID ) -> &Vec<(PedestrianID, TransitRouteID, Option<TransitStopID>, Time)>

source

pub fn generate_scenario(&self, map: &Map, name: String) -> Scenario

source

pub fn infinite_parking(&self) -> bool

source

pub fn all_waiting_people(&self) -> BTreeMap<PersonID, Duration>

source

pub fn describe_internal_stats(&self) -> Vec<String>

source

pub fn debug_queue_lengths(&self, l: LaneID) -> Option<(Distance, Distance)>

source

pub fn get_trip_time_lower_bound( &self, map: &Map, id: TripID ) -> Result<Duration>

Returns the best-case time for a trip in a world with no traffic or intersection delays. Might fail in some cases where the real trip succeeds, but the single-mode path can’t be found. Assumes the TripID exists.

source

pub fn get_highlighted_people(&self) -> &Option<BTreeSet<PersonID>>

source

pub fn get_pedestrian_density( &self, map: &Map ) -> (BTreeMap<RoadID, f64>, BTreeMap<IntersectionID, f64>)

Returns people / m^2. Roads have up to two sidewalks and intersections have many crossings – take the max density along any one.

source§

impl Sim

source

pub fn step_count(&self) -> usize

source

pub fn get_draw_car(&self, id: CarID, map: &Map) -> Option<DrawCarInput>

source

pub fn get_draw_ped( &self, id: PedestrianID, map: &Map ) -> Option<DrawPedestrianInput>

source

pub fn get_draw_cars(&self, on: Traversable, map: &Map) -> Vec<DrawCarInput>

source

pub fn get_draw_peds( &self, on: Traversable, map: &Map ) -> (Vec<DrawPedestrianInput>, Vec<DrawPedCrowdInput>)

source

pub fn get_all_draw_cars(&self, map: &Map) -> Vec<DrawCarInput>

source

pub fn get_all_draw_peds(&self, map: &Map) -> Vec<DrawPedestrianInput>

source

pub fn get_unzoomed_agents(&self, map: &Map) -> Vec<UnzoomedAgent>

This does not include transit riders. Some callers need those in addition, but the rendering ones don’t.

source

pub fn get_unzoomed_transit_riders(&self, map: &Map) -> Vec<UnzoomedAgent>

source§

impl Sim

source

pub fn instantiate( &mut self, scenario: &Scenario, map: &Map, rng: &mut XorShiftRng, timer: &mut Timer<'_> )

source

pub fn instantiate_without_retries( &mut self, scenario: &Scenario, map: &Map, rng: &mut XorShiftRng, retry_if_no_room: bool, timer: &mut Timer<'_> )

If retry_if_no_room is false, any vehicles that fail to spawn because of something else in the way will just wind up as cancelled trips.

source§

impl Sim

source

pub fn new(map: &Map, opts: SimOptions) -> Sim

source

pub(crate) fn spawn_trips( &mut self, input: Vec<(PersonID, TripInfo, StartTripArgs)>, map: &Map, timer: &mut Timer<'_> )

source

pub fn get_free_onstreet_spots(&self, l: LaneID) -> Vec<ParkingSpot>

source

pub fn get_free_offstreet_spots(&self, b: BuildingID) -> Vec<ParkingSpot>

source

pub fn get_free_lot_spots(&self, pl: ParkingLotID) -> Vec<ParkingSpot>

source

pub fn get_all_parking_spots(&self) -> (Vec<ParkingSpot>, Vec<ParkingSpot>)

(Filled, available)

source

pub fn bldg_to_parked_cars(&self, b: BuildingID) -> Vec<CarID>

source

pub fn walking_path_to_nearest_parking_spot( &self, map: &Map, b: BuildingID ) -> Option<Path>

source

pub(crate) fn new_person( &mut self, orig_id: Option<OrigPersonID>, ped_speed: Speed, vehicle_specs: Vec<VehicleSpec> ) -> &Person

source

pub(crate) fn seed_parked_car(&mut self, vehicle: Vehicle, spot: ParkingSpot)

source

pub(crate) fn seed_bus_route(&mut self, route: &TransitRoute)

source

fn start_bus(&mut self, route: &TransitRoute, map: &Map)

source

pub fn set_run_name(&mut self, name: String)

source

pub fn get_run_name(&self) -> &String

source§

impl Sim

source

fn minimal_step( &mut self, map: &Map, max_dt: Duration, maybe_cb: &mut Option<Box<dyn SimCallback>> ) -> bool

source

fn do_step( &mut self, map: &Map, time: Time, cmd: Command, maybe_cb: &mut Option<Box<dyn SimCallback>> ) -> bool

source

fn dispatch_events(&mut self, events: Vec<Event>, map: &Map)

source

pub fn timed_step( &mut self, map: &Map, dt: Duration, maybe_cb: &mut Option<Box<dyn SimCallback>>, timer: &mut Timer<'_> )

source

pub fn tiny_step( &mut self, map: &Map, maybe_cb: &mut Option<Box<dyn SimCallback>> )

source

pub fn time_limited_step( &mut self, map: &Map, dt: Duration, real_time_limit: Duration, maybe_cb: &mut Option<Box<dyn SimCallback>> )

source

pub fn dump_before_abort(&self)

source§

impl Sim

source

pub fn save_dir(&self) -> String

source

fn save_path(&self, base_time: Time) -> String

source

pub fn save(&mut self) -> String

source

pub fn find_previous_savestate(&self, base_time: Time) -> Option<String>

source

pub fn find_next_savestate(&self, base_time: Time) -> Option<String>

source

pub fn load_savestate(path: String, timer: &mut Timer<'_>) -> Result<Sim>

source§

impl Sim

source

pub fn handle_live_edited_traffic_signals(&mut self, map: &Map)

source

pub fn handle_live_edits( &mut self, map: &Map, timer: &mut Timer<'_> ) -> (usize, usize)

Respond to arbitrary map edits without resetting the simulation. Returns the number of (trips cancelled, parked cars displaced).

source

fn find_trips_affected_by_live_edits( &mut self, map: &Map, timer: &mut Timer<'_> ) -> (BTreeSet<(AgentID, TripID)>, usize)

Returns (trips affected, number of parked cars displaced)

source§

impl Sim

source

pub fn delete_car(&mut self, id: CarID, map: &Map)

source

pub fn clear_alerts(&mut self) -> Vec<(Time, AlertLocation, String)>

source§

impl Sim

source

pub fn set_periodic_callback(&mut self, frequency: Duration)

Only one at a time supported.

source

pub fn unset_periodic_callback(&mut self)

source§

impl Sim

source

pub fn record_traffic_for(&mut self, intersections: BTreeSet<IntersectionID>)

source

pub fn num_recorded_trips(&self) -> Option<usize>

source

pub fn save_recorded_traffic(&mut self, map: &Map)

source§

impl Sim

source

pub fn set_highlighted_people(&mut self, people: BTreeSet<PersonID>)

Trait Implementations§

source§

impl Clone for Sim

source§

fn clone(&self) -> Sim

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'de> Deserialize<'de> for Sim

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Serialize for Sim

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Sim

§

impl RefUnwindSafe for Sim

§

impl Send for Sim

§

impl Sync for Sim

§

impl Unpin for Sim

§

impl UnwindSafe for Sim

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

§

fn is_within(&self, b: &G2) -> bool

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,