1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! Nearest-car dispatch — assigns each call to the closest idle elevator.
use ;
/// Scores `(car, stop)` by absolute distance between the car and the stop.
///
/// Paired with the Hungarian assignment in the dispatch system, this
/// yields the globally minimum-total-distance matching across the group
/// — no two cars can be sent to the same hall call.
///
/// Two guards are applied on top of the raw distance, both via the
/// shared [`pair_is_useful`] predicate:
///
/// 1. The `(car, stop)` pair must be serviceable — at least one aboard
/// rider can exit, or at least one waiting rider can fit. A full car
/// at a pickup stop it cannot serve otherwise self-assigns at zero
/// cost (doors cycle open → reject → close forever).
/// 2. A car carrying riders refuses pickups that would pull it backward
/// (off the path to every aboard rider's destination). Without this,
/// a stream of closer-destination boarders can indefinitely preempt
/// a farther aboard rider's delivery — the reported "never reaches
/// the passenger's desired stop" loop.
;