Scheduling Jobs in Parallel Machines To Minimise Total Tardiness

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 44

Our problem: Scheduling jobs in parallel machines to minimise total tardiness

1. Introduction:

This project considers the problem of scheduling a given number of jobs on a


specified number of identical parallel machines to minimize total tardiness. As
the single machine total tardiness problem is strongly NP-hard, (Du and Leung,
1990), it follows that the parallel-machine total tardiness problem is strongly
NP-hard, too (Pfund et al., 2004). Consequently, large instances of the problem
should be attacked by means of heuristic approaches to obtain near optimal
solutions. We will designate this problem as the pll∑Ti problem where P
designates that it is an identical parallel-machine problem, Ti is the tardiness of
job i and ∑Ti indicates that it is desired to minimise total tardiness. The earliest
available heuristic algorithm for solving the pll∑Ti problem is to order the jobs
according to the earliest due date (EDD) rule and assign them to the machines
afterwards. If a job can be finished on time it is assigned to the machine such
that it is completed as closely to its due date as possible. If the job will be late,
it is assigned to the machine with the lowest workload. Dogramaci and Surkis
(1979) apply three different priority rules, namely EDD, shortest processing
time (SPT) and minimum slack. For each of these initial sequences they
proceed as follows: among the jobs that have not yet been assigned to a
machine take the first job, assign it to the machine with the smallest actual
workload and remove it from the list of unscheduled jobs. This step is repeated
until all jobs have been assigned to a machine. In the last step, the machines
are considered individually and m single machine total tardiness problems are
solved. However, since the single machine problem is NP-hard, this procedure
is only good for relatively small instances.

Application:

 In the beverage industry, where jobs need to be scheduled on parallel


bottling machines. Jobs are, for example, beer orders from restaurants,
pubs, and wholesalers. Meeting the due dates is important, because it is
advantageous for the wholesaler, retailer or local pub not to run out of
beer.
 print jobs (like books) are scheduled on parallel presses and finishing
lines. Meeting due dates for orders placed by the different book
publishers is extremely important, too, as a publisher will loose revenues
if a special title (in the worst case the actual bestseller) is not available
on the shelves of the bookstores.
 The pharmaceutical industry usually runs parallel machines to produce
drugs. And they definitely want their blockbusters being available in the
drugstores. Even auditors can be seen as parallel machines that work on
the auditing jobs acquired by their partners

2. various algorithms proposed :

2.1 . Traffic priority index: Ho and Chang (1991) developed a traffic


priority index (TPI) that takes into consideration the congestion in the
shop, i.e. the overall tightness of the due dates. After sequencing the
jobs in ascending TPI values, they assign the jobs to the machines
according to the lowest workload rule. To describe this algorithm, define:

TCR avg(p)n/avg(d)m, where avg(p) and avg(d) are average


processing times and average due dates, respectively.

Md max1≤i≤n{di}

Mp max1≤i≤n{pi}

K constant factor (consistently to the study by Ho and Chang


(1991), we set K equal to 3).

Wd = max{min{0.5+(k-TCR)/TCR,1},0}

Wp = 1- Wd

Ri = (di*Wd/Md)+(Pi*Wp/Mp)

Then the steps of Ho and Chang’s TPI algorithm can be described as follows:

Algorithm TPI

Step 0: The jobs are indexed in ascending TPI values, i.e. , Ri≤Ri+1 for i=1 to
n-1. let U={1,2......n} be the number of unscheduled jobs.
Step 1: Take the job with the smallest index of the set U and insert it on the
first available machine. Remove the job from the set U.

Step 2: Repeat Step 1 until U is empty.

The heuristic presented above separates the tasks of assigning jobs to


machines and scheduling jobs on each machine. However, as stated earlier,
these two decisions in the Pll∑Ti problem are interrelated. Thus, the above
heuristic algorithm ignores the parallel nature of the Pll∑Ti problem.
To consider the interdependence of the two interrelated decisions, Alidaee and
Rosa (1997) use the well known modified due date (MDD) rule of Baker and
Bertrand (1982). They extend the MDD rule for the parallel-machine case as
described in the following algorithm.

2.2. Algorithm MDD:


Step 0: Generate an arbitrary list of the unscheduled jobs U={1......n}.
Step 1: Let Cj for j = {1, . . . ,m} be the sum of processing times of the jobs that
have already been scheduled on machine j. Divide U into U j1 and Uj2 for j={1,
. . . ,m} such that

Uj1= {i € U : Cj + pi > di} and


Uj2=U-Uj2

Step 2: For each machine j =1, . . . ,m find two sets γj and λj of jobs such that
γj ={i€Uj1:Pi=mink€Uj1{Pk}}
λj={i€Uj2:Di=mink€Uj1{Dk}}

Step 3: Let aj be any job from γj and bj any job from the set λj. Choose job gj€
{aj,bj} , for the schedule that satisfies
δgj=min(Cj + paj , dbj) j=1....,m
Schedule the job gl , on the machine l such that δgl = min1≤j≤m{ δgj} and put job gl
in the last position of machine l. Remove job gl from set U.

Step 4: Repeat Steps 1–3 until U is empty.

2.3. BHG ALGORITHM:


This heuristic is proposed by biskup,herrmann and gupta.
The proposed heuristic approach for the Pll∑Ti problem proceeds as follows:
first the m jobs with the smallest index of a list of jobs are simultaneously
assigned to the machines. Generally speaking we use each combination among
the first m jobs from a predefined list as a first assignment. For m=2 we use the
following starting assignments:

 S1=(1),S2=(2)
 S1=(1,2),S2=(0)
For m= 3 we use
 S1=(1),S2=(2),S3=(3)
 S1=(1,2),S2=(3),S3=()
 S1=(1,3),S2=(2),S3=()
 S1=(2,3),S2=(1),S3=()
 S1=(1,2,3),S2=(),S3=()

The number of starting assignments depends upon m as follows:


A(m)=1+∑j=2m∑i=0max(0,m-j-1)Cjm-1

Algorithm BHG

Step 0: Given a list of all n jobs, generate all A(m) possible starting assignments:
sa1; sa2; . . . ; saA(m). Set k=1.

Step 1: Let U:=(m + 1, . . . , n) be the set of unscheduled jobs and sa k be the


actual schedule.

Step 2: Take the job with the smallest index of the set U and insert it optimally
into the actual schedule without altering the predecessor and successor
relations of the given sequences. The job is first inserted at the last position of
machine 1 and then at the first, second; . . . , penultimate position of machine
1. The same insertion strategy is applied for machine 2,3, . . . ,m afterwards. In
case of a tie, the algorithm chooses the sequences with the lowest total
tardiness which was calculated first. Remove the job from the set U.

Step 3: Repeat Step 2 until U is empty.


