我使用Networkx函数进行同构:
GM = nx.algorithms.isomorphism.GraphMatcher(G1,G2,node_match=lambda n1,n2:n1['name']==n2['name']) 我想用一个叫做'type‘的边属性来做同样的事情,但是我不知道怎么做。我刚试过这个:
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.发布于 2019-02-01 19:54:55
您应该更改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) -当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。
https://stackoverflow.com/questions/54476702
复制相似问题