14 Job Sequencing With Dead Lnes
14 Job Sequencing With Dead Lnes
1
Job Sequencing with Deadlines
The problem states- “How can the total profit be maximized if only one job can
be completed at a time?”
2
Greedy Algorithm
Greedy Algorithm is adopted to determine how the next job is selected for an
optimal solution.
The greedy algorithm described below always gives an optimal solution to the
job sequencing problem-
Step-1: Sort all the given jobs in decreasing order of their profit.
Step-2: Check the value of maximum deadline.
Draw a Gantt chart where maximum time on Gantt chart is the value of
maximum deadline.
Step-3: Pick up the jobs one by one.
Put the job on Gantt chart as far as possible from 0 ensuring that the job gets
completed before its deadline.
3
Example
4
Step-1: Sort all the given jobs in decreasing order of their profit
5
Step-2: Value of maximum deadline = 5.
So, draw a Gantt chart with maximum time on Gantt chart = 5 units as shown-
Now,
• We take each job one by one in the order they appear in Step-01.
Step-4: We take job J1. Since its deadline is 5, so we place it in the first empty cell
before deadline 5 as-
7
Step-5: We take job J3. Since its deadline is 3, so we place it in the first empty cell
before deadline 3 as-
Step-6: We take job J2. Since its deadline is 3, so we place it in the first empty cell
before deadline 3. Since the second and third cells are already filled, so we place job
J2 in the first cell as-
8
Step-7: Now, we take job J5. Since its deadline is 4, so we place it in the first empty cell before
deadline 4 as-
The only job left is job J6 whose deadline is 2. All the slots before deadline 2 are already
occupied. Thus, job J6 cannot be completed.
This is the required order in which the jobs must be completed in order to obtain the
maximum profit.
9
Maximum earned profit = Sum of profit of all the jobs in optimal schedule
= Profit of job J2 + Profit of job J4 + Profit of job J3 + Profit of job J5 + Profit of job J1
= 990 units
10
Job Sequencing with Deadlines
We are given a set of n jobs.
Deadline di >= 0 and a profit pi >0 are associated with each job i.
For any job profit is earned if and only if the job is completed by its
deadline.
To complete a job, a job has to be processed by a machine for one
unit of time. Only one machine is available for processing jobs.
A feasible solution of this problem is a subset of jobs such that each
job in this subset can be completed by its deadline
The value of feasible solution J is the sum of the profits of the jobs in
J , or iJ Pi
The optimal solution is a feasible solution which will maximize the
total profit.
The objective is to find an order of processing of jobs which will
maximize the total profit.
Example 1: n = 4, (p1, p2, p3, p4) = (100,10,15,27)
(d 1, d2, d3, d4) = (2, 1, 2, 1)
The maximum deadline is 2 units, hence the feasible solution set must have <=2 jobs.
Feasible solution Processing sequence value
1 (1,2) 2,1 110
2 (1,3) 1,3 or 3, 1 115
3 (1,4) 4, 1 127
4 (2,3) 2, 3 25
5 (3,4) 4,3 42
6 (1) 1 100
7 (2) 2 10
8 (3) 3 15
9 (4) 4 27
Solution 3 is optimal.
High level description of jobs sequencing algorithm :
Algorithm GreedyJob(d, j, n)
// J is a set of jobs that can be completed by their deadlines
{
j : = {1};
for i := 2 to n do
{
if (all jobs in J U {i} can be completed by their deadlines) then
j := j U {i};
}
}
Algorithm JS(d, j, n)
// d[i] ≥ 1, 1 ≤ i ≤ n are the deadlines, n ≥ 1.
// The jobs are ordered such that p[1] ≥ p[2] …… ≥ p[n]
// j[i] is the ith job in the optimal solution, 1 ≤ i ≤ k , at //termination d [ j[i]] ≤
d[j[i+1]], 1 ≤ i ≤ k
{
d[0] := j[0] := 0; // Initialize
j[1] := 1; // Include job 1
k := 1;
for i := 2 to n do
{ //Consider jobs in Descending order of p[i].
// Find position for i and check feasibility of insertion.
r := k;
while( ( d[ j[r]]> d[i] and ( d[j[r]] ≠ r )) do
r := r - 1;
if( d[i] > r )) then
{
// Insert i into j[].
for q = k to (r+1) step -1 do j[q+1] = j[q];
j[r+1] := i;
k:=k+1;
}
}
return k;
}
Solution:
J Assigned Slots Jobs Considered Action Profit
Ø None 1 Assigned to 0
[1,2]
{1} [1,2] 2 [0,1] 20
Solution:
J Assigned Slots Jobs Considered Action Profit
Ø None