The first equivalence you mention is called isomorphism. Use IsomorphicGraphQ
.
The second is not entirely clear to me, but you probably mean homeomorphism.
It seems reasonable (but I have not proven it!) that two directed graphs would be homeomorphic if we obtain isomorphic graphs after repeatedly removing vertices that have one incoming and one outgoing edge, like vertex 2
below, and replacing them with a single edge (would be 1 -> 3
below).

To avoid obtaining multigraphs or self loops, the removal should only be done if vertices 1
and 3
are distinct and there is no edge 1 -> 3
already.
Here's an implementation of this for directed graphs (since that is what you have in your example):
out[g_, v_] := First@DeleteCases[VertexOutComponent[g, v], v]
in[g_, v_] := First@DeleteCases[VertexInComponent[g, v], v]
smooth[graph_?DirectedGraphQ]:=
Module[{g=graph,candidates,v},
While[True,
candidates=Pick[VertexList[g],Transpose[{VertexOutDegree[g],VertexInDegree[g]}],{1,1}];
candidates=Select[candidates, With[{i=in[g,#1],o=out[g,#1]},!EdgeQ[g,i\[DirectedEdge]o]&&i=!=o]&];
If[candidates==={},Break[]];
v=First[candidates];
g=VertexContract[g,{v,out[g,v]}]
];
g
]
homeomorphicQ[g1_?DirectedGraphQ, g2_?DirectedGraphQ] :=
IsomorphicGraphQ[smooth[g1], smooth[g2]]
Graph[{1 -> 2, 2 -> 3, 3 -> 1}]~IsomorphicGraphQ~ Graph[{1 -> 3, 3 -> 2, 2 -> 1}]
givesTrue
. $\endgroup$ – kglr Nov 26 '17 at 2:54IsomorphicGraphQ[Graph[...],Graph[...]]
will not evaluate, whileIsomorphicGraphQ[{a[1, 1, 3, 1] -> a[1, 1, 3, 1]}, {a[1, 1, 1, 3] -> a[1, 1, 1, 3]}]
will return false (incorrectly?). I use this kind of "a-tuple" as vertexes since they are generated byNestGraph
while it will not work correctly if I return list of list (it will be considered matrix). $\endgroup$ – ZisIsNotZis Nov 26 '17 at 15:26IsomorphicGraphQ
of anything besideGraph[...]
will always return false, even forIsomorphicGraphQ[{1 -> 2}, {1 -> 2}]
, whileIsomorphicGraphQ
ofGraph[...]
do not evaluate (it will return the same thing as input). Is that a bug on my mechine or bug of 11.2? $\endgroup$ – ZisIsNotZis Nov 26 '17 at 15:39IsomorphicGraphQ
should be graphs:IsomorphicGraphQ[Graph@{1 -> 2}, Graph@{1 -> 2}]
givesTrue
. $\endgroup$ – kglr Nov 26 '17 at 15:43