Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

24
Algorithms for Algorithms for computing computing Canonical labeling Canonical labeling of Graphs and Sub- of Graphs and Sub- Graph Isomorphism Graph Isomorphism

Transcript of Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Page 1: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Algorithms for Algorithms for computing computing

Canonical labeling Canonical labeling of Graphs and Sub-of Graphs and Sub-

Graph Graph IsomorphismIsomorphism

Page 2: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

AgendaAgenda

Brief overview of complexity issues of Brief overview of complexity issues of Graph Isomorphism, Sub Graph Graph Isomorphism, Sub Graph Isomorphism.Isomorphism.

Canonical Labeling problemCanonical Labeling problem McKay’s Algorithm to find canonical McKay’s Algorithm to find canonical

labels and generators for Aut(G)labels and generators for Aut(G) Ullmann’s Algorithm for Sub-Graph Ullmann’s Algorithm for Sub-Graph

Isomorphism.Isomorphism. Conclusion.Conclusion.

Page 3: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Complexity of Graph Complexity of Graph IsomorphismIsomorphism

and Sub Graph and Sub Graph IsomorphismIsomorphism Sub Graph Isomorphism is a Sub Graph Isomorphism is a NP-Complete NP-Complete

problemproblem Graph Isomorphism (GI) is Graph Isomorphism (GI) is NP NP , but currently , but currently

its still a open problem if GI is in its still a open problem if GI is in P P or or NP-NP-complete.complete.

Babai Babai gave a gave a O(nO(n4m+c4m+c) ) deterministic deterministic algorithm , where algorithm , where m m is the multiplicity of the is the multiplicity of the eigen valueseigen values ( (spectrum) spectrum) of the adjacency of the adjacency matrix.matrix.

Equivalence of spectrumEquivalence of spectrum is a is a Necessary Necessary but but not not Sufficient Sufficient condition to test isomorphism.condition to test isomorphism.

Page 4: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Automorphism Group of Automorphism Group of a Graph.a Graph.

AUT(G)AUT(G) subgroup within a symmetric subgroup within a symmetric group group SSn n (set of all permutations)(set of all permutations)

AUT(G) = { AUT(G) = { g | g g | g € € SSn n and Gand Gg g = G }= G } GGg g is the relabeled graph with is the relabeled graph with

permutation permutation gg In simple terms In simple terms AUT(G) AUT(G) is the set of all is the set of all

permutations under which permutations under which adjacency adjacency matrix matrix of of G G remains the same.remains the same.

A Graph A Graph G G and its compliment and its compliment G’ G’ has has same same AUT(G)AUT(G)

Page 5: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Example of Example of AutomorphismAutomorphism

1

4

3

2

Label-1

0 0 1 00 0 1 01 1 0 10 0 1 0

0 0 1 00 0 1 01 1 0 10 0 1 0

1 2 3 4 2 4 3 1 3 4 1 20 1 1 11 0 0 01 0 0 01 0 0 0

Rewrite the adjacency matrix for each permutation

If a permutation g is in Aut(G) then the adjacency matrix remain the sameWhen we apply g to the adjacency matrix Gg.

Aut(G) = { (1, 2 ,4) , (3) }

Page 6: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Canonical Labeling Canonical Labeling ProblemProblem

Let Let G*(V) G*(V) be the set of labeled graphs be the set of labeled graphs with Vertex set with Vertex set VV..

GG € € G*(V) , Canon(G*(V) , Canon(GG): G*(V) ): G*(V) G*(V) G*(V) Canon(Canon(GG) ) is isomorphic to is isomorphic to GG Canon(Canon(GGgg) = ) = Canon(G) , Canon(G) , g g € S€ Sn n

We are interested in finding this We are interested in finding this mapping function, a direct use of this mapping function, a direct use of this labeling is that we can find labeling is that we can find isomorphism very easily for this.isomorphism very easily for this.

Page 7: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Equitable PartitionsEquitable Partitions

V = V = {1,2,…,n}{1,2,…,n} , , partition partition of of V V is a set is a set of disjoint of subsets of of disjoint of subsets of V V (union of (union of which is which is VV))

pp = = {C{C11,C,C22,….C,….Ck k } , C} , C1 1 U CU C2 2 U … CU … Ck k = = V V d(d(vvii,C,Cjj) = no.of vertices adjacent to v) = no.of vertices adjacent to vi i

in Cin Ci i .. Partition Partition p p is is equitableequitable if if

vvii,v,vj j € C€ Cmm , , dd(v(vii,C,Cpp)) = = dd(v(vjj,C,Cpp) )

