(Latest Revision: Nov 20, 2022)

Solution to Weighted Intervals Problem



The Info You Had To E-Mail:
#   strt-fnsh   w   p   OPT
1     11-14     7   0    7
2     12-15     5   0    7
3     10-18     9   0    9
4     16-20    10   2   17
5     17-21     6   2   17
6     19-23     6   3   17
7     22-28    10   5   27
8     26-29     8   6   27

Backtracking finds that intervals 7, 4, and 1  
form an optimal solution, with total weight 27. 

DETAILS SHOWING HOW TO DO THE PROBLEM


The Assigned Set of Intervals and Weights:
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
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   28   29
1  11      14        7              --------------- p=0
2  12      15        5                   --------------- p=0
3  10      18        9         ---------------------------------------- p=0
4  16      20       10                                       -------------------- p=2
5  17      21        6                                            -------------------- p=2
6  19      23        6                                                      -------------------- p=3
7  22      28       10                                                                     ------------------------------ p=5
8  26      29        8                                                                                         --------------- p=6
We then compute the OPT values from row 1 to row 8.
#   strt-fnsh   w   p   OPT
0      0-0      0   0    0
1     11-14     7   0    7  = max {OPT(0), w1+OPT(p(1))} = max {  0,  7 +  0} =  7
2     12-15     5   0    7  = max {OPT(1), w2+OPT(p(2))} = max {  7,  5 +  0} =  7
3     10-18     9   0    9  = max {OPT(2), w3+OPT(p(3))} = max {  7,  9 +  0} =  9
4     16-20    10   2   17  = max {OPT(3), w4+OPT(p(4))} = max {  9, 10 +  7} = 17
5     17-21     6   2   17  = max {OPT(4), w5+OPT(p(5))} = max { 17,  6 +  7} = 17
6     19-23     6   3   17  = max {OPT(5), w6+OPT(p(6))} = max { 17,  6 +  9} = 17
7     22-28    10   5   27  = max {OPT(6), w7+OPT(p(7))} = max { 17, 10 + 17} = 27
8     26-29     8   6   27  = max {OPT(7), w8+OPT(p(8))} = max { 27,  8 + 17} = 27
Then we do the backtracking. Thus the solution set is now {7,4,1}. Checking the weights we see that w7+w4+w1 = 10+10+7=27 = the computed value of OPT(8).

Note: As has been mentioned elsewhere, generally, when backtracking, if OPT(j) = OPT(j-1), it may or may not be possible to find an optimal solution that contains interval j. However interval j is certainly not needed for an optimal solution, and it's easier just to resume backtracking at row j-1. We will always find an optimal solution this way.