Step 4: Store solution (schedule and tardiness) of sak, k:= k+ 1. If k<A(m), return
to Step 1; otherwise choose the best of the A(m) solutions and terminate.

The implementation of BHG basic heuristic algorithm requires an initial list of


jobs. For this purpose, we considered the following three different starting lists.
1.The jobs are indexed according to the EDD rule, i.e. d i≤di+1 for i = 1, . . . , n-1. If
di=di+1 then pi≥pi+1.
2. The jobs are indexed according to the minimum slack rule, i.e. d i-pi≤di+1 – pi+1
for i = 1, . . . , n-1. If di-pi = di+1-pi+1 then di≤di+1. If di = di+1 then pi≥pi+1.
3. The jobs are indexed according to the TPI rule used in the TPI algorithm, i.e.
Ri≤Ri+1 for i = 1, . . . , n-1. If Ri=Ri+1, then di≤di+1. If di = di+1 then pi≥pi+1.

Using the above three lists results in three proposed heuristic algorithms
abbreviated as BHG-EDD, BHG-Sla and BHG-TPI.

Algorithm BHG-MDD
Step 0: Let the jobs be indexed according to the EDD rule, i.e. di≤di+1 for i = 1, .
. . , n-1. If di = di+1 thenpi≥pi+1. Using this list, generate all A(m) possible
starting assignments: sa1; sa2; . . . ; saA(m). Set k=1.

Step 1: Let U:=(m+1, . . . , n) be the set of unscheduled jobs and sa k be the


actual schedule.

Step 2: Perform Steps 2.1–Step 2.4 as follows.

Step 2.1: Let Cj for j = {1, . . . ,m} be the sum of processing times of the jobs that
have already been scheduled on machine j. Divide U into U j1 and Uj2 for j={1,
. . . ,m} such that

Uj1= {i € U : Cj + pi > di} and


Uj2=U-Uj1

Step 2.2: For each machine j =1, . . . ,m find two sets γj and λj of jobs such that
γj ={i€Uj1:Pi=mink€Uj1{Pk}}
λj={i€Uj2:Di=mink€Uj1{Dk}}

Step 2.3: Let aj be any job from γj and bj any job from the set λj. Choose job gj€
{aj,bj} , for the schedule that satisfies
δgj=min(Cj + paj , dbj) j=1....,m
Select the job gl, such that δgl = min1≤j≤m{ δgj} .

Step 2.4: Insert job gl optimally into the actual schedule without altering the
predecessor and successor relations of the given sequences. The job is first
inserted at the last position of machine 1 and then at the first, second, . . . ,
penultimate position of machine 1. The same insertion strategy is applied for
machine 2, 3, . . . ,m afterwards. In case of a tie, the algorithm chooses the
sequences with the lowest total tardiness which was calculated first.

Step 3: Remove job gl from set U. If set U is empty, proceed to Step 4;


otherwise return to Step 2.

Step 4: Store solution (schedule and tardiness) of sak, k:=k + 1. If k<A(m), return
to Step 1; otherwise choose the best of the A(m) solutions and terminate.

2.4. EXAMPLEles of each method

lets there are 2 identical machines.

Job Processing time Due date


1 10 24
2 20 29
3 14 41
4 16 31
5 25 46
6 15 41

algorithm TPI:
TCR = avg(p)n/avg(d)m,
Avg(p)=100/6=16.66
Avg(d)=212/6=35.33
Therefore ,
TCR = (16.66*6)/(35.33*2)
= 1.415
Md= 46
Mp= 25
K=3
Wd= max{min{0.5+(3-1.415)/1.415,1},0}
Wp=1-Wd=0
Hence,
R1=(24*1)/46, R2=(29*1)/46,...........
They are actually in the order of there due dates. the list ultimately reduces to
EDD. hence the list order we have got is

Unscheduled jobs U:={1,2,4,3,6,5}

Now, following the algorithm


1. Assign job-1 to any m/c lets say to machine 1.
2. Then the next job that is job-2 will be assigned to m/c-2.
3. Since the processing time of job-2 is 20 hence m/c-1 will be free prior
hence next job should be to m/c-1.
4. Similarly keep on doing this until U become empty.
Machine 1 Machine 2
Job 1 Job 2
Job 4 Job 3
Job 6 Job 5

Total penalty 13 units

Solution by algorithm MDD:


U:={1,2,3,4,5,6}
Following the algorithm for the same problem:
1. Initially for m/c-1 C1=0, for m/c-2 C2=0.
2. U11={},U12={1,2,3,4,5,6}
U21={},U22={1,2,3,4,5,6}
3. For m/c-1
γ1 ={} λ1={1}
for m/c-2
γ2 ={} λ2={1}

4. Aj={no job} Bj={1}


5.There is only one job and it is randomly selected to a m/c-1.
6.Now U:={2,3,4,5,6}
7.Again C1=10 and C2=0.
8.U11={2},U12={3,4,5,6}
U21={},U22={2,3,4,5,6}
9. For m/c-1
γ1 ={2} λ1={4}
for m/c-2
γ2 ={} λ2={4}
9. Aj={2} Bj={4}
10.Here δgj=min(Cj + paj , dbj) is min for m/c-2 and job-2.
11.Hence U :={3,4,5,6}
12.Similarly we will find that final solution is same as in TPI method.
13.
Machine 1 Machine 2
Job 1 Job 2
Job 4 Job 3
Job 6 Job 5

And total tardi is =13

Solution by algorithm BHG-EDD


1. Generate the list of jobs using EDD. it will be {1,2,4,3,6,5}
2. S1=(1),S2=(2)
S1=(1,2),S2=(0)
3. m/c-1 = (1) m/c-2 = (2)
m/c-1 = (1,2) m/c-2 = ()
4. Then next job we have job-4 calculate tardi in each case for step-3.
We find tardi in
 m/c-1=(1,4) m/c-2=(2) tardi=0
 m/c-1=(4,1) m/c-2=(2) tardi=2
 m/c-1=(1) m/c-2=(2,4) tardi=5
 m/c-1=(1) m/c-2=(4,2) tardi=7
 m/c-1=(1,2) m/c-2=(4) tardi =1
 m/c-1=(1,2,4) m/c-2=() tardi =16
 m/c-1=(1,4,2) m/c-2=() tardi =17
 m/c-1=(4,1,2) m/c-2=(4) tardi =19

5. next job will be job-3 doing again the same thing we will reach to the same answer as
above 2 methods give.
Machine 1 Machine 2
Job 1 Job 2
Job 4 Job 3
Job 6 Job 5

Algorithm proposed:
We have used algorithm of r.j chambers

Our objective :

1. To study the application of different heuristic approaches in parallel


machines to minimise total tardiness.
2. To identify different parameters in the problem .
3. To simulate all the algorithms including the proposed one(BHG-rj
alorithm) and compare the results ,with the results obtained in paper.

