8
North-Holland Microprocessingand Microprogramming 27 (1989) 657-664 657 Algorithms and Complexity of the Periodic Maintenance Problem * A1 Mok, Louis Rosier, Igor Tulchinsky, and Donald Varvel Department of Computer Sciences, The University of Texas at Austin, Austin, Texas 78712-1188 1 Introduction The k-server periodic maintenance problem (PMPk, k > 1) was introduced by Wei and Liu in [11]. (Let PMP denote simply the periodic maintenance problem.) PMPk is moti- vated by the requirement that machines receive maintenance at fixed intervals from one of k servers each of which can service only one machine at a time. Suppose there are n machines that must be serviced periodically. Machine 1 re- quires service every ml time units, machine 2 every m2 time units, ..., and machine n every m n time units. A "time unit" (or "slot") here is the time needed for one server to service one machine. Note that k machines can be serviced each slot. In a schedule, such a slot will be represented by a k-multiset. An instance of PMPk, therefore, is represented by a mul- tiset of positive integers A = {ml, m2,...,mn}. A k-server schedule S for A is an infinite sequence of k-multisets over {1,2,...,n,blank}, where blank can be repeated within a multiset but 1,..., n cannot, such that successive occur- rences of i are exactly m i slots apart. For simplicity, we omit the set brackets when denoting single-server schedules. As an example, consider the single-server case of five ma- chines, two of which require service every four slots and three of which require service every six slots. We represent this by the input multiset {4, 4, 6, 6, 6}. We assign the indices 1 and 2 to the first two items and the indices 3, 4, and 5 to the last 3. A schedule is "1, 3, 2, 4, 1, 5, 2, 3, l, 4, 2, 5" repeated indef- initely. Notice that "l" and "2" occur every fourth slot and "3", "4", and "5" occur every sixth slot. {2, 3}, on the other hand, requires at least two servers. "{1,2}, {blank, blank}, {1, blank}, {blank, 2}, {1, blank}, {bZank, bZank}" repeated indefinitely is a 2-server schedule for {2, 3}. Wei and Liu in [ll] give a reasonably complicated but polynomial-time testable condition that guarantees the ex- istence of a k-server schedule. Unfortunately, although suf- ficient, this condition is not necessary. The natural question to ask, then, is whether there is a polynomial-time testable condition that is both necessary and sufficient. In this pa- per we consider this question and others. More specifically, we take up two problems concerning the k-server periodic maintenance problem: *This work was supported in part by U.S. Office of Naval Research Grant Nos. N00014-85-K-0117 and N00014-86-K-0763, and National Science Foundation Grant No. CCR-8711579. The decision problem: Given an instance A of PMPk, is there a k-server schedule for A? We consider the problem for general instances and for certain restricted instance classes. The scheduling problem: If the decision problem for a class is in PTIME, can a "useful" representation of the schedule be obtained in deterministic polynomial time? ("Useful" will be made precise shortly.) This is a twofold issue. The decision mechanisms proposed in [11] and the ones we give are constructive. However, the resulting schedule representation might not meet our criterion for "useful". The representation used in [11], for example, consists of starting locations for the items. The obvious scheduling algorithm then main- tains a counter for each item, incrementing and test- ing each counter at each slot. Clearly, scheduling one slot in such a manner will require time proportional to the size of the instance. While this is probably ad- equate for machine maintenance where the duration represented by a slot is on the order of a day, it may lead to difficulty where these techniques are applied to things like processor scheduling. On the other hand, a deterministic finite state generator for the schedule would overcome this objection but might not be pro- ducible in deterministic polynomial time. Such gen- erators typically have a number of states proportional to the magnitudes of the numbers involved or worse, and thus even to write out the code for the finite state generator would often require exponential time. What, then, constitutes a "useful" representation of a schedule? We will represent a schedule by a program that generates the scheduling sequence in constant time per slot scheduled. (Note that the time needed to schedule a slot may be proportional to the number of servers, but for our purposes this is fixed at k.) We call such a program a "fast online scheduler" or "FOLS," a concept introduced in [4] (see also [5]). The FOLS constitutes our working definition of a useful representation of a schedule. Furthermore, we require that the FOLS be producible in deterministic polynomial time. Instance classes for which the FOLSs can be generated in deterministic polynomial time are in the complexity class S-P-C (for "Scheduling-Polynomial-Constant") [4].

Algorithms and complexity of the periodic maintenance problem

  • Upload
    al-mok

  • View
    214

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Algorithms and complexity of the periodic maintenance problem

North-Holland Microprocessing and Microprogramming 27 (1989) 657-664 657

Algorithms and Complexity of the Periodic Maintenance Problem *

A1 Mok, Louis Ros ie r , Igor Tu lch insky , a n d D o n a l d Varvel

D e p a r t m e n t of C o m p u t e r Sciences , T h e U n i v e r s i t y of Texas a t A u s t i n , A u s t i n , Texas 78712-1188

1 I n t r o d u c t i o n

The k-server periodic ma in tenance problem (PMPk, k > 1) was in t roduced by Wei and Liu in [11]. (Let P M P denote s imply the periodic main tenance problem.) PMPk is moti- vated by the requi rement tha t machines receive ma in tenance at fixed intervals f rom one of k servers each of which can service only one machine at a t ime. Suppose there are n machines tha t mus t be serviced periodically. Machine 1 re- quires service every ml t ime units , machine 2 every m2 t ime uni ts , . . . , and machine n every m n t ime units . A "t ime unit" (or "slot") here is the t ime needed for one server to service one machine. Note tha t k machines can be serviced each slot. In a schedule, such a slot will be represented by a k-mult iset .

