speeding up the hungarian algorithm - Science Direct

12 downloads 0 Views 159KB Size Report
Scope and Purpose-This paper shows how a minor modilication to the Hungarian algorithm for the linear assignment problem can drastically reduce execution ...
Computers Opns Rrs. Vol. 17. No. I. pp. 95-96. 1990 Prmted 10 Great Brttam All rights reserved

SPEEDING

UP THE HUNGARIAN M. B.

Department

of Operational

0305-0548 90 s3 00 + 0 00 t. 1990 Pcrgamon Press plc

Cop>rtpht

Research and Operations

(Received

ALGORITHM

WRIGHT*

Management, England

University

April 1988; rerised January

of Lancaster.

Lancaster

LA1 4YX.

19891

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 execution time by up to 90”/0.

to the “Hungarian”

algorithm

for the linear assignment problem reduces

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 Hungarian

most

algorithm

widely [I],

used for the solution

although

other

of this problem

algorithms

is generally

have since been devised

known

which

as the

are claimed

to be faster [2, 3-J. However.

execution

time is detcrmincd

code used. For example,

Jonker

codes used for the Hungarian assesses the effect of another In practical anyway, result

not only by the algorithm

and Volgenant algorithm

minor

can cause large reductions that all the algorithms

so that there is no need for further

assignments

very quickly,

as in an interactive

THE

Let c[i, j] whole total

improvement.

be the initial successive

cost matrix.

alterations

amount

subtracted

from

to the original time. This paper

The standard

to this matrix,

column

and computer

codes used are quick

there are occasions

or where

a long

to use as quick

where a

series of successive

a method

as possible.

MODIFICATION

codes for the Hungarian

by means

So, if u[i] is the total

rows and columns.

modifications in execution

However,

system,

needs to be made [S], when it is important

by making

itself but also by the computer

that minor

modification.

terms, it may be argued

is required

[4] showed

amount

j, the altered

of subtractions

subtracted

matrix

is given

algorithm from

from

row

proceed

or additions i, and

c[j]

to

is the

by:

a[i, j] = c[i, j] - u[i] - r[j]. For

most

linear

assignment

by far the most time-consuming The modification statements

that

the matrix

is therefore

problems,

the arrays

tested

would

does not

have used a[i, j] now saved, but the other

Two codes for the Hungarian modification, and the second

cm

altered.

frequently

These alterations

during

the

are generally

part of the algorithm.

in this paper

matrix

at all. So all computer

use (c[i. j] - u[i] - cfj]).

The time spent altering

algorithm (“NEW”)

use an altered

parts of the process take slightly

EXPERIMENTAL

‘M.

u and c are changed

and so a[i, j] must also be frequently

course of the algorithm,

longer.

TESTS

were compared, the lirst (“OLD”) without the above with it. Both codes were otherwise fairly eflicient,

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. 17:1-G

95

96

M. 8. WRIGHT Tdblr I

Computer r~r~utmn times txcl

for “OLD”

OLD r

n

Mean

and “NEW”

NEW SD

Mean

NEW OLD SD

Mean

SD

50

1.88

0.31

0.82

0.16

043

0.04

100

100

8.52

0.87

3.53

0.53

0.41

0.04

100

150

18.49

2.61

7.88

1.05

0.43

0.04

100

200

30.78

3.96

14.77

I.85

0.48

0.05

100

250

46.02

4.51

27.96

4.78

0.61

0.08

IOIl

300

63.37

7.51

47.42

4.75

0.76

0.09

50

3.18

0.85

I.00

0.23

0.32

0.03

1.000

100

21.03

3.41

4.66

0.84

0.22

0.02

l.ooo

I50

59.09

8.47

2.0X

0.19

0.02

l.OOG l.CQO

ml

I27 32

15.4.i

II.15 ,? 1') __.__

3.01

0.18

0.02

250

215.02

21.24

34.58

4.93

0.16

0.01

1.000

300

32963

25.43

51.68

6.65

0.16

0.02

loo

Ian0

10.000

50

4.25

0.83

1.23

0.23

0.29

0.02

5.03

5.78

0.85

O.IR

0.01

I596

14.36

2.17

0.14

001

235 27

28.73

26.99

3.88

0.11

0.01

250

432.56

46.42

44.43

5.93

0.10

0.01

300

742.03

50.x1

67.44

5.51

0.09

0.01

lO.OOfI

loo

3190

lO.OOG

150

IO5 76

IO.OMl

200

10.000 IO.MXI

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).