Modelling and simulation

Number of machines : m (all are identical)


Number of jobs : n {j 1,j2,j3............)
Processing time of job j : Pj
Due date of job j : Dj
Completion time of job “j”th : Cj (Cj=∑Pj )
job in the sequence
Objective is to find a sequence :∑Ti
to minimise

assumptions followed:

 linear congruent random number generator introduced by Lehmer


(1951) to generate the problem instances using two general seeds,
one for the generation of the processing times (3,794,612) and one
for the due dates (1,794,612).
 Problem hardness is likely to depend on the range of processing
times, number of jobs, number of machines, and the relative
tightness of the due dates. Therefore, the processing times produced
by the generator are of the interval [1, p max]with pmax €[10,99]. Due
date is always assumed to be greater than processing time.
 m={2,3,4,} and n={46,40,35,30,25,20}
 processing times and due dates are considered to be integer.
 Penalty is assumed to be constant for each job tardiness. hence not
considered in the role.
 Jobs are assumed to be static i.e all jobs are available for processing.

Simulation and comparison results

For no. of machines n=2

No. of TPI(traffic MDD(modified BHG- BHG- BHG-TPI BHG-RJ


jobs priority due date) EDD SLA
index)
46 7417 7334 7337 7338 7435
40 3581 3474 3511 3500 3595
35 4819 4766 4752 4757 4794
30 3180 3155 3167 3164 3186
25 1095 1014 1005 1018 1023
20 782 759 751 746 768
.

For no. of machines n=3

No. of TPI(traffic MDD(modified BHG- BHG- BHG-TPI BHG-RJ


jobs priority due date) EDD SLA
index)
46 5606 5480 5489 5498 5509
40 2423 2330 2343 2331 2370
35 1884 1830 1832 1832 1819
30 1853 1780 1799 1786 1806
25 347 315 322 323 374
20 622 620 610 600 606

For no.of machines n=4

No. of TPI(traffic MDD(modified BHG- BHG- BHG-TPI BHG-RJ


jobs priority due date) EDD SLA
index)
46 2243 2076 1685 2150 2144
40 2717 2610 2353 2604 2553
35 1042 945 712 977 903
30 676 604 484 577 692
25 773 715 547 719 732
20 279 262 156 240 204

Inferences

 Overall, each proposed heuristic algorithm significantly performs better


than each of the three best existing algorithms.
 Different number of machines may make some existing algorithms better
than the BHG-Sla algorithm. As the no. of machines increases BHG-slack
is found to be better than other 2 BHG algorithms. As seen for 4
machines case slack is found to be best.
 There is not much difference in all bhg algo’s in 1 machine case.
 As the processing time range increases, the overall effectiveness of each
algorithm in finding an optimal schedule does not appreciably change.
 The proposed heuristic algorithms BHG-TPI and BHGEDD are almost
equivalent in finding an optimal schedule where one is sometimes better
than the other.
 The effectiveness of existing algorithms decreases significantly as the
number of machines increases though this increase is not one directional
for all algorithms.
 The overall relative ranking of the heuristic algorithms in finding an
optimal schedule (from best to worse average OGH values) is as follows:
(BHGTPI,BHG-EDD), BHG-Sla,BHG-rj, MDD, TPI.

References:
1. Du, J., Leung, J.Y.-T., 1990. Minimizing total tardiness on one machine is
NP-hard. Mathematics of Operations Research 15, 483–495.
2. Pfund, M., Fowler, J.W., Gupta, J.N.D., 2004. A survey of algorithms for
single and multi-objective unrelated parallel-machine deterministic
scheduling. Chinese Journal of Industrial Engineers 21, 230–241.
3. Lawler, E.L., Lenstra, J.K., Rinnoy Kan, A.H.J., Shmoys, D.B., 1993.
Sequencing and scheduling: algorithm and complexity. In: Handbooks
in Operations Research and Management Science, Logistic of Production
and Inventory, vol. 4. North-Holland, Amsterdam, pp. 445–524.
4. Wilkerson, L.J., Irwin, J.D., 1971. An improved algorithm for scheduling
independent tasks. AIIE Transactions 3, 239–245.
5. Dogramaci, A., Surkis, J., 1979. Evaluation of a heuristic for scheduling
independent jobs on parallel identical processors. Management Science
25, 1208–1216.
6. Ho, J.C., Chang, Y.L., 1991. Heuristics for minimizing mean tardiness for m
parallel machines. Naval Research Logistics 38, 367–381.
7. Alidaee, B., Rosa, D., 1997. Scheduling parallel machines to minimize
total weighted and unweighted tardiness. Computers Operations
Research 24, 775–788.
8. Dirk Biskup , Jan Herrmann , Jatinder N.D. Gupta . Scheduling identical
parallel machines to minimize total tardiness.

Codes:

Random number generator :


#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
int rdtsc(){
__asm__ __volatile__("rdtsc");
}
int main(){
int n,temp,tempProcess;
FILE *fp=fopen("d:/Input.txt","w");
printf("enter the number of jobs : ");
scanf("%d",&n);
for(int i=0;i<n;i++){
srand(rdtsc());
while(1){
temp=rand();
if(temp>10 && temp<100){
fprintf(fp,"%d ",temp);
break;
}
}
while(1){
tempProcess=rand();
if(tempProcess<temp && tempProcess<100){
fprintf(fp, "%d\n",tempProcess);
break;
}
}

}
fclose(fp);

}
Algorithm TPI (traffic priority index):

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
using namespace std;
int max(int a[],int size);
float maxi(float a,float b);
float mini(float a,float b);
int main()
{
Int m[5][10], p[6], d[6], jobs, machines ,j[10] ,u[10] ,k ,mc[10]
,totalpen ,pen[5] ,c[10];
float r[10], P=0.0, D=0.0, tcr, avgp, avgd, temp[10], wd, wp;

int mp, md;


cout << "enter the number of jobs"<<endl;
cin >> jobs;
cout <<"enter the no. of machines"<<endl;
cin >> machines;
cout <<"processing time and due dates of each jobs\n"<<endl;
for(int i=0;i<jobs;i++)

cin >>p[i] ;
}
for(int i=0;i<jobs;i++)
{
cin >>d[i] ;
}

cout << "job no."<<" "<<"processing time"<<" "<<"due date\n"<<endl;


