What does Buyer Shopping Routes and Time Windows conclude, in numbers, about “Closing the Loop: the Shopping Route Planner and a Pre-Registered Test Plan”?
Answer: Chapter 8 gives the buyer-day procedure, the Shopping Route Planner and a pre-registered test plan: the distance test needs about 37 buyer days and the clock test about 55 days per group. Marked boxes separate published evidence, runnable Python calculations (19 programs), classical sources and the author's hypotheses.
Scope of the numbers: Chapter 7 examines Shen Kuo's account of Ding Wei's "one move, three jobs" (an illustrative account saves 0.826) and Euler's seven bridges. Marked boxes separate published evidence, runnable Python calculations (19 programs), classical sources and the author's hypotheses.
Data table
The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. standard-library Python onlyprinted values that match the answer: 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 |
Show the full program
# 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)))Single source and citation
Fan, Y. (2026). Two-Opt Travelling-Salesman Search and Vehicle Routing with Time Windows: Shortest Shopping Loops in Tokyo, Osaka and Seoul under Counter Opening Hours (Version 1.0.0), Chapter 8: Closing the Loop: the Shopping Route Planner and a Pre-Registered Test Plan. 5D Library. DOI pending
DOI pending · monograph page goes live after publication · 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}
}Other chapter answers in this book
- Chapter 1 · The Price of Nearest First: How Much Longer than the Shortest Loop
- Chapter 2 · Croes's Pairwise Exchange: Reversing a Stretch, Crossings and Local Optima
- Chapter 3 · Segment Moves and One-Way Streets: the Or-opt Neighbourhood and Asymmetric Travel
- Chapter 4 · Held-Karp Dynamic Programming: Exact Solutions, State Counts and "Above the Bound"
- Chapter 5 · The Counters' Clocks: Time-Window Feasibility and the Day with the Most Items
- Chapter 6 · Two Buyers and Random Queues: Vehicle Routing with Time Windows and Planning Slack
- Chapter 7 · Classical Sources East and West: Ding Wei's "One Move, Three Jobs" and Euler's Seven Bridges