DiGraphMatcher.subgraph_monomorphisms_iter#

DiGraphMatcher.subgraph_monomorphisms_iter()[source]#

在图 G1 的子图和 G2 之间生成单同态映射。

示例

创建 DiGraphMatcher 时,参数的顺序很重要。

>>> G = nx.DiGraph([("A", "B"), ("C", "B"), ("D", "C")])
>>> H = nx.DiGraph([(0, 1), (1, 2), (2, 3), (3, 2)])

生成 HG 的子图之间的单同态映射

>>> isomatcher = nx.isomorphism.DiGraphMatcher(G, H)
>>> list(isomatcher.subgraph_monomorphisms_iter())
[]

生成 GH 的子图之间的单同态映射

>>> isomatcher = nx.isomorphism.DiGraphMatcher(H, G)
>>> next(isomatcher.subgraph_monomorphisms_iter())
{3: 'A', 2: 'B', 1: 'C', 0: 'D'}