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
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>
pub fn handle_live_edits(&mut self, map: &Map)
fn new_crossing_state(&self, ctx: &mut Ctx<'_>, car: &Car)
source§impl DrivingSimState
impl DrivingSimState
sourcepub fn get_unzoomed_agents(&self, now: Time, map: &Map) -> Vec<UnzoomedAgent>
pub fn get_unzoomed_agents(&self, now: Time, map: &Map) -> Vec<UnzoomedAgent>
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>
pub fn get_all_draw_cars( &self, now: Time, map: &Map, transit: &TransitSimState ) -> Vec<DrawCarInput>
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>
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>
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)>
sourcepub fn find_vehicles_affected_by_live_edits(
&self,
closed_intersections: &HashSet<IntersectionID>,
edited_lanes: &BTreeSet<LaneID>
) -> Vec<(AgentID, TripID)>
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.
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§
source§impl Clone for DrivingSimState
impl Clone for DrivingSimState
source§fn clone(&self) -> DrivingSimState
fn clone(&self) -> DrivingSimState
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'de> Deserialize<'de> for DrivingSimState
impl<'de> Deserialize<'de> for DrivingSimState
source§fn 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>,
Auto Trait Implementations§
impl Freeze for DrivingSimState
impl RefUnwindSafe for DrivingSimState
impl Send for DrivingSimState
impl Sync for DrivingSimState
impl Unpin for DrivingSimState
impl UnwindSafe for DrivingSimState
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.