Struct sim::mechanics::driving::DrivingSimState

source ·
pub(crate) struct DrivingSimState {
    cars: FixedMap<CarID, Car>,
    queues: HashMap<Traversable, Queue>,
    events: Vec<Event>,
    waiting_to_spawn: BTreeMap<CarID, (Position, Option<PersonID>)>,
    recalc_lanechanging: bool,
    handle_uber_turns: bool,
    time_to_unpark_onstreet: Duration,
    time_to_park_onstreet: Duration,
    time_to_unpark_offstreet: Duration,
    time_to_park_offstreet: Duration,
}
Expand description

Simulates vehicles!

Fields§

§cars: FixedMap<CarID, Car>§queues: HashMap<Traversable, Queue>§events: Vec<Event>§waiting_to_spawn: BTreeMap<CarID, (Position, Option<PersonID>)>§recalc_lanechanging: bool§handle_uber_turns: bool§time_to_unpark_onstreet: Duration§time_to_park_onstreet: Duration§time_to_unpark_offstreet: Duration§time_to_park_offstreet: Duration

Implementations§

source§

impl DrivingSimState

source

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

source

pub fn start_car_on_lane( &mut self, now: Time, params: CreateCar, ctx: &mut Ctx<'_> ) -> Option<CreateCar>

None if it worked, otherwise returns the CreateCar unmodified for possible retry.

source

pub fn vehicle_waiting_to_spawn( &mut self, id: CarID, pos: Position, person: Option<PersonID> )

If start_car_on_lane fails and a retry is scheduled, this is an idempotent way to mark the vehicle as active, but waiting to spawn.

source

pub fn update_car( &mut self, id: CarID, now: Time, ctx: &mut Ctx<'_>, trips: &mut TripManager, transit: &mut TransitSimState, walking: &mut WalkingSimState )

State transitions for this car:

Crossing -> Queued or WaitingToAdvance Unparking -> Crossing IdlingAtStop -> Crossing Queued -> last step handling (Parking or done) WaitingToAdvance -> try to advance to the next step of the path Parking -> done

State transitions for other cars:

Crossing -> Crossing (recalculate dist/time) Queued -> Crossing

Why is it safe to process cars in any order, rather than making sure to follow the order of queues? Because of the invariant that distances should never suddenly jump when a car has entered/exiting a queue. This car might have reached the router’s end distance, but maybe not – might actually be stuck behind other cars. We have to calculate the distances right now to be sure.

source

fn update_car_without_distances( &mut self, car: &mut Car, now: Time, ctx: &mut Ctx<'_>, transit: &mut TransitSimState ) -> bool

source

fn update_car_with_distances( &mut self, car: &mut Car, dists: &[QueueEntry], idx: usize, now: Time, ctx: &mut Ctx<'_>, trips: &mut TripManager, transit: &mut TransitSimState, walking: &mut WalkingSimState ) -> bool

source

pub fn delete_car(&mut self, c: CarID, now: Time, ctx: &mut Ctx<'_>) -> Vehicle

Abruptly remove a vehicle from the simulation. They may be in any arbitrary state, like in the middle of a turn or parking.

source

fn delete_car_internal( &mut self, car: &mut Car, dists: Vec<QueueEntry>, idx: usize, now: Time, ctx: &mut Ctx<'_> )

source

fn update_follower( &mut self, idx_leader: usize, dists: &[QueueEntry], now: Time, ctx: &mut Ctx<'_> )

After a leader (maybe an active vehicle, maybe a static blockage) gets out of the way, update the follower so that they don’t suddenly jump forwards.

source

pub fn update_laggy_head(&mut self, id: CarID, now: Time, ctx: &mut Ctx<'_>)

source

fn trim_last_steps( &mut self, car: &mut Car, now: Time, n: usize, ctx: &mut Ctx<'_> )

source

fn pick_overtaking_lane(&self, car: &Car, map: &Map) -> Option<LaneID>

If the car wants to over-take somebody, what adjacent lane should they use?

  • The lane must be in the same direction as the current; no support for crossing the road’s yellow line yet.
  • Prefer passing on the left (for DrivingSide::Right) For now, just pick one candidate lane, even if both might be usable.
source

fn try_start_lc( &mut self, car: &mut Car, front_current_queue: Distance, idx_in_current_queue: usize, target_lane: LaneID, now: Time, ctx: &mut Ctx<'_> )

source

pub fn collect_events(&mut self) -> Vec<Event>

source

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

source

fn new_crossing_state(&self, ctx: &mut Ctx<'_>, car: &Car)

source§

impl DrivingSimState

source

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

Note the ordering of results is non-deterministic!

source

pub fn does_car_exist(&self, id: CarID) -> bool

source

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

Note the ordering of results is non-deterministic!

source

pub fn get_single_draw_car( &self, id: CarID, now: Time, map: &Map, transit: &TransitSimState ) -> Option<DrawCarInput>

This is about as expensive as get_draw_cars_on.

source

pub fn get_draw_cars_on( &self, now: Time, on: Traversable, map: &Map, transit: &TransitSimState ) -> Vec<DrawCarInput>

source

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

source

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

source

pub fn debug_lane(&self, id: LaneID)

source

pub fn agent_properties(&self, id: CarID, now: Time) -> AgentProperties

source

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

source

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

source

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

source

pub fn percent_along_route(&self, id: CarID) -> f64

source

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

source

pub fn target_lane_penalty(&self, l: LaneID) -> (usize, usize)

source

pub fn find_trips_to_edited_parking( &self, spots: BTreeSet<ParkingSpot> ) -> Vec<(AgentID, TripID)>

source

pub fn find_vehicles_affected_by_live_edits( &self, closed_intersections: &HashSet<IntersectionID>, edited_lanes: &BTreeSet<LaneID> ) -> Vec<(AgentID, TripID)>

Finds vehicles that’re laggy heads on affected parts of the map.

source

pub fn all_waiting_people( &self, now: Time, delays: &mut BTreeMap<PersonID, Duration> )

source

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

source

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

source

fn get_car_front(&self, now: Time, car: &Car) -> Distance

source

fn wants_to_overtake(&self, car: &Car) -> Option<CarID>

Does the given car want to over-take the vehicle in front of it?

Trait Implementations§

source§

impl Clone for DrivingSimState

source§

fn clone(&self) -> DrivingSimState

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 DrivingSimState

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 DrivingSimState

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§

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>,