关于「实证闭环:扫货路线规划器与预注册检验方案」,《买手扫货路线与时间窗》给出的定量结论是什么?

结论:第八章给出买手日流程、扫货路线规划器与预注册检验方案:距离检验约需 37 个买手日,时钟检验每组约需 55 天。书中以标注框区分已发表的证据、可运行的 Python 计算(19 段程序)、原典与作者的假说。

数据口径:书中的坐标、专柜、营业时段、排队时长与限购件数均为示意,不对应任何真实店铺;全部计算由书中程序生成;本书是非个人化经营建议,跨境所购物品须按各地海关规定如实申报并遵守限购规定,书中不讨论任何规避做法。 第五章是全书的转折:示意东京日上,20.99 公里的最短闭环只买到 12 件,件数最多的方案多走 0.32 公里就买齐 15 件;随机日上,把最近邻换成最短闭环每天只多买 0.03 件,按时间窗排序多买 2.93 件。

English version

对照数据表

下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 19, 37, 55

simulated: mean NN excess over 2-opt 0.075 (sd 0.073)
simulated: items plan 14.55, habit 11.13 (pooled sd 1.86)
test 1: H0 mean excess <= 0.05, one-sided alpha 0.05
true excess 0.07, power 0.8:83 logged days
true excess 0.07, power 0.9:115 logged days
true excess 0.08, power 0.8:37 logged days
true excess 0.08, power 0.9:51 logged days
true excess 0.09, power 0.8:21 logged days
true excess 0.09, power 0.9:29 logged days
test 2: items per day, plan vs habit, two-sided alpha 0.05
difference 0.5 items, power 0.8:217 days per arm
difference 0.5 items, power 0.9:291 days per arm
difference 1.0 items, power 0.8:55 days per arm
difference 1.0 items, power 0.9:73 days per arm
difference 2.0 items, power 0.8:14 days per arm
difference 2.0 items, power 0.9:19 days per arm
查看完整验算程序
# Chapter 8. p82: sample sizes for the pre-registered tests.
# Test 1 (distance): on logged buyer days, is the nearest-first loop at
# least 5 % longer than the 2-opt local optimum on the same counters?
# One-sided one-sample test on the per-day excess. Test 2 (clock): days
# randomised between the window-aware plan and the habit of following
# the shortest loop; outcome items per day; two-sided two-sample test.
# Standard deviations are taken from 120 simulated days (fixed seed,
# same illustrative generator as p53); alpha 0.05, power 0.8 and 0.9.
import math
import random
import statistics

RNG = random.Random(20261122)
DAY_START, DAY_END = 570, 1260
Z = statistics.NormalDist()


def make_day(n=10):
    p = [(4.0, 3.0)] + [(RNG.uniform(0, 8), RNG.uniform(0, 6))
                        for _ in range(n)]
    win = [None]
    for _ in range(n):
        e = RNG.choice((600, 630, 660, 690, 720))
        u = RNG.random()
        last = (e + 60 if u < 0.2 else RNG.choice((900, 960, 1020))
                if u < 0.35 else RNG.choice((1080, 1110, 1140, 1170)))
        win.append((e, last, RNG.randint(20, 60), RNG.choice((1, 2))))
    km = [[math.hypot(a[0] - b[0], a[1] - b[1]) for b in p] for a in p]
    tt = [[0.0 if i == j else 8 + 4 * km[i][j] for j in range(n + 1)]
          for i in range(n + 1)]
    return km, tt, win


def loop_len(t, d):
    return math.fsum(d[t[i - 1]][t[i]] for i in range(len(t)))


def nearest(d):
    t, left = [0], list(range(1, len(d)))
    while left:
        j = min(left, key=lambda k: (d[t[-1]][k], k))
        t.append(j)
        left.remove(j)
    return t


