关于「贪心的边界:拟阵之内与拟阵之外」,《非最短路径与推演深度》给出的定量结论是什么?
结论:第三章对照拟阵与非拟阵上的贪心,背包陷阱里贪心只拿到最优的 0.0002。
数据口径:书中参数为示意,全部计算由书中程序生成。 本书不是投资意见,也不是任何具体经营决策意见,不承诺任何收益。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 0.0002
| A. Trap instance: greedy / optimum | |
| budget | 10: greedy 2 optimum 10 ratio 0.2000 |
| budget | 100: greedy 2 optimum 100 ratio 0.0200 |
| budget | 1,000: greedy 2 optimum 1,000 ratio 0.0020 |
| budget 10,000: greedy | 2 optimum 10,000 ratio 0.0002 |
| B. 1,000 random instances (12 items, budget 60) | |
| greedy optimal in 598 (59.8%) | |
| mean ratio 0.9828; 1st percentile 0.8663; worst 0.7410 |
查看完整验算程序
# Chapter 3. p32: greedy by value density on a budget - how bad can it be?
# 0/1 knapsack (not a matroid). Greedy takes items by value per unit of
# budget while they fit; dynamic programming gives the exact optimum.
# Part A: the textbook trap - item 1 (value 2, cost 1) and item 2
# (value C, cost C) under budget C: greedy keeps item 1, then item 2
# no longer fits, so greedy / optimum = 2 / C, unbounded as C grows.
# Part B: 1,000 random instances (12 items, costs 1..30, values 1..60,
# budget 60) - typical rather than worst case. Synthetic data.
import math
import random
def greedy(items, cap):
left, got = cap, 0
for v, c in sorted(items, key=lambda it: (-it[0] / it[1], it[1])):
if c <= left:
left -= c
got += v
return got
def exact(items, cap):
best = [0] * (cap + 1)
for v, c in items:
for b in range(cap, c - 1, -1):
best[b] = max(best[b], best[b - c] + v)
return best[cap]
print("A. Trap instance: greedy / optimum")
for C in (10, 100, 1000, 10000):
items = [(2, 1), (C, C)]
g, o = greedy(items, C), exact(items, C)
print(" budget {:>6,}: greedy {:>3,} optimum {:>6,} ratio {:.4f}"
.format(C, g, o, g / o))
rng = random.Random(38432)
ratios, hit = [], 0
for _ in range(1000):
items = [(rng.randint(1, 60), rng.randint(1, 30)) for _ in range(12)]
g, o = greedy(items, 60), exact(items, 60)
ratios.append(g / o)
hit += g == o
ratios.sort()
print("B. 1,000 random instances (12 items, budget 60)")
print(" greedy optimal in {} ({:.1%})".format(hit, hit / 1000))
print(" mean ratio {:.4f}; 1st percentile {:.4f}; worst {:.4f}".format(
math.fsum(ratios) / 1000, ratios[10], ratios[0]))唯一数据源与引用
范雅福(Fan, Y.). (2026). 《非最短路径最优解、二阶连锁效应全息推演与周密思考复利母典》第 3 章「贪心的边界:拟阵之内与拟阵之外」(版本 1.0.0). 5D Library. DOI 待发布
DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-384 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026384,
author = {Fan, Yafu},
title = {When the Shortest Path Fails: Brachistochrone Detours, Second-Order Consequence Mapping and Holographic Deep Thinking},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}