for(int i=0;i<jobs;i++)
{
cout<< i<<" "<<p[i]<<" "<<d[i]<< endl;
}
for(int i=0;i<jobs;i++)
{
P=P+p[i];
D=D+d[i];
}
avgp=P/jobs;
avgd=D/jobs;
tcr=(avgp*jobs)/(avgd*machines);
mp=max(p,jobs); // calling max function
md=max(d,jobs); // calling max function
wd=maxi(mini(0.5+(3-tcr)/tcr,1.0),0.0); //call the maxi and mini function
wp=1-wd;
for(int i=0;i<jobs;i++)
{
r[i]=(d[i]*wd/md)+(p[i]*wp/mp);
}
for(int i=0;i<jobs;i++)
{
temp[i]=r[i];
}
float emp;
for(int i=0;i<=jobs-2;i++)
{
for(int j=0;j<=jobs-2-i;j++)
{
if(temp[j]>temp[j+1])
{
emp=temp[j];
temp[j]=temp[j+1];
temp[j+1]=emp;
}
}
}
//unscheduled jobs set u can be get as
int x;
for(int j=0;j<jobs;j++)
{
for(int i=0;i<jobs;i++)
{
if ((r[i]==temp[j])&&(i!=x))
{
u[j]=i;
x=u[j];
break;
}
}
}
cout<<"unscheduled set u is"<<endl;
for(int i=0;i<jobs;i++)
{
cout<<u[i]<<" ";
}
//alloting first machine number of unscheduing jobs to each machine
for (int i=0;i<machines;i++)
{
mc[i]=0;
m[i][mc[i]]=u[i];
c[i]=0;
mc[i]++;
}
for (int i=0;i<machines;i++)
{
c[i]=c[i]+p[m[i][mc[i]-1]];
cout<<c[i]<<endl;
}
//for each machine calculate completion times and allotment of jobs to m/c.
for(int l=0;l<jobs-machines;l++)
{

//min. of all completion times


int small=c[0];
k=0;
for (int i=0;i<machines;i++)
{
if(c[i+1]<small)
{
small=c[i+1];
k=i+1;
}
}
m[k][mc[k]]=u[machines+l];
c[k]=c[k]+p[m[k][mc[k]]];
mc[k]++;
}
//printing each machine allotment
cout<< "machines have following allotment"<<endl;
for (int i=0;i<machines;i++)
{
cout <<endl<<"for machine" <<i<<" ";
for (int j=0;j<mc[i];j++)
{
cout<<m[i][j]<<" ";
}
}

//penalty for each machine


for(int i=0;i<machines;i++)
{
pen[i]=0;
for(int j=0;j<mc[i];j++)
{

if(p[m[i][j]]>d[m[i][j]])
pen[i]= pen[i]+p[m[i][j]]-d[m[i][j]];
if(j<mc[i]-1)
p[m[i][j+1]]=p[m[i][j+1]]+p[m[i][j]];
}
cout<<endl;
cout<<pen[i]<<endl;
}
totalpen=0;
for(int i=0;i<machines;i++)
totalpen=totalpen+pen[i];
cout<<totalpen;

getch();
} //final brace
//max function
int max(int a[],int size)
{ int large=a[0];
for (int i=0;i<size;i++)
{
if(a[i]>large)
large=a[i];
}
return large;
}
//maxi
float maxi(float a,float b)
{
if (a>b)
return a;
else
return b;
}
//mini
float mini(float a,float b)
{
if(a<b)
return a;
else
return b;
}

---------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------

ALGORITHM BHG-EDD:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
using namespace std;
int main()

{ //variables define here........

int sa[14][3][10] ,n ,k ,mc ,mj[14][3] ,temp[10] ,tempo ,min ,minimum ,


pr[10];

int pen[3][10] ,penalty[14] ,totalpenalty ,a ,b ,e ,jobs ,machines ,u[6] ,d[6]


f[6]
cout << "enter the number of jobs"<<endl;
cin >> jobs;
cout <<"enter the no. of machines"<<endl;
cin >> machines;
cout <<"processing time and due dates of each jobs\n"<<endl;
for(int i=0;i<jobs;i++)

cin >>p[i] ;
}
for(int i=0;i<jobs;i++)
{
cin >>d[i] ;
}

//unscheduled jobs creation


for(int i=0;i<jobs;i++)
{
temp[i]=d[i];
}
int emp;
for(int i=0;i<=jobs-2;i++)
{
for(int j=0;j<=jobs-2-i;j++)
{
if(temp[j]>temp[j+1])
{
emp=temp[j];
temp[j]=temp[j+1];
temp[j+1]=emp;
}
}
}
//unscheduled jobs set u can be get as
int x;
for(int j=0;j<jobs;j++)
{
for(int i=0;i<jobs;i++)
{
if ((d[i]==temp[j])&&(i!=x))
{
u[j]=i;
x=u[j];
break;
}
}
}
for (int i=0;i<jobs;i++)
cout<<u[i]<<endl;

cout << "job no."<<" "<<"processing time"<<" "<<"due date\n"<<endl;


for(int i=0;i<jobs;i++)
{
cout<< i<<" "<<pr[i]<<" "<<d[i]<< endl;
}
for (int i=0;i<jobs;i++)
{
f[i]=pr[i];
}

