D2: Allocation


Today is Sports Day at World of Math!

Your task is to pick a dream team of students to do a relay race. Each student must be assigned one part of the race to run. The legs are: Egg & Spoon, Backwards Running, Hopping and Skipping. Each athlete has promised that they will achieve their personal best in whatever part of the race you ask them to do. The personal bests are given in this table.

Egg & SpoonBackwards RunningHoppingSkipping
Amos20221424
Biff20191220
Cecil13101816
Dave2223928

Now try to pick a team of World Beaters.

Cost Reduction

The Hungarian algorithm is quite difficult to understand; I'll try my best to explain why it works.

First, we try to simplify the numbers in the table. Notice that Amos will take at least 14 seconds, regardless of what event he does. We could subtract 14 from all of his personal best times. I have called this the basic time and now the time for the Egg & Spoon for Amos is his basic time (14) plus the extra (6).

Egg & SpoonBackwards RunningHoppingSkippingBasic Time
Amos6801014
Biff20191220
Cecil13101816
Dave2223928

I now repaeat this for the other contestants. This process is called row reduction.

Egg & SpoonBackwards RunningHoppingSkippingBasic Time
Amos6801014
Biff870812
Cecil308610
Dave13140199

Now look at the columns. Regardless of who runs the Egg & Spoon race, the time will be at least 3 seconds more than the basic time for the athlete. Amos takes 8 seconds more than his basic time, etc. The basic add-on time for Egg & Spoon is 3 seconds, so we could deduct this from all the times, knowing that whoever runs the Egg & Spoon will add at least 3 seconds to the basic times.

Egg & SpoonBackwards RunningHoppingSkippingBasic Time
Amos3801014
Biff570812
Cecil008610
Dave10140199
Basic add-on3

From the above table we see that Dave takes 10 seconds more than his basic time (9) plus the Egg& Spoon add-on (3). This is not a good event for Dave. I repeat this column reduction for the remaining events.

Egg & SpoonBackwards RunningHoppingSkippingBasic Time
Amos380414
Biff570212
Cecil008010
Dave10140139
Basic add-on3008

I'm getting a bit fed up with all these tables, so I'll explain in a clip instead.

The Hungarian Algorithm

Variations

The Hungarian algorithm is a minimising algorithm and there are three special cases of which we need to be aware.

Maximising Problems

If we are running a business and need to maximise an allocation problem, we change the values to represent how much change we'd give, and try to minimise that total. Eg Four people I, II, III and IV are going to buy stuff of us. The amount they'll each pay is in the table.

ABCD
I20221424
II20191220
III13101816
IV2223928

Pretend that they all pay £30. The change we give them is therefore:

ABCD
I108166
II10111810
III17201214
IV87212

We now try to minimise the change we give (this is equivalent to maximising the costs).

Note that I subtracted from £30. In reality I would subtract from £28 as this is the highest number in the original table.

Gaps In The Table

If Amos was unwilling to do the skipping race, we could get round that by making up a ridiculously high number for his time, and proceed as usual. How high is ridiculously high? In a 4x4 table the maximum that the answer can be is 4× the highest number, since we use four numbers in total. To ensure we don't accidentally make Amos do the skipping race, we make his time greater than 4× the biggest number.

Egg & SpoonBackwards RunningHoppingSkipping
Amos202214-
Biff20191220
Cecil13101816
Dave2223928

becomes

Egg & SpoonBackwards RunningHoppingSkipping
Amos202214100
Biff20191220
Cecil13101816
Dave2223928

The 100 is more than 4× the highest number, so Amos can relax - we won't be using him for the skipping race.

More Rows Than Columns Or Vice Versa

If there wasn't a skipping race, then one athlete would have no event to run. In the case of having an oblong matrix (eg 3 by 4), we add a dummy row/column with zeros in it, much like we did in the transportation section.

Egg & SpoonBackwards RunningHopping
Amos202214
Biff201912
Cecil131018
Dave22239

becomes

Egg & SpoonBackwards RunningHoppingDummy
Amos2022140
Biff2019120
Cecil1310180
Dave222390

and we proceed as before.

Formulating A Linear Program