0% found this document useful (0 votes)
30 views

A task-scheduling probelm as a matroid

The document discusses the task-scheduling problem as a matroid, specifically focusing on scheduling unit-time tasks on a single processor with deadlines and penalties. It introduces a method to determine independent sets of tasks and utilizes a greedy algorithm to minimize penalties for missed deadlines. The document also includes exercises to reinforce the concepts presented, along with a specific example of scheduling tasks with given deadlines and penalties.

Uploaded by

kunalrastogi13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

A task-scheduling probelm as a matroid

The document discusses the task-scheduling problem as a matroid, specifically focusing on scheduling unit-time tasks on a single processor with deadlines and penalties. It introduces a method to determine independent sets of tasks and utilizes a greedy algorithm to minimize penalties for missed deadlines. The document also includes exercises to reinforce the concepts presented, along with a specific example of scheduling tasks with given deadlines and penalties.

Uploaded by

kunalrastogi13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

16.

5 A task-scheduling problem as a matroid 443

Exercises

16.4-1
Show that .S;  k / is a matroid, where S is any finite set and  k is the set of all
subsets of S of size at most k, where k  jSj.

16.4-2 ?
Given an m  n matrix T over some field (such as the reals), show that .S;  / is a
matroid, where S is the set of columns of T and A 2  if and only if the columns
in A are linearly independent.

16.4-3 ?
Show that if .S;  / is a matroid, then .S;  0 / is a matroid, where
 0 D fA0 W S  A0 contains some maximal A 2  g :
That is, the maximal independent sets of .S;  0 / are just the complements of the
maximal independent sets of .S;  /.

16.4-4 ?
Let S be a finite set and let S1 ; S2 ; : : : ; Sk be a partition of S into nonempty disjoint
subsets. Define the structure .S;  / by the condition that  D fA W jA \ Si j  1
for i D 1; 2; : : : ; kg. Show that .S;  / is a matroid. That is, the set of all sets A
that contain at most one member of each subset in the partition determines the
independent sets of a matroid.

16.4-5
Show how to transform the weight function of a weighted matroid problem, where
the desired optimal solution is a minimum-weight maximal independent subset, to
make it a standard weighted-matroid problem. Argue carefully that your transfor-
mation is correct.

? 16.5 A task-scheduling problem as a matroid

An interesting problem that we can solve using matroids is the problem of op-
timally scheduling unit-time tasks on a single processor, where each task has a
deadline, along with a penalty paid if the task misses its deadline. The problem
looks complicated, but we can solve it in a surprisingly simple manner by casting
it as a matroid and using a greedy algorithm.
A unit-time task is a job, such as a program to be run on a computer, that requires
exactly one unit of time to complete. Given a finite set S of unit-time tasks, a
444 Chapter 16 Greedy Algorithms

schedule for S is a permutation of S specifying the order in which to perform


these tasks. The first task in the schedule begins at time 0 and finishes at time 1,
the second task begins at time 1 and finishes at time 2, and so on.
The problem of scheduling unit-time tasks with deadlines and penalties for a
single processor has the following inputs:
 a set S D fa1 ; a2 ; : : : ; an g of n unit-time tasks;
 a set of n integer deadlines d1 ; d2 ; : : : ; dn , such that each di satisfies 1  di  n
and task ai is supposed to finish by time di ; and
 a set of n nonnegative weights or penalties w1 ; w2 ; : : : ; wn , such that we incur
a penalty of wi if task ai is not finished by time di , and we incur no penalty if
a task finishes by its deadline.
We wish to find a schedule for S that minimizes the total penalty incurred for
missed deadlines.
Consider a given schedule. We say that a task is late in this schedule if it finishes
after its deadline. Otherwise, the task is early in the schedule. We can always trans-
form an arbitrary schedule into early-first form, in which the early tasks precede
the late tasks. To see why, note that if some early task ai follows some late task aj ,
then we can switch the positions of ai and aj , and ai will still be early and aj will
still be late.
Furthermore, we claim that we can always transform an arbitrary schedule into
canonical form, in which the early tasks precede the late tasks and we schedule
the early tasks in order of monotonically increasing deadlines. To do so, we put
the schedule into early-first form. Then, as long as there exist two early tasks ai
and aj finishing at respective times k and k C 1 in the schedule such that dj < di ,
we swap the positions of ai and aj . Since aj is early before the swap, k C 1  dj .
Therefore, k C 1 < di , and so ai is still early after the swap. Because task aj is
moved earlier in the schedule, it remains early after the swap.
The search for an optimal schedule thus reduces to finding a set A of tasks that
we assign to be early in the optimal schedule. Having determined A, we can create
the actual schedule by listing the elements of A in order of monotonically increas-
ing deadlines, then listing the late tasks (i.e., S  A) in any order, producing a
canonical ordering of the optimal schedule.
We say that a set A of tasks is independent if there exists a schedule for these
tasks such that no tasks are late. Clearly, the set of early tasks for a schedule forms
an independent set of tasks. Let  denote the set of all independent sets of tasks.
Consider the problem of determining whether a given set A of tasks is indepen-
dent. For t D 0; 1; 2; : : : ; n, let N t .A/ denote the number of tasks in A whose
deadline is t or earlier. Note that N0 .A/ D 0 for any set A.
16.5 A task-scheduling problem as a matroid 445

