2.2 The optimal algorithm
2.2.2 The algorithm
As we stated before, our algorithm first calls the procedure GetRatioValue to obtain parameter R, which is the competitive ratio maintained by the algorithm. Then upon arrival of a job Jj it calls GetOptValue to get the value of minimum
makespan that optimum can achieve. This is simply the makespan of current optimal schedule for online scheduling. The value Tj is computed as R times the
result of GetOptValue(J[j]).
Then the algorithm finds two adjacent virtual machines Vk and Vk+1, and time
tj, such that if Jj is scheduled on Vk+1 in the time interval (0, tj] and on Vk from
tj on, then Jj finishes exactly at time Tj. It is essential that each job is stretched
over the whole interval (0, Tj], which is the maximal time interval which it can
use without violating the desired competitive ratio. Next we update the virtual machines, which means that in the interval (0, Tj] we merge Vkand Vk+1into Vkand
shift machines Vℓ+1, ℓ > k, to Vℓ. Then we continue with the next job. This gives
a complete informal description of the algorithm sufficient for its implementation. To prove that our algorithm works, it is sufficient to show that each job Jj
Algorithm 1 RatioStretch
1: procedure Initialize(Ψ; M1, M2, . . . , Mm) 2: R← GetRatioValue(Ψ; M1, M2, . . . , Mm) 3: for i∈ {1, . . . , m}, τ ∈ (0, ∞) do Vi(τ )← Mi
4: for τ ∈ (0, ∞) do Vm+1 ← ⊥ ⊲ Vm+1 just helps the formulation. 5: (for i∈ {1, . . . , m + 1} do Si ← ∅ ⊲ Defines Si for the proof.) 6: end procedure
7: procedure OnlineJob(Jj)
8: Tj ← R · GetOptValue(Ψ; M1, M2, . . . , Mm; J1, J2, . . . , Jj) 9: k ← min{k | Wk(Tj)≥ pj ≥ Wk+1(Tj)}
⊲ If there is no k then output “failed” and stop.
10: find tj ∈ (0, Tj] such that Wk(tj) + Wk(Tj)− Wk(tj) = pj
11: for τ ∈ (0, tj] do
12: output σj(τ )← Vk+1(τ ) ⊲ Schedule the job to Vk+1 in (0, tj]. 13: for i ∈ {k + 1, . . . , m} do Vi(τ )← Vi+1(τ )
⊲ Update virtual machines on (0, tj]. 14: end for
15: for τ ∈ (tj, Tj] do
16: output σj(τ )← Vk(τ ) ⊲ Schedule the job to Vk in (tj, Tj]. 17: for i ∈ {k, . . . , m} do Vi(τ )← Vi+1(τ )
⊲ Update virtual machines on (tj, Tj]. 18: end for
19: for τ > Tj output σj(τ )← ⊥
20: (Sk← Sk∪ Sk+1 ⊲ Defines Si for the proof.)
21: (for i∈ {k + 1, . . . , m} do Si ← Si+1 ⊲ Defines Si for the proof.) 22: end procedure
23: Initialize(Ψ; M1, M2, . . . , Mm); j← 1 24: while j ≤ n do OnlineJob(Jj); j ← j + 1 25: end while
scheduled on V1, completes by time Tj; this is equivalent to the fact that we can
schedule Jj as described above. We show that this is true as long as GetRatio-
Value returns a valid upper bound on competitive ratio.
To facilitate the proof, we maintain an assignment of scheduled jobs (and con- sequently busy machines at each time) to the set of virtual machines, i.e., for each virtual machine Vi we compute a set Si of jobs assigned to Vi. Although
the incoming job Jj is split between two different virtual machines, at the end of
each iteration each scheduled job belongs to exactly one set Si, since right after
Jj is scheduled the virtual machines executing this job are merged (during the
execution of Jj). We stress that the sets Si serve only as means of bookkeeping
for the purpose of the proof, and their computation is not an integral part of the algorithm.
See Figure 2.1 for an example.
At each time τ , machine Mℓ belongs to Vi if it is the ith fastest idle machine
at time τ (i.e., Vi(τ ) = Mℓ), or if it is running a job j ∈ Si at time τ . At each
time τ the real machines belonging to Vi form a set of adjacent real machines,
i.e., all machines Mk, Mk+1, . . . , Mℓ for some k ≤ ℓ. This relies on the fact that
we always schedule a job on two adjacent virtual machines which are then merged into a single virtual machine during the times when the job is running, and on the fact that these time intervals (0, Tj] increase with j, as adding new jobs cannot
decrease the optimal makespan (i.e., Tj = RCmax∗,Ψ[J[j]]≤ RCmax∗,Ψ[J[j+1]] = Tj+1).
Let vi(t) denote the speed of the virtual machine Vi at time t, i.e. vi(t) =
s(Vi(t)). We define vi(t) = s(⊥) = 0 if Vi is undefined at time t. This corresponds
to the fact that a job scheduled to Vi at time t will be processed by speed vi(t).
Let Wi(t) =
Rt
0 vi(τ )dτ be the total work which can be done on machine Vi
in the time interval (0, t]. By definition we have vi(t) ≥ vi+1(t) and thus also
Wi(t)≥ Wi+1(t) for all i and t. Note also that Wm+1(t) = vm+1(t) = 0 for all t.
Theorem 2.2.1 Suppose the procedure GetOptValue returns always a num- ber in [C∗,Ψ
max, αCmax∗,Ψ] and procedure GetRatioValue returns an upper bound on
competitive ratio R ≥ rΨ(M). Then the algorithm RatioStretch never out-
puts ”failed” and is ¯R = αR competitive for online preemptive scheduling on m uniformly related machines with speeds s1 ≥ s2 ≥ · · · ≥ sm.
We have to ensure, that outputs of GetOptValue are nondecreasing, but this can be done simply by returning the maximum of results of calls to GetOptValue so far. As optima are nondecreasing in time, this cannot break the condition that result of GetOptValue is in [C∗,Ψ
max, αCmax∗,Ψ].
Proof: If RatioStretch schedules a job, it is always completed at time Tj ≤
¯ R · C∗,Ψ
max[(Ji)ni=1]. Thus to prove the theorem, it is sufficient to guarantee that
the algorithm does not fail to find the number k on line 9. This is equivalent to the statement that there is always enough space on V1, i.e., that pj ≤ W1(Tj)
in the iteration when j is to be scheduled. Since Wm+1 = 0 by the definition,
this is sufficient to guarantee that required k exists. Given the choice of k, it is always possible to find time tj (on the next line of the algorithm) as the expression
R· OPT1 R· OPT2
R· OPT1 R· OPT2
Figure 2.1: An illustration of a schedule of two jobs on three machines produced by RatioStretch. Vertical axis denotes the time, horizontal axis corresponds to the speed of the machines. The pictures on the left depict the schedule on the real machines, with bold lines separating the virtual machines. The pictures on the right show only the idle time on the virtual machines. The top pictures show the situation after the first job, with the second job being scheduled on the first two virtual machines. The bottom pictures show the situation with after the second job is scheduled and virtual machines updated.
Wk+1(tj)+Wk(Tj)−Wk(tj) is continuous in tj, for tj = 0 it is equal to Wk(Tj)≥ pj,
and for tj = Tj it is equal to Wk+1(Tj)≤ pj.
Consider now all the jobs that are scheduled on the first virtual machine, i.e., the set S1. Let ¯J1, ¯J2, . . . , ¯Jn′−1 denote the jobs in S1, ordered as they appear on
input. Let ¯Jn′ = J be the incoming job. Let Tj be the time computed on line 8
when a job ¯Jj is processed.
Consider any j′ = 1, . . . , n′ and any time τ ∈ (0, T
j′]. Using the fact that
the times Tj are non-decreasing in j and that the algorithm stretches each job j
over the whole interval (0, Tj], there are at least n′ − j′ jobs from S1 running at
τ , namely jobs ¯Jj′, ¯Jj′+1, . . . , ¯Jn′−1. Including the idle machine, there are at least
m + 1− j′ real machines belonging to V
1. Since V1 is the first virtual machine and
the real machines are adjacent, they must include the fastest real machines M1, . . . ,
Mm+1−j′. It follows that the total work that can be processed on the real machines
belonging to V1 during the interval (0, Tjm] is at least s1Tn′+ s2Tn′−1+· · · + sn′T1.
¯
Jn′ can be scheduled on V1 we need to verify that
¯
pn′ ≤ s1Tn′+ s2Tn′−1+· · · + sn′T1− (¯p1+ ¯p2+· · · + ¯pn′−1). (2.6)
From the assumption of the correctness of GetRatioValue, we can use Lemma 2.1.5 (the first inequality), and then (in second inequality) we use the correctness of GetOptValue: (¯p1+ ¯p2+· · · + ¯pn′) ≤ R Pn′ i=1siCmax∗,Ψ[ ¯J [n′− i + 1]] ≤ Pn′ i=1siTn′−i+1 .
Corollary 2.2.2 With procedures that return the exact values for C∗,Ψ
maxand rΨ(M)
is our algorithm optimal (semi-)online algorithm with competitive ratio rΨ(M).
Proof: The corollary is direct consequence of Theorem 2.2.1 and Definition 2.1.6.
Note that our algorithm is deterministic. (We assume both procedures to be deterministic here.) The lower bound rΨ(M) holds also for randomized algorithms.
Thus randomization does not help here in preemptive (semi-)online scheduling.