The Hungarian Algorithm – Maximisation problems

17
The Hungarian Algorithm – Maximisation problems The Hungarian algorithm for maximisation problems To solve a maximisation problem using the Hungarian algorithm, first subtract all elements in the array from the largest number in the array. Then apply the standard Hungarian algorithm: Step 1 Reduce the array by both row and column subtractions Step 2 Cover 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 3 Augment 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

description

The Hungarian Algorithm – Maximisation problems. The Hungarian algorithm for maximisation problems To solve a maximisation problem using the Hungarian algorithm, first subtract all elements in the array from the largest number in the array. Then apply the standard Hungarian algorithm: - PowerPoint PPT Presentation

Transcript of The Hungarian Algorithm – Maximisation problems

Page 1: The Hungarian Algorithm – Maximisation problems

The Hungarian Algorithm – Maximisation problems

The Hungarian algorithm for maximisation problems

To solve a maximisation problem using the Hungarian algorithm, first subtract all elements in the array from the largest number in the array.

Then apply the standard Hungarian algorithm:

Step 1 Reduce the array by both row and column subtractionsStep 2 Cover 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 3 Augment 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 4 Identify the maximal matching which uses only zero elements,

and apply this matching to the original array to find the minimum cost.

Page 2: The Hungarian Algorithm – Maximisation problems

ExampleA team of four athletes are taking part in a competition involving four events: high jump, long jump, discus and 100 m sprint. One athlete must be chosen for each event, and no athlete can take part in more than one event. In each event, the athlete’s result is converted into points. These points are added together to give the total score for the team.The points which each athlete can expect to achieve in each event, based on their personal best, are shown in the table below.Allocate the athletes to the events so that the total team score is as large as possible.

High jump Long jump Discus 100 m

Abby 120 155 159 113

Beth 175 133 184 152

Claire 134 141 132 104

Donna 176 174 182 168

The Hungarian Algorithm – Maximisation problems

Page 3: The Hungarian Algorithm – Maximisation problems

First convert the problem into a minimisation problem.

The largest element in the array is 184, so subtract each element from 184.

The Hungarian Algorithm – Maximisation problems

High jump Long jump Discus 100 m

Abby 120 155 159 113

Beth 175 133 184 152

Claire 134 141 132 104

Donna 176 174 182 168

High jump Long jump Discus 100 m

Abby 64 155 159 113

Beth 175 133 184 152

Claire 134 141 132 104

Donna 176 174 182 168

High jump Long jump Discus 100 m

Abby 64 29 159 113

Beth 175 133 184 152

Claire 134 141 132 104

Donna 176 174 182 168

High jump Long jump Discus 100 m

Abby 64 29 25 113

Beth 175 133 184 152

Claire 134 141 132 104

Donna 176 174 182 168

High jump Long jump Discus 100 m

Abby 64 29 25 71

Beth 175 133 184 152

Claire 134 141 132 104

Donna 176 174 182 168

High jump Long jump Discus 100 m

Abby 64 29 25 71

Beth 9 133 184 152

Claire 134 141 132 104

Donna 176 174 182 168

High jump Long jump Discus 100 m

Abby 64 29 25 71

Beth 9 51 184 152

Claire 134 141 132 104

Donna 176 174 182 168

High jump Long jump Discus 100 m

Abby 64 29 25 71

Beth 9 51 0 152

Claire 134 141 132 104

Donna 176 174 182 168

High jump Long jump Discus 100 m

Abby 64 29 25 71

Beth 9 51 0 32

Claire 134 141 132 104

Donna 176 174 182 168

High jump Long jump Discus 100 m

Abby 64 29 25 71

Beth 9 51 0 32

Claire 50 141 132 104

Donna 176 174 182 168

High jump Long jump Discus 100 m

Abby 64 29 25 71

Beth 9 51 0 32

Claire 50 43 132 104

Donna 176 174 182 168

High jump Long jump Discus 100 m

Abby 64 29 25 71

Beth 9 51 0 32

Claire 50 43 52 104

Donna 176 174 182 168

High jump Long jump Discus 100 m

Abby 64 29 25 71

Beth 9 51 0 32

Claire 50 43 52 80

Donna 176 174 182 168

High jump Long jump Discus 100 m

Abby 64 29 25 71

Beth 9 51 0 32

Claire 50 43 52 80

Donna 8 174 182 168

High jump Long jump Discus 100 m

Abby 64 29 25 71

Beth 9 51 0 32

Claire 50 43 52 80

Donna 8 10 182 168

