Assignment Problem
Assignment Problem
P1 J1
P2 J2
P3 J3
Assignment Problem
COST MATRIX
Job J1 J2 J3
Person
P1 120 100 80
P2 80 90 110
P3 110 140 120
Assignment Problem
COST MATRIX
Job J1 J2 J3
Person
P1 [X11] 120 [X12] 100 [X13] 80
P2 [X21] 80 [X22] 90 [X23] 110
P3 [X31] 110 [X32] 140 [X33] 120
Assignment Problem
Hungarian Method [Steps]
Step 1:
Your problem should be balanced. Number of
rows should be equal to number of columns. If it
is not the case then add a dummy row (or
column) with zero cost elements.
Hungarian Method [Steps]
Step 2:
Subtract the smallest cost element of each row
from each element of the row (You will get first
reduced cost matrix).
Hungarian Method [Steps]
Step 3:
Subtract the smallest cost element of each
column from each element of the column (You
will get second reduced cost matrix).
Hungarian Method [Steps]
Step 4a:
Examine the rows successively and make
assignment where exactly one zero is found.
Cross all the zeros in the column corresponding
to the cell where assignment is made. Continue
till all the rows are examined.
Hungarian Method [Steps]
Step 4b:
Examine the columns successively and make
assignment where exactly one zero is found. If
you find multiple zeros then you could assign
arbitrarily where you have minimum zeros and
you may repeat the process until all zeros are
assigned or crossed.
Hungarian Method [Steps]
Step 5:
An optimal solution is found if the number of
assigned cells is equal to number of rows (or
columns). If you assigned in a cell arbitrarily then
there are multiple assignments possible. If some
rows (or columns) are left without assignment
then optimality isn’t achieved. Proceed further.
Hungarian Method [Steps]
Step 6:
Draw the minimum number of horizontal and/or
vertical lines through all the zeros. There is a
procedure to achieve this...
I II III IV
A 10 5 13 15
B 3 9 18 3
C 10 7 3 2
D 5 11 9 7
Cost Matrix
Hungarian Method [Example1]
I II III IV
A 10 5 13 15
B 3 9 18 3
C 10 7 3 2
D 5 11 9 7
I II III IV
A 5 0 8 10
B 0 6 15 0
C 8 5 1 0
D 0 6 4 2
I II III IV
A 5 0 8 10
B 0 6 15 0
C 8 5 1 0
D 0 6 4 2
I II III IV
A 5 0 7 10
B 0 6 14 0
C 8 5 0 0
D 0 6 3 2
I II III IV
A 5 0 7 10
B 0 6 14 0
C 8 5 0 0
D 0 6 3 2
I II III IV
A 5 0 7 10
B 0 6 14 0
C 8 5 0 0
D 0 6 3 2
I II III IV
A 5 0 7 10
B 0 6 14 0
C 8 5 0 0
D 0 6 3 2
I II III IV
A 5 0 7 10
B 0 6 14 0
C 8 5 0 0
D 0 6 3 2
I II III IV
A 5 0 7 10
B 0 6 14 0
C 8 5 0 0
D 0 6 3 2
I II III IV
A 5 0 7 10
B 0 6 14 0
C 8 5 0 0
D 0 6 3 2
I II III IV
A 5 0 7 10
B 0 6 14 0
C 8 5 0 0
D 0 6 3 2
I II III IV
A 5 0 7 10
B 0 6 14 0
C 8 5 0 0
D 0 6 3 2
I II III IV
A 5 0 7 10
B 0 6 14 0
C 8 5 0 0
D 0 6 3 2
I II III IV
A 5 0 7 10
B 0 6 14 0
C 8 5 0 0
D 0 6 3 2
I II III IV
A 5 0 7 10
B 0 6 14 0
C 8 5 0 0
D 0 6 3 2
Each row and each column has exactly
one assigned zero. There are four rows
and four columns and four assignments.
Hence, it is optimal assignment
Hungarian Method [Example1]
I II III IV
A 5 0 7 10
B 0 6 14 0
C 8 5 0 0
D 0 6 3 2
I II III IV
A 5 0 7 10
B 0 6 14 0
C 8 5 0 0
D 0 6 3 2
I II III IV V VI
A 9 22 58 11 19 27
B 43 78 72 50 63 48
C 41 28 91 37 45 33
D 74 42 27 49 39 32
E 36 11 57 22 25 18
F 3 56 53 31 17 28
Cost Matrix
Hungarian Method [Example2]
I II III IV V VI
A 9 22 58 11 19 27
B 43 78 72 50 63 48
C 41 28 91 37 45 33
D 74 42 27 49 39 32
E 36 11 57 22 25 18
F 3 56 53 31 17 28
I II III IV V VI
A 0 13 49 2 10 18
B 0 35 29 7 20 5
C 13 0 63 9 17 5
D 47 15 0 22 12 5
E 25 0 46 11 14 7
F 0 53 50 28 14 25
I II III IV V VI
A 0 13 49 2 10 18
B 0 35 29 7 20 5
C 13 0 63 9 17 5
D 47 15 0 22 12 5
E 25 0 46 11 14 7
F 0 53 50 28 14 25
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0
C 13 0 63 7 7 0
D 47 15 0 20 2 0
E 25 0 46 9 4 2
F 0 53 50 26 4 20
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0
C 13 0 63 7 7 0
D 47 15 0 20 2 0
E 25 0 46 9 4 2
F 0 53 50 26 4 20
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0
C 13 0 63 7 7 0
D 47 15 0 20 2 0
E 25 0 46 9 4 2
F 0 53 50 26 4 20
Ignore first four rows because there are multiple zeros.
Make assignment in the fifth row and cross the zeros in the
assigned column
Hungarian Method [Example2]
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0
C 13 0 63 7 7 0
D 47 15 0 20 2 0
E 25 0 46 9 4 2
F 0 53 50 26 4 20
Make assignment in the sixth row and cross the zeros in
the assigned column
Hungarian Method [Example2]
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0
C 13 0 63 7 7 0
D 47 15 0 20 2 0
E 25 0 46 9 4 2
F 0 53 50 26 4 20
Now, proceed column wise and make assignment in the
third column and cross the zeros in the assigned row
Hungarian Method [Example2]
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0
C 13 0 63 7 7 0
D 47 15 0 20 2 0
E 25 0 46 9 4 2
F 0 53 50 26 4 20
Make assignment in the fourth column and cross the zeros
in the assigned row
Hungarian Method [Example2]
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0
C 13 0 63 7 7 0
D 47 15 0 20 2 0
E 25 0 46 9 4 2
F 0 53 50 26 4 20
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0
C 13 0 63 7 7 0
D 47 15 0 20 2 0
E 25 0 46 9 4 2
F 0 53 50 26 4 20
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0
C 13 0 63 7 7 0
D 47 15 0 20 2 0
E 25 0 46 9 4 2
F 0 53 50 26 4 20
You can stick to a systematic procedure to make
assignments or if the need arise you can decide arbitrarily
Hungarian Method [Example2]
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0
C 13 0 63 7 7 0
D 47 15 0 20 2 0
E 25 0 46 9 4 2
F 0 53 50 26 4 20
Now, there are only five assignments but there are six
rows and six columns and hence, this is not optimal
Hungarian Method [Example2]
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0
C 13 0 63 7 7 0
D 47 15 0 20 2 0
E 25 0 46 9 4 2
F 0 53 50 26 4 20
Our aim now is to cover the zeros with minimum
horizontal and/or vertical lines
Hungarian Method [Example2]
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0
C 13 0 63 7 7 0
D 47 15 0 20 2 0
E 25 0 46 9 4 2
F 0 53 50 26 4 20
Our aim now is to cover the zeros with minimum
horizontal and/or vertical lines. There is a systematic
procedure for the same
Hungarian Method [Example2]
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0 √
C 13 0 63 7 7 0
D 47 15 0 20 2 0
E 25 0 46 9 4 2
F 0 53 50 26 4 20
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0 √
C 13 0 63 7 7 0
D 47 15 0 20 2 0
E 25 0 46 9 4 2
F 0 53 50 26 4 20
√ √
Mark columns with zeros in marked rows
Hungarian Method [Example2]
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0 √
C 13 0 63 7 7 0 √
D 47 15 0 20 2 0
E 25 0 46 9 4 2
F 0 53 50 26 4 20 √
√ √
Mark rows (not already marked) which have
assignments in marked columns
Hungarian Method [Example2]
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0 √
C 13 0 63 7 7 0 √
D 47 15 0 20 2 0
E 25 0 46 9 4 2
F 0 53 50 26 4 20 √
√ √ √
Mark columns with zeros in marked rows
Hungarian Method [Example2]
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0 √
C 13 0 63 7 7 0 √
D 47 15 0 20 2 0
E 25 0 46 9 4 2 √
F 0 53 50 26 4 20 √
√ √ √
Mark rows (not already marked) which have
assignments in marked columns
Hungarian Method [Example2]
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0 √
C 13 0 63 7 7 0 √
D 47 15 0 20 2 0
E 25 0 46 9 4 2 √
F 0 53 50 26 4 20 √
√ √ √
DONE. Draw straight lines with unmarked row and
marked columns
Hungarian Method [Example2]
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0 √
C 13 0 63 7 7 0 √
D 47 15 0 20 2 0
E 25 0 46 9 4 2 √
F 0 53 50 26 4 20 √
√ √ √
Number of lines (5) < Number of rows or columns,
hence this is not optimal
Hungarian Method [Example2]
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0 √
C 13 0 63 7 7 0 √
D 47 15 0 20 2 0
E 25 0 46 9 4 2 √
F 0 53 50 26 4 20 √
√ √ √
Look for smallest uncovered element (it is 4)
Hungarian Method [Example2]
I II III IV V VI
A 0 13 49 0 0 13
B 0 35 29 5 10 0 √
C 13 0 63 7 7 0 √
D 47 15 0 20 2 0
E 25 0 46 9 4 2 √
F 0 53 50 26 4 20 √
√ √ √
Subtract 4 from uncovered elements and add 4 where lines
intersect
Hungarian Method [Example2]
I II III IV V VI
A 4 17 49 0 0 17
B 0 35 25 1 6 0 √
C 13 0 59 3 3 0 √
D 51 19 0 20 2 4
E 25 0 42 5 0 2 √
F 0 53 46 22 0 20 √
√ √ √
Subtract 4 from uncovered elements and add 4 where lines
intersect
Hungarian Method [Example2]
I II III IV V VI
A 4 17 49 0 0 17
B 0 35 25 1 6 0
C 13 0 59 3 3 0
D 51 19 0 20 2 4
E 25 0 42 5 0 2
F 0 53 46 22 0 20
Reduced Matrix
Hungarian Method [Example2]
I II III IV V VI
A 4 17 49 0 0 17
B 0 35 25 1 6 0
C 13 0 59 3 3 0
D 51 19 0 20 2 4
E 25 0 42 5 0 2
F 0 53 46 22 0 20
I II III IV V VI
A 4 17 49 0 0 17
B 0 35 25 1 6 0
C 13 0 59 3 3 0
D 51 19 0 20 2 4
E 25 0 42 5 0 2
F 0 53 46 22 0 20
Row fourth
Hungarian Method [Example2]
I II III IV V VI
A 4 17 49 0 0 17
B 0 35 25 1 6 0
C 13 0 59 3 3 0
D 51 19 0 20 2 4
E 25 0 42 5 0 2
F 0 53 46 22 0 20
Column fourth
Hungarian Method [Example2]
I II III IV V VI
A 4 17 49 0 0 17
B 0 35 25 1 6 0
C 13 0 59 3 3 0
D 51 19 0 20 2 4
E 25 0 42 5 0 2
F 0 53 46 22 0 20
I II III IV V VI
A 4 17 49 0 0 17
B 0 35 25 1 6 0
C 13 0 59 3 3 0
D 51 19 0 20 2 4
E 25 0 42 5 0 2
F 0 53 46 22 0 20
Row sixth
Hungarian Method [Example2]
I II III IV V VI
A 4 17 49 0 0 17
B 0 35 25 1 6 0
C 13 0 59 3 3 0
D 51 19 0 20 2 4
E 25 0 42 5 0 2
F 0 53 46 22 0 20
Column sixth
Hungarian Method [Example2]
I II III IV V VI
A 4 17 49 0 0 17
B 0 35 25 1 6 0
C 13 0 59 3 3 0
D 51 19 0 20 2 4
E 25 0 42 5 0 2
F 0 53 46 22 0 20
Row fifth
Hungarian Method [Example2]
I II III IV V VI
A 4 17 49 0 0 17
B 0 35 25 1 6 0
C 13 0 59 3 3 0
D 51 19 0 20 2 4
E 25 0 42 5 0 2
F 0 53 46 22 0 20
Each row and each column has exactly one assignment.
Hence, this is optimal
Hungarian Method [Example2]
I II III IV V VI
A 4 17 49 0 0 17
B 0 35 25 1 6 0
C 13 0 59 3 3 0
D 51 19 0 20 2 4
E 25 0 42 5 0 2
F 0 53 46 22 0 20
I II III IV V VI
A 9 22 58 11 19 27
B 43 78 72 50 63 48
C 41 28 91 37 45 33
D 74 42 27 49 39 32
E 36 11 57 22 25 18
F 3 56 53 31 17 28
COST 142
[ORIGINAL COST MATRIX] A-IV B-I C-VI D-III E-II F-
V
OPTIMAL ALLOCATION
Hungarian Method [Example2]
I II III IV V VI
A 9 22 58 11 19 27
B 43 78 72 50 63 48
C 41 28 91 37 45 33
D 74 42 27 49 39 32
E 36 11 57 22 25 18
F 3 56 53 31 17 28
COST 142
[ORIGINAL COST MATRIX] A-IV B-VI C-II D-III E-V F-
I
ATERNATE SOLUTION [YOU WERE ASKED TO KEEP A NOTE]
Hungarian Method [Steps]
Step 6: The Critical Step
Draw the minimum number of horizontal and/or vertical lines through all the
zeros. There is a procedure to achieve this...
i. Mark (√) to those rows where no assignments are made
ii. Mark (√) to those columns which have zeros in marked rows
iii. Mark (√) to the rows which have assignments in marked columns (do this
step to the rows not already marked)
iv. Repeat until no more rows or columns can be checked
v. Draw straight lines through unmarked rows and marked columns
Hungarian Method [Steps]
Step 6: The Critical Step
Draw the minimum number of horizontal and/or vertical lines through all the
zeros. There is a procedure to achieve this...
i. Mark (√) to those rows where no assignments are made
ii. Mark (√) to those columns which have zeros in marked rows
iii. Mark (√) to the rows which have assignments in marked columns (do this
step to the rows not already marked)
iv. Repeat until no more rows or columns can be checked
v. Draw straight lines through unmarked rows and marked columns
Hungarian Method [Steps]
Step 6: The Critical Step
Draw the minimum number of horizontal and/or vertical lines through all the
zeros. There is a procedure to achieve this...
i. Mark (√) to those rows where no assignments are made
ii. Mark (√) to those columns which have zeros in marked rows
iii. Mark (√) to the rows which have assignments in marked columns (do
this step to the rows not already marked)
iv. Repeat until no more rows or columns can be checked
v. Draw straight lines through unmarked rows and marked columns
Hungarian Method [Steps]
Step 6: The Critical Step
Draw the minimum number of horizontal and/or vertical lines through all the
zeros. There is a procedure to achieve this...
i. Mark (√) to those rows where no assignments are made
ii. Mark (√) to those columns which have zeros in marked rows
iii. Mark (√) to the rows which have assignments in marked columns (do this
step to the rows not already marked)
iv. Repeat until no more rows or columns can be checked
v. Draw straight lines through unmarked rows and marked columns
Hungarian Method [Steps]
Step 6: The Critical Step
Draw the minimum number of horizontal and/or vertical lines through all the
zeros. There is a procedure to achieve this...
i. Mark (√) to those rows where no assignments are made
ii. Mark (√) to those columns which have zeros in marked rows
iii. Mark (√) to the rows which have assignments in marked columns (do this
step to the rows not already marked)
iv. Repeat until no more rows or columns can be checked
v. Draw straight lines through unmarked rows and marked columns
Hungarian Method [Other Important Points]
Package lpSolve
and
Function lp.assign
Hungarian Method [Solution through R]
Hungarian Method [Solution through R]