0

I'm trying to create a dynamic programming algorithm to a job scheduling problem. I have a set of n jobs, with each job i having a start time s(i) and finish time f(i). Start is always before finish, and you can have two jobs at the same time. How would I go about creating an algorithm to maximize the amount of time the resource is busy?

2
  • invert the cost-function. Commented Oct 29, 2017 at 23:28
  • @wildplasser Sorry but what does that mean? Commented Oct 30, 2017 at 0:17

1 Answer 1

1

You have to decide on what state to keep track of at each point. One option would be to keep track of the finish times of the currently running jobs, in which case you could compute the maximum possible busy time roughly as follows.

Create a map from a set of finish times to busy time so far. Initialize it to {null set} -> 0.

For each job in increasing order of start time:

  1. Create a new map and insert into it all of the entries from the old map which have both finish times greater than the current start time.
  2. For each remaining entry in the old map remove from the set of finish times those that are less than or equal to the start time of the current job. If the new map does not have an entry for that set of finish times, or if the value associated with the entry in the old map is greater than the value in the new map for that set, insert the resulting entry into the new map. Now insert the finish time for the current job into the set and add to its value the time taken by the new job. If the new map does not have an entry for the resulting set of finish times, or if that entry has a lower value than the value just calculated, add an entry for that set and value to the new map.
  3. The new map becomes the old map

At the end the largest value in the map is the largest possible busy time. If you keep backtracking information I haven't mentioned, you can trace back to find out what the selection of jobs was.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.