Speeding Up The Hungarian Algorithm: Computers & Operations Research December 1990
Speeding Up The Hungarian Algorithm: Computers & Operations Research December 1990
net/publication/220469495
CITATIONS READS
28 1,094
1 author:
Mike Wright
Lancaster University
51 PUBLICATIONS 920 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Mike Wright on 03 May 2018.
M. B. WRIGHT*
Department of Operational Research and Operations Management, University of Lancaster. Lancaster LA1 4YX.
England
Scope and Purpose-This paper shows how a minor modilication to the Hungarian algorithm for the
linear assignment problem can drastically reduce execution times. This may be useful not only to academic
studies which compare the performances of different algorithms. but also for the many implementations
which use the Hungarian algorithm.
Abstract-A simple modification to the “Hungarian” algorithm for the linear assignment problem reduces
execution time by up to 90”/0.
INTRODUCTION
The linear assignment problem is a standard OR problem. Given an N by N cost matrix. N entries
must be chosen, exactly one from each row and one from each column, in such a way as to minimize
the total cost of the selection.
The algorithm most widely used for the solution of this problem is generally known as the
Hungarian algorithm [I], although other algorithms have since been devised which are claimed
to be faster [2, 3-J.
However. execution time is detcrmincd not only by the algorithm itself but also by the computer
code used. For example, Jonker and Volgenant [4] showed that minor modifications to the original
codes used for the Hungarian algorithm can cause large reductions in execution time. This paper
assesses the effect of another minor modification.
In practical terms, it may be argued that all the algorithms and computer codes used are quick
anyway, so that there is no need for further improvement. However, there are occasions where a
result is required very quickly, as in an interactive system, or where a long series of successive
assignments needs to be made [S], when it is important to use as quick a method as possible.
THE MODIFICATION
Let c[i, j] be the initial cost matrix. The standard codes for the Hungarian algorithm proceed
by making successive alterations to this matrix, by means of subtractions from or additions to
whole rows and columns. So, if u[i] is the total amount subtracted from row i, and c[j] is the
total amount subtracted from column j, the altered matrix is given by:
For most linear assignment problems, the arrays u and c are changed frequently during the
course of the algorithm, and so a[i, j] must also be frequently altered. These alterations are generally
by far the most time-consuming part of the algorithm.
The modification tested in this paper does not use an altered matrix at all. So all computer
statements that would have used a[i, j] now use (c[i. j] - u[i] - cfj]). The time spent altering
the matrix is therefore saved, but the other parts of the process take slightly longer.
EXPERIMENTAL TESTS
Two codes for the Hungarian algorithm were compared, the lirst (“OLD”) without the above
modification, and the second (“NEW”) with it. Both codes were otherwise fairly eflicient,
‘M. B. Wright is a Lecturer in operational research at the University of Lancaster, England. Before that he was with
the operational research group at the Headquarters of British Rail. His main research interests are the practical uses
of heuristics and the application of OR to transport. health services and sport.
cm 17:1-G
95
96 M. 8. WRIGHT
incorporating pointers and the first two of the improvements described by Jonker and Volkenant [4].
Six values of n, the number of rows in the cost matrix, and three values of r, the range of values
in the matrix, were used, giving I8 combinations. For each combination 20 runs of OLD and
NEW were made.
For each of the 360 runs, a cost matrix was created by choosing a random integer between 0
and r for each matrix element c[i, j]. OLD and NEW were then run successively on this matrix
and the execution times were recorded. The computer used was an Amstrad PC1512, and the
language used was Pascal, using Borland’s TURBO system, version 4. The results are summarized
in Table I.
COMMENTS
These results show that NEW is substantially quicker than OLD, especially for large values of
n and r, where the improvement is as high as 90%. Regression analysis shows that the execution
time for NEW is O(n2~22ro~“), compared with O(n2.48r0.38) for OLD. In addition, when each value
of r is considered separately, the power of n for NEW is almost constant (between 2.20 and 2.23),
whereas for OLD it ranges from 1.95 (for r = 100, when virtually no matrix alteration is ever
necessary) to 2.88 (for r = 10,000).
So NEW is not only quicker than OLD, it is also less sensitive to variation in the size of the
matrix and the range of costs within it.
REFERENCES
I. H. W. Kuhn, The Hungarian method for the assignment problem. Naval Rcs. Loyisr. Q. 2, 83-97 (1955).
2. M. S. Hung and W. 0. Rom, Solving the assignment problem by relaxation. Opns Res. 28, 969-982 (1980).
3. R. Jonker and A. Volgenant. A shortest augmenting path algorithm (or dense and sparse-linear assignment problems.
Compuring 38.325340 (1987).
4. R. Jonker and A. Volgenant. Improving the Hungarian assignment algorithm. Opl Res. Lett. 5. 171-175 (1986).
5. M. B. Wright. Applying stochasticalgorithms to a locomotivescheduling problem. J. Opl Res. Soc.40.187-192 (1989).