(Latest Revision: May 12, 2019)

Solution to Weighted Intervals Problem


YOUR ASSIGNED PROBLEM:

start   finish   weight
 13       15       2
 11       13       4
 13       16       2
 14       17       6
 10       13       6
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
1  11       13       4               -------------- p=0
2  10       13       6        --------------------- p=0
3  13       15       2                             -------------- p=2
4  13       16       2                             --------------------- p=2
5  14       17       6                                    --------------------- p=2
We then compute the OPT values from row 1 to row 5.
#   s-f    w    p   OPT
0   0-0    0    0    0
1  11-13   4    0    4   = max {OPT(0), w1+OPT(p(1))} = max {0, 4+0} = 4
2  10-13   6    0    6   = max {OPT(1), w2+OPT(p(2))} = max {4, 6+0} = 6
3  13-15   2    2    8   = max {OPT(2), w3+OPT(p(3))} = max {6, 2+6} = 8
4  13-16   2    2    8   = max {OPT(3), w4+OPT(p(4))} = max {8, 2+6} = 8
5  14-17   6    2   12   = max {OPT(4), w5+OPT(p(5))} = max {8, 6+6} = 12
Backtracking: OPT(5) > OPT(4), so we need interval 5, and we resume backtracking at p(5), which is interval 2

OPT(2) > OPT(1), so we need interval 2, and we resume backtracking at p(2), 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.