GraphTheory
GraphEqual
test graphs for equality
Calling Sequence
Parameters
Description
Examples
GraphEqual(G, H)
G, H
-
graphs
GraphEqual(G,H) returns true if the two input graphs are equal. Here the graphs are equal if they are (i) both directed or both undirected, (ii) both weighted or both unweighted, (iii) have the same vertex labels and in the same order, (iv) have the same edges. Further, if the graphs are both weighted graphs, their edge weights must be equal and integer edge weights are considered different from floating-point edge weights.
Thus G = Graph([1,2,3],{{1,2},{2,3}}) is considered not equal to H = Graph([1,3,2],{{1,2},{2,3}}) even though their edge sets are the same. If you want to test if the graphs are equal up to a permutation of the vertices then you may compare if their edge sets are equal.
For a more general test for graph isomorphism, see GraphTheory[IsIsomorphic].
with⁡GraphTheory:
G≔Graph⁡1,2,3,1,2,2,3
G≔Graph 1: an undirected graph with 3 vertices and 2 edge(s)
H≔Graph⁡1,2,3,1,2,1,3
H≔Graph 2: an undirected graph with 3 vertices and 2 edge(s)
Vertices⁡G,Edges⁡G
1,2,3,1,2,2,3
Vertices⁡H,Edges⁡H
1,2,3,1,2,1,3
GraphEqual⁡G,H
false
H≔Graph⁡Trail⁡1,2,3
H≔Graph 3: an undirected graph with 3 vertices and 2 edge(s)
true
G≔Graph⁡a,b,c,a,b,b,c
G≔Graph 4: an undirected graph with 3 vertices and 2 edge(s)
H≔PermuteVertices⁡G,a,c,b
H≔Graph 5: an undirected graph with 3 vertices and 2 edge(s)
a,b,c,a,b,b,c
a,c,b,a,b,b,c
See Also
Edges
Graph
IsIsomorphic
Trail
Vertices
Download Help Document