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

时间:2019-02-01 09:38:52

标签: python networkx isomorphism

我正在使用Networkx函数实现同构:

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

我想对称为'type'的edge属性执行相同操作,但我不知道如何做。 我刚刚尝试过:

  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.

1 个答案:

答案 0 :(得分:0)

您应按以下方式更改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(可调用) –在边缘时返回True的函数   G1和(u2,v2)中的一对节点(u1,v1)的属性字典   同构测试期间,应将G2中的γ视为相等。的   函数将被称为:

     

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

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

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

相关问题