0

is there a way to find mapping of nodes when searching subgraph isomorphism via NetworkX? For example,

import numpy as np
from networkx.algorithms import isomorphism
import networkx as nx

B = [[0, 2, 1, 0, 0],
     [2, 0, 1, 0, 1],
     [1, 1, 0, 1, 0],
     [0, 0, 1, 0, 0],
     [0, 1, 0, 0, 0]]

A = [[0, 1, 1],
     [1, 0, 2],
     [1, 2, 0]]

G1 = nx.from_numpy_matrix(np.array(B), create_using=nx.MultiGraph())
G2 = nx.from_numpy_matrix(np.array(A), create_using=nx.MultiGraph())
GM = isomorphism.MultiGraphMatcher(G1,G2)
print(GM.subgraph_is_isomorphic())
print(GM.mapping)

Prints {0: 0, 1: 1, 2: 2}, but it is not true.

Anatoli
  • 889
  • 2
  • 15
  • 33

1 Answers1

2

I found the solution:

GM = isomorphism.MultiGraphMatcher(G1, G2, edge_match=lambda x, y: x[0]['weight'] == y[0]['weight'])

According to source code documentation, there should be edge_match function specified for multigraphs.

Anatoli
  • 889
  • 2
  • 15
  • 33