Top Banner
The Kuhn-Munkres Algorithm step by step
33
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Kuhn munkres algorithm

The Kuhn-Munkres

Algorithm

step by step

Page 2: Kuhn munkres algorithm

The Kuhn-Munkres Algorithm:

It’s algorithm to find the maximum weight perfect

matching in a weighted complete bipartite graph

Kuhn-Munkres algorithm consider assignment

problem in terms of bipartite graph

The Kuhn-Munkres algorithm

Page 3: Kuhn munkres algorithm

Key idea

find a good feasible labeling that remains enough edges

in equality graph.

to ensure perfect matching can be done

Algorithm describe

Start with any feasible labeling L

and some matching M in GL

While M is not perfect matching, repeat:

Find an augmenting path in GL to increase the size of M

or

if no path exists, improve L to L’ such that GL ⊂ GL’

The Kuhn-Munkres algorithm

Page 4: Kuhn munkres algorithm

Before the algorithm

Y1 Y2 Y3

X1 X2 X3

1 6 8

4

1

6

Original Graph

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Initial feasiblelabeling

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

6 8

4

Equality Graph + Matching

1)()()( xywylxl

Page 5: Kuhn munkres algorithm

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Updating feasible labeling:

Or how we compute:

Before the algorithm

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

)()()(min xywylxl

TySx

l

If we have the following labeling L. Assume S={X1,X2} T={y2}

Y1 0 Y2 2 Y3 0

X1 4 X2 6 X3 4

1 6 8

4

1

6

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Compute only for x1,x2

With all Y except y2l

Find minimum of:

x1, y1 = l(x1)+l(y1)-w(x1,y2)

= 6 + 0 – 1 = 5

x2, y3 = l(x2)+l(y3)-w(x1,y2)

= 8 + 0 – 6 = 2

Subtract 2 from x1,x2Add 2 to y2

TySx &

Page 6: Kuhn munkres algorithm

Generate initial labeling L and matching M in GL

Step 1. If X is M-saturateda (perfect matching), stop

Otherwise, let u be an M-unsaturated vertex.

Set S = {u} and T = .

Step 2. If , go to step 3.

Otherwise, Compute

Replace L by L’ and G by Gl’

Algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

Page 7: Kuhn munkres algorithm

Algorithm

TSNylG )(

M yz

)(PEMM

Page 8: Kuhn munkres algorithm

Apply Kuhn- Munkers algorithm to find an optimal matching:

Example :

Y1 Y2 Y3

X1 X2 X3

1 6 8

4

1

6

Original Graph

Page 9: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

)(PEMM

Y1 Y2 Y3

X1 X2 X3

1 6 8

4

1

6

Original Graph

Example :

Page 10: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

)(PEMM

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Original Graph

Example :

Page 11: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

)(PEMM

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

Example :

Page 12: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

)(PEMM

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

Example :

Page 13: Kuhn munkres algorithm

)()()(min xywylxl

TySx

l

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

)(PEMM

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

Example :

TSNlG )(

Page 14: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

)(PEMM

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

Example :

Page 15: Kuhn munkres algorithm

)()()(min xywylxl

TySx

l

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

)(PEMM

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

Example :

S = {X1}

T = {}

)(SNlG {y2}

TSNlG )(

Page 16: Kuhn munkres algorithm

)()()(min xywylxl

TySx

l

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

)(PEMM

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1}

T = {}

)(SNlG {y2}

Example :

TSNlG )(

Page 17: Kuhn munkres algorithm

)()()(min xywylxl

TySx

l

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

)(PEMM

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1}

T = {}

)(SNlG {y2}

Example :

TSNlG )(

Page 18: Kuhn munkres algorithm

)()()(min xywylxl

TySx

l

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

)(PEMM

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1}

T = {}

)(SNlG {y2}

Example :

TSNlG )(

Page 19: Kuhn munkres algorithm

)()()(min xywylxl

TySx

l

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

M yz

)(PEMM

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1}

T = {}

)(SNlG {y2}

Example :

TSNlG )(

TSNylG )(

Page 20: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

M yz

)(PEMM

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1}

T = {}

)(SNlG {y2}

Example :

TSNylG )(

Page 21: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

M yz

)(PEMM

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1, X2}

T = {y2}

)(SNlG {y2}

Go to 2

Example :

TSNylG )(

Page 22: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

)(PEMM

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1, X2}

T = {y2}

)(SNlG {y2}

Example :

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

Page 23: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

)(PEMM

Y1 0 Y2 0 Y3 0

X1 6 X2 8 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1, X2}

T = {y2}

)(SNlG {y2}

=2

Example :

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

Page 24: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

)(PEMM

Y1 0 Y2 2 Y3 0

X1 4 X2 6 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1, X2}

T = {y2}

)(SNlG {y2}

Example :

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

Page 25: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

)(PEMM

Y1 0 Y2 2 Y3 0

X1 4 X2 6 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1, X2}

T = {y2}

)(SNlG {y2}

Example :

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

Page 26: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

)(PEMM

Y1 0 Y2 2 Y3 0

X1 4 X2 6 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1, X2}

T = {y2}

)(SNlG {y2,y3}

Example :

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

Page 27: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

)(PEMM

Y1 0 Y2 2 Y3 0

X1 4 X2 6 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1, X2}

T = {y2}

)(SNlG {y2,y3}

Example :

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

Page 28: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

)(PEMM

Y1 0 Y2 2 Y3 0

X1 4 X2 6 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1, X2}

T = {y2}

)(SNlG {y2,y3}

Example :

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

Page 29: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

)(PEMM

Y1 0 Y2 2 Y3 0

X1 4 X2 6 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1, X2}

T = {y2}

)(SNlG {y2,y3}

Example :

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

Page 30: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

)(PEMM

Y1 0 Y2 2 Y3 0

X1 4 X2 6 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1, X2}

T = {y2}

)(SNlG {y2,y3}

Example :

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

Page 31: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

)(PEMM

Y1 0 Y2 2 Y3 0

X1 4 X2 6 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1, X2}

T = {y2}

)(SNlG {y2,y3}

Go to 1

Example :

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

Page 32: Kuhn munkres algorithm

TSNlG )(

)()()(min xywylxl

TySx

l

)(PEMM

Y1 0 Y2 2 Y3 0

X1 4 X2 6 X3 4

1 6 8

4

1

6

Original Graph

Y1 Y2 Y3

X1 X2 X3

Equality Graph + Matching

S = {X1, X2}

T = {y2}

)(SNlG {y2,y3}

Go to 1

stop

Example :

otherwise,)(

if,)(

if,)(

)(^

vl

Tvvl

Svvl

vl l

l

TSNylG )(

M yz

Page 33: Kuhn munkres algorithm

Thanks