# 顶点着色

顶点着色是一种图算法，它为无向图的每个顶点分配一种颜色，使得相邻顶点得到不同颜色，并让所用颜色数尽可能少。形式化地说，给定图 \( G=(V,E) \)，顶点着色问题要求为每个顶点指定一种颜色，使相邻顶点的颜色不同，且所用颜色数最少。<sup>[1](https://onlinelibrary.wiley.com/doi/10.1111/j.1475-3995.2009.00696.x)</sup> 一个正常 \( k \)-着色至多使用 \( k \) 种颜色，而色数 \( \chi(G) \) 是存在这种着色的最小 \( k \)。<sup>[2](https://www.cs.uleth.ca/~morris/Combinatorics/html/sect_colouring-Vertices.html)</sup> 该问题是 NP 完全的<sup>[3](https://reference-global.com/download/article/10.2478/v10209-011-0012-y.pdf)</sup>，但它可为调度、时间表编排、寄存器分配、频率分配和通信网络建模。<sup>[1](https://onlinelibrary.wiley.com/doi/10.1111/j.1475-3995.2009.00696.x)</sup>

| 关键事实 | 详情 |
|---|---|
| 输出 | 一个正常着色：相邻顶点得到不同颜色；\( \chi(G) \) 是最少颜色数<sup>[2](https://www.cs.uleth.ca/~morris/Combinatorics/html/sect_colouring-Vertices.html)</sup> |
| 复杂度 | 对每个固定 \( k \ge 3 \)，判定 \( k \)-可着色性是 NP 完全的；判定 1-可着色性和 2-可着色性是多项式的 |
| 通用上界 | 贪心着色总是至多使用 \( \Delta(G)+1 \) 种颜色<sup>[4](https://iuuk.mff.cuni.cz/~ipenev/KG2S2022Lecture06.pdf)</sup> |
| 精确方法规模 | 分支定界可处理约 80 个顶点的图；某些 125 个顶点的实例仍无法最优求解<sup>[5](https://ar5iv.labs.arxiv.org/html/2206.13678)</sup> |
| 标准基准 | 137 个 DIMACS 实例；当前最好的基于 SAT 的求解器能解其中 94 个<sup>[6](https://arxiv.org/html/2504.04821)</sup> |
| 主要应用 | 时间表编排、寄存器分配、列车站台分配、频率分配和通信网络<sup>[1](https://onlinelibrary.wiley.com/doi/10.1111/j.1475-3995.2009.00696.x)</sup> |

## 工作原理

判定形式“\( G \) 是否 \( k \)-可着色？”是 NP 完全的<sup>[7](https://www.or.uni-bonn.de/~held/hausdorff_school_22/slides/GraphColoringFormulations.pdf)</sup>，这一结果由理查德·M·卡普（Richard M. Karp）1972 年的论文《组合问题之间的可归约性》（*Reducibility among Combinatorial Problems*）确立。<sup>[8](https://doi.org/10.1007/978-1-4684-2001-2_9)</sup> 近似同样困难：对所有 \( \epsilon > 0 \)，在因子 \( n^{1-\epsilon} \) 内近似 \( \chi(G) \) 是 NP 难的<sup>[6](https://arxiv.org/html/2504.04821)</sup>，甚至找到一种颜色数不超过最优颜色数两倍的着色也是 NP 难的。

结构性结果从上方给出答案的界。以任意顶点顺序进行贪心着色，都会产生一个至多使用 \( \Delta(G)+1 \) 种颜色的正常着色，其中 \( \Delta(G) \) 是最大度，因此 \( \chi(G) \le \Delta(G)+1 \)。<sup>[4](https://iuuk.mff.cuni.cz/~ipenev/KG2S2022Lecture06.pdf)</sup> 等号仅对完全图和奇圈成立；布鲁克斯定理（Brooks' theorem）指出，其他每个连通图都满足 \( \chi(G) \le \Delta(G) \)。<sup>[2](https://www.cs.uleth.ca/~morris/Combinatorics/html/sect_colouring-Vertices.html)</sup><sup> • </sup><sup>[4](https://iuuk.mff.cuni.cz/~ipenev/KG2S2022Lecture06.pdf)</sup> 有些情形是多项式的：一个连通的 2-可着色（二部）图可通过广度优先搜索用 2 种颜色着色<sup>[9](https://salil.seas.harvard.edu/file_url/439)</sup>；一个图是完美图——即对每个导出子图 \( H \)，\( \chi(H) \) 都等于最大团的大小——当且仅当它没有任何导出子图是长度至少为 5 的奇圈或这种圈的补图。<sup>[2](https://www.cs.uleth.ca/~morris/Combinatorics/html/sect_colouring-Vertices.html)</sup>

## 如何实现

**贪心与有序贪心。** 贪心（顺序）算法逐个考虑顶点并分配第一个可用颜色；在具有 \( n \) 个顶点和 \( m \) 条边的图上，它运行时间为 \( O(n+m) \)。<sup>[10](https://ar5iv.labs.arxiv.org/html/1505.05825)</sup> 顺序很重要。最大度优先按度数非增地排列顶点，给出界 \( \chi(G) \le 1 + \max_{i} \min\{\deg v_{i},\, i-1\} \)，这有时优于 \( 1+\Delta \)。<sup>[10](https://ar5iv.labs.arxiv.org/html/1505.05825)</sup> 最小度最后反复删除一个最小度顶点，并按删除的逆序着色，得到 \( \chi(G) \le \mathrm{dgn}(G)+1 \)，其中 \( \mathrm{dgn}(G) \) 是退化度；它用六种颜色为任意平面图着色。<sup>[10](https://ar5iv.labs.arxiv.org/html/1505.05825)</sup> 贪心的最坏情形很差：一个糟糕的顺序会在一个 2-可着色的冠图上耗费 \( n/2 \) 种颜色，而最坏情形贪心计数（Grundy 数）与 \( \chi(G) \) 之间的差距可以任意大。<sup>[10](https://ar5iv.labs.arxiv.org/html/1505.05825)</sup><sup> • </sup><sup>[11](https://www.sciencedirect.com/science/article/abs/pii/S0305054824001758)</sup>

**精确方法。** 精确算法分为动态规划（指数级 \( O(2^{|V|}) \) 空间，仅有理论意义）、分支定界枚举（多项式空间，可适用于约 80 个顶点）和基于整数线性规划（ILP）的算法，后者对大规模实例最有效。<sup>[5](https://ar5iv.labs.arxiv.org/html/2206.13678)</sup> 基于 DSATUR 的分支定界族按饱和度——即一个顶点的邻居中已经出现的不同颜色数——排序顶点并进行分支。<sup>[3](https://reference-global.com/download/article/10.2478/v10209-011-0012-y.pdf)</sup> 最先进的 ILP 模型包括基于指派、偏序、代表元、集合覆盖和集合划分的模型，以及基于 OBDD 的模型；基于独立集的模型给出更强的下界，但指派模型和偏序模型的变量少得多，在稀疏图上更胜一筹。<sup>[5](https://ar5iv.labs.arxiv.org/html/2206.13678)</sup>

**大规模图的启发式方法。** 除贪心外，DSATUR 和递归最大优先（Recursive Largest First，RLF）使用精细的动态规则来选择下一个要着色的顶点。模拟退火和禁忌搜索是最早成功应用的局部搜索方法之一，而基于种群的模因算法是最有效的方法之一。贪心加禁忌的方法可扩展到非常大的图，在稀疏实例上表现良好，但在大型稠密实例上很吃力。<sup>[12](https://dl.acm.org/doi/fullHtml/10.1145/3603112)</sup>

## 起源

该问题源自 1852 年 10 月 23 日提出的四色问题：当时弗朗西斯·格思里（Francis Guthrie）请他的兄弟弗雷德里克（Frederick）向奥古斯都·德·摩根（Augustus De Morgan）提出一个问题：四种颜色是否足以给任意地图着色。<sup>[13](https://www.ams.org//journals/notices/202206/noti2490/noti2490.html)</sup> 该证明把问题划分为许多地图子类，并使用计算机算法检查所有可能情形下的四色可着色性。<sup>[14](https://faculty.etsu.edu/gardnerr/5340/notes-Bondy-Murty-GT/Bondy-Murty-GT-11-1.pdf)</sup><sup> • </sup><sup>[3](https://reference-global.com/download/article/10.2478/v10209-011-0012-y.pdf)</sup> 在计算方面，理查德·M·卡普 1972 年的论文《组合问题之间的可归约性》将着色列入经典 NP 完全问题<sup>[8](https://doi.org/10.1007/978-1-4684-2001-2_9)</sup>，而格雷戈里·柴廷（Gregory Chaitin）关于通过图着色进行寄存器分配与溢出的工作于 2004 年发表在《ACM SIGPLAN Notices》上，使着色成为标准的编译器技术。<sup>[15](https://doi.org/10.1145/989393.989403)</sup>

## 变体

**公平着色**要求任意两个颜色类的大小至多相差一，公平色数也类似地定义。<sup>[16](https://link.springer.com/rwe/10.1007/978-1-4614-6624-6_25-1)</sup> 应用包括通信系统中的调度、施工时间表、互斥调度和全天候调度。<sup>[17](https://ar5iv.labs.arxiv.org/html/2504.14711)</sup>

**偏好与列表模型**为调度扩展了基本问题：列表着色、混合图着色、共着色、带偏好的着色和带宽着色处理日益复杂的时间表编排与调度场景。<sup>[18](https://www.gerad.ca/~alainh/G1384.pdf)</sup> 在偏好模型中，卡特赖特（Cartwright）和哈拉里（Harary）的一个经典结果指出，满足所有偏好的顶点着色存在，当且仅当图中不含恰好有一条强边的圈。<sup>[18](https://www.gerad.ca/~alainh/G1384.pdf)</sup> 放宽正常性要求的公平缺陷着色也得到了研究。<sup>[16](https://link.springer.com/rwe/10.1007/978-1-4614-6624-6_25-1)</sup>

## 应用

**寄存器分配。** 在编译中，程序变量是冲突图的顶点，同时活跃的变量由边相连，因此最小着色给出使用最少寄存器的寄存器分配；溢出通过把一个变量拆成两个顶点来建模，这两个顶点由一条偏好边相连，其惩罚等于复制代价。<sup>[18](https://www.gerad.ca/~alainh/G1384.pdf)</sup> 柴廷的表述根据寄存器冲突图做出溢出决策，并估计把计算结果保留在寄存器而非存储器中的代价，从而产生更好的目标代码，且比以前的权宜方法编译时间少得多。<sup>[15](https://doi.org/10.1145/989393.989403)</sup>

**调度。** 综述文献把时间表编排、列车站台分配、频率分配和通信网络列为应用领域。<sup>[1](https://onlinelibrary.wiley.com/doi/10.1111/j.1475-3995.2009.00696.x)</sup>

## 局限与替代方法

标准基准集来自 1993 年秋的 DIMACS 挑战赛，该挑战赛也征集了多重着色等相关问题的结果。<sup>[19](https://mat.tepper.cmu.edu/COLOR04/)</sup> 在 137 个 DIMACS 图上，最近的一项比较报告称，基于 SAT 的 ZykovColor 求解器解出 94 个实例，而 gc-cdcl 为 83 个，POP-S 为 91 个，指派编码为 92 个，CliColCom 为 91 个，exactcolors 分支定价代码为 63 个，DSatur 为 71 个；所有 SAT 方法解出 91 到 94 个。<sup>[6](https://arxiv.org/html/2504.04821)</sup> 已发表的比较在哪种精确方法最强上并不一致：一项报告称，对于 DIMACS 实例，基于 ILP 表述的分支定价表现最好<sup>[20](https://optimization-online.org/wp-content/uploads/2015/10/5159.pdf)</sup>，而较新的实例计数则把分支定价远远排在基于 SAT 的求解器之后。<sup>[6](https://arxiv.org/html/2504.04821)</sup> 基于团的方法补充着色求解器：一种团/着色方法解决了两个尚未解决的 DIMACS 实例（wap02a 和 wap08a），并改进了一个下界（r1000.1c）<sup>[21](https://www.andrew.cmu.edu/user/vanhoeve/papers/cliques_coloring_CP2022.pdf)</sup>，随后 r1000.1c 的色数首次通过精确算术中的精确决策图确定。<sup>[22](https://bonndata.uni-bonn.de/catalog/datasets/10.60507/FK2/ZE9C3L/)</sup> 即便如此，少至 125 个顶点的图仍可能无法被最好的精确算法最优求解。

基于约束规划（CP）、可满足性（SAT）和整数线性规划（ILP）的精确方法通常无法扩展到几千个顶点以上，因为编码会变得过大；在一项实验研究中，用 SAT 编码着色的最大图约有 14,000 个顶点。<sup>[12](https://dl.acm.org/doi/fullHtml/10.1145/3603112)</sup> 对于大规模稠密图，GC-SLIM——一种将禁忌搜索与基于 SAT 的局部改进相结合的混合方法——可扩展到具有数十万个顶点和超过 15 亿条边的稠密图，并在大型稠密图上优于最先进的方法。<sup>[12](https://dl.acm.org/doi/fullHtml/10.1145/3603112)</sup>

## References

1. [A survey on vertex coloring problems (Journal of Scheduling / Wiley)](https://onlinelibrary.wiley.com/doi/10.1111/j.1475-3995.2009.00696.x)
2. [Vertex colouring (Combinatorics textbook chapter, University of Lethbridge)](https://www.cs.uleth.ca/~morris/Combinatorics/html/sect_colouring-Vertices.html)
3. [A Survey of Graph Coloring - Its Types, Methods and Applications](https://reference-global.com/download/article/10.2478/v10209-011-0012-y.pdf)
4. [NDMI012: Combinatorics and Graph Theory 2, Lecture 6 (Charles University)](https://iuuk.mff.cuni.cz/~ipenev/KG2S2022Lecture06.pdf)
5. [Strengthened Partial-Ordering Based ILP Models for the Vertex Coloring Problem](https://ar5iv.labs.arxiv.org/html/2206.13678)
6. [A Customized SAT-based Solver for Graph Coloring (ZykovColor)](https://arxiv.org/html/2504.04821)
7. [Lecture 1: ILP Formulations for the Graph Coloring Problem (Univ. of Bonn)](https://www.or.uni-bonn.de/~held/hausdorff_school_22/slides/GraphColoringFormulations.pdf)
8. [Richard M. Karp (1972). Reducibility among Combinatorial Problems. .](https://doi.org/10.1007/978-1-4684-2001-2_9)
9. [Course notes on greedy graph coloring (Harvard, Salil Vadhan)](https://salil.seas.harvard.edu/file_url/439)
10. [Chapter 13 Graph colouring algorithms (Husfeldt, survey chapter)](https://ar5iv.labs.arxiv.org/html/1505.05825)
11. [Obtaining the Grundy chromatic number: How bad can my greedy heuristic coloring be? (Computers & OR, 2024)](https://www.sciencedirect.com/science/article/abs/pii/S0305054824001758)
12. [SAT-boosted Tabu Search for Coloring Massive Graphs (GC-SLIM)](https://dl.acm.org/doi/fullHtml/10.1145/3603112)
13. [Coloring With a Limited Paintbox (AMS Notices)](https://www.ams.org//journals/notices/202206/noti2490/noti2490.html)
14. [Chapter 11. The Four-Colour Problem (Bondy & Murty notes)](https://faculty.etsu.edu/gardnerr/5340/notes-Bondy-Murty-GT/Bondy-Murty-GT-11-1.pdf)
15. [Gregory Chaitin (2004). Register allocation and spilling via graph coloring. ACM SIGPLAN Notices.](https://doi.org/10.1145/989393.989403)
16. [Equitable Coloring of Graphs (Springer reference-work chapter)](https://link.springer.com/rwe/10.1007/978-1-4614-6624-6_25-1)
17. [Results and Problems on Equitable Coloring of Graphs](https://ar5iv.labs.arxiv.org/html/2504.14711)
18. [Les Cahiers du GERAD: graph colouring models for scheduling with preferences](https://www.gerad.ca/~alainh/G1384.pdf)
19. [Computational Series: Graph Coloring and its Generalizations (COLOR04)](https://mat.tepper.cmu.edu/COLOR04/)
20. [An improved DSATUR-based Branch and Bound for the Vertex Coloring Problem](https://optimization-online.org/wp-content/uploads/2015/10/5159.pdf)
21. [From Cliques to Colorings and Back Again (CP 2022)](https://www.andrew.cmu.edu/user/vanhoeve/papers/cliques_coloring_CP2022.pdf)
22. [Chromatic Numbers from Exact Decision Diagrams in Exact Arithmetic](https://bonndata.uni-bonn.de/catalog/datasets/10.60507/FK2/ZE9C3L/)

---
*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 › Graph theory › Computational graph problems and algorithms › Graph coloring algorithms

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/vertex-coloring

English original: https://www.edgepedia.org/vertex-coloring
