Scheduling with Deadline

27 Aug, 2021
Prerequisite : CPU Scheduling 
What is Scheduling with Deadline ?The goal of a Scheduling problem is to schedule the tasks such that the maximum total profit is obtained. This algorithm for scheduling with a deadline is different from scheduling without a deadline because task completion here is associated with profit. In order to make a profit, the jobs have lets to be completed before the deadline. Otherwise, the job completion does not count or earn profit at all. The objective of this problem is to construct a feasible sequence that gives the maximum profit.
A sequence is feasible if all the jobs end by their deadline. A set of jobs is called a feasible set if at least one sequence is possible. The sequence that is associated with the maximum profit is called the optimal sequence and the elements that constitute the sequence comprise the optimal set of jobs.
Example –Consider the items and profit shown in the following table and let’s find the optimal set of jobs that can be scheduled so that the profit is maximized.
The table depicts jobs with deadline and the profit
The objective of the given problem is to find a feasible set of solutions. Let us apply the greedy approach.
Initially solution = NULL, then job 1 is added, so solution = {1}. It can be observed that job 2 is possible when added as task {2, 1} but not possible when added as a task {1,2}. Why?  Let’s check for that situation,
Consider the sequence {1,2}. Scheduling of task 1 is possible. However, scheduling task 2 is not possible as its deadline is just 1 unit, which is already spent in waiting time. On the other hand {2,1,} is feasible as the deadline of job 2 is not violated and that of job 1 is 2 units. Therefore, after job 2 is processed, job 1 can very well be accommodated. Similarly, one can observe that scheduling of job sequences {1,4}, {2,4}, {3,4}, {1,2,3},{2,3,4} and {1,2,3,4} are not possible.
All possible sequences are –
The maximum profit is associated with the sequence {4,1}. Therefore, the optimal order is {4,1}. One can also observe that while {4,1} is optimal, the sequence {1,4} is not possible as deadline conditions are violated.
Algorithm :
Step1: Sort the jobs in a non-increasing order by profit
Step2: Solution = null
Step3: For all the task do the following:
        select the next job;
        if task is feasible (i.e, the task deadline is not violated) then add this job to the solution
        EEND if
Step4: If all the instances are solved then exit.
Formally, the algorithm for a scheduling problem with a deadline is as follows :
Algorithm Schedule_with_deadline
%%Input: A set of jobs 1 to n with service item
%%Output: An optimal schedule

Begin
    s= sorted array of jobs based on profit in non-decreasing order
    i=1
    schedule=NULL
    while(i <= n) do                        %%for all jobs do
        select the next job i from S        %% selection procedure
        if(Scheduling job is feasible) then    %%Feasibility check
        solution = schedule U job i of S
        i=i+1
    End while
    return(solution)
End
It can be observed that this algorithm first sorts the jobs based on profit, and then selects the jobs one by one for scheduling if the deadline considerations are not violated. This process is repeated for all the jobs, and finally, algorithms return the solution.
There is a principle that exists to check the feasibility of job sequences, this principle states that the sequence of jobs is feasible if its scheduling according to non-decreasing deadlines is feasible.
Therefore, a sequence{1,2,3} is feasible as the jobs are scheduled based on non-decreasing deadlines.
On the other hand, the sequence {1,2,3,4} is not feasible.
The reason is that though there are 4 jobs, this sequence implies that all the jobs should be completed before 3-time units.
As each job takes at least 1-time unit, the sequence is not feasible. Thus one can check the feasibility of the scheduling of jobs using this observation as this is time-saving during competitive exams.
simmytarika5
gabaa406
Operating Systems
Operating Systems
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
File Allocation Methods
Memory Management in Operating System
Logical and Physical Address in Operating System
Segmentation in Operating System
Structures of Directory in Operating System
Process Table and Process Control Block (PCB)
Memory Hierarchy Design and its Characteristics
Difference between Internal and External fragmentation
Process Schedulers in Operating System
File Access Methods in Operating System