pub trait DispatchStrategy: Send + Sync {
// Required method
fn rank(
&mut self,
car: EntityId,
car_position: f64,
stop: EntityId,
stop_position: f64,
group: &ElevatorGroup,
manifest: &DispatchManifest,
world: &World,
) -> Option<f64>;
// Provided methods
fn pre_dispatch(
&mut self,
_group: &ElevatorGroup,
_manifest: &DispatchManifest,
_world: &mut World,
) { ... }
fn prepare_car(
&mut self,
_car: EntityId,
_car_position: f64,
_group: &ElevatorGroup,
_manifest: &DispatchManifest,
_world: &World,
) { ... }
fn fallback(
&mut self,
_car: EntityId,
_car_position: f64,
_group: &ElevatorGroup,
_manifest: &DispatchManifest,
_world: &World,
) -> DispatchDecision { ... }
fn notify_removed(&mut self, _elevator: EntityId) { ... }
}Expand description
Pluggable dispatch algorithm.
Strategies implement rank to score each (car, stop)
pair; the dispatch system then performs an optimal assignment across
the whole group, guaranteeing that no two cars are sent to the same
hall call.
Returning None from rank excludes a pair from assignment — useful
for capacity limits, direction preferences, restricted stops, or
sticky commitments.
Cars that receive no stop fall through to fallback,
which returns the policy for that car (idle, park, etc.).
Required Methods§
Sourcefn rank(
&mut self,
car: EntityId,
car_position: f64,
stop: EntityId,
stop_position: f64,
group: &ElevatorGroup,
manifest: &DispatchManifest,
world: &World,
) -> Option<f64>
fn rank( &mut self, car: EntityId, car_position: f64, stop: EntityId, stop_position: f64, group: &ElevatorGroup, manifest: &DispatchManifest, world: &World, ) -> Option<f64>
Score the cost of sending car to stop. Lower is better.
Returning None marks this (car, stop) pair as unavailable;
the assignment algorithm will never pair them. Use this for
capacity limits, wrong-direction stops, stops outside the line’s
topology, or pairs already committed via a sticky assignment.
Must return a finite, non-negative value if Some — infinities
and NaN can destabilize the underlying Hungarian solver.
Implementations must not mutate per-car state inside rank: the
dispatch system calls rank(car, stop_0..stop_m) in a loop, so
mutating self on one call affects subsequent calls for the same
car within the same pass and produces an asymmetric cost matrix
whose results depend on iteration order. Use
prepare_car to compute and store any
per-car state before rank is called.
Provided Methods§
Sourcefn pre_dispatch(
&mut self,
_group: &ElevatorGroup,
_manifest: &DispatchManifest,
_world: &mut World,
)
fn pre_dispatch( &mut self, _group: &ElevatorGroup, _manifest: &DispatchManifest, _world: &mut World, )
Optional hook called once per group before the assignment pass.
Strategies that need to mutate World extension storage (e.g.
DestinationDispatch writing sticky rider → car assignments)
or pre-populate crate::components::DestinationQueue entries
override this. Default: no-op.
Sourcefn prepare_car(
&mut self,
_car: EntityId,
_car_position: f64,
_group: &ElevatorGroup,
_manifest: &DispatchManifest,
_world: &World,
)
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.
Strategies whose ranking depends on stable per-car state (e.g. the
sweep direction used by SCAN/LOOK) set that state here so later
rank calls see a consistent view regardless of iteration order.
The default is a no-op.
Sourcefn fallback(
&mut self,
_car: EntityId,
_car_position: f64,
_group: &ElevatorGroup,
_manifest: &DispatchManifest,
_world: &World,
) -> DispatchDecision
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.
Called for each car the assignment phase could not pair with a
stop (because there were no stops, or all candidate stops had
rank None for this car). Default: DispatchDecision::Idle.
Sourcefn notify_removed(&mut self, _elevator: EntityId)
fn notify_removed(&mut self, _elevator: EntityId)
Notify the strategy that an elevator has been removed.
Implementations with per-elevator state (e.g. direction tracking) should clean up here to prevent unbounded memory growth.