Page 8: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Ordering among the Ordering among the Partitions.Partitions.

pp1 1 ≤≤ p p2 2 , , pp1 1 is is finer finer than than pp2 2 ((pp2 2 is is coarser coarser than than pp1 1 ))

Let Let P(V) P(V) be a set of all be a set of all partitions partitions on the vertex on the vertex set set V , V , then the operator ‘then the operator ‘≤’ ≤’ creates a partial creates a partial order among the order among the partitions.partitions. {(1),(2),(3),…(n)} {(1),(2),(3),…(n)} ≤..... ≤ ≤..... ≤ ppi i ≤ ≤ ppmm ≤ ≤ ppn n ….. ….. ≤ ≤ {(1,2,3,…,n)}{(1,2,3,…,n)}

..... ≤ ..... ≤ ppi i ≤ ≤ ppmm ≤ ≤ ppn n …..….. ppi i is is coarsest coarsest partition partition finer finer than than ppmm

ppn n is is finestfinest partition partition coarser coarser than than ppm m

We can add the We can add the equitable equitable adjective to adjective to finer finer and and coarser coarser if the if the equitable equitable property is statisfied.property is statisfied.

Page 9: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

FixFix of a of a partitionpartition by by permutation.permutation.

Let Let g € g € SSn n (Symmetric group) , v(Symmetric group) , vi i € € V V , , vviigg

is the image of vis the image of vi i under permutation under permutation g g ..

Let Let W W subset of subset of V V then then WWgg = = {{ vviig g | | vvi i € €

W W }} p p = {C= {C1 1 , C, C2 2 , … C, … Ck k } then } then ppg g = = {C{Cgg

11 , C, Cgg 2 2 , , …}…}

If If ppgg = = p p then then g g is said to is said to Fix p.Fix p. Example: Example: p p = = {(1,2,3),(4),(5,6)} , then {(1,2,3),(4),(5,6)} , then

g = g = {3,2,1,4,6,5} {3,2,1,4,6,5} fixes fixes p.p.

Page 10: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Key Ideas behind Canonical Key Ideas behind Canonical labeling algorithmlabeling algorithm

Quick Recall: We are interested in finding Quick Recall: We are interested in finding Aut(G) Aut(G) and and Canon(G).Canon(G).

Naïve Algorithm: generate all the Naïve Algorithm: generate all the O(O(n!) n!) permutations and find permutations and find Aut(G)Aut(G) and hence and hence compute the compute the Canon(G).Canon(G).

Observation all the elements in Observation all the elements in Aut(G) Aut(G) should correspond to some labeling with should correspond to some labeling with finest finest partition of the vertex set partition of the vertex set V.V.

Also since all the partitions ( Also since all the partitions ( P(V) P(V) ) are ) are ordered with ‘≤’ we can make use of this ordered with ‘≤’ we can make use of this ordering to prune the ordering to prune the finest finest partitions which partitions which are useless.are useless.

Page 11: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Basic Structure of the Basic Structure of the AlgorithmAlgorithm

Start with a Start with a Coarsest Coarsest partition partition ppvv (the (the order of vertices in the input graph).order of vertices in the input graph).

Generate a Generate a Equitable Equitable partition partition Eq(pEq(pvv)) from from ppv v such that such that …………. . ppjj≤ ≤ Eq(pEq(pvv)) ≤ ≤ ppv v , (, (Eq(pEq(pvv)) is coarsest is coarsest

partition which is finer than partition which is finer than ppv v ).). This is called This is called Refinement , R(p) .Refinement , R(p) .

Keep Keep Refining Refining until the partition until the partition becomes becomes finest(discrete) finest(discrete) call these call these terminal partition.terminal partition.

Page 12: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Backtrack depth first Backtrack depth first structure.structure.

pv

R(pv )

