Struct sim::mechanics::queue::Queue[][src]

pub(crate) struct Queue {
    pub id: Traversable,
    members: VecDeque<Queued>,
    pub laggy_head: Option<CarID>,
    pub geom_len: Distance,
    pub reserved_length: Distance,
}

A Queue of vehicles on a single lane or turn. This is where https://a-b-street.github.io/docs/tech/trafficsim/discrete_event.html#exact-positions is implemented.

Some helpful pieces of terminology:

Fields

id: Traversablemembers: VecDeque<Queued>laggy_head: Option<CarID>

This car’s back is still partly in this queue.

geom_len: Distance

How long the lane or turn physically is.

reserved_length: Distance

When a car’s turn is accepted, reserve the vehicle length + FOLLOWING_DISTANCE for the target lane. When the car completely leaves (stops being the laggy_head), free up that space. To prevent blocking the box for possibly scary amounts of time, allocate some of this length first. This is unused for turns themselves. This value can exceed geom_len (for the edge case of ONE long car on a short queue).

Implementations

impl Queue[src]

pub fn new(id: Traversable, map: &Map) -> Queue[src]

pub fn get_last_car_position(
    &self,
    now: Time,
    cars: &FixedMap<CarID, Car>,
    queues: &HashMap<Traversable, Queue>
) -> Option<(CarID, Distance)>
[src]

Get the front of the last car in the queue.

pub fn get_car_positions(
    &self,
    now: Time,
    cars: &FixedMap<CarID, Car>,
    queues: &HashMap<Traversable, Queue>
) -> Vec<QueueEntry>
[src]

Return the exact position of each member of the queue. The farthest along (greatest distance) is first.

fn inner_get_last_car_position(
    &self,
    now: Time,
    cars: &FixedMap<CarID, Car>,
    queues: &HashMap<Traversable, Queue>,
    recursed_queues: &mut BTreeSet<Traversable>,
    intermediate_results: Option<&mut Vec<QueueEntry>>
) -> Option<(CarID, Distance)>
[src]

Returns the front of the last car in the queue, only if the last member is an active car.

pub fn get_idx_to_insert_car(
    &self,
    start_dist: Distance,
    vehicle_len: Distance,
    now: Time,
    cars: &FixedMap<CarID, Car>,
    queues: &HashMap<Traversable, Queue>
) -> Option<usize>
[src]

If the specified car can appear in the queue, return the position in the queue to do so.

pub fn insert_car_at_idx(&mut self, idx: usize, car: &Car)[src]

Record that a car has entered a queue at a position. This must match get_idx_to_insert_car – the same index and immediately after passing that query.

pub fn push_car_onto_end(&mut self, car: CarID)[src]

Record that a car has entered a queue at the end. It’s assumed that try_to_reserve_entry has already happened.

pub fn move_first_car_to_laggy_head(&mut self) -> CarID[src]

Change the first car in the queue to the laggy head, indicating that it’s front has left the queue, but its back is still there. Return that car.

pub fn try_to_reserve_entry(&mut self, car: &Car, force_entry: bool) -> bool[src]

If true, there’s room and the car must actually start the turn (because the space is reserved).

pub fn is_overflowing(&self) -> bool[src]

True if the reserved length exceeds the physical length. This means a vehicle is headed towards the queue already and is expected to not fit entirely inside.

pub fn room_for_car(&self, car: &Car) -> bool[src]

Can a car start a turn for this queue?

pub fn free_reserved_space(&mut self, car: &Car)[src]

Once a car has fully exited a queue, free up the space it was reserving.

pub fn target_lane_penalty(&self) -> (usize, usize)[src]

Return a penalty for entering this queue, as opposed to some adjacent ones. Used for lane-changing. (number of vehicles, is there a bike here)

pub fn get_leader(&self, id: CarID) -> Option<CarID>[src]

Find the vehicle in front of the specified input. None if the specified vehicle isn’t ACTIVE (not a blockage) in the queue at all, or they’re the front (with or without a laggy head).

pub fn add_static_blockage(
    &mut self,
    cause: CarID,
    front: Distance,
    back: Distance,
    idx: usize
)
[src]

Record that a car is blocking a static portion of the queue (from front to back). Must use the index from can_block_from_driveway.

pub fn clear_static_blockage(&mut self, caused_by: CarID, idx: usize)[src]

Record that a car is no longer blocking a static portion of the queue.

pub fn replace_car_with_dynamic_blockage(&mut self, car: &Car, idx: usize)[src]

Record that a car is starting to change lanes away from this queue.

pub fn clear_dynamic_blockage(&mut self, caused_by: CarID, idx: usize)[src]

Record that a car is no longer blocking a dynamic portion of the queue.

pub fn can_block_from_driveway(
    &self,
    pos: &Position,
    vehicle_len: Distance,
    now: Time,
    cars: &FixedMap<CarID, Car>,
    queues: &HashMap<Traversable, Queue>
) -> Option<usize>
[src]

True if a static blockage can be inserted into the queue without anything already there intersecting it. Returns the index if so. The position represents the front of the blockage.

pub fn get_active_cars(&self) -> Vec<CarID>[src]

Get all cars in the queue, not including the laggy head or blockages.

TODO Do NOT use this for calculating indices or getting the leader/follower. Might be safer to just hide this and only expose number of active cars, first, and last.

pub fn remove_car_from_idx(&mut self, car: CarID, idx: usize)[src]

Remove a car from a position. Need to separately do free_reserved_space.

pub fn is_car_at_front(&self, car: CarID) -> bool[src]

If a car thinks it’s reached the end of the queue, double check. Blockages or laggy heads might be in the way.

Trait Implementations

impl Clone for Queue[src]

impl Debug for Queue[src]

impl<'de> Deserialize<'de> for Queue[src]

impl Serialize for Queue[src]

Auto Trait Implementations

impl RefUnwindSafe for Queue

impl Send for Queue

impl Sync for Queue

impl Unpin for Queue

impl UnwindSafe for Queue

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Downcast for T where
    T: Any

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

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

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