Skip to main content

RsrDispatch

Struct RsrDispatch 

Source
pub struct RsrDispatch {
    pub eta_weight: f64,
    pub wrong_direction_penalty: f64,
    pub coincident_car_call_bonus: f64,
    pub load_penalty_coeff: f64,
    pub peak_direction_multiplier: f64,
}
Expand description

Additive RSR-style cost stack. Lower scores win the Hungarian assignment.

See module docs for the cost shape. All weights default to 0.0 except eta_weight (1.0), giving a baseline that mirrors NearestCarDispatch until terms are opted in.

§Weight invariants

Every weight field must be finite and non-negative. The with_* builder methods enforce this with assert!; direct field mutation bypasses the check and is a caller responsibility. A NaN weight propagates through the multiply-add chain and silently collapses every pair’s cost to zero (Rust’s NaN.max(0.0) == 0.0), producing an arbitrary but type-valid assignment from the Hungarian solver — a hard bug to diagnose.

Fields§

§eta_weight: f64

Weight on travel_time = distance / max_speed (seconds). Default 1.0; raising it shifts the blend toward travel time.

§wrong_direction_penalty: f64

Constant added when the candidate stop lies opposite the car’s committed travel direction.

Default 0.0; the Otis RSR lineage uses a large value so any right-direction candidate outranks any wrong-direction one. Ignored for cars in ElevatorPhase::Idle or stopped phases, since an idle car has no committed direction to be opposite to.

§coincident_car_call_bonus: f64

Bonus subtracted when the candidate stop is already a car-call inside this car.

Merges the new pickup with an existing dropoff instead of spawning an unrelated trip. Default 0.0. Read from DispatchManifest::car_calls_for.

§load_penalty_coeff: f64

Coefficient on a smooth load-fraction penalty (load_penalty_coeff · load_ratio).

Fires for partially loaded cars below the bypass_load_*_pct threshold enforced by pair_can_do_work; lets you prefer emptier cars for new pickups without an on/off cliff. Default 0.0.

§peak_direction_multiplier: f64

Multiplier applied to wrong_direction_penalty when the TrafficDetector classifies the current tick as TrafficMode::UpPeak or TrafficMode::DownPeak.

Default 1.0 (mode-agnostic — behaviour identical to pre-peak tuning). Raising it strengthens directional commitment during peaks where a car carrying a lobby-bound load shouldn’t be pulled backwards to grab a new pickup. Off-peak periods keep the unscaled penalty, leaving inter-floor assignments free to reverse cheaply.

Silently reduces to 1.0 when no TrafficDetector resource is installed — tests and custom sims that bypass the auto-install stay unaffected.

Implementations§

Source§

impl RsrDispatch

Source

pub const fn new() -> Self

Create a new RsrDispatch with the baseline weights (eta_weight = 1.0, all penalties/bonuses disabled).

Source

pub fn with_wrong_direction_penalty(self, weight: f64) -> Self

Set the wrong-direction penalty.

§Panics

Panics on non-finite or negative weights — a negative penalty would invert the direction ordering, silently preferring wrong-direction candidates.

Source

pub fn with_coincident_car_call_bonus(self, weight: f64) -> Self

Set the coincident-car-call bonus.

§Panics

Panics on non-finite or negative weights — the bonus is subtracted, so a negative value would become a penalty.

Source

pub fn with_load_penalty_coeff(self, weight: f64) -> Self

Set the load-penalty coefficient.

§Panics

Panics on non-finite or negative weights.

Source

pub fn with_eta_weight(self, weight: f64) -> Self

Set the ETA weight.

§Panics

Panics on non-finite or negative weights. Zero is allowed and reduces the strategy to penalty/bonus tiebreaking alone.

Source

pub fn with_peak_direction_multiplier(self, factor: f64) -> Self

Set the peak-direction multiplier.

§Panics

Panics on non-finite or sub-1.0 values. A multiplier below 1.0 would weaken the direction penalty during peaks (the opposite of the intent) — explicitly disallowed so a typo doesn’t silently invert the tuning.

Trait Implementations§

Source§

impl Default for RsrDispatch

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl DispatchStrategy for RsrDispatch

Source§

fn rank(&mut self, ctx: &RankContext<'_>) -> Option<f64>

Score the cost of sending car to stop. Lower is better. Read more
Source§

fn pre_dispatch( &mut self, _group: &ElevatorGroup, _manifest: &DispatchManifest, _world: &mut World, )

Optional hook called once per group before the assignment pass. Read more
Source§

fn prepare_car( &mut self, _car: EntityId, _car_position: f64, _group: &ElevatorGroup, _manifest: &DispatchManifest, _world: &World, )

Optional hook called once per candidate car, before any rank calls for that car in the current pass. Read more
Source§

fn fallback( &mut self, _car: EntityId, _car_position: f64, _group: &ElevatorGroup, _manifest: &DispatchManifest, _world: &World, ) -> DispatchDecision

Decide what an idle car should do when no stop was assigned to it. Read more
Source§

fn notify_removed(&mut self, _elevator: EntityId)

Notify the strategy that an elevator has been removed. 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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.