Job scheduling

11
Job Scheduling Sanjay Singh Devis Karumanchi Durgesh Waghmare Litun Patra

Transcript of Job scheduling

Page 1: Job scheduling

Job Scheduling

Sanjay SinghDevis Karumanchi

Durgesh WaghmareLitun Patra

Page 2: Job scheduling

Problem statementConsider the following variation on the Interval Scheduling Problem. You

have a processor that can operate 24 hours a day, every day. People submit requests to run daily jobs on the processor. Each such job comes with a start time and an end time; if the job is accepted to run on the processor, it must run continuously, every day, for the period between its start and end times. Given a list of n such jobs, your goal is to accept as many jobs as possible (regardless of their length), subject to the constraint that the processor can run at most one job at any given point in time. Provide an algorithm to do this with a running time that is polynomial in n. You may assume for simplicity that no two jobs have the same start or end times. Example. Consider the following four jobs, specified by (start time, end-time) pairs. (6 P.M., 6 A.M.), (9 P.M., 4 A.M.), (3 A.M., 2 P.M.), (1 P.M., 7 P.M.). The optimal solution would be to pick the two jobs (9 P.M., 4 A.M.) and (1P.M., 7 P.M.), which can be scheduled without overlapping.

Page 3: Job scheduling

Greedy paradigm

Two important componentsBuilds up the solution in small stepsChoose a decision myopicallyTo optimize some underlying criterion

Choose what is best for the momentTypically works in stages

A decision made in one stage can not be changed laterThe choice must lead to the feasible solution

Expected to be an optimal solution

Page 4: Job scheduling

Activity selection problem

Selecting maximal set of mutually compatible activitiesSimple and elegant method

Mutually compatible activities If each activity i occurs during the half open interval [s i, fi)When do [si, fi) and [sj, fj) not overlap? i < j or j < i

Page 5: Job scheduling

Problem definition

Job schedulingJob j starts at sj and finishes at fj

Two jobs i and j are compatible if they do not overlapGoal: Find maximum subset of mutually compatible jobs.

Page 6: Job scheduling

Illustration

Page 7: Job scheduling

Interval Scheduling

Greedy template. Consider jobs in some order. Take each job provided it's compatible with the ones already taken.

- [Earliest start time] Consider jobs in ascending order of start time sj.

- [Earliest finish time] Consider jobs in ascending order of finish time fj.

- [Shortest interval] Consider jobs in ascending order of interval length fj – sj.

- [Fewest conflicts] For each job, count the number of conflicting jobs cj. Schedule in ascending order of conflicts cj. `

Page 8: Job scheduling

The strategies that fail

“Earliest start time” fails

“Shortest interval” fails

“Fewer conflict strategy” fails

Page 9: Job scheduling

SolutionGreedy algorithm

Consider jobs in increasing order of finish time.Take each job provided it is compatible with the ones already

taken.

Page 10: Job scheduling

Time complexity

Sorting the jobs in increasing order of their finish times takes O(n log n) time

Consider the job with the earliest finish time and thereon include the jobs into the solution set that are compatible with the preceding one. This takes O(n) time

So the total running time comes out to be O(n log n)

Page 11: Job scheduling

Thank you