Submittal of an algorithm for consideration for publication in
                                       L.D. Fosdick
                                                                                  Communications of the A C M implies unrestricted use o f the
Algorithms                             Editor                                     algorithm within a computer is permissible.

Algorithm 415                                                                     begin
                                                                                        switch switch := N E X T , L1, N E X T 1, M A R K ;
                                                                                        real min ;
                                                                                        integer array c[l:n], cb[l:m], lambda[l:m], mu[l:n], r[l:n],
Algorithm for the Assignment                                                                 y[l:m];
                                                                                        integer cbl, cl, clO, i, j, k, 1, rl, rs, sw, imin, imax, flag;
Problem (Rectangular                                                                    total := 0; imin := m i i m a x := n i
                                                                                        if n > m then go to JA;
Matrices) [H]                                                                           imin : = n; i m a x := m;
                                                                                        for i : = 1 step 1 until n do
F. Bourgeois,       a n d J . C . L a s s a l l e [ R e c d . 21 S e p t . 1970         begin
and 20 May        1971] C E R N ,     Geneva,       Switzerland                              min := a[i, 1];
                                                                                             f o r j : = 2 step 1 until m do i f a [ i , j ] < rain then rain := a[i,j];
                                                                                             f o r j : = 1 step 1 until m do a[i,j] := a[i,j] -- mitt;
                                                                                             total := total d- mini
                                                                                        end;
                                                                                        i f m > n t h e n g o t o JB;
                                                                                  JA:
                                                                                        for j : = 1 step 1 until m do
                                                                                        begin
    Key Words and Phrases: operations research, optimization                            rain : = a[1,j];
theory, assignment problem, rectangular matrices                                             for i : = 2 step 1 until n do i f a [ i , j ] < min then rain := a[i,j];
    CR Categories: 5.39, 5.40                                                                for i : = 1 step 1 until n do a[i, j] : = a[i, j] -- min i
                                                                                             total := total ~ min i
                                                                                        end;
Description                                                                       JB:
    This ~lgorithm is a companion to [3] where the theoretical                          for i : = 1 step 1 until n do x[i] : = 0;
background is described.                                                                f o r j : = 1 step 1 u n t i l m do y[j] := 0;
                                                                                        for i : = 1 step 1 until n do
