关于「先到先用的代价:重置前耗尽与重置时作废」,《周期配额的路由与倒计时》给出的定量结论是什么?
结论:闲的那天,情形反过来。先到先用照样在第 8 个时段耗尽 H,因为它把 H 用在了大量例行任务上,12 个关键任务里只有 5 个用上 H,产出 482.0 点。固定路由一个关键任务都没落下,却在重置时剩下 48 个 H 单位作废。最有意思的是第三行:按常规预测解出的方案在闲日剩下 128 个单位作废,产出 561.0 点,反而不如固定路由的 579.0 点。原因不在线性规划,而在它用的需求预测:方案按常规日给复杂任务分配了 H 的份额,闲日的复杂任务没有那么多,多出来的 H 就躺在那里,一直躺到重置。用当天需求重新求解,产出 581.4 点,H 一个单位也不剩。
数据口径:示意参数下,线性规划相对先到先用多出 0.1668 到 0.2217,相对按复杂度分档的固定规则只多出 0.41 % 到 5.05 %,大头来自分档本身。 书中参数为示意,不含任何厂商的价格或配额;全部计算由书中程序生成。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 12, 128, 48, 482.0, 561.0, 579.0
| policy | day | points | H-out | H-left | F-left | crit-on-H |
|---|---|---|---|---|---|---|
| arrival | busy x1.2 | 887.4 | 4 | 0 | 39 | 4 |
| fixed | busy x1.2 | 1006.8 | 13 | 2 | 37 | 13 |
| LP plan | busy x1.2 | 1031.0 | 20 | 0 | 32 | 20 |
| LP re-plan | busy x1.2 | 1043.2 | none | 6 | 27 | 24 |
| arrival | quiet x0.6 | 482.0 | 8 | 0 | 551 | 5 |
| fixed | quiet x0.6 | 579.0 | none | 48 | 540 | 12 |
| LP plan | quiet x0.6 | 561.0 | none | 128 | 516 | 12 |
| LP re-plan | quiet x0.6 | 581.4 | 22 | 0 | 556 | 12 |
查看完整验算程序
# Chapter 1. p11: spending a periodic quota in arrival order, one cycle.
# Model: one reset cycle of 24 slots; tasks of four classes arrive in a
# seeded random order. Two tiers: H (heavy reasoning, quota 600 units)
# and F (fast, quota 900 units). Four policies:
# arrival - H while H quota lasts, then F (first come, first served)
# fixed - complex and critical to H, the rest to F; when the
# assigned tier is empty the task falls back to the other
# LP plan - per-class H counts from the p21 linear programme on the
# standing forecast (300, 150, 60, 20); the rest to F
# LP re-plan - the same programme solved on the day's own demand
# Output is in expected output points (value times success share).
# All quotas, costs and shares are illustrative, not vendor figures.
# Published analogue of waste at reset: in the last week of the fiscal
# year, federal procurement ran at 4.9 times the weekly mean (Liebman
# and Mahoney 2017); the chapter text cites it.
import math
import random
from fractions import Fraction as Fr
def simplex(c, A, b, rule="bland", cap=500):
m, n = len(A), len(c)
T = [[Fr(v) for v in A[i]] + [Fr(int(i == j)) for j in range(m)]
+ [Fr(b[i])] for i in range(m)]
z = [-Fr(v) for v in c] + [Fr(0)] * (m + 1)
basis = [n + i for i in range(m)]
steps = 0
while steps < cap:
cols = [j for j in range(n + m) if z[j] < 0]
if not cols:
break
if rule == "bland":
e = cols[0]
else:
e = min(cols, key=lambda j: (z[j], j))
rows = [i for i in range(m) if T[i][e] > 0]
if not rows:
return None
r = min(rows, key=lambda i: (T[i][-1] / T[i][e], basis[i]))
p = T[r][e]
T[r] = [v / p for v in T[r]]
for i in range(m):
if i != r and T[i][e] != 0:
f = T[i][e]
T[i] = [a - f * w for a, w in zip(T[i], T[r])]
f = z[e]
z = [a - f * w for a, w in zip(z, T[r])]
basis[r] = e
steps += 1
x = [Fr(0)] * (n + m)
for i, j in enumerate(basis):
x[j] = T[i][-1]
return x[:n], z[-1], z[n:n + m], steps
VALUE = (1, 2, 5, 10)
COST = {"H": (4, 6, 10, 16), "F": (1, 2, 3, 4)}
SUCC = {"H": (0.97, 0.95, 0.90, 0.85), "F": (0.95, 0.80, 0.45, 0.15)}
QUOTA = {"H": 600, "F": 900}
FORECAST = (300, 150, 60, 20)
def lp_plan(dem):
c = [VALUE[k] * Fr(str(SUCC[t][k])) for t in "HF" for k in range(4)]
A = [[COST["H"][k] if t == "H" else 0 for t in "HF" for k in range(4)],
[COST["F"][k] if t == "F" else 0 for t in "HF" for k in range(4)]]
b = [QUOTA["H"], QUOTA["F"]]
for k in range(4):
A.append([1 if j == k else 0 for t in "HF" for j in range(4)])
b.append(dem[k])
x = simplex(c, A, b)[0]
return [math.floor(x[k]) for k in range(4)]
def run(day, policy, rng):
tasks = [k for k in range(4) for _ in range(day[k])]
rng.shuffle(tasks)
left = dict(QUOTA)
plan = lp_plan(day if policy == "LP re-plan" else FORECAST)
pts, h_out, crit_h = [], None, 0
n = len(tasks)
for i, k in enumerate(tasks):
slot = i * 24 // n
if policy == "arrival":
order = "HF"
elif policy == "fixed":
order = "HF" if k >= 2 else "FH"
else:
order = "HF" if plan[k] > 0 else "F"
for t in order:
if left[t] >= COST[t][k]:
left[t] -= COST[t][k]
pts.append(VALUE[k] * SUCC[t][k])
if t == "H":
if policy.startswith("LP"):
plan[k] -= 1
if k == 3:
crit_h += 1
break
if h_out is None and left["H"] < 4:
h_out = slot
return math.fsum(pts), h_out, left["H"], left["F"], crit_h
DAYS = (("busy x1.2", (360, 180, 72, 24)),
("quiet x0.6", (180, 90, 36, 12)))
print("policy day points H-out H-left F-left crit-on-H")
for name, day in DAYS:
for policy in ("arrival", "fixed", "LP plan", "LP re-plan"):
rng = random.Random(20261113)
p, ho, lh, lf, ch = run(day, policy, rng)
hs = "none" if ho is None else "%d" % ho
print("%-10s %-10s %6.1f %5s %6d %6d %9d" % (
policy, name, p, hs, lh, lf, ch))唯一数据源与引用
范雅福(Fan, Y.). (2026). 《周期配额削峰填谷与跨模型路由、重置倒计时线性规划与重推理轻量模型算力分配母典》第 1 章「先到先用的代价:重置前耗尽与重置时作废」(版本 1.0.0). 5D Library. DOI 待发布
DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-270 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026270,
author = {Fan, Yafu},
title = {Peak-Shaving Periodic Quotas and Cross-Model Routing: Linear Programming against Reset Countdowns to Split Work between Heavy-Reasoning and Fast Models},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}