Professional Documents
Culture Documents
Kernighan Lin
Kernighan Lin
Graph Segmentation
To partition N into 2k parts bisect (i.e. cut into two pieces) graph recursively k times
Problem Formulation
Input: A weighted graph G = (V, E) with Vertex set V. (|V| = 2n) Edge Set E. (|E| = e) Cost cAB for each edge (A, B) in E. Output: 2 subsets X & Y such that V = X Y and X Y = { } (i.e. partition) Each subset (group) has n vertices Total cost of edges crossing the partition is minimized. This problem is NP-Complete!!!!!
Idea of KL Algorithm
Start with any initial partition X and Y. A pass or iteration means exchanging each vertex A X
1. For i := 1 to n do From the unlocked (unexchanged) vertices, choose a pair (A,B) s.t. gain(A,B) is largest. Exchange A and B. Lock A and B. Let gi = gain(A,B). 2. Find the k s.t. G=g1+...+gk is maximized. 3. Switch the first k pairs.
b
2
Given:
Initial weighted graph G with V(G) = { a, b, c, d, e, f } Start with any partition of V(G) into X and Y, say X = { a, c, e } Y = { b, d, f }
c
3
d
1
KL algorithm (2a)
a
4 2 3 1 2 4 6
b
2
Compute the gain values of moving node x to the others set: Gx = Ex - Ix Ex = cost of edges connecting node x with the other group (extra) Ix = cost of edges connecting node x within its own group (intra)
c
3
d
1
cut-size = 3+1+2+4+6 = 16
X = { a, c, e } Y = { b, d, f }
Ga = Ea Ia = 3 Gc = Ec Ic = 0 Ge = Ee Ie = + 1 Gb = Eb Ib = + 2 Gd = Ed Id = 1 Gf = Ef If = + 9
(= 3 4 2) (= 1 + 2 + 4 4 3) (= 6 2 3) (= 3 + 1 2) (= 2 2 1) (= 4 + 6 1)
KL algorithm (2b)
a
4 2 3 1 2 4 6
b
2
c
3
d
1
X = { a, c, e } Y = { b, d, f }
KL algorithm (3)
a
4 2 3 1 2 4 6
b
2
Ga = 3 Gc = 0 Ge = +1
Gb = +2 Gd = 1 Gf = +9
c
3
d
1
cut-size = 16
gab = Ga + Gb 2wab = 3 + 2 23 = 7 gad = Ga + Gd 2wad = 3 1 20 = 4 gaf = Ga + Gf 2waf = 3 + 9 20 = +6 gcb = Gc + Gb 2wcb = 0 + 2 21 = 0 gcd = Gc + Gd 2wcd = 0 1 22 = 5 gcf = Gc + Gf 2wcf = 0 + 9 24 = +1 geb = Ge + Gb 2web = +1 + 2 20 = +3 ged = Ge + Gd 2wed = +1 1 20 = 0 gef = Ge + Gf 2wef = +1 + 9 26 = 2
KL algorithm (4)
a
4 2 3 1 2 4 6
b
2 4
1 1 2 4 2
b
2 3
c
3
d
1 6
c
3
cut-size = 16
cut-size = 16 6 = 10
gaf = Ga + Gf 2caf = 3 + 9 20 = +6
KL algorithm (5)
f
4 1 1 2 4 2
b
2 3
Ga = 3 Gc = 0 Ge = +1
Gb = +2 Gd = 1 Gf = +9
c
6 3
X = { c, e } Y = { b, d }
cut-size = 10
Gc = Gc + 2cca 2ccf = 0 + 2(4 4) = 0 Ge = Ge + 2cea 2cef = 1 + 2(2 6) = 7 Gb = Gb + 2cbf 2cba= 2 + 2(0 3) = 4 Gd = Gd + 2cdf 2cda = 1 + 2(1 0) = 1
KL algorithm (6)
f
4 1 1 2 4 2
Gc = 0 Ge = 7
Gb = 4 Gd = +1
b
2 3
c
6 3
X = { c, e } Y = { b, d } Compute the gains gcb = Gc + Gb 2ccb = 0 4 21 = 6 gcd = Gc + Gd 2ccd = 0 + 1 22 = 3 geb = Ge + Gb 2ceb = 7 4 20 = 11 ged = Ge + Gd 2ced = 7 + 1 20 = 6
cut-size = 10
KL algorithm (7)
f
4 1 1 2 4 2
b
2 3 1
f
2
4 2
b
1 3
c
6 3
d
6
c
4
cut-size = 10
cut-size = 10 (3) = 13
gcd = Gc + Gd 2ccd = 0 + 1 22 = 3
KL algorithm (8)
f
1 2 2 4
b
1 3
Gc = 0 Ge = 7 X = { e } Y = { b }
Gb = 4 Gd = +1
d
6
c
4
cut-size = 13
geb = Ge + Gb 2ceb = 1 2 20 = 3
KL algorithm (9)
Summary of the Gains g = +6 g + g = +6 3 = +3 g + g + g = +6 3 3 = 0 Maximum Gain = g = +6
Exchange only nodes a and f. End of 1 pass. Repeat the Kernighan-Lin.
Time Complexity of KL
For each pass, O(n2) time to find the best pair to exchange. n pairs exchanged. Total time is O(n3) per pass. Better implementation can get O(n2lg n) time
per pass.