## What Is The Hungarian Assignment Method For Solving Problem

Now we will examine a few highly simplified illustrations of **Hungarian Method** for solving an **assignment problem**.

Later in the chapter, you will find more practical versions of assignment models like Crew assignment problem, Travelling salesman problem, etc.

## Example 1: Hungarian Method

The Funny Toys Company has four men available for work on four separate jobs. Only one man can work on any one job. The cost of assigning each man to each job is given in the following table. The objective is to assign men to jobs in such a way that the total cost of assignment is minimum.

Job | ||||
---|---|---|---|---|

Person | 1 | 2 | 3 | 4 |

A | 20 | 25 | 22 | 28 |

B | 15 | 18 | 23 | 17 |

C | 19 | 17 | 21 | 24 |

D | 25 | 23 | 24 | 24 |

Solution.

This is a **minimization example** of assignment problem. We will use the **Hungarian Algorithm** to solve this problem.

#### Step 1

Identify the minimum element in each row and **subtract** it from every element of that row. The result is shown in the following table.

"A man has one hundred dollars and you leave him with two dollars, that's subtraction." -Mae West

Table

On small screens, scroll horizontally to view full calculation

Job | ||||
---|---|---|---|---|

Person | 1 | 2 | 3 | 4 |

A | 0 | 5 | 2 | 8 |

B | 0 | 3 | 8 | 2 |

C | 2 | 0 | 4 | 7 |

D | 2 | 0 | 1 | 1 |

Step 2

Identify the minimum element in each column and subtract it from every element of that column.

Table

Job | ||||
---|---|---|---|---|

Person | 1 | 2 | 3 | 4 |

A | 0 | 5 | 1 | 7 |

B | 0 | 3 | 7 | 1 |

C | 2 | 0 | 3 | 6 |

D | 2 | 0 | 0 | 0 |

Step 3

Make the assignments for the reduced matrix obtained from **steps 1 and 2** in the following way:

- For each row or column with a single zero value cell that has not be assigned or eliminated, box that zero value as an assigned cell.
- For every zero that becomes assigned, cross out (X) all other zeros in the same row and the same column.
- If for a row and a column, there are two or more zeros and one cannot be chosen by inspection, choose the cell arbitrarily for assignment.
- The above process may be continued until every zero cell is either assigned or crossed (X).

#### Step 4

An optimal assignment is found, if the number of assigned cells equals the number of rows (and columns). In case you have chosen a zero cell arbitrarily, there may be alternate optimal solutions. If no optimal solution is found, go to step 5.

Table

Use Horizontal Scrollbar to View Full Table Calculation

#### Step 5

Draw the minimum number of vertical and horizontal lines necessary to cover all the zeros in the reduced matrix obtained from step 3 by adopting the following procedure:

- Mark all the rows that do not have assignments.
- Mark all the columns (not already marked) which have zeros in the marked rows.
- Mark all the rows (not already marked) that have assignments in marked columns.
- Repeat steps 5 (ii) and (iii) until no more rows or columns can be marked.
- Draw straight lines through all unmarked rows and marked columns.

You can also draw the minimum number of lines by inspection.

Table

#### Step 6

Select the smallest element (i.e., 1) from all the uncovered elements. Subtract this smallest element from all the uncovered elements and add it to the elements, which lie at the intersection of two lines. Thus, we obtain another reduced matrix for fresh assignment.

Table

Job | ||||
---|---|---|---|---|

Person | 1 | 2 | 3 | 4 |

A | 0 | 4 | 0 | 6 |

B | 0 | 2 | 6 | 0 |

C | 3 | 0 | 3 | 6 |

D | 3 | 0 | 0 | 0 |

Now again make the assignments for the reduced matrix.

#### Final Table: Hungarian Method

Since the number of assignments is equal to the number of rows (& columns), this is the optimal solution.

The total cost of assignment = A1 + B4 + C2 + D3

Substituting values from original table:

20 + 17 + 17 + 24 = Rs. 78.

## The Hungarian algorithm: An example

