DynamicProgrammingActivity - and j = 1 do if j i f s then...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Dynamic Programming Solution to Maximize the Number of Activities Selected DYNAMIC_ACTIVITY_SELECTOR ( s,f ) /* Assume that s contains start times and f contains finish times */ /* Assume that activities have been presorted by nondecreasing finish time */ /* Assume that there are n activities. */ } 0 { 0 / M for i =1 to n /* Build M i and m i */ /* M i will be the list of compatibility sets for activities 1…i */ /* m i will be the largest size of a compatibility set in M i */ /* M n and m n will provide the optimal solution(s) to the overall problem*/ do 1 i i M M 1 i j FALSE FOUND After executing this loop, j will be the largest activity number < i that is compatible with activity i. Note that all activities < j are automatically compatible with i due to presorting by finish time. while FALSE FOUND
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: and j = 1 do if j i f s then TRUE FOUND else 1 j j for each set j M s i M starts off as . 1 i M If the i th activity can improve the solution, it does so by joining a set of activities with which it is compatible. Activities compatible with activity i are exactly those in . For this reason, we add i to each set in and add the result to . Note that, to avoid duplicating sets, we first remove from each set that is in .) j M j M i M i M j M do /* where \ is set difference operator */ } { \ s M M i i }} { { i s M M i i i M s i s m | | max Each represents a subproblem. To solve it, we use history in two ways: we use to initialize and we use to update . i M M 1 i M i M j i M...
View Full Document

This note was uploaded on 02/13/2012 for the course CS 91.503 taught by Professor Staff during the Spring '11 term at UMass Lowell.

Ask a homework question - tutors are online