33
The Kuhn-Munkres Algorithm step by step

Kuhn munkres algorithm

Embed Size (px)

Citation preview

The Kuhn-Munkres

Algorithm

step by step

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

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

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

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 &

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

Algorithm

TSNylG )(

M yz

)(PEMM

Apply Kuhn- Munkers algorithm to find an optimal matching:

Example :

Y1 Y2 Y3

X1 X2 X3

1 6 8

4

1

6

Original Graph

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 :

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 :

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 :

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 :

)()()(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 )(

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 :

)()()(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 )(

)()()(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 )(

)()()(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 )(

)()()(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 )(

)()()(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 )(

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 )(

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 )(

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

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

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

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

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

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

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

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

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

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

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

Thanks