(Latest Revision:
Nov 20, 2022)
Weighted Intervals Problem
EXAMPLE:
Suppose we have the following weighted intervals.
start finish weight
12 14 7
17 20 10
22 25 5
21 27 8
19 24 4
10 13 6
15 23 5
11 16 8
To solve the problem, we sort the intervals by increasing finish time, and compute the p-values.
This gives us the following list. (I include a pictorial depiction of the intervals.)
# start finish weight 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
1 10 13 6 --------------------- p=0
2 12 14 7 -------------- p=0
3 11 16 8 ----------------------------------- p=0
4 17 20 10 --------------------- p=3
5 15 23 5 -------------------------------------------------------- p=2
6 19 24 4 ----------------------------------- p=3
7 22 25 5 --------------------- p=4
8 21 27 8 ----------------------------------------- p=4
We then use the recursive relation to compute the OPT values from row 1 to row 8.
(As an aid to implementing the base case of the algorithm,
we start with a "sentinel interval 0" that has just row of zeros for
the start & finish times, the weight, the p-value, and the OPT value.)
# strt-fnsh w p OPT
0 0-0 0 0 0
1 10-13 6 0 6 = max {OPT(0), w1+OPT(p(1))} = max { 0, 6 + 0} = 6
2 12-14 7 0 7 = max {OPT(1), w2+OPT(p(2))} = max { 6, 7 + 0} = 7
3 11-16 8 0 8 = max {OPT(2), w3+OPT(p(3))} = max { 7, 8 + 0} = 8
4 17-20 10 3 18 = max {OPT(3), w4+OPT(p(4))} = max { 8, 10 + 8} = 18
5 15-23 5 2 18 = max {OPT(4), w5+OPT(p(5))} = max {18, 5 + 7} = 18
6 19-24 4 3 18 = max {OPT(5), w6+OPT(p(6))} = max {18, 4 + 8} = 18
7 22-25 5 4 23 = max {OPT(6), w7+OPT(p(7))} = max {18, 5 + 18} = 23
8 21-27 8 4 26 = max {OPT(7), w8+OPT(p(8))} = max {23, 8 + 18} = 26
Then we do the backtracking.
26=OPT(8) > OPT(7)=23, so we need interval 8, and we resume backtracking at interval p(8), which is interval 4.
18=OPT(4) > OPT(3)=8, so we need interval 4, and we resume backtracking at interval p(4), which is interval 3.
8=OPT(3) > OPT(2)=7, so we need interval 3, and we resume backtracking at interval p(3), which is interval 0, (but backtracking at interval 0 is the sentinel, so we stop).
The work above shows that intervals 8, 4, and 3 comprise an optimal solution,
having combined weight of 8+10+8=26.
Note:
Generally, when backtracking, if OPT(j) = OPT(j-1), it may or may not
be possible to use interval j in an optimal solution. (It is only possible when w(j)+OPT(p(j))=OPT(j-1).) However, when OPT(j) = OPT(j-1), we never need interval j to get an optimal solution. Rather than check to see if w(j)+OPT(p(j))=OPT(j-1), it's less work just to resume backtracking at row j-1. We will always find an optimal solution this way.
The discussion above shows how to work this kind of problem. Your assignment is to do the following problem, and to produce a corresponding table and backtracking results, according to the technique illustrated in the example.
YOUR ASSIGNED PROBLEM:
start finish weight
10 18 9
22 28 10
12 15 5
26 29 8
11 14 7
19 23 6
17 21 6
16 20 10
Let me know if you have questions about how such problems are solved. The algorithm is covered in sections 6.1 and 6.2.
Directions For Submitting Solution:
You will e-mail me your homework solution.
Below is a sample of the information I want in your e-mail. It shows what the information would be for the example problem at the beginning of this document.
You must give me the same kind of information, in the same format,
for your assigned problem.
-------------------------------------------
# strt-fnsh w p OPT
1 10-13 6 0 6
2 12-14 7 0 7
3 11-16 8 0 8
4 17-20 10 3 18
5 15-23 5 2 18
6 19-24 4 3 18
7 22-25 5 4 23
8 21-27 8 4 26
Backtracking finds that intervals 8, 4, and 3
form an optimal solution, with total weight 26.
-------------------------------------------
- Prepare your solution to the problem, in the form indicated.
- COPY AND PASTE the text of your solution into an e-mail.
- DO NOT attach a file to your e-mail.
- DO copy and paste the text of your solution into the message window of the e-mail.
- DO Make the following exact text the subject line of your e-mail.
CS 4440 Weighted Intervals Problem
- DO copy the exact text above and & PASTE IT IN as the subject line of your e-mail
to make sure it is correct.
- Get it right, or get no credit!
- Send the E-mail to tester2@cs.csustan.edu