# 局部搜索（优化）

局部搜索是一种优化方法，它反复地从当前候选解移动到邻域解；在迭代改进变体中，移动必须改善目标值，搜索停在局部最优处，而其他变体也可能接受变差的移动，或在步骤或时间预算耗尽时停止。它是求解NP难组合优化问题的一种启发式方法，其中假定P ≠ NP，没有任何算法能保证在多项式时间内返回最优解，它以解质量换取计算时间。<sup>[1](https://link.springer.com/rwe/10.1007/978-3-032-00385-0_6)</sup> 由于它只在小范围局部邻域中移动并使用局部知识，它通常是不完备的：不保证能找到存在的解，而解不存在这一事实也永远无法确定。<sup>[2](https://www.cs.ubc.ca/~hoos/SLS-Internal/ch1.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 输出 | 相对于所选邻域局部最优的解，不一定是全局最优<sup>[3](https://homes.di.unimi.it/cordone/courses/2026-ae/Lez13-Materiali/LocalSearchTemplate.pdf)</sup> |
| 典型邻域 | k-交换邻域，解之间至多在k个分量上不同；TSP的2-opt邻域大小为\( \Theta(|s|^{2}) \)<sup>[2](https://www.cs.ubc.ca/~hoos/SLS-Internal/ch1.pdf)</sup><sup> • </sup><sup>[4](https://link.springer.com/chapter/10.1007/978-3-031-13714-3_5)</sup> |
| 完备性 | 不完备：无法证明最优性，也无法证明解不存在<sup>[2](https://www.cs.ubc.ca/~hoos/SLS-Internal/ch1.pdf)</sup> |
| 枢轴规则 | 首次改进在找到第一个改进邻域解时移动；最佳改进扫描整个邻域并取最优者<sup>[4](https://link.springer.com/chapter/10.1007/978-3-031-13714-3_5)</sup> |
| 复杂性地位 | 对FLIP和Kernighan-Lin图划分，寻找局部最优是PLS完全的<sup>[5](https://www.karlin.mff.cuni.cz/~krajicek/jpy2.pdf)</sup> |
| 解质量 | 迭代Lin-Kernighan对多达1,000,000个城市的TSP实例得到的解与最优值的差距在0.5%以内<sup>[6](https://api.pageplace.de/preview/DT0400.9780691187563_A33704901/preview-9780691187563_A33704901.pdf)</sup> |
| 近期发展 | BTBS-LNS等学习型LNS在MIPLIB2017上以300秒截止时间报告的原始间隙比Gurobi（v9.5.0）好10%<sup>[7](https://proceedings.iclr.cc/paper_files/paper/2025/file/7eca17ef54789b0663cab421f2e9dbf5-Paper-Conference.pdf)</sup> |

## 工作原理

一个优化实例是一对\( (S, f) \)，其中解空间为\( S \)，代价函数为\( f: S \to \mathbb{R} \)。邻域函数\( N: S \to \mathcal{P}(S) \)为每个解\( s \)指定一个邻域解集合\( N(s) \)，若对所有\( t \in N(s) \)都有\( f(s) \le f(t) \)，则\( s \)是关于\( N \)的局部极小。<sup>[3](https://homes.di.unimi.it/cordone/courses/2026-ae/Lez13-Materiali/LocalSearchTemplate.pdf)</sup> 局部最优性总是相对于特定邻域定义的：2-最优的TSP巡回不必是3-最优的。<sup>[4](https://link.springer.com/chapter/10.1007/978-3-031-13714-3_5)</sup>

最广泛使用的邻域关系是k-交换邻域，其中两个候选解若至多在k个解分量上不同则为邻域解。<sup>[2](https://www.cs.ubc.ca/~hoos/SLS-Internal/ch1.pdf)</sup> 对TSP，2-opt（2-交换）邻域用两条新边替换两条旧边，大小为\( \Theta(|s|^{2}) \)；验证3-opt最优性需\( O(n^{3}) \)，这使无限制3-opt局限于相对较小的实例。<sup>[4](https://link.springer.com/chapter/10.1007/978-3-031-13714-3_5)</sup> 对SAT，搜索空间是真值赋值的集合，随变量数指数增长，大多数算法使用1-翻转邻域，目标函数计算未满足子句数。<sup>[8](https://www.cs.ubc.ca/~hoos/Publ/jar00.pdf)</sup>

## 如何执行

典型算法是确定性迭代改进（也称迭代下降，最大化时称爬山），它从初始解出发，反复搜索其邻域中质量更好的解，在第一个局部最优处终止，其质量可能任意差。<sup>[2](https://www.cs.ubc.ca/~hoos/SLS-Internal/ch1.pdf)</sup><sup> • </sup><sup>[3](https://homes.di.unimi.it/cordone/courses/2026-ae/Lez13-Materiali/LocalSearchTemplate.pdf)</sup> 实践者需做四个决定：

1. **初始化**，来自随机或贪心构造；多起点从不同初始解重跑过程。<sup>[3](https://homes.di.unimi.it/cordone/courses/2026-ae/Lez13-Materiali/LocalSearchTemplate.pdf)</sup>
2. **邻域生成与评估**。首次改进策略下，一旦发现改进移动就改变当前解；最佳改进（最陡下降）下，检查整个邻域并接受最佳邻域解。<sup>[4](https://link.springer.com/chapter/10.1007/978-3-031-13714-3_5)</sup>
3. **移动接受**，区分下文所述各变体。
4. **终止**，当不存在改进邻域解或步骤或时间预算耗尽时。<sup>[2](https://www.cs.ubc.ca/~hoos/SLS-Internal/ch1.pdf)</sup>

实现选择与枢轴规则同样重要。邻域缩减技术包括候选列表、忽略长于平均行程长度\( \beta \)倍（\( \beta \)略大于1）的边的粒度搜索，以及对TSP只将每个城市与其最近的p个邻域城市相连，这将2-opt邻域从\( n^{2} \)缩小到\( n \cdot p^{2} \)，质量损失往往可忽略。<sup>[4](https://link.springer.com/chapter/10.1007/978-3-031-13714-3_5)</sup> 在SAT求解器中，几乎所有随机局部搜索算法每步恰好翻转一个变量，并使用周期性重启。<sup>[9](https://cs.uwaterloo.ca/~dtompkin/papers/sat04proc-ubcsat.pdf)</sup>

首次改进与最佳改进的选择没有普遍答案。在非常大的工业MAXSAT问题上，用最佳改进移动找到的首个局部最优在统计上显著优于首次改进移动找到的，但随着搜索继续这一优势反转，且由于定位最佳改进移动更昂贵，已设计出近似最佳改进算法并证明其与首次改进搜索一样高效。<sup>[10](https://dl.acm.org/doi/10.5555/2891460.2891591)</sup> 2025年EJOR的一项计算研究得出结论，一般情形下似乎不存在识别最佳枢轴策略的经验法则。<sup>[11](https://ideas.repec.org/a/eee/ejores/v326y2025i3p413-426.html)</sup>

## 起源

历史综述描述了运输问题的一种局部搜索方法，基于船舶的循环改道，其结果在二战期间获得，但直到战时限制结束后才发表。<sup>[12](https://homepages.cwi.nl/~lex/files/histco.pdf)</sup> 有更充分记载的脉络始于1950年代末和1960年代初TSP的边交换启发式。<sup>[6](https://api.pageplace.de/preview/DT0400.9780691187563_A33704901/preview-9780691187563_A33704901.pdf)</sup> G. A. Croes于1958年在《运筹学》上引入2-opt边交换启发式<sup>[13](https://doi.org/10.1287/opre.6.6.791)</sup>，[Shen Lin](https://www.edgepedia.org/zh/shen-lin)于1965年在《贝尔系统技术杂志》上给出TSP的计算机解。<sup>[14](https://doi.org/10.1002/j.1538-7305.1965.tb04146.x)</sup> 交换策略随后传播到图划分，见于B. W. Kernighan和S. Lin 1970年《贝尔系统技术杂志》的程序。<sup>[15](https://doi.org/10.1002/j.1538-7305.1970.tb01770.x)</sup> 1973年，S. Lin和B. W. Kernighan在《运筹学》上发表了以他们名字命名的变深度启发式<sup>[16](https://doi.org/10.1287/opre.21.2.498)</sup>：它依次确定k对要交换的链路，当增益准则\( G^{*} \)不为正时终止。<sup>[16](https://doi.org/10.1287/opre.21.2.498)</sup> 多项式时间局部搜索的复杂性类PLS由[David S. Johnson](https://www.edgepedia.org/zh/david-s-johnson)、Christos H. Papadimitriou和[Mihalis Yannakakis](https://www.edgepedia.org/zh/mihalis-yannakakis)在1988年《计算机与系统科学杂志》的论文“局部搜索有多容易？”中定义。<sup>[5](https://www.karlin.mff.cuni.cz/~krajicek/jpy2.pdf)</sup>

## 变体

所有主要变体都以不同接受规则实例化同一循环；已证明单一模板可涵盖迭代改进、模拟退火、阈值接受、禁忌搜索和遗传算法。<sup>[3](https://homes.di.unimi.it/cordone/courses/2026-ae/Lez13-Materiali/LocalSearchTemplate.pdf)</sup>

- **模拟退火**，由S. Kirkpatrick、C. D. Gelatt和M. P. Vecchi于1983年在《科学》上发表<sup>[17](https://doi.org/10.1126/science.220.4598.671)</sup>，以概率\( e^{-k/T} \)在温度T下接受量为k的变差步骤。<sup>[18](https://artint.info/3e/html/ArtInt3e.Ch4.S6.html)</sup> 在温和条件下，模拟退火保证渐近找到最优解。<sup>[19](https://pure.tue.nl/ws/files/4282236/9410744.pdf)</sup> 阈值接受是确定性对应物，接受低于非负阈值的变差移动，阈值在运行中递减。<sup>[3](https://homes.di.unimi.it/cordone/courses/2026-ae/Lez13-Materiali/LocalSearchTemplate.pdf)</sup>
- **禁忌搜索**，由Fred Glover于1986年提出<sup>[20](https://doi.org/10.1016/0305-0548%2886%2990048-1)</sup>，将迭代改进与接受增成本解相结合，使用有限禁忌表记录移动，在禁忌任期内不得逆转近期变化； aspiration准则撤销禁忌，最常见于某移动产生优于已知最佳的解时。<sup>[3](https://homes.di.unimi.it/cordone/courses/2026-ae/Lez13-Materiali/LocalSearchTemplate.pdf)</sup><sup> • </sup><sup>[21](https://sci2s.ugr.es/sites/default/files/files/Teaching/OtherPostGraduateCourses/Metaheuristicas/TabuSearch.pdf)</sup>
- **变邻域搜索**，由N. Mladenović和P. Hansen于1997年在《计算机与运筹学》上发表<sup>[22](https://doi.org/10.1016/s0305-0548%2897%2900031-2)</sup>，利用一个邻域的局部极小不必是另一邻域的局部极小；其K个邻域参数化使得\( |N_{1}(s)| \le |N_{2}(s)| \le \cdots \le |N_{K}(s)| \)。<sup>[23](https://optimization-online.org/wp-content/uploads/2008/04/1954.pdf)</sup>
- **迭代局部搜索**，由Helena Ramalhinho Dias Lourenço、Olivier C. Martin和Thomas Stutzle于2001年框架化<sup>[24](https://doi.org/10.2139/ssrn.273397)</sup>，扰动局部最优并重新优化；同一思想以多个其他名称被重新发现。<sup>[23](https://optimization-online.org/wp-content/uploads/2008/04/1954.pdf)</sup>
- **大邻域搜索**通过破坏方法（移除部分解）和修复方法（重建解）隐式定义邻域<sup>[25](https://proceedings.neurips.cc/paper_files/paper/2020/file/e769e03a9d329b2e864b4bf4ff54ff39-Paper.pdf)</sup>；带时间窗取送货的[自适应大邻域搜索](https://www.edgepedia.org/zh/adaptive-large-neighborhood-search)由Stefan Ropke和David Pisinger于2006年在《运输科学》上发表。<sup>[26](https://doi.org/10.1287/trsc.1050.0135)</sup> **局部分支**由Matteo Fischetti和Andrea Lodi于2003年在《数学规划》上发表。<sup>[27](https://doi.org/10.1007/s10107-003-0395-5)</sup>

## 应用

**TSP与路径规划。** 二交换和三交换算法所得解与最优值的差距在某个百分比以内，变深度Lin-Kernighan搜索将差距缩小到2%以内，迭代Lin-Kernighan过程对多达1,000,000个城市的实例找到与最优值差距在0.5%以内的解。<sup>[6](https://api.pageplace.de/preview/DT0400.9780691187563_A33704901/preview-9780691187563_A33704901.pdf)</sup> 迭代Lin-Kernighan算法被描述为可能是对称TSP现存最有效的近似算法。<sup>[3](https://homes.di.unimi.it/cordone/courses/2026-ae/Lez13-Materiali/LocalSearchTemplate.pdf)</sup>

**SAT求解。** GSAT由Selman、Levesque和Mitchell于1992年引入，通过对变量赋值的贪心下降最小化未满足子句数；WalkSAT架构基于Selman、Kautz和Cohen于1994年首次发表的思想，并由McAllester、Selman和Kautz于1997年正式定义为框架。<sup>[8](https://www.cs.ubc.ca/~hoos/Publ/jar00.pdf)</sup>

**调度与MILP。** [作业车间调度](https://www.edgepedia.org/zh/job-shop-scheduling)的局部搜索已在标准实例上跨迭代改进、模拟退火、禁忌搜索和遗传算法进行了综述。<sup>[19](https://pure.tue.nl/ws/files/4282236/9410744.pdf)</sup> 对混合整数规划，学习型LNS框架选择变量子集用商业求解器重新优化<sup>[25](https://proceedings.neurips.cc/paper_files/paper/2020/file/e769e03a9d329b2e864b4bf4ff54ff39-Paper.pdf)</sup>；BTBS-LNS在MIPLIB2017上以300秒截止时间报告的原始间隙比Gurobi（v9.5.0）好10%<sup>[7](https://proceedings.iclr.cc/paper_files/paper/2025/file/7eca17ef54789b0663cab421f2e9dbf5-Paper-Conference.pdf)</sup>，LLM-LNS使用双层自进化LLM代理自动化大规模MILP的邻域选择。<sup>[28](https://proceedings.mlr.press/v267/ye25j.html)</sup>

## 局限与替代方法

主要缺点是陷困：局部搜索停滞在所有附近解都不更好的局部最优处，而搜索空间其他部分显著更好。<sup>[29](https://backend.orbit.dtu.dk/ws/files/288231618/Escaping_Local_Optima_With_Local_Search_A_Theory_Driven_Discussion.pdf)</sup> 平台——相邻解值相等的集合——加剧了问题；由min(max(...))构造的目标函数产生许多平台，其解都是局部最优。<sup>[4](https://link.springer.com/chapter/10.1007/978-3-031-13714-3_5)</sup> 在TSP的2-改变邻域中，连续改进序列可指数长<sup>[5](https://www.karlin.mff.cuni.cz/~krajicek/jpy2.pdf)</sup>，且2-opt在某些实例和初始巡回上可在停止前做\( \Theta(2^{N/2}) \)次移动。<sup>[30](https://www.csc.kth.se/utbildning/kth/kurser/DD2440/avalg14/TSP-JohMcg97.pdf)</sup>

由Johnson、Papadimitriou和Yannakakis定义的类PLS包含带有多项式时间过程的局部搜索问题：构造初始解、评估解成本、存在改进邻域解时返回它，从而局部最优性可在多项式时间内验证，它有完全问题：FLIP是PLS完全的，寻找对Kernighan-Lin过程局部最优的图划分是PLS完全的。<sup>[5](https://www.karlin.mff.cuni.cz/~krajicek/jpy2.pdf)</sup> 若FP ≠ PLS，则不存在多项式时间算法（即使非局部）能在一般适应度景观中找到局部峰值。<sup>[31](https://drops.dagstuhl.de/storage/00lipics/lipics-vol364-stacs2026/LIPIcs.STACS.2026.59/LIPIcs.STACS.2026.59.pdf)</sup>

逃逸机制相互权衡。每次运行以概率p成功的随机算法在n次独立运行后以概率\( 1-(1-p)^{n} \)找到解。<sup>[18](https://artint.info/3e/html/ArtInt3e.Ch4.S6.html)</sup> 理论驱动分析比较重启与变邻域搜索中更大搜索半径：若全局最优的吸引盆大，重启有益且优于更大搜索半径，且不存在普遍最佳的逃逸策略。<sup>[29](https://backend.orbit.dtu.dk/ws/files/288231618/Escaping_Local_Optima_With_Local_Search_A_Theory_Driven_Discussion.pdf)</sup>

与分支定界等精确方法相比，局部搜索以解质量换取计算时间；对NP难组合优化问题，不能期望有保证返回最优解的多项式时间算法。<sup>[1](https://link.springer.com/rwe/10.1007/978-3-032-00385-0_6)</sup> 遗传算法等基于种群的方法同时维护多个解而非一条轨迹。<sup>[3](https://homes.di.unimi.it/cordone/courses/2026-ae/Lez13-Materiali/LocalSearchTemplate.pdf)</sup>

## References

1. [Theory of Local Search (Michiels, Aarts & Korst, Handbook of Heuristics, first online 17 October 2025)](https://link.springer.com/rwe/10.1007/978-3-032-00385-0_6)
2. [Stochastic Local Search: Foundations and Applications, Chapter 1 (Hoos & Stützle)](https://www.cs.ubc.ca/~hoos/SLS-Internal/ch1.pdf)
3. [A template capturing the common features of local search algorithms (Computers & Operations Research, PII S0305054897000932)](https://homes.di.unimi.it/cordone/courses/2026-ae/Lez13-Materiali/LocalSearchTemplate.pdf)
4. [Improvement methods / Local Search (Handbook of Heuristics chapter, Springer)](https://link.springer.com/chapter/10.1007/978-3-031-13714-3_5)
5. [How easy is local search? (Johnson, Papadimitriou, Yannakakis, J. Comput. Syst. Sci. 37(1), 79-100, 1988)](https://www.karlin.mff.cuni.cz/~krajicek/jpy2.pdf)
6. [Theoretical Aspects of Local Search (Michiels, Aarts, Korst, book preview)](https://api.pageplace.de/preview/DT0400.9780691187563_A33704901/preview-9780691187563_A33704901.pdf)
7. [BTBS-LNS: Binarized-Tightening Branch-and-Search for Large Neighborhood Search (ICLR 2025)](https://proceedings.iclr.cc/paper_files/paper/2025/file/7eca17ef54789b0663cab421f2e9dbf5-Paper-Conference.pdf)
8. [Local Search Algorithms for SAT: An Empirical Evaluation (Hoos & Stützle, JAR 2000)](https://www.cs.ubc.ca/~hoos/Publ/jar00.pdf)
9. [UBCSAT: An Implementation and Experimentation Environment for SLS Algorithms for SAT and MAX-SAT (Tompkins & Hoos, SAT 2004)](https://cs.uwaterloo.ca/~dtompkin/papers/sat04proc-ubcsat.pdf)
10. [Greedy or not? Best improving versus first improving stochastic local search for MAXSAT (Whitley, Howe, Hains, AAAI 2013)](https://dl.acm.org/doi/10.5555/2891460.2891591)
11. [First-improvement or best-improvement? An in-depth local search computational study (EJOR, vol. 326, 2025)](https://ideas.repec.org/a/eee/ejores/v326y2025i3p413-426.html)
12. [On the history of combinatorial optimization (until 1960) (Schrijver)](https://homepages.cwi.nl/~lex/files/histco.pdf)
13. [G. A. Croes (1958). A Method for Solving Traveling-Salesman Problems. Operations Research.](https://doi.org/10.1287/opre.6.6.791)
14. [Shen Lin (1965). Computer Solutions of the Traveling Salesman Problem. Bell System Technical Journal.](https://doi.org/10.1002/j.1538-7305.1965.tb04146.x)
15. [B. W. Kernighan, S. Lin (1970). An Efficient Heuristic Procedure for Partitioning Graphs. Bell System Technical Journal.](https://doi.org/10.1002/j.1538-7305.1970.tb01770.x)
16. [S. Lin, B. W. Kernighan (1973). An Effective Heuristic Algorithm for the Traveling-Salesman Problem. Operations Research.](https://doi.org/10.1287/opre.21.2.498)
17. [S. Kirkpatrick, C. D. Gelatt, M. P. Vecchi (1983). Optimization by Simulated Annealing. Science.](https://doi.org/10.1126/science.220.4598.671)
18. [Local Search, Artificial Intelligence: Foundations of Computational Agents, 3rd Edition, Section 4.6](https://artint.info/3e/html/ArtInt3e.Ch4.S6.html)
19. [Job shop scheduling by local search (Vaessens, Aarts, Lenstra)](https://pure.tue.nl/ws/files/4282236/9410744.pdf)
20. [Future paths for integer programming and links to artificial intelligence (Computers & Operations Research, 1986)](https://doi.org/10.1016/0305-0548%2886%2990048-1)
21. [An Introduction to Tabu Search (Gendreau)](https://sci2s.ugr.es/sites/default/files/files/Teaching/OtherPostGraduateCourses/Metaheuristicas/TabuSearch.pdf)
22. [Variable neighborhood search (Computers & Operations Research, 1997)](https://doi.org/10.1016/s0305-0548%2897%2900031-2)
23. [Metaheuristic hybridization with GRASP (Resende & Ribeiro)](https://optimization-online.org/wp-content/uploads/2008/04/1954.pdf)
24. [Helena Ramalhinho Dias Lourenço, Olivier C. Martin, Thomas Stutzle (2001). Iterated Local Search. SSRN Electronic Journal.](https://doi.org/10.2139/ssrn.273397)
25. [A General Large Neighborhood Search Framework for Solving Integer Linear Programs (NeurIPS 2020)](https://proceedings.neurips.cc/paper_files/paper/2020/file/e769e03a9d329b2e864b4bf4ff54ff39-Paper.pdf)
26. [Stefan Ropke, David Pisinger (2006). An Adaptive Large Neighborhood Search Heuristic for the Pickup and Delivery Problem with Time Windows. Transportation Science.](https://doi.org/10.1287/trsc.1050.0135)
27. [Matteo Fischetti, Andrea Lodi (2003). Local branching. Mathematical Programming.](https://doi.org/10.1007/s10107-003-0395-5)
28. [Large Language Model-driven Large Neighborhood Search for Large-Scale MILP Problems (ICML 2025)](https://proceedings.mlr.press/v267/ye25j.html)
29. [Escaping Local Optima with Local Search: A Theory-Driven Discussion (Doerr et al., GECCO)](https://backend.orbit.dtu.dk/ws/files/288231618/Escaping_Local_Optima_With_Local_Search_A_Theory_Driven_Discussion.pdf)
30. [The Traveling Salesman Problem: A Case Study in Local Optimization (Johnson & McGeoch, in Local Search in Combinatorial Optimization, Wiley 1997)](https://www.csc.kth.se/utbildning/kth/kurser/DD2440/avalg14/TSP-JohMcg97.pdf)
31. [When Is Local Search Both Effective and Efficient? (STACS 2026, LIPIcs vol. 364)](https://drops.dagstuhl.de/storage/00lipics/lipics-vol364-stacs2026/LIPIcs.STACS.2026.59/LIPIcs.STACS.2026.59.pdf)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Algorithms and computational methods › Optimization and dynamic programming › Local search and metaheuristics

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/local-search-optimization

English original: https://www.edgepedia.org/local-search-optimization