High jump Long jump Discus 100 m

Abby 64 29 25 71

Beth 9 51 0 32

Claire 50 43 52 80

Donna 8 10 2 168

High jump Long jump Discus 100 m

Abby 64 29 25 71

Beth 9 51 0 32

Claire 50 43 52 80

Donna 8 10 2 16

Page 4: The Hungarian Algorithm – Maximisation problems

Step 1: Reduce the array by both row and column subtractions

To reduce by row subtractions, subtract the smallest element in each row from each element in the row.

The smallest element in Abby’s row is 25, so subtract 25 from each element in the row.

The Hungarian Algorithm – Maximisation problems

High jump Long jump Discus 100 m

Abby 64 29 25 71

Beth 9 51 0 32

Claire 50 43 52 80

Donna 8 10 2 16

High jump Long jump Discus 100 m

Abby 64 29 25 71

Beth 9 51 0 32

Claire 50 43 52 80

Donna 8 10 2 16

High jump Long jump Discus 100 m

Abby 39 4 0 46

Beth 9 51 0 32

Claire 50 43 52 80

Donna 8 10 2 16

Page 5: The Hungarian Algorithm – Maximisation problems

Step 1: Reduce the array by both row and column subtractions

To reduce by row subtractions, subtract the smallest element in each row from each element in the row.

Beth’s row already contains a zero, so this row cannot be reduced.

The Hungarian Algorithm – Maximisation problems

High jump Long jump Discus 100 m

Abby 39 4 0 46

Beth 9 51 0 32

Claire 50 43 52 80

Donna 8 10 2 16

High jump Long jump Discus 100 m

Abby 39 4 0 46

Beth 9 51 0 32

Claire 50 43 52 80

Donna 8 10 2 16

Page 6: The Hungarian Algorithm – Maximisation problems

Step 1: Reduce the array by both row and column subtractions

To reduce by row subtractions, subtract the smallest element in each row from each element in the row.

The smallest element in Claire’s row is 43, so subtract 43 from each element in this row.

The Hungarian Algorithm – Maximisation problems

High jump Long jump Discus 100 m

Abby 39 4 0 46

Beth 9 51 0 32

Claire 50 43 52 80

Donna 8 10 2 16

High jump Long jump Discus 100 m

Abby 39 4 0 46

Beth 9 51 0 32

Claire 50 43 52 80

Donna 8 10 2 16

High jump Long jump Discus 100 m

Abby 39 4 0 46

Beth 9 51 0 32

Claire 7 0 9 37

Donna 8 10 2 16

Page 7: The Hungarian Algorithm – Maximisation problems

Step 1: Reduce the array by both row and column subtractions

To reduce by row subtractions, subtract the smallest element in each row from each element in the row.

The smallest element in Donna’s row is 2, so subtract 2 from each element in this row.

The Hungarian Algorithm – Maximisation problems

High jump Long jump Discus 100 m

Abby 39 4 0 46

Beth 9 51 0 32

Claire 7 0 9 37

Donna 8 10 2 16

High jump Long jump Discus 100 m

Abby 39 4 0 46

Beth 9 51 0 32

Claire 7 0 9 37

Donna 8 10 2 16

High jump Long jump Discus 100 m

Abby 39 4 0 46

Beth 9 51 0 32

Claire 7 0 9 37

Donna 6 8 0 14

Page 8: The Hungarian Algorithm – Maximisation problems

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.

Step 1: Reduce the array by both row and column subtractions

High jump Long jump Discus 100 m

Abby 39 4 0 46

Beth 9 51 0 32

Claire 7 0 9 37

Donna 6 8 0 14

Page 9: The Hungarian Algorithm – Maximisation problems

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 smallest element in the High jump column is 6, so subtract 6 from each element in the column.

The Hungarian Algorithm – Maximisation problems

High jump Long jump Discus 100 m

Abby 39 4 0 46

Beth 9 51 0 32

Claire 7 0 9 37

Donna 6 8 0 14

High jump Long jump Discus 100 m

Abby 39 4 0 46

Beth 9 51 0 32

Claire 7 0 9 37

Donna 6 8 0 14

High jump Long jump Discus 100 m

Abby 33 4 0 46

Beth 3 51 0 32

Claire 1 0 9 37

Donna 0 8 0 14

Page 10: The Hungarian Algorithm – Maximisation problems

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 Long jump and Discus columns already contain zeros, so no column reduction is possible.

The Hungarian Algorithm – Maximisation problems

High jump Long jump Discus 100 m

Abby 33 4 0 46

