(Latest Revision:
Nov 07, 2021)
Solution to Weighted Intervals Problem
The Info You Had To E-Mail:
# start finish weight 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.
DETAILS SHOWING HOW TO DO THE PROBLEM
The Assigned Set of Intervals and Weights:
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.
# 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 compute the OPT values from row 1 to row 8.
# s-f 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), w5+OPT(p(6))} = max {18, 4 + 8} = 18
7 22-25 5 4 23 = max {OPT(6), w5+OPT(p(7))} = max {18, 5 + 18} = 23
8 21-27 8 4 26 = max {OPT(7), w5+OPT(p(8))} = max {23, 8 + 18} = 26
Then we do the backtracking.
OPT(8) > OPT(7), so we need interval 8, and we resume backtracking at p(8), which is interval 4
OPT(4) > OPT(3), so we need interval 4, and we resume backtracking at p(4), which is interval 3
OPT(3) > OPT(2), so we need interval 3, and we resume backtracking at p(3), which is interval 0, (but 0 means stop).
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. However interval j is not needed for an optimal solution, and probably the easiest thing to do is resume backtracking at row j-1. You will always find an optimal solution this way.