# 子图同构

子图同构是这样一个计算问题：判定一个较小的模式图能否映射到一个较大的宿主图中，使得模式图的每条边都映射为宿主图的一条边，且模式图中不同的顶点映射到宿主图中不同的顶点。形式化地说，给定两个无向图 G 和 F，问题是是否存在一个从 F 的顶点到 G 的顶点的保邻接单射映射。<sup>[1](https://arxiv.org/html/1908.11248)</sup> 该问题是 NP 完全的<sup>[2](https://www.cicirello.org/publications/survey-1999.pdf)</sup>，但它是化学信息学、RDF 查询处理、图数据库、社交网络分析、计算机视觉和符号识别中模式匹配的主力工具<sup>[3](https://www.ijcai.org/proceedings/2023/0626.pdf)</sup>，也用于模型检查、执法、编译器实现和机械锁设计。<sup>[4](https://link.springer.com/content/pdf/10.1007/978-3-030-51372-6_19.pdf)</sup>

| 关键事实 | 细节 |
|---|---|
| 输入与输出 | 两个图（模式图和宿主图）；判定形式回答是或否，求解器还支持搜索、计数和枚举所有匹配<sup>[1](https://arxiv.org/html/1908.11248)</sup><sup> • </sup><sup>[4](https://link.springer.com/content/pdf/10.1007/978-3-030-51372-6_19.pdf)</sup> |
| 复杂性 | NP 完全；普通图同构是否 NP 完全仍是开放问题<sup>[2](https://www.cicirello.org/publications/survey-1999.pdf)</sup> |
| 细粒度下界 | 除非指数时间假设失败，否则没有算法能在 \( 2^{o(n\sqrt{\log n})} \) 时间内运行（n = 两个图的顶点总数）<sup>[5](https://ar5iv.labs.arxiv.org/html/1504.02876)</sup> |
| 经典算法 | 乌尔曼（Ullmann）的带矩阵细化的回溯算法，《ACM杂志》（Journal of the ACM），1976<sup>[6](https://doi.org/10.1145/321921.321925)</sup> |
| 化学信息学基准 | 在 SMARTS-分子对上，VF2 的中位匹配时间为 0.04 ms，乌尔曼为 0.1 ms<sup>[7](https://pmc.ncbi.nlm.nih.gov/articles/PMC3586954/)</sup> |
| 实践中的困难性 | 只有约二十个模式顶点和几百个目标顶点的随机实例也可能在计算上具有挑战性<sup>[8](https://ciaranm.github.io/papers/jair-really-hard-sip-paper.pdf)</sup> |
| 近期硬件趋势 | Δ-Motif 系统报告相比 VF2 等既有方法最高 595 倍加速<sup>[9](https://arxiv.org/html/2508.21287)</sup> |

## 工作原理

所有精确算法都搜索从模式顶点到宿主顶点的部分映射空间，区别在于它们以多大力度剪枝该空间。<sup>[1](https://arxiv.org/html/1908.11248)</sup> 一个部分映射在满足以下条件时可行：它是一对一的，保留存在的标签，并保持邻接性：每一对已经映射的相邻模式顶点都必须对应到相邻的宿主顶点。

乌尔曼的细化操作在一个布尔矩阵 M 上进行，每行对应一个模式顶点，每列对应一个宿主顶点，其中条目 \( m_{ij} = 1 \) 标记模式顶点 i 到宿主顶点 j 的一个候选的、标签兼容的映射。<sup>[6](https://doi.org/10.1145/321921.321925)</sup><sup> • </sup><sup>[7](https://pmc.ncbi.nlm.nih.gov/articles/PMC3586954/)</sup> 细化步骤检查每个候选映射的邻域：若该映射要存活，模式顶点 i 的每个邻居都必须在宿主顶点 j 的邻居中至少有一个兼容候选。不满足该一致性条件的条目从 1 变为 0，且此类变化可能级联，迫使 M 中其他位置进一步变化，直到所有剩余的 1 条目局部一致。<sup>[6](https://doi.org/10.1145/321921.321925)</sup><sup> • </sup><sup>[7](https://pmc.ncbi.nlm.nih.gov/articles/PMC3586954/)</sup> 这种邻域一致性剪枝在深度优先树搜索之前和期间应用，正是它从暴力枚举中移除后继节点。<sup>[6](https://doi.org/10.1145/321921.321925)</sup><sup> • </sup><sup>[2](https://www.cicirello.org/publications/survey-1999.pdf)</sup> 细化检查三件事：顶点度、一对一映射约束，以及邻接保持的前向检查。<sup>[10](https://www.osti.gov/servlets/purl/895418)</sup>

VF2 算法则沿模式图的拓扑迭代地扩展部分解，维护一个中间状态，保存部分映射以及已映射前沿的邻接集。每次扩展都要通过一个合成可行性函数 \( F_{\mathrm{syn}}(s, n, m) = R_{\mathrm{adj}} \wedge R_{\mathrm{inout}} \)，其中 \( R_{\mathrm{adj}} \) 保证候选对的相邻节点相互映射，\( R_{\mathrm{inout}} \) 对节点基数进行一步前瞻以提前剪枝。<sup>[7](https://pmc.ncbi.nlm.nih.gov/articles/PMC3586954/)</sup> 机制上的对比是：乌尔曼以任意的、非拓扑的节点顺序处理兼容矩阵，而 VF2 按照子结构的拓扑添加节点对。<sup>[7](https://pmc.ncbi.nlm.nih.gov/articles/PMC3586954/)</sup>

## 实现方式

已发表的比较从四个方面分析精确的内存求解器：在数据图中过滤候选顶点的方法、对查询顶点排序的方法、枚举部分结果的方法，以及其他优化技术。<sup>[11](https://dl.acm.org/doi/10.1145/3318464.3380581)</sup> 过滤传播约束（度序列、邻域兼容性、全不同推理）以在搜索前缩小候选集。排序选择模式顶点被匹配的顺序，通常优先选择与许多已匹配顶点相连的顶点，因为据报道，GraphQL 和 RI 中的排序方法通常是内存系统中最为有效的。<sup>[11](https://dl.acm.org/doi/10.1145/3318464.3380581)</sup> 枚举以深度优先方式扩展部分映射，在每一步应用可行性检查，失败时回溯；基于集合交的局部候选计算在这一阶段表现最好，而当查询变大时，失败集剪枝显著提高性能。<sup>[11](https://dl.acm.org/doi/10.1145/3318464.3380581)</sup>

## 起源

最早被广泛使用的表述是 J. R. 乌尔曼（J. R. Ullmann）1976 年发表于《ACM杂志》（Journal of the ACM）的论文，该论文通过推理消除后继节点，从而获得比暴力树搜索更高的效率。<sup>[6](https://doi.org/10.1145/321921.321925)</sup> 乌尔曼后来将该方法重新表述为用于二元约束满足和子图同构的位向量算法（《ACM实验算法杂志》（ACM Journal of Experimental Algorithmics），2010）。<sup>[12](https://doi.org/10.1145/1671970.1921702)</sup> 用于生化数据的 RI 算法由文琴佐·博尼奇（Vincenzo Bonnici）及其同事发表于《BMC生物信息学》（BMC Bioinformatics），2013 年。<sup>[13](https://doi.org/10.1186/1471-2105-14-s7-s13)</sup> 面向巨大且稠密图的 VF3 由文琴佐·卡莱蒂（Vincenzo Carletti）及其同事发表于《IEEE模式分析与机器智能汇刊》（IEEE Transactions on Pattern Analysis and Machine Intelligence），2017 年。<sup>[14](https://doi.org/10.1109/tpami.2017.2696940)</sup> VF2++ 由阿尔帕尔·尤特纳（Alpár Jüttner）和彼得·马达拉西（Péter Madarasi）发表于《离散应用数学》（Discrete Applied Mathematics），2018 年。<sup>[15](https://doi.org/10.1016/j.dam.2018.02.018)</sup> 最近，用于标记图的 ArcMatch 出现在《数据挖掘与知识发现》（Data Mining and Knowledge Discovery），2024 年<sup>[16](https://doi.org/10.1007/s10618-024-01061-8)</sup>；塞缪尔·费拉兹（Samuel Ferraz）及其同事的 DuMato 以 warp 为中心的 GPU 系统发表于《并行与分布式计算杂志》（Journal of Parallel and Distributed Computing），2024 年<sup>[17](https://doi.org/10.1016/j.jpdc.2024.104903)</sup>；威尔弗里德·阿格贝托（Wilfried Agbeto）及其同事的 FASTiso 发表于 bioRxiv，2025 年<sup>[18](https://doi.org/10.1101/2025.02.28.640915)</sup>；郭书阳（Shuyang Guo）及其同事的 HFrame 框架将算法与图神经网络结合，发表于 arXiv，2025 年。<sup>[19](https://doi.org/10.48550/arxiv.2507.20226)</sup>

## 变体

已发表的比较将精确算法分为三类范式：树搜索（乌尔曼、VF 系列、RI 及其相关算法）、约束规划（LAD、乌尔曼的位向量算法、格拉斯哥求解器（Glasgow solver））和图索引（GraphQL、QuickSI、GADDI、SPath、TurboISO）。<sup>[20](https://www.sciencedirect.com/science/article/abs/pii/S0167865518302733)</sup>

**树搜索变体。** VF 系列涵盖两种变体：非诱导版本允许目标中存在额外边，而诱导版本不允许，实现可能只限于两者之一。<sup>[11](https://dl.acm.org/doi/10.1145/3318464.3380581)</sup><sup> • </sup><sup>[8](https://ciaranm.github.io/papers/jair-really-hard-sip-paper.pdf)</sup> VF3 增加了针对同时大而稠密的图的改进，这是最先进算法最棘手的情形，并在公共数据集上较前身显示出显著加速。<sup>[21](https://link.springer.com/chapter/10.1007/978-3-319-58961-9_12)</sup> 一个去除了部分启发式的简化版本 VF3-Light，在某些图类上实际上更快。<sup>[20](https://www.sciencedirect.com/science/article/abs/pii/S0167865518302733)</sup> VF2++ 改进了 VF2 的节点排序和可行性计算<sup>[15](https://doi.org/10.1016/j.dam.2018.02.018)</sup>；RI 使用基于拓扑的搜索策略。<sup>[3](https://www.ijcai.org/proceedings/2023/0626.pdf)</sup>

**约束规划。** 模式顶点成为变量，其定义域为宿主顶点。格拉斯哥求解器结合基于邻域度序列的度过滤、通过补充图的路径计数约束、全不同过滤，以及位并行传播、重启、禁解记录和可扩展到至少 36 核的并行搜索。<sup>[4](https://link.springer.com/content/pdf/10.1007/978-3-030-51372-6_19.pdf)</sup> 它处理诱导和非诱导变体、有向边、自环、标签、单射和局部单射变体、同态以及计数。<sup>[4](https://link.springer.com/content/pdf/10.1007/978-3-030-51372-6_19.pdf)</sup> 过滤成本不同：前向检查对差分约束运行时间为 \( O(n_{p}) \)，对边约束为 \( O(d_{p} \cdot n_{t}) \)；乌尔曼的弧一致性过滤使用 AC4 为 \( O(e_{p} \cdot n_{t}^{2}) \)；LAD 的局部全不同过滤为 \( O(n_{p} \cdot n_{t} \cdot d_{p}^{2} \cdot d_{t}^{2}) \)。<sup>[22](https://ciaranm.github.io/papers/lion2016-sip-portfolios.pdf)</sup>

**其他族。** 颜色编码通过用恰好 \( n_{F} \) 种颜色随机给宿主顶点着色并应用动态规划，将问题归约为彩色版本；它可以枚举 RI 和 LAD 不支持的不连通模式。<sup>[1](https://arxiv.org/html/1908.11248)</sup> Nauty 风格的规范标号通过使用顶点不变量和划分细化将图归约为规范形式来检测同构。<sup>[10](https://www.osti.gov/servlets/purl/895418)</sup> 面向数据库的系统如 QuickSI 将测试算法与基于特征的索引配对用于过滤阶段，解决查询图增大时出现的验证瓶颈。<sup>[23](https://psycnet.apa.org/doi/10.14778/1453856.1453899)</sup>

## 应用

子结构搜索是旗舰用途：化学信息学软件将 SMARTS 查询模式与分子图匹配，其中 VF2 因其运行时间特征而被推荐。<sup>[7](https://pmc.ncbi.nlm.nih.gov/articles/PMC3586954/)</sup> 在针对 ZINC 分子的 1,235 个 SMARTS 表达式上，两种经典算法都在 1 ms 内完成大多数匹配，VF2 中位数为 0.04 ms，乌尔曼为 0.1 ms，基准作者推荐将 VF2 用于分子子结构搜索，理由是其总体优越性约为一个数量级。<sup>[7](https://pmc.ncbi.nlm.nih.gov/articles/PMC3586954/)</sup> RI 是专门为搜索生化数据而开发的<sup>[13](https://doi.org/10.1186/1471-2105-14-s7-s13)</sup>，而用于搜索生物结构化数据的核心算法是乌尔曼和 VF2 的带过滤回溯设计。<sup>[24](https://journal.embnet.org/index.php/embnetjournal/article/view/416)</sup> 除化学外，有文献记载的应用包括模型检查、执法、编译器实现、机械锁设计和图数据库<sup>[4](https://link.springer.com/content/pdf/10.1007/978-3-030-51372-6_19.pdf)</sup>，以及符号识别、社交网络、计算机视觉和 RDF 查询处理。<sup>[3](https://www.ijcai.org/proceedings/2023/0626.pdf)</sup>

近期系统面向并行和学习式匹配。Δ-Motif 将匹配重新表述为对表格化模体嵌入进行数据库连接、排序、合并和过滤，报告相比 VF2 和 GSI 等既有方法最高 595 倍加速，在社交网络上它 1 至 2 秒完成，而 VF2 需要超过 200 秒。<sup>[9](https://arxiv.org/html/2508.21287)</sup> G-Morph 是一个用于标记图上诱导子图同构的 GPU 过滤-连接系统，在真实图上优于基于 GPU 的 GSI 和基于 CPU 的 VF3，加速最高分别为 15.78 倍和 43.56 倍。<sup>[25](https://par.nsf.gov/servlets/purl/10337540)</sup> 在学习式方面，IsoNet++ 是一种用于基于子图同构的图检索的早期交互图神经网络，在六个数据集上优于包括 NeuroMatch 和 IsoNet 在内的十一个基线<sup>[26](https://proceedings.neurips.cc/paper_files/paper/2024/file/8dc8a46f3981224217d32eb3f8362998-Paper-Conference.pdf)</sup>，而 GNN-PE 框架训练 GNN 产生路径嵌入，从而能够进行索引级剪枝，在美国专利数据集（US Patents dataset）上具有 100% 召回率和 99.5% 剪枝能力。<sup>[27](https://ar5iv.labs.arxiv.org/html/2511.09052)</sup> 这种取舍并不统一：GNN-PE 面向精确子图匹配，而其他神经和嵌入方法通过在噪声数据上放弃回溯和约束传播求解器提供的精确性保证，来换取速度和鲁棒性。<sup>[27](https://ar5iv.labs.arxiv.org/html/2511.09052)</sup>

## 局限与替代方案

尽管所有已知精确算法在输入规模上都是指数级的，但实践中真正困难的实例很少，输入规模并不是难度的指标。<sup>[10](https://www.osti.gov/servlets/purl/895418)</sup><sup> • </sup><sup>[4](https://link.springer.com/content/pdf/10.1007/978-3-030-51372-6_19.pdf)</sup> 刻意构造的随机实例可能只有约二十个模式顶点和几百个目标顶点就具有挑战性。<sup>[8](https://ciaranm.github.io/papers/jair-really-hard-sip-paper.pdf)</sup> 图越对称，或包含的重复子部分越多，匹配就越困难，因为算法会面对更多相似的候选位置<sup>[20](https://www.sciencedirect.com/science/article/abs/pii/S0167865518302733)</sup>；强正则图是特别困难的一类。<sup>[2](https://www.cicirello.org/publications/survey-1999.pdf)</sup> 内存也有限制：乌尔曼的经典算法需要与节点数平方成正比的空间。<sup>[20](https://www.sciencedirect.com/science/article/abs/pii/S0167865518302733)</sup> 图数据库中广泛研究的过滤/验证索引技术被论证为建立在对 NP 完全问题经验困难性的误解之上，并且与任何合理的子图同构算法搭配时都无法提供帮助。<sup>[8](https://ciaranm.github.io/papers/jair-really-hard-sip-paper.pdf)</sup>

图编辑距离，即将一个图变换为另一个图的最小代价编辑操作序列，是核心的容错替代方案；图同构、子图同构和最大公共子图都是特殊代价函数下编辑距离的特殊实例。<sup>[28](https://www.ai.rug.nl/ki2/literature/graphmatch-bunke.pdf)</sup> 最优容错方法大多是 A* 搜索变体，在时间和空间上呈指数级，而近似方法（松弛、神经网络、遗传算法、最大流）具有多项式界，但可能错过最优解。<sup>[28](https://www.ai.rug.nl/ki2/literature/graphmatch-bunke.pdf)</sup> 图核提供了基于向量的比较，其动机是子图同构和最大公共子图的 NP 完全性；计算任何完全核至少与图同构一样困难，因此诸如魏斯费勒-莱曼（Weisfeiler-Lehman）子树核（可在 \( O(h \cdot m) \) 时间内计算）这样的实用核牺牲了表达能力，而现有核无法区分连通性、平面性和二部性等性质。<sup>[29](https://www.jair.org/index.php/jair/article/download/13225/26741)</sup>

## References

1. [Efficient Implementation of Color Coding Algorithm for Subgraph Isomorphism Problem](https://arxiv.org/html/1908.11248)
2. [Survey of Graph Matching Algorithms](https://www.cicirello.org/publications/survey-1999.pdf)
3. [PathLAD+: An Improved Exact Algorithm for Subgraph Isomorphism Problem (IJCAI 2023)](https://www.ijcai.org/proceedings/2023/0626.pdf)
4. [The Glasgow Subgraph Solver: Using Constraint Programming to Tackle Hard Subgraph Isomorphism Problem Variants (CP/ICGT 2020; University of Glasgow repository copy merged here)](https://link.springer.com/content/pdf/10.1007/978-3-030-51372-6_19.pdf)
5. [The Hardness of Subgraph Isomorphism (Lokshtanov et al.)](https://ar5iv.labs.arxiv.org/html/1504.02876)
6. [J. R. Ullmann (1976). An Algorithm for Subgraph Isomorphism. Journal of the ACM.](https://doi.org/10.1145/321921.321925)
7. [Systematic benchmark of substructure search in molecular graphs, From Ullmann to VF2 (Journal of Cheminformatics; Springer publisher page 10.1186/1758-2946-4-13 merged here)](https://pmc.ncbi.nlm.nih.gov/articles/PMC3586954/)
8. [When Subgraph Isomorphism is Really Hard, and Why This Matters for Graph Databases (JAIR 2018)](https://ciaranm.github.io/papers/jair-really-hard-sip-paper.pdf)
9. [Δ-Motif: Parallel Subgraph Isomorphism via Tabular Operations](https://arxiv.org/html/2508.21287)
10. [Graph-based pattern matching survey (semantic graphs)](https://www.osti.gov/servlets/purl/895418)
11. [In-Memory Subgraph Matching: An In-depth Study (SIGMOD 2020)](https://dl.acm.org/doi/10.1145/3318464.3380581)
12. [Julian R. Ullmann (2010). Bit-vector algorithms for binary constraint satisfaction and subgraph isomorphism. ACM Journal of Experimental Algorithmics.](https://doi.org/10.1145/1671970.1921702)
13. [Vincenzo Bonnici and colleagues (2013). A subgraph isomorphism algorithm and its application to biochemical data. BMC Bioinformatics.](https://doi.org/10.1186/1471-2105-14-s7-s13)
14. [Vincenzo Carletti and colleagues (2017). Challenging the Time Complexity of Exact Subgraph Isomorphism for Huge and Dense Graphs with VF3. IEEE Transactions on Pattern Analysis and Machine Intelligence.](https://doi.org/10.1109/tpami.2017.2696940)
15. [Alpár Jüttner, Péter Madarasi (2018). VF2++, An improved subgraph isomorphism algorithm. Discrete Applied Mathematics.](https://doi.org/10.1016/j.dam.2018.02.018)
16. [Vincenzo Bonnici and colleagues (2024). ArcMatch: high-performance subgraph matching for labeled graphs by exploiting edge domains. Data Mining and Knowledge Discovery.](https://doi.org/10.1007/s10618-024-01061-8)
17. [Samuel Ferraz and colleagues (2024). DuMato: An efficient warp-centric subgraph enumeration system for GPU. Journal of Parallel and Distributed Computing.](https://doi.org/10.1016/j.jpdc.2024.104903)
18. [Wilfried Agbeto, Camille Coti, Vladimir Reinharz (2025). FASTiso: Fast Algorithm on Search state Tree for subgraph ISOmorphism in graphs of any size and density. bioRxiv (Cold Spring Harbor Laboratory).](https://doi.org/10.1101/2025.02.28.640915)
19. [Guo, Shuyang and colleagues (2025). Improving Subgraph Matching by Combining Algorithms and Graph Neural Networks. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2507.20226)
20. [Comparing performance of graph matching algorithms on huge graphs](https://www.sciencedirect.com/science/article/abs/pii/S0167865518302733)
21. [Introducing VF3: A New Algorithm for Subgraph Isomorphism (GbRPR 2017)](https://link.springer.com/chapter/10.1007/978-3-319-58961-9_12)
22. [Portfolios of Subgraph Isomorphism Algorithms (LION 2016)](https://ciaranm.github.io/papers/lion2016-sip-portfolios.pdf)
23. [Taming verification hardness: an efficient algorithm for testing subgraph isomorphism (QuickSI, PVLDB 2008)](https://psycnet.apa.org/doi/10.14778/1453856.1453899)
24. [Core algorithms to search in biological structured data (EMBnet.journal)](https://journal.embnet.org/index.php/embnetjournal/article/view/416)
25. [G-Morph: fast GPU-based induced subgraph isomorphism search on labeled graphs](https://par.nsf.gov/servlets/purl/10337540)
26. [Iteratively Refined Early Interaction Alignment for Subgraph Matching based Graph Retrieval (IsoNet++, NeurIPS 2024)](https://proceedings.neurips.cc/paper_files/paper/2024/file/8dc8a46f3981224217d32eb3f8362998-Paper-Conference.pdf)
27. [Efficient Distributed Exact Subgraph Matching via GNN-PE: Load Balancing, Cache Optimization, and Query Plan Ranking](https://ar5iv.labs.arxiv.org/html/2511.09052)
28. [Graph Matching: Theoretical Foundations, Algorithms, and Applications](https://www.ai.rug.nl/ki2/literature/graphmatch-bunke.pdf)
29. [Graph Kernels: A Survey (JAIR)](https://www.jair.org/index.php/jair/article/download/13225/26741)

---
*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Sep 30, 2026; Oct 15, 2026; Oct 21, 2026; Oct 25, 2026 · Last review: Sep 30, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 逻辑与离散数学 › General discrete mathematics and discrete structures › Graph theory › Computational graph problems and algorithms › NP-hard graph problems and their algorithms

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/subgraph-isomorphism

English original: https://www.edgepedia.org/subgraph-isomorphism
