# 2-可满足性

**2-可满足性**（2-SAT）是这样一个问题：判定一个合取范式的布尔公式——其中每个子句恰好包含两个文字——是否存在一个真值指派，使所有子句同时得到满足。它是布尔可满足性问题在多项式时间内可解的标准限制之一：一般 SAT 和 3-SAT 是 NP-完全的，而 2-SAT 可以通过构建蕴含的有向图并检查其强连通分量（图中相互可达的顶点的极大集合）在线性时间内求解。<sup>[1](https://neelmishra.github.io/blog/dsa/graphs/2-sat/index.html)</sup><sup> • </sup><sup>[2](https://courses.grainger.illinois.edu/cs473/fa2019/lectures/lecture23.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 输入 | 一个 2-CNF 公式：子句的合取，每个子句是恰好两个文字的析取，每个文字是一个变量或其否定<sup>[1](https://neelmishra.github.io/blog/dsa/graphs/2-sat/index.html)</sup> |
| 判定复杂度 | 可在多项式时间内求解，具体为线性时间<sup>[2](https://courses.grainger.illinois.edu/cs473/fa2019/lectures/lecture23.pdf)</sup> |
| 图规模 | 蕴含图有 2n 个顶点（每个文字一个）和 2m 条边，其中 m 为子句数<sup>[3](https://www.cl.cam.ac.uk/~mr10/qbf2slds.pdf)</sup> |
| 可满足性判据 | 公式可满足当且仅当不存在变量 x 及其否定 ¬x 位于同一个强连通分量中<sup>[4](https://github.com/cp-algorithms/cp-algorithms/blob/main/src/graph/2SAT.md)</sup> |
| 运行时间 | 该判据可通过求所有强连通分量在 O(n + m) 时间内验证<sup>[4](https://github.com/cp-algorithms/cp-algorithms/blob/main/src/graph/2SAT.md)</sup> |
| 计数变体 | #2-SAT，即计数满足赋值，是 #P-完全的<sup>[5](https://newton.kias.re.kr/~jaewan/AQIS2019/p2.pdf)</sup> |
| 经典文献 | Aspvall、Plass 和 Tarjan，*Information Processing Letters* 8(3):121–123，1979 年 3 月<sup>[6](https://doi.org/10.1016/0020-0190(79)90002-4)</sup> |

## 问题定义

输入由 n 个布尔变量 x_1, …, x_n 和一个合取范式（CNF）公式组成，该公式是子句的合取，其中每个子句是文字的析取，且每个子句恰好有两个文字。文字是一个变量或其否定。任务是判定是否存在某个真值指派使每个子句为真，并且在搜索版本中，产生这样的一个指派。<sup>[1](https://neelmishra.github.io/blog/dsa/graphs/2-sat/index.html)</sup><sup> • </sup><sup>[7](https://sandeepswain.dev/citadel/cp/two-sat)</sup>

单文字子句可以通过重复该文字来当作双文字子句处理，因为 (x) 等价于 (x ∨ x)，所以双文字假设不失一般性。<sup>[3](https://www.cl.cam.ac.uk/~mr10/qbf2slds.pdf)</sup>

2-SAT 位于可满足性内部可处理性的边界上。SAT 和 3-SAT 是 NP-完全的，目前不知道从 SAT 或 3-SAT 到 2-SAT 的多项式时间归约；如果存在这样的归约，SAT 和 3-SAT 就可在多项式时间内求解。归约失败的原因在单个子句中即可见：子句 (x ∨ y ∨ z) 无法在保持可满足性的前提下重写为同一组变量上的若干双文字子句。<sup>[2](https://courses.grainger.illinois.edu/cs473/fa2019/lectures/lecture23.pdf)</sup>

## 蕴含图

每个双文字子句等价于一对蕴含。子句 (a ∨ b) 等价于 ¬a → b 和 ¬b → a，因为如果 a 为假，则 b 必须为真；如果 b 为假，则 a 必须为真。其他子句形式 (a ∨ ¬b)、(¬a ∨ b) 和 (¬a ∨ ¬b) 按同一规则得到相应的蕴含对。<sup>[3](https://www.cl.cam.ac.uk/~mr10/qbf2slds.pdf)</sup>

公式的**蕴含图**为每个文字设一个顶点，n 个变量共 2n 个顶点，并为每个子句设置上述两条有向边，m 个子句共 2m 条边。例如，子句 (u ∨ ¬v) 转换为从 ¬u 到 ¬v 的弧和从 v 到 u 的弧。<sup>[3](https://www.cl.cam.ac.uk/~mr10/qbf2slds.pdf)</sup><sup> • </sup><sup>[8](https://upcommons.upc.edu/bitstreams/e7f49ee0-d114-46de-8c5c-d19da868d7c9/download)</sup>

该图编码了公式的逻辑：从文字 ℓ 到文字 ℓ′ 的任何路径意味着将 ℓ 设为真迫使 ℓ′ 也为真。

## 可满足性判据与算法

核心判据是一个图可达性条件。如果变量 x 及其否定 ¬x 位于同一个强连通分量中，则公式不可满足：x 蕴含 ¬x 且 ¬x 蕴含 x，因此 x 的任一真值都迫使其自身的否定，矛盾。<sup>[8](https://upcommons.upc.edu/bitstreams/e7f49ee0-d114-46de-8c5c-d19da868d7c9/download)</sup> 该条件不仅是必要的，也是充分的：如果对每个变量 x，顶点 x 和 ¬x 位于不同的强连通分量中，则公式存在满足赋值。<sup>[4](https://github.com/cp-algorithms/cp-algorithms/blob/main/src/graph/2SAT.md)</sup>

因此算法分三个阶段运行，每个阶段都是线性时间：

1. 从公式构建邻接表表示的蕴含图。<sup>[9](https://people.engr.tamu.edu/andreas-klappenecker/csce411-f18/csce411-2sat.pdf)</sup>
2. 计算强连通分量，例如使用 Kosaraju 算法（执行两次深度优先搜索，一次在图上，一次在其反向图上），或使用 Tarjan 算法。<sup>[8](https://upcommons.upc.edu/bitstreams/e7f49ee0-d114-46de-8c5c-d19da868d7c9/download)</sup><sup> • </sup><sup>[10](https://github.com/topics/2sat)</sup> 如果任何分量同时包含 x 和 ¬x，则报告不可满足。<sup>[8](https://upcommons.upc.edu/bitstreams/e7f49ee0-d114-46de-8c5c-d19da868d7c9/download)</sup>
3. 否则，从分量结构指派真值。强连通分量构成一个有向无环图，可以进行拓扑排序；当 ¬x 的分量先于 x 的分量时，将 x 设为真，反之设为假，即可得到一个满足赋值。正确性证明表明，被赋为真的变量不能到达其否定，也不能对任何其他变量 y 同时到达 y 和 ¬y，因为任一情况都会迫使 ¬x 从 x 可达。<sup>[4](https://github.com/cp-algorithms/cp-algorithms/blob/main/src/graph/2SAT.md)</sup><sup> • </sup><sup>[9](https://people.engr.tamu.edu/andreas-klappenecker/csce411-f18/csce411-2sat.pdf)</sup>

总运行时间为 O(n + m)，其中 n 是变量数，m 是子句数。<sup>[4](https://github.com/cp-algorithms/cp-algorithms/blob/main/src/graph/2SAT.md)</sup> 存在一种随机化替代方案：Papadimitriou 在 1991 年给出了一个基于随机游走的 2-SAT 算法。<sup>[11](https://www.cs.toronto.edu/~bor/373f17/docs/W12.pdf)</sup>

## 历史

蕴含图方法及其线性时间分析来自 1979 年的论文《一种用于测试某些量化布尔公式真值的线性时间算法》，作者为 Bengt Aspvall、Michael F. Plass 和 Robert Endre Tarjan，发表于 *Information Processing Letters* 第 8 卷，第 121–123 页。该论文处理每个子句至多两个文字的量化 CNF 公式，其中普通 2-SAT 是仅含存在量词的情形，并将真值测试归约为求有向图的强连通分量。<sup>[6](https://doi.org/10.1016/0020-0190(79)90002-4)</sup><sup> • </sup><sup>[3](https://www.cl.cam.ac.uk/~mr10/qbf2slds.pdf)</sup>

在复杂性理论中，2-SAT 也出现在 Schaefer 关于布尔约束满足的二分定理中：与 2-SAT 子句等价的关系构成了那里可处理的约束语言之一。<sup>[12](https://www.researchgate.net/publication/282544899_Tractability_in_Constraint_Satisfaction_Problems_A_Survey)</sup>

## 计数解：#2-SAT

对于 2-CNF，判定可满足性是容易的，但计数满足赋值则不然。问题 #2-SAT 要求给出 2-CNF 公式的满足赋值（也称为模型）的数量，它是 #P-完全的。<sup>[5](https://newton.kias.re.kr/~jaewan/AQIS2019/p2.pdf)</sup> 即使在严格的限制下，困难性依然存在：对于 2MONCNF，即同时是单调的（没有否定文字）和 2-CNF 的公式，可满足性是平凡的，因为将所有变量设为真即可满足公式，但计数模型是 #P-完全的，并且对任何正常数 \( \epsilon \)，在因子 \( 2^{n^{1-\epsilon}} \) 内近似计数是 NP-困难的。<sup>[13](https://www.cs.cornell.edu/selman/papers/pdf/05.sat.new-approach-model-counting.pdf)</sup> 单调 2CNF 的满足赋值计数同样没有完全多项式随机近似方案（FPRAS），除非 RP = NP。<sup>[14](https://renyi.hu/~miklosi/CCC/ComputationalComplexityOfCountingAndSampling.pdf)</sup>

尽管如此，精确计数仍有比穷举搜索更快的算法。2010 年，Zhou 等人给出了 #2-SAT 的 \( \mathcal{O}^*(1.1892^m) \) 时间算法，其中 m 是子句数，\( \mathcal{O}^* \) 记号省略了多项式因子。2025 年，Junqiang Peng、Zimo Sheng 和 Mingyu Xiao 证明了 #2-SAT 和 #3-SAT 的加权版本可以分别在 \( \mathcal{O}^*(1.1082^m) \) 和 \( \mathcal{O}^*(1.4423^m) \) 时间内求解，这些结果直接适用于非加权情形，并改进了之前的界；他们的方法结合了新的归约规则、精细的分支分析以及公式的原始图和对偶图的路径分解。<sup>[15](https://arxiv.org/abs/2507.14504)</sup>

## 相关问题

**Max-2-SAT。** 将要求从满足所有子句放宽为满足尽可能多的子句会恢复困难性：即使每个子句至多包含两个文字，最大可满足性问题也是 NP-完全的（MAX-2-SAT）。<sup>[16](https://doi.org/10.1016/S0166-218X(02)00402-X)</sup> 该类问题存在快速指数时间算法：对于有 n 个变量和 m 个二元子句的实例，Scott 和 Sorkin 给出了针对 r 值变量的 Max 2-CSP 问题的 \( O(n r^{5+19m/100}) \) 时间算法，涵盖了 Max 2-Sat 和 Max Cut。<sup>[17](https://arxiv.org/abs/cs/0604080)</sup>

**量子 2-SAT。** 2-量子可满足性问题将 2-CNF 可满足性推广到量子比特，等价于判定一个具有两体项的自旋-1/2 哈密顿量是否无阻挫。其计数版本 #2-QSAT 与经典 #2-SAT 一样是 #P-完全的。<sup>[18](https://arxiv.org/abs/1403.1588)</sup> Bravyi 证明了量子 2-SAT 在代数计算模型中有确定性的 \( O(n^4) \) 算法，其中 n 是变量数；后来的结果给出了确定性的 \( O(n+m) \) 算法，其中 m 是局部投影算符的数量，在该模型中达到了最优复杂度。<sup>[19](https://zesty.cs.uchicago.edu/articles/v014a001/)</sup>

**应用。** 蕴含图构造被用作建模工具：例如，调度冲突可以编码为成对约束，并转化为一个 2-SAT 实例，其蕴含图由冲突约束构建。<sup>[20](https://repovive.com/roadmaps/graph-theory/2-sat/modeling-scheduling)</sup> 更广泛地说，通用类型的 SAT 求解器——而非专门的 2-SAT 算法——被应用于诸如课程时间表和员工排班等实际调度问题。<sup>[21](https://ideas.repec.org/a/inm/orinte/v47y2017i6p537-554.html)</sup><sup> • </sup><sup>[22](https://doaj.org/article/12e8748c4a554a81bce74d0895cf6711)</sup>

## References

1. [2-SAT – Boolean Satisfiability via Implication Graphs, Neel Mishra](https://neelmishra.github.io/blog/dsa/graphs/2-sat/index.html)
2. [CS 473: Algorithms, Fall 2019, Lecture 23, University of Illinois](https://courses.grainger.illinois.edu/cs473/fa2019/lectures/lecture23.pdf)
3. [Martin Richards, presentation of Aspvall, Plass, and Tarjan (1979), University of Cambridge Computer Laboratory](https://www.cl.cam.ac.uk/~mr10/qbf2slds.pdf)
4. [2-SAT, cp-algorithms](https://github.com/cp-algorithms/cp-algorithms/blob/main/src/graph/2SAT.md)
5. [AQIS 2019 paper reducing #2-SAT to quantum counting problems, Korea Institute for Advanced Study](https://newton.kias.re.kr/~jaewan/AQIS2019/p2.pdf)
6. [Bengt Aspvall, Michael F. Plass, Robert Endre Tarjan (1979). A linear-time algorithm for testing the truth of certain quantified Boolean formulas. Information Processing Letters 8(3):121–123.](https://doi.org/10.1016/0020-0190(79)90002-4)
7. [2-SAT – Implication Graphs and Strongly Connected Components, Sandeep Swain](https://sandeepswain.dev/citadel/cp/two-sat)
8. [Analysis and solution of graph problems (course notes on strongly connected components and 2-SAT), Universitat Politècnica de Catalunya](https://upcommons.upc.edu/bitstreams/e7f49ee0-d114-46de-8c5c-d19da868d7c9/download)
9. [Andreas Klappenecker, CSCE 411 lecture notes on 2-SAT, Texas A&M University](https://people.engr.tamu.edu/andreas-klappenecker/csce411-f18/csce411-2sat.pdf)
10. [2sat topic, GitHub](https://github.com/topics/2sat)
11. [CSC373 lecture notes on algorithm design, University of Toronto](https://www.cs.toronto.edu/~bor/373f17/docs/W12.pdf)
12. [Tractability in Constraint Satisfaction Problems: A Survey](https://www.researchgate.net/publication/282544899_Tractability_in_Constraint_Satisfaction_Problems_A_Survey)
13. [Carla Gomes, Ashish Sabharwal, Bart Selman (2005). Model counting (ApproxCount paper), Cornell University](https://www.cs.cornell.edu/selman/papers/pdf/05.sat.new-approach-model-counting.pdf)
14. [Computational complexity of counting and sampling (section on #IS and #Mon-2SAT), Rényi Institute](https://renyi.hu/~miklosi/CCC/ComputationalComplexityOfCountingAndSampling.pdf)
15. [Junqiang Peng, Zimo Sheng, Mingyu Xiao (2025). New Algorithms for #2-SAT and #3-SAT. arXiv:2507.14504](https://arxiv.org/abs/2507.14504)
16. [Worst-case upper bounds for MAX-2-SAT with an application to MAX-CUT, Discrete Applied Mathematics](https://doi.org/10.1016/S0166-218X(02)00402-X)
17. [Alexander D. Scott, Gregory B. Sorkin. Linear-programming design and analysis of fast algorithms for Max 2-Sat and Max 2-CSP. arXiv:cs/0604080](https://arxiv.org/abs/cs/0604080)
18. [Niel de Beaudrap (2014). Difficult instances of the counting problem for 2-quantum-SAT are very atypical. arXiv:1403.1588](https://arxiv.org/abs/1403.1588)
19. [Linear-Time Algorithm for Quantum 2SAT, Theory of Computing](https://zesty.cs.uchicago.edu/articles/v014a001/)
20. [Modeling Scheduling – 2-SAT, Repovive graph theory notes](https://repovive.com/roadmaps/graph-theory/2-sat/modeling-scheduling)
21. [Ofer Strichman (2017). Near-Optimal Course Scheduling at the Technion. Interfaces 47(6):537–554.](https://ideas.repec.org/a/inm/orinte/v47y2017i6p537-554.html)
22. [Employee Scheduling With SAT-Based Pseudo-Boolean Constraint Solving, DOAJ](https://doaj.org/article/12e8748c4a554a81bce74d0895cf6711)

---
*Initially written Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 逻辑与离散数学 › Formal logic and foundations › Logical calculi and logical syntax › Propositional logic › CNF satisfiability algorithms

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/2-satisfiability

English original: https://www.edgepedia.org/2-satisfiability
