Open In App

Scheduling with Deadline

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

JOB DEADLINE PROFIT(₨)
1 2 60
2 1 30
3 2 40
4 1 80

The objective of the given problem is to find a feasible set of solutions. Let us apply the greedy approach.

All possible sequences are –

job sequence total profit
2, 1 90
3, 1 or 1, 3 100
2, 3 70
4, 1 140
4, 3 120

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.

Article Tags :