n=machines;
switch(n)
{
case 2:cout<<"two starting assignments";
k=2;
mc=2;
sa[0][0][0]=u[0];
sa[0][1][0]=u[1];
sa[1][0][0]=u[0];
sa[1][0][1]=u[1];
mj[0][0]=1;
mj[0][1]=1;
mj[1][0]=2;
mj[1][1]=0;

break;
case 3: k=5;mc=2;
//sa 0
sa[0][0][0]=u[0]; mj[0][0]=1; sa[0][1][0]=u[1]; mj[0][1]=1;
sa[0][2][0]=u[2]; mj[0][2]=1;
//sa1
sa[1][0][0]=u[0]; mj[1][0]=2; sa[1][0][1]=u[1]; mj[1][1]=1;
sa[1][1][0]=u[2]; mj[1][2]=0;
//sa2
sa[2][0][0]=u[0]; mj[2][0]=2; sa[2][0][1]=u[2]; mj[2][1]=1;
sa[2][1][0]=u[1]; mj[2][2]=0;
//sa3
sa[3][0][0]=u[1]; mj[3][0]=2; sa[3][1][1]=u[2]; mj[3][1]=1;
sa[3][2][0]=u[0]; mj[3][2]=0;
//sa4
sa[4][0][0]=u[0]; mj[4][0]=3; sa[4][0][1]=u[1]; mj[4][1]=0;
sa[4][0][2]=u[2]; mj[4][2]=0; break;

case 4: k=15;mc=4;
//sa0
sa[0][0][0]=u[0]; mj[0][0]=1; sa[0][1][0]=u[1]; mj[0][1]=1;
sa[0][2][0]=u[2]; mj[0][2]=1; sa[0][3][0]=u[3]; mj[0][3]=1;
//sa1
sa[1][0][0]=u[0]; mj[1][0]=2; sa[1][0][1]=u[1]; mj[1][0]=1;
sa[1][1][0]=u[2]; mj[1][2]=1; sa[1][2][0]=u[3]; mj[1][3]=0;
//sa2
sa[2][0][0]=u[0]; mj[2][0]=2; sa[2][0][1]=u[2]; mj[2][1]=1;
sa[2][1][0]=u[1]; mj[2][2]=1; sa[2][2][0]=u[3]; mj[2][3]=0;
//sa3
sa[3][0][0]=u[0]; mj[3][0]=2; sa[3][0][1]=u[3]; mj[3][1]=1;
sa[3][1][0]=u[1]; mj[3][2]=1; sa[3][2][0]=u[2]; mj[3][3]=0;
//sa4
sa[4][0][0]=u[1]; mj[4][0]=2; sa[4][0][1]=u[2]; mj[4][1]=1;
sa[4][1][0]=u[0]; mj[4][2]=1; sa[4][2][0]=u[3]; mj[4][3]=0;
//sa5
sa[5][0][0]=u[1]; mj[5][0]=2; sa[5][0][1]=u[3]; mj[5][1]=1;
sa[5][1][0]=u[0]; mj[5][2]=1; sa[5][2][0]=u[2]; mj[5][3]=0;
//sa6
sa[6][0][0]=u[2]; mj[6][0]=2; sa[6][0][1]=u[3]; mj[6][1]=1;
sa[6][1][0]=u[0]; mj[6][2]=1; sa[6][2][0]=u[1]; mj[6][3]=0;

//sa7
sa[7][0][0]=u[0]; mj[7][0]=2; sa[7][0][1]=u[1]; mj[7][1]=2;
sa[7][1][0]=u[2]; mj[7][2]=0; sa[7][1][1]=u[3]; mj[7][3]=0;
//sa8
sa[8][0][0]=u[0]; mj[8][0]=2; sa[8][0][1]=u[2]; mj[8][1]=2;
sa[8][1][0]=u[1]; mj[8][2]=0; sa[8][1][1]=u[3]; mj[8][3]=0;
//sa9
sa[9][0][0]=u[0]; mj[9][0]=2; sa[9][0][1]=u[3]; mj[9][1]=2;
sa[9][1][0]=u[1]; mj[9][2]=0; sa[9][1][1]=u[2]; mj[9][3]=0;
//sa10
sa[10][0][0]=u[0]; mj[10][0]=3; sa[10][0][1]=u[1]; mj[10][1]=1;
sa[10][0][2]=u[2]; mj[10][2]=0; sa[10][1][0]=u[3]; mj[10][3]=0;
//sa11
sa[11][0][0]=u[0]; mj[11][0]=3; sa[11][0][1]=u[1]; mj[11][1]=1;
sa[11][0][2]=u[3]; mj[11][2]=0; sa[11][1][0]=u[2]; mj[11][3]=0;
//sa12
sa[12][0][0]=u[0]; mj[12][0]=3; sa[12][0][1]=u[2]; mj[12][1]=1;
sa[12][0][2]=u[3]; mj[12][2]=0; sa[12][1][0]=u[1]; mj[12][3]=0;
//sa13
sa[13][0][0]=u[1]; mj[13][0]=3; sa[13][0][1]=u[2]; mj[13][1]=1;
sa[13][0][2]=u[3]; mj[13][2]=0; sa[13][1][0]=u[0]; mj[13][3]=0;
//sa14
sa[14][0][0]=u[0]; mj[14][0]=4; sa[14][0][1]=u[1]; mj[14][1]=0;
sa[14][0][2]=u[2]; mj[14][2]=0; sa[14][0][3]=u[3]; mj[14][3]=0;

}
for(int l=0;l<k;l++)
{
for(int p=mc;p<jobs;p++)
{
for(int y=0;y<mc;y++)
{
for(int i=0;i<mc;i++)
{
if(i!=y)
mj[l][i]=mj[l][i]-1;
}
//adding new element at 0th place for 1st m/c.
if(mj[l][y]>0)
{
for(int i=mj[l][y];i>0;i--)
{
sa[l][y][i]=sa[l][y][i-1];
}
}
sa[l][y][0]=u[p];
pen[y][0]=0;

//penalty for this addition element


for(int i=0;i<mc;i++)
{
for(int j=0;j<=mj[l][i];j++)
{
if(pr[sa[l][i][j]]>d[sa[l][i][j]])
{
pen[y][0]=pen[y][0]+pr[sa[l][i][j]]-d[sa[l][i][j]];

}
if(j<mj[l][i])
{
pr[sa[l][i][j+1]]=pr[sa[l][i][j]]+pr[sa[l][i][j+1]];
}
}
}
//processing times back to the same value.......
for (int i=0;i<jobs;i++)
{
pr[i]=f[i];
}

//if addition takes place in xth position


for(int x=1;x<=mj[l][y];x++)
{
tempo=sa[l][y][x-1];
sa[l][y][x-1]=sa[l][y][x];
sa[l][y][x]=tempo;
pen[y][x]=0;
for(int i=0;i<mc;i++)
{
for(int j=0;j<=mj[l][i];j++)
{
if(pr[sa[l][i][j]]>d[sa[l][i][j]])
{
pen[y][x]=pen[y][x]+pr[sa[l][i][j]]-d[sa[l][i][j]];

}
if(j<mj[l][i])
{
pr[sa[l][i][j+1]]=pr[sa[l][i][j]]+pr[sa[l][i][j+1]];
}
}
}
for (int i=0;i<jobs;i++)
{
pr[i]=f[i];
}
}

for(int i=0;i<mc;i++)
{
if(i!=y)
mj[l][i]=mj[l][i]+1;
}

min=pen[0][mj[l][0]];
a=0;
b=mj[l][0];
for(int i=0;i<mc;i++)
{
for(int j=0;j<=mj[l][i];j++)
{
if(pen[i][j]<min)
{
min=pen[i][j];
a=i;
b=j;
}
}
}
if(b!=mj[l][a])
{
for(int i=mj[l][a];i>=b;i--)
{
sa[l][a][i]=sa[l][a][i-1];
}
sa[l][a][b]=u[p];
mj[l][a]++;
}
else
{
sa[l][a][mj[l][a]]=u[p];
mj[l][a]++;
}

} //bracket for unscheduled jobs u....i.e for p loop


penalty[l]=pen[a][b];

}
//bracket for starting assignment.....

minimum=penalty[0];
e=0;
for(int i=0;i<k;i++)
{
if(penalty[i]<minimum)
{
minimum=penalty[i];
e=i;
}
}
//eth starting assignment has to be taken
// hence allotment is given by......

cout<< "machines have following allotment"<<endl;


for (int i=0;i<machines;i++)
{
cout <<endl<<"for machine" <<i<<" ";
for (int j=0;j<mj[e][i];j++)
{
cout<<sa[e][i][j]<<" ";
}
}cout<<endl;
totalpenalty=penalty[e];
cout<<totalpenalty<<endl;
getch();

}
//bracket to close the main.

---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------

