0% found this document useful (0 votes)
36 views18 pages

14 Job Sequencing With Dead Lnes

The document describes the job sequencing with deadlines problem and provides an algorithm to solve it greedily. It aims to maximize total profit by sequencing jobs that can each be completed by their individual deadlines on a single processor. The greedy algorithm sorts jobs by decreasing profit and schedules each next job as late as possible while respecting deadlines. An example is provided and solved step-by-step to illustrate the algorithm.

Uploaded by

the477577
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views18 pages

14 Job Sequencing With Dead Lnes

The document describes the job sequencing with deadlines problem and provides an algorithm to solve it greedily. It aims to maximize total profit by sequencing jobs that can each be completed by their individual deadlines on a single processor. The greedy algorithm sorts jobs by decreasing profit and schedules each next job as late as possible while respecting deadlines. An example is provided and solved step-by-step to illustrate the algorithm.

Uploaded by

the477577
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Design and Analysis of Algorithms

Job Sequencing with Deadlines

1
Job Sequencing with Deadlines

You are given a set of jobs.


Each job has a defined deadline and some profit associated with it.
The profit of a job is given only when that job is completed within its deadline.
Only one processor is available for processing all the jobs.
Processor takes one unit of time to complete a job.

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.

• We place the job on Gantt chart as far as possible from 0.


6
Step-3: We take job J4. Since its deadline is 2, so we place it in the first empty cell
before deadline 2 as

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.

The optimal schedule is-

J2, J4, J3, J5, J1

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

= 180 + 300 + 190 + 120 + 200

= 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 iJ 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;
}

Time taken by this algorithm is o(n2)


Example 2:
Let n =5 , (P1,P2,P3,P4,P5)= (20,15,10,5,1) and (d1,d2,d3,d4,d5) = (2,2,1,3,3).

Solution:
J Assigned Slots Jobs Considered Action Profit

Ø None 1 Assigned to 0
[1,2]
{1} [1,2] 2 [0,1] 20

{1,2} [0,1], [1,2] 3 Can’t fit, Reject 35

{1,2} [0,1], [1,2] 4 Assigned[2,3] 35

{1,2,4} [0,1], [1,2], 5 Reject 40


[2,3]

The optimal solution is J = {1,2,4} with a profit of 40.


Example 3:
Let n =7 , (P1,P2,P3,P4,P5 ,P6,P7)= (3,5,20,18,1,6,30) and
(d1,d2,d3,d4,d5,d6,d7) = (1,3,4,3,2,1,2).

Solution:
J Assigned Slots Jobs Considered Action Profit

Ø None

The optimal solution is J = { } with a profit of .


Thank You

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy