Struct sim::mechanics::queue::Queue

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

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:

  • a “laggy head” is a vehicle whose front is now past the end of this queue, but whose back may still be partially in the queue. The position of the first car in the queue is still bounded by the laggy head’s back.
  • a “static blockage” is due to a vehicle exiting a driveway and immediately cutting across a few lanes. The “static” part means it occupies a fixed interval of distance in the queue. When the vehicle is finished exiting the driveway, this blockage is removed.
  • a “dynamic blockage” is due to a vehicle changing lanes in the middle of the queue. The exact position of the blockage in this queue is unknown (it depends on the target queue). The blockage just occupies the length of the vehicle and keeps following whatever’s in front of it.
  • “active cars” are the main members of the queue – everything except for laggy heads and blockages.

Fields§

§id: Traversable§members: 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§

source§

impl Queue

source

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

source

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

Get the front of the last car in the queue.

source

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

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

source

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

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

source

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>

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

source

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

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.

source

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

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

source

pub fn move_first_car_to_laggy_head(&mut self) -> CarID

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.

source

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

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

source

pub fn is_overflowing(&self) -> bool

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.

source

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

Can a car start a turn for this queue?

source

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

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

source

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

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)

source

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

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).

source

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

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.

source

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

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

source

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

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

source

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

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

source

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

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.

source

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

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.

source

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

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

source

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

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§

source§

impl Clone for Queue

source§

fn clone(&self) -> Queue

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 Debug for Queue

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Queue

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 Queue

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 Queue

§

impl RefUnwindSafe for Queue

§

impl Send for Queue

§

impl Sync for Queue

§

impl Unpin for Queue

§

impl UnwindSafe for Queue

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