(Latest Revision: Mar 30, 2021)

Solution to Weighted Intervals Problem



The Info You Had To E-Mail:
#   start    finish    weight    P    OPT
1    10        13        5       0     5
2    12        14        4       0     5
3    11        15        7       0     7
4    14        19        8       2    13
5    16        21       10       3    17
6    20        23        6       4    19
7    18        24        8       3    19
8    22        25        5       5    22

Backtracking finds that intervals 8, 5, and 3  
form an optimal solution, with total weight 22. 

DETAILS SHOWING HOW TO DO THE PROBLEM


The Assigned Set of Intervals and Weights:
start   finish   weight
  11      15       7
  16      21      10
  12      14       4
  20      23       6
  10      13       5
  18      24       8
  14      19       8
  22      25       5
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
1  10       13       5        --------------------- p=0
2  12       14       4                      -------------- p=0
3  11       15       7               ---------------------------- p=0
4  14       19       8                                    ---------------------------------- p=2
5  16       21      10                                                  ----------------------------------- p=3
6  20       23       6                                                                              --------------------- p=4
7  18       24       8                                                                ------------------------------------------ p=3
8  22       25       5                                                                                            --------------------- p=5
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   5    0    5   = max {OPT(0), w1+OPT(p(1))} = max { 0,  5 +  0} =  5
2  12-14   4    0    5   = max {OPT(1), w2+OPT(p(2))} = max { 5,  4 +  0} =  5
3  11-15   7    0    7   = max {OPT(2), w3+OPT(p(3))} = max { 5,  7 +  0} =  7
4  14-19   8    2   13   = max {OPT(3), w4+OPT(p(4))} = max { 7,  8 +  5} = 13
5  16-21  10    3   17   = max {OPT(4), w5+OPT(p(5))} = max {13, 10 +  7} = 17
6  20-23   6    4   19   = max {OPT(5), w5+OPT(p(6))} = max {17,  6 + 13} = 19
7  18-24   8    3   19   = max {OPT(6), w5+OPT(p(7))} = max {19,  8 +  7} = 19
8  22-25   5    5   22   = max {OPT(7), w5+OPT(p(8))} = max {19,  5 + 17} = 22
Then we do the backtracking.

OPT(8) > OPT(7), so we need interval 8, and we resume backtracking at p(8), which is interval 5
OPT(5) > OPT(4), so we need interval 5, and we resume backtracking at p(5), 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.