brute-force graph isomorphism with networkx

1.4k views Asked by At

I'm trying to write a brute-force approach to check if two graphs are isomorphic. I am using the class networkx but I don't want to use the built in functions for isomorphism.
I understand that I have to check all node-permutations of a graph but I don't know how to do that. So how would I permutate nodes in a networkx graph?

1

There are 1 answers

5
jgloves On BEST ANSWER

The following gives a list of all permutations of the nodes of a graph H.

from itertools import permutations

list(permutations(H.nodes(), len(H.nodes()))

After that, you could compare their adjacency matrices. See the following code: https://github.com/jgloves/graphTheory/blob/master/are_isomorphic.py