0% found this document useful (0 votes)
5K views24 pages

Job Sequencing With Deadlines: The Problem Is Stated As Below

The document describes the job sequencing problem with deadlines and profits. It introduces a greedy algorithm that sorts jobs by decreasing profit and sequentially adds jobs to the sequence if their deadline is met. The algorithm runs in O(n^2) time and finds an optimal solution. It provides an example showing the steps of applying the greedy approach.

Uploaded by

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

Job Sequencing With Deadlines: The Problem Is Stated As Below

The document describes the job sequencing problem with deadlines and profits. It introduces a greedy algorithm that sorts jobs by decreasing profit and sequentially adds jobs to the sequence if their deadline is met. The algorithm runs in O(n^2) time and finds an optimal solution. It provides an example showing the steps of applying the greedy approach.

Uploaded by

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

JOB SEQUENCING WITH

DEADLINES
The problem is stated as below.
• There are n jobs to be processed on a machine.
• Each job i has a deadline di≥ 0 and profit pi≥0 .
• Pi is earned if the job is completed by its deadline.
• The job is completed if it is processed on a machine
for unit time.
• Only one machine is available for processing jobs.
• Only one job is processed at a time on the machine.
1
JOB SEQUENCING WITH
DEADLINES (Contd..)
• A feasible solution is a subset of jobs J such that
each job is completed by its deadline.
• An optimal solution is a feasible solution with
maximum profit value.
Example : Let n = 4, (p1,p2,p3,p4) = (100,10,15,27),
(d1,d2,d3,d4) = (2,1,2,1)

2
JOB SEQUENCING WITH
DEADLINES (Contd..)
Sr.No. Feasible Processing Profit value
Solution Sequence
(i) (1,2) (2,1) 110
(ii) (1,3) (1,3) or (3,1) 115
(iii) (1,4) (4,1) 127 is the optimal one
(iv) (2,3) (2,3) 25
(v) (3,4) (4,3) 42
(vi) (1) (1) 100
(vii) (2) (2) 10
(viii) (3) (3) 15
(ix) (4) (4) 27

3
GREEDY ALGORITHM TO
OBTAIN AN OPTIMAL SOLUTION
• Consider the jobs in the non increasing order
of profits subject to the constraint that the
resulting job sequence J is a feasible
solution.
• In the example considered before, the non-
increasing profit vector is
(100 27 15 10) (2 1 2 1)
p1 p4 p3 p2 d1 d4 d3 d2
4
GREEDY ALGORITHM TO OBTAIN AN
OPTIMAL SOLUTION (Contd..)

J = { 1} is a feasible one
J = { 1, 4} is a feasible one with processing
sequence ( 4,1)
J = { 1, 3, 4} is not feasible
J = { 1, 2, 4} is not feasible
J = { 1, 4} is optimal

5
GREEDY ALGORITHM TO OBTAIN AN
OPTIMAL SOLUTION (Contd..)

Theorem: Let J be a set of K jobs and


 = (i1,i2,….ik) be a permutation of jobs in J
such that di1 ≤ di2 ≤…≤ dik.
• J is a feasible solution if the jobs in J can be
processed in the order  without violating
any deadly.

6
GREEDY ALGORITHM TO OBTAIN AN
OPTIMAL SOLUTION (Contd..)

Theorem: Let J be a set of K jobs and


 = (i1,i2,….ik) be a permutation of jobs in J
such that di1 ≤ di2 ≤…≤ dik.
• J is a feasible solution if the jobs in J can be
processed in the order  without violating
any deadly.

7
GREEDY ALGORITHM TO OBTAIN AN
OPTIMAL SOLUTION
Job Sequencing with Deadline Approach
• Sort all the jobs in decreasing order of profit
• Initiative the result sequence as first job in
sorted jobs
• Do following for remaining (n-1) jobs.
If the current job can fit in the current result
sequence without missing the deadline,
add current job to the result
else ignore the current job
8
Example:For the following sequence of jobs give the
optimal solution which will achieve maximum profit.
Job J1 J2 J3 J4 J5 J6 J7
profit 3 5 20 15 2 6 30
deadline 1 3 4 3 2 1 2

Solution:
Step 1: Sort the jobs according to profit value
Job J7 J3 J4 J6 J2 J1 J5
profit 30 20 15 6 5 3 2
deadline 2 4 3 1 3 1 2

Step 2: Select maximum deadline


9
Step 2: Select maximum deadline

0 1 2 3 4

Step 3: Select job according to profit value

J7
0 1 2 3 4

J7 J3
0 1 2 3 4
10
Step 3: Select job according to profit value

J7
0 1 2 3 4
J7 J3
0 1 2 3 4
J7 J4 J3
0 1 2 3 4