ALGORITHM BHG-SLACK

ALGORITHM BHG-EDD:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
using namespace std;
int main()

{ //variables define here........

int sa[14][3][10] ,n ,k ,mc ,mj[14][3] ,temp[10] ,tempo ,min ,minimum ,


pr[10],sla[6];

int pen[3][10] ,penalty[14] ,totalpenalty ,a ,b ,e ,jobs ,machines ,u[6] ,d[6]


f[6]
cout << "enter the number of jobs"<<endl;
cin >> jobs;
cout <<"enter the no. of machines"<<endl;
cin >> machines;
cout <<"processing time and due dates of each jobs\n"<<endl;
for(int i=0;i<jobs;i++)
cin >>p[i] ;
}
for(int i=0;i<jobs;i++)
{
cin >>d[i] ;
}
for(int i=0;i<jobs;i++)
{
Sla[i]=d[i]-p[i];
}

//unscheduled jobs creation


for(int i=0;i<jobs;i++)
{
temp[i]=sla[i];
}
int emp;
for(int i=0;i<=jobs-2;i++)
{
for(int j=0;j<=jobs-2-i;j++)
{
if(temp[j]>temp[j+1])
{
emp=temp[j];
temp[j]=temp[j+1];
temp[j+1]=emp;
}
}
}
//unscheduled jobs set u can be get as
int x;
for(int j=0;j<jobs;j++)
{
for(int i=0;i<jobs;i++)
{
if ((d[i]==temp[j])&&(i!=x))
{
u[j]=i;
x=u[j];
break;
}
}
}
for (int i=0;i<jobs;i++)
cout<<u[i]<<endl;

cout << "job no."<<" "<<"processing time"<<" "<<"due date\n"<<endl;


for(int i=0;i<jobs;i++)
{
cout<< i<<" "<<pr[i]<<" "<<d[i]<< endl;
}
for (int i=0;i<jobs;i++)
{
f[i]=pr[i];
}

n=machines;
switch(n)
{
case 2:cout<<"two starting assignments";
k=2;
mc=2;
sa[0][0][0]=u[0];
sa[0][1][0]=u[1];
sa[1][0][0]=u[0];
sa[1][0][1]=u[1];
mj[0][0]=1;
mj[0][1]=1;
mj[1][0]=2;
mj[1][1]=0;

break;
case 3: k=5;mc=2;
//sa 0
sa[0][0][0]=u[0]; mj[0][0]=1; sa[0][1][0]=u[1]; mj[0][1]=1;
sa[0][2][0]=u[2]; mj[0][2]=1;
//sa1
sa[1][0][0]=u[0]; mj[1][0]=2; sa[1][0][1]=u[1]; mj[1][1]=1;
sa[1][1][0]=u[2]; mj[1][2]=0;
//sa2
sa[2][0][0]=u[0]; mj[2][0]=2; sa[2][0][1]=u[2]; mj[2][1]=1;
sa[2][1][0]=u[1]; mj[2][2]=0;
//sa3
sa[3][0][0]=u[1]; mj[3][0]=2; sa[3][1][1]=u[2]; mj[3][1]=1;
sa[3][2][0]=u[0]; mj[3][2]=0;
//sa4
sa[4][0][0]=u[0]; mj[4][0]=3; sa[4][0][1]=u[1]; mj[4][1]=0;
sa[4][0][2]=u[2]; mj[4][2]=0; break;

case 4: k=15;mc=4;
//sa0
sa[0][0][0]=u[0]; mj[0][0]=1; sa[0][1][0]=u[1]; mj[0][1]=1;
sa[0][2][0]=u[2]; mj[0][2]=1; sa[0][3][0]=u[3]; mj[0][3]=1;
//sa1
sa[1][0][0]=u[0]; mj[1][0]=2; sa[1][0][1]=u[1]; mj[1][0]=1;
sa[1][1][0]=u[2]; mj[1][2]=1; sa[1][2][0]=u[3]; mj[1][3]=0;
//sa2
sa[2][0][0]=u[0]; mj[2][0]=2; sa[2][0][1]=u[2]; mj[2][1]=1;
sa[2][1][0]=u[1]; mj[2][2]=1; sa[2][2][0]=u[3]; mj[2][3]=0;
//sa3
sa[3][0][0]=u[0]; mj[3][0]=2; sa[3][0][1]=u[3]; mj[3][1]=1;
sa[3][1][0]=u[1]; mj[3][2]=1; sa[3][2][0]=u[2]; mj[3][3]=0;
//sa4
sa[4][0][0]=u[1]; mj[4][0]=2; sa[4][0][1]=u[2]; mj[4][1]=1;
sa[4][1][0]=u[0]; mj[4][2]=1; sa[4][2][0]=u[3]; mj[4][3]=0;
//sa5
sa[5][0][0]=u[1]; mj[5][0]=2; sa[5][0][1]=u[3]; mj[5][1]=1;
sa[5][1][0]=u[0]; mj[5][2]=1; sa[5][2][0]=u[2]; mj[5][3]=0;
//sa6
sa[6][0][0]=u[2]; mj[6][0]=2; sa[6][0][1]=u[3]; mj[6][1]=1;
sa[6][1][0]=u[0]; mj[6][2]=1; sa[6][2][0]=u[1]; mj[6][3]=0;

//sa7
sa[7][0][0]=u[0]; mj[7][0]=2; sa[7][0][1]=u[1]; mj[7][1]=2;
sa[7][1][0]=u[2]; mj[7][2]=0; sa[7][1][1]=u[3]; mj[7][3]=0;
//sa8
sa[8][0][0]=u[0]; mj[8][0]=2; sa[8][0][1]=u[2]; mj[8][1]=2;
sa[8][1][0]=u[1]; mj[8][2]=0; sa[8][1][1]=u[3]; mj[8][3]=0;
//sa9
sa[9][0][0]=u[0]; mj[9][0]=2; sa[9][0][1]=u[3]; mj[9][1]=2;
sa[9][1][0]=u[1]; mj[9][2]=0; sa[9][1][1]=u[2]; mj[9][3]=0;
//sa10
sa[10][0][0]=u[0]; mj[10][0]=3; sa[10][0][1]=u[1]; mj[10][1]=1;
sa[10][0][2]=u[2]; mj[10][2]=0; sa[10][1][0]=u[3]; mj[10][3]=0;
//sa11
sa[11][0][0]=u[0]; mj[11][0]=3; sa[11][0][1]=u[1]; mj[11][1]=1;
sa[11][0][2]=u[3]; mj[11][2]=0; sa[11][1][0]=u[2]; mj[11][3]=0;
//sa12
sa[12][0][0]=u[0]; mj[12][0]=3; sa[12][0][1]=u[2]; mj[12][1]=1;
sa[12][0][2]=u[3]; mj[12][2]=0; sa[12][1][0]=u[1]; mj[12][3]=0;
//sa13
sa[13][0][0]=u[1]; mj[13][0]=3; sa[13][0][1]=u[2]; mj[13][1]=1;
sa[13][0][2]=u[3]; mj[13][2]=0; sa[13][1][0]=u[0]; mj[13][3]=0;
//sa14
sa[14][0][0]=u[0]; mj[14][0]=4; sa[14][0][1]=u[1]; mj[14][1]=0;
sa[14][0][2]=u[2]; mj[14][2]=0; sa[14][0][3]=u[3]; mj[14][3]=0;

}
for(int l=0;l<k;l++)
{
for(int p=mc;p<jobs;p++)
{
for(int y=0;y<mc;y++)
{
for(int i=0;i<mc;i++)
{
if(i!=y)
mj[l][i]=mj[l][i]-1;
}
//adding new element at 0th place for 1st m/c.
if(mj[l][y]>0)
{
for(int i=mj[l][y];i>0;i--)
{
sa[l][y][i]=sa[l][y][i-1];
}
}
sa[l][y][0]=u[p];
pen[y][0]=0;

//penalty for this addition element


for(int i=0;i<mc;i++)
{
for(int j=0;j<=mj[l][i];j++)
{
if(pr[sa[l][i][j]]>d[sa[l][i][j]])
{
pen[y][0]=pen[y][0]+pr[sa[l][i][j]]-d[sa[l][i][j]];

}
if(j<mj[l][i])
{
pr[sa[l][i][j+1]]=pr[sa[l][i][j]]+pr[sa[l][i][j+1]];
}
}
}
//processing times back to the same value.......
for (int i=0;i<jobs;i++)
{
pr[i]=f[i];
}

//if addition takes place in xth position


for(int x=1;x<=mj[l][y];x++)
{
tempo=sa[l][y][x-1];
sa[l][y][x-1]=sa[l][y][x];
sa[l][y][x]=tempo;
pen[y][x]=0;
for(int i=0;i<mc;i++)
{
for(int j=0;j<=mj[l][i];j++)
{
if(pr[sa[l][i][j]]>d[sa[l][i][j]])
{
pen[y][x]=pen[y][x]+pr[sa[l][i][j]]-d[sa[l][i][j]];

}
if(j<mj[l][i])
{
pr[sa[l][i][j+1]]=pr[sa[l][i][j]]+pr[sa[l][i][j+1]];
}
}
}
for (int i=0;i<jobs;i++)
{
pr[i]=f[i];
}
}

for(int i=0;i<mc;i++)
{
if(i!=y)
mj[l][i]=mj[l][i]+1;
}

min=pen[0][mj[l][0]];
a=0;
b=mj[l][0];
for(int i=0;i<mc;i++)
{
for(int j=0;j<=mj[l][i];j++)
{
if(pen[i][j]<min)
{
min=pen[i][j];
a=i;
b=j;
}
}
}
if(b!=mj[l][a])
{
for(int i=mj[l][a];i>=b;i--)
{
sa[l][a][i]=sa[l][a][i-1];
}
sa[l][a][b]=u[p];
mj[l][a]++;
}
else
{
sa[l][a][mj[l][a]]=u[p];
mj[l][a]++;
}

} //bracket for unscheduled jobs u....i.e for p loop


penalty[l]=pen[a][b];

}
//bracket for starting assignment.....

minimum=penalty[0];
e=0;
for(int i=0;i<k;i++)
{
if(penalty[i]<minimum)
{
minimum=penalty[i];
e=i;
}
}
//eth starting assignment has to be taken
// hence allotment is given by......

cout<< "machines have following allotment"<<endl;


for (int i=0;i<machines;i++)
{
cout <<endl<<"for machine" <<i<<" ";
for (int j=0;j<mj[e][i];j++)
{
cout<<sa[e][i][j]<<" ";
}
}cout<<endl;
totalpenalty=penalty[e];
cout<<totalpenalty<<endl;
getch();

}
//bracket to close the main.

