# 平面性检验

**平面性检验**是判定给定图是否为平面图的算法问题，即能否在平面中画出该图而任意两条边都不相交；通常还要求在答案为是或否时分别给出一个平面嵌入或一个非平面性证书。<sup>[1](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.planarity.check_planarity.html)</sup> 该问题可在线性时间内求解，这一结果由[约翰·霍普克罗夫特](https://www.edgepedia.org/zh/john-hopcroft)（John Hopcroft）与罗伯特·塔扬（Robert Tarjan）于 1974 年首次确立；NetworkX 和 Boost 图库（Boost Graph Library）等主流图库中已有高效实现。<sup>[2](https://doi.org/10.1145/321850.321852)</sup><sup> • </sup><sup>[3](https://www.boost.org/doc/libs/latest/libs/graph/doc/html/graph/algorithms/planar/boyer_myrvold.html)</sup>

| 关键事实 | 细节 |
|---|---|
| 定义 | 一个图是平面图，当且仅当它能在平面中画出而没有任何边相交<sup>[1](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.planarity.check_planarity.html)</sup> |
| 刻画 | 一个简单图是平面图，当且仅当它不包含任何作为 K₅ 或 K₃,₃ 之扩张的子图（库拉托夫斯基（Kuratowski）定理）<sup>[4](https://www.boost.org/doc/libs/latest/libs/graph/doc/html/graph/algorithms/planar/planar_graphs.html)</sup> |
| 边数上界 | 含 n 个顶点的平面图至多有 3n − 6 条边和 2n − 4 个面；欧拉（Euler）公式为 n + f = e + c + 1<sup>[4](https://www.boost.org/doc/libs/latest/libs/graph/doc/html/graph/algorithms/planar/planar_graphs.html)</sup> |
| 复杂度 | 判定平面性需要 O(n) 时间；在非平面画法中最小化交叉数是 NP 完全的<sup>[2](https://doi.org/10.1145/321850.321852)</sup><sup> • </sup><sup>[5](https://technav.ieee.org/topic/graph-drawing/)</sup> |
| 首个线性算法 | 霍普克罗夫特与塔扬，1974 年，使用深度优先搜索与路径添加，时间为 O(V)，空间为 O(V)<sup>[2](https://doi.org/10.1145/321850.321852)</sup> |
| 输出 | 一个平面（组合）嵌入，即每个顶点处关联边的循环次序；或者一个作为非平面性证书的库拉托夫斯基子图<sup>[1](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.planarity.check_planarity.html)</sup> |
| 库实现 | NetworkX 使用左右平面性检验；Boost 使用 Boyer-Myrvold 算法<sup>[1](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.planarity.check_planarity.html)</sup><sup> • </sup><sup>[3](https://www.boost.org/doc/libs/latest/libs/graph/doc/html/graph/algorithms/planar/boyer_myrvold.html)</sup> |

## 平面嵌入

平面性检验通常不只返回是或否。当图是平面图时，有用的输出是一个平面嵌入，也称为组合嵌入：对每个顶点，给出其关联边的一个循环（顺时针或逆时针）次序。该嵌入记录了无交叉画法的拓扑结构，而不固定边长、边形状或顶点位置；实际画法只是该拓扑的无穷多种实例化之一。<sup>[1](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.planarity.check_planarity.html)</sup><sup> • </sup><sup>[6](https://www.csd.uoc.gr/~hy583/papers/ch15.pdf)</sup> 嵌入是连接检验与下游算法（如面遍历和直线绘制）的核心数据结构。<sup>[4](https://www.boost.org/doc/libs/latest/libs/graph/doc/html/graph/algorithms/planar/planar_graphs.html)</sup>

当图不是平面图时，许多算法可以返回一个库拉托夫斯基子图，即一小组边，它们可以收缩成 K₅ 或 K₃,₃，作为可检验的非平面性证明。在 Boost 中，返回的边集可以用函数 `is_kuratowski_subgraph` 验证；在 NetworkX 中，反例生成是可选的，因为它比检验本身更昂贵。<sup>[3](https://www.boost.org/doc/libs/latest/libs/graph/doc/html/graph/algorithms/planar/boyer_myrvold.html)</sup><sup> • </sup><sup>[1](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.planarity.check_planarity.html)</sup>

## 平面性的刻画

两个经典结果为大多数检验奠定了基础。[库拉托夫斯基定理](https://www.edgepedia.org/zh/kuratowskis-theorem)指出，一个没有自环或平行边的图是平面图，当且仅当它不包含任何作为完全图 K₅ 或完全二部图 K₃,₃ 之扩张的子图。瓦格纳（Wagner）定理用图子式给出了类似陈述。[欧拉公式](https://www.edgepedia.org/zh/eulers-formula)给出稀疏性上界：含 n 个顶点的平面图至多有 3n − 6 条边，因此平面图是稀疏的，其边可以在线性时间内逐条检查。<sup>[4](https://www.boost.org/doc/libs/latest/libs/graph/doc/html/graph/algorithms/planar/planar_graphs.html)</sup><sup> • </sup><sup>[6](https://www.csd.uoc.gr/~hy583/papers/ch15.pdf)</sup>

边数上界也界定了证明非平面性所需的工作量。欧拉公式意味着，含 n 个顶点的非平面图必定在某个含 3n − 5 条边的子图内包含一个库拉托夫斯基子图；因此，在检验稠密图时，可以把任意选定的 3n − 5 条边交给算法，仍能在 O(n) 时间内得到证书。<sup>[3](https://www.boost.org/doc/libs/latest/libs/graph/doc/html/graph/algorithms/planar/boyer_myrvold.html)</sup>

## 算法史

**早期方法。** 奥斯兰德（Auslander）与帕特（Parter）于 1961 年提出了首个解法，戈德斯坦（Goldstein）于 1963 年作了修正；德穆克龙（Demoucron）、马尔格朗斯（Malgrance）与佩尔蒂塞（Pertuiset）于 1964 年给出了另一种算法。伦佩尔（Lempel）、埃文（Even）与塞德鲍姆（Cederbaum）于 1967 年给出了一个运行时间为 O(n³) 的顶点添加算法，使用由 st 编号引导的顶点添加。<sup>[6](https://www.csd.uoc.gr/~hy583/papers/ch15.pdf)</sup>

**线性时间。** 1974 年，霍普克罗夫特与塔扬取得突破：一种基于深度优先搜索的奥斯兰德-帕特方法的迭代形式，能在 O(V) 时间与空间内检验平面性。他们的 ALGOL 实现能在不到 12 秒内检验多达 900 个顶点的图。然而，该算法最初只返回是或否的答案，且被广泛认为难以解释和实现。<sup>[2](https://doi.org/10.1145/321850.321852)</sup><sup> • </sup><sup>[6](https://www.csd.uoc.gr/~hy583/papers/ch15.pdf)</sup>

**使顶点添加线性化。** 1976 年，两项独立结果表明伦佩尔-埃文-塞德鲍姆方法也可以在线性时间内运行：埃文与塔扬证明，双连通图的 st 次序可以在线性时间内找到；布斯（Booth）与卢克（Lueker）引入了 PQ 树，这是一种表示所有允许次序、并在线性时间内检验所需连续性条件的数据结构。千叶（Chiba）及其同事于 1985 年展示了如何从该算法中提取平面嵌入。<sup>[6](https://www.csd.uoc.gr/~hy583/papers/ch15.pdf)</sup>

**边添加与左右检验。** 博耶（Boyer）与米尔沃尔德（Myrvold）沿用 1999 年一种与施-许（Shih-Hsu）PC 树方法有关的表述，于 2004 年发表了一种简化的 O(n) 方法：每次向部分嵌入中添加一条边，用路径遍历过程中的少量局部决策取代批量平面性条件检验。<sup>[6](https://www.csd.uoc.gr/~hy583/papers/ch15.pdf)</sup><sup> • </sup><sup>[7](https://jgaa-v5.cs.brown.edu/index.php/jgaa/article/view/paper91)</sup> 另一条线索是平面性的左右刻画，从 1955 年的吴（Wu）经 1982 年的德弗雷塞（de Fraysseix）与罗森斯蒂尔（Rosenstiehl），一直发展到 2006 年的德弗雷塞、奥索纳·德·门德斯（Ossona de Mendez）与罗森斯蒂尔；康斯坦茨大学（University of Konstanz）的计算机科学家乌尔里克·布兰德斯（Ulrik Brandes）于 2009 年对这些算法作了详细阐述，并指出该方法避免了 PQ 树之类棘手的数据结构。<sup>[8](https://citeseerx.ist.psu.edu/document?doi=a9cb4d8e8d25de33f693132d6fc48a81a3e5c179&repid=rep1&type=pdf)</sup>

## 算法族

综述文献区分线性时间算法的两大流派：伦佩尔、埃文与塞德鲍姆开创的顶点添加方法，逐个把顶点加入部分嵌入；以及霍普克罗夫特与塔扬开创的路径添加方法，合并整条整条的路径。左右方法通常被视为第三种独立方法。<sup>[8](https://citeseerx.ist.psu.edu/document?doi=a9cb4d8e8d25de33f693132d6fc48a81a3e5c179&repid=rep1&type=pdf)</sup>

霍普克罗夫特-塔扬路径添加方法作用于双连通图的深度优先搜索树。它选择一个环，识别附着于其上的各分量（段），递归检验每一段是否满足文献所称的强平面性，并检查各段是否交错，即两段是否无法在不交叉的情况下置于环的同一侧，因而必须画在不同侧。<sup>[6](https://www.csd.uoc.gr/~hy583/papers/ch15.pdf)</sup> 每一段置于左侧还是右侧的决策会被记录下来，这些标记决定如何重排邻接表以产生嵌入。<sup>[6](https://www.csd.uoc.gr/~hy583/papers/ch15.pdf)</sup>

博耶-米尔沃尔德边添加方法把单条边视为加入部分嵌入的基本单位，利用一条边就能使子图变为双连通这一事实。在 Boost 实现中，大多数情况下运行时间为 O(n)，在稠密图上要求进行库拉托夫斯基子图隔离时为 O(n + m)；它接受任意无向图，包括带自环和重边的图。<sup>[7](https://jgaa-v5.cs.brown.edu/index.php/jgaa/article/view/paper91)</sup><sup> • </sup><sup>[3](https://www.boost.org/doc/libs/latest/libs/graph/doc/html/graph/algorithms/planar/boyer_myrvold.html)</sup>

## 实现

NetworkX 的 `check_planarity` 函数基于左右平面性检验，返回一个元组：一个布尔值，以及当图为平面图时的一个 `PlanarEmbedding` 对象，或在设置 `counterexample` 参数时的一个库拉托夫斯基子图。更轻量的 `is_planar` 函数只检验平面性，不构造嵌入或反例。<sup>[1](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.planarity.check_planarity.html)</sup> 独立的 `planarity` Python 包封装了边添加平面性套件（Edge Addition Planarity Suite，EAPS），为 Python 与 NetworkX 开发者提供检验、嵌入、绘制和禁用于图隔离功能。<sup>[9](https://github.com/graph-algorithms/planarity)</sup> 在 C++ 中，Boost 图库提供 `boyer_myrvold_planarity_test` 以及一条完整流水线：用 `make_connected`、`make_biconnected_planar` 和 `make_maximal_planar` 增广图，用 `planar_canonical_ordering` 产生顶点次序，用 `chrobak_payne_straight_line_drawing` 在 (2n − 4) × (n − 2) 网格上计算整数坐标，并提供用于嵌入和库拉托夫斯基证书的验证函数。<sup>[4](https://www.boost.org/doc/libs/latest/libs/graph/doc/html/graph/algorithms/planar/planar_graphs.html)</sup>

## 应用

**电路设计。** 一个经典动机来自超大规模集成电路（VLSI）与印刷电路设计：电路被建模为图，边对应导线；交叉意味着两条路径发生连通，从而对电路逻辑产生副作用。1973 年[贝尔实验室](https://www.edgepedia.org/zh/bell-labs)（Bell Labs）的一项研究把能否在不使用交叉或多层布线的情况下完成互连这一问题，表述为对表示电路的图进行平面性检验，并讨论了将模块与网络映射到图顶点和边的选择如何影响模型。<sup>[6](https://www.csd.uoc.gr/~hy583/papers/ch15.pdf)</sup><sup> • </sup><sup>[10](https://www.nokia.com/bell-labs/publications-and-media/publications/a-proper-model-for-testing-the-planarity-of-electrical-circuits/)</sup>

**图绘制。** 平面性检验是图绘制流水线的第一步，而复杂度对比十分鲜明：检验是否存在无交叉嵌入可在线性时间内解决，而在非平面画法中最小化交叉数是 NP 完全的，因此精确交叉最小化只对小图可行，实践中以启发式方法为主。相关的绘制问题继承了这一结构；例如，判定一个图是否为 1-平面图，即每条边至多被交叉一次，即使对受限图类也是 NP 完全的。<sup>[5](https://technav.ieee.org/topic/graph-drawing/)</sup><sup> • </sup><sup>[11](https://arxiv.org/abs/1911.00573)</sup>

**稀疏性驱动的算法。** 由于欧拉公式把平面图的边数限制在约为顶点数的三倍，平面性常被用作进入那些运行时间依赖稀疏性的算法的入口，应用于道路网络以及其他嵌入平面曲面的结构等领域。<sup>[6](https://www.csd.uoc.gr/~hy583/papers/ch15.pdf)</sup>

## 变体与动态情形

基本判定问题衍生出带约束的变体。在部分嵌入平面性问题中，输入是一个图连同其某个子图的拓扑画法，问题是该画法能否无交叉地扩展到整个图；安杰利尼（Angelini）及其同事于 2010 年给出了一个线性时间算法，而 2024 年一个基于修改版 PC 树的顶点添加算法给出了更简单的独立解法。<sup>[12](https://arxiv.org/abs/2410.13536)</sup> 其他变体固定顶点划分或方向，例如有向图的带状平面性与多级平面性。<sup>[13](https://arxiv.org/abs/1309.0683)</sup><sup> • </sup><sup>[14](https://arxiv.org/abs/1810.13297)</sup>

动态平面性检验维护一个位，指示一个随时间变化的图当前是否为平面图。雅各布·霍尔姆（Jacob Holm）与伊娃·罗滕贝格（Eva Rotenberg）——两人都是研究动态图算法的计算机科学家——提出的增量算法以 O(log³ n) 最坏情况时间处理每次边插入，依赖于一个 O(log² n) 的全动态数据结构，用以在边插入、删除和翻转下维护平面嵌入。<sup>[15](https://backend.orbit.dtu.dk/ws/files/377544371/LIPIcs.ESA.2024.70.pdf)</sup>

## References

1. [check_planarity, NetworkX 3.7 documentation](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.planarity.check_planarity.html)
2. [John Hopcroft, Robert Tarjan (1974). Efficient Planarity Testing. Journal of the ACM 21(4), 549–568.](https://doi.org/10.1145/321850.321852)
3. [boost.org](https://www.boost.org/doc/libs/latest/libs/graph/doc/html/graph/algorithms/planar/boyer_myrvold.html)
4. [Planar Graphs, Boost.Graph Documentation](https://www.boost.org/doc/libs/latest/libs/graph/doc/html/graph/algorithms/planar/planar_graphs.html)
5. [Graph Drawing, IEEE Technology Navigator](https://technav.ieee.org/topic/graph-drawing/)
6. [Planarity Testing (course chapter, University of Crete, HY583)](https://www.csd.uoc.gr/~hy583/papers/ch15.pdf)
7. [John Boyer, Wendy Myrvold (2004). On the Cutting Edge: Simplified O(n) Planarity by Edge Addition. Journal of Graph Algorithms and Applications 8(3), 241–273.](https://jgaa-v5.cs.brown.edu/index.php/jgaa/article/view/paper91)
8. [Ulrik Brandes (2009). The Left-Right Planarity Test.](https://citeseerx.ist.psu.edu/document?doi=a9cb4d8e8d25de33f693132d6fc48a81a3e5c179&repid=rep1&type=pdf)
9. [graph-algorithms/planarity, GitHub](https://github.com/graph-algorithms/planarity)
10. [A Proper Model for Testing the Planarity of Electrical Circuits, Nokia Bell Labs (1973)](https://www.nokia.com/bell-labs/publications-and-media/publications/a-proper-model-for-testing-the-planarity-of-electrical-circuits/)
11. [An Experimental Study of a 1-planarity Testing and Embedding Algorithm, arXiv](https://arxiv.org/abs/1911.00573)
12. [Simon D. Fink, Ignaz Rutter, Sandhya T. P (2024). A Simple Partially Embedded Planarity Test Based on Vertex-Addition. arXiv.](https://arxiv.org/abs/2410.13536)
13. [Strip Planarity Testing of Embedded Planar Graphs, arXiv](https://arxiv.org/abs/1309.0683)
14. [Multilevel Planarity, arXiv](https://arxiv.org/abs/1810.13297)
15. [Dynamic planarity testing discussion, ESA 2024 proceedings (DTU Orbit)](https://backend.orbit.dtu.dk/ws/files/377544371/LIPIcs.ESA.2024.70.pdf)

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

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

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/planarity-testing

English original: https://www.edgepedia.org/planarity-testing
