Professional Documents
Culture Documents
Scheduling Jobs in Parallel Machines To Minimise Total Tardiness
Scheduling Jobs in Parallel Machines To Minimise Total Tardiness
Scheduling Jobs in Parallel Machines To Minimise Total Tardiness
1. Introduction:
Application:
Md max1≤i≤n{di}
Mp max1≤i≤n{pi}
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: 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.
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=()
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 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.
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 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
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 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.
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
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 :
assumptions followed:
Inferences
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:
}
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;
cin >>p[i] ;
}
for(int i=0;i<jobs;i++)
{
cin >>d[i] ;
}
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()
cin >>p[i] ;
}
for(int i=0;i<jobs;i++)
{
cin >>d[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;
}
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(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 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......
}
//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()
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;
}
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(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 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......
}
//bracket to close the main.
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
#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] ;
}
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
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
#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;
}