You can pass custom comparing functions to the method isomorphic_vf2
with the node_compat_fn
and edge_compat_fn
arguments. From the docs:
node_compat_fn - a function that receives the two graphs and two node indices (one from the first graph, one from the second graph) and returns True if the nodes given by the two indices are compatible (i.e. they could be matched to each other) or False otherwise. This can be used to restrict the set of isomorphisms based on node-specific criteria that are too complicated to be represented by node color vectors (i.e. the color1 and color2 parameters). None means that every node is compatible with every other node.
and
edge_compat_fn - a function that receives the two graphs and two edge indices (one from the first graph, one from the second graph) and returns True if the edges given by the two indices are compatible (i.e. they could be matched to each other) or False otherwise. This can be used to restrict the set of isomorphisms based on edge-specific criteria that are too complicated to be represented by edge color vectors (i.e. the edge_color1 and edge_color2 parameters). None means that every edge is compatible with every other node.
Example:
import igraph as ig
G1=ig.Graph(directed=True)
G2=ig.Graph(directed=True)
G1.add_vertices(2)
G2.add_vertices(2)
G1.vs[0]['gaga'] = 'gugu'
G2.vs[0]['gaga'] = 'gogo'
G1.add_edge(0,1)
G2.add_edge(1,0)
print G1.isomorphic_vf2(G2)
def cmp_nodes(g1, g2, i1, i2):
return g1.vs[i1]['gaga'] == g2.vs[i2]['gaga']
print G1.isomorphic_vf2(G2, node_compat_fn=cmp_nodes)
Here is the included unit-test of this exact feature.