gpt4 book ai didi

python - 具有边属性的 networkx 中的同构

转载 作者:行者123 更新时间:2023-12-05 06:28:13 26 4
gpt4 key购买 nike

我正在为同构使用 Networkx 函数:

  GM = nx.algorithms.isomorphism.GraphMatcher(G1,G2,node_match=lambda n1,n2:n1['name']==n2['name']) 

我想对名为“类型”的边属性执行相同的操作,但我不知道该怎么做。我刚试过这个:

  GM = nx.algorithms.isomorphism.GraphMatcher(G1,G2,node_match=lambda n1,n2:n1['name']==n2['name'], edge_match= lambda G[u1][v1],G2[u2][v2]: g[u1][v1]['type'] == g2[u2][v2]['type']) 

但它不起作用。谢谢!

编辑:这是来自文档:

 edge_match : callable
A function that returns True iff the edge attribute dictionary for
the pair of nodes (u1, v1) in G1 and (u2, v2) in G2 should be
considered equal during the isomorphism test. The function will be
called like::

edge_match(G1[u1][v1], G2[u2][v2])

That is, the function will receive the edge attribute dictionaries
of the edges under consideration. If None, then no attributes are
considered when testing for an isomorphism.

最佳答案

您应该按如下方式更改 edge_match 函数:

GM = nx.algorithms.isomorphism.GraphMatcher(G1,G2,node_match=lambda n1,n2:n1['name']==n2['name'], edge_match= lambda e1,e2: e1['type'] == e2['type'])

说明:

文档说:

edge_match (callable) – A function that returns True iff the edge attribute dictionary for the pair of nodes (u1, v1) in G1 and (u2, v2) in G2 should be considered equal during the isomorphism test. The function will be called like:

edge_match(G1[u1][v1], G2[u2][v2])

G[u][v] 是边 (u, v) 的数据字典。

所以 lambda e1,e2: e1['type'] == e2['type'] 是一个给定 2 条边的数据字典 的函数,返回如果两条边的类型相等,则为真。

关于python - 具有边属性的 networkx 中的同构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54476702/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com