# Allocation problems - The Hungarian Algorithm The Hungarian algorithm Step 1Reduce the array by both row and column subtractions Step 2Cover the zero elements.

## Presentation on theme: "Allocation problems - The Hungarian Algorithm The Hungarian algorithm Step 1Reduce the array by both row and column subtractions Step 2Cover the zero elements."— Presentation transcript:

Allocation problems - The Hungarian Algorithm The Hungarian algorithm Step 1Reduce the array by both row and column subtractions Step 2Cover the zero elements with the minimum number of lines. If the number of lines is the same as the size of the array, then go to Step 4. Step 3Augment the elements. To do this, identify the minimum uncovered element. Subtract this element from all uncovered elements, and add this element to all elements covered by two lines. Then return to step 2. Step 4Identify the maximal matching which uses only zero elements, and apply this matching to the original array to find the minimum cost.

Allocation problems - The Hungarian Algorithm Example Four workers are to be assigned to four tasks. No worker is to carry out more than one task. The expected times taken for each worker to carry out each of the tasks is shown below. Allocate the workers to the tasks so that the total time taken is as short as possible, giving the minimum time required. Task 1Task 2Task 3Task 4 Eva35241742 Fred33212335 George27201633 Holly29311938

Allocation problems - The Hungarian Algorithm The minimum number of lines needed to cover all the zeros is 2, Now reduce the array by subtracting the minimum entry in each column from all the entries in the column. so the solution is not optimal. Task 1Task 2Task 3Task 4 Eva187025 Fred120214 George114017 Holly1012019 Step 1:Reduce the array by both row and column subtractions

Allocation problems - The Hungarian Algorithm Step 1:Reduce the array by both row and column subtractions To reduce by column subtractions, subtract the smallest element in each column from each element in the column. The Task 2 and Task 3 columns both contain zeros, so no column subtraction can be done in these two columns. Task 1Task 2Task 3Task 4 Eva87025 Fred20214 George14017 Holly012019

Allocation problems - The Hungarian Algorithm Step 2:Cover the zero elements with the minimum number of lines Look for rows and columns containing more than one zero. In this case, the Task 3 column has three zeros and Fred’s row has two zeros, so cover these with lines. Task 1Task 2Task 3Task 4 Eva87011 Fred2020 George1403 Holly01205 The remaining zero, in square H1, can be covered by either a vertical or horizontal line. The choice of line will not affect the final result. Three lines have been used, so this array does not give the optimal allocation.

Allocation problems - The Hungarian Algorithm Step 3:Augment the elements The smallest uncovered element is 1 (in square G1). Subtract 1 from all uncovered elements and add 1 to all elements covered by two lines Task 1Task 2Task 3Task 4 Eva76010 Fred2030 George0302 Holly01215 Now return to Step 2.

Allocation problems - The Hungarian Algorithm Step 2:Cover the zero elements with the minimum number of lines. Again, look for rows and columns containing more than one zero. Here, the Task 1 and Task 3 columns and Fred’s row each have two zeros. Covering these with lines covers all the zeros. Task 1Task 2Task 3Task 4 Eva76010 Fred2030 George0302 Holly01215 Three lines have been used, so this array still does not give the optimal allocation.

Allocation problems - The Hungarian Algorithm Step 3:Augment the elements. The smallest uncovered element is 2 (in square G4). Subtract 2 from all uncovered elements and add 2 to all elements covered by two lines. Task 1Task 2Task 3Task 4 Eva7408 Fred4050 George0100 Holly01013 Now return to Step 2.

Allocation problems - The Hungarian Algorithm Step 2:Cover the zero elements with the minimum number of lines. In this case, it is not possible to cover the zero elements with less than four lines. Since four lines are required for this 4 by 4 array, the optimal allocation can now be found from this array. Now go to Step 4. Task 1Task 2Task 3Task 4 Eva7408 Fred4050 George0100 Holly01013 There are several different ways of covering them with four lines.