References                                                                              begin
1. Silver, R. A n Algorithm for the assignment problem. C o m m .                            f o r j : = 1 step 1 until m do
A C M 3 (Nov. 1960), 605-606.                                                                begin
2. Munkres, J. Algorithms for the assignment and transportation                                   ifa[i,j] ~0 Vx[i] ~0Vy[j]                  ~0thengotoJ1;
problems. J. S I A M 5 (Mar. 1957), 32-38.                                                        x[i] := j; y[jl := i;
3. Bourgeois, F. and Lassalle, J. C. A n extension o f the Munkres                J1 :
algorithm for the assignment problem to rectangular matrices.                                end i
C o m m . A C M 15 (Dec. 1971), 802-804.                                                end;
                                                                                        comment Start labeling;
Algorithm                                                                         START:
procedure assignment (a, n, m, x, total) ;                                             f l a g := n; rl := cl := O; rs := 1;
  value a, n, m; integer n, m;                                                          for i : = 1 step 1 until n do
  real total; array a; integer array x i                                                begin
comment: a [i, j] is an n X m matrix, x [1 ], x[2], . . . , x[n] are assigned                mu[i] : = 0;
  integer values which minimize total := s u m ( i := l(1)n) of the                          if x[i] ~ 0 then go to 11;
  elements a[i, x[i]]. If m > n the x[i] are distinct and are a subset                       rl := rl d- lir[rl] := i;mu[i] := --1;
  o f the integers 1, 2 . . . . , m. If m = n the x[i] are a permutation                    f l a g : = f l a g -- 1;
  of the integers 1, 2 . . . . . n. If m < n the set o f x[i] consists o f        I1:
  some permutation o f the integers 1, 2, . . . , m interspersed with                   end;
  n - m zeros. The permutation and the positions of the zeros are                      if f l a g = i m & then go to F I N I ;
  chosen in such a way as to minimize the above sum with the                            f o r j : = 1 step 1 until m do lambda[j] : = 0;
  convention that a[i, o] is to be taken equal to zero. imin =                         comment Label and scan;
  min(n, m) and i m a x = m a x ( n , m) must be such that: imin > O,             LABEL:
  i m a x > 1.                                                                          i := r[rs]; rs := rs + 1;
  This procedure is based on that o f Silver [1] which uses the                        f o r j : = 1 step 1 until m do
  assignment algorithm of Munkres [2]. Silver's procedure has                          begin
  been extended to handle the case n ~ m;                                                   if a[i,j] ~ 0 V lambda[j] ~ 0 then go to J2;
                                                                                            iambda [j] : = i; cl := cl -t- 1; c[cl] := j;
                                                                                            if y[j] = 0 then go to M A R K ;
     Copyright O 1971, Association for Computing Machinery, Inc.                            rl := rl -b 1; r[rl] : = y[y]; mu[y[j]] := i;
     General permission to republish, but not for profit, an algorithm            J2:
is granted, provided that reference is made to this publication, to                    end;
its date of issue, and to the fact that reprinting privileges were                     if rs =< d then go to L A B E L i
granted by permission o f the Association for Computing Machinery.                     comment Renormalize;
                                                                                        sw : = 1;cl0 : = cl; cbl : = 0;
                                                                                       f o r j : = 1 step 1 until m do
                                                                                       begin
                                                                                            iflambda[j] ~ 0 then go to J3;
                                                                                            cbl := cbl -b 1; cb[cbl] := j;



805                                                                               Communications                            December 1971
                                                                                  of                                        Volume 14
                                                                                  the A C M                                 N u m b e r 12
J3:                                                                                       if y[cb[l]] = 0 then
        end;                                                                               begin
       min := a[r[1], cb[1]];                                                                 j : = cb[l]; sw : = 2; g o t o L 1 ;
       for k : = 1 step 1 until rl do                                                      end;
       begin                                                                               cl:=el+l;         c[cl]:=cb[l]; r l : = r l + l ;
           for I : = 1 step I until cbl do                                                 r[rl] : = y[cb[l]];
          if air[k], cb[l]] < rain then rain := a[r[k], cb[l]];                 LI:
       end;                                                                             end;
       total := total + rain X (rl+cbl--imax);                                  13:
       for i : = 1 step 1 until n do                                                end;
       begin                                                                        go to switch[sw + 2];
          ifmu[i] ~ 0 then go to 12;                                            NEXT 1:
          ifcl0 < 1 then go to 13;                                                  if clO = cl then go to L A B E L ;
          for l : = 1 step 1 until clO do a[i, c[I]] : = a[i, c[l]] -t- min;        for i : = c/0 + 1 step 1 until c / d o mu[y[c[i]]] : = c[i];
          go to 13;                                                                 go to L A B E L ;
/2:                                                                                 comment Mark new column and permute;
         for I : = 1 step 1 until cbl do                                        MARK:
         begin                                                                      y[j] : = i : = lambda[j];
           a[i, cb[l]] := a[i, cb[l]] - rain;                                       if x[i] = 0 then begin x[i] : = j; go to S T A R T ;
            go to switch[sw];                                                     end;
NEXT:                                                                             k:=j;      j:=x[i];   x [ i ] : = k; go to M A R K ;
             if a[i, cb[l]] ~ 0 V lambda[cb[l]] ~- 0 then go to L1 ;            FINI:
             lambda[cb[l]] := i;                                                end




Algorithm 416                                                                      a number o f arguments equal to ord[i]. In this case dx[i] should
                                                                                   contain the difference between the argument o f highest index o f
                                                                                  f[i] and that o f f [ i - 1].
                                                                                      U p o n execution o f I N T P the coefficients of the desired poly-
Rapid Computation of                                                               nomial are stored in c in such a manner that the coefficient in
                                                                                   front of the power t ~-1 is contained in c[i]. Other parameters are
Coefficients of                                                                    not changed. Caution: The given data must be such that it is
                                                                                   possible to construct N e w t o n ' s interpolation formula with
Interpolation Formulas tEl]                                                        divided differences from them. We must also have ord[1] = 1.
                                                                                   Observe that if derivatives o f f are given the corresponding
 Sven-~kke Gustafson*            [ R e c d . 21 A u g . 1969]                      divided differences with confluent arguments must be evaluated
Computer         Science Department,            Stanford     University,           and given as input data.
                                                                                     Examples o f use o f INTP:
