先说明。 本文中出现的仓库并不真实存在。我们汇集了小型物流仓库实际运转的方式构成了它。品目和货架坐标是编的,代码、画面和日志是实际跑过的。
订单是客人放进购物车的顺序。仓库是货架摆放的顺序。
这两者毫无关系。 可大多数拣货清单就照订单顺序打印出来。于是人跑到 1 号通道,再跑到 4 号通道,再折回 1 号通道。
不主张,去量
「排个序就快了」谁都会说。这个样例把两条路线都算出来,一起摆到画面上。

as typed 106 steps · walking order 82 steps · saved 24 steps
按订单走是 106 步,按货架顺序走是 82 步。一张五行的订单就拉开了 24 步。
步数的计算是故意做得粗糙的。
/// Crude on purpose: moving along an aisle costs one per bay, and changing
/// aisle costs the walk to the end and back. It does not need to be a real
/// floor plan to show that the two sequences are not the same length.
哪怕不是真实的仓库平面图,「两个顺序的长度不一样」这件事也看得见。那就是这一篇主张的全部;再多主张就需要平面图了。
排序不是数据
订单里不该有「顺序」这个字段。顺序是从位置里生出来的,不是被送进来的。
/// The same lines, in the sequence a person actually walks.
List<Line> get _walkOrder => List.of(_lines)
..sort((a, b) {
final byAisle = a.slot.aisle.compareTo(b.slot.aisle);
if (byAisle != 0) return byAisle;
return a.slot.bay.compareTo(b.slot.bay);
});
东西被挪到别的货架,从下一次拣货开始顺序就自己变了。要是顺序被存了下来,就得有人把它们全部重算,而因为没人去做,清单就一点点错下去。
验证会确认那个顺序。
slots = [r["slot"] for r in start["rows"]]
assert slots == sorted(slots), "the route must be in walking order"
而且测试装置自己也检查排序。
final sorted = List.of(slots)..sort();
expect(slots, sorted, reason: 'the route must be in walking order');
省下的步数不能出现在源码里
24 这个数字是从哪来的,就是这篇文章全部的可信度。 所以只要源码里有这个数字,验证就失败。
src = open(os.path.join(SERVER, "bin", "server.dart")).read()
assert str(start["saved"]).split()[0] not in src, "the saving must be computed, never stored"
walking order saved 24 steps, and that number is nowhere in the source
这个检查最早出现在可以追问的记录。画面上的数值如果在源码里被写成字符串,那它不是计算,是画上去的。