def two_opt(t, d):
    t, n = t[:], len(t)
    improved = True
    while improved:
        improved = False
        for i in range(n - 1):
            for k in range(i + 2, n if i else n - 1):
                a, b, c, e = t[i], t[i + 1], t[k], t[(k + 1) % n]
                if d[a][b] + d[c][e] - d[a][c] - d[b][e] > 1e-12:
                    t[i + 1:k + 1] = reversed(t[i + 1:k + 1])
                    improved = True
    return t


def follow(order, tt, win):
    t, cur, items = DAY_START, 0, 0
    for j in order:
        e, last, s, q = win[j]
        st = max(t + tt[cur][j], e)
        if st > last or st + s + tt[j][0] > DAY_END:
            continue
        t, cur = st + s, j
        items += q  # step
    return items


def best_items(tt, win):
    n, inf, top = len(win) - 1, float("inf"), 0
    f = [[inf] * (n + 1) for _ in range(1 << (n + 1))]
    for j in range(1, n + 1):
        st = max(DAY_START + tt[0][j], win[j][0])
        if st <= win[j][1]:
            f[1 << j][j] = st + win[j][2]
    for m in range(2, 1 << (n + 1), 2):
        for j in range(1, n + 1):
            t = f[m][j]
            if t == inf:
                continue
            if t + tt[j][0] <= DAY_END:
                items = 0
                for k in range(1, n + 1):
                    if (m >> k) & 1:
                        items += win[k][3]  # step
                top = max(top, items)
            for k in range(1, n + 1):
                st = max(t + tt[j][k], win[k][0])
                if (not (m >> k) & 1 and st <= win[k][1]
                        and st + win[k][2] < f[m | 1 << k][k]):
                    f[m | 1 << k][k] = st + win[k][2]
    return top


excess, plan_items, habit_items = [], [], []
for _ in range(120):
    km, tt, win = make_day()
    nn = nearest(km)
    excess.append(loop_len(nn, km) / loop_len(two_opt(nn, km), km) - 1)
    plan_items.append(best_items(tt, win))
    habit_items.append(follow(two_opt(nn, km)[1:], tt, win))
sd_e = statistics.stdev(excess)
sd_i = math.sqrt((statistics.variance(plan_items)
                 + statistics.variance(habit_items)) / 2)
print("simulated: mean NN excess over 2-opt %.3f (sd %.3f)" % (
    statistics.fmean(excess), sd_e))
print("simulated: items plan %.2f, habit %.2f (pooled sd %.2f)" % (
    statistics.fmean(plan_items), statistics.fmean(habit_items), sd_i))
print("test 1: H0 mean excess <= 0.05, one-sided alpha 0.05")
for true in (0.07, 0.08, 0.09):
    for pw in (0.8, 0.9):
        n = ((Z.inv_cdf(0.95) + Z.inv_cdf(pw)) * sd_e / (true - 0.05)) ** 2
        print("  true excess %.2f, power %.1f: %4d logged days" % (
            true, pw, math.ceil(n)))
print("test 2: items per day, plan vs habit, two-sided alpha 0.05")
for delta in (0.5, 1.0, 2.0):
    for pw in (0.8, 0.9):
        n = 2 * ((Z.inv_cdf(0.975) + Z.inv_cdf(pw)) * sd_i / delta) ** 2
        print("  difference %.1f items, power %.1f: %4d days per arm" % (
            delta, pw, math.ceil(n)))

唯一数据源与引用

范雅福(Fan, Y.). (2026). 《旅行商二元交换与时间窗车辆路径、东京大阪首尔扫货路线最短闭环与专柜开门时间窗母典》第 8 章「实证闭环:扫货路线规划器与预注册检验方案」(版本 1.0.0). 5D Library. DOI 待发布

DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-298 · v1.0.0 · CC-BY-NC-ND-4.0

BibTeX
@book{fan2026298,
  author    = {Fan, Yafu},
  title     = {Two-Opt Travelling-Salesman Search and Vehicle Routing with Time Windows: Shortest Shopping Loops in Tokyo, Osaka and Seoul under Counter Opening Hours},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  note      = {DOI pending}
}

本书其他章节结论