# 寻路

寻路（pathfinding）是这样一个计算问题：在图或地图上找出一条从起点到目标的路线，通常还要使距离、通行时间或能量之类的代价最小。它是道路网络导航、移动机器人、自动驾驶车辆和游戏角色寻路的基础，并被视作导航系统的核心组成部分——这些系统要保证从起点到终点安全而高效地移动<sup>[1](https://doi.org/10.1109/ACCESS.2025.3618837)</sup>。

| 关键事实 | 详情 |
|---|---|
| 问题设定 | 环境被建模为一张图，节点是位置（栅格单元、道路交叉口或导航网格多边形），边带有移动代价<sup>[2](https://www.redblobgames.com/pathfinding/a-star/implementation.html)</sup> |
| 奠基算法 | 迪杰斯特拉算法（Dijkstra's algorithm，1959，*Numerische Mathematik*，第269–271页）与 A*（哈特、尼尔森与拉斐尔，1968，IEEE Transactions on Systems Science and Cybernetics 4(2)，第100–107页）<sup>[3](https://arxiv.org/abs/2607.01454)</sup> |
| A* 的评价函数 | 节点按 \( f(n) = g(n) + h(n) \) 递增的顺序扩展，即已付出的代价加上到目标的估计代价<sup>[4](https://inst.eecs.berkeley.edu/~cs188/textbook/search/informed.html)</sup> |
| 最优性条件 | 在分支因子有限、弧代价有正下界、启发式函数可采纳（即从不高估真实剩余代价）的条件下，A* 返回最优解<sup>[5](https://www.cs.ubc.ca/~poole/aibook/2e/html2e/ArtInt2e.Ch3.S6.SS1.html)</sup> |
| 静态与动态 | 静态路径规划处理固定环境中的静止物体；动态路径规划则适应实时变化、移动障碍物和变化的地形<sup>[1](https://doi.org/10.1109/ACCESS.2025.3618837)</sup> |
| 路网加速 | 收缩层次（contraction hierarchies）通过添加捷径边对大陆规模的路网做预处理；随后用改造过的双向迪杰斯特拉算法在不到一毫秒内回答精确查询，只访问几百个节点<sup>[6](https://pubsonline.informs.org/doi/pdf/10.1287/trsc.1110.0401)</sup> |
| 游戏引擎实践 | 虚幻引擎（Unreal Engine）从碰撞几何体生成导航网格，将其分块，再划分为多边形，构成一张图，每个多边形带有代价，用于选出代价最低的路径<sup>[7](https://dev.epicgames.com/documentation/unreal-engine/navigation-system-in-unreal-engine?lang=en-US)</sup> |

## 图、栅格与地图

每一种寻路方法都建立在把环境表示为图的基础上。在方格栅格上，每个单元是一个节点，与相邻单元相连；而搜索代码并不专属于栅格：只要替换邻居函数、代价函数和[启发式](https://www.edgepedia.org/zh/heuristic)函数，同一份 A* 代码就能跑在任何图结构上<sup>[2](https://www.redblobgames.com/pathfinding/a-star/implementation.html)</sup>。图中的“位置”未必是地图上的位置；视问题而定，它们可以携带方向、燃料或物品栏之类的额外状态<sup>[2](https://www.redblobgames.com/pathfinding/a-star/implementation.html)</sup>。

**化简图。** 搜索需要处理的节点越少，运行就越快，因此大地图常被替换为更小的抽象：位于外侧拐角等关键决策点的路点、覆盖任意形状可行走区域的导航网格、粗细分层的表示，以及用大方块表示开阔区域、用小方块表示不规则边缘的四叉树<sup>[8](https://www.redblobgames.com/pathfinding/grids/algorithms.html)</sup>。

## 经典算法

它完备且最优，但搜索面很宽，因为它对目标在哪儿毫无概念。

**A\*** 在迪杰斯特拉的搜索上加入启发式：它几乎就是迪杰斯特拉算法，只是节点的优先级等于已付出的代价加上对剩余代价的启发式估计<sup>[2](https://www.redblobgames.com/pathfinding/a-star/implementation.html)</sup>。启发式的质量决定工作量：启发式为 0 时，A* 退化为迪杰斯特拉算法；启发式等于真实最短路径长度时，A* 直奔目标；启发式超过真实长度时，A* 不再保证最短路径<sup>[8](https://www.redblobgames.com/pathfinding/grids/algorithms.html)</sup>。

**可采纳性与一致性。** 若 \( 0 \leq h(n) \leq h^{*}(n) \)，其中 \( h^{*}(n) \) 是从 \( n \) 到目标的真实最优代价，则称启发式是可采纳的；在可采纳的条件下，A* 的树搜索给出最优解<sup>[4](https://inst.eecs.berkeley.edu/~cs188/textbook/search/informed.html)</sup>。一个充分条件式的表述还要求分支因子有限、弧代价大于某个 \( \epsilon > 0 \)<sup>[5](https://www.cs.ubc.ca/~poole/aibook/2e/html2e/ArtInt2e.Ch3.S6.SS1.html)</sup>。不一致是有实际代价的，因为节点可能被反复扩展；但关于不一致启发式的研究表明，它们也能带来启发式取值的多样性，从而减少节点扩展的总数<sup>[10](https://www.sciencedirect.com/science/article/pii/S0004370211000221)</sup>。

**实践中的启发式。** 在栅格上，距离是常用的启发式：四方向移动用[曼哈顿距离](https://www.edgepedia.org/zh/manhattan-distance)，路径规划中用直线距离，八连通栅格上用八向启发式（octile）<sup>[11](https://github.com/riscy/a_star_on_grids)</sup>。更好的启发式可以通过分析地图预先算出，例如预先计算到若干地标点的距离，再外推估计别处的距离——这一技术在真实游戏的地图上用大约 20 行代码就带来了可观的加速<sup>[8](https://www.redblobgames.com/pathfinding/grids/algorithms.html)</sup>。当有多个可采纳的启发式可用时，它们的最大值同样可采纳，并且单独支配其中每一个，所以取最大值是常见做法<sup>[4](https://inst.eecs.berkeley.edu/~cs188/textbook/search/informed.html)</sup>。

**局限。** A* 必须把它正在考虑的所有节点保存在内存中，其空间复杂度令人却步；SMA* 和 RBFS 等内存受限的变体正是为此设计的<sup>[12](https://cw.fel.cvut.cz/old/_media/courses/a3b33kui/knihy/artificial_intelligence_a_modern_approach_3rd_edition_chapter_03.pdf?cache=nocache)</sup>。A* 在变化的环境中还缺乏适应性：任何环境变化都必须从头重算，在仓库、农田或搜救行动这类大规模动态场景中代价高昂<sup>[13](https://www.mdpi.com/2673-4052/6/4/52)</sup>。这促成了 D* 与 D* Lite 等重规划算法，它们被列为移动机器人导航的经典方法<sup>[14](https://doi.org/10.1016/j.dajour.2026.100722)</sup>。

## 加速与变体

**双向搜索**从两端同时搜索，当前沿相遇时停止。在路网上，研究论文常以迪杰斯特拉算法为基础，并用双向迪杰斯特拉作为基线；有分析说明了它为何在该领域表现良好，同时指出构造测试问题时一个会拖累 A* 性能的简单错误<sup>[15](https://digitalcommons.du.edu/etd/1303/)</sup>。双向 A* 的变体可扩展到双目标搜索：在 1000 个基准算例上，用于双目标搜索的双向 A* 算法（BOBA*）全部求得最优解，平均运行时间比 BOA*、双目标迪杰斯特拉和双向双目标迪杰斯特拉快五倍<sup>[16](https://arxiv.org/abs/2105.11888)</sup>。

**基于预处理的路径规划。** 收缩层次在预处理阶段利用路网的层次结构添加捷径边；此后，改造过的双向迪杰斯特拉算法能在不到一毫秒内找到精确最短路径，只访问几百个节点，搜索空间之小使移动端实现成为可能，包括处理交通拥堵<sup>[6](https://pubsonline.informs.org/doi/pdf/10.1287/trsc.1110.0401)</sup>。层次化加速技术也为 A* 本身提供距离估计，已有算法从收缩层次中提取启发式取值，用于大规模路网中的精确路径规划<sup>[17](https://arxiv.org/abs/1910.12526)</sup>。

**针对栅格的优化。** 移动代价一致时，广度优先搜索比迪杰斯特拉算法更合适；把优先队列分桶或分区，可以利用代价范围有限这一点；Fringe Search 分批处理开放集，在不需要精确排序时能带来很大收益<sup>[8](https://www.redblobgames.com/pathfinding/grids/algorithms.html)</sup>。跳点搜索（Jump Point Search）在权重一致的栅格区域内跳跃前进，而不是逐个扩展节点<sup>[8](https://www.redblobgames.com/pathfinding/grids/algorithms.html)</sup>。对于任意角度移动，Theta* 及相关算法让寻路器直接分析拉直后的路径，因为单纯对栅格路径做拉绳（string-pulling）并不保证仍然最短<sup>[8](https://www.redblobgames.com/pathfinding/grids/algorithms.html)</sup>。

## 游戏中的寻路

游戏引擎通过导航网格封装这些思想。[虚幻引擎](https://www.edgepedia.org/zh/unreal-engine)从关卡的碰撞几何体生成导航网格，先分块再划分为多边形，并给每个多边形指定代价，智能体据此寻找总体代价最低的路径；该系统支持静态、动态和仅动态修改器三种生成模式，能连接平台、桥梁等不相连的区域，并提供互惠速度障碍（Reciprocal Velocity Obstacles）和 Detour Crowd Manager，用于在游戏过程中避开动态障碍物和其他智能体<sup>[7](https://dev.epicgames.com/documentation/unreal-engine/navigation-system-in-unreal-engine?lang=en-US)</sup>。这套方法背后的 Recast 与 Detour 导航网格工具已集成进虚幻和 Unity<sup>[18](https://gameai.readthedocs.io/_/downloads/en/latest/pdf/)</sup>。

## 机器人与基于学习的方法

机器人路径规划通常分为经典方法（迪杰斯特拉、A*、D*、D* Lite、路线图法和单元分解法）与智能方法，后者包括粒子群优化、蚁群优化、遗传算法、模糊逻辑和势场法<sup>[14](https://doi.org/10.1016/j.dajour.2026.100722)</sup>。机器学习方法在当前的学术研究中已占主导地位：强化学习、深度强化学习、图神经网络，以及改编自自然语言处理的基于 [Transformer](https://www.edgepedia.org/zh/transformer) 的方法；2025 年的一种物流机器人路径规划方法就把 Transformer 与图卷积网络结合，以处理多模态数据<sup>[14](https://doi.org/10.1016/j.dajour.2026.100722)</sup>。2025 年的一篇 IEEE 综述把各类方法归为传统的栅格法、图法和采样法，以及现代的反应式、预测式、优化、机器学习和仿生算法，并指出可扩展的深度强化学习和能跨平台泛化、无需大量重新训练的图神经网络模型是一个研究方向<sup>[1](https://doi.org/10.1109/ACCESS.2025.3618837)</sup>。

**学习启发式。** 启发式函数本身也可以学习。近期工作把启发式学习表述为约束优化问题，并提出交叉熵可采纳性（Cross-Entropy Admissibility）——一种在训练中强制满足可采纳性的损失函数，使学到的启发式仍保留 A* 的最优性保证<sup>[19](https://arxiv.org/abs/2509.22626)</sup>。

**几何感知的表示。** 经典导航网格假定可通行性与机器人朝向无关，这对狭窄空间中的非圆形机器人并不成立。SE(2) 导航网格在多边形区域中编码依赖偏航角的可通行性，并与 A*–拉绳–A* 策略配合，分层优化位置与朝向；在仿真中，它在每个评测场景里都比经典导航网格多覆盖 50% 以上的可通行面积，ASA 策略还把几何路径长度缩短了 6.2%<sup>[3](https://arxiv.org/abs/2607.01454)</sup>。

**无地图与仿生导航。** 并非所有导航都在地图上做图搜索。Bee-Nav 策略受蜜蜂在长途旅行前进行的视觉学习飞行启发，让飞行机器人远离巢穴后依靠路径积分返回，并用视觉归航网络抵消积分漂移；它引用的最先进水平是一个微型飞行机器人，用低功耗 AI 芯片上 500 kB 的内存在一个 4 × 5 米的区域内导航<sup>[20](https://www.nature.com/articles/s41586-026-10461-3)</sup>。

## References

1. [A Comprehensive Survey of Path Planning Algorithms for Autonomous Systems and Mobile Robots, IEEE Access 13 (2025)](https://doi.org/10.1109/ACCESS.2025.3618837)
2. [Implementation of A*, Red Blob Games](https://www.redblobgames.com/pathfinding/a-star/implementation.html)
3. [SE(2) Navigation Mesh, arXiv:2607.01454](https://arxiv.org/abs/2607.01454)
4. [Informed Search, CS 188 Introduction to Artificial Intelligence, UC Berkeley](https://inst.eecs.berkeley.edu/~cs188/textbook/search/informed.html)
5. [A* Search, Artificial Intelligence: Foundations of Computational Agents, 2nd ed., UBC](https://www.cs.ubc.ca/~poole/aibook/2e/html2e/ArtInt2e.Ch3.S6.SS1.html)
6. [Geisberger, Sanders, Schultes, Vetter (2012). Exact Routing in Large Road Networks Using Contraction Hierarchies. Transportation Science 46(3):388–404](https://pubsonline.informs.org/doi/pdf/10.1287/trsc.1110.0401)
7. [Navigation System in Unreal Engine, Epic Developer Community](https://dev.epicgames.com/documentation/unreal-engine/navigation-system-in-unreal-engine?lang=en-US)
8. [Grid pathfinding optimizations, Red Blob Games](https://www.redblobgames.com/pathfinding/grids/algorithms.html)
9. [CS 221 States-based Models Cheatsheet, Stanford](https://stanford.edu/~shervine/teaching/cs-221/cheatsheet-states-models/)
10. [Inconsistent heuristics in theory and practice, Artificial Intelligence (ScienceDirect)](https://www.sciencedirect.com/science/article/pii/S0004370211000221)
11. [a_star_on_grids: Best practices for implementing A* on four- and eight-connected grids, GitHub](https://github.com/riscy/a_star_on_grids)
12. [Artificial Intelligence: A Modern Approach, 3rd ed., Chapter 3](https://cw.fel.cvut.cz/old/_media/courses/a3b33kui/knihy/artificial_intelligence_a_modern_approach_3rd_edition_chapter_03.pdf?cache=nocache)
13. [A Comprehensive Review of Improved A* Path Planning Algorithms and Their Hybrid Integrations, Automation 6(4):52 (2025)](https://www.mdpi.com/2673-4052/6/4/52)
14. [A critical review of analytical approaches to path planning for autonomous mobile robots, Decision Analytics Journal 20 (2026)](https://doi.org/10.1016/j.dajour.2026.100722)
15. [Sawlani (2017). Explaining the Performance of Bidirectional Dijkstra and A* on Road Networks, University of Denver](https://digitalcommons.du.edu/etd/1303/)
16. [Bi-objective Search with Bi-directional A*, arXiv:2105.11888](https://arxiv.org/abs/2105.11888)
17. [A Fast and Tight Heuristic for A* in Road Networks, arXiv:1910.12526](https://arxiv.org/abs/1910.12526)
18. [Game AI (navigation meshes, Recast and Detour)](https://gameai.readthedocs.io/_/downloads/en/latest/pdf/)
19. [Learning Admissible Heuristics for A*: Theory and Practice, arXiv:2509.22626](https://arxiv.org/abs/2509.22626)
20. [Efficient robot navigation inspired by honeybee learning flights, Nature (2026)](https://www.nature.com/articles/s41586-026-10461-3)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Algorithms and computational methods › Graph and network algorithms › Shortest paths

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/pathfinding

English original: https://www.edgepedia.org/pathfinding
