# 回答集编程

回答集编程（ASP）是一种声明式逻辑编程范式，用于组合搜索和知识表示：一个问题被编码为规则，其稳定模型（称为回答集）对应该问题的解，而一个称为回答集求解器的程序负责计算这些回答集。<sup>[1](https://cdn.aaai.org/AAAI/2008/AAAI08-270.pdf)</sup> 与 Prolog 不同，求解器不接受查询作为输入；它唯一期望的输入是程序本身，输出则是该程序的回答集。<sup>[2](https://ojs.aaai.org/aimagazine/index.php/aimagazine/article/download/2670/2572)</sup> 几乎所有实现都遵循两步求值流程：基化器将带变量的程序转换为等价的无变量程序，然后求解器在该命题程序上搜索回答集。<sup>[3](https://www.ijcai.org/proceedings/2018/0769.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 输入与输出 | 求解器只接受程序，不接受查询，并打印程序的回答集<sup>[2](https://ojs.aaai.org/aimagazine/index.php/aimagazine/article/download/2670/2572)</sup> |
| 回答集的定义 | 一个原子集合，它是程序归约的最小模型<sup>[4](https://arxiv.org/html/2607.08136)</sup> |
| 解的数量 | 一个程序可以没有稳定模型，也可以有一个或多个；其语义是非单调的<sup>[5](https://mag.di.unimi.it/aiclass/aa0405/asp-primer.pdf)</sup> |
| 求值工作流 | 建模、基化、求解，依次进行<sup>[3](https://www.ijcai.org/proceedings/2018/0769.pdf)</sup> |
| 复杂度 | 判定一个程序是否有回答集是 NP 完全的；对于析取程序则是 \( \Sigma_{2}^{P} \) 完全的<sup>[6](https://link.springer.com/article/10.1007/s10601-016-9257-7)</sup> |
| 代表性求解器 | DLV，由 Leone 及其同事报告（2006）<sup>[7](https://doi.org/10.1145/1149114.1149117)</sup>；以及冲突驱动的 clasp，由 Gebser、Kaufmann 和 Schaub 报告（2012）<sup>[8](https://doi.org/10.1016/j.artint.2012.04.001)</sup> |
| 有文献记载的应用 | 航天飞机规划与诊断、产品配置、系统发育推断<sup>[1](https://cdn.aaai.org/AAAI/2008/AAAI08-270.pdf)</sup> |

## 工作原理

对于不含否定的正程序，回答集是在规则下封闭的最小基原子集合。否定需要借助 Gelfond–Lifschitz 归约。给定程序 \( \Pi \) 和解释 \( I \)，归约的获得方式是：丢弃所有体中含有默认否定文字 \( \mathit{not}\, c \) 且 \( c \in I \) 的规则，然后从剩余规则体中移除所有默认否定文字；\( I \) 是稳定模型（即回答集），当且仅当它在集合包含关系下是归约的最小模型。<sup>[4](https://arxiv.org/html/2607.08136)</sup> 等价地说，稳定模型满足一种不动点式方程：删除否定文字为假的规则，并检查结果是否返回原集合。<sup>[5](https://mag.di.unimi.it/aiclass/aa0405/asp-primer.pdf)</sup> 之所以需要归约，是因为失败即否定是非单调的：向程序添加新信息可能迫使推理者撤回先前的结论，因此程序的含义无法用普通的最小模型语义来刻画。在一般形式中，命题公式 \( F \) 相对于原子集合 \( X \) 的归约 \( F^{X} \) 将每个不被 \( X \) 满足的极大子公式替换为假，而 \( X \) 是稳定的，当它在满足 \( F^{X} \) 的集合中最小。<sup>[1](https://cdn.aaai.org/AAAI/2008/AAAI08-270.pdf)</sup> 程序可以没有稳定模型，也可以有一个或多个：两条规则的例子 \( \mathit{happy} \leftarrow \mathit{not}\, \mathit{sad} \)、\( \mathit{sad} \leftarrow \mathit{not}\, \mathit{happy} \) 有两个稳定模型，而 \( f \leftarrow \mathit{not}\, f \) 没有。<sup>[5](https://mag.di.unimi.it/aiclass/aa0405/asp-primer.pdf)</sup> 早期关于失败即否定的一个方案——程序完成——后来成为通往可满足性测试的桥梁。<sup>[9](https://ar5iv.labs.arxiv.org/html/1108.3281)</sup>

## 如何实现

实践者遵循建模、基化、求解的工作流。<sup>[10](https://www.cs.uni-potsdam.de/wv/publications/DBLP_journals/aim/KaufmannLPS16.pdf)</sup> 建模通常采用生成—定义—测试方法：选择规则生成潜在解，约束消除坏解，辅助谓词由 Prolog 风格的规则定义，例如基数至少为 10 的团或哈密顿回路的编码。<sup>[1](https://cdn.aaai.org/AAAI/2008/AAAI08-270.pdf)</sup> 优化部分使用优化语句或弱约束，将解与待最小化的代价关联起来。<sup>[11](https://www.cs.uni-potsdam.de/wv/publications/DBLP_journals/aim/GebserS16.pdf)</sup> 随后基化器用基项替换变量；现代基化器如 gringo 使用半朴素数据库求值，当输入是带变量的程序时基化是 EXPTIME 困难的，而得到的基程序规模可能是指数级的。<sup>[10](https://www.cs.uni-potsdam.de/wv/publications/DBLP_journals/aim/KaufmannLPS16.pdf)</sup>

早期的原生求解器如 smodels 和 DLV<sup>[7](https://doi.org/10.1145/1149114.1149117)</sup> 扩展了 DPLL 过程，加入专门的无基集推理。第二代求解器如 clasp 集成了 CDCL 风格的搜索，将 ASP 推理映射为禁集上的单元传播：完成禁集是显式的，而环公式禁集在违反时变为显式，由无基集算法检测；clasp 还加入了预处理、监视文字、基于活跃度的启发式、重启、冲突子句学习、共享学习禁集的并行求解，以及用于枚举和优化的枚举器。<sup>[3](https://www.ijcai.org/proceedings/2018/0769.pdf)</sup><sup> • </sup><sup>[10](https://www.cs.uni-potsdam.de/wv/publications/DBLP_journals/aim/KaufmannLPS16.pdf)</sup> 基于翻译的求解器走另一条路：cmodels 通过子句化的完成计算紧程序的回答集，并调用外部 SAT 求解器如 minisat。<sup>[6](https://link.springer.com/article/10.1007/s10601-016-9257-7)</sup>

## 起源

Prolog 否定的语义在 ASP 之前以“合宜模型”之名被研究过，这是一个在若干独立出版物中发展出的等价概念；成为标准参考文献的版本引入了“稳定模型”这一术语。<sup>[12](https://www.cs.utexas.edu/~vl/papers/felicitous-final.pdf)</sup> ASP 作为一种编程范式，由 Marek 和 Truszczyński 的论文（1998，arXiv）<sup>[13](https://doi.org/10.48550/arxiv.cs/9809032)</sup> 以及 Niemelä 的论文（1999，Annals of Mathematics and Artificial Intelligence）<sup>[14](https://doi.org/10.1023/a:1018930122475)</sup> 所框定，后者提出将稳定模型语义下的逻辑程序作为组合搜索的约束编程范式；“回答集编程”一词首次被用作某文集一部分的标题，前述第一篇论文即发表于该文集。<sup>[1](https://cdn.aaai.org/AAAI/2008/AAAI08-270.pdf)</sup> 在这一提案中，用表示实例的事实扩展后的程序的回答集与该实例的解一一对应，这种编码非常适合 NP 中的问题。<sup>[15](https://www.cambridge.org/core/journals/theory-and-practice-of-logic-programming/article/historical-review-of-variants-of-informal-semantics-for-logic-programs-under-answer-set-semantics-gl88-gl91-gk14-dv12/C8DEF6D26A6AAD41177D0BCE9EA37239)</sup> Van Gelder、Ross 和 Schlipf（1991，Journal of the ACM）的良基语义启发了早期求解器的强传播方法。<sup>[16](https://doi.org/10.1145/116825.116838)</sup> 早期求解器 smodels 之后是 DLV，由 Leone 及其同事报告（2006，ACM Transactions on Computational Logic）<sup>[7](https://doi.org/10.1145/1149114.1149117)</sup>；以及 clingo，围绕 Gebser、Kaufmann 和 Schaub 的 clasp 求解器构建（2012，Artificial Intelligence）。<sup>[8](https://doi.org/10.1016/j.artint.2012.04.001)</sup>

## 变体

非析取逻辑程序可以紧凑地表示 NP 和 coNP 中的所有问题，而析取程序则刻画 \( \Sigma_{2}^{P} \) 和 \( \Pi_{2}^{P} \)。<sup>[3](https://www.ijcai.org/proceedings/2018/0769.pdf)</sup> 语言扩展拓宽了这一范围。带边界的选择规则以及约束是标准配置，约束消除满足其体的回答集。<sup>[2](https://ojs.aaai.org/aimagazine/index.php/aimagazine/article/download/2670/2572)</sup> Gelfond 和 Lifschitz（1991）将经典否定加入逻辑程序。<sup>[17](https://doi.org/10.1007/bf03037169)</sup> 非单调递归聚合，如同析取规则，允许表达多项式层级第二层的问题。<sup>[11](https://www.cs.uni-potsdam.de/wv/publications/DBLP_journals/aim/GebserS16.pdf)</sup> HEX 程序为 ASP 配备外部知识或计算源，由 DLVHEX 系统集成。<sup>[3](https://www.ijcai.org/proceedings/2018/0769.pdf)</sup> 带量词的 ASP 扩展 ASP(Q) 被提出，用于在整个多项式层级上建模问题，超越标准 ASP 的 \( \Sigma_{2}^{P} \) 上限。<sup>[18](https://drops.dagstuhl.de/storage/01oasics/oasics-vol138-rw2024+rw2025/OASIcs.RW.2024-2025.8/OASIcs.RW.2024-2025.8.pdf)</sup> 在 clingo 中实现的多重求解使基化和求解过程在持续变化的逻辑程序下保持运行。<sup>[19](https://www.cambridge.org/core/journals/theory-and-practice-of-logic-programming/article/abs/multishot-asp-solving-with-clingo/FAED3429900D84CDD5155326A36548F2)</sup>

## 应用

有文献记载的应用包括[航天飞机](https://www.edgepedia.org/zh/space-shuttle)规划与诊断、催生了基于网络的配置器的产品配置，以及面向语言和寄主—寄生虫系统的系统发育树推断。<sup>[1](https://cdn.aaai.org/AAAI/2008/AAAI08-270.pdf)</sup> smodels 早期用于一个重要计算问题的场景包括规划生成。<sup>[12](https://www.cs.utexas.edu/~vl/papers/felicitous-final.pdf)</sup>

## 局限与替代方案

传统的基化—求解架构有一个内在局限，即基化瓶颈：一个或少数几个约束的基化可能在计算上难以承受。<sup>[20](https://www.ijcai.org/proceedings/2020/0234.pdf)</sup> 对于带变量的程序，基化是 EXPTIME 困难的<sup>[10](https://www.cs.uni-potsdam.de/wv/publications/DBLP_journals/aim/KaufmannLPS16.pdf)</sup>，而带函数符号或递归聚合的规则的系统实例化在最坏情况下是无限的，因此基化器依赖简化和近似，这使它们对输入程序具有顺序依赖性。<sup>[21](https://www.cambridge.org/core/services/aop-cambridge-core/content/view/573D6EDC447B516CF2A5D90B1A262332/S1471068422000308a.pdf/on_the_foundations_of_grounding_in_answer_set_programming.pdf)</sup> 在基于翻译的求解中，环公式的数量可能是指数级的。<sup>[3](https://www.ijcai.org/proceedings/2018/0769.pdf)</sup> 惰性基化系统如 GASP、ASPERIX 和 ALPHA 仅在其体被满足时才实例化规则，但其性能无法与基化—求解系统竞争；在一次评估中，ALPHA 在给定的时间和内存内没有解出任何实例。<sup>[20](https://www.ijcai.org/proceedings/2020/0234.pdf)</sup> 基于编译的替代方案绕过基化：WASP-EAGER 将约束翻译为 CDCL 传播器，在已发表的比较中优于 CLINGO、WASP 和 WASP-LAZY。<sup>[20](https://www.ijcai.org/proceedings/2020/0234.pdf)</sup> 混合式 proasp 系统在 14 个问题共 2366 个实例上与 clingo 进行了比较。<sup>[18](https://drops.dagstuhl.de/storage/01oasics/oasics-vol138-rw2024+rw2025/OASIcs.RW.2024-2025.8/OASIcs.RW.2024-2025.8.pdf)</sup>

相对于 SAT，判定一个非析取程序是否有回答集是 NP 完全的，与 SAT 属于同一类，但形式化结果表明，回答集语义下的规则严格比命题公式更具表达力，而 ASP 充当高层前端：带变量的逻辑程序接受新实例作为数据，而改变 SAT 问题规格通常需要重写编码。<sup>[6](https://link.springer.com/article/10.1007/s10601-016-9257-7)</sup> 将正递归翻译为 SAT 时，最紧凑的翻译会带来对数级膨胀，而不允许新原子时则带来指数级膨胀。<sup>[22](https://aaltodoc.aalto.fi/server/api/core/bitstreams/311a28a0-1c73-450c-8b5e-ec0a96e9a0a9/content)</sup> 对于精确回答集计数，Kabir、Chakraborty 和 Meel（2023）的 sharpASP 框架在已发表的比较中优于先前最先进的计数器。<sup>[23](https://ojs.aaai.org/index.php/AAAI/article-view/28927)</sup>

## References

1. [What Is Answer Set Programming? (Lifschitz, AAAI 2008)](https://cdn.aaai.org/AAAI/2008/AAAI08-270.pdf)
2. [Answer Sets and the Language of Answer Set Programming (Lifschitz, AI Magazine 2016)](https://ojs.aaai.org/aimagazine/index.php/aimagazine/article/download/2670/2572)
3. [Evaluation Techniques and Systems for Answer Set Programming: a Survey (Calimeri et al., IJCAI 2018)](https://www.ijcai.org/proceedings/2018/0769.pdf)
4. [Answer Set Programming Energised! End-to-End Neurosymbolic Reasoning and Learning with ASP and Energy Based Models (arXiv, 2026)](https://arxiv.org/html/2607.08136)
5. [A primer on Answer Set Programming (Provetti)](https://mag.di.unimi.it/aiclass/aa0405/asp-primer.pdf)
6. [What is answer set programming to propositional satisfiability (Lierler, Constraints 2017)](https://link.springer.com/article/10.1007/s10601-016-9257-7)
7. [Nicola Leone and colleagues (2006). The DLV system for knowledge representation and reasoning. ACM Transactions on Computational Logic.](https://doi.org/10.1145/1149114.1149117)
8. [Martin Gebser, Benjamin Kaufmann, Torsten Schaub (2012). Conflict-driven answer set solving: From theory to practice. Artificial Intelligence.](https://doi.org/10.1016/j.artint.2012.04.001)
9. [Answer-Set Programming Now (Lifschitz)](https://ar5iv.labs.arxiv.org/html/1108.3281)
10. [Grounding and Solving in Answer Set Programming (Kaufmann, Lange, Schaub, AI Magazine 2016)](https://www.cs.uni-potsdam.de/wv/publications/DBLP_journals/aim/KaufmannLPS16.pdf)
11. [Modeling and Language Extensions (Gebser & Schaub, AI Magazine)](https://www.cs.uni-potsdam.de/wv/publications/DBLP_journals/aim/GebserS16.pdf)
12. [From Felicitous Models to Answer Set Programming (Lifschitz)](https://www.cs.utexas.edu/~vl/papers/felicitous-final.pdf)
13. [Marek, Victor W., Truszczynski, Miroslaw (1998). Stable models and an alternative logic programming paradigm. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.cs/9809032)
14. [Ilkka Niemelä (1999). Logic programs with stable model semantics as a constraint programming paradigm. Annals of Mathematics and Artificial Intelligence.](https://doi.org/10.1023/a:1018930122475)
15. [Historical Review of Variants of Informal Semantics for Logic Programs under Answer Set Semantics: GL'88, GL'91, GK'14, D-V'12 (TPLP)](https://www.cambridge.org/core/journals/theory-and-practice-of-logic-programming/article/historical-review-of-variants-of-informal-semantics-for-logic-programs-under-answer-set-semantics-gl88-gl91-gk14-dv12/C8DEF6D26A6AAD41177D0BCE9EA37239)
16. [Allen Van Gelder, Kenneth A. Ross, John S. Schlipf (1991). The well-founded semantics for general logic programs. Journal of the ACM.](https://doi.org/10.1145/116825.116838)
17. [Michael Gelfond, Vladimir Lifschitz (1991). Classical negation in logic programs and disjunctive databases. New Generation Computing.](https://doi.org/10.1007/bf03037169)
18. [ASP Essentials: Modelling and Efficient Solving (OASIcs Reasoning Web 2024-2025)](https://drops.dagstuhl.de/storage/01oasics/oasics-vol138-rw2024+rw2025/OASIcs.RW.2024-2025.8/OASIcs.RW.2024-2025.8.pdf)
19. [Multi-shot ASP solving with clingo (TPLP)](https://www.cambridge.org/core/journals/theory-and-practice-of-logic-programming/article/abs/multishot-asp-solving-with-clingo/FAED3429900D84CDD5155326A36548F2)
20. [Overcoming the Grounding Bottleneck Due to Constraints in ASP Solving: Constraints Become Propagators (Cuteri et al., IJCAI 2020)](https://www.ijcai.org/proceedings/2020/0234.pdf)
21. [On the Foundations of Grounding in Answer Set Programming (Gebser, Kaminski, Kaufmann, Schaub, TPLP 2022)](https://www.cambridge.org/core/services/aop-cambridge-core/content/view/573D6EDC447B516CF2A5D90B1A262332/S1471068422000308a.pdf/on_the_foundations_of_grounding_in_answer_set_programming.pdf)
22. [Answer Set Programming (Janhunen, Aalto University)](https://aaltodoc.aalto.fi/server/api/core/bitstreams/311a28a0-1c73-450c-8b5e-ec0a96e9a0a9/content)
23. [Exact ASP Counting with Compact Encodings (sharpASP, AAAI 2024)](https://ojs.aaai.org/index.php/AAAI/article-view/28927)

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

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/answer-set-programming

English original: https://www.edgepedia.org/answer-set-programming
