# 指派算法

指派算法求解线性指派问题：给定一组代理和一组任务，以及每个代理–任务对的成本或得分，它要找出使总成本最小或总收益最大的一一配对。输入是一个 \( n \times n \) 成本矩阵 \( C = (c_{ij}) \)，输出是一个排列，把每一行匹配到互不相同的列，并使所选元素之和最小。<sup>[1](https://epubs.siam.org/doi/book/10.1137/1.9781611972238)</sup> 匈牙利算法在多项式时间内运行，由库恩（Kuhn）于1955年首次提出。<sup>[2](https://resources.mpi-inf.mpg.de/departments/d1/teaching/ss11/OPT/lec11.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 问题 | 在 \( n \times n \) 成本矩阵的每一行和每一列中各选恰好一个元素，使总和最小<sup>[1](https://epubs.siam.org/doi/book/10.1137/1.9781611972238)</sup> |
| 经典方法 | 匈牙利方法，由H. W. 库恩发表于《海军研究后勤季刊》，1955年<sup>[3](https://doi.org/10.1002/nav.3800020109)</sup> |
| 复杂度 | 库恩原始形式为 \( O(n^4) \)；后续实现为 \( O(n^3) \)<sup>[4](https://luc.devroye.org/Gameroff+Campana-The_Hungarian_Method-COMP252-2024.pdf)</sup> |
| 主要替代方法 | 最短增广路径（容克–福尔根南特）、拍卖算法、成本缩放<sup>[5](https://doi.org/10.1007/bf02278710)</sup><sup> • </sup><sup>[6](https://doi.org/10.1007/bf01584237)</sup><sup> • </sup><sup>[7](https://doi.org/10.1007/bf01585996)</sup> |
| 已知最佳界 | 整数成本下为 \( O(\sqrt{n} \cdot m \cdot \log(n \cdot N)) \)（加博–塔扬）<sup>[8](https://www.columbia.edu/~cs2035/courses/ieor8100.F18/GabTar.pdf)</sup> |
| 典型用途 | 多目标跟踪、输入排队交换、物流和数据关联<sup>[9](https://www.cs.princeton.edu/courses/archive/spr05/cos423/lectures/07assignment.pdf)</sup><sup> • </sup><sup>[1](https://epubs.siam.org/doi/book/10.1137/1.9781611972238)</sup> |

## 工作原理

指派问题等价于在一个完全二分图中寻找最小成本完美匹配，该图每行一个节点、每列一个节点，边成本为 \( c_{ij} \)。<sup>[10](https://public.websites.umich.edu/~murty/books/network_programming/network-3.pdf)</sup> 匈牙利方法是一种原始–对偶算法：它维护行的对偶变量 \( u_i \) 和列的对偶变量 \( v_j \)，满足 \( u_i + v_j \le c_{ij} \)，并最大化 \( \sum_i u_i + \sum_j v_j \)。<sup>[2](https://resources.mpi-inf.mpg.de/departments/d1/teaching/ss11/OPT/lec11.pdf)</sup> 缩减成本为 \( \bar{c}_{ij} = c_{ij} - u_i - v_j \)；由对偶性，当每条被指派边的 \( \bar{c}_{ij} = 0 \) 时，该指派最优，这就是互补松弛条件。<sup>[2](https://resources.mpi-inf.mpg.de/departments/d1/teaching/ss11/OPT/lec11.pdf)</sup> 库恩把对偶问题表述为：寻找非负整数 \( u_1, \ldots, u_n \) 和 \( v_1, \ldots, v_n \)，满足 \( u_i + v_j \ge r_{ij} \)，并使 \( \sum u_i + \sum v_j \) 最小，他称这样一组数为一个覆盖。<sup>[11](https://www.math.toronto.edu/mccann/1855/KuhnNRL55.pdf)</sup>

关键的直觉是：沿某一行或某一列加上或减去一个常数，不会改变哪个完美匹配最便宜。<sup>[9](https://www.cs.princeton.edu/courses/archive/spr05/cos423/lectures/07assignment.pdf)</sup> 因此，该方法在变换矩阵、使元素趋向零的同时，把变换记录在对偶变量中。柯尼希（König）的一个结果为匹配步骤提供了依据：如果最多能选出 \( m \) 个相互独立的标记，那么 \( m \) 条直线就能覆盖所有被标记的位置。<sup>[11](https://www.math.toronto.edu/mccann/1855/KuhnNRL55.pdf)</sup> 柯尼希1916年的匹配/顶点覆盖对偶性被推广到了加权情形；其证明没有给出显式算法，但隐含地定义了库恩所发展的迭代过程。<sup>[12](http://www.inf.u-szeged.hu/~csendes/EgervarySI/MartelloFinal.pdf)</sup>

## 具体做法

标准的 \( O(n^3) \) 实现如下进行<sup>[2](https://resources.mpi-inf.mpg.de/departments/d1/teaching/ss11/OPT/lec11.pdf)</sup>：

1. 从每一行减去该行的最小值，再从每一列减去该列的最小值，得到一个非负矩阵，每行每列都有零，且对偶变量 \( u_i, v_j \) 等于所减去的量。
2. 仅使用缩减成本为零的边寻找最大匹配，从未匹配的行出发生长一棵交替树。
3. 若匹配是完美的，停止：由互补松弛性，它是最优的。
4. 否则，在未被树覆盖的元素上计算 \( \alpha = \min \{ \bar{c}_{ij} \} \)，并更新对偶变量：树中的行 \( u_i \leftarrow u_i + \alpha \)，树中的列 \( v_j \leftarrow v_j - \alpha \)。<sup>[2](https://resources.mpi-inf.mpg.de/departments/d1/teaching/ss11/OPT/lec11.pdf)</sup>
5. 从第2步重复；\( n \) 次匹配增广各需 \( O(n^2) \)，总计 \( O(n^3) \)。<sup>[4](https://luc.devroye.org/Gameroff+Campana-The_Hungarian_Method-COMP252-2024.pdf)</sup>

库恩1955年的版本至多需要 \( O(n^4) \)。<sup>[10](https://public.websites.umich.edu/~murty/books/network_programming/network-3.pdf)</sup> 关于 \( O(n^3) \) 改进的归属，文献中的说法不一：一种说法归功于富泽（Tomizawa，1971）以及独立得出该结果的埃德蒙兹（Edmonds）和卡普（Karp，1972）<sup>[4](https://luc.devroye.org/Gameroff+Campana-The_Hungarian_Method-COMP252-2024.pdf)</sup>，而教科书则归功于劳勒（Lawler）1976年通过逐次最短路径技术给出的实现<sup>[10](https://public.websites.umich.edu/~murty/books/network_programming/network-3.pdf)</sup>；已发表的文献并未解决这一归属问题。

## 起源

库恩于1955年3月在《海军研究后勤季刊》第2卷第1–2期第83–97页发表了匈牙利方法。<sup>[3](https://doi.org/10.1002/nav.3800020109)</sup><sup> • </sup><sup>[13](https://doi.org/10.1007/bf01456961)</sup><sup> • </sup><sup>[12](http://www.inf.u-szeged.hu/~csendes/EgervarySI/MartelloFinal.pdf)</sup> 库恩于1953年秋把埃格尔瓦里（Egerváry）的论文从匈牙利语译成英语，将其与柯尼希的结果相结合，构成了该算法的基础。<sup>[14](https://www.math.utoronto.ca/mccann/1855/KuhnEJOR12.pdf)</sup> 库恩指出，这些思想比线性规划的诞生还要早15年以上。<sup>[3](https://doi.org/10.1002/nav.3800020109)</sup>

詹姆斯·芒克雷斯（James Munkres）于1957年3月在《工业与应用数学学会杂志》第5卷第1期第32–38页发表了库恩算法的一个变体，附有正确性证明，并推广到了运输问题。<sup>[15](https://doi.org/10.1137/0105003)</sup><sup> • </sup><sup>[16](https://www.sciencedirect.com/science/article/abs/pii/S0377221705007137)</sup> 雅可比（Jacobi）于1851年去世后，其遗稿于1890年出版，其中包含一个与匈牙利方法基本相同的算法。<sup>[14](https://www.math.utoronto.ca/mccann/1855/KuhnEJOR12.pdf)</sup>

## 变体

**最短增广路径。** 富泽于1971年观察到，转为非负缩减成本后，可用迪杰斯特拉（Dijkstra）算法求解最短路径子问题；经过 \( O(n) \) 次增广，得到 \( O(n^3) \)。<sup>[17](https://doi.org/10.1002/net.3230010206)</sup><sup> • </sup><sup>[18](https://gwern.net/doc/statistics/decision/1987-jonker.pdf)</sup> 容克–福尔根南特算法（LAPJV）于1987年发表在《计算》上，增加了新的初始化例程和一种特殊的迪杰斯特拉实现；其初始化和增广阶段均以 \( O(n^3) \) 运行，在稀疏问题上，它一致地快于当时文献中的最佳算法。<sup>[5](https://doi.org/10.1007/bf02278710)</sup>

**拍卖算法。** 迪米特里·P. 贝尔塞卡斯（Dimitri P. Bertsekas）于1981年在《数学规划》上提出了拍卖算法<sup>[6](https://doi.org/10.1007/bf01584237)</sup>，其动机是并行计算；未指派的人对物品出价，价格充当对偶变量，出价增量保证 \( \varepsilon \)-互补松弛性，因此最终成本与最优值之差在 \( n \cdot \varepsilon \) 以内。<sup>[19](https://web.mit.edu/dimitrib/www/Auction_Survey.pdf)</sup> 雅可比版本中所有未指派的代理同时出价，适合并行计算；逆向拍卖则处理非对称问题并减少价格战。<sup>[20](https://web.mit.edu/dimitrib/www/Ch2_AUCTION.pdf)</sup> 该算法通过 \( \varepsilon \)-缩放改进到 \( O(n^3 \log(n \cdot C)) \)，其中 \( C = \max |c_{ij}| \)。<sup>[21](https://cris.unibo.it/retrieve/e1dcb335-c29e-7715-e053-1705fe0a6cc9/1047369.pdf)</sup>

**成本缩放。** 戈德堡（Goldberg）和肯尼迪（Kennedy）的成本缩放推–重标记算法于1995年发表在《数学规划》上<sup>[7](https://doi.org/10.1007/bf01585996)</sup>；最佳强多项式界 \( O(n(m + n \log n)) \)（\( n \) 个节点、\( m \) 条边）由匈牙利方法达到，而加博和塔扬的缩放算法在整数成本下以 \( O(\sqrt{n} \cdot m \cdot \log(n \cdot N)) \) 运行。<sup>[22](https://homes.di.unimi.it/righini/Didattica/OttimizzazioneSuGrafo/MaterialeOG/1995%20Goldberg%20Kennedy%20-%20Cost%20scaling%20for%20assignment%20problem.pdf)</sup><sup> • </sup><sup>[8](https://www.columbia.edu/~cs2035/courses/ieor8100.F18/GabTar.pdf)</sup> 并行工作很早就开始了：温（Wein）和泽尼奥斯（Zenios）于1991年研究了大规模并行求解<sup>[23](https://doi.org/10.1016/0743-7315%2891%2990092-n)</sup>，达特（Date）和纳吉（Nagi）于2016年构建了GPU加速的匈牙利算法。<sup>[24](https://doi.org/10.1016/j.parco.2016.05.012)</sup>

## 应用

凡需把检测匹配到轨迹、或把资源匹配到需求之处，都会出现指派求解器。分辨率有限的传感器进行多目标跟踪，会产生恰好是这种形式的多重指派问题<sup>[20](https://web.mit.edu/dimitrib/www/Ch2_AUCTION.pdf)</sup>，多指标指派问题近年来在多目标跟踪和数据关联中有应用。<sup>[1](https://epubs.siam.org/doi/book/10.1137/1.9781611972238)</sup> 在输入排队分组交换中，均匀到达下FIFO排队把吞吐量限制在58%，而最大权重匹配可达到100%。<sup>[9](https://www.cs.princeton.edu/courses/archive/spr05/cos423/lectures/07assignment.pdf)</sup>

## 局限与替代方法

暴力法在大规模下毫无希望：\( n \) 个元素的排列数为 \( n! \)，因此枚举对大规模实例不可行。<sup>[25](https://www.mdpi.com/1999-4893/15/10/377)</sup> 拍卖算法在适当的表述下可以直接处理人数与物品数不等的非对称（矩形）实例，只要至少存在一个可行指派，就保证终止。<sup>[30](https://faculty.engineering.asu.edu/sites/g/files/litvpz5506/files/2026-06/A-Forward-Reverse-Auction-Algorithm-for-Asymmetric-Assignment-Problems.pdf)</sup><sup> • </sup><sup>[26](https://ar5iv.labs.arxiv.org/html/1810.03562)</sup> 将拍卖类方法改造用于带子集容量约束的指派问题，已被证明在某些实例上会循环，无法终止。<sup>[27](https://ulrich-bauer.org/pub/ConstrainedAssignment.pdf)</sup>

矩形（不平衡）问题通常通过用零成本虚拟元素把矩阵填充为 \( n \times n \)（\( n = \max(r, c) \)）来处理，最大化问题则通过把所有成本取负、并对最终答案取负来转化为最小化。<sup>[28](https://neelmishra.github.io/blog/cp/optimization/hungarian-detailed.html)</sup> 禁止的指派通过省略相应弧来处理，相当于令 \( c_{ij} = +\infty \)。<sup>[10](https://public.websites.umich.edu/~murty/books/network_programming/network-3.pdf)</sup> 对八种代码（APC、CTCS、LAPm、JV、NAUCTION_SP、AFLP、AFR、CSA）在稠密实例上的计算比较未发现精确排名：最快的代码取决于成本类别。<sup>[21](https://cris.unibo.it/retrieve/e1dcb335-c29e-7715-e053-1705fe0a6cc9/1047369.pdf)</sup> 由于指派问题的线性规划松弛是整的，其基本解对应排列矩阵，因此匈牙利方法及其同类方法能精确求解该线性规划。<sup>[29](https://www.andrew.cmu.edu/course/42-731/handouts/Burkard%5FLAP%5Freview.pdf)</sup>

## References

1. [Assignment Problems (Burkard, Dell'Amico, Martello, SIAM)](https://epubs.siam.org/doi/book/10.1137/1.9781611972238)
2. [Optimization I Lecture 11: The Assignment Problem and Primal-Dual Algorithms (MPI-INF)](https://resources.mpi-inf.mpg.de/departments/d1/teaching/ss11/OPT/lec11.pdf)
3. [H. W. Kuhn (1955). The Hungarian method for the assignment problem. Naval Research Logistics Quarterly.](https://doi.org/10.1002/nav.3800020109)
4. [The Hungarian Method (Gameroff & Campana, COMP252 lecture transcript, McGill, 2024)](https://luc.devroye.org/Gameroff+Campana-The_Hungarian_Method-COMP252-2024.pdf)
5. [R. Jonker, A. Volgenant (1987). A shortest augmenting path algorithm for dense and sparse linear assignment problems. Computing.](https://doi.org/10.1007/bf02278710)
6. [Dimitri P. Bertsekas (1981). A new algorithm for the assignment problem. Mathematical Programming.](https://doi.org/10.1007/bf01584237)
7. [Andrew V. Goldberg, Robert Kennedy (1995). An efficient cost scaling algorithm for the assignment problem. Mathematical Programming.](https://doi.org/10.1007/bf01585996)
8. [Faster scaling algorithms for network problems (Gabow & Tarjan)](https://www.columbia.edu/~cs2035/courses/ieor8100.F18/GabTar.pdf)
9. [Assignment Problem (Kleinberg–Tardos slides, Princeton COS 423, Kevin Wayne)](https://www.cs.princeton.edu/courses/archive/spr05/cos423/lectures/07assignment.pdf)
10. [Network Programming, Chapter 3: The Hungarian Method (Ahuja, Magnanti, Orlin / Murty)](https://public.websites.umich.edu/~murty/books/network_programming/network-3.pdf)
11. [The Hungarian method for the assignment problem (full text PDF)](https://www.math.toronto.edu/mccann/1855/KuhnNRL55.pdf)
12. [Jenő Egerváry: from the origins of the Hungarian algorithm to satellite communication (Martello et al.)](http://www.inf.u-szeged.hu/~csendes/EgervarySI/MartelloFinal.pdf)
13. [Dénes König (1916). Über Graphen und ihre Anwendung auf Determinantentheorie und Mengenlehre. Mathematische Annalen.](https://doi.org/10.1007/bf01456961)
14. [A tale of three eras: The discovery and rediscovery of the Hungarian Method (Kuhn, 2012)](https://www.math.utoronto.ca/mccann/1855/KuhnEJOR12.pdf)
15. [James Munkres (1957). Algorithms for the Assignment and Transportation Problems. Journal of the Society for Industrial and Applied Mathematics.](https://doi.org/10.1137/0105003)
16. [Assignment problems: A golden anniversary survey (Pentico, EJOR)](https://www.sciencedirect.com/science/article/abs/pii/S0377221705007137)
17. [N. Tomizawa (1971). On some techniques useful for solution of transportation network problems. Networks.](https://doi.org/10.1002/net.3230010206)
18. [A shortest augmenting path algorithm for dense and sparse linear assignment problems (Jonker & Volgenant, Computing 38, 1987)](https://gwern.net/doc/statistics/decision/1987-jonker.pdf)
19. [Auction algorithms for network flow problems: A tutorial introduction (Bertsekas)](https://web.mit.edu/dimitrib/www/Auction_Survey.pdf)
20. [Auction Algorithms for the Assignment Problem (book chapter, Bertsekas)](https://web.mit.edu/dimitrib/www/Ch2_AUCTION.pdf)
21. [Review Article (assignment problem algorithms survey, University of Bologna repository)](https://cris.unibo.it/retrieve/e1dcb335-c29e-7715-e053-1705fe0a6cc9/1047369.pdf)
22. [Cost scaling for the assignment problem (Goldberg & Kennedy, 1995)](https://homes.di.unimi.it/righini/Didattica/OttimizzazioneSuGrafo/MaterialeOG/1995%20Goldberg%20Kennedy%20-%20Cost%20scaling%20for%20assignment%20problem.pdf)
23. [On the massively parallel solution of the assignment problem (Journal of Parallel and Distributed Computing, 1991)](https://doi.org/10.1016/0743-7315%2891%2990092-n)
24. [Ketan Date, Rakesh Nagi (2016). GPU-accelerated Hungarian algorithms for the Linear Assignment Problem. Parallel Computing.](https://doi.org/10.1016/j.parco.2016.05.012)
25. [The Assignment Problem and Its Relation to Logistics Problems (Algorithms, MDPI)](https://www.mdpi.com/1999-4893/15/10/377)
26. [The equivalence between two classic algorithms for the assignment problem](https://ar5iv.labs.arxiv.org/html/1810.03562)
27. [Assignment Problem with Constraints (Bauer, thesis)](https://ulrich-bauer.org/pub/ConstrainedAssignment.pdf)
28. [Hungarian Algorithm Walkthrough (Neel Mishra, 2025)](https://neelmishra.github.io/blog/cp/optimization/hungarian-detailed.html)
29. [Linear Assignment Problems and Extensions (Burkard et al., review)](https://www.andrew.cmu.edu/course/42-731/handouts/Burkard%5FLAP%5Freview.pdf)
30. [A Forward Reverse Auction Algorithm for Asymmetric Assignment Problems (faculty.engineering.asu.edu)](https://faculty.engineering.asu.edu/sites/g/files/litvpz5506/files/2026-06/A-Forward-Reverse-Auction-Algorithm-for-Asymmetric-Assignment-Problems.pdf)

---
*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Sep 30, 2026 · Last review: Sep 30, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 逻辑与离散数学 › General discrete mathematics and discrete structures › Combinatorics

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/assignment-algorithm

English original: https://www.edgepedia.org/assignment-algorithm