---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------

ALGORITHM- MDD(modified due date)

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
using namespace std;

int main()
{
int m[5][10],p[],d[],jobs,machines,j[10],u[10],k,mc[10],totalpen,pen[5],c[10];
int u1[5][10],u2[5][10],mu1[10],mu2[10],y[2],fg[5],min2,min,h[2];
int mp,md;
cout << "enter the number of jobs"<<endl;
cin >> jobs;
cout <<"enter the no. of machines"<<endl;
cin >> machines;
cout <<"processing time and due dates of each jobs\n"<<endl;
for(int i=0;i<jobs;i++)

cin >>p[i] ;
}
for(int i=0;i<jobs;i++)
{
cin >>d[i] ;
}

cout << "job no."<<" "<<"processing time"<<" "<<"due date\n"<<endl;


for(int i=0;i<jobs;i++)
{
cout<< i<<" "<<p[i]<<" "<<d[i]<< endl;
}
for(int i=0;i<jobs;i++)
{
u[i]=i;
}
// one more loop the outermost
for(int l=jobs-1;l>=0;l++)
{
for(int i=0;i<machines;i++)
{
c[i]=0;
}
for(int i=0;i<machines;i++)
{
for(int j=0;j<l+1;l++)
{
if(c[i]+p[j]>d[j])
{
u1[i][mu1[i]]=u[j];
mu1[i]++;
}
else
{
u2[i][mu2[i]]=u[j];
mu2[i]++;
}
}
}
for(int i=0;i<machines;i++)
{
int small=p[u1[i][mu1[i]]];
for (int j=0;j<machines;j++)
{
for (int k=0;k<mu1[j];k++)
{
if(p[u1[j][k]]<small)
{
small=p[u1[j][k]];
int min=u1[j][k];
}
}
}
y[i]=min;
int small2=d[u1[i][mu1[i]]];
for (int j=0;j<machines;j++)
{
for (int k=0;k<mu1[j];k++)
{
if(d[u1[j][k]]<small2)
{
small2=d[u1[j][k]];
min2=u2[j][k];
}
}
}
h[i]=min2;
}
for(int i=0;i<machines;i++)
{
if((c[i]+p[y[i]])<(c[i]+d[y[i]]))
{
fg[i]=y[i];
}
else
{
fg[i]=j[i];
}
}
int small=fg[0];
int b;
for(int i=0;i<machines;i++)
{
if(fg[i]<small)
{
small=fg[i];
k=i;
}
}
for(int i=0;i<machines;i++)
mc[i]=0;
m[k][mc[k]]=small;
for(int i=0;i<machines;i++)
{if(u[i]==m[k][mc[k]])
{
b=i;
break;
}
}
for(int i=b;i<machines-1;i++)
{
u[b]=u[b+1];
}
}
cout<< "machines have following allotment"<<endl;
for (int i=0;i<machines;i++)
{
cout <<endl<<"for machine" <<i<<" ";
for (int j=0;j<mc[i];j++)
{
cout<<m[i][j]<<" ";
}
}
//penalty for each machine
for(int i=0;i<machines;i++)
{
pen[i]=0;
for(int j=0;j<mc[i];j++)
{

if(p[m[i][j]]>d[m[i][j]])
pen[i]= pen[i]+p[m[i][j]]-d[m[i][j]];
if(j<mc[i]-1)
p[m[i][j+1]]=p[m[i][j+1]]+p[m[i][j]];
}
cout<<endl;
cout<<pen[i]<<endl;
}
totalpen=0;
for(int i=0;i<machines;i++)
totalpen=totalpen+pen[i];
cout<<totalpen;