We consider an example where four jobs (J1, J2, J3, and J4) need to be executed by four workers (W1, W2, W3, and W4), one job per worker. The matrix below shows the cost of assigning a certain worker to a certain job. The objective is to minimize the total cost of the assignment.

J1 | J2 | J3 | J4 | |

W1 | 82 | 83 | 69 | 92 |

W2 | 77 | 37 | 49 | 92 |

W3 | 11 | 69 | 5 | 86 |

W4 | 8 | 9 | 98 | 23 |

Below we will explain the Hungarian algorithm using this example. Note that a general description of the algorithm can be found here.

**Step 1: Subtract row minima**

We start with subtracting the row minimum from each row. The smallest element in the first row is, for example, 69. Therefore, we substract 69 from each element in the first row. The resulting matrix is:

J1 | J2 | J3 | J4 | ||

W1 | 13 | 14 | 0 | 23 | (-69) |

W2 | 40 | 0 | 12 | 55 | (-37) |

W3 | 6 | 64 | 0 | 81 | (-5) |

W4 | 0 | 1 | 90 | 15 | (-8) |

**Step 2: Subtract column minima**

Similarly, we subtract the column minimum from each column, giving the following matrix:

J1 | J2 | J3 | J4 | |

W1 | 13 | 14 | 0 | 8 |

W2 | 40 | 0 | 12 | 40 |

W3 | 6 | 64 | 0 | 66 |

W4 | 0 | 1 | 90 | 0 |

(-15) |

**Step 3: Cover all zeros with a minimum number of lines**

We will now determine the minimum number of lines (horizontal or vertical) that are required to cover all zeros in the matrix. All zeros can be covered using 3 lines:

J1 | J2 | J3 | J4 | ||

W1 | 13 | 14 | 0 | 8 | |

W2 | 40 | 0 | 12 | 40 | x |

W3 | 6 | 64 | 0 | 66 | |

W4 | 0 | 1 | 90 | 0 | x |

x |

Because the number of lines required (3) is lower than the size of the matrix (*n*=4), we continue with Step 4.

**Step 4: Create additional zeros**

First, we find that the smallest uncovered number is 6. We subtract this number from all uncovered elements and add it to all elements that are covered twice. This results in the following matrix:

J1 | J2 | J3 | J4 | |

W1 | 7 | 8 | 0 | 2 |

W2 | 40 | 0 | 18 | 40 |

W3 | 0 | 58 | 0 | 60 |

W4 | 0 | 1 | 96 | 0 |

Now we return to Step 3.

**Step 3: Cover all zeros with a minimum number of lines**

Again, We determine the minimum number of lines required to cover all zeros in the matrix. Now there are 4 lines required:

J1 | J2 | J3 | J4 | ||

W1 | 7 | 8 | 0 | 2 | x |

W2 | 40 | 0 | 18 | 40 | x |

W3 | 0 | 58 | 0 | 60 | x |

W4 | 0 | 1 | 96 | 0 | x |

Because the number of lines required (4) equals the size of the matrix (*n*=4), an optimal assignment exists among the zeros in the matrix. Therefore, the algorithm stops.

**The optimal assignment**

The following zeros cover an optimal assignment:

J1 | J2 | J3 | J4 | |

W1 | 7 | 8 | 0 | 2 |

W2 | 40 | 0 | 18 | 40 |

W3 | 0 | 58 | 0 | 60 |

W4 | 0 | 1 | 96 | 0 |

This corresponds to the following optimal assignment in the original cost matrix:

J1 | J2 | J3 | J4 | |

W1 | 82 | 83 | 69 | 92 |

W2 | 77 | 37 | 49 | 92 |

W3 | 11 | 69 | 5 | 86 |

W4 | 8 | 9 | 98 | 23 |

Thus, worker 1 should perform job 3, worker 2 job 2, worker 3 job 1, and worker 4 should perform job 4. The total cost of this optimal assignment is to 69 + 37 + 11 + 23 = 140.

Solve your own problem online

## One thought on “What Is The Hungarian Assignment Method For Solving Problem”