首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有边属性的networkx中的同构

具有边属性的networkx中的同构
EN

Stack Overflow用户
提问于 2019-02-01 17:38:52
回答 1查看 191关注 0票数 2

我使用Networkx函数进行同构:

代码语言:javascript
复制
  GM = nx.algorithms.isomorphism.GraphMatcher(G1,G2,node_match=lambda n1,n2:n1['name']==n2['name']) 

我想用一个叫做'type‘的边属性来做同样的事情,但是我不知道怎么做。我刚试过这个:

代码语言:javascript
复制
  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']) 

但它不起作用。谢谢!

编辑:这来自文档:

代码语言:javascript
复制
 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.
EN

回答 1

Stack Overflow用户

发布于 2019-02-01 19:54:55

您应该更改edge_match函数,如下所示:

代码语言:javascript
复制
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) -当G1中的节点对(u1,v1)和G2中的(u2,v2)的边缘属性字典在同构测试期间被视为相等时,该函数返回True。该函数的调用方式如下:

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

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

因此,lambda e1,e2: e1['type'] == e2['type']是一个函数,在给定数据字典为2条边的情况下,如果这两条边的类型相等,则返回true。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54476702

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档