getch();
}
//final brace

---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------

PROPOSED ONE(BHG WITH R.J CHAMBERS ALGORITHM)

#include <stdio.h>
#include <conio.h>
#include <math.h>
int formation[3],p[20],d[20],u[20];
int job_no;
void leastPenalty(int x[]){
int penalty=0,min=-1,i,temp[3],j,add=0;
FILE *f=fopen("C:/schd1.dat","r");
for(i=0;i<6;i++){
penalty=add=0;
fscanf(f,"%d%d%d",&temp[0],&temp[1],&temp[2]);
for(j=0;j<3;j++){
if(add+p[x[temp[j]]]>d[x[temp[j]]])
penalty+=(add+p[x[temp[j]]]-
d[x[temp[j]]])*u[x[temp[j]]];
add+=p[x[temp[j]]];
}
if(min==-1||min>=penalty){
for(j=0;j<3;j++)
formation[j]=x[temp[j]];
min=penalty;
}
}
fclose(f);
}
int getValueOfPenalty(int seq[]){
int i,penalty=0,add=0;
for(i=0;i<job_no;i++){
if(add+p[seq[i]]>d[seq[i]])
penalty+=(add+p[seq[i]]-d[seq[i]])*u[seq[i]];
add+=p[seq[i]];
}
return penalty;
}

int main(){
FILE *fabc;
FILE *fa;
int i,initial=0,j,min=10000,value,xyz;
int temp[20],is[20];
int x[3];
fabc=fopen("c:/decompl.dat","w+");
printf("\n\n\n ..............Please press any key to continue");
getch();
printf("\nGive the number of jobs= ");
scanf("%d",&job_no);
printf("\nGive the 1.processing time, 2.due date, 3.penalty per unit");
printf("\ntime tardy for each job\n\n");
for(i=0;i<job_no;i++){
printf(" Job no. = %2d\n",i+1);
printf("\nprocessing time = ");
scanf("%d",&p[i]);
printf("\ndue date = ");
scanf("%d",&d[i]);
printf("\npenalty per unit time tardy = ");
scanf("%d",&u[i]);
}
/*p[0]=10;p[1]=20;p[2]=14;p[3]=16;p[4]=25;p[5]=15;
d[0]=24;d[1]=29;d[2]=41;d[3]=31;d[4]=46;d[5]=41;
u[0]=25;u[1]=10;u[2]=20;u[3]=7; u[4]=12;u[5]=8;*/
fprintf(fabc,"\n\nNo of jobs=%d\n\n",job_no);
fprintf(fabc,"Job no. Processing time Due date Penalty/unit time
tardy\n");

fprintf(fabc,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~\n");
for(i=0;i<job_no;++i)
fprintf(fabc,"%d %18d %15d %20d\n",i+1,p[i],d[i],u[i]);

fprintf(fabc,"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~\n");

/
****************************************************************
**********/
/* Calculation of initial Sequence */
/**********************************************************
****************/

for(i=0;i<job_no;i++)
temp[i]=d[i];
for(i=0;i<job_no;i++){
for(j=0;j<job_no;j++)
if(temp[j]!=-1&&min>temp[j])
min=temp[j];
for(j=0;j<job_no;j++)
if(min==temp[j]){
temp[j]=-1;
is[initial++]=j;
break;
}
min=10000;
}
another:
printf("\n Initial Sequence=");
fprintf(fabc,"\nInitial Qequence=");
for(initial=0;initial<job_no;++initial)
{
printf("%3d",is[initial]+1);
fprintf(fabc,"%3d",is[initial]+1);
}

/
****************************************************************
**************/
/* Calculation of Penalty in Initial Sequence */

/***************************************************************
***************/
value=getValueOfPenalty(is);
printf("\nPenalty in Initial Sequence =%d\n",value);
fprintf(fabc,"\n\nPenalty in Initial Sequence=%2d",value);
printf("\n.................press any key to proceed futher\n");
getch();
/***************************************************************
***************/
/* Calculation of Final sequence */

/***************************************************************
***************/
/*is[0]=3;is[1]=4;is[2]=5;is[3]=2;is[4]=1;is[5]=0;
value=getValueOfPenalty(is);*/
while(1){
initial=0;
for(i=0;i<job_no;i++)
temp[i]=is[i];
for(i=0;i<job_no/3+1;i++){
for(j=0;j<3;j++)
x[j]=is[initial++];
leastPenalty(x);
initial-=3;
for(j=0;j<3;j++)
is[initial++]=formation[j];
initial--;
if(job_no-2*(i+1)>=3)
continue;
if(job_no-2*(i+1)==1)
break;
x[0]=is[i*initial];
x[1]=is[i*initial+1];
x[2]=is[i*initial];
min=p[x[0]]>d[x[0]]?(p[x[0]]-d[x[0]])*u[x[0]]:0+(p[x[0]]
+p[x[1]])>d[x[1]]?(p[x[1]]+p[x[0]]-d[x[1]])*u[x[1]]:0;
xyz=p[x[1]]>d[x[1]]?(p[x[1]]-d[x[1]])*u[x[1]]:0+(p[x[1]]
+p[x[2]])>d[x[2]]?(p[x[2]]+p[x[1]]-d[x[2]])*u[x[2]]:0;
if(min>xyz){
is[i*initial]=x[1];
is[i*initial+1]=x[2];
}
else{
is[i*initial]=x[0];
is[i*initial+1]=x[1];
}
i++;

}
if(value<=getValueOfPenalty(is)){
for(i=0;i<job_no;i++)
is[i]=temp[i];
break;
}
else{
for(i=0;i<job_no;i++)
temp[i]=is[i];
printf("\nsequence = ");
for(i=0;i<job_no;i++)
printf("%d ",is[i]+1);
printf("\nvalue = %d",getValueOfPenalty(is));
}
value=getValueOfPenalty(is);
}
printf("\n\n\n\nfinal sequence = ");
for(i=0;i<job_no;i++)
printf("%d ",is[i]+1);
printf("\nvalue = %d\n\n\n",value);
getch();
fclose(fabc);
return 0;
}

You might also like