R(….R(R( (pv )R(….R(R( (pv )

Discrete partitions

Refine & Prune

Page 13: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Refinement Procedure. Refinement Procedure. R(p,a)R(p,a)

R(p,a) R(p,a) is a function such thatis a function such that INPUT: any partition INPUT: any partition p p , , a a subset of subset of pp OUTPUT: OUTPUT: coarsest coarsest equitable partition which equitable partition which

is finer than is finer than pp.. p = p = { { CC1 1 ,, CC2 2 ,C,C1 1 .... C.... Ckk} } , let, let p’ = pp’ = p

a = a = {{WW }}

forfor(i=0;i<k;i++)(i=0;i<k;i++) partition partition CCii according to according to d(v,W) d(v,W) call the call the

partitions partitions BB.. p’ =p’ =(( p’- p’-{{CCii}) U (}) U (BB))

Page 14: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

ExampleExample

4

1

0 2

35

p = { (0,1,2,3,4,5) } , a = { (0,1,2,3,4,5)}

d(0,a)=3 , d(1,a)=3,d(2,a)=3,d(3,a)=1d(4,a)=1,d(5,a)=1 Two buckets of values 3 , 1B = {(0,1,2) , (3,4,5) } = R(p,a)

p = {(0,1,2),(3),(4,5)} not equitablea = {(3)}Loop1: C1 = (0,1,2)d(0,a) = 1, d(1,a) = 0 , d(2,a) =0 B= {(0),(1,2)}Loop2: C2 = (3)d(3,a) = 0 , B= {(3)} Loop3: C3 = (4,5)d(4,a) = 0 , d(5,a) = 0 , B={(4,5)}R(p,a) = {(0),(1,2),(3),(4,5)}

Page 15: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

ExampleExample

4

1

0 2

35

{(3,4,5) (0,1,2)}

{(3)(4,5)(1,2)(0)}

{(3)(4)(5)(2)(1)(0)}{(3)(5)(4)(1)(2)(0)}

{(4)(3,5)(0,2)(1)}

{(4)(3)(5)(2)(0)(1)}

3 4

4 5 3

Page 16: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Collect all the leaf nodes Collect all the leaf nodes Let Let X X be the collection of all the leaf nodes in be the collection of all the leaf nodes in

the back track tree.the back track tree. Now we can define a operator ‘~’ on tNow we can define a operator ‘~’ on t1 1 , t, t2 2 € € XX

tt1 1 ~ t~ t2 2 iff G iff Gt1 t1 = G= Gt2 t2

Re-label the vertices in the order of tRe-label the vertices in the order of t1 1 and tand t2 2 and and check if the adjacency matrices are the same.check if the adjacency matrices are the same.

Note ~ partitions Note ~ partitions X X into equivalence classes we just into equivalence classes we just need one class pick a element and define need one class pick a element and define Aut(G)Aut(G)

Aut(G) = Aut(G) = {{ g | t = tg | t = tccg g , t € , t € X X , t ~ t, t ~ tc c }}

In fact we can stick to a single equivalence In fact we can stick to a single equivalence class and eliminate all the others (that’s where class and eliminate all the others (that’s where the pruning comes into picture)the pruning comes into picture)

Page 17: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

The complete tree is never The complete tree is never generated!generated!

Since Since |Aut(G)| ≤ |X| |Aut(G)| ≤ |X| Generating all Generating all X X is a big overkill infact its not is a big overkill infact its not

possible since possible since |Aut(G)| |Aut(G)| could be could be O(n!)O(n!) If we observe carefully we just need to generate If we observe carefully we just need to generate

ONE ONE equivalence class.equivalence class. How do we make sure that backtracking How do we make sure that backtracking

leads to leaf nodes from a leads to leaf nodes from a singlesingle equivalence class ?equivalence class ? We need some property which is common for We need some property which is common for

the all leaf nodes in a single equivalence class the all leaf nodes in a single equivalence class along all the internal nodes.along all the internal nodes.

Page 18: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Property of terminal nodes Property of terminal nodes used to prune…used to prune…

Objective: We want to prune all the Objective: We want to prune all the internal nodes( from different equivalence internal nodes( from different equivalence classes) in the backtrack tree.classes) in the backtrack tree.

Step 1: First find two terminal nodes Step 1: First find two terminal nodes tt1 1 , t, t2 2

€ X € X such that such that GGt1 t1 = G= Gt2 t2 , then its clear that , then its clear that tt1 1 ~ t~ t2 2 ((also for some also for some g € Sg € Snn , , ttgg

1 1 = t= t2 2 )) From above its clear that we need some From above its clear that we need some

function function F F which will not change when which will not change when g g is applied to is applied to p p F(GF(Ggg,,ppgg) = ) = F(G,F(G,p)p)

Page 19: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Property to prune.Property to prune.

If If tt11 = = ppkk≤ p≤ pkk ≤ p ≤ pk-1k-1 …….≤ p …….≤ p22 ≤ p ≤ p11

F’(tF’(t11) = (F(G, ) = (F(G, ppkk) F(G, ) F(G, ppk-1k-1) …..) ….. F(G, F(G, pp11)))) F*(tF*(t11) = (F(G, ) = (F(G, pp11) F(G, ) F(G, pp22) …..) ….. F(G, F(G, ppkk))))

We can generateWe can generate F*(t F*(t11) ) by finding some by finding some two terminal nodes two terminal nodes tt1 1 , t, t2 2 € X € X , such that , such that GGt1t1 = G = Gt2t2

Once we generate Once we generate F*(tF*(t11) ) prune any path prune any path which does not match the which does not match the suffix suffix of of F*(tF*(t11))

Page 20: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Pruning IllustratedPruning Illustrated

p1

p2 = R(pv )

R(….R(R( (pv )

Pruned because F*(t1) don’t match at some suffix

R(….R(R( (pv )

Compute F*(t1) = (F(G, Compute F*(t1) = (F(G, p1p1) F(G, ) F(G, p2p2) ….. F(G, ) ….. F(G, pkpk))))

t1 t2

Page 21: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Ullmann’s Sub-Graph Ullmann’s Sub-Graph Isomorphism algorithmIsomorphism algorithm

Problem: Given a graphs Problem: Given a graphs GGa a ,G,Gb b wewe want to find if want to find if GGa a is isomorphic to any sub graph in is isomorphic to any sub graph in GGb .b .

Let Let M M be a matching matrix of size |a x b | , be a matching matrix of size |a x b | , MMij ij = 1 = 1 , , if if degree(j, Gdegree(j, Gaa) ≤ degree(j, G) ≤ degree(j, Gbb) , 0 ) , 0 otherwise.otherwise.

A systematic enumeration algorithm (depth first, A systematic enumeration algorithm (depth first, backtrack) would generate this matrix backtrack) would generate this matrix M M such thatsuch that There is exactly There is exactly one 1 one 1 per row and columnper row and column Once the depth of the enumeration reaches |a| check if Once the depth of the enumeration reaches |a| check if

adjacency matrix of adjacency matrix of GGa a and adjacency of match from and adjacency of match from M M matches.matches.

Page 22: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

Ullmann’s observation for Ullmann’s observation for pruningpruning

Let Let MMd d be the matching matrix generated at any depth be the matching matrix generated at any depth d d ≤ |a|≤ |a|

Then the bottom Then the bottom |a-d||a-d| rows of rows of MMd d and and M M are the same, are the same, the brute force algorithm will just continue.the brute force algorithm will just continue. Ullmann made an observation that makes use of some extra Ullmann made an observation that makes use of some extra

information from the top information from the top |d| |d| rows which are fixed.rows which are fixed. OBSERVATION:OBSERVATION: If If vvi i €€ VVa a and and vvj j € V€ Vb b are mapped in one are mapped in one

of the top of the top |d| |d| rows in rows in MMd d . . Then any vertex adjacent to Then any vertex adjacent to vvi i in in GGa a can be mapped only to vertex adjacent to can be mapped only to vertex adjacent to vvj j in in GGb b ..

With above observation we can reduce the # of 1’s in the With above observation we can reduce the # of 1’s in the bottom bottom |a-d| |a-d| rows of rows of MMd d thus reducing search space.thus reducing search space.

Ullmann showed experimentally the validity of this Ullmann showed experimentally the validity of this pruning approach.pruning approach.

Page 23: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

ReferencesReferences D. G. Corneil and C. C. Gotlieb. An efficient algorithm for

graph isomorphism. In Journal of the ACM (JACM), pages 51–64, Volume 17 , Issue1 (January 1970).

D. Cvetkovi´c, P. Rowlingson, and S. Simi´c. Eigenspaces of graphs. In Cambridge University Press, 1997.

C. D. Godsil and B. D. McKay. Constructing cospectral graphs. In Acquationes Mathematicae, pages 257–268, 2001.

F. Harary. The determinant of the adjacency matrix of a graph. In SIAM Review, pages 202–210, Vol.4, 1962.

Brendan D. McKay. Computing automorphishms and canonical labelling of graphs. In Combinatorial Mathematics, pages 223–232, Volume 686/1978.

B. D. McKay. Practical graph isomorphism. In Congressus Numerantium, pages 45–87, 1981.

Page 24: Algorithms for computing Canonical labeling of Graphs and Sub-Graph Isomorphism.

ReferencesReferences

A. J. Schwenk. Almost all trees are cospectral. In New Directions in the Theory of Graphs (Proc. Third Annual Arbor Conference), pages 275–307, 1973.J. R. Ullmann. An algorithm for subgraph isomorphism. In Journal of the ACM (JACM), pages 31–42, Volume 23 , Issue 1 (January 1976).