A Level Further Mathematics · Chapter 72 · Decision Mathematics · Decision 2
Giving each worker one job at the least total cost sounds like endless trial and error, but the Hungarian algorithm solves it with a few subtractions.
A manager with four workers and four jobs, each worker suited differently to each job, wants the cheapest way to give everyone one job. This chapter teaches the Hungarian algorithm, which finds the best allocation by creating zeros in the cost matrix and choosing among them.
In this chapter · jump to a section
Start here
Your route through this chapter
By the end of this chapter you will be able to:
- set up a cost matrix and add a dummy row or column when it is not square
- reduce a cost matrix by rows and by columns
- cover the zeros with the least number of lines and decide whether an allocation can be made
- carry out the augmentation step and read off an optimal allocation
- adapt the algorithm for maximising profit and for prohibited allocations
- formulate an allocation problem as a linear programme
Time: two sessions, about 3 hours, plus the practice ladder and the exam workshop.
You need first: transportation problems, and the idea of a linear programme.
The big idea
The big idea
An allocation problem pairs each worker with exactly one task, and each task with exactly one worker, to minimise the total cost. Subtracting a constant from a whole row or column changes every allocation's cost by the same amount, so it never changes which allocation is best.
This chapter uses four workers, A to D, and four tasks, 1 to 4. The table shows the cost, in pounds, of each worker doing each task.
| 1 | 2 | 3 | 4 | |
|---|---|---|---|---|
| A | 6 | 11 | 7 | 14 |
| B | 13 | 19 | 6 | 20 |
| C | 20 | 17 | 14 | 10 |
| D | 18 | 15 | 13 | 9 |
The cheapest allocation, found in section 4, costs £37. Notice that D is given task 2 at a cost of 15, even though D's cheapest task is 4. Giving task 4 to C instead saves more overall.
Allocation problems
An allocation, or assignment, problem has workers and tasks. Each worker does exactly one task and each task is done by exactly one worker. The cost matrix gives the cost of every pairing.
Counting allocations
The first worker can take any of tasks, the second any of the remaining , and so on. So there are possible allocations. Four workers give 24, but ten give over three million, so checking them all quickly becomes impossible.
A special transportation problem
An allocation problem is a transportation problem in which every supply and every demand equals 1. The transportation method would work, but it is very degenerate. The Hungarian algorithm is much quicker for this special case.
Adding a constant works too
Adding the same number to every entry of a row also leaves the best allocation unchanged. The algorithm only ever subtracts, to create zeros, but the augmentation step effectively adds to some rows and columns. Both directions keep the ranking of allocations the same.
Why subtracting works
Every allocation uses exactly one entry from each row. Subtracting a number from a whole row lowers every allocation's cost by that number. The ranking of allocations is unchanged, so the cheapest allocation stays the cheapest.
Zeros mark the best choices
After subtracting, every entry is still zero or positive. An allocation that uses only zero entries costs nothing in the reduced matrix, so it must be optimal. The algorithm creates zeros until such an allocation exists.
The algorithm in outline
Reduce the rows, then the columns. Cover all the zeros with as few lines as possible. If lines are needed, allocate on the zeros. Otherwise, adjust the matrix to create a new zero and cover again.
Where allocation problems arise
Allocation problems appear whenever items must be paired one-to-one: staff to shifts, machines to jobs, teachers to classes, or swimmers to legs of a relay. In each case every item on one side must be matched with exactly one item on the other, and some pairings are better than others.
The name of the algorithm
The Hungarian algorithm is named after two Hungarian mathematicians, Dénes Kőnig and Jenő Egerváry, whose results it relies on. It was developed into its modern form by Harold Kuhn in 1955. It remains a standard method for allocation problems of moderate size.
Section 1
Setting up the problem
The cost matrix
Write the costs in a square table with workers as rows and tasks as columns. Label every row and column clearly. The algorithm works on the numbers, but the labels are needed to state the final allocation.
Common mistake: forgetting to add a dummy row or column of zeros when the matrix is not square. The algorithm needs one task for every worker. With more tasks than workers, add a dummy worker; with more workers than tasks, add a dummy task, each with zero costs.
Dummy rows and columns
A dummy worker or task represents "nobody" or "nothing". Its costs are zero because no real work or cost is involved. In the final allocation, a dummy pairing shows which task is left undone or which worker is left idle.
Reading a problem in words
Allocation problems appear as workers and jobs, machines and tasks, drivers and routes, or teams and events. Identify which items are being paired, check that each must be used exactly once, and build the matrix.
Ties in row and column minima
If a row has two equal least entries, row reduction creates two zeros in that row. That is perfectly fine: both mark equally good choices for that worker. Ties often lead to several optimal allocations later on.
Equal costs
If two entries are equal, the algorithm treats them the same. Ties may give more than one optimal allocation, all with the same cost. State one allocation, and say if others exist when the question asks.
Costs, times or distances
The entries can be costs, times or distances, as long as smaller is better and totals are meaningful. If larger is better, such as profits or scores, the matrix must first be converted, as section 5 explains.
Units of the entries
Entries might be pounds, minutes or kilometres. Make sure they are all in the same units before starting, and state the units in the final answer. Mixing units, such as hours and minutes, silently ruins the comparison between pairings.
Checking the matrix
Before starting, check that the matrix is square and that each entry is in the right place. A single misplaced entry changes the answer. A careful check now saves time later.
Why not try every allocation?
For four workers, listing all 24 allocations is tedious but possible. For eight workers there are 40 320, and for twelve almost half a billion. The Hungarian algorithm needs only a few passes through the matrix whatever its size, so it stays practical where listing does not.
Allocations and permutations
Each allocation corresponds to a permutation of the tasks: the order in which tasks are given to workers A, B, C and so on. Counting allocations is therefore counting permutations, which is why the answer is . This connects allocation problems to the counting methods of earlier mathematics.
Worked example 1: counting allocations
How many possible allocations are there for four workers and four tasks?
| Working | Reason |
|---|---|
| A has 4 choices, then B has 3 | Each task is used once |
| C has 2 choices, then D has 1 | The last worker takes what is left |
| allocations | Multiply the numbers of choices |
Interpreting a dummy task
If there are more workers than tasks, a dummy task is added as an extra column of zeros. The worker allocated to the dummy task is left without real work. The algorithm chooses that worker so that the real tasks are covered as cheaply as possible.
Dummies and fairness
A dummy decides who is left out, purely on cost. That may not be what a manager wants: the same worker might always be left idle. If fairness matters, the costs can be adjusted, or a rule added outside the model.
Worked example 2: a dummy worker
Only workers A, B and C are available for the four tasks. Set up the matrix and find the least cost.
| Working | Reason |
|---|---|
| Add a dummy row of zeros | Three workers but four tasks |
| Allocation A1, B3, C4, dummy 2 | Found by the Hungarian algorithm |
| Cost ; task 2 is not done | The dummy pairing costs nothing |
Check yourself. How many possible allocations are there for five workers and five tasks?
Show the answer
There are possible allocations, one for each way of ordering the tasks among the workers.
Section 2
Reducing the matrix
Row reduction
Subtract the least entry in each row from every entry in that row. Each row then contains at least one zero. For the workers, the row minima are 6, 6, 10 and 9.
Common mistake: reading the total cost of the allocation from the reduced matrix instead of from the original costs. Reduction subtracts the same amount from every allocation, so the reduced entries are not real costs. Always add up the original costs of the chosen pairings.
Row and column reduction
- Total subtracted
- 36
- Lines to cover the zeros
- 3
- Cost of the allocation
- 37
Figure 72.1 shows the reduction in two stages. The shaded allocation is the optimal one, and its true cost comes from the original matrix.
Column reduction
Next, subtract the least entry in each column from every entry in that column. Columns that already contain a zero are unchanged. For the workers, only column 2 changes, with least entry 5.
The reduced matrix
After both reductions, every row and every column contains at least one zero. The reduced matrix is the starting point for the rest of the algorithm. All its entries are non-negative.
The reduction total
The total subtracted, rows and columns together, is a lower bound for the optimal cost. Here it is . No allocation can cost less than this, since every allocation's cost fell by exactly 36.
Rows first
Exam questions usually ask for rows to be reduced first, then columns. Reducing columns first gives a different reduced matrix but the same optimal allocation. Follow the order the question gives.
Why reduction creates zeros
Each row reduction creates a zero at the cheapest task for that worker. Each column reduction creates a zero at the cheapest worker for that task. The zeros mark promising pairings.
Proof: reducing a row does not change the optimal allocation
Every allocation uses exactly one entry from row . If is subtracted from row , each allocation's total cost becomes
so for any two allocations with costs and ,
The differences between allocations are unchanged, so the cheapest allocation is still the cheapest. The same argument applies to columns.
Reduction in words
Row reduction asks each worker: compared with your cheapest task, how much extra would each other task cost? Column reduction then asks each task: compared with its cheapest worker, how much extra would each other worker cost? The reduced entries are these extra costs.
Recording the reductions
Write the amount subtracted beside each row and below each column. Their total gives the lower bound, and the record lets an examiner check the reduced matrix. A clear record also helps when tracing an error back through the working.
A picture of reduction
Imagine each row of the matrix as a list of prices offered by one worker. Row reduction removes each worker's basic charge, leaving only the extra each task would cost. Column reduction does the same for each task. What remains shows the relative merits of the pairings, not their absolute costs.
Reduction never creates negatives
Subtracting a row's least entry leaves every entry in that row zero or positive. The same holds for columns. So the reduced matrix always has non-negative entries, which is essential for the argument that an allocation on zeros is optimal.
Worked example 3: row reduction
Reduce the rows of the workers' cost matrix.
| Working | Reason |
|---|---|
| Row minima 6, 6, 10 and 9 | Least entry in each row |
| Row A becomes 0, 5, 1, 8 | Subtract 6 from every entry |
| Rows B, C, D: 7, 13, 0, 14; 10, 7, 4, 0; 9, 6, 4, 0 | Subtract each row's minimum |
When columns need no reduction
If every column already contains a zero after row reduction, column reduction changes nothing. That is quite common, as columns 1, 3 and 4 show here. It is still worth stating that the column minima are zero, to show the step was checked.
Reduction can finish the job
Sometimes, after reduction, the zeros already allow a complete allocation. Then no augmentation is needed, and the reduction total is the optimal cost. The converted profit matrix in section 5 is an example of this.
Worked example 4: column reduction
Reduce the columns of the row-reduced matrix, and find the reduction total.
| Working | Reason |
|---|---|
| Column minima 0, 5, 0, 0 | Only column 2 lacks a zero |
| Column 2 becomes 0, 8, 2, 1 | Subtract 5 from every entry |
| Total subtracted | A lower bound for the cost |
Check yourself. After row reduction, what does row C of the workers' matrix become?
Show the answer
Row C is 20, 17, 14, 10, with least entry 10. Subtracting 10 gives 10, 7, 4, 0, so the zero is in task 4.
What a line represents
A line through a row says that worker will be allocated to one of the zeros in that row. A line through a column says that task will be given to one of the zeros in that column. Covering every zero with few lines shows how few independent choices the zeros allow.
Section 3
Covering the zeros
The covering test
Cover all the zeros in the reduced matrix using horizontal and vertical lines, using as few lines as possible. If the least number of lines equals , an optimal allocation can be made on the zeros. If fewer lines suffice, it cannot yet.
Common mistake: deciding the matrix is optimal when the zeros can be covered by fewer than n lines. Fewer than lines means the zeros are bunched into too few rows and columns. There is then no way to choose zeros with one in each row and column.
Finding the least number of lines
Start with rows or columns containing several zeros, since one line covers them all. Then add lines for any zeros still uncovered. Check that no smaller set of lines would do: a good guess can be confirmed by finding that many independent zeros.
Independent zeros
Zeros are independent if no two share a row or a column. The least number of covering lines equals the greatest number of independent zeros. This result, König's theorem, is why the covering test works.
The workers' reduced matrix
Rows A and B and column 4 cover every zero: A has zeros in columns 1 and 2, B in column 3, and C and D in column 4. So 3 lines suffice, which is fewer than 4. The matrix is not yet optimal.
Why not just allocate?
With only 3 independent zeros, at most 3 workers can be placed on zeros. The fourth must take a non-zero entry, and a different allocation might avoid that. More zeros are needed before an optimal allocation can be read off.
Drawing lines in an exam
Draw lines clearly through whole rows or columns, and state how many are used. Examiners award marks for the number of lines and for the conclusion drawn from it, so write both down.
A strategy for drawing lines
Start with any row or column that has more zeros than any other, and draw a line through it. Then look at the zeros still uncovered and repeat. If the result uses more lines than seem necessary, try starting from a different row or column.
Checking you have the least number
To confirm that lines are the least possible, find zeros with no two in the same row or column. Each line can cover at most one of them, so at least lines are needed. For the workers, the zeros at A1, B3 and C4 do this for .
Worked example 5: covering the zeros
Cover the zeros of the workers' reduced matrix and decide whether an allocation can be made.
| Working | Reason |
|---|---|
| Lines through rows A and B and column 4 | Every zero is covered |
| 3 lines are enough | No 2 lines cover them all |
| , so not yet optimal | Need as many lines as workers |
Lines and independent zeros together
The covering test and the count of independent zeros always agree. If three lines suffice, at most three zeros can be chosen with no two in a line. This equality, König's theorem, is what makes a simple count of lines a reliable test of optimality.
A worked check with the workers
Try to place four workers on zeros of the reduced matrix. A must take task 1 or 2, B must take task 3, and both C and D want task 4. Since C and D cannot both have task 4, a complete allocation on zeros is impossible.
Worked example 6: the lower bound
Explain why the optimal cost is at least 36, and use the covering test to explain why 36 is not achieved.
| Working | Reason |
|---|---|
| Reduction subtracted 36 from every allocation | All reduced entries are non-negative |
| So every allocation costs at least 36 | The reduced cost is at least zero |
| Only 3 independent zeros, so cost exceeds 36 | No allocation uses only zeros |
Check yourself. After the augmentation in section 4, how many lines are needed to cover the zeros?
Show the answer
After augmenting, four lines are needed: the zeros now include four independent ones, at A1, B3, C4 and D2. Four lines equal four workers, so the matrix is optimal.
Why augmentation is needed
Reduction alone creates one zero in each row and column, but those zeros may cluster. Augmentation moves value around the matrix to create zeros in new places, without changing which allocation is best. It is repeated only until enough independent zeros exist.
Section 4
Augmenting and allocating
The augmentation step
Find the least entry not covered by any line. Subtract it from every uncovered entry and add it to every entry covered by two lines. Entries covered by one line stay the same. Then cover the zeros again.
Common mistake: adding the least uncovered entry to the uncovered entries instead of subtracting it. Subtracting creates a new zero where the lines did not reach. Adding only makes those entries larger, so the number of lines needed never increases.
Covering zeros and augmenting
- Lines needed
- 3
- Least uncovered entry
- 1
- Optimal?
- no: augment
- Augmentations needed
- 1
Figure 72.2 shows the covering lines before and after the augmentation, and what goes wrong if the least entry is added instead.
Why the augmentation works
Subtracting from the uncovered entries is like subtracting from every row without a line and adding back to every column with a line. That is a combination of row and column reductions, so the optimal allocation is unchanged. And it creates at least one new zero.
Applying it to the workers
The uncovered entries are in rows C and D, columns 1 to 3: 10, 2, 4 and 9, 1, 4. The least is 1. Subtract 1 from these and add 1 to the entries in rows A and B of column 4.
The new matrix
The new matrix is 0, 0, 1, 9; 7, 8, 0, 15; 9, 1, 3, 0; 8, 0, 3, 0. Now four lines are needed to cover the zeros, so an optimal allocation can be made.
Proof: the augmentation step is a combination of reductions
Let be the least uncovered entry. Subtract from every row without a line, and add to every column with a line. An uncovered entry changes by
an entry covered once is unchanged, and an entry where a row line and a column line cross changes by
Since subtracting from rows and adding to columns change every allocation's cost equally, the optimal allocation is unchanged.
Reading off the allocation
Look for a row or column with only one zero, and allocate there. Cross out that row and column, and repeat. For the workers, B has only one zero, in column 3; then C must take 4, D must take 2 and A takes 1.
Why the bound was nearly met
The lower bound of 36 came from the reductions, and the augmentation then subtracted 1 from six uncovered entries and added 1 to two crossing entries. The net effect on the best allocation was to raise the bound by exactly 1, to 37.
The cost of the allocation
Add the original costs of the chosen pairings: A1 6, B3 6, C4 10 and D2 15. The total is 37, one more than the lower bound of 36, which matches the one augmentation step of size 1.
Repeated augmentations
Sometimes one augmentation is not enough. Cover the zeros again, and if fewer than lines still suffice, augment again. Each augmentation adds to the lower bound, and the process always finishes.
The effect on the lower bound
Each augmentation raises the lower bound. Here the least uncovered entry was 1, and the bound rose from 36 to 37, which is the optimal cost. In general the rise depends on the numbers of lines and rows involved, but it is always positive.
Covering again after augmenting
After augmenting, the old lines no longer apply. Cover the zeros of the new matrix from scratch, using the least number of lines. Reusing the old lines can hide a new zero and lead to a wrong conclusion about optimality.
Worked example 7: augmenting
Carry out the augmentation step on the workers' reduced matrix.
| Working | Reason |
|---|---|
| Least uncovered entry is 1, in row D, column 2 | Search outside the three lines |
| Subtract 1 from rows C and D in columns 1 to 3 | These entries are uncovered |
| Add 1 to A4 and B4 | Covered by two lines |
Several optimal allocations
When the final matrix has more zeros than needed, there may be more than one way to choose independent zeros. Each gives an optimal allocation with the same cost. Exam questions sometimes ask for every optimal allocation, so check for alternatives.
Checking the allocation
Make sure the allocation uses each row once and each column once. Then add the original costs. If the total is below the reduction total, a mistake has been made, because no allocation can beat the lower bound.
Worked example 8: the allocation
Read off the optimal allocation and its cost.
| Working | Reason |
|---|---|
| B has one zero, in column 3: B3 | Allocate single zeros first |
| Then C4, D2 and A1 | Each row and column once |
| Cost | Read from the original matrix |
Check yourself. How many augmentation steps did the workers' problem need?
Show the answer
One augmentation step was needed. After it, the zeros could not be covered with fewer than four lines, so the optimal allocation could be read off.
Section 5
Maximisation and prohibited allocations
Maximising
If the matrix holds profits, the aim is the greatest total. Subtract every entry from the largest entry in the matrix to get opportunity costs, then apply the Hungarian algorithm to minimise them. The same allocation maximises the profit.
Common mistake: applying the Hungarian algorithm directly to a profit matrix, which finds the least profitable allocation. The algorithm always minimises. Converting profits to opportunity costs first turns the maximisation into a minimisation.
Maximising profit
- Largest entry
- 20
- Maximum profit
- 66
- Allocation
- A4, B2, C1, D3
Figure 72.3 converts the workers' matrix into a profit problem. The maximum profit of 66 needs a different allocation from the minimum cost.
Why the conversion works
Each allocation's opportunity cost is times the largest entry minus its profit. Minimising the opportunity cost therefore maximises the profit. Any constant larger than every entry would work, but the largest entry keeps the numbers small.
How large should M be?
M must be larger than any total the algorithm could otherwise reach, so that a pairing with cost M is never worth choosing. In hand working, keep it as the letter M and treat it as larger than any number it is compared with, just as in the big-M method.
Prohibited allocations
If a worker cannot do a task, give that pairing a very large cost, written M. The algorithm will never choose it. For a maximisation, give the prohibited pairing a profit of 0 or a very large opportunity cost after conversion.
Reading the maximum profit
As with costs, read the total from the original profit matrix, not the converted one. For the workers, the best allocation A4, B2, C1, D3 gives .
Combining adjustments
A problem may need a dummy, a conversion and a prohibited pairing all at once. Apply them in a sensible order: square the matrix, mark prohibited pairings, then convert if maximising. Keep track of which entries are real.
Opportunity costs
An opportunity cost measures what is lost by not choosing the best possible value. Subtracting each profit from the largest profit gives how far each pairing falls short of the best pairing in the whole matrix. Minimising the total shortfall maximises the total profit.
Prohibited pairings in a profit problem
If a pairing is prohibited in a profit problem, give it a very large opportunity cost after the conversion, rather than a profit of 0 before it. This makes certain it is never chosen, even when all the other profits are small.
Scores and ratings
Some problems give scores, such as how well each swimmer performs each stroke, where higher is better. Treat them exactly like profits: subtract every score from the highest, then minimise. Read the final total from the original scores.
Worked example 9: converting profits
Treat the workers' matrix as profits and convert it for maximisation.
| Working | Reason |
|---|---|
| Largest entry is 20 | Found in rows B and C |
| Row A becomes 14, 9, 13, 6 | Subtract each entry from 20 |
| Rows B, C, D: 7, 1, 14, 0; 0, 3, 6, 10; 2, 5, 7, 11 | Subtract each entry from 20 |
Comparing minimum and maximum
The cheapest allocation for the workers, A1, B3, C4, D2, is quite different from the most profitable one, A4, B2, C1, D3. That is no surprise: the two problems ask opposite questions of the same numbers, and the conversion makes the difference precise.
A quick check on a maximisation
The maximum profit can be no more than the sum of the row maxima, here . The answer 66 is below this, as it must be. Such quick bounds catch errors in conversions.
Worked example 10: the maximum profit
Find the allocation that maximises the profit.
| Working | Reason |
|---|---|
| Hungarian algorithm on the converted matrix | Minimise the opportunity cost |
| Allocation A4, B2, C1, D3 | Zeros after reduction allow this |
| Profit | Read from the original profits |
Check yourself. In the converted matrix of worked example 9, what is the opportunity cost of C doing task 1?
Show the answer
C doing task 1 has profit 20, the largest entry. Its opportunity cost is , so it is a very attractive pairing.
Allocation as linear programming
Seeing the allocation problem as a linear programme connects it to everything else in Decision Mathematics. Computer solvers use this formulation, especially when extra conditions make the Hungarian algorithm hard to apply. Examples include limits on total time or groups of workers who must work together.
Section 6
Formulating as a linear programme
Decision variables
Let if worker does task , and 0 otherwise. There is one variable for each pairing, so an problem has variables. Each variable is either 0 or 1.
Common mistake: leaving out the column constraints, so two workers could be given the same task. Each task must be done exactly once, so each column of variables must sum to 1. Without these constraints, the cheapest task could be given to everyone.
The objective
Minimise , the total cost of the chosen pairings. Only pairings with contribute. For the workers, the objective has sixteen terms.
Row constraints
Each worker does exactly one task: for every worker . For A, this is .
Column constraints
Each task is done exactly once: for every task . For task 1, this is .
Totally unimodular constraints
The reason fractional solutions never appear is technical: the constraint matrix has a property called total unimodularity, which guarantees whole-number vertices. Transportation problems share this property, which is why their solutions are whole numbers too.
Integer variables
In principle each must be 0 or 1. Remarkably, solving the linear programme with always gives whole-number answers, because of the problem's special structure. So the ordinary simplex method could be used.
Why use the Hungarian algorithm?
The linear programme has variables and constraints, which is large even for small . The Hungarian algorithm uses the structure directly and is far quicker by hand. The formulation shows how the problem fits into linear programming.
The cost of a restriction
Prohibiting A1 raised the optimal cost from 37 to 45. The difference, 8, is the price of the restriction. Managers can use such differences to decide whether a restriction, such as a worker's preference, is worth honouring.
Worked example 11: a prohibited pairing
Worker A cannot do task 1. Find the new optimal allocation and its cost.
| Working | Reason |
|---|---|
| Replace A1 by a very large cost M | A1 can never be chosen |
| Hungarian algorithm gives A2, B3, C4, D1 | The best allocation avoiding A1 |
| Cost | Read from the original matrix |
Constraints in a smaller example
For two workers and two tasks, the constraints are , , and . The only solutions with each variable 0 or 1 are the two possible allocations, as expected.
Adapting the formulation
A prohibited pairing can be removed by setting its variable to 0. A maximisation simply changes "minimise" to "maximise" in the objective. The constraints stay the same, which is one advantage of the linear programming view.
Worked example 12: the linear programme
Formulate the workers' problem as a linear programme.
| Working | Reason |
|---|---|
| if worker does task ; 16 variables | One for every pairing |
| Minimise | Total cost of chosen pairings |
| Each row sums to 1; each column sums to 1 | One task each, each task once |
Check yourself. For five workers and five tasks, how many decision variables are needed?
Show the answer
There is one variable for each pairing of a worker with a task, so the problem needs variables.
Reference
Results in this chapter
| Result | What it says | When to use it | In the formula booklet? |
|---|---|---|---|
| allocations | Number of possibilities | Why an algorithm is needed | No, learn it |
| Add a dummy of zeros | Square the matrix | Unequal numbers | No, learn it |
| Reduce rows, then columns | Create zeros | Start of the algorithm | No, derive it |
| lines needed means optimal | Covering test | After each reduction | No, learn it |
| Subtract least uncovered; add at crossings | Augmentation | Fewer than lines | No, learn it |
| Subtract from the largest entry | Maximisation | Profit matrices | No, learn it |
Reasoning
Modelling task: assigning delivery drivers
The situation
A delivery firm has four drivers, A to D, and four routes, 1 to 4, for tomorrow. The costs in the big idea are each driver's expected cost for each route, in pounds, allowing for distance from home and familiarity with the area. The manager wants each driver on one route at the least total cost.
Assumptions
Each driver takes exactly one route and each route needs exactly one driver. The costs are fixed and independent: one driver's route does not affect another's cost. No driver is unable to drive any route.
These assumptions make the plan a four by four allocation problem.
The model
Row reduction subtracts 6, 6, 10 and 9, and column reduction subtracts 5 from column 2. Three lines cover the zeros, so one augmentation with the least uncovered entry, 1, is needed. Then four lines are needed and an allocation can be made.
Results
The best plan is A on route 1, B on route 3, C on route 4 and D on route 2, costing £37. The lower bound from the reductions was £36, so the augmentation added just £1.
Evaluating the model
The model ignores driver preferences and fairness: D gets an expensive route because it suits the plan overall. A manager might accept a slightly higher cost for a fairer plan.
If driver A cannot take route 1 tomorrow, the model adapts easily with a prohibited pairing. The new best plan costs £45, showing exactly what that restriction would cost.
Your turn
Only drivers A, B and C are available tomorrow. Which route is left uncovered in the cheapest plan, and what does the plan cost?
Show a model answer
Add a dummy driver with zero costs. The Hungarian algorithm gives A1, B3, C4 and the dummy on route 2, so route 2 is left uncovered and the cost is pounds.
Practice
Practice ladder
Rung 1: Recall and fluency
Q1. State how many possible allocations there are for six workers and six tasks.
Worked solution to Q1
The first worker has 6 choices, the next 5, and so on down to 1. So there are possible allocations.
Q2. Write down row B of the workers' matrix after row reduction.
Worked solution to Q2
Row B is 13, 19, 6, 20, and its least entry is 6, for task 3. Subtracting 6 from each entry gives 7, 13, 0, 14, so B's zero marks its cheapest task.
Q3. Give the total amount subtracted by row and column reduction for the workers' matrix.
Worked solution to Q3
The row reductions subtract and the column reduction subtracts 5. The total is 36, a lower bound for the optimal cost.
Rung 2: Application
Q4. Determine the least number of lines needed to cover the zeros of the workers' reduced matrix.
Worked solution to Q4
Lines through rows A and B and column 4 cover every zero, and two lines cannot. So 3 lines are needed, which is fewer than the 4 workers.
Q5. After the augmentation, write down row C of the new matrix.
Worked solution to Q5
Row C was 10, 2, 4, 0, and its first three entries were uncovered. Subtracting the least uncovered entry, 1, gives 9, 1, 3, 0.
Q6. Calculate the cost of the optimal allocation for the workers.
Worked solution to Q6
The optimal allocation is A1, B3, C4 and D2. Adding the original costs gives pounds.
Rung 3: Analysis
Q7. Worker D is unavailable, leaving three workers for four tasks. Find the least cost.
Worked solution to Q7
Adding a dummy row of zeros, the Hungarian algorithm gives A1, B3, C4 and the dummy on task 2. The cost is , with task 2 not done.
Q8. Suppose the entries are profits. Find the maximum total profit for the workers.
Worked solution to Q8
Converting by subtracting from 20 and minimising gives the allocation A4, B2, C1 and D3. The profit is .
Q9. If A cannot do task 1, deduce the least cost of an allocation.
Worked solution to Q9
Giving A1 a very large cost, the algorithm finds A2, B3, C4 and D1. The cost is , which is 8 more than before.
Rung 4: Stretch
Q10. A student sums the reduced matrix entries at the optimal allocation and reports a cost of 0. Explain the error.
Worked solution to Q10
The reduced entries have had 37 subtracted from this allocation's total, so they add to 0. The real cost comes from the original matrix: .
Q11. A student adds the least uncovered entry to the uncovered entries. Explain what happens to the number of lines needed.
Worked solution to Q11
No new zero is created, because the uncovered entries only get larger. The same 3 lines still cover every zero, so the algorithm makes no progress.
Q12. A student applies the Hungarian algorithm directly to the profits. Find the profit of their allocation and explain the error.
Worked solution to Q12
The algorithm minimises, so it finds the allocation A1, B3, C4, D2 with profit 37, the least possible. Converting to opportunity costs first gives the maximum, 66.
Exam practice
Exam technique and worked answer workshop
How these questions are marked
M1 marks go to reducing rows and columns, covering zeros, and carrying out the augmentation correctly. A1 marks go to correct reduced matrices, the allocation and its cost. B1 marks go to explanations, such as why the covering test shows optimality, and to conversions for maximisation.
Show every matrix, state the number of lines each time, and give the least uncovered entry. Read the final cost from the original matrix and state the allocation clearly.
Exam question 1 (6 marks · Paper 4 · about 8 minutes)
Reduce the workers' cost matrix by rows and then by columns. Cover the zeros with the least number of lines and explain what this shows. (6)
Mark scheme for exam question 1
Row minima 6, 6, 10, 9 M1
Correct row-reduced matrix A1
Column 2 reduced by 5 M1
Correct reduced matrix A1
3 lines A1
Fewer than 4, so not yet optimal B1
Exam question 2 (7 marks · Paper 4 · about 10 minutes)
Complete the Hungarian algorithm for the workers, showing the augmentation step, and state the optimal allocation and its cost. (7)
Mark scheme for exam question 2
Least uncovered entry 1 B1
Subtracts from uncovered entries M1
Adds at crossings M1
Correct new matrix A1
4 lines needed B1
A1, B3, C4, D2 A1
Cost 37 A1
Exam question 3 (5 marks · Paper 4 · about 7 minutes)
Explain why the optimal cost is at least 36, and why the allocation of cost 37 is optimal. (5)
Mark scheme for exam question 3
Reduction total 36 B1
Every allocation reduced by 36 M1
Reduced entries non-negative, so cost at least 36 A1
Final matrix has an allocation on zeros M1
So 37 is optimal A1
Exam question 4 (6 marks · Paper 4 · about 8 minutes)
Only workers A, B and C are available for the four tasks. Explain how to adapt the matrix, and find the allocation and cost that the Hungarian algorithm gives. (6)
Mark scheme for exam question 4
Matrix is not square B1
Add a dummy row of zeros M1
Hungarian algorithm applied M1
A1, B3, C4 A1
Dummy on task 2 A1
Cost 22 A1
Exam question 5 (7 marks · Paper 4 · about 10 minutes)
The workers' matrix gives profits rather than costs. Explain how to adapt the Hungarian algorithm, and find the allocation that maximises the total profit. (7)
Mark scheme for exam question 5
Subtract every entry from 20 M1
Correct converted matrix A1
Reduces rows and columns M1
Covers zeros correctly M1
Allocation A4, B2, C1, D3 A1
Profit 66 A1
Read from the original profits B1
Exam question 6 (6 marks · Paper 4 · about 8 minutes)
Worker A cannot do task 1. Explain how this is handled, and find the new optimal allocation and its cost. (6)
Mark scheme for exam question 6
Large cost M for A1 B1
Reduces with M present M1
Augments as needed M1
A2, B3, C4, D1 A1
Cost 45 A1
An increase of 8 B1
Exam question 7 (6 marks · Paper 4 · about 8 minutes)
Formulate the workers' allocation problem as a linear programme, defining your variables and stating the objective and constraints. (6)
Mark scheme for exam question 7
is 1 if worker does task , else 0 B1
Minimise total cost M1
Objective with 16 terms A1
Each row sums to 1 M1
Each column sums to 1 A1
B1
Exam question 8 (5 marks · Paper 4 · about 7 minutes)
A student, augmenting the reduced matrix, adds the least uncovered entry to every uncovered entry. Explain the effect and the correct step. (5)
Mark scheme for exam question 8
Uncovered entries increase M1
No new zero created A1
Still 3 lines A1
Should subtract from uncovered entries B1
And add where lines cross B1
Annotated model answer: exam question 2
The least uncovered entry is 1, in row D, column 2. B1. Subtract 1 from every uncovered entry, in rows C and D, columns 1 to 3. M1. Add 1 where two lines cross, at A4 and B4. M1. The new matrix is 0, 0, 1, 9; 7, 8, 0, 15; 9, 1, 3, 0; 8, 0, 3, 0. A1.
Now four lines are needed to cover the zeros, so an allocation can be made. B1. B has one zero, in column 3, then C4, D2 and A1 follow. A1. The cost is . A1.
Annotated model answer: exam question 5
The Hungarian algorithm minimises, so subtract every entry from the largest, 20. M1. Row A becomes 14, 9, 13, 6, and so on. A1. Reducing rows and columns, M1, then covering the zeros, M1, leads to the allocation A4, B2, C1 and D3. A1.
The total profit is read from the original matrix: . A1. The converted entries are opportunity costs, not profits. B1.
Connections
Synoptic link
Transportation problems introduced balancing with dummies and improvement towards an optimum; allocation problems are the special case where every supply and demand is 1. Linear programming supplied the formulation with constraints and an objective.
Graphs, networks and planarity introduced bipartite graphs, and an allocation is a perfect matching in a complete bipartite graph. The covering test relies on König's theorem linking matchings and covers.
Synoptic question 1. Explain why an allocation problem is a special case of a transportation problem.
Answer to synoptic question 1
Each worker is a source with supply 1 and each task is a destination with demand 1. Sending one unit from worker to task means worker does task , at the cost in the matrix.
Recap
Recap and next step
- An allocation pairs workers with tasks one-to-one; there are possibilities.
- Add a dummy row or column of zeros if the matrix is not square.
- Reduce rows, then columns; the total subtracted is a lower bound for the cost.
- Cover the zeros with the least number of lines; lines means an allocation on zeros is possible.
- Otherwise subtract the least uncovered entry from uncovered entries and add it at crossings, then repeat.
- For profits, subtract every entry from the largest first; read costs or profits from the original matrix.
Next chapter: Flows in networks, which finds the greatest flow that can pass through a network of pipes or roads.
For your exam board
This chapter covers Pearson Edexcel A Level Further Mathematics (9FM0) Decision Mathematics 2 section 2: allocation problems, the Hungarian algorithm with row and column reduction and augmentation, dummy rows and columns, maximisation, prohibited allocations, and formulating allocation problems as linear programmes. It is assessed on Paper 4D, Decision Mathematics 2. Similar content appears in AQA (7367) and OCR (H245) discrete options.