Combinatorial Optimization and Graph Theory ORCO
Matchings in bipartite graphs Execution of the Hungarian Method
Zolt´an Szigeti
Z. Szigeti OCG-ORCO 1 / 1
Algorithm Hungarian method (Kuhn)
Example
Execute the Hungarian method to find a minimum weight perfect matching in the following bipartite graph.
U V
u1 u2 u3 u4
v1 v2 v3 v4
v4 v3 v2 v1 3
u1 u2 u3 u4
2 1 1
1 3 4
4 5 5
8
8 8
2 7
9
Z. Szigeti OCG-ORCO 1 / 1
Execution of the Hungarian method
3 min{3,9,8,7}
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3
min{2,4,5,8}
2
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3
min{1,1,2,4}
2 1
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3
min{1,5,3,8}
2 1 1
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
y1
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
3 + 0 = 3
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
3 + 06= 9
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
3 + 06= 8
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
3 + 06= 7
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
2 + 0 = 2
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
2 + 06= 4
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
2 + 06= 5
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
2 + 06= 8
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
1 + 0 = 1
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
1 + 0 = 1
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
1 + 06= 2
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
1 + 06= 4
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
1 + 0 = 1
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
1 + 06= 5
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
1 + 06= 3
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
1 + 06= 8
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
3 2 1 1
0 0 0 0
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1 5 3
8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
5 5
1 1 1 1
1 1 1 1
5 5
5
s t
(D1,g1)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(0,1) s
t
(x0,g1)
(0,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (0,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(0,1) s
t
(x0,g1)
(0,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (0,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
s t
D10
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(0,1) s
t
(x0,g1)
(0,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (0,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
s 1 t
D10
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(0,1) s
t
(x0,g1)
(0,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (0,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
s 1 t
D10
2
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(0,1) s
t
(x0,g1)
(0,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (0,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
3 2
s 1 t
D10
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(0,1) s
t
(x0,g1)
(0,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (0,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
3 2
s 1 t
D10
4
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(0,1) s
t
(x0,g1)
(0,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (0,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
4 3 2
s 1 t
D10 5
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(0,1) s
t
(x0,g1)
(0,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (0,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
4 3 2
s 1 t
D10 5
6
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(0,1) s
t
(x0,g1)
(0,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (0,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
6
4 3 2
s 1 t
D10 5
7
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(0,1) s
t
(x0,g1)
(0,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (0,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
t
6
4 3 2
s 1 D10
5 7
8
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(0,1) s
t
(x0,g1)
(0,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (0,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
s D10
t
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(0,1) s
t
(x0,g1)
(0,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (0,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
s D10
t
1 5 1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(0,1) s
t
(x0,g1)
(0,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (0,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
s D10
t
1 5 1
ε1= min{1,5,1}
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(1,1) s
t
(x1,g1)
(1,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (1,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
s D10
t
1 5 1
ε1= min{1,5,1}
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(1,1) s
t
(x1,g1)
(1,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (1,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
s t
D11
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(1,1) s
t
(x1,g1)
(1,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (1,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
s t
D11
1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(1,1) s
t
(x1,g1)
(1,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (1,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
s t
D11
1 2
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(1,1) s
t
(x1,g1)
(1,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (1,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
2
s t
D11
1 3
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(1,1) s
t
(x1,g1)
(1,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (1,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
3 2
s t
D11
1 4
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(1,1) s
t
(x1,g1)
(1,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (1,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
3 2
s t
D11
1 4
5
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(1,1) s
t
(x1,g1)
(1,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (1,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
5
3 2
s t
D11
1 4
6
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(1,1) s
t
(x1,g1)
(1,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (1,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
t
5
3 2
s D11
1 4
6
7
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(1,1) s
t
(x1,g1)
(1,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (1,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
t
5
3 2
s D11
1 4
6
7
8
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(1,1) s
t
(x1,g1)
(1,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (1,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
t
s D11
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(1,1) s
t
(x1,g1)
(1,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (1,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
t
s D11
1 5 1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)(0,1)(1,1) s
t
(x1,g1)
(1,1) (0,1) (0,1) (0,1)
(0,5) (0,5) (0,5) (1,5) (0,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
t
s D11
1 5 1
ε2= min{1,5,1}
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)
(1,5)
(0,1) (0,1)(1,1)(1,1) s
t
(x2,g1)
(1,1) (1,1)
(0,5) (0,5) (0,5) (1,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
t
s D11
1 5 1
ε2= min{1,5,1}
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)
(1,5)
(0,1) (0,1)(1,1)(1,1) s
t
(x2,g1)
(1,1) (1,1)
(0,5) (0,5) (0,5) (1,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
s t
D12
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)
(1,5)
(0,1) (0,1)(1,1)(1,1) s
t
(x2,g1)
(1,1) (1,1)
(0,5) (0,5) (0,5) (1,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
s t
D12
1
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)
(1,5)
(0,1) (0,1)(1,1)(1,1) s
t
(x2,g1)
(1,1) (1,1)
(0,5) (0,5) (0,5) (1,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
s t
D12
1 2
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)
(1,5)
(0,1) (0,1)(1,1)(1,1) s
t
(x2,g1)
(1,1) (1,1)
(0,5) (0,5) (0,5) (1,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
2
s t
D12
1 3
Z. Szigeti OCG-ORCO 2 / 1
Execution of the Hungarian method
G1
(0,1) (0,1)
(1,5)
(0,1) (0,1)(1,1)(1,1) s
t
(x2,g1)
(1,1) (1,1)
(0,5) (0,5) (0,5) (1,5)
5 3 8 4 5
7 2 8
3 9
11 2
4 1 8
0 0 0 0
3 2 1 1
y1
2
s t
D12
1 3
4
Z. Szigeti OCG-ORCO 2 / 1