Stanford,       CA 94305                                                           Example 1. Determine the polynomial o f degree less than n which
                                                                                   interpolates a function f at n distinct points x~, i = 1, 2, . . . , n.
                                                                                  Input d a t a : d x [ i ] = x l , f [ i ] = J~, ord[i] = 1, i = 1, 2 . . . . , n.
                                                                                   Example 2. Let x~, x2, x3, x4 be four given points. We know
     Key Words and Phrases: divided differences, Newton's                         .A, ~ . ~, f2.a, and.A • Determine the polynomial of degree 3 which
interpolation formula                                                              reproduces these quantities. Input data: n = 4,
     CR Category: 5.13                                                         dx[1]   =xx            ord[1]   =   I   f[l]   =A
                                                                               dx[2]   =x2--xl        ord[2]   =   2   f[2]   =./~.2
                                                                               dx[3]   =x~--x2        ord[3]   =   2   f[3]   =J~.3
Description                                                                    dx[4]   = x,           ord[4]   =   1   f[4]   = A
    This algorithm is a companion to [1] where the theoretical                    Example 3. The same problem when we are given f ( - 1 ) , f ' ( - - 1 ) ,
background is described
                                                                                 f " ( - - I ) , and f(1). Input data: n = 4,

References                                                                     dx[1]   = -1     ord[1] = 1 f[1] = f ( - 1 )
                                                                               dx[2]   =    0   ord[2] = 2 f[21 = f ' ( - - 1)
1. Gustafson, Sven-/~ke. Rapid computation of interpolation                    dx[3]   =    0   ord[3] = 3 f[31 = 0 . 5 . / " ( - - 1 )
formulae and mechanical quadrature rules. Comm. A C M 14                       dx[4]   =    1   ord[4] = 1 f[4] = f(1)
(Dec. 1971), 797-801.
                                                                               For further details see [I ];
                                                                               integer i,j, k; real ai, h, d, xx;
Algorithm                                                                         real array arg [1 : n];
procedure I N T P (dx, f, c, ord, n) ;                                            comment Initiate phase DI;
  value n; real array dx, f, c;                                                   for i : = 1 step 1 until n do
  integer array ord; integer n;                                                      arg[i] : = if ord[i] = 1 then dx[i] else dx[i] q- arg[i-- 1];
begin                                                                             comment Phase DI;
comment 1NTP determines the coefficients of the polynomial of de-                 for i : = 2 step 1 until n do
  gree less than n which reproduces given function values and                    begin
  divided differences. The parameters of I N T P are:                               j : = ord[i];
                                                                                     i f j = 1 then go to divde;
idenlifier    type             comment                                               d : = f[i];
n             integer                                                                for k : = i step -- 1 until i -- j + 2 dof[k] : = f [ k - - 1];
ord           integer array    Array bounds [1 :n]                                  f [ i - - j + l ] : = d;
dx, f, c      real array       Array bounds [1 :n]                                   h : = dx[i]; ai : = arg[i];
  n is the number o f coefficients o f the interpolating polynomial.
  ord gives the character o f the input data: if ord[i] = 1 then x[i]
  should be an argument and f[i] the corresponding function value.             * Present Address: Inst. F. lnformations Behandling (Numeisk an-
  But if ord[i] > 1 thenf[i] should contain a divided difference with          alys), K T H , 10044 Stockholm, Sweden.

806                                                                            Communications                           December 1971
                                                                               of                                       Volume 14
                                                                               the A C M                                N u m b e r 12

P805 bourgeois

  • 1.
    Submittal of analgorithm for consideration for publication in L.D. Fosdick Communications of the A C M implies unrestricted use o f the Algorithms Editor algorithm within a computer is permissible. Algorithm 415 begin switch switch := N E X T , L1, N E X T 1, M A R K ; real min ; integer array c[l:n], cb[l:m], lambda[l:m], mu[l:n], r[l:n], Algorithm for the Assignment y[l:m]; integer cbl, cl, clO, i, j, k, 1, rl, rs, sw, imin, imax, flag; Problem (Rectangular total := 0; imin := m i i m a x := n i if n > m then go to JA; Matrices) [H] imin : = n; i m a x := m; for i : = 1 step 1 until n do F. Bourgeois, a n d J . C . L a s s a l l e [ R e c d . 21 S e p t . 1970 begin and 20 May 1971] C E R N , Geneva, Switzerland min := a[i, 1]; f o r j : = 2 step 1 until m do i f a [ i , j ] < rain then rain := a[i,j]; f o r j : = 1 step 1 until m do a[i,j] := a[i,j] -- mitt; total := total d- mini end; i f m > n t h e n g o t o JB; JA: for j : = 1 step 1 until m do begin Key Words and Phrases: operations research, optimization rain : = a[1,j]; theory, assignment problem, rectangular matrices for i : = 2 step 1 until n do i f a [ i , j ] < min then rain := a[i,j]; CR Categories: 5.39, 5.40 for i : = 1 step 1 until n do a[i, j] : = a[i, j] -- min i total := total ~ min i end; Description JB: This ~lgorithm is a companion to [3] where the theoretical for i : = 1 step 1 until n do x[i] : = 0; background is described. f o r j : = 1 step 1 u n t i l m do y[j] := 0; for i : = 1 step 1 until n do References begin 1. Silver, R. A n Algorithm for the assignment problem. C o m m . f o r j : = 1 step 1 until m do A C M 3 (Nov. 1960), 605-606. begin 2. Munkres, J. Algorithms for the assignment and transportation ifa[i,j] ~0 Vx[i] ~0Vy[j] ~0thengotoJ1; problems. J. S I A M 5 (Mar. 1957), 32-38. x[i] := j; y[jl := i; 3. Bourgeois, F. and Lassalle, J. C. A n extension o f the Munkres J1 : algorithm for the assignment problem to rectangular matrices. end i C o m m . A C M 15 (Dec. 1971), 802-804. end; comment Start labeling; Algorithm START: procedure assignment (a, n, m, x, total) ; f l a g := n; rl := cl := O; rs := 1; value a, n, m; integer n, m; for i : = 1 step 1 until n do real total; array a; integer array x i begin comment: a [i, j] is an n X m matrix, x [1 ], x[2], . . . , x[n] are assigned mu[i] : = 0; integer values which minimize total := s u m ( i := l(1)n) of the if x[i] ~ 0 then go to 11; elements a[i, x[i]]. If m > n the x[i] are distinct and are a subset rl := rl d- lir[rl] := i;mu[i] := --1; o f the integers 1, 2 . . . . , m. If m = n the x[i] are a permutation f l a g : = f l a g -- 1; of the integers 1, 2 . . . . . n. If m < n the set o f x[i] consists o f I1: some permutation o f the integers 1, 2, . . . , m interspersed with end; n - m zeros. The permutation and the positions of the zeros are if f l a g = i m & then go to F I N I ; chosen in such a way as to minimize the above sum with the f o r j : = 1 step 1 until m do lambda[j] : = 0; convention that a[i, o] is to be taken equal to zero. imin = comment Label and scan; min(n, m) and i m a x = m a x ( n , m) must be such that: imin > O, LABEL: i m a x > 1. i := r[rs]; rs := rs + 1; This procedure is based on that o f Silver [1] which uses the f o r j : = 1 step 1 until m do assignment algorithm of Munkres [2]. Silver's procedure has begin been extended to handle the case n ~ m; if a[i,j] ~ 0 V lambda[j] ~ 0 then go to J2; iambda [j] : = i; cl := cl -t- 1; c[cl] := j; if y[j] = 0 then go to M A R K ; Copyright O 1971, Association for Computing Machinery, Inc. rl := rl -b 1; r[rl] : = y[y]; mu[y[j]] := i; General permission to republish, but not for profit, an algorithm J2: is granted, provided that reference is made to this publication, to end; its date of issue, and to the fact that reprinting privileges were if rs =< d then go to L A B E L i granted by permission o f the Association for Computing Machinery. comment Renormalize; sw : = 1;cl0 : = cl; cbl : = 0; f o r j : = 1 step 1 until m do begin iflambda[j] ~ 0 then go to J3; cbl := cbl -b 1; cb[cbl] := j; 805 Communications December 1971 of Volume 14 the A C M N u m b e r 12
  • 2.
    J3: if y[cb[l]] = 0 then end; begin min := a[r[1], cb[1]]; j : = cb[l]; sw : = 2; g o t o L 1 ; for k : = 1 step 1 until rl do end; begin cl:=el+l; c[cl]:=cb[l]; r l : = r l + l ; for I : = 1 step I until cbl do r[rl] : = y[cb[l]]; if air[k], cb[l]] < rain then rain := a[r[k], cb[l]]; LI: end; end; total := total + rain X (rl+cbl--imax); 13: for i : = 1 step 1 until n do end; begin go to switch[sw + 2]; ifmu[i] ~ 0 then go to 12; NEXT 1: ifcl0 < 1 then go to 13; if clO = cl then go to L A B E L ; for l : = 1 step 1 until clO do a[i, c[I]] : = a[i, c[l]] -t- min; for i : = c/0 + 1 step 1 until c / d o mu[y[c[i]]] : = c[i]; go to 13; go to L A B E L ; /2: comment Mark new column and permute; for I : = 1 step 1 until cbl do MARK: begin y[j] : = i : = lambda[j]; a[i, cb[l]] := a[i, cb[l]] - rain; if x[i] = 0 then begin x[i] : = j; go to S T A R T ; go to switch[sw]; end; NEXT: k:=j; j:=x[i]; x [ i ] : = k; go to M A R K ; if a[i, cb[l]] ~ 0 V lambda[cb[l]] ~- 0 then go to L1 ; FINI: lambda[cb[l]] := i; end Algorithm 416 a number o f arguments equal to ord[i]. In this case dx[i] should contain the difference between the argument o f highest index o f f[i] and that o f f [ i - 1]. U p o n execution o f I N T P the coefficients of the desired poly- Rapid Computation of nomial are stored in c in such a manner that the coefficient in front of the power t ~-1 is contained in c[i]. Other parameters are Coefficients of not changed. Caution: The given data must be such that it is possible to construct N e w t o n ' s interpolation formula with Interpolation Formulas tEl] divided differences from them. We must also have ord[1] = 1. Observe that if derivatives o f f are given the corresponding Sven-~kke Gustafson* [ R e c d . 21 A u g . 1969] divided differences with confluent arguments must be evaluated Computer Science Department, Stanford University, and given as input data. Examples o f use o f INTP: Stanford, CA 94305 Example 1. Determine the polynomial o f degree less than n which interpolates a function f at n distinct points x~, i = 1, 2, . . . , n. Input d a t a : d x [ i ] = x l , f [ i ] = J~, ord[i] = 1, i = 1, 2 . . . . , n. Example 2. Let x~, x2, x3, x4 be four given points. We know Key Words and Phrases: divided differences, Newton's .A, ~ . ~, f2.a, and.A • Determine the polynomial of degree 3 which interpolation formula reproduces these quantities. Input data: n = 4, CR Category: 5.13 dx[1] =xx ord[1] = I f[l] =A dx[2] =x2--xl ord[2] = 2 f[2] =./~.2 dx[3] =x~--x2 ord[3] = 2 f[3] =J~.3 Description dx[4] = x, ord[4] = 1 f[4] = A This algorithm is a companion to [1] where the theoretical Example 3. The same problem when we are given f ( - 1 ) , f ' ( - - 1 ) , background is described f " ( - - I ) , and f(1). Input data: n = 4, References dx[1] = -1 ord[1] = 1 f[1] = f ( - 1 ) dx[2] = 0 ord[2] = 2 f[21 = f ' ( - - 1) 1. Gustafson, Sven-/~ke. Rapid computation of interpolation dx[3] = 0 ord[3] = 3 f[31 = 0 . 5 . / " ( - - 1 ) formulae and mechanical quadrature rules. Comm. A C M 14 dx[4] = 1 ord[4] = 1 f[4] = f(1) (Dec. 1971), 797-801. For further details see [I ]; integer i,j, k; real ai, h, d, xx; Algorithm real array arg [1 : n]; procedure I N T P (dx, f, c, ord, n) ; comment Initiate phase DI; value n; real array dx, f, c; for i : = 1 step 1 until n do integer array ord; integer n; arg[i] : = if ord[i] = 1 then dx[i] else dx[i] q- arg[i-- 1]; begin comment Phase DI; comment 1NTP determines the coefficients of the polynomial of de- for i : = 2 step 1 until n do gree less than n which reproduces given function values and begin divided differences. The parameters of I N T P are: j : = ord[i]; i f j = 1 then go to divde; idenlifier type comment d : = f[i]; n integer for k : = i step -- 1 until i -- j + 2 dof[k] : = f [ k - - 1]; ord integer array Array bounds [1 :n] f [ i - - j + l ] : = d; dx, f, c real array Array bounds [1 :n] h : = dx[i]; ai : = arg[i]; n is the number o f coefficients o f the interpolating polynomial. ord gives the character o f the input data: if ord[i] = 1 then x[i] should be an argument and f[i] the corresponding function value. * Present Address: Inst. F. lnformations Behandling (Numeisk an- But if ord[i] > 1 thenf[i] should contain a divided difference with alys), K T H , 10044 Stockholm, Sweden. 806 Communications December 1971 of Volume 14 the A C M N u m b e r 12