An ins tance of PMPk, therefore, is represented by a mul- t iset of positive integers A = {ml , m 2 , . . . , m n } . A k-server schedule S for A is an infinite sequence of k-mult ise ts over { 1 , 2 , . . . , n , b l a n k } , where blank can be repeated within a mul t ise t bu t 1 , . . . , n cannot , such t ha t successive occur- rences of i are exact ly m i slots apart . For simplicity, we omit the set brackets when denot ing single-server schedules.

As an example, consider the single-server case of five ma- chines, two of which require service every four slots and three of which require service every six slots. We represent this by the input mul t ise t {4, 4, 6, 6, 6}. We assign the indices 1 and 2 to the first two i tems and the indices 3, 4, and 5 to the last 3. A schedule is "1, 3, 2, 4, 1, 5, 2, 3, l , 4, 2, 5" repeated indef- initely. Notice tha t "l" and "2" occur every four th slot and "3", "4", and "5" occur every s ixth slot. {2, 3}, on the other hand, requires at least two servers. "{1,2}, {blank, blank}, {1, blank}, {blank, 2}, {1, blank}, {bZank, bZank}" repeated indefinitely is a 2-server schedule for {2, 3}.

Wei and Liu in [ll] give a reasonably complicated but polynomial - t ime testable condition tha t guarantees the ex- istence of a k-server schedule. Unfortunately, a l though suf- ficient, th is condit ion is not necessary. The na tura l quest ion to ask, then, is whether there is a polynomial- t ime testable condition tha t is both necessary and sufficient. In this pa- per we consider this quest ion and others. More specifically, we take up two problems concerning the k-server periodic ma in tenance problem:

*This work was supported in part by U.S. Office of Naval Research Grant Nos. N00014-85-K-0117 and N00014-86-K-0763, and National Science Foundation Grant No. CCR-8711579.

The decision problem: Given an instance A of PMPk, is there a k-server schedule for A? We consider the problem for general ins tances and for certain restricted ins tance classes.

The scheduling problem: If the decision problem for

a class is in PTIME, can a "useful" representat ion of the schedule be obtained in determinist ic polynomial t ime? ("Useful" will be made precise shortly.) This is a twofold issue. The decision mechan i sms proposed in [11] and the ones we give are constructive. However, the result ing schedule representat ion might not meet our criterion for "useful". The representat ion used in [11], for example, consists of s ta r t ing locations for the i tems. The obvious scheduling algori thm then main- ta ins a counter for each item, increment ing and test- ing each counter at each slot. Clearly, scheduling one slot in such a manne r will require t ime proport ional to the size of the instance. While this is probably ad- equate for machine main tenance where the durat ion represented by a slot is on the order of a day, it may lead to difficulty where these techniques are applied to th ings like processor scheduling. On the other hand,

a determinis t ic finite s ta te generator for the schedule would overcome this objection but might not be pro- ducible in determinist ic polynomial time. Such gen- erators typically have a number of s ta tes proport ional to the magn i tudes of the numbers involved or worse, and thus even to write out the code for the finite s ta te generator would often require exponential t ime.

Wha t , then, cons t i tu tes a "useful" representat ion of a schedule? We will represent a schedule by a program that generates the scheduling sequence in constant t ime per slot scheduled. (Note tha t the t ime needed to schedule a slot may be proport ional to the number of servers, bu t for our purposes this is fixed at k.) We call such a program a "fast online scheduler" or "FOLS," a concept introduced in [4] (see also [5]). The FOLS const i tu tes our working definition of a useful representat ion of a schedule. Fur thermore, we require tha t the FOLS be producible in determinist ic polynomial t ime. Ins tance classes for which the FOLSs can be generated in determinis t ic polynomial t ime are in the complexity class S-P-C (for "Schedul ing-Polynomial -Constant" ) [4].

Page 2: Algorithms and complexity of the periodic maintenance problem

658 A. Mok et al. /Algorithms and Complexity of the Periodic Maintenance Problem

A s indicated, in this paper we address the decision prob- lem for the general case and bo th the decision problem and the scheduling problem for certain special classes. Each of the two special classes we discuss tu rns out to be in S-P-C. These classes are not the only ones t ha t can be handled in determinis t ic polynomial t ime. In fact, we know of several o thers tha t may be approached us ing modificat ions of the techniques used in [4]. We have chosen these two as sig- nificantly different examples of the sorts of restr ict ions tha t

may prove useful. The special classes we address are CM, in which each mi is a mult iple of each of m l , . . . , mi-1, and C2, in which the ins tance consists of only two dist inct inte- gers. The resul ts we obtain in the lat ter case could be useful because in practice m a n y of the machines to be main ta ined may be identical, or at least have identical service intervals. Here is an overview of our results:

• Let LpMPk = {{ r r t l , . . . , m , } l a k-server schedule exists

for { m l , . . . , m n } } . T h e n for k > 1, LpMp~ is NP- complete in the s t rong sense. 1 Recall now the quest ion

posed earlier concerning the existence of a polynomial- t ime tes table necessary and sufficient condit ion for k- server schedulability. We can now s ta te tha t unless P = N P there is no such condition. The proof is long and somewha t tedious, and involves a fair a m o u n t of number theory. Nevertheless, we feel it has a certain