Beth 3 51 0 32

Claire 1 0 9 37

Donna 0 8 0 14

High jump Long jump Discus 100 m

Abby 33 4 0 46

Beth 3 51 0 32

Claire 1 0 9 37

Donna 0 8 0 14

Page 11: The Hungarian Algorithm – Maximisation problems

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 smallest number in the 100 m column is 14, so subtract 14 from each element in this column.

The Hungarian Algorithm – Maximisation problems

High jump Long jump Discus 100 m

Abby 33 4 0 46

Beth 3 51 0 32

Claire 1 0 9 37

Donna 0 8 0 14

High jump Long jump Discus 100 m

Abby 33 4 0 46

Beth 3 51 0 32

Claire 1 0 9 37

Donna 0 8 0 14

High jump Long jump Discus 100 m

Abby 33 4 0 32

Beth 3 51 0 18

Claire 1 0 9 23

Donna 0 8 0 0

Page 12: The Hungarian Algorithm – Maximisation problems

High jump Long jump Discus 100 m

Abby 33 4 0 32

Beth 3 51 0 18

Claire 1 0 9 23

Donna 0 8 0 0

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 Discus column has three zeros and Donna’s row has two zeros, so cover these with lines.

The remaining zero 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.

The Hungarian Algorithm – Maximisation problems

Page 13: The Hungarian Algorithm – Maximisation problems

High jump Long jump Discus 100 m

Abby 33 4 0 32

Beth 3 51 0 18

Claire 1 0 9 23

Donna 0 8 0 0

Step 3: Augment the elements

The smallest uncovered element is 3 (in square B1).

Subtract 3 from all uncovered elementsand add 3 to all elements covered by two lines

The Hungarian Algorithm – Maximisation problems

High jump Long jump Discus 100 m

Abby 30 1 0 29

Beth 0 48 0 15

Claire 1 0 9 23

Donna 0 8 0 0

High jump Long jump Discus 100 m

Abby 30 1 0 29

Beth 0 48 0 15

Claire 1 0 12 23

Donna 0 8 3 0

Page 14: The Hungarian Algorithm – Maximisation problems

Step 3: Augment the elements

The smallest uncovered element is 3 (in square B1).

Subtract 3 from all uncovered elementsand add 3 to all elements covered by two lines

The Hungarian Algorithm – Maximisation problems

High jump Long jump Discus 100 m

Abby 30 1 0 29

Beth 0 48 0 15

Claire 1 0 12 23

Donna 0 8 3 0

Now return to Step 2.

Page 15: The Hungarian Algorithm – Maximisation problems

High jump Long jump Discus 100 m

Abby 30 1 0 29

Beth 0 48 0 15

Claire 1 0 12 23

Donna 0 8 3 0

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.

There are several different ways of covering them with four lines.

The Hungarian Algorithm – Maximisation problems

Page 16: The Hungarian Algorithm – Maximisation problems

Step 4: Identify the maximal matching using zero elements.

Look for rows and columns containing just one zero.

There is just one zero in Abby’s row and Claire’s row,and there is just one zero in the 100 m column.This means that square B1 must be the fourth zero selected.

The Hungarian Algorithm – Maximisation problems

High jump Long jump Discus 100 m

Abby 30 1 0 29

Beth 0 48 0 15

Claire 1 0 12 23

Donna 0 8 3 0

High jump Long jump Discus 100 m

Abby 30 1 0 29

Beth 0 48 0 15

Claire 1 0 12 23

Donna 0 8 3 0

High jump Long jump Discus 100 m

Abby 30 1 0 29

Beth 0 48 0 15

Claire 1 0 12 23

Donna 0 8 3 0

High jump Long jump Discus 100 m

Abby 30 1 0 29

Beth 0 48 0 15

Claire 1 0 12 23

Donna 0 8 3 0

Page 17: The Hungarian Algorithm – Maximisation problems

Step 4: Identify the maximal matching using zero elements.

From the array, Abby is allocated Discus, Beth is allocated High jump, Claire is allocated Long jump, and Donna is allocated 100 m.

Going back to the original array gives the points for each event.

Total points = 159 + 175 + 141 + 168 = 643.

The Hungarian Algorithm – Maximisation problems

High jump Long jump Discus 100 m

Abby 30 1 0 29

Beth 0 48 0 15

Claire 1 0 12 23

Donna 0 8 3 0

High jump Long jump Discus 100 m

Abby 120 155 159 113

Beth 175 133 184 152

Claire 134 141 132 104

Donna 176 174 182 168