networkx.algorithms.isomorphism.is_isomorphic
的用法。用法:
is_isomorphic(G1, G2, node_match=None, edge_match=None)
如果圖 G1 和 G2 是同構的,則返回 True,否則返回 False。
- G1, G2: graphs:
兩個圖形 G1 和 G2 必須是同一類型。
- node_match:可調用的
如果在同構測試期間應將 G1 中的節點 n1 和 G2 中的 n2 視為相等,則返回 True 的函數。如果未指定node_match,則不考慮節點屬性。
該函數將被稱為
node_match(G1.nodes[n1], G2.nodes[n2])。
也就是說,該函數將接收 n1 和 n2 的節點屬性字典作為輸入。
- edge_match:可調用的
如果 G1 中的節點對 (u1, v1) 和 G2 中的 (u2, v2) 的邊屬性字典在同構測試期間應被視為相等,則返回 True 的函數。如果未指定edge_match,則不考慮邊屬性。
該函數將被稱為
edge_match(G1[u1][v1], G2[u2][v2])。
也就是說,該函數將接收正在考慮的邊的邊屬性字典。
參數:
注意:
使用 vf2 算法 [1]。
參考:
- 1
L. P. Cordella, P. Foggia, C. Sansone, M. Vento, “An Improved Algorithm for Matching Large Graphs”, 3rd IAPR-TC15 Workshop on Graph-based Representations in Pattern Recognition, Cuen, pp. 149-159, 2001. https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.101.5342
例子:
>>> import networkx.algorithms.isomorphism as iso
對於有向圖 G1 和 G2,使用 ‘weight’ 邊屬性(默認值:1)
>>> G1 = nx.DiGraph() >>> G2 = nx.DiGraph() >>> nx.add_path(G1, [1, 2, 3, 4], weight=1) >>> nx.add_path(G2, [10, 20, 30, 40], weight=2) >>> em = iso.numerical_edge_match("weight", 1) >>> nx.is_isomorphic(G1, G2) # no weights considered True >>> nx.is_isomorphic(G1, G2, edge_match=em) # match weights False
對於多向圖 G1 和 G2,使用 ‘fill’ 節點屬性(默認值:'')
>>> G1 = nx.MultiDiGraph() >>> G2 = nx.MultiDiGraph() >>> G1.add_nodes_from([1, 2, 3], fill="red") >>> G2.add_nodes_from([10, 20, 30, 40], fill="red") >>> nx.add_path(G1, [1, 2, 3, 4], weight=3, linewidth=2.5) >>> nx.add_path(G2, [10, 20, 30, 40], weight=3) >>> nm = iso.categorical_node_match("fill", "red") >>> nx.is_isomorphic(G1, G2, node_match=nm) True
對於多向圖 G1 和 G2,使用 ‘weight’ 邊屬性(默認值:7)
>>> G1.add_edge(1, 2, weight=7) 1 >>> G2.add_edge(10, 20) 1 >>> em = iso.numerical_multiedge_match("weight", 7, rtol=1e-6) >>> nx.is_isomorphic(G1, G2, edge_match=em) True
對於多重圖 G1 和 G2,使用 ‘weight’ 和 ‘linewidth’ 邊屬性,默認值為 7 和 2.5。還使用默認值‘red’的‘fill’節點屬性。
>>> em = iso.numerical_multiedge_match(["weight", "linewidth"], [7, 2.5]) >>> nm = iso.categorical_node_match("fill", "red") >>> nx.is_isomorphic(G1, G2, edge_match=em, node_match=nm) True
相關用法
- Python NetworkX is_isolate用法及代碼示例
- Python NetworkX is_directed_acyclic_graph用法及代碼示例
- Python NetworkX is_graphical用法及代碼示例
- Python NetworkX is_locally_k_edge_connected用法及代碼示例
- Python NetworkX is_simple_path用法及代碼示例
- Python NetworkX is_bipartite用法及代碼示例
- Python NetworkX is_distance_regular用法及代碼示例
- Python NetworkX is_bipartite_node_set用法及代碼示例
- Python NetworkX is_strongly_regular用法及代碼示例
- Python NetworkX is_k_edge_connected用法及代碼示例
- Python NetworkX is_threshold_graph用法及代碼示例
- Python NetworkX is_semiconnected用法及代碼示例
- Python NetworkX is_weighted用法及代碼示例
- Python NetworkX is_biconnected用法及代碼示例
- Python NetworkX is_aperiodic用法及代碼示例
- Python NetworkX is_eulerian用法及代碼示例
- Python NetworkX is_chordal用法及代碼示例
- Python NetworkX is_at_free用法及代碼示例
- Python NetworkX is_connected用法及代碼示例
- Python NetworkX is_negatively_weighted用法及代碼示例
- Python NetworkX isolates用法及代碼示例
- Python NetworkX inverse_line_graph用法及代碼示例
- Python NetworkX intersection用法及代碼示例
- Python NetworkX intersection_array用法及代碼示例
- Python NetworkX induced_subgraph用法及代碼示例
注:本文由純淨天空篩選整理自networkx.org大神的英文原創作品 networkx.algorithms.isomorphism.is_isomorphic。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。