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
sourceimpl DrivingSimState
impl DrivingSimState
pub fn new(map: &Map, opts: &SimOptions) -> DrivingSimState
sourcepub fn start_car_on_lane(
&mut self,
now: Time,
params: CreateCar,
ctx: &mut Ctx<'_>
) -> Option<CreateCar>
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.
sourcepub fn vehicle_waiting_to_spawn(
&mut self,
id: CarID,
pos: Position,
person: Option<PersonID>
)
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.
sourcepub fn update_car(
&mut self,
id: CarID,
now: Time,
ctx: &mut Ctx<'_>,
trips: &mut TripManager,
transit: &mut TransitSimState,
walking: &mut WalkingSimState
)
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.
fn update_car_without_distances(
&mut self,
car: &mut Car,
now: Time,
ctx: &mut Ctx<'_>,
transit: &mut TransitSimState
) -> bool
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
sourcepub fn delete_car(&mut self, c: CarID, now: Time, ctx: &mut Ctx<'_>) -> Vehicle
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.
fn delete_car_internal(
&mut self,
car: &mut Car,
dists: Vec<QueueEntry>,
idx: usize,
now: Time,
ctx: &mut Ctx<'_>
)
sourcefn update_follower(
&mut self,
idx_leader: usize,
dists: &[QueueEntry],
now: Time,
ctx: &mut Ctx<'_>
)
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.
pub fn update_laggy_head(&mut self, id: CarID, now: Time, ctx: &mut Ctx<'_>)
fn trim_last_steps(
&mut self,
car: &mut Car,
now: Time,
n: usize,
ctx: &mut Ctx<'_>
)
sourcefn pick_overtaking_lane(&self, car: &Car, map: &Map) -> Option<LaneID>
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.
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<'_>
)
pub fn collect_events(&mut self) -> Vec<Event>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub fn handle_live_edits(&mut self, map: &Map)
fn new_crossing_state(&self, ctx: &mut Ctx<'_>, car: &Car)
sourceimpl DrivingSimState
impl DrivingSimState
sourcepub fn get_unzoomed_agents(&self, now: Time, map: &Map) -> Vec<UnzoomedAgent>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn get_unzoomed_agents(&self, now: Time, map: &Map) -> Vec<UnzoomedAgent>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Note the ordering of results is non-deterministic!
pub fn does_car_exist(&self, id: CarID) -> bool
sourcepub fn get_all_draw_cars(
&self,
now: Time,
map: &Map,
transit: &TransitSimState
) -> Vec<DrawCarInput>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn get_all_draw_cars(
&self,
now: Time,
map: &Map,
transit: &TransitSimState
) -> Vec<DrawCarInput>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Note the ordering of results is non-deterministic!
sourcepub fn get_single_draw_car(
&self,
id: CarID,
now: Time,
map: &Map,
transit: &TransitSimState
) -> Option<DrawCarInput>
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.
pub fn get_draw_cars_on(
&self,
now: Time,
on: Traversable,
map: &Map,
transit: &TransitSimState
) -> Vec<DrawCarInput>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub fn debug_car_json(&self, id: CarID) -> String
pub fn debug_car_ui(&self, id: CarID) -> String
pub fn debug_lane(&self, id: LaneID)
pub fn agent_properties(&self, id: CarID, now: Time) -> AgentProperties
pub fn get_path(&self, id: CarID) -> Option<&Path>
pub fn get_all_driving_paths(&self) -> Vec<&Path>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub fn trace_route(&self, now: Time, id: CarID, map: &Map) -> Option<PolyLine>
pub fn percent_along_route(&self, id: CarID) -> f64
pub fn get_owner_of_car(&self, id: CarID) -> Option<PersonID>
pub fn target_lane_penalty(&self, l: LaneID) -> (usize, usize)
pub fn find_trips_to_edited_parking(
&self,
spots: BTreeSet<ParkingSpot>
) -> Vec<(AgentID, TripID)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
sourcepub fn find_vehicles_affected_by_live_edits(
&self,
closed_intersections: &HashSet<IntersectionID>,
edited_lanes: &BTreeSet<LaneID>
) -> Vec<(AgentID, TripID)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn find_vehicles_affected_by_live_edits(
&self,
closed_intersections: &HashSet<IntersectionID>,
edited_lanes: &BTreeSet<LaneID>
) -> Vec<(AgentID, TripID)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Finds vehicles that’re laggy heads on affected parts of the map.
pub fn all_waiting_people(
&self,
now: Time,
delays: &mut BTreeMap<PersonID, Duration>
)
pub fn debug_queue_lengths(&self, l: LaneID) -> Option<(Distance, Distance)>
pub fn get_blocked_by_graph(
&self,
now: Time,
map: &Map,
intersections: &IntersectionSimState
) -> BTreeMap<AgentID, (Duration, DelayCause)>
fn get_car_front(&self, now: Time, car: &Car) -> Distance
sourcefn wants_to_overtake(&self, car: &Car) -> Option<CarID>
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
sourceimpl Clone for DrivingSimState
impl Clone for DrivingSimState
sourcefn clone(&self) -> DrivingSimState
fn clone(&self) -> DrivingSimState
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'de> Deserialize<'de> for DrivingSimState
impl<'de> Deserialize<'de> for DrivingSimState
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Serialize for DrivingSimState
impl Serialize for DrivingSimState
Auto Trait Implementations
impl RefUnwindSafe for DrivingSimState
impl Send for DrivingSimState
impl Sync for DrivingSimState
impl Unpin for DrivingSimState
impl UnwindSafe for DrivingSimState
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
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
. Read more
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
fn as_any(&self) -> &(dyn Any + 'static)
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. Read more
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
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. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more