Editorial for IOI '02 P4 - Batch Scheduling


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

This problem can be solved using dynamic programming. Let Ci be the minimum total cost of all partitionings of jobs Ji,Ji+1,,Jn into batches. Let Ci(k) be the minimum total cost when the first batch is selected as {Ji,Ji+1,,Jk1}. That is, Ci(k)=Ck+(S+Ti+Ti+1++Tk1)×(Fi+Fi+1++Fn).

Then we have that

  • Ci=min{Ci(k)k=i+1,,n+1} for 1in,
  • and Cn+1=0.

O(n2) Time Algorithm

The time complexity of the above algorithm is O(n2).

O(n) Time Algorithm

Investigating the property of Ci(k), P. Bucker [1] showed that this problem can be solved in O(n) time.

From Ci(k)=Ck+(S+Ti+Ti+1++Tk1)×(Fi+Fi+1++Fn), we have that for i<k<l,

Ci(k)Ci(l)ClCk+(Tk+Tk+1++Tl1)×(Fi+Fi+1++Fn)0CkClTk+Tk+1++Tl1Fi+Fi+1++Fn

Let g(k,l)=CkClTk+Tk+1++Tl1 and f(i)=Fi+Fi+1++Fn.

Property 1: Assume that g(k,l)f(i) for 1i<k<l. Then Ci(k)Ci(l).

Property 2: Assume g(j,k)g(k,l) for some 1j<k<ln. Then for each i with 1i<j, Ci(j)Ci(k) or Ci(l)Ci(k).

Property 2 implies that if g(j,k)g(k,l) for j<k<l, Ck is not needed for computing Fi. Using this property, a linear time algorithm can be designed, which is given in the following.

Algorithm Batch

The algorithm calculates the values Ci for i=n down to 1. It uses a queue-like list Q=(ir,ir1,,i2,i1) with tail ir and head i1 satisfying the following properties:

  • ir<ir1<<i2<i1 and
  • g(ir,ir1)>g(ir1,ir2)>>g(i2,i1) — (1)

When Ci is calculated,

  1. // Using f(i), remove unnecessary element at head of Q.

    If f(i)g(i2,i1), delete i1 from Q since for all hi, f(h)f(i)g(i2,i1) and Ch(i2)Ch(i1) by Property 1.

    Continue this procedure until for some tl, g(ir,ir1)>g(ir1,ir2)>>g(it+1,it)>f(i).

    Then by Property 1, Ci(iv+1)>Ci(iv) for v=t,,r1 or r=t and Q contains only it.

    Therefore, Ci(it) is equal to min{Ci(k)k=i+1,,n+1}.

  2. // When inserting i at the tail of Q, maintain Q for the condition (1) to be satisfied.

    If g(i,ir)g(ir,ir1), delete ir from Q by Property 2.

    Continue this procedure until g(i,iv)>g(iv,iv1).

    Append i as a new tail of Q.

Analysis

Each i is inserted into Q and deleted from Q at most once. In each insertion and deletion, it takes a constant time. Therefore the time complexity is O(n).


Comments

There are no comments at the moment.