I don't understand very well section 16.5 of the 3rd edition of the famous Introduction to Algorithms
book, known as CLRS. It defines the problem of scheduling unit-time tasks with deadlines and penalties for a single processor with the following inputs:
- a set $S = {a_{1}, a_{2}, ..., a_{n}}$ of $n$ unit-time tasks
- a set of $n$ integer deadlines ${d_{1}, d_{2}, ..., d_{n}}$ such that each $d_{i}$ satisfies $1 \leq d_{i} \leq n$ and task $a_i$ is supposed to finish by time $d_i$
- a set of of $n$ nonnegative weights or penalties ${w_{1}, w_{2}, ..., w_{n}}$, such that we incur a penalty of $w_i$ if task $a_i$ is not finished by time $d_i$, and we incur no penalty if a task finished by its deadline.
And the following goal:
We wish to find a schedule for S that minimizes the total penalty incurred for missed deadlines.
NOTE: I'm aware that there are other posts here about similar problems (scheduling unit-time tasks with profit etc.), but I'm trying to understand this particular explanation, on the CLRS book.
So, I'll get now to the point. On the same page (444), where it explains the core idea, the book talks about the early-first form and the canonical form, without mentioning the penalties anymore: it talks exclusively about the deadlines (I'm not going to copy the whole text, I'm assuming that who answers the question owns the book).
My first question: because the whole reasoning does not mention penalties, it looks like to me it will work only if all the penalties are equal, which would be a different problem. I'm probably missing something here. But what? No matter how you order the tasks based on deadlines, you cannot possibly minimize the penalties without taking them into account. In other words, even if you hit 99/100 deadlines and missed the deadline for that one single task, its penalty might be bigger than the penalties of all the other tasks combined. I don't understand CRLS's logic, in this particular case.
My second question: on the next page (445), CLRS mentions the penalties in one place:
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.
And after that it mentions theorem 16.13 claiming substantially that $(S, I)$ is a matroid.
I believe I understand that, it makes sense. But, how can we determine in the first place the subset of the early tasks without taking into account the actual values of each $w_i$ penalty? In my understanding, that's not possible. I wouldn't dare claiming there's a mistake in the CLRS book, but that's my only theory at the moment. Very likely I'm wrong, but I cannot figure out why. On page 444, it mentions twice "monotonically increasing deadlines" but never anything like "monotonically decreasing penalties".
On the other side, I've done some research and I've read about variations of this problem with profits instead of penalties. I've understood that the tasks need to be ordered by monotonically decreasing profit. After doing that, we put each task as close to its deadline as possible, and move left only (= early) when the slot is already taken. That makes completely sense, because the profit is taken into account. If we consider penalties as negative profits, shouldn't the same logic apply? But, even with a different logic, how can we ignore the $w_i$ values?