Lemma 16.12
For any set of tasks A, the following statements are equivalent.
1. The set A is independent.
2. For t D 0; 1; 2; : : : ; n, we have N t .A/  t.
3. If the tasks in A are scheduled in order of monotonically increasing deadlines,
then no task is late.

Proof To show that (1) implies (2), we prove the contrapositive: if N t .A/ > t for
some t, then there is no way to make a schedule with no late tasks for set A, because
more than t tasks must finish before time t. Therefore, (1) implies (2). If (2) holds,
then (3) must follow: there is no way to “get stuck” when scheduling the tasks in
order of monotonically increasing deadlines, since (2) implies that the ith largest
deadline is at least i. Finally, (3) trivially implies (1).

Using property 2 of Lemma 16.12, we can easily compute whether or not a given
set of tasks is independent (see Exercise 16.5-2).
The problem of minimizing the sum of the penalties of the late tasks is the same
as the problem of maximizing the sum of the penalties of the early tasks. The
following theorem thus ensures that we can use the greedy algorithm to find an
independent set A of tasks with the maximum total penalty.

Theorem 16.13
If S is a set of unit-time tasks with deadlines, and  is the set of all independent
sets of tasks, then the corresponding system .S;  / is a matroid.

Proof Every subset of an independent set of tasks is certainly independent. To


prove the exchange property, suppose that B and A are independent sets of tasks
and that jBj > jAj. Let k be the largest t such that N t .B/  N t .A/. (Such a value
of t exists, since N0 .A/ D N0 .B/ D 0.) Since Nn .B/ D jBj and Nn .A/ D jAj,
but jBj > jAj, we must have that k < n and that Nj .B/ > Nj .A/ for all j in
the range k C 1  j  n. Therefore, B contains more tasks with deadline k C 1
than A does. Let ai be a task in B  A with deadline k C 1. Let A0 D A [ fai g.
We now show that A0 must be independent by using property 2 of Lemma 16.12.
For 0  t  k, we have N t .A0 / D N t .A/  t, since A is independent. For
k < t  n, we have N t .A0 /  N t .B/  t, since B is independent. Therefore, A0
is independent, completing our proof that .S;  / is a matroid.

By Theorem 16.11, we can use a greedy algorithm to find a maximum-weight


independent set of tasks A. We can then create an optimal schedule having the
tasks in A as its early tasks. This method is an efficient algorithm for scheduling
446 Chapter 16 Greedy Algorithms

Task
ai 1 2 3 4 5 6 7
di 4 2 4 3 1 4 6
wi 70 60 50 40 30 20 10

Figure 16.7 An instance of the problem of scheduling unit-time tasks with deadlines and penalties
for a single processor.

unit-time tasks with deadlines and penalties for a single processor. The running
time is O.n2 / using G REEDY, since each of the O.n/ independence checks made
by that algorithm takes time O.n/ (see Exercise 16.5-2). Problem 16-4 gives a
faster implementation.
Figure 16.7 demonstrates an example of the problem of scheduling unit-time
tasks with deadlines and penalties for a single processor. In this example, the
greedy algorithm selects, in order, tasks a1 , a2 , a3 , and a4 , then rejects a5 (because
N4 .fa1 ; a2 ; a3 ; a4 ; a5 g/ D 5) and a6 (because N4 .fa1 ; a2 ; a3 ; a4 ; a6 g/ D 5), and
finally accepts a7 . The final optimal schedule is
ha2 ; a4 ; a1 ; a3 ; a7 ; a5 ; a6 i ;
which has a total penalty incurred of w5 C w6 D 50.

Exercises

16.5-1
Solve the instance of the scheduling problem given in Figure 16.7, but with each
penalty wi replaced by 80  wi .

16.5-2
Show how to use property 2 of Lemma 16.12 to determine in time O.jAj/ whether
or not a given set A of tasks is independent.

Problems

16-1 Coin changing


Consider the problem of making change for n cents using the fewest number of
coins. Assume that each coin’s value is an integer.
a. Describe a greedy algorithm to make change consisting of quarters, dimes,
nickels, and pennies. Prove that your algorithm yields an optimal solution.

You might also like