Bug introduced in 9.0.1 or earlier and fixed in 11.0.1
Consider the following two graphs:
g1 = Graph[{1, 2, 3}, {}];
g2 = SimpleGraph@Graph[{1, 2, 3}, {1 <-> 1}];
They are clearly the same thing because SimpleGraph
will remove the self loop (only edge) from g2
.
Yet IsomorphicGraphQ
disagrees:
IsomorphicGraphQ[g1, g2]
(* False *)
I believe this is a bug and it exists in all of 9.0.1 through to 10.4.0.
Is there a workaround?
Answer
A simple workaround is to re-build the graph object by cycling it through some other representation. Here are two possible solutions:
rebuildGraph[g_] := Uncompress@Compress[g] (* solution 1 *)
rebuildGraph[g_] := Graph[VertexList[g], EdgeList[g]] (* solution 2 destroys properties but it's fine for isomorphism testing purposes *)
isomorphicGraphQ[g1_, g2_] :=
IsomorphicGraphQ[rebuildGraph[g1], rebuildGraph[g2]]
Now this gives a correct result:
isomorphicGraphQ[g1, g2]
(* True *)
Comments
Post a Comment