elegance and is not unreasonably difficult to digest.

• Classes for which we i l lustrate positive resul ts are:

- W h e n each main tenance interval is a mult iple of all shor ter ma in tenance intervals, the decision problem is in PTIME. We call this class CM. More formally, CM = { { m l , . . . ,mn}lmi < mj mj is a mult iple of mi}. T he results for this re- s t r ic ted class of PMPk correspond directly to and expand on similar results reported for another problem, pinwheel (PP), in [4].

- W h e n an ins tance consists of only two dist inct numbers , the decision problem is in PTIME. We call this class C2. More formally, C2 = { { m l , . . . , mn}[3i, j such tha t Vk m k = i or m k = j} . The results for this restr icted class of PMPk are similar to the resul ts for the class 793 of PP, again reported in [4]. The differences are suffi- cient, however, to make possible a much simpler a lgor i thm for C2.

- For the classes defined above, the single-server scheduling problem is in S-P-C. T h a t is, for an ins tance of CM or C2 there exists a polynomial- t ime p rogram generator whose ou t pu t is a single- server scheduler tha t operates in cons tant t ime per slot scheduled. For CM the resul ts can be generalized to the mult i -server case.

1All c o m p l e t e n e s s r e s u l t s m e n t i o n e d in this paper are with r e s p e c t to polynomial time many-one reductions.

The remainder of this paper will establish the resul ts out- lined above. Section 2 contains the NP-completeness proof for the general case. Because of l imitat ions imposed on the length of this paper , we will include only a detailed sketch of the NP-ha rdness proof. A complete proof can be found in [1]. Section 3 concerns the restricted classes we have chosen as examples: CM (multiples) and ¢2 (two dist inct numbers) . In each case we will indicate a polynomial- t ime (or bet ter)

solution to the decision problem and show how to cons t ruc t a FOLS.

2 LpMPk, k > 1, is N P - c o m p l e t e in the s t r o n g sense

We now show tha t LpMpk , k > 1, is NP-complete in the s t rong sense. T h a t is, it is NP-comple te even if the numbers used to express ins tances are represented in unary. We will first show tha t LpMP1 polynomial t ime many-one reduces to LpMp~, for any k > 1. We then show tha t LpMP1 is NP-hard in the s t rong sense. Thus , LpMPk is NP-hard in the s t rong sense, for any k > 1. We then show tha t LpMpk,k _> 1, is in NP, and hence NP-complete in the s t rong sense.

We begin our proof of NP-hardness by showing t ha t a

proof of the NP-hardness of LpMpI is sufficient.

L e r n m a 1 LpMP1 polynomial time many-one reduces to

LpMpk, for any k > 1.

Proof: Pad the single-server instance with k - 1 Is. The given single-server instance has a schedule if and only if the resul t ing k-server ins tance has a schedule, k - 1 servers serve the machines of period l, and the remaining server models the given single-server instance. []

Much of what follows depends on the concepts of cyclic schedules and cyclic subschedules - - concepts which we will now define. We will show tha t an infinite schedule SI for ins tance A = { m l , . . . , m~} consists of repet i t ions of identi- cal segments of length l = LCMn=l(mi). Then SI = (Sc) w, where Sc is of length 1. Hereafter Sc will be represented s imply by S. We call such a segment S a "cyclic schedule" for A.

L e m m a 2 Any infinite schedule SI for an instance A = { m l , . . . ,ran} consists of repetitions of a cyclic schedule of length I = LCMn=l(ml).

Proof." Assume an infinite schedule SI exists for instance A. Now suppose t ha t index i appears in slot j . Then i also appears in slots j + c. ml for all na tura l c. This follows from the definition of a schedule. But because l is a mult iple of m~, i appears in slots j q- kl for all na tura l k. Thus , all length l segments of SI t ha t begin with a slot number tha t is a mult iple of I are identical to the segment consist ing of slots 0 th rough l - 1. []

Page 3: Algorithms and complexity of the periodic maintenance problem

A. Mok et al. / Algorithms and Complexity of the Periodic Maintenance Problem 659

If d divides I, then one can project S into d smaller cyclic

schedules ("subsehedules") S o , . . . , S d-1 each of length l/d by considering the slots in S modulo d - - t ha t is, subschedule Sj consists of those slots of S whose indices are congruent to j modulo d. Fur thermore , if d divides mi, then i will appear on only one subschedule. A schedule for A exists if and only if the d subschedules exist. For example, the cyclic single- server schedule S ="1,2,1,3,1,2,1,4" has two single-server

subschedules modulo 2: So ="1,1,1,1" and S1 ="2,3,2,4." In what follows we will refer to So, . . . , Sd-1 as the subschedules for S modulo d.

T h e o r e m 1 LpMP1 is NP-hard in the strong sense.

Proof: For the dura t ion of this proof we restrict our a t tent ion to single-server schedules. Thus , for the t ime being, the words "schedule," "subschedule," etc. refer implicitly to the single-server case.

The proof is by polynomial - t ime reduction from 3- satisfiability (3-SAT) [2]. Given an ins tance C of 3-SAT, we will describe a polynomial t ime construct ion F tha t will produce an ins tance of PMP1, F ( C ) , t ha t can be scheduled iff C is satisfiable.

Let C be an ins tance of 3-SAT over variables x l , . . . ,x~; wi thout loss of generality let C = A~=I Cj , Cj = V3=l c j k ,

where each Cjk is a dis t inct literal - - i.e., either a variable or the negat ion of a variable. Also wi thout loss of generality, we a s sume tha t no clause contains bo th a variable and its negation.

In part icular , F(C) will have the following form:

{ r ep2 ( x 1 ) , . . . , rap2 (xi), rep2 (X'l) . . . . , rap2 (31) . . . . , • y •

bx 1 t i m e s b~x I t i m e s

ep=(,:,~) . . . . . rep=(,~,,), ~, ep=(~,,),. :., rep=(~,~), b z n t i m e s b~n t i m e s

/1 . . . . . f~, rep~( C, ) . . . . . rep=(Cm)}. Informally, the various rap2 t e rms represent and are largely derived from their respective a rguments . The fi t e rms are derived from the representa t ions given to xi and ~i, and serve to insure tha t bo th xi and gi may not s imul taneous ly be true.

We will assign values to the rep2 and f t e rms such tha t 2n is a factor of each. l will be the LCM of all these val- ues. According to L e m m a 2 there is a cyclic schedule of this length iff F(C) is schedulable. Thus , if we let S' denote a potential cyclic schedule for F(C), of length l, we can con- sider subschedules modulo 2n - - So, . . . , $2n-1 - - of length l/2n.

If an index appears 2d • n slots apar t on S then it will appear d slots apar t on exactly on.....Ae of the sub- schedules. We cons t ruc t rep2(xl), 1 < i <_ n, so tha t

rep2(zl)/2n is relative pr ime to rep2(zj)/2n, 1 < j < n,i ¢ j , and relative pr ime to rep2(-~i)/2n,1 <_ j <_ n. Similarly, we cons t ruc t rep2(-~i), 1 < i < n, so tha t rep2(gi)/2n is relative pr ime to rep~(gj)/2n, 1 <_ j <_ n,i ~ j , and relative prime to rep2(xj)/2n, 1 < j < n. In a schedule or subschedule, relative prime service in- tervals mi and mj result in a conflict for one in every m i . m j slots, so two indices, whose periods divided by

2n are relative prime, mus t occupy different subschedules. Thus , we will have a one-to-one correspondence between

rep2(xl), rep2('~l) . . . . . rep2(zn), rep2(-~n) and So . . . . , $2n-1 - - and hence a one-to-one correspondence between the liter- als and the subschedules. T h a t is, one subschedule will con- ta in all of the indices whose periods are rep2(zl), another all of the indices whose periods are rep2(-~l), etc. However, these indices will not completely fill all the slots of any sub- schedule.

The representat ion of the conjunct Cj divided by 2n, rep2(Cj)/2n, 1 <_ j < m, will share a prime factor with the representa t ion of each of Cj ' s const i tuent literals divided by

2n - - rep2(cjl)/2n, rep2(cj2)/2n, and rep2(cj3)/2n - - and be relative prime to the representat ion of the 2n - 3 other Iiterals divided by 2n. Thus , the sole index whose period is rep2(Cj) mus t share a subschedule with the indices whose periods are the representat ion of one of Cj ' s cons t i tuent lit- erals.

f i /2n, 1 <_ i <_ n, will share a pr ime factor with the rep- resentat ion of xl and the representat ion of ~i divided by 2n, and be relative pr ime to the representat ion of the other 2 n - 2 literals divided by 2n. Thus , the sole index whose period is fi mus t share a subsehedule with the indices whose periods

are either rep2(xi) or rep2(~i). The interpretat ion we want is t ha t ass igning the index with period fi to the same subsched- ule as those indices with period rep2(xi)(rep2(~i)) models xi being "false" (" t rue") . In order to do this, the role of the fl t e rm is to "hog" enough of the slots on the subschedule to which it is assigned, to insure tha t no index whose period is rep2(Cj), 1 < j < m, can occupy the same subschedule. Thus , the index whose period is rep2(Cj), 1 < j < m, must share a subschedule with the indices whose periods are the

representa t ion of one of its cons t i tuent literals - - bu t this subschedule cannot be occupied by any index whose period is ] '1 , . - . , f~. Th i s will insure tha t the index whose period is rep2(Cj) cannot appear in the subschedule correspond- ing to xi while the index whose period is rep2(Ck) appears in the subschedule corresponding to gi - - thus effectively

modell ing ~(xi A ~i).

In the resul t ing periodic main tenance ins tance F ( C ) , if the indices corresponding to rep2(Cj), 1 < j <_ m, can be assigned to subschedules, then C can be satisfied by assign- ing the corresponding variables "true". This should follow readily f rom the above discussion. Likewise, if C is satis- fiable then F(C) can be scheduled by placing the indices corresponding to rep2(Cj), 1 <_ j < m, on the subschedules corresponding to the literal which makes Cj "true" in C ' s sat isfying ass ignment . The lat ter claim does not yet follow

Page 4: Algorithms and complexity of the periodic maintenance problem

660 A. Mok et aL ~Algorithms and Complexity of the Periodic Maintenance Problem

from the discussion. Its t ruth is a bit more difficult to es- tablish and depends heavily on the values chosen for each of

the undefined terms including bzl, b~zl,..., b=,, and b-~,.

To complete the proof, we demonstrate how to find

values for b=~, b~z~, . . . , bzn, b'~x,, rep2(xl), rep2(xl) . . . . . rep2(x~), rep2(~n), f l , . . . , f , , rep2(C1),. . . , and rep2(Cm) that possess the following p r o p e r t i e s :

1. For each i, 1 <_ i <_ n, rep2(zl)/2n is relative prime to

(a) rep2(xj)/2n, 1 <_ j < n, i ~ j , and

(b) ret~(~j) /2n, 1 < j < n.

2. For each i, 1 < i < n, rep2(~i)/2n is relative prime to

(a) rep2(-~j)12n, 1 <_ j <_ n, i ~t j , and

(b) rep2(xj) /2 . , 1 _< j __ n.

3. For each j , 1 <_ j < m, rep2(Cj)/2n will share

a prime factor with rep2(cji)/2n, rep2(cj2)/2n, and rep2(cja)/2n but be relative prime to the representa-

tions of the other 2n - 3 literals divided by 2n.

4. For each i, 1 < i < n, f i /2n will share a prime fac- tor with rep2(xl)/2n and rep2('Zi)/2n but be relative prime to the representation of the other 2n - 2 literals

divided by 2n.

5. For each i , j , 1 < i < n, 1 <_ j <_ m, indices whose

periods are rep2(xi) (or rep2(~i)), fl, and rep2(Cj) cannot appear in the same subschedule modulo 2n.

6. If C is satisfiable then F(C) can be scheduled.

An assignment of values satisfying these requirements

can be obtained by the following s teps :

1. Compute the first 2n primes greater than m and n; call

them pl through p2~. This may be done in determin-

istic polynomial time (see [6]). Let repl(xl) := p21-1

and repl(~i) := p21.

2. Let fi := 2n repl(xt) repl(-~i), 1 < i < n. Note that

f l <_f2<_. . .<_fn.

3. Let rep2(Cj) ;-~ 2n[repl(Cjl)repl(cj2)repl(cj3)] 2, 1 < j < m .

4. Let rep2(xl) := 2n[repl(xl)] 2, 1 < i < u.

5. Let rep2(~i) := 2n[repl('Zi)] 2, 1 < i < n.

6. Let b=, := [repl(xl)] 2 - repl(xi), 1 < i < n.

7. Let b~ i := [repl(-~i)] 2 - repl(~i), 1 < i < n.

Clearly F ( C ) can be derived from C in polynomial time. The proof that F(C) can be scheduled if and only if C is satisfiable has been omitted due to the space constraint. It

may be found in [1].

Note that all of the numbers used in F(C) are of mag- nitude polynomial in the size of C. Thus, LpMP1 remains NP-hard even if P M P 1 instances are expressed in unary,

and is therefore NP-hard in the strong sense. []

C o r o l l a r y 1 LpMPk, k >_ 1, is NP-hard in the strong sense.

Proof." Follows from Lemma 1 and Theorem 1. []

T h e o r e m 2 LpMPk, k >_ 1, is in NP.

Proof: Let A = { m l , . . . , m = } be an instance of P M P k . Consider the construction of an infinite k-server schedule

for A. We need to select starting slots for each index that will insure the avoidance of more than k collisions for any

particular slot. Our algorithm proceeds as follows:

1.

2.

Guess start ing locations a l , . . . , a N , 0 _< al < bl, for the n items.

Examine each set of the n items taken k + 1 at a time. Two items i and j conflict if and only if al -- a:(mod G C D ( m i , m j ) ) , and the k + 1 items all

conflict on the same slot if and only if each conflicts pairwise with each of the others, by the Generalized

Chinese Remainder Theorem (see e.g. [6]). Therefore, reject if a set of k + 1 items is found in which each item conflicts with each of the others.

3. Otherwise accept.

Note that the number of distinct sets of n items taken k + 1 n! at a time is (n-k-D!(k+~)!, which is polynomial in n for fixed

k. Thus, this algorithm runs in nondeterministic polynomial

time, and LpMPk, k _> 1, is in NP. []

C o r o l l a r y 2 LpMPk, k > 1, is NP-complete in the strong s e n s e .

Proof: Follows from Theorem 1 and Theorem 2. []

There is a relationship between P M P and the simulta- neous congruences problem (SCP) of [8] and [9]. We now

cast S C P ' s definition in terms of P M P . Given input: pe-

riods m l , . . . , m n , starting locations a l , . . . , a N , and k, the S C P is concerned with whether there are at least k simul- taneous conflicts. If the answer is "no," then k - 1 servers

are enough for the given selection of starting locations. It was established in [9] that S C P is NP-complete. Note that from the proof of Theorem 2 it can be seen that S C P for

fixed k is in PTIME.

A natural problem to address next is the complexity of LpMp = {(A, k ) [ A C P M P k } . The astute reader has no doubt already observed that the proof of Theorem 2 does not

Page 5: Algorithms and complexity of the periodic maintenance problem

A. Mok et aL / Algorithms and Complexity of the Periodic Maintenance Problem 661

work when k becomes part of the input. (This is because n! (n-k-1)!(k+X)! is not polynomial in k.) This question and

others will be taken up in a sequel to this paper where we show LpMp to be EP-complete 2 [1].

3 P o s i t i v e r e s u l t s f o r r e s t r i c t e d s i n g l e - s e r v e r c l a s s e s

In this section we present positive results for the single-server classes CM, in which each maintenance interval is a multiple of all smaller maintenance intervals, and C2, in which there are only two distinct maintenance intervals. In each case we will show that the decision problem can be solved in PTIME and that a FOLS can be constructed in deterministic poly- nomial t ime. The results for CM can easily be generalized to multiple servers. Throughout this section, unless stated otherwise, the use of the words "schedule," "schedulable," etc., refer to the single-server case.

We first consider the class CM. An instance A = {ml, . -- , ran} E CM has the characteristic that if ml > mj then mi is a multiple of mj. Note that an item i requires exactly 1/ml of the slots of a cyclic schedule, and that there- fore if ~ 1/mi > 1 no schedule is possible. However, an algorithm was given in [4] that may be used to schedule all instances of CM where ~ 1/ml < 1. While that algo- r i thm was proved correct for the corresponding special class of the pinwheel problem, which differs somewhat from peri- odic maintenance, it in fact produces a schedule that is also correct for PMP1. (This result also follows from a theorem in [ll].) The following is the algorithm from [4]:

Simplygreedy(A, n) { A is in ascending order, n is number of items. } { We create a cyclic schedule of length A[n], slot numbers 0..A[n]-i } fo r i := 1 to n do b e g i n { For each item ... }

j := location of first empty slot; w h i l e j < LCM(A) do b e g i n { Schedule i into all slots where it belongs. }

Schedule A[i] into slot j; j := j + A[i]

e n d e n d

"Simplygreedy" works by first scheduling item 1 into slot 0 and then every ml slots in a cyclic schedule of length LCM(A). It then finds the first empty slot and repeats this for m 2 , . . . , ms . Because the item periods are multiples, no conflicts occur. Thus, the decision problem for CM is trivial.

2EP is the second level of the polynomial-time hierarchy and con- sists of those languages that can be recognized by a nondeterministic polynomial-time machine with a nondeterministic polynomial-time or- acle [10].

"Simplygreedy" produces the schedule in a non- incremental fashion. That is, if slots i and j are consecutive slots, we have no guarantee that slot j will be scheduled after slot i. Also, because LCM is usually exponential in the length of the input, "Simplygreedy" may take time ex- ponential in the length of the input for each item scheduled. "Simplygreedy" therefore does not constitute a FOLS.

A more useful scheduling algorithm would have the prop- erty of producing the schedule in an incremental manner, taking constant time per slot. Such a scheduling algorithm would meet our definition of a FOLS. "Reservedgreedy" is such an algorithm:

Reservedgreedy(h,n) { A is in ascending order, n is the number of items. } Integer array S[0..A[n]-I]; { This array represents the cyclic schedule }

f u n c t i o n Blank(x) Blank := (Six] > n) o r (Six] < 0) {Index out of range}

o r (x-A[S[x]] < 0) { Wrong value to be genuine } or (S[x] <> S[x-A[S[x]]]) { Wrong value to be genuine }

e n d Blank;

b e g i n q := 1; { The index currently being scheduled } p := 0; { The current slot } r e p e a t { Repeatedly produce a cyclic schedule, length A[n]. }

i f Blank(p) t h e n b e g i n if (q < = n) t h e n b e g i n { Schedule q in current slot and reserve next }

Sip] := q; if (p + A[q]) < A[n] t h e n S[p+A[q]] := q; Output(q) ; q : = q + 1 { Next item }

e n d e lse b e g i n { This slot should he blank. }

Output(blank); S[p] := n + 1 { Impossible value = blank }

e n d e n d e lse b e g i n { Propagate reservation }

i f (p + A[S[p]]) < A[n] t h e n

S[p+A[S[p]]] := S[p]; Output(S[p])

e n d

{ Advance to next slot. } p := ( p + l ) r o o d A[n]; i f p=0 t h e n q := 1

f o r e v e r e n d

"Reservedgreedy" takes advantage of the fact that

Page 6: Algorithms and complexity of the periodic maintenance problem

662 A. Mok et al. / Algorithms and Complexity of the Periodic Maintenance Problem

smaller number s are scheduled first, allowing the schedule to be buil t incrementally, slot by slot. Larger periods are mul t ip les of smaller ones. If the i tem presently being sched- uled has period mi and the slot p being considered is unoc- cupied, the i t em may safely be scheduled because for all j , slot p + jm i is also present ly unoccupied.

In each i terat ion of the main loop, the a lgor i thm looks at the current slot. If the slot is unoccupied, it schedules the i tem which is due to be scheduled there. Also, a "reser- vation" is made in the slot in which the i tem is due to ap- pear nex t t ime (hence the n a m e "P~eservedgreedy"). Now the a lgor i thm has establ ished the s ta r t ing posit ion for the i tem; fur thermore , it will know tha t the i tem mus t be sched- uled again when it reaches the slot for which it earlier made a reservation. When it encounters a reservation, the algo- r i t hm reserves a slot for the i t em's next appearance. Thus , reservat ions are propagated. W h e n the a lgor i thm reaches an unoccupied slot it marks it as the s ta r t ing posit ion for the next i tem, and so on. The most interest ing quest ion is how we can recognize whether a slot in an uninitialized array is occupied.

One key feature of "Reservedgreedy" is t ha t it is self- initializing - - i.e., the a lgor i thm recognizes an unoccupied slot wi thout needing to initialize the array S. This is impor- tan t , since S will often be of size exponent ia l in the length of the instance. If we had to initialize it, ei ther we could not generate the FOLS in polynomial t ime or the initialization code in the FOLS itself would require more t han polyno- mial t ime. Assume a slot j u s t encountered is occupied. It m u s t be a reservation. We can find the period of the i tem occupying the slot, and compute the previous scheduling of t ha t i tem. If in fact we find someth ing else where tha t i tem should have been scheduled before, then we know t ha t the current slot cannot be a reservation. Our only a s sumpt ion is t ha t the slot is occupied, and this a s sumpt ion leads to a contradict ion. We will recognize any current slot which has not been reserved as blank. Thus , our a lgor i thm can gener- ate a correct schedule wi thout needing to initialize the array

S.

There follows a proof t ha t the a lgor i thm works.

L e m m a 3 ~Reservedgreedy" can recognize slots that should be blank.

Proof: For "Reservedgreedy" to work properly wi thout re- quir ing S to be initialized depends entirely on the algo- r i t hm ' s ability to recognize whether or not the present slot should be considered blank. This is done in the s t a t emen t

Blank := (Six] > n) o r (Six] < 0) { Index out of range }

o r (x-A[S[x]] < 0) { Wrong value to be genuine }

o r (S[x] < > S[x-A[S[x]]]) { Wrong value to be genuine }

There are now four cases:

1. The index number of the i tem in the current slot is not a valid i tem index number . Therefore, the slot mus t be blank.

2. The slot contains a valid index number , bu t when we check back for an earlier scheduling we go beyond the beginning of the schedule.

3. The slot contains a valid index number , bu t when we check back for an earlier scheduling, we find a different

index number .

4. The index is valid, and appears where it should earlier in the schedule.

The first three cases indicate tha t the slot has not been re- served and should therefore be considered blank. Because scheduling is done sequentially, the earlier slot we exam- ine has already been scheduled and its index propagated

ahead. Thus , if the present slot has already been scheduled the four th case will hold. Otherwise, one of the first three will hold.

The above covers all possible cases. Thus , the a lgor i thm can always determine whether or not a slot should be con- sidered blank. []

T h e o r e m 3 For input A, "Reservedgreedy" produces a schedule identical to that produced by ~Simplygreedy'.

Proof: Consider the step where "Reservedgreedy" reserves a slot for an i tem i with period j . Clearly, for k _> 1, j . k itera- t ions of the main program loop later, the a lgor i thm will rec- ognize the reservation and schedule i. Thus , in effect, every t ime a s t a r t ing posit ion if scheduled for an i tem i, all slots j .k uni t s ahead are guaran teed to become reserved by the t ime the a lgor i thm gets there. Thus , logically, the scheduling of the s ta r t ing posit ion by "Reservedgreedy" is equivalent to scheduling of all occurences of the i tem by "Simplygreedy". Since, like "Simplygreedy", "Reservedgreedy" schedules the smallest numbe r s first, we are guaranteed tha t the same slots will be occupied ("Simplygreedy") or reserved ("Reserved- greedy") for bo th algori thms. Thus , the result ing schedules are the same. [3

Wi th only a slight modification, "Reservedgreedy" be- comes a FOLS. It can be produced by the following P T P G (Polynomial T ime P rogram Generator) :

1. Assign values to e lements of array A and n.

2. Insert the body of "Reservedgreedy ' .

We find the following observations interesting:

Page 7: Algorithms and complexity of the periodic maintenance problem

A. Mok et al. / Algorithms and Complexity of the Periodic Maintenance Problem 663

1. The FOLS and associated P T P G work for ins tances with any number of dist inct main tenance intervals. Most of the restr icted classes we have examined, bo th in this paper and in [4] and [5], have involved restrict- ing the number of dis t inct number s in the input .

2. This technique may easily be extended to the corre- sponding mult i -server classes, since ins tances consist- ing of mult iples can always be broken up into k - 1 sets of i tems where ~ 1/al = 1 and one set where

I/ai < I. Thus , our a lgor i thm can be generalized to generate a k-server FOLS whenever the ins tance is such tha t ~ 1/al <_ k.

3. "Reservedgreedy" is self-stabilizing [3]. The only vari- ables are p, q, and S. If s tar ted in an arbi t rary s ta te , the p rogram will generate an incorrect schedule for up to A[n] slots, bu t will then begin generat ing a correct schedule.

As noted before, the array S in "Reservedgreedy" will often be of length exponent ia l in the length of the instance.

While this may seem a little peculiar, it is allowed by the definition of a FOLS. The a lgor i thm uses cons tan t t ime (and space) per slot scheduled. Large total resources may be used since the ou tpu t is an infinite schedule.

The other class we use as an example is C2, the class of ins tances consist ing of only two dist inct numbers . In con- t ras t to CM, the decision problem for C2 is not trivial. For example, a l though for the ins tance A = {2,3} the s u m of the reciprocals of the main tenance intervals is less than one, A cannot be scheduled. In addition, we will demons t ra te a FOLS tha t does not require exponent ial space. Thus , in some ways C2 makes a bet ter example than CM.

For this class, there exist easily verified necessary and sufficient condit ions for de termining schedulability. For no- ta t ional convenience, we will represent an ins tance consist ing of a repet i t ions of xl and b repeti t ions of x2 as the quadruple (a, xl,b, x2). We define d to be GCD(xl,X2) and x~ and x~ to be xl /d and x2/d, respectively. T h e n A = (a, Xl,b, x2) can be scheduled if and only if there exist u, v such tha t the following condit ions are satisfied:

1. u + v = d

2. u.x'l >a

3. v'x~>_b

These equat ions follow as a direct result of the appli- cat ion of the Generalized Chinese Remainder Theorem (see, e.g., [6]). The result is an instance of integer linear program- ming with a fixed number of variables, and can therefore be solved in determinis t ic polynomial t ime [7].

Making a schedule then becomes simple. Every block of d slots is par t i t ioned into two parts , the first u slots long

and the second v slots long. The XlS are scheduled in the u portion, and the z2s in the v portion, one after the other, unti l all s ta r t ing posit ions are established. If a > u (b > v) then the s ta r t ing posit ions for the remaining x l s (x2s) will be scheduled in the next u (v) portion. The linear p rogramming problem simply requires dividing each block of d slots up into a u por t ion and a v port ion such tha t the s ta r t ing locations can be so allocated.

A FOLS can now easily be constructed. Given an in- s tance A = (a, Zl,b, x2), calculate d,u, and v. As noted above, this can be done in determinist ic polynomial time. Then insert the following code:

cl := 0; { Next xl index to be scheduled } c2 := 0; { Next z2 index to be scheduled } m l := 0; { Beginning of next series of Xl indices } m2 := u; { Beginning of next series of x2 indices } p := 0; { Next slot number to be scheduled } r e p e a t

i f (p r o o d d) < u t h e n { We're in the "u" section of a block of slots. }

i f (p > = m l ) o r (cl < > 0) t h e n b e g i n if (cl = 0) t h e n m l := m l + xl; { First Xl index: compute next occurrance. } ou tpu t ( c l ) ; cl := (cl + 1) r o o d a

e n d e l se output(blank)

{We've scheduled all necessary XlS until m l is reached.} e l se { In the "v" section of a block of slots, schedule z2s. } { The code is symmet r i c to the "then" portion. }

i f (p > = m2) o r (c2 < > 0) t h e n b e g i n if (cs = 0) t h e n m2 := m2 + z2; output (c2 + a); c2 := (c2 + 1) r o o d b

e n d e l se output(blank);

p :-- p + 1; i f p < = LCM(x l , x2) t h e n b e g i n

cl := 0 ;c2 :-- 0 ; m l := 0; m2 := u ; p := 0 e n d f o r e v e r ;

The FOLS is completely symmetr ic , consist ing of two pieces of code, one becoming active when the a lgor i thm is scanning in the u port ion of the schedule and the other be- coming active in the v portion. The two are mutua l ly exclu- sive, so in effect one par t of the a lgori thm sleeps while the other makes a schedule for its area.

As in the FOLS for CM, the schedule is developed in- crementally, in cons tan t t ime per slot scheduled. Thus , in each i teration the scheduler does the following: First, it de- te rmines whether the current slot is in the u port ion or the v portion. If the scheduler is scheduling the first of the x l s (x2s), it marks the slot xl (x2) uni ts ahead on the schedule.

Page 8: Algorithms and complexity of the periodic maintenance problem

664 A. Mok et al. ~Algorithms and Complexity of the Periodic Maintenance Problem

That way, after it places all of the z ls in the u portion, it will know that the remaining slots must be idle. Otherwise, it schedules the appropriate xl (x2) into the slot. Then it moves on to the next slot.

Note that the resulting FOLS does not need exponential space, since it does not retain a copy of the schedule it cre- ates. It does not extend easily to the multi-server case, but it is self stabilizing.

In this section we have demonstrated deterministic polynomial-time decision procedures, polynomial-time pro- gram generators, and FOLS for the classes CM and C2. Thus, we have established that each of these classes is in the com- plexity class S-P-C.

Acknowledgements

We thank C. L. Liu for directing our attention to [11] and for other helpful comments.

R e f e r e n c e s

[1] S. Baruah, L. Rosier, I. Tulchinsky, and D. Varvel, "The Complexity of Periodic Maintenance," in preparation.

[2] S. Cook, "The Complexity of Theorem Proving Proce- dures," Proceedings of the Third Annual ACM Sympo- sium on the Theory of Computing, pp. 151-158, 1971.

[3] E. Dijkstra, "Self Stabilizing Systems In Spite Of Dis- tributed Control," Communications of the ACM, 17: 643-644, 1974.

[4] R. Ilolte, A. Mok, L. Rosier, I. Tulchinsky, D. Varvel, "The Pinwheel: A Real-Time Scheduling Problem," Proceedings of the 22nd Hawaii International Confer- ence on System Science, pp. 693-702, Kailua-Kona, January 1989.

[5] R. Holte, L. Rosier, I. Tulchinsky, D. Varvel, "Pinwheel Scheduling With Two Distinct Numbers," MFCS '89, August/September 1989.

[6] D. Knuth, T h e A r t of C o m p u t e r P r o g r a m m i n g : Vol. 2, S e m i n u m e r i e a l A l g o r i t h m s , Addison- Wesley, 1973.

[7] It. Lenstra, "Integer Programming with a Fixed Num- ber of Variables," Mathematics of Operations Research, Vol. 8, No. 4, pp. 538-548, November 1983.

[8] J. Leung and M. Merrill, "A Note on Preemptive Scheduling of Periodic, Real-Time Tasks," Information Processing Letters, Vol. 11, pp. 115-118, 1980.

[9] J. Leung and J. Whitehead, "On the Complexity of Fixed-Priority Scheduling of Periodic, Real-Time Tasks," Performance Evaluation 2, pp. 237-250, 1982.

[10] L. Stockmeyer, "The Polynomial Time Ilierarchy," Theoretical Computer Science, 3:1, pp. 1-22, 1976.

[11] W. Wet and C. Liu, "On a Periodic Maintenance Prob- lem," Operations Research Letters, Vol. 2, No. 2, pp. 90-93, June 1983.