I am new to python and am trying to write a program that can take a matrix of 1's and 0's as an input, create a graph from it, then keep generating another random graph until it find an isomorphic pair.
I keep messing up my logic and keep getting either an infinite loop or a loop that doesn't accomplish what I want accomplished. Any help would be appreciated.
Here's the part of my program with the issue
i = 0
for i in range(counterP):
g4 = numpy.reshape(numpy.random.random_integers(0, 1, size=matrix_sizeP), (vertex_countP, vertex_countP))
g5 = numpy.reshape(numpy.random.random_integers(0, 1, size=matrix_sizeP), (vertex_countP, vertex_countP))
G4 = nx.Graph(g4)
G5 = nx.Graph(g5)
G4G5 = iso.GraphMatcher(G4,G5)
isomP = G4G5.is_isomorphic()
if isomP is True:
ed = nx.number_of_edges(G4)
print("Iteration", i, ":", ed, "edges")
print(G4G5.mapping)
i = i + 1
else:
g5 = numpy.reshape(numpy.random.random_integers(0, 1, size=matrix_sizeP), (vertex_countP, vertex_countP))
G5 = nx.Graph(g5)
isomP = G4G5.is_isomorphic()
Your program logic is indeed slightly off. Here is a version which does what I understand you want:
Sample runs: