难题与启发式回答
Hard Problems and Heuristic Answers

原始链接: https://stochastic.blog/hard-problems-and-heuristic-answers/

这篇文章探讨了计算上易解的问题与本质上“困难”的问题之间的界限,并特别聚焦于旅行商问题(TSP)。作者利用 OpenFlights 数据集构建了一个包含 12 个机场的 TSP 实例,以说明在数以千计的可能性中寻找最优路径所面临的挑战。 文中区分了精确解与启发式算法,解释了当问题无法进行高效计算时,我们必须以牺牲最优性来换取速度。通过审视 P 对 NP、多项式归约以及 SAT 求解器等概念,作者展示了指数级增长为何使得某些问题在大规模下无法实现完美求解。 通过蒙特卡洛模拟和快速排序等随机算法的具体示例,文章凸显了这些“困难”问题的本质。最终,这项工作强调了我们能证明的内容与能计算的内容之间的差距,并非技术的缺失,而是计算复杂性的一项基本属性。其目标在于超越简单的优化,学习如何通过严谨的方法和实用的近似手段来应对这一现实。

Hacker News 最新 | 往日 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 难题与启发式答案 (stochastic.blog) 5 分,由 Anon84 发布于 1 小时前 | 隐藏 | 往日 | 收藏 | 讨论 | 帮助 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 加入 YC | 联系 搜索:
相关文章

原文

In Post 8 we built the optimization toolkit that turns a problem into a solvable form, learning how gradients and convexity give us a path to good answers. Now we face the harder truth: some problems resist every clever trick we know, and the only honest response is to understand exactly how hard they are, then reach for methods that trade certainty for speed. By the end of this post we will have solved a 12-airport traveling salesman problem (find the shortest round trip visiting every airport once) exactly at 62,741 km, then watched three different heuristics (approximate methods that trade guaranteed optimality for speed) chase that number with varying success, and we will understand why the gap between them is not a failure but the very nature of hard problems.

The OpenFlights dataset gives us the raw material: about 7,700 airports and 67,000 routes in roughly 2 MB of CSV files. We build a graph from the routes, compute great-circle distances between airports, and construct a small but real traveling salesman problem that spans six continents. The through-line of this post is the gap between what we can prove and what we can compute, and how every method we meet is really a different way of negotiating that gap.

The data

Before any solver touches a tour, we need to know what we are working with. The route graph has 3,425 nodes and 19,256 edges after we drop duplicates and self-loops, and the degree (number of direct connections) distribution shows the pattern immediately.

Airport route degree distribution

Figure 2. Degree distribution has a heavy tail: a few hubs have enormous degree, while most airports connect to only a handful of destinations.

The log-log plot shows a heavy tail: a few hubs like LHR and JFK carry enormous degree while most airports connect to only a handful of destinations. The hub base rate, defined as airports with degree at least 10, sits at 21.9 percent. This is the structure that makes a geographically spread TSP meaningful, because the giant component holds 3,397 of our 3,425 airports, so a tour across major cities stays within one connected world.

The bar chart confirms the imbalance: hubs are a minority, yet they dominate connectivity.

Hub status distribution

Figure 1. Hubs are a small minority of airports but dominate connectivity.

For our purposes this matters because a 12-airport sample drawn from major international hubs will have realistic distances and a genuine optimization problem. We also found 1,625 duplicate IATA rows and one self-loop, which we collapse before building the tour instance. The data is messy enough to be real, clean enough to work with.

Hardness and randomness

With the graph built, the first module confronts the wall between answers we can check and answers we can find. P vs NP asks whether every problem whose answer we can check quickly also has a solution we can find quickly, and for the problems in this post we accept the consensus answer: no. Polynomial reductions let us convert one hard problem into another, and we demonstrate this with a five-node graph where the minimum vertex cover (a set of nodes that touches every edge) is the set {0, 1, 3} of size 3. The complement of that cover, {2, 4}, is automatically an independent set (a set of nodes with no edges between them), and we verify that no edge connects the two nodes. This is the reduction in miniature: solve one problem, get the other for free.

SAT (Boolean satisfiability: can a formula's clauses all be made true by some assignment) is the canonical NP-complete (the hardest class of NP problems; a fast method for one would fast-solve all of them) problem, and we brute-force a three-variable instance with clauses (1, -2), (2, 3), (-1, -3). The satisfying assignment comes back as {1: True, 2: True, 3: False}, found by checking all eight possible assignments. At three variables this is instant, but the exponential growth is the whole point.

The Traveling Salesman Problem is our running example, and we build a 12-airport instance with a mean pairwise distance of 9,600 km. Monte Carlo algorithms estimate by random sampling, so we draw 2,000 random tours and watch the distribution: the mean lands at 115,019 km, the best random tour at 75,277 km. Random tours almost never respect geography, which is why the mean sits so far above any sensible route. Las Vegas algorithms use randomness but always return a correct answer, and our randomized quicksort on the airport coordinates proves the point: the output is always sorted, only the runtime varies.

联系我们 contact @ memedata.com