J6 J7 J4 J3
0 1 2 3 4

11
Step 4: Now calculate the total profit and job sequence

J6 J7 J4 J3
0 1 2 3 4

Job Sequence is : J6 ---> J7---->J4----->J3


Total Profit is: 6+30+15+20=71

12
Example: For the following sequence unit time jobs
with deadline and profit. Using the Greedy approach
find the optimal solution with n=5. (Dec 2016)

Job P1 P2 P3 P4 P5
Profit 20 15 10 5 1
Deadline 2 2 1 3 3

Example: For the following sequence unit time jobs


with deadline and profit. Using the Greedy approach
find the optimal solution with n=6.
Job J1 J2 J3 J4 J5 J6
Profit 10 7 15 3 20 5
Deadline 1 3 1 3 3 1
13
Select maximum deadline

0 1 2 3

Arrange the job in non increasing order by profit value

Job J1 J2 J3 J4 J5
Profit 20 15 10 5 1
Deadline 2 2 1 3 3

14
Select job P1=20 and D =2

P1
0 1 2 3

Next job is P2=15 & D=2 but deadline 2 is already filled by P1

P2 P1 P4
0 1 2 3

We get optimal sequence P2-P1-P4 & Maximum


Profit will be 40
15
Example: For the following sequence unit time jobs
with deadline and profit. Using the Greedy approach
find the optimal solution with n=5. (Nov 2018)

Job P1 P2 P3 P4 P5
Profit 60 100 20 40 20
Deadline 2 1 3 2 1

16
Example: Using the Greedy approach find the optimal
solution for following jobs with deadline and profit.
N=7
Profit (P1..P7) = (3,5,18,20,6,1,38)
Deadline (d1...d7) = (1,3,3,4,1,2,1)

17
JS(D,J,n,dmax)
Algorithm
int k,TS[dmax];
for(i=1;i<n;i++)
TS[i]=0;
for(i=1;i<n;i++)
{ K=min(dmax,D[i])
if(TS[k]==0) then
TS[k]=J[i];
}

18
GREEDY ALGORITHM FOR JOB
SEQUENSING WITH DEADLINE
Procedure greedy job (D, J, n) J may be represented by
// J is the set of n jobs to be completed// one dimensional array J (1: K)
// by their deadlines // The deadlines are
J {1} D (J(1))  D(J(2))  ..  D(J(K))
for I  2 to n do To test if JU {i} is feasible,
If all jobs in JU{i} can be completed we insert i into J and verify
by their deadlines D(J)  r 1  r  k+1
then J  JU{I}
end if
repeat
end greedy-job

19
GREEDY ALGORITHM FOR
SEQUENCING UNIT TIME JOBS
Procedure JS(D,J,n,k)
// D(i)  1, 1 i  n are the deadlines //
// the jobs are ordered such that //
// p1  p2  …….  pn //
// in the optimal solution ,D(J(i)  D(J(i+1)) //
// 1  i  k //
integer D(o:n), J(o:n), i, k, n, r
D(0) J(0)  0
// J(0) is a fictious job with D(0) = 0 //
K1; J(1) 1 // job one is inserted into J //
for i 2 to do // consider jobs in non increasing order of pi //
20
GREEDY ALGORITHM FOR
SEQUENCING UNIT TIME JOBS (Contd..)
// find the position of i and check feasibility of insertion //
r k // r and k are indices for existing job in J //
// find r such that i can be inserted after r //
while D(J(r)) > D(i) and D(i) ≠ r do
// job r can be processed after i and //
// deadline of job r is not exactly r //
r r-1 // consider whether job r-1 can be processed after i //
repeat

21
GREEDY ALGORITHM FOR
SEQUENCING UNIT TIME JOBS (Contd..)

if D(J(r))  d(i) and D(i) > r then


// the new job i can come after existing job r;
insert i into J at position r+1 //
for I  k to r+1 by –1 do
J(I+1) J(l) // shift jobs( r+1) to k right by//
//one position //
repeat
22
GREEDY ALGORITHM FOR
SEQUENCING UNIT TIME JOBS (Contd..)
J(r+1)i ; k k+1
// i is inserted at position r+1 //
// and total jobs in J are increased by one //
repeat
end JS

23
COMPLEXITY ANALYSIS
OF JS ALGORITHM
• Let n be the number of jobs and s be the number of
jobs included in the solution.
• The loop between lines 4-15 (the for-loop) is
iterated (n-1)times.
• Each iteration takes O(k) where k is the number of
existing jobs.
The time needed by the algorithm is 0(sn) s  n so
the worst case time is 0(n2).
If di = n - i+1 1  i  n, JS takes θ(n2) time
D and J need θ(s) amount of space.
24

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